[PATCH xf86-video-amdgpu 06/19] Introduce amdgpu_device_setup helper

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


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

It folds the device specifics (open fd, device init) into a single
place.

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

diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index ec132e0..afc8d4c 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -165,6 +165,35 @@ void amdgpu_kernel_close_fd(AMDGPUEntPtr pAMDGPUEnt)
 	pAMDGPUEnt->fd = -1;
 }
 
+static Bool amdgpu_device_setup(ScrnInfoPtr pScrn,
+				struct pci_device *pci_dev,
+				struct xf86_platform_device *platform_dev,
+				AMDGPUEntPtr pAMDGPUEnt)
+{
+	uint32_t major_version;
+	uint32_t minor_version;
+
+	pAMDGPUEnt->platform_dev = platform_dev;
+	pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, pci_dev, platform_dev);
+	if (pAMDGPUEnt->fd < 0)
+		return FALSE;
+
+	if (amdgpu_device_initialize(pAMDGPUEnt->fd,
+				     &major_version,
+				     &minor_version,
+				     &pAMDGPUEnt->pDev)) {
+		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			   "amdgpu_device_initialize failed\n");
+		goto error_amdgpu;
+	}
+
+	return TRUE;
+
+error_amdgpu:
+	amdgpu_kernel_close_fd(pAMDGPUEnt);
+	return FALSE;
+}
+
 static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 {
 	ScrnInfoPtr pScrn = NULL;
@@ -205,28 +234,16 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 	pPriv = xf86GetEntityPrivate(pEnt->index, gAMDGPUEntityIndex);
 
 	if (!pPriv->ptr) {
-		uint32_t major_version;
-		uint32_t minor_version;
-
 		pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
 		if (!pPriv->ptr)
 			goto error;
 
-		pAMDGPUEnt = pPriv->ptr;
-		pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, pci_dev, NULL);
-		if (pAMDGPUEnt->fd < 0)
+		if (!amdgpu_device_setup(pScrn, pci_dev, NULL, pPriv->ptr))
 			goto error;
 
+		pAMDGPUEnt = pPriv->ptr;
 		pAMDGPUEnt->fd_ref = 1;
 
-		if (amdgpu_device_initialize(pAMDGPUEnt->fd,
-					     &major_version,
-					     &minor_version,
-					     &pAMDGPUEnt->pDev)) {
-			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-				   "amdgpu_device_initialize failed\n");
-			goto error_amdgpu;
-		}
 	} else {
 		pAMDGPUEnt = pPriv->ptr;
 		pAMDGPUEnt->fd_ref++;
@@ -240,8 +257,6 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 
 	return TRUE;
 
-error_amdgpu:
-	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
 	free(pEnt);
 	return FALSE;
@@ -321,26 +336,15 @@ amdgpu_platform_probe(DriverPtr pDriver,
 	pPriv = xf86GetEntityPrivate(pEnt->index, gAMDGPUEntityIndex);
 
 	if (!pPriv->ptr) {
-		uint32_t major_version;
-		uint32_t minor_version;
 
 		pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
-		pAMDGPUEnt = pPriv->ptr;
-		pAMDGPUEnt->platform_dev = dev;
-		pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, NULL, dev);
-		if (pAMDGPUEnt->fd < 0)
+
+		if (!amdgpu_device_setup(pScrn, NULL, dev, pPriv->ptr))
 			goto error;
 
+		pAMDGPUEnt = pPriv->ptr;
 		pAMDGPUEnt->fd_ref = 1;
 
-		if (amdgpu_device_initialize(pAMDGPUEnt->fd,
-					     &major_version,
-					     &minor_version,
-					     &pAMDGPUEnt->pDev)) {
-			xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
-				   "amdgpu_device_initialize failed\n");
-			goto error_amdgpu;
-		}
 	} else {
 		pAMDGPUEnt = pPriv->ptr;
 		pAMDGPUEnt->fd_ref++;
@@ -354,8 +358,6 @@ amdgpu_platform_probe(DriverPtr pDriver,
 
 	return TRUE;
 
-error_amdgpu:
-	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
 	free(pEnt);
 	return FALSE;
-- 
2.16.0



More information about the amd-gfx mailing list