Commit 87392385 authored by Eric Anholt's avatar Eric Anholt

gallium/drm: Define the DRM entrypoints in drm_helper.h

This cuts even more code duplication.

Part-of: <!6751>
parent bc10b496
......@@ -66,88 +66,25 @@ struct pipe_loader_drm_device {
static const struct pipe_loader_ops pipe_loader_drm_ops;
#ifdef GALLIUM_STATIC_TARGETS
static const struct drm_driver_descriptor driver_descriptors[] = {
{
.driver_name = "i915",
.create_screen = pipe_i915_create_screen,
},
{
.driver_name = "iris",
.create_screen = pipe_iris_create_screen,
.driconf_xml = &iris_driconf_xml,
},
{
.driver_name = "nouveau",
.create_screen = pipe_nouveau_create_screen,
},
{
.driver_name = "r300",
.create_screen = pipe_r300_create_screen,
},
{
.driver_name = "r600",
.create_screen = pipe_r600_create_screen,
},
{
.driver_name = "radeonsi",
.create_screen = pipe_radeonsi_create_screen,
.driconf_xml = &radeonsi_driconf_xml,
},
{
.driver_name = "vmwgfx",
.create_screen = pipe_vmwgfx_create_screen,
},
{
.driver_name = "kgsl",
.create_screen = pipe_freedreno_create_screen,
},
{
.driver_name = "msm",
.create_screen = pipe_freedreno_create_screen,
},
{
.driver_name = "virtio_gpu",
.create_screen = pipe_virgl_create_screen,
.driconf_xml = &virgl_driconf_xml,
},
{
.driver_name = "v3d",
.create_screen = pipe_v3d_create_screen,
.driconf_xml = &v3d_driconf_xml,
},
{
.driver_name = "vc4",
.create_screen = pipe_vc4_create_screen,
.driconf_xml = &v3d_driconf_xml,
},
{
.driver_name = "panfrost",
.create_screen = pipe_panfrost_create_screen,
},
{
.driver_name = "etnaviv",
.create_screen = pipe_etna_create_screen,
},
{
.driver_name = "tegra",
.create_screen = pipe_tegra_create_screen,
},
{
.driver_name = "lima",
.create_screen = pipe_lima_create_screen,
},
{
.driver_name = "zink",
.create_screen = pipe_zink_create_screen,
},
static const struct drm_driver_descriptor *driver_descriptors[] = {
&i915_driver_descriptor,
&iris_driver_descriptor,
&nouveau_driver_descriptor,
&r300_driver_descriptor,
&r600_driver_descriptor,
&radeonsi_driver_descriptor,
&vmwgfx_driver_descriptor,
&kgsl_driver_descriptor,
&msm_driver_descriptor,
&virtio_gpu_driver_descriptor,
&v3d_driver_descriptor,
&vc4_driver_descriptor,
&panfrost_driver_descriptor,
&etnaviv_driver_descriptor,
&tegra_driver_descriptor,
&lima_driver_descriptor,
&zink_driver_descriptor,
};
static const struct drm_driver_descriptor default_driver_descriptor = {
.driver_name = "kmsro",
.create_screen = pipe_kmsro_create_screen,
.driconf_xml = &v3d_driconf_xml,
};
#endif
static const struct drm_driver_descriptor *
......@@ -155,10 +92,10 @@ get_driver_descriptor(const char *driver_name, struct util_dl_library **plib)
{
#ifdef GALLIUM_STATIC_TARGETS
for (int i = 0; i < ARRAY_SIZE(driver_descriptors); i++) {
if (strcmp(driver_descriptors[i].driver_name, driver_name) == 0)
return &driver_descriptors[i];
if (strcmp(driver_descriptors[i]->driver_name, driver_name) == 0)
return driver_descriptors[i];
}
return &default_driver_descriptor;
return &kmsro_driver_descriptor;
#else
*plib = pipe_loader_find_module(driver_name, PIPE_SEARCH_DIR);
if (!*plib)
......
......@@ -7,26 +7,62 @@
#include "frontend/drm_driver.h"
#include "util/driconf.h"
/* The static pipe loader refers to all of the pipe_*_create_screen functions
* for all drivers, regardless of whether they are configured in this Mesa
* build, or whether they're included in the specific gallium target. The
* target will include this header with the #defines for the specific drivers
* it's including, and the disabled drivers will have their create function
* stubbed out.
/**
* Instantiate a drm_driver_descriptor struct.
*/
#define STUB_CREATE_SCREEN(driver) \
struct pipe_screen * \
#define DEFINE_DRM_DRIVER_DESCRIPTOR(descriptor_name, driver, driconf, func) \
const struct drm_driver_descriptor descriptor_name = { \
.driver_name = #driver, \
.driconf_xml = driconf, \
.create_screen = func, \
};
/* The static pipe loader refers to the *_driver_descriptor structs for all
* drivers, regardless of whether they are configured in this Mesa build, or
* whether they're included in the specific gallium target. The target (dri,
* vdpau, etc.) will include this header with the #defines for the specific
* drivers it's including, and the disabled drivers will have a descriptor
* with a stub create function logging the failure.
*
* The dynamic pipe loader instead has target/pipeloader/pipe_*.c including
* this header in a pipe_*.so for each driver which will have one driver's
* GALLIUM_* defined. We make a single driver_descriptor entrypoint that is
* dlsym()ed by the dynamic pipe loader.
*/
#ifdef PIPE_LOADER_DYNAMIC
#define DRM_DRIVER_DESCRIPTOR(driver, driconf) \
PUBLIC DEFINE_DRM_DRIVER_DESCRIPTOR(driver_descriptor, driver, driconf, pipe_##driver##_create_screen)
#define DRM_DRIVER_DESCRIPTOR_STUB(driver)
#define DRM_DRIVER_DESCRIPTOR_ALIAS(driver, alias, driconf)
#else
#define DRM_DRIVER_DESCRIPTOR(driver, driconf) \
DEFINE_DRM_DRIVER_DESCRIPTOR(driver##_driver_descriptor, driver, driconf, pipe_##driver##_create_screen)
#define DRM_DRIVER_DESCRIPTOR_STUB(driver) \
static struct pipe_screen * \
pipe_##driver##_create_screen(int fd, const struct pipe_screen_config *config) \
{ \
fprintf(stderr, #driver ": driver missing\n"); \
return NULL; \
}
} \
DRM_DRIVER_DESCRIPTOR(driver, NULL)
#define DRM_DRIVER_DESCRIPTOR_ALIAS(driver, alias, driconf) \
DEFINE_DRM_DRIVER_DESCRIPTOR(alias##_driver_descriptor, alias, driconf, pipe_##driver##_create_screen)
#endif
#ifdef GALLIUM_I915
#include "i915/drm/i915_drm_public.h"
#include "i915/i915_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_i915_create_screen(int fd, const struct pipe_screen_config *config)
{
struct i915_winsys *iws;
......@@ -39,15 +75,15 @@ pipe_i915_create_screen(int fd, const struct pipe_screen_config *config)
screen = i915_screen_create(iws);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(i915, NULL)
#else
STUB_CREATE_SCREEN(i915)
DRM_DRIVER_DESCRIPTOR_STUB(i915)
#endif
#ifdef GALLIUM_IRIS
#include "iris/drm/iris_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_iris_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -59,16 +95,16 @@ pipe_iris_create_screen(int fd, const struct pipe_screen_config *config)
const char *iris_driconf_xml =
#include "iris/iris_driinfo.h"
;
DRM_DRIVER_DESCRIPTOR(iris, &iris_driconf_xml)
#else
STUB_CREATE_SCREEN(iris)
const char *iris_driconf_xml = NULL;
DRM_DRIVER_DESCRIPTOR_STUB(iris)
#endif
#ifdef GALLIUM_NOUVEAU
#include "nouveau/drm/nouveau_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_nouveau_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -76,15 +112,22 @@ pipe_nouveau_create_screen(int fd, const struct pipe_screen_config *config)
screen = nouveau_drm_screen_create(fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(nouveau, NULL)
#else
STUB_CREATE_SCREEN(nouveau)
DRM_DRIVER_DESCRIPTOR_STUB(nouveau)
#endif
#if defined(GALLIUM_VC4) || defined(GALLIUM_V3D)
const char *v3d_driconf_xml =
#include "v3d/v3d_driinfo.h"
;
#endif
#ifdef GALLIUM_KMSRO
#include "kmsro/drm/kmsro_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_kmsro_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -92,9 +135,14 @@ pipe_kmsro_create_screen(int fd, const struct pipe_screen_config *config)
screen = kmsro_drm_screen_create(fd, config);
return screen ? debug_screen_wrap(screen) : NULL;
}
#if defined(GALLIUM_VC4) || defined(GALLIUM_V3D)
DRM_DRIVER_DESCRIPTOR(kmsro, &v3d_driconf_xml)
#else
DRM_DRIVER_DESCRIPTOR(kmsro, NULL)
#endif
#else
STUB_CREATE_SCREEN(kmsro)
DRM_DRIVER_DESCRIPTOR_STUB(kmsro)
#endif
#ifdef GALLIUM_R300
......@@ -102,7 +150,7 @@ STUB_CREATE_SCREEN(kmsro)
#include "radeon/drm/radeon_drm_public.h"
#include "r300/r300_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_r300_create_screen(int fd, const struct pipe_screen_config *config)
{
struct radeon_winsys *rw;
......@@ -110,9 +158,10 @@ pipe_r300_create_screen(int fd, const struct pipe_screen_config *config)
rw = radeon_drm_winsys_create(fd, config, r300_screen_create);
return rw ? debug_screen_wrap(rw->screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(r300, NULL)
#else
STUB_CREATE_SCREEN(r300)
DRM_DRIVER_DESCRIPTOR_STUB(r300)
#endif
#ifdef GALLIUM_R600
......@@ -120,7 +169,7 @@ STUB_CREATE_SCREEN(r300)
#include "radeon/drm/radeon_drm_public.h"
#include "r600/r600_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_r600_create_screen(int fd, const struct pipe_screen_config *config)
{
struct radeon_winsys *rw;
......@@ -128,15 +177,16 @@ pipe_r600_create_screen(int fd, const struct pipe_screen_config *config)
rw = radeon_drm_winsys_create(fd, config, r600_screen_create);
return rw ? debug_screen_wrap(rw->screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(r600, NULL)
#else
STUB_CREATE_SCREEN(r600)
DRM_DRIVER_DESCRIPTOR_STUB(r600)
#endif
#ifdef GALLIUM_RADEONSI
#include "radeonsi/si_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen = radeonsi_screen_create(fd, config);
......@@ -147,17 +197,17 @@ pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config)
const char *radeonsi_driconf_xml =
#include "radeonsi/si_driinfo.h"
;
DRM_DRIVER_DESCRIPTOR(radeonsi, &radeonsi_driconf_xml)
#else
STUB_CREATE_SCREEN(radeonsi)
const char *radeonsi_driconf_xml = NULL;
DRM_DRIVER_DESCRIPTOR_STUB(radeonsi)
#endif
#ifdef GALLIUM_VMWGFX
#include "svga/drm/svga_drm_public.h"
#include "svga/svga_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_vmwgfx_create_screen(int fd, const struct pipe_screen_config *config)
{
struct svga_winsys_screen *sws;
......@@ -170,33 +220,35 @@ pipe_vmwgfx_create_screen(int fd, const struct pipe_screen_config *config)
screen = svga_screen_create(sws);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(vmwgfx, NULL)
#else
STUB_CREATE_SCREEN(vmwgfx)
DRM_DRIVER_DESCRIPTOR_STUB(vmwgfx)
#endif
#ifdef GALLIUM_FREEDRENO
#include "freedreno/drm/freedreno_drm_public.h"
struct pipe_screen *
pipe_freedreno_create_screen(int fd, const struct pipe_screen_config *config)
static struct pipe_screen *
pipe_msm_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
screen = fd_drm_screen_create(fd, NULL);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(msm, NULL)
#else
STUB_CREATE_SCREEN(freedreno)
DRM_DRIVER_DESCRIPTOR_STUB(msm)
#endif
DRM_DRIVER_DESCRIPTOR_ALIAS(msm, kgsl, NULL)
#ifdef GALLIUM_VIRGL
#include "virgl/drm/virgl_drm_public.h"
#include "virgl/virgl_public.h"
struct pipe_screen *
pipe_virgl_create_screen(int fd, const struct pipe_screen_config *config)
static struct pipe_screen *
pipe_virtio_gpu_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -207,16 +259,16 @@ pipe_virgl_create_screen(int fd, const struct pipe_screen_config *config)
const char *virgl_driconf_xml =
#include "virgl/virgl_driinfo.h"
;
DRM_DRIVER_DESCRIPTOR(virtio_gpu, &virgl_driconf_xml)
#else
STUB_CREATE_SCREEN(virgl)
const char *virgl_driconf_xml = NULL;
DRM_DRIVER_DESCRIPTOR_STUB(virtio_gpu)
#endif
#ifdef GALLIUM_VC4
#include "vc4/drm/vc4_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_vc4_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -224,14 +276,15 @@ pipe_vc4_create_screen(int fd, const struct pipe_screen_config *config)
screen = vc4_drm_screen_create(fd, config);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(vc4, &v3d_driconf_xml)
#else
STUB_CREATE_SCREEN(vc4)
DRM_DRIVER_DESCRIPTOR_STUB(vc4)
#endif
#ifdef GALLIUM_V3D
#include "v3d/drm/v3d_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_v3d_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -240,19 +293,16 @@ pipe_v3d_create_screen(int fd, const struct pipe_screen_config *config)
return screen ? debug_screen_wrap(screen) : NULL;
}
const char *v3d_driconf_xml =
#include "v3d/v3d_driinfo.h"
;
DRM_DRIVER_DESCRIPTOR(v3d, &v3d_driconf_xml)
#else
STUB_CREATE_SCREEN(v3d)
const char *v3d_driconf_xml = NULL;
DRM_DRIVER_DESCRIPTOR_STUB(v3d)
#endif
#ifdef GALLIUM_PANFROST
#include "panfrost/drm/panfrost_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -260,31 +310,33 @@ pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config)
screen = panfrost_drm_screen_create(fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(panfrost, NULL)
#else
STUB_CREATE_SCREEN(panfrost)
DRM_DRIVER_DESCRIPTOR_STUB(panfrost)
#endif
#ifdef GALLIUM_ETNAVIV
#include "etnaviv/drm/etnaviv_drm_public.h"
struct pipe_screen *
pipe_etna_create_screen(int fd, const struct pipe_screen_config *config)
static struct pipe_screen *
pipe_etnaviv_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
screen = etna_drm_screen_create(fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(etnaviv, NULL)
#else
STUB_CREATE_SCREEN(etna)
DRM_DRIVER_DESCRIPTOR_STUB(etnaviv)
#endif
#ifdef GALLIUM_TEGRA
#include "tegra/drm/tegra_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_tegra_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -293,15 +345,16 @@ pipe_tegra_create_screen(int fd, const struct pipe_screen_config *config)
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(tegra, NULL)
#else
STUB_CREATE_SCREEN(tegra)
DRM_DRIVER_DESCRIPTOR_STUB(tegra)
#endif
#ifdef GALLIUM_LIMA
#include "lima/drm/lima_drm_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_lima_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
......@@ -309,24 +362,26 @@ pipe_lima_create_screen(int fd, const struct pipe_screen_config *config)
screen = lima_drm_screen_create(fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(lima, NULL)
#else
STUB_CREATE_SCREEN(lima)
DRM_DRIVER_DESCRIPTOR_STUB(lima)
#endif
#ifdef GALLIUM_ZINK
#include "zink/zink_public.h"
struct pipe_screen *
static struct pipe_screen *
pipe_zink_create_screen(int fd, const struct pipe_screen_config *config)
{
struct pipe_screen *screen;
screen = zink_drm_create_screen(fd);
return screen ? debug_screen_wrap(screen) : NULL;
}
DRM_DRIVER_DESCRIPTOR(zink, NULL)
#else
STUB_CREATE_SCREEN(zink)
DRM_DRIVER_DESCRIPTOR_STUB(zink)
#endif
#endif /* DRM_HELPER_H */
......@@ -4,64 +4,23 @@
struct pipe_screen;
struct pipe_screen_config;
extern const char *iris_driconf_xml;
extern const char *radeonsi_driconf_xml;
extern const char *v3d_driconf_xml;
extern const char *virgl_driconf_xml;
struct pipe_screen *
pipe_i915_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_iris_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_nouveau_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_r300_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_r600_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_radeonsi_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_vmwgfx_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_freedreno_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_virgl_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_v3d_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_vc4_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_panfrost_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_kmsro_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_etna_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_imx_drm_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_tegra_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_lima_create_screen(int fd, const struct pipe_screen_config *config);
struct pipe_screen *
pipe_zink_create_screen(int fd, const struct pipe_screen_config *config);
extern const struct drm_driver_descriptor i915_driver_descriptor;
extern const struct drm_driver_descriptor iris_driver_descriptor;
extern const struct drm_driver_descriptor nouveau_driver_descriptor;
extern const struct drm_driver_descriptor r300_driver_descriptor;
extern const struct drm_driver_descriptor r600_driver_descriptor;
extern const struct drm_driver_descriptor radeonsi_driver_descriptor;
extern const struct drm_driver_descriptor vmwgfx_driver_descriptor;
extern const struct drm_driver_descriptor kgsl_driver_descriptor;
extern const struct drm_driver_descriptor msm_driver_descriptor;
extern const struct drm_driver_descriptor virtio_gpu_driver_descriptor;
extern const struct drm_driver_descriptor v3d_driver_descriptor;
extern const struct drm_driver_descriptor vc4_driver_descriptor;
extern const struct drm_driver_descriptor panfrost_driver_descriptor;
extern const struct drm_driver_descriptor etnaviv_driver_descriptor;
extern const struct drm_driver_descriptor tegra_driver_descriptor;
extern const struct drm_driver_descriptor lima_driver_descriptor;
extern const struct drm_driver_descriptor zink_driver_descriptor;
extern const struct drm_driver_descriptor kmsro_driver_descriptor;
#endif /* _DRM_HELPER_PUBLIC_H */
......@@ -36,14 +36,4 @@ struct drm_driver_descriptor
extern const struct drm_driver_descriptor driver_descriptor;
/**
* Instantiate a drm_driver_descriptor struct.
*/
#define DRM_DRIVER_DESCRIPTOR(driver_name_str, driconf, func) \
const struct drm_driver_descriptor driver_descriptor = { \
.driver_name = driver_name_str, \
.driconf_xml = driconf, \
.create_screen = func, \
};
#endif
......@@ -73,7 +73,7 @@ foreach x : pipe_loaders
shared_library(
'pipe_@0@'.format(x[1]),
'pipe_@0@.c'.format(x[1]),
c_args : [pipe_loader_comp_args],
c_args : [pipe_loader_comp_args, '-DPIPE_LOADER_DYNAMIC=1'],
cpp_args : [pipe_loader_comp_args],
gnu_symbol_visibility : 'hidden',