[Mesa-dev] [PATCH 07/10] egl_dri2: use loader util lib

Emil Velikov emil.l.velikov at gmail.com
Sat Jan 11 08:54:48 PST 2014


Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/egl/drivers/dri2/Android.mk         |   4 +-
 src/egl/drivers/dri2/Makefile.am        |   4 +-
 src/egl/drivers/dri2/common.c           | 144 --------------------------------
 src/egl/drivers/dri2/egl_dri2.h         |   5 --
 src/egl/drivers/dri2/platform_android.c | 107 +-----------------------
 src/egl/drivers/dri2/platform_drm.c     |   5 +-
 src/egl/drivers/dri2/platform_wayland.c |   5 +-
 7 files changed, 15 insertions(+), 259 deletions(-)
 delete mode 100644 src/egl/drivers/dri2/common.c

diff --git a/src/egl/drivers/dri2/Android.mk b/src/egl/drivers/dri2/Android.mk
index 4af8581..e46c8a9 100644
--- a/src/egl/drivers/dri2/Android.mk
+++ b/src/egl/drivers/dri2/Android.mk
@@ -40,9 +40,7 @@ LOCAL_C_INCLUDES := \
 	$(MESA_TOP)/src/mapi \
 	$(MESA_TOP)/src/egl/main \
 	$(MESA_TOP)/src/loader \
-	$(DRM_GRALLOC_TOP) \
-	$(DRM_TOP) \
-	$(DRM_TOP)/include/drm
+	$(DRM_GRALLOC_TOP)
 
 LOCAL_MODULE := libmesa_egl_dri2
 
diff --git a/src/egl/drivers/dri2/Makefile.am b/src/egl/drivers/dri2/Makefile.am
index 7e8ed78..6a9ae50 100644
--- a/src/egl/drivers/dri2/Makefile.am
+++ b/src/egl/drivers/dri2/Makefile.am
@@ -38,10 +38,10 @@ AM_CFLAGS = \
 noinst_LTLIBRARIES = libegl_dri2.la
 
 libegl_dri2_la_SOURCES = \
-	egl_dri2.c \
-	common.c
+	egl_dri2.c
 
 libegl_dri2_la_LIBADD = \
+	$(top_builddir)/src/loader/libloader.la \
 	$(EGL_LIB_DEPS)
 
 if HAVE_SHARED_GLAPI
diff --git a/src/egl/drivers/dri2/common.c b/src/egl/drivers/dri2/common.c
deleted file mode 100644
index a889484..0000000
--- a/src/egl/drivers/dri2/common.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright © 2011 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Authors:
- *    Kristian Høgsberg <krh at bitplanet.net>
- *    Benjamin Franzke <benjaminfranzke at googlemail.com>
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "egl_dri2.h"
-
-#ifdef HAVE_LIBUDEV
-
-#define DRIVER_MAP_DRI2_ONLY
-#include "pci_ids/pci_id_driver_map.h"
-
-#include <libudev.h>
-
-static struct udev_device *
-dri2_udev_device_new_from_fd(struct udev *udev, int fd)
-{
-   struct udev_device *device;
-   struct stat buf;
-
-   if (fstat(fd, &buf) < 0) {
-      _eglLog(_EGL_WARNING, "EGL-DRI2: failed to stat fd %d", fd);
-      return NULL;
-   }
-
-   device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
-   if (device == NULL) {
-      _eglLog(_EGL_WARNING,
-              "EGL-DRI2: could not create udev device for fd %d", fd);
-      return NULL;
-   }
-
-   return device;
-}
-
-char *
-dri2_get_device_name_for_fd(int fd)
-{
-   struct udev *udev;
-   struct udev_device *device;
-   const char *const_device_name;
-   char *device_name = NULL;
-
-   udev = udev_new();
-   device = dri2_udev_device_new_from_fd(udev, fd);
-   if (device == NULL)
-      return NULL;
-
-   const_device_name = udev_device_get_devnode(device);
-   if (!const_device_name)
-      goto out;
-   device_name = strdup(const_device_name);
-
-out:
-   udev_device_unref(device);
-   udev_unref(udev);
-
-   return device_name;
-}
-
-char *
-dri2_get_driver_for_fd(int fd)
-{
-   struct udev *udev;
-   struct udev_device *device, *parent;
-   const char *pci_id;
-   char *driver = NULL;
-   int vendor_id, chip_id, i, j;
-
-   udev = udev_new();
-   device = dri2_udev_device_new_from_fd(udev, fd);
-   if (device == NULL)
-      return NULL;
-
-   parent = udev_device_get_parent(device);
-   if (parent == NULL) {
-      _eglLog(_EGL_WARNING, "DRI2: could not get parent device");
-      goto out;
-   }
-
-   pci_id = udev_device_get_property_value(parent, "PCI_ID");
-   if (pci_id == NULL ||
-       sscanf(pci_id, "%x:%x", &vendor_id, &chip_id) != 2) {
-      _eglLog(_EGL_WARNING, "EGL-DRI2: malformed or no PCI ID");
-      goto out;
-   }
-
-   for (i = 0; driver_map[i].driver; i++) {
-      if (vendor_id != driver_map[i].vendor_id)
-         continue;
-      if (driver_map[i].num_chips_ids == -1) {
-         driver = strdup(driver_map[i].driver);
-         _eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s",
-                 fd, vendor_id, chip_id, driver);
-         goto out;
-      }
-
-      for (j = 0; j < driver_map[i].num_chips_ids; j++)
-         if (driver_map[i].chip_ids[j] == chip_id) {
-            driver = strdup(driver_map[i].driver);
-            _eglLog(_EGL_DEBUG, "pci id for %d: %04x:%04x, driver %s",
-                    fd, vendor_id, chip_id, driver);
-            goto out;
-         }
-   }
-
-out:
-   udev_device_unref(device);
-   udev_unref(udev);
-
-   return driver;
-}
-
-#endif /* HAVE_LIBUDEV */
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index d29dd98..dfc5927 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -271,9 +271,4 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp);
 EGLBoolean
 dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *disp);
 
