On Nov 26, 2007 6:51 PM, Jerome Glisse <[EMAIL PROTECTED]> wrote:
...
> > Sounds like this will all work out after all :)
> > Kristian
>
> Yes, between i started looking at your dri2 branch and didn't find dri2
> branch in your intel ddx repository did you pushed the code anywhere else ?
> Would help me to see what i need to do for dri2 in ddx.

I didn't push that yet, but I've attached the patch as it looks right
now.  It's still very much work-in-progress.

Kristian
commit 3a16f83c278902ff673bc21272a3b95eb6237dab
Author: Kristian Høgsberg <[EMAIL PROTECTED]>
Date:   Mon Nov 19 17:31:02 2007 -0500

    dri2 wip

diff --git a/src/i830.h b/src/i830.h
index 57f0544..ba20df8 100644
--- a/src/i830.h
+++ b/src/i830.h
@@ -295,6 +295,12 @@ enum last_3d {
     LAST_3D_ROTATION
 };
 
+enum dri_type {
+    DRI_TYPE_NONE,
+    DRI_TYPE_XF86DRI,
+    DRI_TYPE_DRI2
+};
+
 typedef struct _I830Rec {
    unsigned char *MMIOBase;
    unsigned char *GTTBase;
@@ -456,7 +462,7 @@ typedef struct _I830Rec {
    CARD32 samplerstate[6];
 
    Bool directRenderingDisabled;	/* DRI disabled in PreInit. */
-   Bool directRenderingEnabled;		/* DRI enabled this generation. */
+   enum dri_type directRendering;	/* Type of DRI enabled this generation. */
 
 #ifdef XF86DRI
    Bool directRenderingOpen;
diff --git a/src/i830_accel.c b/src/i830_accel.c
index 4d9ea79..e38897e 100644
--- a/src/i830_accel.c
+++ b/src/i830_accel.c
@@ -136,7 +136,7 @@ I830WaitLpRing(ScrnInfoPtr pScrn, int n, int timeout_millis)
 	     i830_dump_error_state(pScrn);
 	 ErrorF("space: %d wanted %d\n", ring->space, n);
 #ifdef XF86DRI
-	 if (pI830->directRenderingEnabled) {
+	 if (pI830->directRendering == DRI_TYPE_XF86DRI) {
 	    DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
 	    DRICloseScreen(screenInfo.screens[pScrn->scrnIndex]);
 	 }
@@ -176,7 +176,7 @@ I830Sync(ScrnInfoPtr pScrn)
 #ifdef XF86DRI
    /* VT switching tries to do this.
     */
-   if (!pI830->LockHeld && pI830->directRenderingEnabled) {
+   if (!pI830->LockHeld && pI830->directRendering != DRI_TYPE_NONE) {
       return;
    }
 #endif
diff --git a/src/i830_display.c b/src/i830_display.c
index d988b86..8b07c51 100644
--- a/src/i830_display.c
+++ b/src/i830_display.c
@@ -408,7 +408,7 @@ i830PipeSetBase(xf86CrtcPtr crtc, int x, int y)
     }
 
 #ifdef XF86DRI
-    if (pI830->directRenderingEnabled) {
+    if (pI830->directRendering == DRI_TYPE_XF86DRI) {
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 
 	if (!sPriv)
@@ -755,7 +755,7 @@ i830_crtc_dpms(xf86CrtcPtr crtc, int mode)
     intel_crtc->dpms_mode = mode;
 
 #ifdef XF86DRI
-    if (pI830->directRenderingEnabled) {
+    if (pI830->directRendering == DRI_TYPE_XF86DRI) {
 	drmI830Sarea *sPriv = (drmI830Sarea *) DRIGetSAREAPrivate(pScrn->pScreen);
 	Bool enabled = crtc->enabled && mode != DPMSModeOff;
 
diff --git a/src/i830_dri.c b/src/i830_dri.c
index 4d3458f..511b183 100644
--- a/src/i830_dri.c
+++ b/src/i830_dri.c
@@ -1236,6 +1236,10 @@ I830DRIInitBuffers(WindowPtr pWin, RegionPtr prgn, CARD32 index)
    i830MarkSync(pScrn);
 }
 
+/* FIXME: fix this for real */
+#define ALLOCATE_LOCAL(size) xalloc(size)
+#define DEALLOCATE_LOCAL(ptr) xfree(ptr)
+
 /* This routine is a modified form of XAADoBitBlt with the calls to
  * ScreenToScreenBitBlt built in. My routine has the prgnSrc as source
  * instead of destination. My origin is upside down so the ydir cases
@@ -1748,7 +1752,7 @@ I830DRISetVBlankInterrupt (ScrnInfoPtr pScrn, Bool on)
     if (!pI830->want_vblank_interrupts)
 	on = FALSE;
 
-    if (pI830->directRenderingEnabled && pI830->drmMinor >= 5) {
+    if (pI830->directRendering == DRI_TYPE_XF86DRI && pI830->drmMinor >= 5) {
 	if (on) {
 	    if (xf86_config->num_crtc > 1 && xf86_config->crtc[1]->enabled)
 		if (pI830->drmMinor >= 6)
@@ -1775,7 +1779,7 @@ I830DRILock(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
-   if (pI830->directRenderingEnabled && !pI830->LockHeld) {
+   if (pI830->directRendering == DRI_TYPE_XF86DRI && !pI830->LockHeld) {
       DRILock(screenInfo.screens[pScrn->scrnIndex], 0);
       pI830->LockHeld = 1;
       I830RefreshRing(pScrn);
@@ -1792,7 +1796,7 @@ I830DRIUnlock(ScrnInfoPtr pScrn)
 {
    I830Ptr pI830 = I830PTR(pScrn);
 
-   if (pI830->directRenderingEnabled && pI830->LockHeld) {
+   if (pI830->directRendering == DRI_TYPE_XF86DRI && pI830->LockHeld) {
       DRIUnlock(screenInfo.screens[pScrn->scrnIndex]);
       pI830->LockHeld = 0;
    }
diff --git a/src/i830_driver.c b/src/i830_driver.c
index eacaefc..08a5904 100644
--- a/src/i830_driver.c
+++ b/src/i830_driver.c
@@ -208,6 +208,10 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 #endif
 #endif
 
+#ifdef DRI2
+#include "dri2.h"
+#endif
+
 #ifdef I830_USE_EXA
 const char *I830exaSymbols[] = {
     "exaGetVersion",
@@ -1467,7 +1471,7 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    pI830->directRenderingDisabled =
 	!xf86ReturnOptValBool(pI830->Options, OPTION_DRI, TRUE);
 
-#ifdef XF86DRI
+#if defined(XF86DRI) || defined(DRI2)
    if (!pI830->directRenderingDisabled) {
       if (pI830->noAccel || pI830->SWCursor) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "DRI is disabled because it "
@@ -1718,6 +1722,14 @@ I830PreInit(ScrnInfoPtr pScrn, int flags)
    }
 #endif
 
+#if defined(DRI2)
+   /* Load the dri2 module if requested. */
+   if (xf86ReturnOptValBool(pI830->Options, OPTION_DRI, FALSE) &&
+       !pI830->directRenderingDisabled) {
+       xf86LoadSubModule(pScrn, "dri2");
+   }
+#endif
+
    pI830->preinit = FALSE;
 
    return TRUE;
@@ -2233,7 +2245,7 @@ IntelEmitInvarientState(ScrnInfoPtr pScrn)
       return;
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering == DRI_TYPE_XF86DRI) {
       drmI830Sarea *sarea = DRIGetSAREAPrivate(pScrn->pScreen);
 
       /* Mark that the X Server was the last holder of the context */
@@ -2393,21 +2405,69 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       pScrn->videoRam &= ~3;
    }
 
+   pI830->directRendering = DRI_TYPE_NONE;
+#ifdef DRI2
+   do {
+       char busId[64];
+       drmVersionPtr version;
+
+#if XSERVER_LIBPCIACCESS
+       sprintf(busId, "pci:%04x:%02x:%02x.%d",
+	       pI830->PciInfo->domain, pI830->PciInfo->bus,
+	       pI830->PciInfo->dev, pI830->PciInfo->func);
+#else
+       snprintf(busId, "PCI:%d:%d:%d",
+		((pciConfigPtr) pI830->PciInfo->thisCard)->busnum,
+		((pciConfigPtr) pI830->PciInfo->thisCard)->devnum,
+		((pciConfigPtr) pI830->PciInfo->thisCard)->funcnum);
+#endif
+
+       xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "[dri2] bailing\n");
+       break;
+       
+       /* Low level DRM open */
+       pI830->drmSubFD = drmOpen("i915", busId);
+       if (pI830->drmSubFD < 0) {
+	   xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+		      "[dri2] drmOpen failed\n");
+	   break;
+       }
+
+       version = drmGetVersion(pI830->drmSubFD);
+       if (version) {
+	   if (version->version_major != 1 || version->version_minor < 3) {
+	       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+			  "[dri2] Need at least version 1.3 for dri2\n");
+	       drmClose(pI830->drmSubFD);
+	       break;
+	   }	       
+	   drmFreeVersion(version);
+       }
+
+       xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		  "[dri2] Opened drm device successfully\n");
+       pI830->directRendering = DRI_TYPE_DRI2;
+       
+   } while (0);
+#endif
+
 #ifdef XF86DRI
    /* Check for appropriate bpp and module support to initialize DRI. */
-   if (!I830CheckDRIAvailable(pScrn)) {
-      pI830->directRenderingDisabled = TRUE;
-   }
+   if (pI830->directRendering == DRI_TYPE_NONE) {
 
-   /* If DRI hasn't been explicitly disabled, try to initialize it.
-    * It will be used by the memory allocator.
-    */
-   if (!pI830->directRenderingDisabled)
-      pI830->directRenderingEnabled = I830DRIScreenInit(pScreen);
-   else
-      pI830->directRenderingEnabled = FALSE;
-#else
-   pI830->directRenderingEnabled = FALSE;
+       if (!I830CheckDRIAvailable(pScrn)) {
+	   pI830->directRendering = DRI_TYPE_XF86DRI;
+       }
+
+       /* If DRI hasn't been explicitly disabled, try to initialize it.
+	* It will be used by the memory allocator.
+	*/
+       if (!pI830->directRenderingDisabled)
+	   pI830->directRendering =
+	       I830DRIScreenInit(pScreen) ? DRI_TYPE_XF86DRI : DRI_TYPE_NONE;
+       else
+	   pI830->directRendering = DRI_TYPE_NONE;
+   }
 #endif
 
    /* Set up our video memory allocator for the chosen videoRam */
@@ -2489,7 +2549,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    /* Need MMIO mapped to do GTT lookups during memory allocation. */
    I830MapMMIO(pScrn);
 
-#if defined(XF86DRI)
+#if defined(XF86DRI) || defined(DRI2)
    /*
     * If DRI is potentially usable, check if there is enough memory available
     * for it, and if there's also enough to allow tiling to be enabled.
@@ -2504,7 +2564,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     pI830->XvEnabled = !pI830->XvDisabled;
 #endif
 
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering != DRI_TYPE_NONE) {
       int savedDisplayWidth = pScrn->displayWidth;
       Bool tiled = FALSE;
 
@@ -2561,7 +2621,8 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 		    (i & 1) ? "untiled" : "tiled");
 
 	 if (i830_allocate_2d_memory(pScrn) &&
-	     i830_allocate_3d_memory(pScrn))
+	     (pI830->directRendering == DRI_TYPE_DRI2 ||
+	      i830_allocate_3d_memory(pScrn)))
 	 {
 	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Success.\n");
 	    if (pScrn->displayWidth != savedDisplayWidth) {
@@ -2580,7 +2641,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       if (i == MM_TURNS) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
 		    "Not enough video memory.  Disabling DRI.\n");
-	 pI830->directRenderingEnabled = FALSE;
+	 pI830->directRendering = DRI_TYPE_NONE;
       }
    }
 #endif
@@ -2600,7 +2661,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		 "Cannot support DRI with frame buffer width > 2048.\n");
       pI830->tiling = FALSE;
-      pI830->directRenderingEnabled = FALSE;
+      pI830->directRendering = DRI_TYPE_NONE;
    }
 
    pScrn->displayWidth = pScrn->displayWidth;
@@ -2700,27 +2761,30 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    }
 #endif
 
-#ifdef XF86DRI
+#if defined(XF86DRI) || defined(DRI2)
    /*
     * Setup DRI after visuals have been established, but before fbScreenInit
     * is called.   fbScreenInit will eventually call into the drivers
     * InitGLXVisuals call back.
     */
 
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering != DRI_TYPE_NONE) {
       if (pI830->noAccel || pI830->SWCursor || (pI830->StolenOnly && I830IsPrimary(pScrn))) {
 	 xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "DRI is disabled because it "
 		    "needs HW cursor, 2D accel and AGPGART.\n");
-	 pI830->directRenderingEnabled = FALSE;
+	 pI830->directRendering = DRI_TYPE_NONE;
       }
    }
 
-   if (pI830->directRenderingEnabled)
-      pI830->directRenderingEnabled = I830DRIDoMappings(pScreen);
+   if (pI830->directRendering == DRI_TYPE_XF86DRI)
+      pI830->directRendering =
+	  I830DRIDoMappings(pScreen) ? DRI_TYPE_XF86DRI : DRI_TYPE_NONE;
 
+#if 0 /* FIXME: free this... */
    /* If we failed for any reason, free DRI memory. */
    if (!pI830->directRenderingEnabled)
       i830_free_3d_memory(pScrn);
+#endif
 
    config = XF86_CRTC_CONFIG_PTR(pScrn);
 
@@ -2732,8 +2796,8 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
     * Also make sure the DRM can handle the swap.
     */
    if (I830LVDSPresent(pScrn) && !IS_I965GM(pI830) &&
-       (!pI830->directRenderingEnabled ||
-	(pI830->directRenderingEnabled && pI830->drmMinor >= 10))) {
+       (pI830->directRendering == DRI_TYPE_NONE ||
+	(pI830->directRendering == DRI_TYPE_XF86DRI && pI830->drmMinor >= 10))) {
        xf86DrvMsg(pScrn->scrnIndex, X_INFO, "adjusting plane->pipe mappings "
 		  "to allow for framebuffer compression\n");
        for (c = 0; c < config->num_crtc; c++) {
@@ -2746,9 +2810,6 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 	       intel_crtc->plane = 0;
       }
    }
