[PATCH igt 1/2] lib: Attempt to load the module for a missing device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If we asked to open a particular chipset and we find no matching device,
try again after attempting to load its module. Previously we only did
this for vgem, which is not automatically probed during boot, but if we
want to leave the module unloaded we have to try harder when we need the
device.

Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx>
---
 lib/drmtest.c | 68 +++++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 50 insertions(+), 18 deletions(-)

diff --git a/lib/drmtest.c b/lib/drmtest.c
index e6bdbc35..3a2a6343 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -235,20 +235,14 @@ static int modprobe(const char *driver)
 	return igt_kmod_load(driver, "");
 }
 
-/**
- * __drm_open_driver:
- * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
- *
- * Open the first DRM device we can find, searching up to 16 device nodes
- *
- * Returns:
- * An open DRM fd or -1 on error
- */
-int __drm_open_driver(int chipset)
+static void modprobe_i915(const char *name)
 {
-	if (chipset & DRIVER_VGEM)
-		modprobe("vgem");
+	/* When loading i915, we also want to load snd-hda et al */
+	igt_i915_driver_load(NULL);
+}
 
+static int __open_device(unsigned int chipset)
+{
 	for (int i = 0; i < 16; i++) {
 		char name[80];
 		int fd;
@@ -262,16 +256,13 @@ int __drm_open_driver(int chipset)
 		    has_known_intel_chipset(fd))
 			return fd;
 
-		if (chipset & DRIVER_VC4 &&
-		    is_vc4_device(fd))
+		if (chipset & DRIVER_VC4 && is_vc4_device(fd))
 			return fd;
 
-		if (chipset & DRIVER_VGEM &&
-		    is_vgem_device(fd))
+		if (chipset & DRIVER_VGEM && is_vgem_device(fd))
 			return fd;
 
-		if (chipset & DRIVER_VIRTIO &&
-		    is_virtio_device(fd))
+		if (chipset & DRIVER_VIRTIO && is_virtio_device(fd))
 			return fd;
 
 		if (chipset & DRIVER_AMDGPU && is_amd_device(fd))
@@ -287,6 +278,47 @@ int __drm_open_driver(int chipset)
 	return -1;
 }
 
+/**
+ * __drm_open_driver:
+ * @chipset: OR'd flags for each chipset to search, eg. #DRIVER_INTEL
+ *
+ * Open the first DRM device we can find, searching up to 16 device nodes
+ *
+ * Returns:
+ * An open DRM fd or -1 on error
+ */
+int __drm_open_driver(int chipset)
+{
+	static const struct {
+		unsigned int bit;
+		const char *module;
+		void (*modprobe)(const char *name);
+	} modules[] = {
+		{ DRIVER_AMDGPU, "amdgpu" },
+		{ DRIVER_INTEL, "i915", modprobe_i915 },
+		{ DRIVER_VC4, "vc4" },
+		{ DRIVER_VGEM, "vgem" },
+		{ DRIVER_VIRTIO, "virtio-gpu" },
+		{}
+	}, *m;
+	int fd;
+
+	fd = __open_device(chipset);
+	if (fd != -1)
+		return fd;
+
+	for (m = modules; m->module; m++) {
+		if (chipset & (1ul << m->bit)) {
+			if (m->modprobe)
+				m->modprobe(m->module);
+			else
+				modprobe(m->module);
+		}
+	}
+
+	return __open_device(chipset);
+}
+
 static int __drm_open_driver_render(int chipset)
 {
 	char *name;
-- 
2.15.0

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux