From 55002c84ee70b0d2447b05e720cb4d85ba0080b3 Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Thu, 21 Jan 2016 07:58:46 -0600 Subject: pipe: use gallium loader function Based on Rob Clark's work to avoid duplicating gallium driver loading code and statically linking each driver's pipe and winsys libraries. Signed-off-by: Rob Herring --- gralloc_drm_pipe.c | 184 +++++------------------------------------------------ 1 file changed, 17 insertions(+), 167 deletions(-) (limited to 'gralloc_drm_pipe.c') diff --git a/gralloc_drm_pipe.c b/gralloc_drm_pipe.c index bb50857..79b8f05 100644 --- a/gralloc_drm_pipe.c +++ b/gralloc_drm_pipe.c @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -37,12 +38,19 @@ #include "gralloc_drm.h" #include "gralloc_drm_priv.h" +#if defined(__LP64__) +#define DRI_LIBRARY_PATH "/system/lib64/dri" +#else +#define DRI_LIBRARY_PATH "/system/lib/dri" +#endif + struct pipe_manager { struct gralloc_drm_drv_t base; int fd; - char driver[16]; + void *gallium; pthread_mutex_t mutex; + struct pipe_loader_device *dev; struct pipe_screen *screen; struct pipe_context *context; }; @@ -367,176 +375,14 @@ static void pipe_destroy(struct gralloc_drm_drv_t *drv) if (pm->context) pm->context->destroy(pm->context); pm->screen->destroy(pm->screen); + dlclose(pm->gallium); FREE(pm); } -/* for freedreno */ -#include "freedreno/drm/freedreno_drm_public.h" -/* for nouveau */ -#include "nouveau/drm/nouveau_drm_public.h" -/* for r300 */ -#include "radeon/drm/radeon_drm_public.h" -#include "r300/r300_public.h" -/* for r600 */ -#include "r600/r600_public.h" -/* for vmwgfx */ -#include "svga/drm/svga_drm_public.h" -#include "svga/svga_public.h" -/* for debug */ -#include "target-helpers/inline_debug_helper.h" - -static int pipe_init_screen(struct pipe_manager *pm) -{ - struct pipe_screen *screen; - -#ifdef ENABLE_PIPE_FREEDRENO - if (strcmp(pm->driver, "msm")) - screen = fd_drm_screen_create(pm->fd); - else -#endif -#ifdef ENABLE_PIPE_NOUVEAU - if (strcmp(pm->driver, "nouveau") == 0) - screen = nouveau_drm_screen_create(pm->fd); - else -#endif -#ifdef ENABLE_PIPE_R300 - if (strcmp(pm->driver, "r300") == 0) { - struct radeon_winsys *sws = - radeon_drm_winsys_create(pm->fd, r300_screen_create); - - screen = sws ? sws->screen : NULL; - } - else -#endif -#ifdef ENABLE_PIPE_R600 - if (strcmp(pm->driver, "r600") == 0) { - struct radeon_winsys *sws = - radeon_drm_winsys_create(pm->fd, r600_screen_create); - - screen = sws ? sws->screen : NULL; - } - else -#endif -#ifdef ENABLE_PIPE_VMWGFX - if (strcmp(pm->driver, "vmwgfx") == 0) { - struct svga_winsys_screen *sws = - svga_drm_winsys_screen_create(pm->fd); - - screen = sws ? svga_screen_create(sws) : NULL; - } - else -#endif - screen = NULL; - - if (!screen) { - ALOGW("failed to create pipe screen for %s", pm->driver); - return -EINVAL; - } - - pm->screen = debug_screen_wrap(screen); - - return 0; -} - -#include -#include -#include -static int pipe_get_pci_id(struct pipe_manager *pm, - const char *name, int *vendor, int *device) -{ - int err = -EINVAL; - - if (strcmp(name, "i915") == 0) { - struct drm_i915_getparam gp; - - *vendor = 0x8086; - - memset(&gp, 0, sizeof(gp)); - gp.param = I915_PARAM_CHIPSET_ID; - gp.value = device; - err = drmCommandWriteRead(pm->fd, DRM_I915_GETPARAM, &gp, sizeof(gp)); - } - else if (strcmp(name, "radeon") == 0) { - struct drm_radeon_info info; - - *vendor = 0x1002; - - memset(&info, 0, sizeof(info)); - info.request = RADEON_INFO_DEVICE_ID; - info.value = (long) device; - err = drmCommandWriteRead(pm->fd, DRM_RADEON_INFO, &info, sizeof(info)); - } - else if (strcmp(name, "nouveau") == 0) { - *vendor = 0x10de; - *device = 0; - err = 0; - } - else if (strcmp(name, "vmwgfx") == 0) { - *vendor = 0x15ad; - /* assume SVGA II */ - *device = 0x0405; - err = 0; - } - else { - err = -EINVAL; - } - - return err; -} - -#define DRIVER_MAP_GALLIUM_ONLY -#include "pci_ids/pci_id_driver_map.h" -static int pipe_find_driver(struct pipe_manager *pm, const char *name) -{ - int vendor, device; - int err; - const char *driver; - - err = pipe_get_pci_id(pm, name, &vendor, &device); - if (!err) { - int idx; - - /* look up in the driver map */ - for (idx = 0; driver_map[idx].driver; idx++) { - int i; - - if (vendor != driver_map[idx].vendor_id) - continue; - - if (driver_map[idx].num_chips_ids == -1) - break; - - for (i = 0; i < driver_map[idx].num_chips_ids; i++) { - if (driver_map[idx].chip_ids[i] == device) - break; - } - if (i < driver_map[idx].num_chips_ids) - break; - } - - driver = driver_map[idx].driver; - err = (driver) ? 0 : -ENODEV; - } - else { - if (strcmp(name, "vmwgfx") == 0) { - driver = "vmwgfx"; - err = 0; - } - if (strcmp(name, "msm") == 0) { - driver = "msm"; - err = 0; - } - } - - if (!err) - strncpy(pm->driver, driver, sizeof(pm->driver) - 1); - - return err; -} - struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *name) { struct pipe_manager *pm; + struct pipe_screen *(*load_pipe_screen)(struct pipe_loader_device **dev, int fd); pm = CALLOC(1, sizeof(*pm)); if (!pm) { @@ -547,12 +393,16 @@ struct gralloc_drm_drv_t *gralloc_drm_drv_create_for_pipe(int fd, const char *na pm->fd = fd; pthread_mutex_init(&pm->mutex, NULL); - if (pipe_find_driver(pm, name)) { + pm->gallium = dlopen(DRI_LIBRARY_PATH"/gallium_dri.so", RTLD_NOW | RTLD_GLOBAL); + if (!pm->gallium) { FREE(pm); return NULL; } + load_pipe_screen = dlsym(pm->gallium, "load_pipe_screen"); - if (pipe_init_screen(pm)) { + pm->screen = load_pipe_screen(&pm->dev, fd); + if (!pm->screen) { + dlclose(pm->gallium); FREE(pm); return NULL; } -- cgit v1.1