Ben Skeggs de1c84
From aa2f34d80ef3118eae0cce73b610c36cdcb978fe Mon Sep 17 00:00:00 2001
Ben Skeggs de1c84
From: Ben Skeggs <bskeggs@redhat.com>
Ben Skeggs de1c84
Date: Sat, 22 Apr 2017 02:26:28 +1000
Ben Skeggs de1c84
Subject: [PATCH xserver] xfree86: use modesetting driver by default on GeForce
Ben Skeggs de1c84
 8 and newer
Ben Skeggs de1c84
Ben Skeggs de1c84
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Ben Skeggs de1c84
---
Ben Skeggs de1c84
 hw/xfree86/common/xf86pciBus.c | 20 ++++++++++++++++++++
Ben Skeggs de1c84
 1 file changed, 20 insertions(+)
Ben Skeggs de1c84
Ben Skeggs de1c84
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
Ben Skeggs de1c84
index 8158c2b62..78d1c947d 100644
Ben Skeggs de1c84
--- a/hw/xfree86/common/xf86pciBus.c
Ben Skeggs de1c84
+++ b/hw/xfree86/common/xf86pciBus.c
Ben Skeggs de1c84
@@ -37,6 +37,7 @@
Ben Skeggs de1c84
 #include <unistd.h>
Ben Skeggs de1c84
 #include <x11 x.h="">
Ben Skeggs de1c84
 #include <pciaccess.h>
Ben Skeggs de1c84
+#include <xf86drm.h>
Ben Skeggs de1c84
 #include "os.h"
Ben Skeggs de1c84
 #include "Pci.h"
Ben Skeggs de1c84
 #include "xf86.h"
Ben Skeggs de1c84
@@ -1190,6 +1191,25 @@ xf86VideoPtrToDriverList(struct pci_device *dev,
Ben Skeggs de1c84
         int idx = 0;
Ben Skeggs de1c84
 
5bc7f7
 #if defined(__linux__) || defined(__NetBSD__)
Ben Skeggs de1c84
+        char busid[32];
Ben Skeggs de1c84
+        int fd;
Ben Skeggs de1c84
+
Ben Skeggs de1c84
+        snprintf(busid, sizeof(busid), "pci:%04x:%02x:%02x.%d",
Ben Skeggs de1c84
+                 dev->domain, dev->bus, dev->dev, dev->func);
Ben Skeggs de1c84
+
Ben Skeggs de1c84
+	/* 'modesetting' is preferred for GeForce 8 and newer GPUs */
Ben Skeggs de1c84
+        fd = drmOpenWithType("nouveau", busid, DRM_NODE_RENDER);
Ben Skeggs de1c84
+        if (fd >= 0) {
Ben Skeggs de1c84
+            uint64_t args[] = { 11 /* NOUVEAU_GETPARAM_CHIPSET_ID */, 0 };
Ben Skeggs de1c84
+            int ret = drmCommandWriteRead(fd, 0 /* DRM_NOUVEAU_GETPARAM */,
Ben Skeggs de1c84
+                                          &args, sizeof(args));
Ben Skeggs de1c84
+            drmClose(fd);
Ben Skeggs de1c84
+            if (ret == 0) {
Ben Skeggs de1c84
+                if (args[1] == 0x050 || args[1] >= 0x80)
Ben Skeggs de1c84
+                    break;
Ben Skeggs de1c84
+            }
Ben Skeggs de1c84
+        }
Ben Skeggs de1c84
+
Ben Skeggs de1c84
         driverList[idx++] = "nouveau";
Ben Skeggs de1c84
 #endif
Ben Skeggs de1c84
         driverList[idx++] = "nv";
Ben Skeggs de1c84
-- 
Ben Skeggs de1c84
2.12.2
Ben Skeggs de1c84