62565be
From b27f93c6dbe0a6e416db2c65738e996c70a403c1 Mon Sep 17 00:00:00 2001
62565be
From: Fedora X Ninjas <airlied@redhat.com>
62565be
Date: Thu, 6 May 2010 12:55:34 +1000
62565be
Subject: [PATCH] xf86: allow for no outputs connected at startup operation.
62565be
62565be
When nothing is connected at startup and we canGrow, allow the server to start with a 1024x768 framebuffer, and when the drivers send hotplug events this will expand to the correct size dynamically.
62565be
62565be
Signed-off-by: Dave Airlie <airlied@redhat.com>
62565be
---
62565be
 hw/xfree86/modes/xf86Crtc.c |   66 ++++++++++++++++++++++++++++++------------
62565be
 1 files changed, 47 insertions(+), 19 deletions(-)
62565be
62565be
diff --git a/hw/xfree86/modes/xf86Crtc.c b/hw/xfree86/modes/xf86Crtc.c
62565be
index 571ffd0..99082ec 100644
62565be
--- a/hw/xfree86/modes/xf86Crtc.c
62565be
+++ b/hw/xfree86/modes/xf86Crtc.c
62565be
@@ -48,6 +48,8 @@
62565be
 
62565be
 #include "xf86xv.h"
62565be
 
62565be
+#define NO_OUTPUT_DEFAULT_WIDTH 1024
62565be
+#define NO_OUTPUT_DEFAULT_HEIGHT 768
62565be
 /*
62565be
  * Initialize xf86CrtcConfig structure
62565be
  */
62565be
@@ -1946,7 +1948,7 @@ xf86SetScrnInfoModes (ScrnInfoPtr scrn)
62565be
 #endif
62565be
 }
62565be
 
62565be
-static void
62565be
+static Bool
62565be
 xf86CollectEnabledOutputs(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
62565be
 			  Bool *enabled)
62565be
 {
62565be
@@ -1961,8 +1963,10 @@ xf86CollectEnabledOutputs(ScrnInfoPtr scrn, xf86CrtcConfigPtr config,
62565be
 		   "No outputs definitely connected, trying again...\n");
62565be
 
62565be
 	for (o = 0; o < config->num_output; o++)
62565be
-	    enabled[o] = xf86OutputEnabled(config->output[o], FALSE);
62565be
+	    any_enabled |= enabled[o] = xf86OutputEnabled(config->output[o], FALSE);
62565be
     }
62565be
+
62565be
+    return any_enabled;
62565be
 }
62565be
 
62565be
 static Bool
62565be
@@ -2409,6 +2413,8 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
62565be
     Bool		*enabled;
62565be
     int			width, height;
62565be
     int			i = scrn->scrnIndex;
62565be
+    Bool have_outputs = TRUE;
62565be
+    Bool ret;
62565be
 
62565be
     /* Set up the device options */
62565be
     config->options = xnfalloc (sizeof (xf86DeviceOptions));
62565be
@@ -2433,20 +2439,26 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
62565be
     modes = xnfcalloc (config->num_output, sizeof (DisplayModePtr));
62565be
     enabled = xnfcalloc (config->num_output, sizeof (Bool));
62565be
     
