Blob Blame History Raw
From b5b76ad849bfda1e75192d1cb3c6c0fcc623bb91 Mon Sep 17 00:00:00 2001
From: Chris Wilson <chris@chris-wilson.co.uk>
Date: Mon, 20 Aug 2012 12:01:39 +0100
Subject: [PATCH 1/3] Sanity check that the driver is an i915.ko GEM device
 before claiming it

This fixes an issue with us claiming Poulsbo and friends even though we
do not speak their language.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 src/intel_module.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/intel_module.c b/src/intel_module.c
index c0403ca..0a70b24 100644
--- a/src/intel_module.c
+++ b/src/intel_module.c
@@ -31,6 +31,7 @@
 #include <xf86_OSproc.h>
 #include <xf86Parser.h>
 #include <xf86drmMode.h>
+#include <i915_drm.h>

 #include <xorgVersion.h>

@@ -369,20 +370,35 @@ static Bool intel_driver_func(ScrnInfoPtr pScrn,
 static Bool has_kernel_mode_setting(struct pci_device *dev)
 {
	char id[20];
-	int ret;
+	int ret, fd;

	snprintf(id, sizeof(id),
		 "pci:%04x:%02x:%02x.%d",
		 dev->domain, dev->bus, dev->dev, dev->func);

	ret = drmCheckModesettingSupported(id);
-	if (ret && xf86LoadKernelModule("i915"))
-		ret = drmCheckModesettingSupported(id);
-	/* Be nice to the user and load fbcon too */
-	if (!ret)
+	if (ret) {
+		if (xf86LoadKernelModule("i915"))
+			ret = drmCheckModesettingSupported(id);
+		if (ret)
+			return FALSE;
+		/* Be nice to the user and load fbcon too */
		(void)xf86LoadKernelModule("fbcon");
+	}
+
+	/* Confirm that this is a i915.ko device with GEM/KMS enabled */
+	ret = FALSE;
+	fd = drmOpen(NULL, id);
+	if (fd != -1) {
+		struct drm_i915_getparam gp;
+
+		gp.param = I915_PARAM_HAS_GEM;
+		gp.value = &ret;
+		(void)drmIoctl(fd, DRM_IOCTL_I915_GETPARAM, &gp, sizeof(gp));
+		close(fd);
+	}

-	return ret == 0;
+	return ret;
 }

 extern XF86ConfigPtr xf86configptr;
--
1.7.7.6