[PATCH xf86-video-ati] Add support for server managed fds

Hans de Goede hdegoede at redhat.com
Tue Mar 11 03:09:19 PDT 2014


Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/radeon_kms.c   | 60 +++++++++++++++++++++++++++++++++++++++++++++---------
 src/radeon_probe.c |  5 +++++
 src/radeon_probe.h |  2 ++
 3 files changed, 57 insertions(+), 10 deletions(-)

diff --git a/src/radeon_kms.c b/src/radeon_kms.c
index 4a6c38e..6c5994c 100644
--- a/src/radeon_kms.c
+++ b/src/radeon_kms.c
@@ -180,7 +180,11 @@ static void RADEONFreeRec(ScrnInfoPtr pScrn)
         pRADEONEnt = pPriv->ptr;
         pRADEONEnt->fd_ref--;
         if (!pRADEONEnt->fd_ref) {
-            drmClose(pRADEONEnt->fd);
+#ifdef XF86_PDEV_SERVER_FD
+            if (!(pRADEONEnt->platform_dev &&
+                    pRADEONEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
+#endif
+                drmClose(pRADEONEnt->fd);
             pRADEONEnt->fd = 0;
         }
     }
@@ -599,6 +603,15 @@ static Bool radeon_open_drm_master(ScrnInfoPtr pScrn)
 	goto out;
     }
 
+#if defined(ODEV_ATTRIB_FD)
+    if (pRADEONEnt->platform_dev) {
+        info->dri2.drm_fd = xf86_get_platform_device_int_attrib(
+                                pRADEONEnt->platform_dev, ODEV_ATTRIB_FD, -1);
+        if (info->dri2.drm_fd != -1)
+            goto got_fd;
+    }
+#endif
+
 #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,9,99,901,0)
     XNFasprintf(&busid, "pci:%04x:%02x:%02x.%d",
                 dev->domain, dev->bus, dev->dev, dev->func);
@@ -636,6 +649,7 @@ static Bool radeon_open_drm_master(ScrnInfoPtr pScrn)
 	return FALSE;
     }
 
+ got_fd:
     pRADEONEnt->fd = info->dri2.drm_fd;
     pRADEONEnt->fd_ref = 1;
  out:
@@ -1108,6 +1122,7 @@ static Bool RADEONCloseScreen_KMS(CLOSE_SCREEN_ARGS_DECL)
 {
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     RADEONInfoPtr  info  = RADEONPTR(pScrn);
+    RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn);
 
     xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
 		   "RADEONCloseScreen\n");
@@ -1126,7 +1141,11 @@ static Bool RADEONCloseScreen_KMS(CLOSE_SCREEN_ARGS_DECL)
     if (info->accel_state->use_vbos)
         radeon_vbo_free_lists(pScrn);
 
-    drmDropMaster(info->dri2.drm_fd);
+#ifdef XF86_PDEV_SERVER_FD
+    if (!(pRADEONEnt->platform_dev &&
+            pRADEONEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
+#endif
+        drmDropMaster(info->dri2.drm_fd);
 
     drmmode_fini(pScrn, &info->drmmode);
     if (info->dri2.enabled)
@@ -1158,6 +1177,7 @@ Bool RADEONScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
 {
     ScrnInfoPtr    pScrn = xf86ScreenToScrn(pScreen);
     RADEONInfoPtr  info  = RADEONPTR(pScrn);
+    RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn);
     int            subPixelOrder = SubPixelUnknown;
     char*          s;
     void *front_ptr;
@@ -1172,11 +1192,18 @@ Bool RADEONScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
 			  pScrn->defaultVisual)) return FALSE;
     miSetPixmapDepths ();
 
