i915: Fetch the real deviceID for EGL
authorJakob Bornecrantz <jakob@tungstengraphics.com>
Mon, 7 Jul 2008 12:29:11 +0000 (14:29 +0200)
committerJakob Bornecrantz <jakob@tungstengraphics.com>
Mon, 7 Jul 2008 12:29:11 +0000 (14:29 +0200)
src/gallium/winsys/egl_drm/intel/intel_egl.c
src/gallium/winsys/egl_drm/intel/intel_egl.h
src/gallium/winsys/egl_drm/intel/intel_screen.c

index 9e12a024eb0e6aeadb2bcb73d528858bbf93fe80..ed96703e37e8425cbb10d80e5b154bc28ca44d58 100644 (file)
@@ -13,6 +13,7 @@
 #include "eglmode.h"
 #include "eglscreen.h"
 #include "eglsurface.h"
+#include "egllog.h"
 
 #include "intel_egl.h"
 
 
 #include "state_tracker/st_public.h"
 
-struct egl_drm_device* egl_drm_create_device(int drmFD);
+static void
+drm_get_device_id(struct egl_drm_device *device)
+{
+       char path[512];
+       FILE *file;
+
+       /* TODO get the real minor */
+       int minor = 0;
+
+       snprintf(path, sizeof(path), "/sys/class/drm/card%d/device/device", minor);
+       file = fopen(path, "r");
+       if (!file) {
+               _eglLog(_EGL_WARNING, "Could not retrive device ID\n");
+               return;
+       }
 
-struct egl_drm_device*
+       fgets(path, sizeof( path ), file);
+       sscanf(path, "%x", &device->deviceID);
+       fclose(file);
+}
+
+static struct egl_drm_device*
 egl_drm_create_device(int drmFD)
 {
        struct egl_drm_device *device = malloc(sizeof(*device));
        memset(device, 0, sizeof(*device));
        device->drmFD = drmFD;
 
+       device->version = drmGetVersion(device->drmFD);
+
+       drm_get_device_id(device);
+
        if (!intel_create_device(device)) {
                free(device);
                return NULL;
@@ -105,6 +129,7 @@ drm_add_modes_from_connector(_EGLScreen *screen, drmModeConnectorPtr connector)
        }
 }
 
+
 static EGLBoolean
 drm_initialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor)
 {
@@ -183,6 +208,7 @@ drm_terminate(_EGLDriver *drv, EGLDisplay dpy)
        struct drm_driver *drm_drv = (struct drm_driver *)drv;
 
        intel_destroy_device(drm_drv->device);
+       drmFreeVersion(drm_drv->device->version);
 
        drmClose(drm_drv->device->drmFD);
 
index 84b6c212bfdfd79fc5b65e203a7ea843731bca4a..1ee27e0847a1e1d54f94962cd415ed0debdae33c 100644 (file)
@@ -2,10 +2,15 @@
 #ifndef _INTEL_EGL_H_
 #define _INTEL_EGL_H_
 
+#include <xf86drm.h>
+
 struct egl_drm_device
 {
        void *priv;
        int drmFD;
+
+       drmVersionPtr version;
+       int deviceID;
 };
 
 struct egl_drm_context
index 12f605e0bea8dc095876a6de4945d763a5ed4c37..8e6d184440e2c0a9cf1b90b0f8110ca3a072366c 100644 (file)
@@ -53,8 +53,7 @@ intel_create_device(struct egl_drm_device *device)
        device->priv = (void *)intel_screen;
        intel_screen->device = device;
 
-       /** TODO JB: ugly hack */
-       intel_screen->deviceID = PCI_CHIP_I945_GM;
+       intel_screen->deviceID = device->deviceID;
 
        intel_be_init_device(&intel_screen->base, device->drmFD, PCI_CHIP_I945_GM);