[Intel-gfx] [PATCH 1/2] Enable SNA via a configuration file option.

Eugeni Dodonov eugeni.dodonov at intel.com
Mon Oct 31 18:10:18 CET 2011


This allows to use UXA and SNA from within the same driver, by setting
an "UseSNA" option in the driver config - for example, by creating an
/etc/X11/xorg.conf.d/99-intel-sna.conf:

Section "Device"
	Identifier "intel"
	driver "intel"
	Option "UseSna" "True"
EndSection

This also allows to record the entity_num within the main intel driver,
not only SNA.

Signed-off-by: Eugeni Dodonov <eugeni.dodonov at intel.com>
---
 src/common.h         |    2 +-
 src/intel_driver.c   |   96 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/intel_module.c   |    6 +---
 src/sna/sna_driver.c |   14 +------
 src/sna/sna_module.h |    3 +-
 5 files changed, 100 insertions(+), 21 deletions(-)

diff --git a/src/common.h b/src/common.h
index 6f23cdd..6b86801 100644
--- a/src/common.h
+++ b/src/common.h
@@ -77,7 +77,7 @@ I830DPRINTF_stub(const char *filename, int line, const char *function,
 
 /* I830 hooks for the I810 driver setup/probe. */
 extern const OptionInfoRec *I830AvailableOptions(int chipid, int busid);
-extern void intel_init_scrn(ScrnInfoPtr scrn);
+extern void intel_init_scrn(ScrnInfoPtr scrn, int entity_num);
 
 /* Symbol lists shared by the i810 and i830 parts. */
 extern int I830EntityIndex;
diff --git a/src/intel_driver.c b/src/intel_driver.c
index 24696da..09c306c 100644
--- a/src/intel_driver.c
+++ b/src/intel_driver.c
@@ -101,6 +101,7 @@ typedef enum {
    OPTION_DEBUG_WAIT,
    OPTION_HOTPLUG,
    OPTION_RELAXED_FENCING,
+   OPTION_USE_SNA,
 } I830Opts;
 
 static OptionInfoRec I830Options[] = {
@@ -122,6 +123,7 @@ static OptionInfoRec I830Options[] = {
    {OPTION_DEBUG_WAIT, "DebugWait", OPTV_BOOLEAN, {0}, FALSE},
    {OPTION_HOTPLUG,	"HotPlug",	OPTV_BOOLEAN,	{0},	TRUE},
    {OPTION_RELAXED_FENCING,	"RelaxedFencing",	OPTV_BOOLEAN,	{0},	TRUE},
+   {OPTION_USE_SNA,	"UseSna",	OPTV_BOOLEAN,	{0},	FALSE},
    {-1,			NULL,		OPTV_NONE,	{0},	FALSE}
 };
 /* *INDENT-ON* */
@@ -1326,9 +1328,91 @@ static Bool I830PMEvent(int scrnIndex, pmEvent event, Bool undo)
 	return TRUE;
 }
 
-void intel_init_scrn(ScrnInfoPtr scrn)
+/*
+ * Due to the nature of xserver drivers, we need to do a lot of
+ * things just to attempt to parse driver options. So we do it all
+ * here, check if we are supposed to use SNA, and call the corresponding
+ * real setup afterwards.
+ */
+static Bool intelPreInit(ScrnInfoPtr scrn, int flags)
 {
-	scrn->PreInit = I830PreInit;
+	rgb defaultWeight = { 0, 0, 0 };
+	Bool use_sna;
+	EntityInfoPtr pEnt;
+	int flags24;
+	OptionInfoPtr Options;
+
+	xf86DrvMsg(0, X_INFO, "Inside intelPreInit...\n");
+
+	if (scrn->numEntities != 1)
+		return FALSE;
+
+	pEnt = xf86GetEntityInfo(scrn->entityList[0]);
+
+	xf86DrvMsg(0, X_INFO, "Detecting monitor...\n");
+
+	scrn->monitor = scrn->confScreen->monitor;
+	scrn->progClock = TRUE;
+	scrn->rgbBits = 8;
+
+	flags24 = Support32bppFb | PreferConvert24to32 | SupportConvert24to32;
+
+	if (!xf86SetDepthBpp(scrn, 0, 0, 0, flags24))
+		return FALSE;
+
+	switch (scrn->depth) {
+	case 8:
+	case 15:
+	case 16:
+	case 24:
+	case 30:
+		break;
+	default:
+		xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+			   "Given depth (%d) is not supported by intel driver\n",
+			   scrn->depth);
+		return FALSE;
+	}
+
+	if (!xf86SetWeight(scrn, defaultWeight, defaultWeight))
+		return FALSE;
+	if (!xf86SetDefaultVisual(scrn, -1))
+		return FALSE;
+
+	/* Now the main trick - collecting driver option to find out if we
+	 * need SNA... */
+	xf86CollectOptions(scrn, NULL);
+
+	if (!(Options = malloc(sizeof(I830Options))))
+		return FALSE;
+	memcpy(Options, I830Options, sizeof(I830Options));
+	xf86ProcessOptions(scrn->scrnIndex, scrn->options, Options);
+
+	xf86DrvMsg(0, X_INFO, "Detecting SNA...\n");
+	use_sna = xf86ReturnOptValBool(Options,
+			OPTION_USE_SNA,
+			FALSE);
+
+	/* Clean up */
+	free(Options);
+	PreInitCleanup(scrn);
+	if (use_sna) {
+		/* Using SNA, re-initialize function pointers */
+		xf86DrvMsg(scrn->scrnIndex, X_INFO, "Enabling SNA via option\n");
+		sna_init_scrn(scrn);
+		return sna_pre_init(scrn, flags);
+	}
+	else {
+		xf86DrvMsg(scrn->scrnIndex, X_INFO, "SNA not enabled, using UXA\n");
+		return I830PreInit(scrn, flags);
+	}
+}
+
+void intel_init_scrn(ScrnInfoPtr scrn, int entity_num)
+{
+	EntityInfoPtr entity;
+
+	scrn->PreInit = intelPreInit;
 	scrn->ScreenInit = I830ScreenInit;
 	scrn->SwitchMode = I830SwitchMode;
 	scrn->AdjustFrame = i830AdjustFrame;
@@ -1337,4 +1421,12 @@ void intel_init_scrn(ScrnInfoPtr scrn)
 	scrn->FreeScreen = I830FreeScreen;
 	scrn->ValidMode = I830ValidMode;
 	scrn->PMEvent = I830PMEvent;
+
+	xf86SetEntitySharable(scrn->entityList[0]);
+
+	entity = xf86GetEntityInfo(entity_num);
+	xf86SetEntityInstanceForScreen(scrn,
+				       entity->index,
+				       xf86GetNumEntityInstances(entity->index)-1);
+	free(entity);
 }
