[PATCH xf86-video-amdgpu 07/19] Factor out common code to amdgpu_probe()

Emil Velikov emil.l.velikov at gmail.com
Wed Apr 4 14:29:42 UTC 2018


From: Emil Velikov <emil.velikov at collabora.com>

Keep the distinct pci/platform screen management in the separate probe
entry point and fold the rest into a single function.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 src/amdgpu_probe.c | 71 +++++++-----------------------------------------------
 1 file changed, 9 insertions(+), 62 deletions(-)

diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index afc8d4c..d1ad13f 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -194,16 +194,14 @@ error_amdgpu:
 	return FALSE;
 }
 
-static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
+static Bool
+amdgpu_probe(ScrnInfoPtr pScrn, int entity_num,
+	     struct pci_device *pci_dev, struct xf86_platform_device *dev)
 {
-	ScrnInfoPtr pScrn = NULL;
 	EntityInfoPtr pEnt = NULL;
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
 
-	pScrn = xf86ConfigPciEntity(pScrn, 0, entity_num, NULL,
-				    NULL, NULL, NULL, NULL, NULL);
-
 	if (!pScrn)
 		return FALSE;
 
@@ -211,7 +209,6 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 	pScrn->driverName = AMDGPU_DRIVER_NAME;
 	pScrn->name = AMDGPU_NAME;
 	pScrn->Probe = NULL;
-
 	pScrn->PreInit = AMDGPUPreInit_KMS;
 	pScrn->ScreenInit = AMDGPUScreenInit_KMS;
 	pScrn->SwitchMode = AMDGPUSwitchMode_KMS;
@@ -238,7 +235,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 		if (!pPriv->ptr)
 			goto error;
 
-		if (!amdgpu_device_setup(pScrn, pci_dev, NULL, pPriv->ptr))
+		if (!amdgpu_device_setup(pScrn, pci_dev, dev, pPriv->ptr))
 			goto error;
 
 		pAMDGPUEnt = pPriv->ptr;
@@ -266,7 +263,10 @@ static Bool
 amdgpu_pci_probe(DriverPtr pDriver,
 		 int entity_num, struct pci_device *device, intptr_t match_data)
 {
-	return amdgpu_get_scrninfo(entity_num, device);
+	ScrnInfoPtr pScrn = xf86ConfigPciEntity(NULL, 0, entity_num, NULL,
+						NULL, NULL, NULL, NULL, NULL);
+
+	return amdgpu_probe(pScrn, entity_num, device, NULL);
 }
 
 static Bool AMDGPUDriverFunc(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
@@ -295,9 +295,6 @@ amdgpu_platform_probe(DriverPtr pDriver,
 {
 	ScrnInfoPtr pScrn;
 	int scr_flags = 0;
-	EntityInfoPtr pEnt = NULL;
-	DevUnion *pPriv;
-	AMDGPUEntPtr pAMDGPUEnt;
 
 	if (!dev->pdev)
 		return FALSE;
@@ -310,57 +307,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 		xf86SetEntityShared(entity_num);
 	xf86AddEntityToScreen(pScrn, entity_num);
 
-	pScrn->driverVersion = AMDGPU_VERSION_CURRENT;
-	pScrn->driverName = AMDGPU_DRIVER_NAME;
-	pScrn->name = AMDGPU_NAME;
-	pScrn->Probe = NULL;
-	pScrn->PreInit = AMDGPUPreInit_KMS;
-	pScrn->ScreenInit = AMDGPUScreenInit_KMS;
-	pScrn->SwitchMode = AMDGPUSwitchMode_KMS;
-	pScrn->AdjustFrame = AMDGPUAdjustFrame_KMS;
-	pScrn->EnterVT = AMDGPUEnterVT_KMS;
-	pScrn->LeaveVT = AMDGPULeaveVT_KMS;
-	pScrn->FreeScreen = AMDGPUFreeScreen_KMS;
-	pScrn->ValidMode = AMDGPUValidMode;
-
-	pEnt = xf86GetEntityInfo(entity_num);
-
-	/* Create a AMDGPUEntity for all chips, even with old single head
-	 * Radeon, need to use pAMDGPUEnt for new monitor detection routines.
-	 */
-	xf86SetEntitySharable(entity_num);
-
-	if (gAMDGPUEntityIndex == -1)
-		gAMDGPUEntityIndex = xf86AllocateEntityPrivateIndex();
-
-	pPriv = xf86GetEntityPrivate(pEnt->index, gAMDGPUEntityIndex);
-
-	if (!pPriv->ptr) {
-
-		pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
-
-		if (!amdgpu_device_setup(pScrn, NULL, dev, pPriv->ptr))
-			goto error;
-
-		pAMDGPUEnt = pPriv->ptr;
-		pAMDGPUEnt->fd_ref = 1;
-
-	} else {
-		pAMDGPUEnt = pPriv->ptr;
-		pAMDGPUEnt->fd_ref++;
-	}
-
-	xf86SetEntityInstanceForScreen(pScrn, pEnt->index,
-				       xf86GetNumEntityInstances(pEnt->
-								 index)
-				       - 1);
-	free(pEnt);
-
-	return TRUE;
-
-error:
-	free(pEnt);
-	return FALSE;
+	return amdgpu_probe(pScrn, entity_num, NULL, dev);
 }
 #endif
 
-- 
2.16.0



More information about the amd-gfx mailing list