intel: add support for per-instance GPU enumeration
authorChia-I Wu <olv@lunarg.com>
Fri, 20 Feb 2015 19:50:12 +0000 (12:50 -0700)
committerChia-I Wu <olv@lunarg.com>
Thu, 26 Feb 2015 05:49:06 +0000 (13:49 +0800)
Every instance should be indepedenent and have its own list of intel_gpus.

icd/intel/gpu.c
icd/intel/gpu.h
icd/intel/instance.c
icd/intel/instance.h

index 8c22a68..d8db946 100644 (file)
@@ -38,8 +38,6 @@
 #include "wsi_x11.h"
 #include "xglIcd.h"
 
-static struct intel_gpu *intel_gpus;
-
 static const char * const intel_gpu_exts[INTEL_EXT_COUNT] = {
 #ifdef ENABLE_WSI_X11
     [INTEL_EXT_WSI_X11] = "XGL_WSI_X11",
@@ -114,67 +112,7 @@ static const char *gpu_get_name(const struct intel_gpu *gpu)
     return name;
 }
 
-static struct intel_gpu *gpu_create(int gen, int devid,
-                                    const char *primary_node,
-                                    const char *render_node)
-{
-    struct intel_gpu *gpu;
-    size_t primary_len, render_len;
-
-    gpu = icd_alloc(sizeof(*gpu), 0, XGL_SYSTEM_ALLOC_API_OBJECT);
-    if (!gpu)
-        return NULL;
-
-    memset(gpu, 0, sizeof(*gpu));
-    set_loader_magic_value(gpu);
-
-    gpu->devid = devid;
-
-    primary_len = strlen(primary_node);
-    render_len = (render_node) ? strlen(render_node) : 0;
-
-    gpu->primary_node = icd_alloc(primary_len + 1 +
-            ((render_len) ? (render_len + 1) : 0), 0, XGL_SYSTEM_ALLOC_INTERNAL);
-    if (!gpu->primary_node) {
-        icd_free(gpu);
-        return NULL;
-    }
-
-    memcpy(gpu->primary_node, primary_node, primary_len + 1);
-
-    if (render_node) {
-        gpu->render_node = gpu->primary_node + primary_len + 1;
-        memcpy(gpu->render_node, render_node, render_len + 1);
-    }
-
-    gpu->gen_opaque = gen;
-
-    switch (intel_gpu_gen(gpu)) {
-    case INTEL_GEN(7.5):
-        gpu->gt = gen_get_hsw_gt(devid);
-        break;
-    case INTEL_GEN(7):
-        gpu->gt = gen_get_ivb_gt(devid);
-        break;
-    case INTEL_GEN(6):
-        gpu->gt = gen_get_snb_gt(devid);
-        break;
-    }
-
-    /* 150K dwords */
-    gpu->max_batch_buffer_size = sizeof(uint32_t) * 150*1024;
-
-    /* the winsys is prepared for one reloc every two dwords, then minus 2 */
-    gpu->batch_buffer_reloc_count =
-        gpu->max_batch_buffer_size / sizeof(uint32_t) / 2 - 2;
-
-    gpu->primary_fd_internal = -1;
-    gpu->render_fd_internal = -1;
-
-    return gpu;
-}
-
-static void gpu_destroy(struct intel_gpu *gpu)
+void intel_gpu_destroy(struct intel_gpu *gpu)
 {
     intel_gpu_close(gpu);
 
@@ -187,22 +125,6 @@ static void gpu_destroy(struct intel_gpu *gpu)
     icd_free(gpu);
 }
 
-/**
- * Return true if \p gpu is a valid intel_gpu.
- */
-bool intel_gpu_is_valid(const struct intel_gpu *gpu)
-{
-    const struct intel_gpu *iter = intel_gpus;
-
-    while (iter) {
-        if (iter == gpu)
-            return true;
-        iter = iter->next;
-    }
-
-    return false;
-}
-
 static int devid_to_gen(int devid)
 {
     int gen;
@@ -224,10 +146,12 @@ static int devid_to_gen(int devid)
     return gen;
 }
 
