Merge branch 'master' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / mga / server / mga_dri.c
index 19ddb38510f0337eca2416b88fbea16cdac23a82..bc575e62ee8c8fe46c42eb0cfe70fc375925be9a 100644 (file)
@@ -1,4 +1,3 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/mga/mga_dri.c,v 1.28 2003/02/08 21:26:58 dawes Exp $ */
 
 /*
  * Copyright 2000 VA Linux Systems Inc., Fremont, California.
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 
 #include "driver.h"
 #include "drm.h"
+#include "memops.h"
 
 #include "mga_reg.h"
 #include "mga.h"
 #include "mga_macros.h"
 #include "mga_dri.h"
-#include "mga_sarea.h"
-
-#include "sarea.h"
-
 
 
 /* Quiescence, locking
 
 static void MGAWaitForIdleDMA( struct DRIDriverContextRec *ctx, MGAPtr pMga )
 {
-   drmMGALock lock;
+   drm_lock_t lock;
    int ret;
    int i = 0;
 
-   memset( &lock, 0, sizeof(drmMGALock) );
+   memset( &lock, 0, sizeof(lock) );
 
    for (;;) {
       do {
          /* first ask for quiescent and flush */
-         lock.flags = DRM_MGA_LOCK_QUIESCENT | DRM_MGA_LOCK_FLUSH;
+         lock.flags = DRM_LOCK_QUIESCENT | DRM_LOCK_FLUSH;
          do {
            ret = drmCommandWrite( ctx->drmFD, DRM_MGA_FLUSH,
-                                   &lock, sizeof( drmMGALock ) );
+                                   &lock, sizeof( lock ) );
          } while ( ret == -EBUSY && i++ < DRM_MGA_IDLE_RETRY );
 
          /* if it's still busy just try quiescent */
          if ( ret == -EBUSY ) { 
-            lock.flags = DRM_MGA_LOCK_QUIESCENT;
+            lock.flags = DRM_LOCK_QUIESCENT;
             do {
               ret = drmCommandWrite( ctx->drmFD, DRM_MGA_FLUSH,
-                                      &lock, sizeof( drmMGALock ) );
+                                      &lock, sizeof( lock ) );
             } while ( ret == -EBUSY && i++ < DRM_MGA_IDLE_RETRY );
          }
       } while ( ( ret == -EBUSY ) && ( i++ < MGA_TIMEOUT ) );
