commit 8990a83

Michael Forney  ·  2023-07-03 20:42:42 +0000 UTC
parent 3fe15e7
drm: Fallback to dumb driver if hardware-specific driver fails
1 files changed,  +14, -14
M drm.c
M drm.c
+14, -14
 1@@ -53,9 +53,6 @@ find_driver(int fd)
 2 	if (fstat(fd, &st) == -1)
 3 		return NULL;
 4 
 5-	if (getenv("WLD_DRM_DUMB"))
 6-		goto dumb;
 7-
 8 	n = snprintf(path, sizeof(path), "/sys/dev/char/%u:%u/device/", major(st.st_rdev), minor(st.st_rdev));
 9 	if (n + 6 >= sizeof(path))
10 		return NULL;
11@@ -64,7 +61,7 @@ find_driver(int fd)
12 	strcpy(path_part, "vendor");
13 	file = fopen(path, "r");
14 	if (!file)
15-		goto dumb;
16+		return NULL;
17 	fgets(id, sizeof id, file);
18 	fclose(file);
19 	vendor_id = strtoul(id, NULL, 0);
20@@ -72,7 +69,7 @@ find_driver(int fd)
21 	strcpy(path_part, "device");
22 	file = fopen(path, "r");
23 	if (!file)
24-		goto dumb;
25+		return NULL;
26 	fgets(id, sizeof id, file);
27 	fclose(file);
28 	device_id = strtoul(id, NULL, 0);
29@@ -83,12 +80,7 @@ find_driver(int fd)
30 			return drivers[index];
31 	}
32 
33-	DEBUG("No DRM driver supports device 0x%x:0x%x\n", vendor_id, device_id);
34-
35 	return NULL;
36-
37-dumb:
38-	return &dumb_drm_driver;
39 }
40 
41 EXPORT
42@@ -96,11 +88,19 @@ struct wld_context *
43 wld_drm_create_context(int fd)
44 {
45 	const struct drm_driver *driver;
46+	struct wld_context *context;
47+
48+	if (!getenv("WLD_DRM_DUMB")) {
49+		driver = find_driver(fd);
50+		if (driver) {
51+			context = driver->create_context(fd);
52+			if (context)
53+				return context;
54+		}
55+	}
56 
57-	if (!(driver = find_driver(fd)))
58-		return NULL;
59-
60-	return driver->create_context(fd);
61+	DEBUG("Falling back to dumb DRM driver\n");
62+	return dumb_drm_driver.create_context(fd);
63 }
64 
65 EXPORT