Emil Velikov
2012-Nov-01  14:40 UTC
[Nouveau] [PATCH 0/4] nouveau: xserver 1.13 compat fixes
Here are a few patches adding some missing functions in
NvPlatformProbe, which iirc is being used as of xserver 1.13
First patch adds a nouveau_kernel_mode_enabled helper, similar
to xf86-video-radeon
Second and third use the function in Nv{Pci,Platform}Probe
And last one ensures we can still use ZaphodHead and relative
head positioning via xorg.conf
The coding style may be a bit off, despite my best attempts
Please review and comment
 
 [PATCH 1/4] nouveau: add nouveau_kernel_mode_enabled()
 [PATCH 2/4] nouveau: Use helper function
 [PATCH 3/4] nouveau: Check for kms in NvPlatformProbe
 [PATCH 4/4] nouveau: fix entity handling in NvPlatformProbe
Emil Velikov
2012-Nov-01  14:40 UTC
[Nouveau] [PATCH 1/4] nouveau: add nouveau_kernel_mode_enabled()
Used in later patch to remove code duplication and improve
NvPciProbe() and NvPlatformProbe()
Copied verbatim from xf86-video-radeon
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/nv_driver.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
diff --git a/src/nv_driver.c b/src/nv_driver.c
index 9b5b9d6..eff0d47 100644
--- a/src/nv_driver.c
+++ b/src/nv_driver.c
@@ -252,6 +252,74 @@ NVDriverFunc(ScrnInfoPtr scrn, xorgDriverFuncOp op, void
*data)
 }
 
 static Bool
+nouveau_kernel_mode_enabled(ScrnInfoPtr pScrn, struct pci_device *pci_dev)
+{
+	struct nouveau_device *dev = NULL;
+	drmVersion *version;
+	char *busid;
+	int chipset, ret;
+
+	if (!xf86LoaderCheckSymbol("DRICreatePCIBusID")) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "[drm] No DRICreatePCIBusID symbol\n");
+		return FALSE;
+	}
+
+	busid = DRICreatePCIBusID(pci_dev);
+	ret = drmCheckModesettingSupported(busid);
+	if (ret) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[drm] KMS not
enabled\n");
+		free(busid);
+		return FALSE;
+	}
+
+	ret = nouveau_device_open(busid, &dev);
+	if (ret) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "[drm] failed to open device\n");
+		free(busid);
+		return FALSE;
+	}
+	/* Check the version reported by the kernel module.  In theory we
+	 * shouldn't have to do this, as libdrm_nouveau will do its own checks.
+	 * But, we're currently using the kernel patchlevel to also version
+	 * the DRI interface.
+	 */
+	version = drmGetVersion(dev->fd);
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO,	
+		   "[drm] nouveau interface version: %d.%d.%d\n",
+		   version->version_major, version->version_minor,
+		   version->version_patchlevel);
+	drmFree(version);
+
+	chipset = dev->chipset;
+	nouveau_device_del(&dev);
+	free(busid);
+
+	switch (chipset & 0xf0) {
+	case 0x00:
+	case 0x10:
+	case 0x20:
+	case 0x30:
+	case 0x40:
+	case 0x60:
+	case 0x50:
+	case 0x80:
+	case 0x90:
+	case 0xa0:
+	case 0xc0:
+	case 0xd0:
+	case 0xe0:
+		break;
+	default:
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "Unknown chipset: NV%02x\n", chipset);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+static Bool
 NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev,
 	   intptr_t match_data)
 {
-- 
1.8.0
Emil Velikov
2012-Nov-01  14:40 UTC
[Nouveau] [PATCH 2/4] nouveau: Use helper function nouveau_kernel_mode_enabled()
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/nv_driver.c | 64 ++++++---------------------------------------------------
 1 file changed, 6 insertions(+), 58 deletions(-)
diff --git a/src/nv_driver.c b/src/nv_driver.c
index eff0d47..911b05d 100644
--- a/src/nv_driver.c
+++ b/src/nv_driver.c
@@ -319,6 +319,7 @@ nouveau_kernel_mode_enabled(ScrnInfoPtr pScrn, struct
pci_device *pci_dev)
 
 	return TRUE;
 }
+
 static Bool
 NVPciProbe(DriverPtr drv, int entity_num, struct pci_device *pci_dev,
 	   intptr_t match_data)