diff --git a/src/intel_module.c b/src/intel_module.c
index cd9c1a3..a39ce21 100644
--- a/src/intel_module.c
+++ b/src/intel_module.c
@@ -344,11 +344,7 @@ static Bool intel_pci_probe(DriverPtr		driver,
 #endif
 
 		default:
-#if USE_SNA
-			sna_init_scrn(scrn, entity_num);
-#else
-			intel_init_scrn(scrn);
-#endif
+			intel_init_scrn(scrn, entity_num);
 			break;
 		}
 	}
diff --git a/src/sna/sna_driver.c b/src/sna/sna_driver.c
index 0df7ca0..4118cdd 100644
--- a/src/sna/sna_driver.c
+++ b/src/sna/sna_driver.c
@@ -396,7 +396,7 @@ static void sna_selftest(void)
  * As a result, we want to set up that server initialization once rather
  * that doing it per generation.
  */
-static Bool sna_pre_init(ScrnInfoPtr scrn, int flags)
+Bool sna_pre_init(ScrnInfoPtr scrn, int flags)
 {
 	struct sna *sna;
 	rgb defaultWeight = { 0, 0, 0 };
@@ -1019,10 +1019,8 @@ static Bool sna_pm_event(int scrnIndex, pmEvent event, Bool undo)
 	return TRUE;
 }
 
-void sna_init_scrn(ScrnInfoPtr scrn, int entity_num)
+void sna_init_scrn(ScrnInfoPtr scrn)
 {
-	EntityInfoPtr entity;
-
 #if defined(USE_GIT_DESCRIBE)
 	xf86DrvMsg(scrn->scrnIndex, X_INFO,
 		   "SNA compiled from %s\n", git_version);
@@ -1044,12 +1042,4 @@ void sna_init_scrn(ScrnInfoPtr scrn, int entity_num)
 	scrn->FreeScreen = sna_free_screen;
 	scrn->ValidMode = sna_valid_mode;
 	scrn->PMEvent = sna_pm_event;
-
-	xf86SetEntitySharable(scrn->entityList[0]);
-
-	entity = xf86GetEntityInfo(entity_num);
-	xf86SetEntityInstanceForScreen(scrn,
-				       entity->index,
-				       xf86GetNumEntityInstances(entity->index)-1);
-	free(entity);
 }
diff --git a/src/sna/sna_module.h b/src/sna/sna_module.h
index 97d5dd5..34022ba 100644
--- a/src/sna/sna_module.h
+++ b/src/sna/sna_module.h
@@ -1,3 +1,4 @@
 const OptionInfoRec *sna_available_options(int chipid, int busid);
-void sna_init_scrn(ScrnInfoPtr scrn, int entity_num);
+void sna_init_scrn(ScrnInfoPtr scrn);
+Bool sna_pre_init(ScrnInfoPtr scrn, int flags);
 
-- 
1.7.7.1




More information about the Intel-gfx mailing list