8830e76
From 536626891b60039c0f3f9b4cd96156e9fe810f39 Mon Sep 17 00:00:00 2001
97c6429
From: Dave Airlie <airlied@redhat.com>
97c6429
Date: Fri, 17 Aug 2012 09:49:24 +1000
8830e76
Subject: [PATCH] autobind GPUs to the screen, (v2)
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
97c6429
DO NOT UPSTREAM.
97c6429
---
fc48514
 hw/xfree86/common/xf86Init.c        |   12 ++++++++++++
fc48514
 hw/xfree86/common/xf86platformBus.c |    3 +++
8830e76
 hw/xfree86/modes/xf86Crtc.c         |   28 ++++++++++++++++++++++++++++
8830e76
 3 files changed, 43 insertions(+)
97c6429
97c6429
diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c
8830e76
index d231ced..89629c1 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
 
fc48514
+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
 {
8830e76
@@ -926,6 +936,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
8830e76
index a73aea2..3810076 100644
97c6429
--- a/hw/xfree86/common/xf86platformBus.c
97c6429
+++ b/hw/xfree86/common/xf86platformBus.c
8830e76
@@ -387,6 +387,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
 {
8830e76
@@ -446,6 +448,7 @@ xf86platformAddDevice(int index)
fc48514
 
fc48514
    /* attach unbound to 0 protocol screen */
fc48514
    AttachUnboundGPU(xf86Screens[0]->pScreen, xf86GPUScreens[i]->pScreen);
fc48514
+   xf86AutoConfigOutputDevice(xf86GPUScreens[i], xf86Screens[0]);
fc48514
 
97c6429
    return 0;
97c6429
 }
fc48514
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
8830e76
index 8f05c53..ba84e6b 100644
fc48514
--- a/hw/xfree86/modes/xf86Crtc.c
fc48514
+++ b/hw/xfree86/modes/xf86Crtc.c
8830e76
@@ -3321,3 +3321,31 @@ xf86DetachAllCrtc(ScrnInfoPtr scrn)
fc48514
             crtc->x = crtc->y = 0;
fc48514
         }
fc48514
 }
fc48514
+
fc48514
+
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);
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 */
fc48514
+            
fc48514
+        DetachUnboundGPU(pScrn->pScreen);
fc48514
+        AttachOffloadGPU(master->pScreen, pScrn->pScreen);
fc48514
+        slave_config->randr_provider->offload_sink = master_provider;
fc48514
+    } else if ((master->capabilities & RR_Capability_SourceOutput) &&
fc48514
+               pScrn->capabilities & RR_Capability_SinkOutput) {
fc48514
+        /* sink offload */
fc48514
+        DetachUnboundGPU(pScrn->pScreen);
fc48514
+        AttachOutputGPU(master->pScreen, pScrn->pScreen);
fc48514
+        slave_config->randr_provider->output_source = master_provider;
fc48514
+    }
fc48514
+}
97c6429
-- 
fc48514
1.7.10.2
97c6429