summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2009-04-27 17:29:36 -0700
committerCarl Worth <cworth@cworth.org>2009-05-26 16:12:16 -0700
commita04a51c9bb6066454e0fda3c7897f97dab436358 (patch)
tree65e44ad0a63ad1d3b34042209c30deea79d3f018
parentc3bf8b980134a2761701e4bc18235695a1cb07a4 (diff)
Open the DRM and keep the handle throughout server startup to finish.
This will let us configure the server from start to finish with the most pertinent information available (KMS vs UMS, DRI2 vs non-DRI). Also, we now close the DRI2 fd at terminate, which we didn't before. This duplicates some code from DRI1 for getting a master FD like I'd done in DRI2, but given that we weren't loading DRI1 ourselves, this is also a bogosity cleanup, and avoids allocating the extra DRI1 private.
-rw-r--r--src/i830_dri.c35
-rw-r--r--src/i830_driver.c82
2 files changed, 65 insertions, 52 deletions
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 0648249a..fc059dfe 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -329,7 +329,7 @@ Bool I830DRI2ScreenInit(ScreenPtr pScreen)
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
I830Ptr pI830 = I830PTR(pScrn);
DRI2InfoRec info;
- char *p, buf[64];
+ char *p;
int i;
struct stat sbuf;
dev_t d;
@@ -355,36 +355,7 @@ Bool I830DRI2ScreenInit(ScreenPtr pScreen)
}
#endif
- sprintf(buf, "pci:%04x:%02x:%02x.%d",
- pI830->PciInfo->domain,
- pI830->PciInfo->bus,
- pI830->PciInfo->dev,
- pI830->PciInfo->func);
-
- /* Use the already opened (master) fd from modesetting */
- if (pI830->use_drm_mode) {
- info.fd = pI830->drmSubFD;
- } else {
- info.fd = drmOpen("i915", buf);
- drmSetVersion sv;
- int err;
-
- /* 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.
- * (see DRIOpenDRMMaster() in DRI1)
- */
- sv.drm_di_major = 1;
- sv.drm_di_minor = 1;
- sv.drm_dd_major = -1;
- err = drmSetInterfaceVersion(info.fd, &sv);
- if (err != 0)
- return FALSE;
- }
-
- if (info.fd < 0) {
- xf86DrvMsg(pScrn->scrnIndex, X_WARNING, "Failed to open DRM device\n");
- return FALSE;
- }
+ info.fd = pI830->drmSubFD;
/* The whole drmOpen thing is a fiasco and we need to find a way
* back to just using open(2). For now, however, lets just make
@@ -423,8 +394,6 @@ Bool I830DRI2ScreenInit(ScreenPtr pScreen)
info.CopyRegion = I830DRI2CopyRegion;
- pI830->drmSubFD = info.fd;
-
return DRI2ScreenInit(pScreen, &info);
}
diff --git a/src/i830_driver.c b/src/i830_driver.c
index 854ad0fb..ef4d5758 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -1414,28 +1414,61 @@ I830AccelMethodInit(ScrnInfoPtr pScrn)
}
static Bool
-I830DrmModeInit(ScrnInfoPtr pScrn)
+i830_open_drm_master(ScrnInfoPtr scrn)
{
- I830Ptr pI830 = I830PTR(pScrn);
- char *bus_id;
- int ret;
+ I830Ptr i830 = I830PTR(scrn);
+ struct pci_device *dev = i830->PciInfo;
+ char *busid;
+ drmSetVersion sv;
+ int err;
+
+ /* We wish we had asprintf, but all we get is XNFprintf. */
+ busid = XNFprintf("pci:%04x:%02x:%02x.%d",
+ dev->domain, dev->bus, dev->dev, dev->func);
+
+ i830->drmSubFD = drmOpen("i915", busid);
+ if (i830->drmSubFD == -1) {
+ xf86DrvMsg(scrn->scrnIndex, X_ERROR,
+ "[drm] Failed to open DRM device for %s\n", busid);
+ return FALSE;
+ }
- pI830->accel = ACCEL_UXA;
+ xfree(busid);
- bus_id = DRICreatePCIBusID(pI830->PciInfo);
+ /* 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.
+ * (see DRIOpenDRMMaster() in DRI1)
+ */
+ sv.drm_di_major = 1;
+ sv.drm_di_minor = 1;
+ sv.drm_dd_major = -1;
+ err = drmSetInterfaceVersion(i830->drmSubFD, &sv);
+ if (err != 0) {
+ drmClose(i830->drmSubFD);
+ i830->drmSubFD = -1;
+ return FALSE;
+ }
- /* Create a bus Id */
- /* Low level DRM open */
- ret = DRIOpenDRMMaster(pScrn, SAREA_MAX, bus_id, "i915");
- xfree(bus_id);
- if (!ret) {
- xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
- "[dri] DRIGetVersion failed to open the DRM\n"
- "[dri] Disabling DRI.\n");
- return FALSE;
+ return TRUE;
+}
+
+static void
+i830_close_drm_master(ScrnInfoPtr scrn)
+{
+ I830Ptr i830 = I830PTR(scrn);
+ if (i830->drmSubFD > 0) {
+ drmClose(i830->drmSubFD);
+ i830->drmSubFD = -1;
}
+}
+
+static Bool
+I830DrmModeInit(ScrnInfoPtr pScrn)
+{
+ I830Ptr pI830 = I830PTR(pScrn);
+
+ pI830->accel = ACCEL_UXA;
- pI830->drmSubFD = DRIMasterFD(pScrn);
if (drmmode_pre_init(pScrn, pI830->drmSubFD, pI830->cpp) == FALSE) {
xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
"Kernel modesetting setup failed\n");
@@ -1477,11 +1510,17 @@ I830XvInit(ScrnInfoPtr pScrn)
}
/**
- * This is called per zaphod head (so usually just once) to do initialization
- * before the Screen is created.
+ * This is called before ScreenInit to do any require probing of screen
+ * configuration.
*
* This code generally covers probing, module loading, option handling
* card mapping, and RandR setup.
+ *
+ * Since xf86InitialConfiguration ends up requiring that we set video modes
+ * in order to detect configuration, we end up having to do a lot of driver
+ * setup (talking to the DRM, mapping the device, etc.) in this function.
+ * As a result, we want to set up that server initialization once rather
+ * that doing it per generation.
*/
static Bool
I830PreInit(ScrnInfoPtr pScrn, int flags)
@@ -1531,6 +1570,8 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
pI830->PciInfo = xf86GetPciInfoForEntity(pI830->pEnt->index);
+ i830_open_drm_master(pScrn);
+
if (xf86RegisterResources(pI830->pEnt->index, NULL, ResNone)) {
PreInitCleanup(pScrn);
return FALSE;
@@ -2839,12 +2880,15 @@ i830AdjustFrame(int scrnIndex, int x, int y, int flags)
static void
I830FreeScreen(int scrnIndex, int flags)
{
-#ifdef INTEL_XVMC
ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
+#ifdef INTEL_XVMC
I830Ptr pI830 = I830PTR(pScrn);
if (pI830 && pI830->XvMCEnabled)
intel_xvmc_finish(xf86Screens[scrnIndex]);
#endif
+
+ i830_close_drm_master(pScrn);
+
I830FreeRec(xf86Screens[scrnIndex]);
if (xf86LoaderCheckSymbol("vgaHWFreeHWRec"))
vgaHWFreeHWRec(xf86Screens[scrnIndex]);