summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJammy Zhou <Jammy.Zhou@amd.com>2016-12-13 12:32:39 +0900
committerMichel Dänzer <michel@daenzer.net>2016-12-19 17:20:25 +0900
commitb5c189473dba2cffc9e4df310ce5c86ceca99a94 (patch)
tree40115f54cc4689ef62eec17b90411c28c273e90b /src
parentedd276185d42962a13faf9ec9eeebc754ef284e7 (diff)
Use render node for DRI3 if available
Signed-off-by: Jammy Zhou <Jammy.Zhou@amd.com> Reviewed-by: Michel Dänzer <michel.daenzer@amd.com> [ Second attempt, let's see if there's any fallout this time... ]
Diffstat (limited to 'src')
-rw-r--r--src/amdgpu_dri3.c37
-rw-r--r--src/amdgpu_probe.h1
2 files changed, 35 insertions, 3 deletions
diff --git a/src/amdgpu_dri3.c b/src/amdgpu_dri3.c
index f87c014..87e3d85 100644
--- a/src/amdgpu_dri3.c
+++ b/src/amdgpu_dri3.c
@@ -40,9 +40,7 @@
#include <errno.h>
#include <libgen.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);
@@ -88,6 +86,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);
+ AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
+ int fd;
+
+ fd = open(pAMDGPUEnt->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);
+ AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
+ int ret = BadAlloc;
+
+ if (pAMDGPUEnt->render_node)
+ ret = open_render_node(screen, out);
+
+ if (ret != Success)
+ ret = open_master_node(screen, out);
+
+ return ret;
+}
+
#if DRI3_SCREEN_INFO_VERSION >= 1 && XORG_VERSION_CURRENT <= XORG_VERSION_NUMERIC(1,18,99,1,0)
static int
@@ -229,6 +257,9 @@ Bool
amdgpu_dri3_screen_init(ScreenPtr screen)
{
ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+ AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
+
+ pAMDGPUEnt->render_node = drmGetRenderDeviceNameFromFd(pAMDGPUEnt->fd);
if (!dri3_screen_init(screen, &amdgpu_dri3_screen_info)) {
xf86DrvMsg(scrn->scrnIndex, X_WARNING,
diff --git a/src/amdgpu_probe.h b/src/amdgpu_probe.h
index 0302d02..0f43233 100644
--- a/src/amdgpu_probe.h
+++ b/src/amdgpu_probe.h
@@ -68,6 +68,7 @@ typedef struct {
ScrnInfoPtr primary_scrn;
ScrnInfoPtr secondary_scrn;
struct xf86_platform_device *platform_dev;
+ char *render_node;
} AMDGPUEntRec, *AMDGPUEntPtr;
extern const OptionInfoRec *AMDGPUOptionsWeak(void);