[PATCH xf86-video-amdgpu] Use render node for DRI3 if available

Jammy Zhou Jammy.Zhou at amd.com
Fri Nov 13 00:15:14 PST 2015


Change-Id: Ic96d4f02ad2a61659f10e19e87bd17c5564ea798
Signed-off-by: Jammy Zhou <Jammy.Zhou at amd.com>
---
 src/amdgpu_dri3.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 src/amdgpu_drv.h  |  1 +
 2 files changed, 75 insertions(+), 3 deletions(-)

diff --git a/src/amdgpu_dri3.c b/src/amdgpu_dri3.c
index 73a79ac..7afe39d 100644
--- a/src/amdgpu_dri3.c
+++ b/src/amdgpu_dri3.c
@@ -39,9 +39,7 @@
 #include <fcntl.h>
 #include <errno.h>
 
-
-static int
-amdgpu_dri3_open(ScreenPtr screen, RRProviderPtr provider, int *out)
+static int open_master_node(ScreenPtr screen, int *out)
 {
 	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
 	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
@@ -87,6 +85,36 @@ amdgpu_dri3_open(ScreenPtr screen, RRProviderPtr provider, int *out)
 	return Success;
 }
 
+static int open_render_node(ScreenPtr screen, int *out)
+{
+	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+	int fd;
+
+	fd = open(info->render_node, O_RDWR | O_CLOEXEC);
+	if (fd < 0)
+		return BadAlloc;
+
+	*out = fd;
+	return Success;
+}
+
+static int
+amdgpu_dri3_open(ScreenPtr screen, RRProviderPtr provider, int *out)
+{
+	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+	int ret;
+
+	if (info->render_node)
+		ret = open_render_node(screen, out);
+
+	if (ret != Success)
+		ret = open_master_node(screen, out);
+
+	return ret;
+}
+
 static PixmapPtr amdgpu_dri3_pixmap_from_fd(ScreenPtr screen,
 					    int fd,
 					    CARD16 width,
@@ -169,10 +197,53 @@ static dri3_screen_info_rec amdgpu_dri3_screen_info = {
 	.fd_from_pixmap = amdgpu_dri3_fd_from_pixmap
 };
 
+static char *get_render_node(ScreenPtr screen)
+{
+	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+	drmDevicePtr *devices;
+	uint32_t  num_devices;
+	char *render_node = NULL;
+	int r, i;
+
+	r = drmGetDevices(NULL, 0);
+	if (r < 0)
+		return NULL;
+
+	num_devices = r;
+	devices = calloc(num_devices, sizeof(drmDevicePtr));
+	if (devices == NULL)
+		return NULL;
+
+	r = drmGetDevices(devices, num_devices);
+	if (r < 0) {
+		free(devices);
+		return NULL;
+	}
+
+	for (i = 0; i < num_devices; i++) {
+		if ((devices[i]->businfo.pci->domain == info->PciInfo->domain)
+		  && (devices[i]->businfo.pci->bus == info->PciInfo->bus)
+		  && (devices[i]->businfo.pci->dev == info->PciInfo->dev)
+		  && (devices[i]->businfo.pci->func == info->PciInfo->func))
+			break;
+	}
+
+	if (i < num_devices)
+		render_node = strdup(devices[i]->nodes[DRM_NODE_RENDER]);
+
+	drmFreeDevices(devices, num_devices);
+	free(devices);
+	return render_node;
+}
+
 Bool
 amdgpu_dri3_screen_init(ScreenPtr screen)
 {
 	ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+
+	info->render_node = get_render_node(screen);
 
 	if (!dri3_screen_init(screen, &amdgpu_dri3_screen_info)) {
 		xf86DrvMsg(scrn->scrnIndex, X_WARNING,
diff --git a/src/amdgpu_drv.h b/src/amdgpu_drv.h
index 4797693..08eba69 100644
--- a/src/amdgpu_drv.h
+++ b/src/amdgpu_drv.h
@@ -202,6 +202,7 @@ typedef struct {
 
 	Bool directRenderingEnabled;
 	struct amdgpu_dri2 dri2;
+	char *render_node;
 
 	/* accel */
 	PixmapPtr fbcon_pixmap;
-- 
1.9.1



More information about the xorg-driver-ati mailing list