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 9e12a02..ed96703 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 84b6c21..1ee27e0 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 12f605e..8e6d184 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);