-char *
-dri2_get_driver_for_fd(int fd);
-char *
-dri2_get_device_name_for_fd(int fd);
-
 #endif /* EGL_DRI2_INCLUDED */
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 2c20de7..4a201c8 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -34,11 +34,7 @@
 #include <sync/sync.h>
 #endif
 
-/* for droid_get_pci_id */
-#include <xf86drm.h>
-#include <i915_drm.h>
-#include <radeon_drm.h>
-
+#include "loader.h"
 #include "egl_dri2.h"
 #include "gralloc_drm.h"
 
@@ -602,103 +598,6 @@ droid_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *dpy)
    return (count != 0);
 }
 
-static EGLBoolean
-droid_get_pci_id(int fd, int *vendor_id, int *chip_id)
-{
-   drmVersionPtr version;
-
-   *chip_id = -1;
-
-   version = drmGetVersion(fd);
-   if (!version) {
-      _eglLog(_EGL_WARNING, "invalid drm fd");
-      return EGL_FALSE;
-   }
-   if (!version->name) {
-      _eglLog(_EGL_WARNING, "unable to determine the driver name");
-      drmFreeVersion(version);
-      return EGL_FALSE;
-   }
-
-   if (strcmp(version->name, "i915") == 0) {
-      struct drm_i915_getparam gp;
-      int ret;
-
-      *vendor_id = 0x8086;
-
-      memset(&gp, 0, sizeof(gp));
-      gp.param = I915_PARAM_CHIPSET_ID;
-      gp.value = chip_id;
-      ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
-      if (ret) {
-         _eglLog(_EGL_WARNING, "failed to get param for i915");
-	 *chip_id = -1;
-      }
-   }
-   else if (strcmp(version->name, "radeon") == 0) {
-      struct drm_radeon_info info;
-      int ret;
-
-      *vendor_id = 0x1002;
-
-      memset(&info, 0, sizeof(info));
-      info.request = RADEON_INFO_DEVICE_ID;
-      info.value = (unsigned long) chip_id;
-      ret = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
-      if (ret) {
-         _eglLog(_EGL_WARNING, "failed to get info for radeon");
-	 *chip_id = -1;
-      }
-   }
-   else if (strcmp(version->name, "nouveau") == 0) {
-      *vendor_id = 0x10de;
-      /* not used */
-      *chip_id = 0;
-   }
-   else if (strcmp(version->name, "vmwgfx") == 0) {
-      *vendor_id = 0x15ad;
-      /* assume SVGA II */
-      *chip_id = 0x0405;
-   }
-
-   drmFreeVersion(version);
-
-   return (*chip_id >= 0);
-}
-
-#define DRIVER_MAP_DRI2_ONLY
-#include "pci_ids/pci_id_driver_map.h"
-static const char *
-droid_get_driver_name(int fd)
-{
-   int vendor_id = -1, chip_id = -1;
-   int idx, i;
-   char *name;
-
-   if (!droid_get_pci_id(fd, &vendor_id, &chip_id))
-      return NULL;
-
-   for (idx = 0; driver_map[idx].driver; idx++) {
-      if (vendor_id != 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] == chip_id)
-            break;
-      }
-      if (i < driver_map[idx].num_chips_ids)
-	      break;
-   }
-
-   _eglLog(_EGL_INFO, "pci id for fd %d: %04x:%04x, driver %s",
-         fd, vendor_id, chip_id, driver_map[idx].driver);
-
-   return driver_map[idx].driver;
-}
-
 static int
 droid_open_device(void)
 {
@@ -761,6 +660,8 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
 
    _eglSetLogProc(droid_log);
 
+   loader_set_logger(_eglLog);
+
    dri2_dpy = calloc(1, sizeof(*dri2_dpy));
    if (!dri2_dpy)
       return _eglError(EGL_BAD_ALLOC, "eglInitialize");
@@ -773,7 +674,7 @@ dri2_initialize_android(_EGLDriver *drv, _EGLDisplay *dpy)
       goto cleanup_display;
    }
 
