diff options
author | Rob Herring <robh@kernel.org> | 2016-01-21 07:58:46 -0600 |
---|---|---|
committer | Chih-Wei Huang <cwhuang@linux.org.tw> | 2016-03-17 10:54:50 +0800 |
commit | 55002c84ee70b0d2447b05e720cb4d85ba0080b3 (patch) | |
tree | 85bca308037d5b4ba3c90c3fa7addb0b0b0294a8 | |
parent | 564c47171be849fe926986b03aedefaa0ef0da4e (diff) | |
download | external_drm_gralloc-55002c84ee70b0d2447b05e720cb4d85ba0080b3.zip external_drm_gralloc-55002c84ee70b0d2447b05e720cb4d85ba0080b3.tar.gz external_drm_gralloc-55002c84ee70b0d2447b05e720cb4d85ba0080b3.tar.bz2 |
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 <robh@kernel.org>
-rw-r--r-- | Android.mk | 28 | ||||
-rw-r--r-- | gralloc_drm_pipe.c | 184 | ||||
-rw-r--r-- | pci_ids/pci_id_driver_map.h | 91 |
3 files changed, 23 insertions, 280 deletions
@@ -27,15 +27,15 @@ freedreno_drivers := freedreno intel_drivers := i915 i965 i915g ilo radeon_drivers := r300g r600g radeonsi nouveau_drivers := nouveau -vmwgfx_drivers := vmwgfx +pipe_drivers := freedreno virgl vmwgfx valid_drivers := \ prebuilt \ + $(pipe_drivers) \ $(freedreno_drivers) \ $(intel_drivers) \ $(radeon_drivers) \ - $(nouveau_drivers) \ - $(vmwgfx_drivers) + $(nouveau_drivers) # warn about invalid drivers invalid_drivers := $(filter-out $(valid_drivers), $(DRM_GPU_DRIVERS)) @@ -45,12 +45,6 @@ $(warning invalid GPU drivers: $(invalid_drivers)) DRM_GPU_DRIVERS := $(filter-out $(invalid_drivers), $(DRM_GPU_DRIVERS)) endif -ifneq ($(filter $(vmwgfx_drivers), $(DRM_GPU_DRIVERS)),) -DRM_USES_PIPE := true -else -DRM_USES_PIPE := false -endif - ifneq ($(strip $(DRM_GPU_DRIVERS)),) LOCAL_PATH := $(call my-dir) @@ -122,32 +116,22 @@ LOCAL_CFLAGS += -DENABLE_NOUVEAU LOCAL_SHARED_LIBRARIES += libdrm_nouveau endif -ifeq ($(strip $(DRM_USES_PIPE)),true) +ifneq ($(filter $(pipe_drivers), $(DRM_GPU_DRIVERS)),) LOCAL_SRC_FILES += gralloc_drm_pipe.c LOCAL_CFLAGS += -DENABLE_PIPE LOCAL_C_INCLUDES += \ external/mesa/include \ external/mesa/src \ external/mesa/src/gallium/include \ - external/mesa/src/gallium/winsys \ - external/mesa/src/gallium/drivers \ external/mesa/src/gallium/auxiliary -ifneq ($(filter vmwgfx, $(DRM_GPU_DRIVERS)),) -LOCAL_CFLAGS += -DENABLE_PIPE_VMWGFX -LOCAL_STATIC_LIBRARIES += \ - libmesa_pipe_svga \ - libmesa_winsys_svga -LOCAL_C_INCLUDES += \ - external/mesa/src/gallium/drivers/svga/include -endif - LOCAL_STATIC_LIBRARIES += \ libmesa_gallium \ libmesa_util \ LOCAL_SHARED_LIBRARIES += libdl -endif # DRM_USES_PIPE +endif # pipe_drivers + include $(BUILD_SHARED_LIBRARY) 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 <cutils/log.h> #include <errno.h> +#include <dlfcn.h> #include <svga_types.h> #include <svga3d_types.h> @@ -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 <xf86drm.h> -#include <i915_drm.h> -#include <radeon_drm.h> -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; } diff --git a/pci_ids/pci_id_driver_map.h b/pci_ids/pci_id_driver_map.h deleted file mode 100644 index b89414a..0000000 --- a/pci_ids/pci_id_driver_map.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef _PCI_ID_DRIVER_MAP_H_ -#define _PCI_ID_DRIVER_MAP_H_ - -#include <stddef.h> - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) -#endif - -#if !defined(DRIVER_MAP_DRI2_ONLY) && !defined(DRIVER_MAP_GALLIUM_ONLY) -static const int i810_chip_ids[] = { -#define CHIPSET(chip, desc, misc) chip, -#include "pci_ids/i810_pci_ids.h" -#undef CHIPSET -}; -#endif - -static const int i915_chip_ids[] = { -#define CHIPSET(chip, desc, misc) chip, -#include "pci_ids/i915_pci_ids.h" -#undef CHIPSET -}; - -static const int i965_chip_ids[] = { -#define CHIPSET(chip, desc, misc) chip, -#include "pci_ids/i965_pci_ids.h" -#undef CHIPSET -}; - -#ifndef DRIVER_MAP_GALLIUM_ONLY -static const int r100_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/radeon_pci_ids.h" -#undef CHIPSET -}; - -static const int r200_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/r200_pci_ids.h" -#undef CHIPSET -}; -#endif - -static const int r300_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/r300_pci_ids.h" -#undef CHIPSET -}; - -static const int r600_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/r600_pci_ids.h" -#undef CHIPSET -}; - -static const int radeonsi_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/radeonsi_pci_ids.h" -#undef CHIPSET -}; - -static const int vmwgfx_chip_ids[] = { -#define CHIPSET(chip, name, family) chip, -#include "pci_ids/vmwgfx_pci_ids.h" -#undef CHIPSET -}; - -static const struct { - int vendor_id; - const char *driver; - const int *chip_ids; - int num_chips_ids; -} driver_map[] = { -#if !defined(DRIVER_MAP_DRI2_ONLY) && !defined(DRIVER_MAP_GALLIUM_ONLY) - { 0x8086, "i810", i810_chip_ids, ARRAY_SIZE(i810_chip_ids) }, -#endif - { 0x8086, "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) }, - { 0x8086, "i965", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) }, -#ifndef DRIVER_MAP_GALLIUM_ONLY - { 0x1002, "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) }, - { 0x1002, "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) }, -#endif - { 0x1002, "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) }, - { 0x1002, "r600", r600_chip_ids, ARRAY_SIZE(r600_chip_ids) }, - { 0x1002, "radeonsi", radeonsi_chip_ids, ARRAY_SIZE(radeonsi_chip_ids) }, - { 0x10de, "nouveau", NULL, -1 }, - { 0x15ad, "vmwgfx", vmwgfx_chip_ids, ARRAY_SIZE(vmwgfx_chip_ids) }, - { 0x0000, NULL, NULL, 0 }, -}; - -#endif /* _PCI_ID_DRIVER_MAP_H_ */ |