488b3f2
From cd6f931fb06f825f246222a4362fbf728f8dce73 Mon Sep 17 00:00:00 2001
97c6429
From: Dave Airlie <airlied@redhat.com>
97c6429
Date: Fri, 17 Aug 2012 09:49:24 +1000
Dave Airlie 9620f4c
Subject: [PATCH] autobind GPUs to the screen, (v3)
97c6429
97c6429
this is racy and really not what we want for hotplug going forward,
97c6429
but until DE support is in GNOME its probably for the best.
97c6429
8830e76
v2: fix if config or slave config is NULL
Dave Airlie 9620f4c
v3: fix multi useful slaves
97c6429
DO NOT UPSTREAM.
Dave Airlie 02cbf43
Dave Airlie 02cbf43
Signed-off-by: Dave Airlie <airlied@gmail.com>
97c6429
---
Dave Airlie 9620f4c
 hw/xfree86/common/xf86Init.c        | 12 ++++++++++++
Dave Airlie 9620f4c
 hw/xfree86/common/xf86platformBus.c |  3 +++
Dave Airlie 9620f4c
 hw/xfree86/modes/xf86Crtc.c         | 32 ++++++++++++++++++++++++++++++++
Dave Airlie 02cbf43
 3 files changed, 47 insertions(+)
97c6429
97c6429
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
488b3f2
index 6282252..dc33ad1 100644
97c6429
--- a/hw/xfree86/common/xf86Init.c
97c6429
+++ b/hw/xfree86/common/xf86Init.c
fc48514
@@ -361,6 +361,16 @@ xf86CreateRootWindow(WindowPtr pWin)
fc48514
     return ret;
fc48514
 }
97c6429
 
Dave Airlie 9dc0b02
+extern void xf86AutoConfigOutputDevice(ScrnInfoPtr pScrn, ScrnInfoPtr master);                              
fc48514
+static void
fc48514
+xf86AutoConfigOutputDevices(void)
fc48514
+{
fc48514
+    int i;
fc48514
+
fc48514
+    for (i = 0; i < xf86NumGPUScreens; i++)
fc48514
+        xf86AutoConfigOutputDevice(xf86GPUScreens[i], xf86Screens[0]);
fc48514
+}
fc48514
+
fc48514
 static void
fc48514
 InstallSignalHandlers(void)
fc48514
 {
488b3f2
@@ -949,6 +959,8 @@ InitOutput(ScreenInfo * pScreenInfo, int argc, char **argv)
fc48514
     for (i = 0; i < xf86NumGPUScreens; i++)
fc48514
         AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
97c6429
 
fc48514
+    xf86AutoConfigOutputDevices();
fc48514
+
97c6429
     xf86VGAarbiterWrapFunctions();
97c6429
     if (sigio_blocked)
fc48514
         OsReleaseSIGIO();
97c6429
diff --git a/hw/xfree86/common/xf86platformBus.c b/hw/xfree86/common/xf86platformBus.c
488b3f2
index 33b2b7d..be3bdd9 100644
97c6429
--- a/hw/xfree86/common/xf86platformBus.c
97c6429
+++ b/hw/xfree86/common/xf86platformBus.c
Dave Airlie 02cbf43
@@ -393,6 +393,8 @@ xf86platformProbeDev(DriverPtr drvp)
fc48514
     return foundScreen;
fc48514
 }
97c6429
 
fc48514
+extern void xf86AutoConfigOutputDevice(ScrnInfoPtr pScrn, ScrnInfoPtr master);
97c6429
+
fc48514
 int
fc48514
 xf86platformAddDevice(int index)
fc48514
 {
Dave Airlie 9dc0b02
@@ -465,6 +467,7 @@ xf86platformAddDevice(int index)
Dave Airlie 9dc0b02
    }
fc48514
    /* attach unbound to 0 protocol screen */
fc48514
    AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
fc48514
+   xf86AutoConfigOutputDevice(xf86GPUScreens[i], xf86Screens[0]);
fc48514
 
488b3f2
    RRResourcesChanged(xf86Screens[0]->pScreen);
488b3f2
    RRTellChanged(xf86Screens[0]->pScreen);
fc48514
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
488b3f2
index 4726f2a..e83ea13 100644
fc48514
--- a/hw/xfree86/modes/xf86Crtc.c
fc48514
+++ b/hw/xfree86/modes/xf86Crtc.c
488b3f2
@@ -3440,3 +3440,35 @@ xf86DetachAllCrtc(ScrnInfoPtr scrn)
fc48514
             crtc->x = crtc->y = 0;
fc48514
         }
fc48514
 }
fc48514
+
Dave Airlie 9dc0b02
+
fc48514
+void xf86AutoConfigOutputDevice(ScrnInfoPtr pScrn, ScrnInfoPtr master)
fc48514
+{
fc48514
+    RRProviderPtr master_provider;
fc48514
+    xf86CrtcConfigPtr config = XF86_CRTC_CONFIG_PTR(master);
fc48514
+    xf86CrtcConfigPtr slave_config = XF86_CRTC_CONFIG_PTR(pScrn);
Dave Airlie 9620f4c
+    Bool unbound = FALSE;
fc48514
+
8830e76
+    if (!config || !slave_config)
8830e76
+        return;
8830e76
+
fc48514
+    master_provider = config->randr_provider;
fc48514
+
fc48514
+    if ((master->capabilities & RR_Capability_SinkOffload) &&
fc48514
+        pScrn->capabilities & RR_Capability_SourceOffload) {
fc48514
+            /* source offload */
Dave Airlie 9dc0b02
+            
fc48514
+        DetachUnboundGPU(pScrn->pScreen);
Dave Airlie 9620f4c
+        unbound = TRUE;
fc48514
+        AttachOffloadGPU(master->pScreen, pScrn->pScreen);
fc48514
+        slave_config->randr_provider->offload_sink = master_provider;
Dave Airlie 9620f4c
+    }
Dave Airlie 9620f4c
+    if ((master->capabilities & RR_Capability_SourceOutput) &&
fc48514
+               pScrn->capabilities & RR_Capability_SinkOutput) {
fc48514
+        /* sink offload */
Dave Airlie 9620f4c
+        if (!unbound)
Dave Airlie 9620f4c
+            DetachUnboundGPU(pScrn->pScreen);
fc48514
+        AttachOutputGPU(master->pScreen, pScrn->pScreen);
fc48514
+        slave_config->randr_provider->output_source = master_provider;
fc48514
+    }
fc48514
+}
Dave Airlie 9dc0b02
-- 
488b3f2
1.8.3.1
Dave Airlie 9dc0b02