-    ret = drmSetMaster(info->dri2.drm_fd);
-    if (ret) {
-        ErrorF("Unable to retrieve master\n");
-        return FALSE;
+#ifdef XF86_PDEV_SERVER_FD
+    if (!(pRADEONEnt->platform_dev &&
+            pRADEONEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
+#endif
+    {
+        ret = drmSetMaster(info->dri2.drm_fd);
+        if (ret) {
+            ErrorF("Unable to retrieve master\n");
+            return FALSE;
+        }
     }
+
     info->directRenderingEnabled = FALSE;
     if (info->r600_shadow_fb == FALSE)
         info->directRenderingEnabled = radeon_dri2_screen_init(pScreen);
@@ -1389,15 +1416,23 @@ Bool RADEONEnterVT_KMS(VT_FUNC_ARGS_DECL)
 {
     SCRN_INFO_PTR(arg);
     RADEONInfoPtr  info  = RADEONPTR(pScrn);
+    RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn);
     int ret;
 
     xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
 		   "RADEONEnterVT_KMS\n");
 
 
-    ret = drmSetMaster(info->dri2.drm_fd);
-    if (ret)
-	ErrorF("Unable to retrieve master\n");
+#ifdef XF86_PDEV_SERVER_FD
+    if (!(pRADEONEnt->platform_dev &&
+            pRADEONEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
+#endif
+    {
+        ret = drmSetMaster(info->dri2.drm_fd);
+        if (ret)
+            ErrorF("Unable to retrieve master\n");
+    }
+
     info->accel_state->XInited3D = FALSE;
     info->accel_state->engineMode = EXA_ENGINEMODE_UNKNOWN;
 
@@ -1414,11 +1449,16 @@ void RADEONLeaveVT_KMS(VT_FUNC_ARGS_DECL)
 {
     SCRN_INFO_PTR(arg);
     RADEONInfoPtr  info  = RADEONPTR(pScrn);
+    RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn);
 
     xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, RADEON_LOGLEVEL_DEBUG,
 		   "RADEONLeaveVT_KMS\n");
 
-    drmDropMaster(info->dri2.drm_fd);
+#ifdef XF86_PDEV_SERVER_FD
+    if (!(pRADEONEnt->platform_dev &&
+            pRADEONEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
+#endif
+        drmDropMaster(info->dri2.drm_fd);
 
     xf86RotateFreeShadow(pScrn);
 
diff --git a/src/radeon_probe.c b/src/radeon_probe.c
index 2d3c58e..ad1e96e 100644
--- a/src/radeon_probe.c
+++ b/src/radeon_probe.c
@@ -202,6 +202,10 @@ RADEONDriverFunc(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
 	    flag = (CARD32 *)data;
 	    (*flag) = 0;
 	    return TRUE;
+#if XORG_VERSION_CURRENT > XORG_VERSION_NUMERIC(1,15,99,0,0)
+	case SUPPORTS_SERVER_FDS:
+	    return TRUE;
+#endif
 	default:
 	    return FALSE;
     }
@@ -272,6 +276,7 @@ radeon_platform_probe(DriverPtr pDriver,
             pRADEONEnt = pPriv->ptr;
             pRADEONEnt->HasSecondary = TRUE;
         }
+        pRADEONEnt->platform_dev = dev;
     }
 
     free(pEnt);
diff --git a/src/radeon_probe.h b/src/radeon_probe.h
index cea6695..4f5e645 100644
--- a/src/radeon_probe.h
+++ b/src/radeon_probe.h
@@ -42,6 +42,7 @@
 #include "randrstr.h"
 
 #include "xf86Crtc.h"
+#include "xf86platformBus.h"
 
 #include "compat-api.h"
 #include "exa.h"
@@ -136,6 +137,7 @@ typedef struct
     int fd_ref;
     unsigned long     fd_wakeup_registered; /* server generation for which fd has been registered for wakeup handling */
     int fd_wakeup_ref;
+    struct xf86_platform_device *platform_dev;
 } RADEONEntRec, *RADEONEntPtr;
 
 extern const OptionInfoRec *RADEONOptionsWeak(void);
-- 
1.9.0



More information about the xorg-devel mailing list