ab13247
From 9ee22b4f743a2850fed35f179c56f94ce4bb5242 Mon Sep 17 00:00:00 2001
ab13247
From: Adam Jackson <ajax@redhat.com>
ab13247
Date: Tue, 3 Mar 2009 10:58:33 -0500
ab13247
Subject: [PATCH] Primary video device hack
ab13247
ab13247
---
ab13247
 hw/xfree86/common/xf86pciBus.c |   54 ++++++++++++++++++++++++++++++++++-----
ab13247
 1 files changed, 47 insertions(+), 7 deletions(-)
ab13247
ab13247
diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c
ab13247
index 467a0c3..f9999d8 100644
ab13247
--- a/hw/xfree86/common/xf86pciBus.c
ab13247
+++ b/hw/xfree86/common/xf86pciBus.c
ab13247
@@ -341,6 +341,39 @@ restorePciBusState(BusAccPtr ptr)
ab13247
 }
ab13247
 #undef MASKBITS
ab13247
 
ab13247
+/* oh god what have i done */
ab13247
+static Bool
ab13247
+looks_like_bios_primary(struct pci_device *info)
ab13247
+{
ab13247
+    unsigned char *bios;
ab13247
+    unsigned short vendor, device;
ab13247
+    int offset;
ab13247
+    Bool ret = FALSE;
ab13247
+
ab13247
+    bios = xf86MapVidMem(-1, VIDMEM_MMIO, 0xc0000, 0x10000);
ab13247
+    if (!bios)
ab13247
+        return FALSE;
ab13247
+
ab13247
+    if (bios[0] != 0x55 || bios[1] != 0xAA)
ab13247
+        goto out;
ab13247
+
ab13247
+    offset = (bios[0x19] << 8) + bios[0x18];
ab13247
+
ab13247
+    if (bios[offset] != 'P' ||
ab13247
+        bios[offset+1] != 'C' ||
ab13247
+        bios[offset+2] != 'I' ||
ab13247
+        bios[offset+3] != 'R')
ab13247
+        goto out;
ab13247
+
ab13247
+    vendor = (bios[offset+5] << 8) + bios[offset+4];
ab13247
+    device = (bios[offset+7] << 8) + bios[offset+6];
ab13247
+
ab13247
+    ret = (info->vendor_id == vendor) && (info->device_id == device);
ab13247
+
ab13247
+out:
ab13247
+    xf86UnMapVidMem(-1, bios, 0x10000);
ab13247
+    return ret;
ab13247
+}
ab13247
 
ab13247
 /*
ab13247
  * xf86Bus.c interface
ab13247
@@ -375,24 +408,31 @@ xf86PciProbe(void)
ab13247
 	}
ab13247
     }
ab13247
 
ab13247
-
ab13247
     /* If we haven't found a primary device try a different heuristic */
ab13247
     if (primaryBus.type == BUS_NONE && num) {
ab13247
 	for (i = 0; i < num; i++) {
ab13247
 	    uint16_t  command;
ab13247
 
ab13247
 	    info = xf86PciVideoInfo[i];
ab13247
+            if (!IS_VGA(info->device_class))
ab13247
+                continue;
ab13247
+
ab13247
 	    pci_device_cfg_read_u16(info, & command, 4);
ab13247
 
ab13247
-	    if ((command & PCI_CMD_MEM_ENABLE) 
ab13247
-		&& ((num == 1) || IS_VGA(info->device_class))) {
ab13247
-		if (primaryBus.type == BUS_NONE) {
ab13247
+	    if ((command & PCI_CMD_MEM_ENABLE)) {
ab13247
+                if (num == 1) {
ab13247
 		    primaryBus.type = BUS_PCI;
ab13247
 		    primaryBus.id.pci = info;
ab13247
-		} else {
ab13247
-		    xf86Msg(X_NOTICE,
ab13247
+                    break;
ab13247
+                } else if (looks_like_bios_primary(info)) {
ab13247
+                    if (primaryBus.type == BUS_NONE) {
ab13247
+                        primaryBus.type = BUS_PCI;
ab13247
+                        primaryBus.id.pci = info;
ab13247
+                    } else {
ab13247
+		        xf86Msg(X_NOTICE,
ab13247
 			    "More than one possible primary device found\n");
ab13247
-		    primaryBus.type ^= (BusType)(-1);
ab13247
+		        primaryBus.type ^= (BusType)(-1);
ab13247
+                    }
ab13247
 		}
ab13247
 	    }
ab13247
 	}
ab13247
-- 
ab13247
1.6.1.3
ab13247