@@ -208,7 +205,7 @@ static int MGADRIAgpInit(struct DRIDriverContextRec *ctx, MGAPtr pMga)
       return 0;
    }
    fprintf( stderr,
-              "[agp] WARP microcode handle = 0x%08lx\n",
+              "[agp] WARP microcode handle = 0x%08x\n",
               pMga->warp.handle );
 
    if ( drmMap( ctx->drmFD,
@@ -235,7 +232,7 @@ static int MGADRIAgpInit(struct DRIDriverContextRec *ctx, MGAPtr pMga)
       return 0;
    }
    fprintf( stderr,
-              "[agp] Primary DMA handle = 0x%08lx\n",
+              "[agp] Primary DMA handle = 0x%08x\n",
               pMga->primary.handle );
 
    if ( drmMap( ctx->drmFD,
@@ -262,7 +259,7 @@ static int MGADRIAgpInit(struct DRIDriverContextRec *ctx, MGAPtr pMga)
       return 0;
    }
    fprintf( stderr,
-              "[agp] DMA buffers handle = 0x%08lx\n",
+              "[agp] DMA buffers handle = 0x%08x\n",
               pMga->buffers.handle );
 
    if ( drmMap( ctx->drmFD,
@@ -306,7 +303,7 @@ static int MGADRIAgpInit(struct DRIDriverContextRec *ctx, MGAPtr pMga)
    }
 /* should i map it ? */
    fprintf( stderr,
-               "[agp] agpTexture handle = 0x%08lx\n",
+               "[agp] agpTexture handle = 0x%08x\n",
                pMga->agpTextures.handle );
    fprintf( stderr,
                "[agp] agpTexture size: %d kb\n", pMga->agpTextures.size/1024 );
@@ -319,7 +316,7 @@ static int MGADRIMapInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
    pMga->registers.size = MGAIOMAPSIZE;
 
    if ( drmAddMap( ctx->drmFD,
-                  (drmHandle)pMga->IOAddress,
+                  (drm_handle_t)pMga->IOAddress,
                   pMga->registers.size,
                   DRM_REGISTERS, DRM_READ_ONLY,
                   &pMga->registers.handle ) < 0 ) {
@@ -341,7 +338,7 @@ static int MGADRIMapInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
       return 0;
    }
    fprintf( stderr,
-              "[drm] Status handle = 0x%08lx\n",
+              "[drm] Status handle = 0x%08x\n",
               pMga->status.handle );
 
    if ( drmMap( ctx->drmFD,
@@ -361,13 +358,13 @@ static int MGADRIMapInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
 
 static int MGADRIKernelInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
 {
-   drmMGAInit init;
+   drm_mga_init_t init;
    int ret;
 
-   memset( &init, 0, sizeof(drmMGAInit) );
+   memset( &init, 0, sizeof(init) );
 
    init.func = MGA_INIT_DMA;
-   init.sarea_priv_offset = sizeof(XF86DRISAREARec);
+   init.sarea_priv_offset = sizeof(drm_sarea_t);
 
    switch ( pMga->Chipset ) {
    case PCI_CHIP_MGAG550:
@@ -423,7 +420,7 @@ static int MGADRIKernelInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
    init.texture_offset[1] = pMga->agpTextures.handle;
    init.texture_size[1] = pMga->agpTextures.size;
 
-   ret = drmCommandWrite( ctx->drmFD, DRM_MGA_INIT, &init, sizeof(drmMGAInit));
+   ret = drmCommandWrite( ctx->drmFD, DRM_MGA_INIT, &init, sizeof(init));
    if ( ret < 0 ) {
       fprintf( stderr,
                  "[drm] Failed to initialize DMA! (%d)\n", ret );
@@ -624,7 +621,7 @@ static void print_client_msg( MGADRIPtr pMGADRI )
    pMGADRI->primary.size       = pMga->primary.size;
    pMGADRI->buffers.handle     = pMga->buffers.handle;
    pMGADRI->buffers.size       = pMga->buffers.size;
-   pMGADRI->sarea_priv_offset = sizeof(XF86DRISAREARec);
+   pMGADRI->sarea_priv_offset = sizeof(drm_sarea_t);
 #endif
 }
 
@@ -722,7 +719,7 @@ static int MGAScreenInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
    /* Need to AddMap the framebuffer and mmio regions here:
     */
    if (drmAddMap( ctx->drmFD,
-                 (drmHandle)ctx->FBStart,
+                 (drm_handle_t)ctx->FBStart,
                  ctx->FBSize,
                  DRM_FRAME_BUFFER,
                  0,
@@ -799,9 +796,9 @@ static int MGAScreenInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
 
    /* Initialize the SAREA private data structure */
    {
-      MGASAREAPrivPtr pSAREAPriv;
-      pSAREAPriv = (MGASAREAPrivPtr)(((char*)ctx->pSAREA) + 
-                                       sizeof(XF86DRISAREARec));
+      drm_mga_sarea_t *pSAREAPriv;
+      pSAREAPriv = (drm_mga_sarea_t *)(((char*)ctx->pSAREA) + 
+                                       sizeof(drm_sarea_t));
       memset(pSAREAPriv, 0, sizeof(*pSAREAPriv));
    }
 
@@ -809,11 +806,11 @@ static int MGAScreenInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
     * the clear ioctl to do this, but would need to setup hw state
     * first.
     */
-   memset((char *)ctx->FBAddress + pMga->frontOffset,
+   drimemsetio((char *)ctx->FBAddress + pMga->frontOffset,
          0,
          pMga->frontPitch * ctx->shared.virtualHeight );
 
-   memset((char *)ctx->FBAddress + pMga->backOffset,
+   drimemsetio((char *)ctx->FBAddress + pMga->backOffset,
          0,
          pMga->backPitch * ctx->shared.virtualHeight );
 
@@ -872,7 +869,7 @@ static int MGAScreenInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
    pMGADRI->primary.size       = pMga->primary.size;
    pMGADRI->buffers.handle     = pMga->buffers.handle;
    pMGADRI->buffers.size       = pMga->buffers.size;
-   pMGADRI->sarea_priv_offset = sizeof(XF86DRISAREARec);
+   pMGADRI->sarea_priv_offset = sizeof(drm_sarea_t);
 
    print_client_msg( pMGADRI );
 
@@ -880,50 +877,6 @@ static int MGAScreenInit( struct DRIDriverContextRec *ctx, MGAPtr pMga )
 }
 
 
-/**
- * \brief Establish the set of modes available for the display.
- *
- * \param ctx display handle.
- * \param numModes will receive the number of supported modes.
- * \param modes will point to the list of supported modes.
- *
- * \return one on success, or zero on failure.
- * 
- * Allocates a single visual and fills it with information according to the
- * display bit depth. Supports only 16 and 32 bpp bit depths, aborting
- * otherwise.
- */
-const __GLcontextModes __glModes[] = {
-    
-    /* 32 bit, RGBA Depth=24 Stencil=8 */
-    {.rgbMode = GL_TRUE, .colorIndexMode = GL_FALSE, .doubleBufferMode = GL_TRUE, .stereoMode = GL_FALSE,
-     .haveAccumBuffer = GL_FALSE, .haveDepthBuffer = GL_TRUE, .haveStencilBuffer = GL_TRUE,
-     .redBits = 8, .greenBits = 8, .blueBits = 8, .alphaBits = 8,
-     .redMask = 0xff0000, .greenMask = 0xff00, .blueMask = 0xff, .alphaMask = 0xff000000,
-     .rgbBits = 32, .indexBits = 0,
-     .accumRedBits = 0, .accumGreenBits = 0, .accumBlueBits = 0, .accumAlphaBits = 0,
-     .depthBits = 24, .stencilBits = 8,
-     .numAuxBuffers= 0, .level = 0, .pixmapMode = GL_FALSE, },
-
-    /* 16 bit, RGB Depth=16 */
-    {.rgbMode = GL_TRUE, .colorIndexMode = GL_FALSE, .doubleBufferMode = GL_TRUE, .stereoMode = GL_FALSE,
-     .haveAccumBuffer = GL_FALSE, .haveDepthBuffer = GL_TRUE, .haveStencilBuffer = GL_FALSE,
-     .redBits = 5, .greenBits = 6, .blueBits = 5, .alphaBits = 0,
-     .redMask = 0xf800, .greenMask = 0x07e0, .blueMask = 0x001f, .alphaMask = 0x0,
-     .rgbBits = 16, .indexBits = 0,
-     .accumRedBits = 0, .accumGreenBits = 0, .accumBlueBits = 0, .accumAlphaBits = 0,
-     .depthBits = 16, .stencilBits = 0,
-     .numAuxBuffers= 0, .level = 0, .pixmapMode = GL_FALSE, },
-};
-static int mgaInitContextModes( const DRIDriverContext *ctx,
-                                  int *numModes, const __GLcontextModes **modes)
-{
-   *numModes = sizeof(__glModes)/sizeof(__GLcontextModes *);
-   *modes = &__glModes[0];
-   return 1;
-}
-
-
 /**
  * \brief Validate the fbdev mode.
  * 
@@ -1047,7 +1000,6 @@ static int mgaEngineRestore( const DRIDriverContext *ctx )
  * \sa DRIDriverRec.
  */
 struct DRIDriverRec __driDriver = {
-   mgaInitContextModes,
    mgaValidateMode,
    mgaPostValidateMode,
    mgaInitFBDev,