-   dri2_dpy->driver_name = (char *) droid_get_driver_name(dri2_dpy->fd);
+   dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);
    if (dri2_dpy->driver_name == NULL) {
       err = "DRI2: failed to get driver name";
       goto cleanup_device;
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 181b29d..a2b387d 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -36,6 +36,7 @@
 #include <unistd.h>
 
 #include "egl_dri2.h"
+#include "loader.h"
 
 static struct gbm_bo *
 lock_front_buffer(struct gbm_surface *_surf)
@@ -447,6 +448,8 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
    int fd = -1;
    int i;
 
+   loader_set_logger(_eglLog);
+
    dri2_dpy = calloc(1, sizeof *dri2_dpy);
    if (!dri2_dpy)
       return _eglError(EGL_BAD_ALLOC, "eglInitialize");
@@ -482,7 +485,7 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
    }
 
    dri2_dpy->fd = fd;
-   dri2_dpy->device_name = dri2_get_device_name_for_fd(dri2_dpy->fd);
+   dri2_dpy->device_name = loader_get_device_name_for_fd(dri2_dpy->fd);
    dri2_dpy->driver_name = dri2_dpy->gbm_dri->base.driver_name;
 
    dri2_dpy->dri_screen = dri2_dpy->gbm_dri->screen;
diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c
index 5c8440d..50750a9 100644
--- a/src/egl/drivers/dri2/platform_wayland.c
+++ b/src/egl/drivers/dri2/platform_wayland.c
@@ -36,6 +36,7 @@
 #include <xf86drm.h>
 
 #include "egl_dri2.h"
+#include "loader.h"
 
 #include <wayland-client.h>
 #include "wayland-drm-client-protocol.h"
@@ -962,6 +963,8 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
    static const unsigned int rgb_masks[4] = { 0xff0000, 0xff00, 0xff, 0 };
    static const unsigned int rgb565_masks[4] = { 0xf800, 0x07e0, 0x001f, 0 };
 
+   loader_set_logger(_eglLog);
+
    drv->API.CreateWindowSurface = dri2_create_window_surface;
    drv->API.DestroySurface = dri2_destroy_surface;
    drv->API.SwapBuffers = dri2_swap_buffers;
@@ -1006,7 +1009,7 @@ dri2_initialize_wayland(_EGLDriver *drv, _EGLDisplay *disp)
    if (roundtrip(dri2_dpy) < 0 || !dri2_dpy->authenticated)
       goto cleanup_fd;
 
-   dri2_dpy->driver_name = dri2_get_driver_for_fd(dri2_dpy->fd);
+   dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd, 0);
    if (dri2_dpy->driver_name == NULL) {
       _eglError(EGL_BAD_ALLOC, "DRI2: failed to get driver name");
       goto cleanup_fd;
-- 
1.8.5.1



More information about the mesa-dev mailing list