gallium: Update the drm_api.
authorThomas Hellstrom <thellstrom-at-vmware-dot-com>
Tue, 28 Apr 2009 09:23:11 +0000 (11:23 +0200)
committerThomas Hellstrom <thellstrom-at-vmware-dot-com>
Tue, 28 Apr 2009 09:25:56 +0000 (11:25 +0200)
Make it possible to pass state-tracker-specific data to the
init_screen function, and even open the door for device-specific
state-tracker screen initialization.

Signed-off-by: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
src/gallium/include/state_tracker/drm_api.h
src/gallium/state_trackers/dri2/dri_screen.c
src/gallium/state_trackers/dri2/dri_screen.h
src/gallium/state_trackers/egl/egl_tracker.c
src/gallium/state_trackers/xorg/xorg_driver.c
src/gallium/winsys/drm/intel/gem/intel_be_api.h
src/gallium/winsys/drm/intel/gem/intel_be_device.c
src/gallium/winsys/drm/nouveau/dri/nouveau_screen.c
src/gallium/winsys/drm/nouveau/drm/nouveau_drm_api.c
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/drm/radeon/core/radeon_drm.h

index 435435da29ccbfb0bbe710aa8e1572ce66cf82de..5790b2f6c7e1c845d9925a4e5ec0328c57d3b1d1 100644 (file)
@@ -10,13 +10,30 @@ struct pipe_buffer;
 struct pipe_context;
 struct pipe_texture;
 
+enum drm_create_screen_mode {
+       DRM_CREATE_NORMAL = 0,
+       DRM_CREATE_DRI1,
+       DRM_CREATE_DRIVER = 1024,
+       DRM_CREATE_MAX
+};
+
+/**
+ * Modes other than DRM_CREATE_NORMAL derive from this struct.
+ */
+/*@{*/
+struct drm_create_screen_arg {
+       enum drm_create_screen_mode mode;
+};
+/*@}*/
+
 struct drm_api
 {
        /**
         * Special buffer functions
         */
        /*@{*/
-       struct pipe_screen*  (*create_screen)(int drmFB, int pciID);
+       struct pipe_screen*  (*create_screen)(int drm_fd,
+                                             struct drm_create_screen_arg *arg);
        struct pipe_context* (*create_context)(struct pipe_screen *screen);
        /*@}*/
 
index ab5878a4bce88ea2e7799fff4b32a28d1a27e287..ab33003f5165467bfabf07cc6856e2448fa43fb5 100644 (file)
@@ -67,37 +67,6 @@ static const __DRIextension *dri_screen_extensions[] = {
     NULL
 };
 
-
-static void
-dri_get_drm_minor(struct dri_screen *screen)
-{
-   /* TODO get the real minor */
-   screen->minor = 0;
-}
-
-
-static void
-dri_get_device_id(struct dri_screen *screen)
-{
-   char path[512];
-   FILE *file;
-
-   /*
-    * There must be a better way to get the deviceID.
-    * XXX this only works on Linux.
-    */
-   snprintf(path, sizeof(path), "/sys/class/drm/card%d/device/device", screen->minor);
-   file = fopen(path, "r");
-   if (!file) {
-      return;
-   }
-
-   fgets(path, sizeof(path), file);
-   sscanf(path, "%x", &screen->deviceID);
-   fclose(file);
-}
-
-
 static const __DRIconfig **
 dri_fill_in_modes(__DRIscreenPrivate *psp,
                   unsigned pixel_bits, unsigned depth_bits,
@@ -212,13 +181,11 @@ dri_init_screen2(__DRIscreenPrivate *sPriv)
 
    screen->sPriv = sPriv;
    screen->fd = sPriv->fd;
-   dri_get_drm_minor(screen);
-   dri_get_device_id(screen);
    sPriv->private = (void *) screen;
    sPriv->extensions = dri_screen_extensions;
 
 
-   screen->pipe_screen = drm_api_hooks.create_screen(screen->fd, screen->deviceID);
+   screen->pipe_screen = drm_api_hooks.create_screen(screen->fd, NULL);
    if (!screen->pipe_screen) {
       debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__);
       goto fail;
index fe2676d0be3c063ce01e9aa2a931e27f4fe8d8ee..3751ec61211338439853b51b3b83bda1d2a2e4eb 100644 (file)
@@ -54,9 +54,7 @@ struct dri_screen
    struct dri_context *dummyContext;
 
    /* drm */
-   int deviceID;
    int fd;
-   int minor;
 
    /* gallium */
    struct pipe_winsys *pipe_winsys;
index abdf84544f3f54f8b8238b920a5718b0705f273a..8e620084617af56b671d8ad2550bf7e1ba6bff61 100644 (file)
@@ -146,7 +146,7 @@ drm_initialize(_EGLDriver *drv, EGLDisplay dpy, EGLint *major, EGLint *minor)
        dev->drmFD = fd;
        drm_get_device_id(dev);
 
-       dev->screen = drm_api_hooks.create_screen(dev->drmFD, dev->deviceID);
+       dev->screen = drm_api_hooks.create_screen(dev->drmFD, NULL);
        if (!dev->screen)
                goto err_screen;
        dev->winsys = dev->screen->winsys;
index 8a2711e70cd7b1bddb0867f33f34579cd6ad945e..45e831f0c289ce8fb52780f068b6899433bf49be 100644 (file)
@@ -476,7 +476,7 @@ ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     }
 
     if (!ms->screen) {
-       ms->screen = drm_api_hooks.create_screen(ms->fd, ms->PciInfo->device_id);
+       ms->screen = drm_api_hooks.create_screen(ms->fd, NULL);
 
        if (!ms->screen) {
            FatalError("Could not init pipe_screen\n");
index 73e458d4ba9c963055055dd49d4528f8f4c0104e..1c622f3b97867d17d4d31c82e71dbaeb2da4043e 100644 (file)
@@ -8,7 +8,8 @@
 
 #include "intel_be_device.h"
 
-struct pipe_screen *intel_be_create_screen(int drmFD, int pciID);
+struct pipe_screen *intel_be_create_screen(int drmFD,
+                                          struct drm_create_screen_arg *arg);
 struct pipe_context *intel_be_create_context(struct pipe_screen *screen);
 
 #endif
index c866c2a2f1e8507f8d0a167099b7314eec26315d..907ac86637f2138713dec5ead110608305089e10 100644 (file)
@@ -14,6 +14,7 @@
 #include "softpipe/sp_winsys.h"
 
 #include "intel_be_api.h"
+#include <stdio.h>
 
 /*
  * Buffer
@@ -290,11 +291,42 @@ intel_be_init_device(struct intel_be_device *dev, int fd, unsigned id)
        return true;
 }
 
+static void
+intel_be_get_device_id(unsigned int *device_id)
+{
+   char path[512];
+   FILE *file;
+
+   /*
+    * FIXME: Fix this up to use a drm ioctl or whatever.
+    */
+
+   snprintf(path, sizeof(path), "/sys/class/drm/card0/device/device");
+   file = fopen(path, "r");
+   if (!file) {
+      return;
+   }
+
+   fgets(path, sizeof(path), file);
+   sscanf(path, "%x", device_id);
+   fclose(file);
+}
+
 struct pipe_screen *
-intel_be_create_screen(int drmFD, int deviceID)
+intel_be_create_screen(int drmFD, struct drm_create_screen_arg *arg)
 {
        struct intel_be_device *dev;
        struct pipe_screen *screen;
+       unsigned int deviceID;
+
+       if (arg != NULL) {
+               switch(arg->mode) {
+               case DRM_CREATE_NORMAL:
+                       break;
+               default:
+                       return NULL;
+               }
+       }
 
        /* Allocate the private area */
        dev = malloc(sizeof(*dev));
@@ -302,6 +334,7 @@ intel_be_create_screen(int drmFD, int deviceID)
                return NULL;
        memset(dev, 0, sizeof(*dev));
 
+       intel_be_get_device_id(&deviceID);
        intel_be_init_device(dev, drmFD, deviceID);
 
        if (dev->softpipe) {
index 0b45b1ff1f69cf15a5b0aa143042954c3a15e73b..4e9b76a9090d79331e43beeee726db1206a2d3fa 100644 (file)
@@ -267,7 +267,7 @@ nouveau_screen_create(__DRIscreenPrivate *psp)
 
        nouveau_device_open_existing(&nv_screen->device, 0, psp->fd, 0);
 
-       nv_screen->pscreen = drm_api_hooks.create_screen(psp->fd, 0);
+       nv_screen->pscreen = drm_api_hooks.create_screen(psp->fd, NULL);
        if (!nv_screen->pscreen) {
                FREE(nv_screen);
                return NULL;
index c0127e803f14f3ba9356e06ce7cde8a787ea4d8c..a558fda1401fa2b70400ed4b08917ff80b1e6296 100644 (file)
@@ -8,7 +8,7 @@
 #include "nouveau_bo.h"
 
 static struct pipe_screen *
-nouveau_drm_create_screen(int fd, int pciid)
+nouveau_drm_create_screen(int fd, struct drm_create_screen_arg *arg)
 {
        struct pipe_winsys *ws;
        struct nouveau_winsys *nvws;
index 3446654e287cf79c9eef486a70d7063b0fea4281..1f89d1b1d10f170cf4a1ad511c59f4c089faf857 100644 (file)
@@ -31,7 +31,8 @@
 #include "radeon_drm.h"
 
 /* Create a pipe_screen. */
-struct pipe_screen* radeon_create_screen(int drmFB, int pciID)
+struct pipe_screen* radeon_create_screen(int drmFB,
+                                        struct drm_create_screen_arg *arg )
 {
     struct radeon_winsys* winsys = radeon_pipe_winsys(drmFB);
 
index ca2d98ed1a16da521129d2e6126b4d81c791a251..049f9984dbac65cd5114d1309a499604b246b79f 100644 (file)
@@ -40,7 +40,8 @@
 #include "radeon_r300.h"
 #include "radeon_winsys_softpipe.h"
 
-struct pipe_screen* radeon_create_screen(int drmFB, int pciID);
+struct pipe_screen* radeon_create_screen(int drmFB,
+                                        struct drm_create_screen_arg *arg);
 
 struct pipe_context* radeon_create_context(struct pipe_screen* screen);