summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2013-12-28 17:13:01 -0800
committerEric Anholt <eric@anholt.net>2014-08-21 15:31:43 -0700
commita5ffc1d93e05f6bdbcc25c8a219231aef69dfbf2 (patch)
treeed9db8b57130ed265994c68d4993c140356a037c
parentff61f74937f27eafccaef9c818a3b13ff35a937a (diff)
Move the device opening code to a helper function.
This will get reused for dri3.
-rw-r--r--src/driver.c81
1 files changed, 45 insertions, 36 deletions
diff --git a/src/driver.c b/src/driver.c
index 597214d..7a7efe7 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -599,6 +599,50 @@ FreeRec(ScrnInfoPtr pScrn)
#define DRM_CAP_CURSOR_HEIGHT 0x9
#endif
+static int
+ms_open_drm(ScrnInfoPtr pScrn)
+{
+ modesettingPtr ms = modesettingPTR(pScrn);
+ EntityInfoPtr pEnt = ms->pEnt;
+ char *BusID = NULL;
+ const char *devicename;
+
+#if XSERVER_PLATFORM_BUS
+ if (pEnt->location.type == BUS_PLATFORM) {
+#ifdef XF86_PDEV_SERVER_FD
+ if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
+ return xf86_get_platform_device_int_attrib(pEnt->location.id.plat, ODEV_ATTRIB_FD, -1);
+ else
+#endif
+ {
+ char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
+ return open_hw(path);
+ }
+ }
+ else
+#endif
+ if (pEnt->location.type == BUS_PCI) {
+ ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
+ if (ms->PciInfo) {
+ BusID = malloc(64);
+ sprintf(BusID, "PCI:%d:%d:%d",
+#if XSERVER_LIBPCIACCESS
+ ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
+ ms->PciInfo->dev, ms->PciInfo->func
+#else
+ ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
+ ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
+ ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
+#endif
+ );
+ }
+ return drmOpen(NULL, BusID);
+ } else {
+ devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
+ return open_hw(devicename);
+ }
+}
+
static Bool
PreInit(ScrnInfoPtr pScrn, int flags)
{
@@ -606,8 +650,6 @@ PreInit(ScrnInfoPtr pScrn, int flags)
rgb defaultWeight = { 0, 0, 0 };
EntityInfoPtr pEnt;
EntPtr msEnt = NULL;
- char *BusID = NULL;
- const char *devicename;
Bool prefer_shadow = TRUE;
uint64_t value = 0;
int ret;
@@ -656,40 +698,7 @@ PreInit(ScrnInfoPtr pScrn, int flags)
pScrn->progClock = TRUE;
pScrn->rgbBits = 8;
-#if XSERVER_PLATFORM_BUS
- if (pEnt->location.type == BUS_PLATFORM) {
-#ifdef XF86_PDEV_SERVER_FD
- if (pEnt->location.id.plat->flags & XF86_PDEV_SERVER_FD)
- ms->fd = xf86_get_platform_device_int_attrib(pEnt->location.id.plat, ODEV_ATTRIB_FD, -1);
- else
-#endif
- {
- char *path = xf86_get_platform_device_attrib(pEnt->location.id.plat, ODEV_ATTRIB_PATH);
- ms->fd = open_hw(path);
- }
- }
- else
-#endif
- if (pEnt->location.type == BUS_PCI) {
- ms->PciInfo = xf86GetPciInfoForEntity(ms->pEnt->index);
- if (ms->PciInfo) {
- BusID = malloc(64);
- sprintf(BusID, "PCI:%d:%d:%d",
-#if XSERVER_LIBPCIACCESS
- ((ms->PciInfo->domain << 8) | ms->PciInfo->bus),
- ms->PciInfo->dev, ms->PciInfo->func
-#else
- ((pciConfigPtr) ms->PciInfo->thisCard)->busnum,
- ((pciConfigPtr) ms->PciInfo->thisCard)->devnum,
- ((pciConfigPtr) ms->PciInfo->thisCard)->funcnum
-#endif
- );
- }
- ms->fd = drmOpen(NULL, BusID);
- } else {
- devicename = xf86FindOptionValue(ms->pEnt->device->options, "kmsdev");
- ms->fd = open_hw(devicename);
- }
+ ms->fd = ms_open_drm(pScrn);
if (ms->fd < 0)
return FALSE;