@@ -328,72 +329,19 @@ NVPciProbe(DriverPtr drv, int entity_num, struct
pci_device *pci_dev,
 		  (pci_dev->vendor_id << 16) | pci_dev->device_id, NULL },
 		{ -1, -1, NULL }
 	};
-	struct nouveau_device *dev = NULL;
 	EntityInfoPtr pEnt = NULL;
 	ScrnInfoPtr pScrn = NULL;
-	drmVersion *version;
-	int chipset, ret;
-	char *busid;
-
-	if (!xf86LoaderCheckSymbol("DRICreatePCIBusID")) {
-		xf86DrvMsg(-1, X_ERROR, "[drm] No DRICreatePCIBusID symbol\n");
-		return FALSE;
-	}
-	busid = DRICreatePCIBusID(pci_dev);
-
-	ret = nouveau_device_open(busid, &dev);
-	if (ret) {
-		xf86DrvMsg(-1, X_ERROR, "[drm] failed to open device\n");
-		free(busid);
-		return FALSE;
-	}
-
-	/* Check the version reported by the kernel module.  In theory we
-	 * shouldn't have to do this, as libdrm_nouveau will do its own checks.
-	 * But, we're currently using the kernel patchlevel to also version
-	 * the DRI interface.
-	 */
-	version = drmGetVersion(dev->fd);
-	xf86DrvMsg(-1, X_INFO, "[drm] nouveau interface version:
%d.%d.%d\n",
-		   version->version_major, version->version_minor,
-		   version->version_patchlevel);
-	drmFree(version);
-
-	chipset = dev->chipset;
-	nouveau_device_del(&dev);
-
-	ret = drmCheckModesettingSupported(busid);
-	free(busid);
-	if (ret) {
-		xf86DrvMsg(-1, X_ERROR, "[drm] KMS not enabled\n");
-		return FALSE;
-	}
-
-	switch (chipset & 0xf0) {
-	case 0x00:
-	case 0x10:
-	case 0x20:
-	case 0x30:
-	case 0x40:
-	case 0x60:
-	case 0x50:
-	case 0x80:
-	case 0x90:
-	case 0xa0:
-	case 0xc0:
-	case 0xd0:
-	case 0xe0:
-		break;
-	default:
-		xf86DrvMsg(-1, X_ERROR, "Unknown chipset: NV%02x\n", chipset);
-		return FALSE;
-	}
+	int ret;
 
 	pScrn = xf86ConfigPciEntity(pScrn, 0, entity_num, NVChipsets,
 				    NULL, NULL, NULL, NULL, NULL);
 	if (!pScrn)
 		return FALSE;
 
+	if (!nouveau_kernel_mode_enabled(pScrn, pci_dev)) {
+		return FALSE;
+	}
+
 	pScrn->driverVersion    = NV_VERSION;
 	pScrn->driverName       = NV_DRIVER_NAME;
 	pScrn->name             = NV_NAME;
-- 
1.8.0
Emil Velikov
2012-Nov-01  14:40 UTC
[Nouveau] [PATCH 3/4] nouveau: Check for kms in NvPlatformProbe
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/nv_driver.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/nv_driver.c b/src/nv_driver.c
index 911b05d..c1a50cd 100644
--- a/src/nv_driver.c
+++ b/src/nv_driver.c
@@ -57,6 +57,8 @@ static void    NVFreeScreen(FREE_SCREEN_ARGS_DECL);
 
 static Bool	NVMapMem(ScrnInfoPtr pScrn);
 static Bool	NVUnmapMem(ScrnInfoPtr pScrn);
+static Bool	nouveau_kernel_mode_enabled(ScrnInfoPtr pScrn,
+				   struct pci_device *pci_dev);
 
 #define NOUVEAU_PCI_DEVICE(_vendor_id, _device_id)                            
