Blob Blame History Raw
From d75ffcdbf8c1e3c8e0d46debcd533a9f2560f0a8 Mon Sep 17 00:00:00 2001
From: Hans De Goede <hdegoede@redhat.com>
Date: Mon, 12 Dec 2016 17:03:16 +0100
Subject: [PATCH xserver 5/6] xfree86: Allow overriding primary GPU detection
 from an OutputClass section

Allow using:

Option "PrimaryGPU" "yes"

In an OutputClass section to override the default primary GPU device
selection which selects the GPU used as output by the firmware.

If multiple output devices match an OutputClass section with
the PrimaryGPU option set, the first one enumerated becomes the
primary GPU.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 hw/xfree86/common/xf86platformBus.c | 19 +++++++++++++++++++
 hw/xfree86/man/xorg.conf.man        | 12 +++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
index 39b3248..fc17d15 100644
--- a/hw/xfree86/common/xf86platformBus.c
+++ b/hw/xfree86/common/xf86platformBus.c
@@ -286,6 +286,7 @@ xf86platformProbe(void)
 {
     int i;
     Bool pci = TRUE;
+    XF86ConfOutputClassPtr cl;
 
     config_odev_probe(xf86PlatformDeviceProbe);
 
@@ -301,6 +302,24 @@ xf86platformProbe(void)
         }
     }
 
+    /* First see if there is an OutputClass match marking a device as primary */
+    for (i = 0; i < xf86_num_platform_devices; i++) {
+        struct xf86_platform_device *dev = &xf86_platform_devices[i];
+        for (cl = xf86configptr->conf_outputclass_lst; cl; cl = cl->list.next) {
+            if (!OutputClassMatches(cl, dev))
+                continue;
+
+            if (xf86CheckBoolOption(cl->option_lst, "PrimaryGPU", FALSE)) {
+                xf86Msg(X_CONFIG, "OutputClass \"%s\" setting %s as PrimaryGPU\n",
+                        cl->identifier, dev->attribs->path);
+                primaryBus.type = BUS_PLATFORM;
+                primaryBus.id.plat = dev;
+                return 0;
+            }
+        }
+    }
+
+    /* Then check for pci_device_is_boot_vga() */
     for (i = 0; i < xf86_num_platform_devices; i++) {
         struct xf86_platform_device *dev = &xf86_platform_devices[i];
 
diff --git a/hw/xfree86/man/xorg.conf.man b/hw/xfree86/man/xorg.conf.man
index 8928a53..79b71a8 100644
--- a/hw/xfree86/man/xorg.conf.man
+++ b/hw/xfree86/man/xorg.conf.man
@@ -1285,11 +1285,21 @@ When an output device has been matched to the
 .B OutputClass
 section, any
 .B Option
-entries are applied to the device. See the
+entries are applied to the device. One
+.B OutputClass
+specific
+.B Option
+is recognized. See the
 .B Device
 section below for a description of the remaining
 .B Option
 entries.
+.TP 7
+.BI "Option \*qPrimaryGPU\*q \*q" boolean \*q
+This option specifies that the matched device should be treated as the
+primary GPU, replacing the selection of the GPU used as output by the
+firmware. If multiple output devices match an OutputClass section with
+the PrimaryGPU option set, the first one enumerated becomes the primary GPU.
 .SH "DEVICE SECTION"
 The config file may have multiple
 .B Device
-- 
2.9.3