-XGL_RESULT intel_gpu_add(int devid, const char *primary_node,
-                         const char *render_node, struct intel_gpu **gpu_ret)
+XGL_RESULT intel_gpu_create(const struct intel_instance *instance, int devid,
+                            const char *primary_node, const char *render_node,
+                            struct intel_gpu **gpu_ret)
 {
     const int gen = devid_to_gen(devid);
+    size_t primary_len, render_len;
     struct intel_gpu *gpu;
 
     if (gen < 0) {
@@ -236,35 +160,59 @@ XGL_RESULT intel_gpu_add(int devid, const char *primary_node,
         return XGL_ERROR_INITIALIZATION_FAILED;
     }
 
-    gpu = gpu_create(gen, devid, primary_node, render_node);
+    gpu = icd_alloc(sizeof(*gpu), 0, XGL_SYSTEM_ALLOC_API_OBJECT);
     if (!gpu)
         return XGL_ERROR_OUT_OF_MEMORY;
 
-    gpu->next = intel_gpus;
-    intel_gpus = gpu;
+    memset(gpu, 0, sizeof(*gpu));
+    set_loader_magic_value(gpu);
 
-    *gpu_ret = gpu;
+    gpu->devid = devid;
 
-    return XGL_SUCCESS;
-}
+    primary_len = strlen(primary_node);
+    render_len = (render_node) ? strlen(render_node) : 0;
 
-void intel_gpu_remove_all(void)
-{
-    struct intel_gpu *gpu = intel_gpus;
+    gpu->primary_node = icd_alloc(primary_len + 1 +
+            ((render_len) ? (render_len + 1) : 0), 0, XGL_SYSTEM_ALLOC_INTERNAL);
+    if (!gpu->primary_node) {
+        icd_free(gpu);
+        return XGL_ERROR_OUT_OF_MEMORY;
+    }
 
-    while (gpu) {
-        struct intel_gpu *next = gpu->next;
+    memcpy(gpu->primary_node, primary_node, primary_len + 1);
 
-        gpu_destroy(gpu);
-        gpu = next;
+    if (render_node) {
+        gpu->render_node = gpu->primary_node + primary_len + 1;
+        memcpy(gpu->render_node, render_node, render_len + 1);
     }
 
-    intel_gpus = NULL;
-}
+    gpu->gen_opaque = gen;
 
-struct intel_gpu *intel_gpu_get_list(void)
-{
-    return intel_gpus;
+    switch (intel_gpu_gen(gpu)) {
+    case INTEL_GEN(7.5):
+        gpu->gt = gen_get_hsw_gt(devid);
+        break;
+    case INTEL_GEN(7):
+        gpu->gt = gen_get_ivb_gt(devid);
+        break;
+    case INTEL_GEN(6):
+        gpu->gt = gen_get_snb_gt(devid);
+        break;
+    }
+
+    /* 150K dwords */
+    gpu->max_batch_buffer_size = sizeof(uint32_t) * 150*1024;
+
+    /* the winsys is prepared for one reloc every two dwords, then minus 2 */
+    gpu->batch_buffer_reloc_count =
+        gpu->max_batch_buffer_size / sizeof(uint32_t) / 2 - 2;
+
+    gpu->primary_fd_internal = -1;
+    gpu->render_fd_internal = -1;
+
+    *gpu_ret = gpu;
+
+    return XGL_SUCCESS;
 }
 
 void intel_gpu_get_props(const struct intel_gpu *gpu,
index d74b0c0..5230afc 100644 (file)
@@ -48,6 +48,7 @@ enum intel_gpu_engine_type {
     INTEL_GPU_ENGINE_COUNT
 };
 
+struct intel_instance;
 struct intel_winsys;
 struct intel_wsi_x11;
 
@@ -98,12 +99,10 @@ static inline int intel_gpu_gen(const struct intel_gpu *gpu)
 #endif
 }
 
-bool intel_gpu_is_valid(const struct intel_gpu *gpu);
-
-XGL_RESULT intel_gpu_add(int devid, const char *primary_node,
-                         const char *render_node, struct intel_gpu **gpu_ret);
-void intel_gpu_remove_all(void);
-struct intel_gpu *intel_gpu_get_list(void);
+XGL_RESULT intel_gpu_create(const struct intel_instance *instance, int devid,
+                            const char *primary_node, const char *render_node,
+                            struct intel_gpu **gpu_ret);
+void intel_gpu_destroy(struct intel_gpu *gpu);
 
 void intel_gpu_get_props(const struct intel_gpu *gpu,
                          XGL_PHYSICAL_GPU_PROPERTIES *props);
index ab19566..9e2c56b 100644 (file)
@@ -78,9 +78,30 @@ static void intel_debug_init(void)
     }
 }
 
+static void intel_instance_add_gpu(struct intel_instance *instance,
+                                   struct intel_gpu *gpu)
+{
+    gpu->next = instance->gpus;
+    instance->gpus = gpu;
+}
+
+static void intel_instance_remove_gpus(struct intel_instance *instance)
+{
+    struct intel_gpu *gpu = instance->gpus;
+
+    while (gpu) {
+        struct intel_gpu *next = gpu->next;
+
+        intel_gpu_destroy(gpu);
+        gpu = next;
+    }
+
+    instance->gpus = NULL;
+}
+
 static void intel_instance_destroy(struct intel_instance *instance)
 {
-    intel_gpu_remove_all();
+    intel_instance_remove_gpus(instance);
     icd_free(instance);
 }
 
@@ -130,16 +151,17 @@ ICD_EXPORT XGL_RESULT XGLAPI xglDestroyInstance(
 }
 
 ICD_EXPORT XGL_RESULT XGLAPI xglEnumerateGpus(
-    XGL_INSTANCE                                instance,
+    XGL_INSTANCE                                instance_,
     uint32_t                                    maxGpus,
     uint32_t*                                   pGpuCount,
     XGL_PHYSICAL_GPU*                           pGpus)
 {
+    struct intel_instance *instance = intel_instance(instance_);
     struct icd_drm_device *devices, *dev;
     XGL_RESULT ret;
     uint32_t count;
 
-    intel_gpu_remove_all();
+    intel_instance_remove_gpus(instance);
 
     if (!maxGpus) {
         *pGpuCount = 0;
@@ -162,8 +184,11 @@ ICD_EXPORT XGL_RESULT XGLAPI xglEnumerateGpus(
         render_node = icd_drm_get_devnode(dev, ICD_DRM_MINOR_RENDER);
 
         devid = (intel_devid_override) ? intel_devid_override : dev->devid;
-        ret = intel_gpu_add(devid, primary_node, render_node, &gpu);
+        ret = intel_gpu_create(instance, devid,
+                primary_node, render_node, &gpu);
         if (ret == XGL_SUCCESS) {
+            intel_instance_add_gpu(instance, gpu);
+
             pGpus[count++] = (XGL_PHYSICAL_GPU) gpu;
             if (count >= maxGpus)
                 break;
index 3971f16..f6f447d 100644 (file)
 
 #include "intel.h"
 
+struct intel_gpu;
+
 struct intel_instance {
     /* the loader expects a "void *" at the beginning */
     void *loader_data;
+
+    struct intel_gpu *gpus;
 };
 
 static inline struct intel_instance *intel_instance(XGL_INSTANCE instance)