\
 	{ (_vendor_id), (_device_id), PCI_MATCH_ANY, PCI_MATCH_ANY,            \
@@ -76,7 +78,9 @@ static Bool NVPciProbe (	DriverPtr 		drv,
 #ifdef XSERVER_PLATFORM_BUS
 static Bool
 NVPlatformProbe(DriverPtr driver,
-            int entity_num, int flags, struct xf86_platform_device *dev,
intptr_t dev_match_data)
+		   int entity_num, int flags,
+		   struct xf86_platform_device *dev,
+		   intptr_t dev_match_data)
 {
 	ScrnInfoPtr scrn = NULL;
 	uint32_t scr_flags = 0;
@@ -84,12 +88,17 @@ NVPlatformProbe(DriverPtr driver,
 	if (!dev->pdev)
 		return FALSE;
 
-        if (flags & PLATFORM_PROBE_GPU_SCREEN)
-               scr_flags = XF86_ALLOCATE_GPU_SCREEN;
+	if (flags & PLATFORM_PROBE_GPU_SCREEN)
+		scr_flags = XF86_ALLOCATE_GPU_SCREEN;
 
 	scrn = xf86AllocateScreen(driver, scr_flags);
+	if (!scrn)
+		return FALSE;
 	xf86AddEntityToScreen(scrn, entity_num);
 
+	if (!nouveau_kernel_mode_enabled(scrn, dev->pdev))
+		return FALSE;
+
 	scrn->driverVersion    = NV_VERSION;
 	scrn->driverName       = NV_DRIVER_NAME;
 	scrn->name             = NV_NAME;
@@ -102,7 +111,8 @@ NVPlatformProbe(DriverPtr driver,
 	scrn->EnterVT          = NVEnterVT;
 	scrn->LeaveVT          = NVLeaveVT;
 	scrn->FreeScreen       = NVFreeScreen;
-	return scrn != NULL;
+
+	return TRUE;
 }
 #endif
 
-- 
1.8.0
Emil Velikov
2012-Nov-01  14:40 UTC
[Nouveau] [PATCH 4/4] nouveau: fix entity handling in NvPlatformProbe
Ensure that the entity is shareable, making ZaphodHeads work again
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=56347
Connect entity to screen - should fix relative screen positioning in xorg.conf
Reported-by: shox on IRC
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/nv_driver.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/src/nv_driver.c b/src/nv_driver.c
index c1a50cd..7c7f822 100644
--- a/src/nv_driver.c
+++ b/src/nv_driver.c
@@ -84,6 +84,7 @@ NVPlatformProbe(DriverPtr driver,
 {
 	ScrnInfoPtr scrn = NULL;
 	uint32_t scr_flags = 0;
+	EntityInfoPtr pEnt = NULL;
 
 	if (!dev->pdev)
 		return FALSE;
@@ -112,6 +113,11 @@ NVPlatformProbe(DriverPtr driver,
 	scrn->LeaveVT          = NVLeaveVT;
 	scrn->FreeScreen       = NVFreeScreen;
 
+	xf86SetEntitySharable(entity_num);
+
+	pEnt = xf86GetEntityInfo(entity_num);
+	xf86SetEntityInstanceForScreen(scrn, pEnt->index,
xf86GetNumEntityInstances(pEnt->index) - 1);
+	free(pEnt);
 	return TRUE;
 }
 #endif
-- 
1.8.0
Emil Velikov
2012-Nov-02  00:51 UTC
[Nouveau] [PATCH 0/4] nouveau: xserver 1.13 compat fixes
On Thu, 01 Nov 2012 14:40:54 -0000, Emil Velikov wrote:> Here are a few patches adding some missing functions in > NvPlatformProbe, which iirc is being used as of xserver 1.13 > > First patch adds a nouveau_kernel_mode_enabled helper, similar > to xf86-video-radeon > Second and third use the function in Nv{Pci,Platform}Probe > And last one ensures we can still use ZaphodHead and relative > head positioning via xorg.conf > > The coding style may be a bit off, despite my best attempts > > Please review and commentA few notes * patch1 - it may be better to split the function to has_kms and is_gpu_supported * patch2 - introduced a minor memory leak, when has_kms fails * patch3 - is ok * patch4 - is incomplete, it turns out that we need to explicitly check if IsSharable and SetShared() it. Note radeon and others would need a similar fix. Intel is OK I'm planning to consolidate the common parts of Nv{Pci,Platform}Probe() into a common function, and send another series ~Emil> > [PATCH 1/4] nouveau: add nouveau_kernel_mode_enabled() > [PATCH 2/4] nouveau: Use helper function > [PATCH 3/4] nouveau: Check for kms in NvPlatformProbe > [PATCH 4/4] nouveau: fix entity handling in NvPlatformProbe
Possibly Parallel Threads
- [PATCH (nouveau)] Add xwayland support
- Bugfix + dri1 cleanup patches
- [PATCH 1/2] present: Fixup return type of nouveau_present_init()
- [Patches][nouveau/ddx]: Improvements to bufferswap implementation and timestamping
- Nouveau fails to initialize G94GL / Quadro-FX1800 on aarch64 board