From 3d7861fe112f25874319d4cdc12b745fbcd359cf Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Mon, 17 Mar 2014 10:38:13 +0100 Subject: Add radeon_get_drm_master_fd helper function This is a preparation patch for adding server-managed-fd support without it turning into a goto fest. Signed-off-by: Hans de Goede --- src/radeon_kms.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) (limited to 'src/radeon_kms.c') diff --git a/src/radeon_kms.c b/src/radeon_kms.c index 16a1b5f3..c0f97624 100644 --- a/src/radeon_kms.c +++ b/src/radeon_kms.c @@ -581,23 +581,12 @@ static Bool RADEONPreInitChipType_KMS(ScrnInfoPtr pScrn) return TRUE; } -static Bool radeon_open_drm_master(ScrnInfoPtr pScrn) +static int radeon_get_drm_master_fd(ScrnInfoPtr pScrn) { RADEONInfoPtr info = RADEONPTR(pScrn); - RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); struct pci_device *dev = info->PciInfo; char *busid; - drmSetVersion sv; - int err; - - if (pRADEONEnt->fd) { - xf86DrvMsg(pScrn->scrnIndex, X_INFO, - " reusing fd for second head\n"); - - info->drmmode.fd = info->dri2.drm_fd = pRADEONEnt->fd; - pRADEONEnt->fd_ref++; - return TRUE; - } + int fd; #if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,9,99,901,0) XNFasprintf(&busid, "pci:%04x:%02x:%02x.%d", @@ -607,16 +596,35 @@ static Bool radeon_open_drm_master(ScrnInfoPtr pScrn) dev->domain, dev->bus, dev->dev, dev->func); #endif - info->dri2.drm_fd = drmOpen(NULL, busid); - if (info->dri2.drm_fd == -1) { - + fd = drmOpen(NULL, busid); + if (fd == -1) xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[drm] Failed to open DRM device for %s: %s\n", busid, strerror(errno)); - free(busid); - return FALSE; - } + free(busid); + return fd; +} + +static Bool radeon_open_drm_master(ScrnInfoPtr pScrn) +{ + RADEONInfoPtr info = RADEONPTR(pScrn); + RADEONEntPtr pRADEONEnt = RADEONEntPriv(pScrn); + drmSetVersion sv; + int err; + + if (pRADEONEnt->fd) { + xf86DrvMsg(pScrn->scrnIndex, X_INFO, + " reusing fd for second head\n"); + + info->drmmode.fd = info->dri2.drm_fd = pRADEONEnt->fd; + pRADEONEnt->fd_ref++; + return TRUE; + } + + info->dri2.drm_fd = radeon_get_drm_master_fd(pScrn); + if (info->dri2.drm_fd == -1) + return FALSE; /* Check that what we opened was a master or a master-capable FD, * by setting the version of the interface we'll use to talk to it. -- cgit v1.2.3