[PATCH xserver 3/4] xfree86: introduce the xf86PromoteLastGPUScreenToLastScreen() helper

Laszlo Ersek lersek at redhat.com
Sun Sep 4 01:11:41 UTC 2016


This is a helper function that we'll use in the next patch.

Cc: Adam Jackson <ajax at redhat.com>
Cc: Dave Airlie <airlied at redhat.com>
Cc: Keith Packard <keithp at keithp.com>
Signed-off-by: Laszlo Ersek <lersek at redhat.com>
---
 hw/xfree86/common/xf86.h       |  1 +
 hw/xfree86/common/xf86Helper.c | 43 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/hw/xfree86/common/xf86.h b/hw/xfree86/common/xf86.h
index e54c811709dd..be2ba30b350b 100644
--- a/hw/xfree86/common/xf86.h
+++ b/hw/xfree86/common/xf86.h
@@ -240,6 +240,7 @@ extern _X_EXPORT void xf86AddDriver(DriverPtr driver, void *module,
 extern _X_EXPORT void xf86DeleteDriver(int drvIndex);
 extern _X_EXPORT ScrnInfoPtr xf86AllocateScreen(DriverPtr drv, int flags);
 extern _X_EXPORT void xf86DeleteScreen(ScrnInfoPtr pScrn);
+extern _X_EXPORT void xf86PromoteLastGPUScreenToLastScreen(void);
 extern _X_EXPORT int xf86AllocateScrnInfoPrivateIndex(void);
 extern _X_EXPORT Bool xf86AddPixFormat(ScrnInfoPtr pScrn, int depth, int bpp,
                                        int pad);
diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c
index 6f3a6086b410..2cf9010a4bf3 100644
--- a/hw/xfree86/common/xf86Helper.c
+++ b/hw/xfree86/common/xf86Helper.c
@@ -281,6 +281,49 @@ xf86DeleteScreen(ScrnInfoPtr pScrn)
 }
 
 /*
+ * Promote (move) the last entry from xf86GPUScreens to the last entry in
+ * xf86Screens. The caller is responsible for ensuring that on input,
+ * xf86GPUScreens is not empty, and that xf86Screens contains fewer than
+ * GPU_SCREEN_OFFSET elements.
+ *
+ * This function is only valid to call for DDX, not DIX, purposes; i.e., during
+ * the initial hardware enumeration in InitOutput() -> xf86BusConfig(). In
+ * particular it does not care about the screenInfo.screens and
+ * screenInfo.gpuscreens arrays.
+ */
+
+void
+xf86PromoteLastGPUScreenToLastScreen(void)
+{
+    ScrnInfoPtr pScrn;
+    int i;
+
+    assert(xf86NumGPUScreens > 0);
+    assert(xf86NumScreens < GPU_SCREEN_OFFSET);
+
+    pScrn = xf86GPUScreens[xf86NumGPUScreens - 1];
+    assert(pScrn->is_gpu);
+    assert(pScrn->scrnIndex >= GPU_SCREEN_OFFSET);
+
+    xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
+               "promoting secondary graphics card...\n");
+
+    /*
+     * Don't reallocate xf86GPUScreens because (a) xf86DeleteScreen() does
+     * neither, (b) xnfreallocarray() doesn't support complete freeing.
+     */
+    xf86NumGPUScreens--;
+    i = xf86NumScreens++;
+    xf86Screens = xnfreallocarray(xf86Screens, xf86NumScreens, sizeof pScrn);
+    xf86Screens[i] = pScrn;
+    pScrn->is_gpu = FALSE;
+    pScrn->scrnIndex = i;
+    /* don't change pScrn->origIndex */
+
+    xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "... to primary.\n");
+}
+
+/*
  * Allocate a private in ScrnInfoRec.
  */
 
-- 
2.9.2




More information about the xorg-devel mailing list