-
-#else
-   pI830->directRenderingEnabled = FALSE;
 #endif
 
 #ifdef XF86DRI
@@ -2852,8 +2913,14 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    /* Must be called before EnterVT, so we can acquire the DRI lock when
     * binding our memory.
     */
-   if (pI830->directRenderingEnabled)
-      pI830->directRenderingEnabled = I830DRIFinishScreenInit(pScreen);
+   if (pI830->directRendering == DRI_TYPE_XF86DRI)
+      pI830->directRendering =
+	  I830DRIFinishScreenInit(pScreen) ? DRI_TYPE_XF86DRI : DRI_TYPE_NONE;
+#endif
+
+#ifdef DRI2
+   if (pI830->directRendering == DRI_TYPE_DRI2)
+       DRI2ScreenInit(pScreen, pI830->drmSubFD);
 #endif
 
    if (!I830EnterVT(scrnIndex, 0))
@@ -2882,7 +2949,7 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
    IntelEmitInvarientState(pScrn);
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering == DRI_TYPE_XF86DRI) {
       pI830->directRenderingOpen = TRUE;
       xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Enabled\n");
    } else {
@@ -2891,7 +2958,12 @@ I830ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
       else
 	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Failed\n");
    }
-#else
+#endif
+
+#ifdef DRI2
+#endif
+
+#if !defined(XF86DRI) || !defined(DRI2)
    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "direct rendering: Not available\n");
 #endif
 
