aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Velikov <[email protected]>2019-02-19 14:08:07 +0000
committerEmil Velikov <[email protected]>2019-02-28 12:02:38 +0000
commit218c7b5acaa053482d368afbce4612232731b3a4 (patch)
treeefccc2f4bf55e3d36a0f0e62ec355829cf45e174
parent893421f3159ac6d82bb56b3feccf79dd71eb250e (diff)
egl/sl: use drmDevice API to enumerate available devices
This provides for a more comprehensive iteration and slightly more straight-forward codebase. v2: - s/dpy/disp/ - keep original 64 devices (Eric) Signed-off-by: Emil Velikov <[email protected]> Reviewed-by: Eric Engestrom <[email protected]> Reviewed-by: Mathias Fröhlich <[email protected]> Reviewed-by: Gurchetan Singh <[email protected]>
-rw-r--r--src/egl/drivers/dri2/platform_surfaceless.c73
1 files changed, 37 insertions, 36 deletions
diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c
index 42bd17e8341..ccdc370d059 100644
--- a/src/egl/drivers/dri2/platform_surfaceless.c
+++ b/src/egl/drivers/dri2/platform_surfaceless.c
@@ -274,55 +274,56 @@ static const __DRIextension *swrast_loader_extensions[] = {
static bool
surfaceless_probe_device(_EGLDisplay *disp, bool swrast)
{
+#define MAX_DRM_DEVICES 64
struct dri2_egl_display *dri2_dpy = disp->DriverData;
- const int limit = 64;
- const int base = 128;
- int fd;
- int i;
-
- /* Attempt to find DRM device. */
- for (i = 0; i < limit; ++i) {
- char *card_path;
- if (asprintf(&card_path, DRM_RENDER_DEV_NAME, DRM_DIR_NAME, base + i) < 0)
+ drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
+ int i, num_devices;
+
+ num_devices = drmGetDevices2(0, devices, ARRAY_SIZE(devices));
+ if (num_devices < 0)
+ return false;
+
+ for (i = 0; i < num_devices; ++i) {
+ device = devices[i];
+
+ if (!(device->available_nodes & (1 << DRM_NODE_RENDER)))
continue;
- fd = loader_open_device(card_path);
- free(card_path);
- if (fd < 0)
+ dri2_dpy->fd = loader_open_device(device->nodes[DRM_NODE_RENDER]);
+ if (dri2_dpy->fd < 0)
continue;
- if (swrast) {
- dri2_dpy->driver_name = strdup("kms_swrast");
- dri2_dpy->loader_extensions = swrast_loader_extensions;
- } else {
- dri2_dpy->driver_name = loader_get_driver_for_fd(fd);
- dri2_dpy->loader_extensions = image_loader_extensions;
- }
- if (!dri2_dpy->driver_name) {
- close(fd);
+ disp->Device = _eglAddDevice(dri2_dpy->fd, swrast);
+ if (!disp->Device) {
+ close(dri2_dpy->fd);
+ dri2_dpy->fd = -1;
continue;
}
- dri2_dpy->fd = fd;
- if (dri2_load_driver_dri3(disp)) {
- _EGLDevice *dev = _eglAddDevice(dri2_dpy->fd, swrast);
- if (!dev) {
- dlclose(dri2_dpy->driver);
- _eglLog(_EGL_WARNING, "DRI2: failed to find EGLDevice");
- continue;
- }
- disp->Device = dev;
- return true;
- }
+ if (swrast)
+ dri2_dpy->driver_name = strdup("kms_swrast");
+ else
+ dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd);
+
+ if (dri2_dpy->driver_name && dri2_load_driver_dri3(disp))
+ break;
- close(fd);
- dri2_dpy->fd = -1;
free(dri2_dpy->driver_name);
dri2_dpy->driver_name = NULL;
- dri2_dpy->loader_extensions = NULL;
+ close(dri2_dpy->fd);
+ dri2_dpy->fd = -1;
}
+ drmFreeDevices(devices, num_devices);
+
+ if (i == num_devices)
+ return false;
+
+ if (swrast)
+ dri2_dpy->loader_extensions = swrast_loader_extensions;
+ else
+ dri2_dpy->loader_extensions = image_loader_extensions;
- return false;
+ return true;
}
static bool