[PATCH xf86-video-amdgpu 01/19] Move amdgpu_bus_id/amgpu_kernel_mode within amdgpu_kernel_open_fd

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


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

Small step towards unifying the code paths and removing a handful of
duplication.

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

diff --git a/src/amdgpu_probe.c b/src/amdgpu_probe.c
index 0217060..075e5c1 100644
--- a/src/amdgpu_probe.c
+++ b/src/amdgpu_probe.c
@@ -112,9 +112,12 @@ static Bool amdgpu_kernel_mode_enabled(ScrnInfoPtr pScrn, char *busIdString)
 	return TRUE;
 }
 
-static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, char *busid,
+static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn,
+				 struct pci_device *pci_dev,
 				 struct xf86_platform_device *platform_dev)
 {
+	struct pci_device *dev;
+	char *busid;
 	int fd;
 
 #ifdef XF86_PDEV_SERVER_FD
@@ -126,11 +129,26 @@ static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, char *busid,
 	}
 #endif
 
+	if (platform_dev)
+		dev = platform_dev->pdev;
+	else
+		dev = pci_dev;
+
+	busid = amdgpu_bus_id(pScrn, dev);
+	if (!busid)
+		return -1;
+
+	if (!amdgpu_kernel_mode_enabled(pScrn, busid)) {
+		free(busid);
+		return -1;
+	}
+
 	fd = drmOpen(NULL, busid);
 	if (fd == -1)
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 			   "[drm] Failed to open DRM device for %s: %s\n",
 			   busid, strerror(errno));
+	free(busid);
 	return fd;
 }
 
@@ -145,12 +163,12 @@ void amdgpu_kernel_close_fd(AMDGPUEntPtr pAMDGPUEnt)
 }
 
 static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn, AMDGPUEntPtr pAMDGPUEnt,
-				   char *busid)
+				   struct pci_device *pci_dev)
 {
 	drmSetVersion sv;
 	int err;
 
-	pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, busid, NULL);
+	pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, pci_dev, NULL);
 	if (pAMDGPUEnt->fd == -1)
 		return FALSE;
 
@@ -176,7 +194,6 @@ static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn, AMDGPUEntPtr pAMDGPUEnt,
 static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 {
 	ScrnInfoPtr pScrn = NULL;
-	char *busid;
 	EntityInfoPtr pEnt = NULL;
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
@@ -187,10 +204,6 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 	if (!pScrn)
 		return FALSE;
 
-	busid = amdgpu_bus_id(pScrn, pci_dev);
-	if (!amdgpu_kernel_mode_enabled(pScrn, busid))
-		goto error;
-
 	pScrn->driverVersion = AMDGPU_VERSION_CURRENT;
 	pScrn->driverName = AMDGPU_DRIVER_NAME;
 	pScrn->name = AMDGPU_NAME;
@@ -226,7 +239,7 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 			goto error;
 
 		pAMDGPUEnt = pPriv->ptr;
-		if (!amdgpu_open_drm_master(pScrn, pAMDGPUEnt, busid))
+		if (!amdgpu_open_drm_master(pScrn, pAMDGPUEnt, pci_dev))
 			goto error;
 
 		pAMDGPUEnt->fd_ref = 1;
@@ -249,7 +262,6 @@ static Bool amdgpu_get_scrninfo(int entity_num, struct pci_device *pci_dev)
 								 index)
 				       - 1);
 	free(pEnt);
-	free(busid);
 
 	return TRUE;
 
@@ -257,7 +269,6 @@ error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
 	free(pEnt);
-	free(busid);
 	return FALSE;
 }
 
@@ -294,7 +305,6 @@ amdgpu_platform_probe(DriverPtr pDriver,
 {
 	ScrnInfoPtr pScrn;
 	int scr_flags = 0;
-	char *busid;
 	EntityInfoPtr pEnt = NULL;
 	DevUnion *pPriv;
 	AMDGPUEntPtr pAMDGPUEnt;
@@ -310,13 +320,6 @@ amdgpu_platform_probe(DriverPtr pDriver,
 		xf86SetEntityShared(entity_num);
 	xf86AddEntityToScreen(pScrn, entity_num);
 
-	busid = amdgpu_bus_id(pScrn, dev->pdev);
-	if (!busid)
-		return FALSE;
-
-	if (!amdgpu_kernel_mode_enabled(pScrn, busid))
-		goto error;
-
 	pScrn->driverVersion = AMDGPU_VERSION_CURRENT;
 	pScrn->driverName = AMDGPU_DRIVER_NAME;
 	pScrn->name = AMDGPU_NAME;
@@ -349,7 +352,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
 		pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
 		pAMDGPUEnt = pPriv->ptr;
 		pAMDGPUEnt->platform_dev = dev;
-		pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, busid, dev);
+		pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, NULL, dev);
 		if (pAMDGPUEnt->fd < 0)
 			goto error;
 
@@ -373,7 +376,6 @@ amdgpu_platform_probe(DriverPtr pDriver,
 								 index)
 				       - 1);
 	free(pEnt);
-	free(busid);
 
 	return TRUE;
 
@@ -381,7 +383,6 @@ error_amdgpu:
 	amdgpu_kernel_close_fd(pAMDGPUEnt);
 error:
 	free(pEnt);
-	free(busid);
 	return FALSE;
 }
 #endif
-- 
2.16.0



More information about the amd-gfx mailing list