@@ -3051,7 +3123,7 @@ I830EnterVT(int scrnIndex, int flags)
    pI830->leaving = FALSE;
 
 #ifdef XF86DRI_MM
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering != DRI_TYPE_NONE) {
       /* Unlock the memory manager first of all so that we can pin our
        * buffer objects
        */
@@ -3100,7 +3172,7 @@ I830EnterVT(int scrnIndex, int flags)
    SetHWOperatingState(pScrn);
 
 #ifdef XF86DRI
-   if (pI830->directRenderingEnabled) {
+   if (pI830->directRendering == DRI_TYPE_XF86DRI) {
       /* Update buffer offsets in sarea and mappings, since buffer offsets
        * may have changed.
        */
@@ -3171,7 +3243,7 @@ I830CloseScreen(int scrnIndex, ScreenPtr pScreen)
    if (pScrn->vtSema == TRUE) {
       I830LeaveVT(scrnIndex, 0);
 #ifdef XF86DRI_MM
-      if (pI830->directRenderingEnabled) {
+      if (pI830->directRendering != DRI_TYPE_NONE) {
  	 if (pI830->memory_manager != NULL) {
 	    drmMMUnlock(pI830->drmSubFD, DRM_BO_MEM_TT, 1);
 	 }
diff --git a/src/i830_memory.c b/src/i830_memory.c
index 7b89c40..e9aa0c6 100644
--- a/src/i830_memory.c
+++ b/src/i830_memory.c
@@ -437,7 +437,7 @@ i830_allocator_init(ScrnInfoPtr pScrn, unsigned long offset, unsigned long size)
      * 5.4 or newer so we can rely on the lock being held after DRIScreenInit,
      * rather than after DRIFinishScreenInit.
      */
-    if (pI830->directRenderingEnabled && pI830->drmMinor >= 7 &&
+    if (pI830->directRendering != DRI_TYPE_NONE && pI830->drmMinor >= 7 &&
 	(dri_major > 5 || (dri_major == 5 && dri_minor >= 4)))
     {
 	int mmsize;
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
--
_______________________________________________
Dri-devel mailing list
Dri-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/dri-devel

Reply via email to