#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",
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);
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;
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) {
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,
}
}
+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);
}
}
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;
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;