62565be
-    xf86CollectEnabledOutputs(scrn, config, enabled);
62565be
-
62565be
-    if (xf86TargetUserpref(scrn, config, modes, enabled, width, height))
62565be
-	xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n");
62565be
-    else if (xf86TargetRightOf(scrn, config, modes, enabled, width, height))
62565be
-	xf86DrvMsg(i, X_INFO, "Using spanning desktop for initial modes\n");
62565be
-    else if (xf86TargetPreferred(scrn, config, modes, enabled, width, height))
62565be
-	xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n");
62565be
-    else if (xf86TargetAspect(scrn, config, modes, enabled, width, height))
62565be
-	xf86DrvMsg(i, X_INFO, "Using fuzzy aspect match for initial modes\n");
62565be
-    else if (xf86TargetFallback(scrn, config, modes, enabled, width, height))
62565be
-	xf86DrvMsg(i, X_INFO, "Using sloppy heuristic for initial modes\n");
62565be
-    else
62565be
-	xf86DrvMsg(i, X_WARNING, "Unable to find initial modes\n");
62565be
+    ret = xf86CollectEnabledOutputs(scrn, config, enabled);
62565be
+    if (ret == FALSE && canGrow) {
62565be
+	xf86DrvMsg(i, X_WARNING, "Unable to find connected outputs - setting %dx%d initial framebuffer\n",
62565be
+		   NO_OUTPUT_DEFAULT_WIDTH, NO_OUTPUT_DEFAULT_HEIGHT);
62565be
+	have_outputs = FALSE;
62565be
+    }
62565be
+    else {
62565be
+	if (xf86TargetUserpref(scrn, config, modes, enabled, width, height))
62565be
+	    xf86DrvMsg(i, X_INFO, "Using user preference for initial modes\n");
62565be
+	else if (xf86TargetRightOf(scrn, config, modes, enabled, width, height))
62565be
+	    xf86DrvMsg(i, X_INFO, "Using spanning desktop for initial modes\n");
62565be
+	else if (xf86TargetPreferred(scrn, config, modes, enabled, width, height))
62565be
+	    xf86DrvMsg(i, X_INFO, "Using exact sizes for initial modes\n");
62565be
+	else if (xf86TargetAspect(scrn, config, modes, enabled, width, height))
62565be
+	    xf86DrvMsg(i, X_INFO, "Using fuzzy aspect match for initial modes\n");
62565be
+	else if (xf86TargetFallback(scrn, config, modes, enabled, width, height))
62565be
+	    xf86DrvMsg(i, X_INFO, "Using sloppy heuristic for initial modes\n");
62565be
+	else
62565be
+	    xf86DrvMsg(i, X_WARNING, "Unable to find initial modes\n");
62565be
+    }
62565be
 
62565be
     for (o = -1; nextEnabledOutput(config, enabled, &o); ) {
62565be
 	if (!modes[o])
62565be
@@ -2479,7 +2491,7 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
62565be
     /*
62565be
      * Assign CRTCs to fit output configuration
62565be
      */
62565be
-    if (!xf86PickCrtcs (scrn, crtcs, modes, 0, width, height))
62565be
+    if (have_outputs && !xf86PickCrtcs (scrn, crtcs, modes, 0, width, height))
62565be
     {
62565be
 	xfree (crtcs);
62565be
 	xfree (modes);
62565be
@@ -2541,6 +2553,13 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
62565be
 	 */
62565be
 	xf86DefaultScreenLimits (scrn, &width, &height, canGrow);
62565be
     
62565be
+	if (have_outputs == FALSE) {
62565be
+	    if (width < NO_OUTPUT_DEFAULT_WIDTH && height < NO_OUTPUT_DEFAULT_HEIGHT) {
62565be
+		width = NO_OUTPUT_DEFAULT_WIDTH;
62565be
+		height = NO_OUTPUT_DEFAULT_HEIGHT;
62565be
+	    }
62565be
+	}
62565be
+
62565be
 	scrn->display->virtualX = width;
62565be
 	scrn->display->virtualY = height;
62565be
     }
62565be
@@ -2566,8 +2585,17 @@ xf86InitialConfiguration (ScrnInfoPtr scrn, Bool canGrow)
62565be
 			      width, height);
62565be
     }
62565be
 
62565be
-    /* Mirror output modes to scrn mode list */
62565be
-    xf86SetScrnInfoModes (scrn);
62565be
+    if (have_outputs) {
62565be
+	/* Mirror output modes to scrn mode list */
62565be
+	xf86SetScrnInfoModes (scrn);
62565be
+    } else {
62565be
+	/* Clear any existing modes from scrn->modes */
62565be
+	while (scrn->modes != NULL)
62565be
+	    xf86DeleteMode(&scrn->modes, scrn->modes);
62565be
+	scrn->modes = xf86ModesAdd(scrn->modes,
62565be
+				   xf86CVTMode(width, height, 60, 0, 0));
62565be
+    }
62565be
+
62565be
     
62565be
     xfree (crtcs);
62565be
     xfree (modes);
62565be
-- 
62565be
1.7.0.1
62565be