Commit a79735ab authored by Tom Denis's avatar Tom Denis Committed by Michel Dänzer
Browse files

Add support for server managed fds



Based on radeon commit ed0cfbb4fe77146b0b38f777bc28f3a4ea6da07f

and 2nd patch:

Fix building on older servers without xf86platformBus.h

Based on radeon commit b50da3b96c212086cb58501dbe988d64f1f35b6d
Signed-off-by: Tom Denis's avatarTom St Denis <tom.stdenis@amd.com>

[ Michel Dänzer: Fixed up amdgpu_kernel_open_fd() not to need
  AMDGPUEntPriv(), which doesn't work yet at that point ]
Signed-off-by: Michel Dänzer's avatarMichel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Michel Dänzer's avatarMichel Dänzer <michel.daenzer@amd.com>
parent b93934a9
......@@ -126,7 +126,11 @@ static void AMDGPUFreeRec(ScrnInfoPtr pScrn)
pAMDGPUEnt->fd_ref--;
if (!pAMDGPUEnt->fd_ref) {
amdgpu_device_deinitialize(pAMDGPUEnt->pDev);
drmClose(pAMDGPUEnt->fd);
#ifdef XF86_PDEV_SERVER_FD
if (!(pAMDGPUEnt->platform_dev &&
pAMDGPUEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
#endif
drmClose(pAMDGPUEnt->fd);
pAMDGPUEnt->fd = 0;
}
}
......@@ -937,6 +941,41 @@ void AMDGPUUnblank(ScrnInfoPtr pScrn)
}
}
static Bool amdgpu_set_drm_master(ScrnInfoPtr pScrn)
{
AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(pScrn);
int err;
#ifdef XF86_PDEV_SERVER_FD
if (pAMDGPUEnt->platform_dev &&
(pAMDGPUEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
return TRUE;
#endif
err = drmSetMaster(info->dri2.drm_fd);
if (err)
ErrorF("Unable to retrieve master\n");
return err == 0;
}
static void amdgpu_drop_drm_master(ScrnInfoPtr pScrn)
{
AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(pScrn);
#ifdef XF86_PDEV_SERVER_FD
if (pAMDGPUEnt->platform_dev &&
(pAMDGPUEnt->platform_dev->flags & XF86_PDEV_SERVER_FD))
return;
#endif
drmDropMaster(info->dri2.drm_fd);
}
static Bool AMDGPUSaveScreen_KMS(ScreenPtr pScreen, int mode)
{
ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
......@@ -980,8 +1019,7 @@ static Bool AMDGPUCloseScreen_KMS(CLOSE_SCREEN_ARGS_DECL)
DeleteCallback(&FlushCallback, amdgpu_flush_callback, pScrn);
amdgpu_sync_close(pScreen);
drmDropMaster(info->dri2.drm_fd);
amdgpu_drop_drm_master(pScrn);
drmmode_fini(pScrn, &info->drmmode);
if (info->dri2.enabled) {
......@@ -1019,7 +1057,6 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
int driLevel;
char *s;
void *front_ptr;
int ret;
pScrn->fbOffset = 0;
......@@ -1030,11 +1067,9 @@ Bool AMDGPUScreenInit_KMS(SCREEN_INIT_ARGS_DECL)
return FALSE;
miSetPixmapDepths();
ret = drmSetMaster(info->dri2.drm_fd);
if (ret) {
ErrorF("Unable to retrieve master\n");
if (!amdgpu_set_drm_master(pScrn))
return FALSE;
}
info->directRenderingEnabled = FALSE;
if (info->shadow_fb == FALSE)
info->directRenderingEnabled = amdgpu_dri2_screen_init(pScreen);
......@@ -1254,14 +1289,11 @@ Bool AMDGPUEnterVT_KMS(VT_FUNC_ARGS_DECL)
{
SCRN_INFO_PTR(arg);
AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
int ret;
xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, AMDGPU_LOGLEVEL_DEBUG,
"AMDGPUEnterVT_KMS\n");
ret = drmSetMaster(info->dri2.drm_fd);
if (ret)
ErrorF("Unable to retrieve master\n");
amdgpu_set_drm_master(pScrn);
pScrn->vtSema = TRUE;
......@@ -1274,12 +1306,11 @@ Bool AMDGPUEnterVT_KMS(VT_FUNC_ARGS_DECL)
void AMDGPULeaveVT_KMS(VT_FUNC_ARGS_DECL)
{
SCRN_INFO_PTR(arg);
AMDGPUInfoPtr info = AMDGPUPTR(pScrn);
xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, AMDGPU_LOGLEVEL_DEBUG,
"AMDGPULeaveVT_KMS\n");
drmDropMaster(info->dri2.drm_fd);
amdgpu_drop_drm_master(pScrn);
xf86RotateFreeShadow(pScrn);
drmmode_scanout_free(pScrn);
......
......@@ -112,11 +112,21 @@ static Bool amdgpu_kernel_mode_enabled(ScrnInfoPtr pScrn,
return TRUE;
}
static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, struct pci_device *dev)
static int amdgpu_kernel_open_fd(ScrnInfoPtr pScrn, struct pci_device *dev,
struct xf86_platform_device *platform_dev)
{
char *busid;
int fd;
#ifdef XF86_PDEV_SERVER_FD
if (platform_dev) {
fd = xf86_get_platform_device_int_attrib(platform_dev,
ODEV_ATTRIB_FD, -1);
if (fd != -1)
return 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);
......@@ -153,7 +163,7 @@ static Bool amdgpu_open_drm_master(ScrnInfoPtr pScrn)
return TRUE;
}
info->dri2.drm_fd = amdgpu_kernel_open_fd(pScrn, info->PciInfo);
info->dri2.drm_fd = amdgpu_kernel_open_fd(pScrn, info->PciInfo, NULL);
if (info->dri2.drm_fd == -1)
return FALSE;
......@@ -280,7 +290,11 @@ static Bool AMDGPUDriverFunc(ScrnInfoPtr scrn, xorgDriverFuncOp op, void *data)
flag = (CARD32 *) data;
(*flag) = 0;
return TRUE;
default:
#if XORG_VERSION_CURRENT > XORG_VERSION_NUMERIC(1,15,99,0,0)
case SUPPORTS_SERVER_FDS:
return TRUE;
#endif
default:
return FALSE;
}
}
......@@ -343,7 +357,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
pPriv->ptr = xnfcalloc(sizeof(AMDGPUEntRec), 1);
pAMDGPUEnt = pPriv->ptr;
pAMDGPUEnt->HasSecondary = FALSE;
pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, dev->pdev);
pAMDGPUEnt->fd = amdgpu_kernel_open_fd(pScrn, dev->pdev, dev);
if (pAMDGPUEnt->fd < 0)
goto error_fd;
......@@ -361,6 +375,7 @@ amdgpu_platform_probe(DriverPtr pDriver,
pAMDGPUEnt = pPriv->ptr;
pAMDGPUEnt->HasSecondary = TRUE;
}
pAMDGPUEnt->platform_dev = dev;
xf86SetEntityInstanceForScreen(pScrn, pEnt->index,
xf86GetNumEntityInstances(pEnt->
......
......@@ -37,12 +37,17 @@
#define _AMDGPU_PROBE_H_ 1
#include <stdint.h>
#include "xorg-server.h"
#include "xf86str.h"
#include "xf86DDC.h"
#include "randrstr.h"
#include "xf86Crtc.h"
#ifdef XSERVER_PLATFORM_BUS
#include "xf86platformBus.h"
#endif
#include <amdgpu.h>
#include "compat-api.h"
......@@ -82,6 +87,7 @@ typedef struct {
unsigned long fd_wakeup_registered; /* server generation for which fd has been registered for wakeup handling */
int fd_wakeup_ref;
unsigned int assigned_crtcs;
struct xf86_platform_device *platform_dev;
} AMDGPUEntRec, *AMDGPUEntPtr;
extern const OptionInfoRec *AMDGPUOptionsWeak(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment