[PATCH xf86-video-amdgpu] Use render node for DRI3 if available (v2)
Jammy Zhou
Jammy.Zhou at amd.com
Fri Nov 20 01:03:05 PST 2015
v2: refine the code
Signed-off-by: Jammy Zhou <Jammy.Zhou at amd.com>
---
configure.ac | 2 +-
src/amdgpu_dri3.c | 37 ++++++++++++++++++++++++++++++++++---
src/amdgpu_probe.h | 1 +
3 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/configure.ac b/configure.ac
index b8bae49..919cf3c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -129,7 +129,7 @@ if test "x$GLAMOR_XV" = xyes; then
fi
# Checks for libraries.
-PKG_CHECK_MODULES(LIBDRM, [libdrm >= 2.4.46])
+PKG_CHECK_MODULES(LIBDRM, [libdrm >= 2.4.60])
PKG_CHECK_MODULES(LIBDRM_AMDGPU, [libdrm_amdgpu])
PKG_CHECK_MODULES(EGL, $LIBEGL, [EGL=yes], [EGL=no])
PKG_CHECK_MODULES(LIBEPOXY, $LIBEPOXY, [LIBEPOXY=yes], [LIBEPOXY=no])
diff --git a/src/amdgpu_dri3.c b/src/amdgpu_dri3.c
index 73a79ac..c4b40d0 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);
+ 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;
+}
+
static PixmapPtr amdgpu_dri3_pixmap_from_fd(ScreenPtr screen,
int fd,
CARD16 width,
@@ -173,6 +201,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 5194f4c..6edd4a1 100644
--- a/src/amdgpu_probe.h
+++ b/src/amdgpu_probe.h
@@ -86,6 +86,7 @@ typedef struct {
int fd_wakeup_ref;
unsigned int assigned_crtcs;
struct xf86_platform_device *platform_dev;
+ char *render_node;
} AMDGPUEntRec, *AMDGPUEntPtr;
extern const OptionInfoRec *AMDGPUOptionsWeak(void);
--
1.9.1
More information about the xorg-driver-ati
mailing list