diff options
Diffstat (limited to 'src/mga_dri.c')
-rw-r--r-- | src/mga_dri.c | 182 |
1 files changed, 46 insertions, 136 deletions
diff --git a/src/mga_dri.c b/src/mga_dri.c index 1506a7f..d919161 100644 --- a/src/mga_dri.c +++ b/src/mga_dri.c @@ -52,7 +52,7 @@ #include "mga_macros.h" #include "mga_dri.h" #include "mga_sarea.h" -#include "mga_common.h" +#include "mga_drm.h" #define _XF86DRI_SERVER_ #include "GL/glxtokens.h" @@ -70,7 +70,7 @@ #include "mga_macros.h" #include "mga_dri.h" -#include "mga_sarea.h" +#define DRM_MGA_IDLE_RETRY 2048 static char MGAKernelDriverName[] = "mga"; static char MGAClientDriverName[] = "mga"; @@ -343,27 +343,27 @@ static void MGADestroyContext( ScreenPtr pScreen, drm_context_t hwContext, static void MGAWaitForIdleDMA( ScrnInfoPtr pScrn ) { MGAPtr pMga = MGAPTR(pScrn); - drmMGALock lock; + drm_lock_t lock; int ret; int i = 0; - memset( &lock, 0, sizeof(drmMGALock) ); + memset( &lock, 0, sizeof(drm_lock_t) ); 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( pMga->drmFD, DRM_MGA_FLUSH, - &lock, sizeof( drmMGALock ) ); + &lock, sizeof( drm_lock_t ) ); } 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( pMga->drmFD, DRM_MGA_FLUSH, - &lock, sizeof( drmMGALock ) ); + &lock, sizeof( drm_lock_t ) ); } while ( ret == -EBUSY && i++ < DRM_MGA_IDLE_RETRY ); } } while ( ( ret == -EBUSY ) && ( i++ < MGA_TIMEOUT ) ); @@ -583,7 +583,17 @@ static unsigned int mylog2( unsigned int n ) return log2; } -static Bool MGADRIAgpInit(ScreenPtr pScreen) +/** + * Initialize DMA and secondary texture memory + * + * \todo + * The sizes used for the primary DMA buffer and the bin size and count for + * the secondary DMA buffers should be configurable from the xorg.conf. + * + * \todo + * Add support for PCI cards. + */ +static Bool MGADRIBootstrapDMA(ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; MGAPtr pMga = MGAPTR(pScrn); @@ -700,18 +710,6 @@ static Bool MGADRIAgpInit(ScreenPtr pScreen) "[agp] WARP microcode handle = 0x%08lx\n", pMGADRIServer->warp.handle ); - if ( drmMap( pMga->drmFD, - pMGADRIServer->warp.handle, - pMGADRIServer->warp.size, - &pMGADRIServer->warp.map ) < 0 ) { - xf86DrvMsg( pScreen->myNum, X_ERROR, - "[agp] Could not map WARP microcode\n" ); - return FALSE; - } - xf86DrvMsg( pScreen->myNum, X_INFO, - "[agp] WARP microcode mapped at 0x%08lx\n", - (unsigned long)pMGADRIServer->warp.map ); - /* Primary DMA space */ if ( drmAddMap( pMga->drmFD, @@ -727,18 +725,6 @@ static Bool MGADRIAgpInit(ScreenPtr pScreen) "[agp] Primary DMA handle = 0x%08lx\n", pMGADRIServer->primary.handle ); - if ( drmMap( pMga->drmFD, - pMGADRIServer->primary.handle, - pMGADRIServer->primary.size, - &pMGADRIServer->primary.map ) < 0 ) { - xf86DrvMsg( pScreen->myNum, X_ERROR, - "[agp] Could not map primary DMA\n" ); - return FALSE; - } - xf86DrvMsg( pScreen->myNum, X_INFO, - "[agp] Primary DMA mapped at 0x%08lx\n", - (unsigned long)pMGADRIServer->primary.map ); - /* DMA buffers */ if ( drmAddMap( pMga->drmFD, @@ -754,18 +740,6 @@ static Bool MGADRIAgpInit(ScreenPtr pScreen) "[agp] DMA buffers handle = 0x%08lx\n", pMGADRIServer->buffers.handle ); - if ( drmMap( pMga->drmFD, - pMGADRIServer->buffers.handle, - pMGADRIServer->buffers.size, - &pMGADRIServer->buffers.map ) < 0 ) { - xf86DrvMsg( pScreen->myNum, X_ERROR, - "[agp] Could not map DMA buffers\n" ); - return FALSE; - } - xf86DrvMsg( pScreen->myNum, X_INFO, - "[agp] DMA buffers mapped at 0x%08lx\n", - (unsigned long)pMGADRIServer->buffers.map ); - count = drmAddBufs( pMga->drmFD, MGA_NUM_BUFFERS, MGA_BUFFER_SIZE, DRM_AGP_BUFFER, pMGADRIServer->buffers.offset ); @@ -793,22 +767,13 @@ static Bool MGADRIAgpInit(ScreenPtr pScreen) "[agp] Could not add agpTexture mapping\n" ); return FALSE; } -/* should i map it ? */ + xf86DrvMsg( pScreen->myNum, X_INFO, "[agp] agpTexture handle = 0x%08lx\n", pMGADRIServer->agpTextures.handle ); xf86DrvMsg( pScreen->myNum, X_INFO, "[agp] agpTexture size: %d kb\n", pMGADRIServer->agpTextures.size/1024 ); - return TRUE; -} - -static Bool MGADRIMapInit( ScreenPtr pScreen ) -{ - ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; - MGAPtr pMga = MGAPTR(pScrn); - MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; - pMGADRIServer->registers.size = MGAIOMAPSIZE; if ( drmAddMap( pMga->drmFD, @@ -837,18 +802,6 @@ static Bool MGADRIMapInit( ScreenPtr pScreen ) "[drm] Status handle = 0x%08lx\n", pMGADRIServer->status.handle ); - if ( drmMap( pMga->drmFD, - pMGADRIServer->status.handle, - pMGADRIServer->status.size, - &pMGADRIServer->status.map ) < 0 ) { - xf86DrvMsg( pScreen->myNum, X_ERROR, - "[agp] Could not map status page\n" ); - return FALSE; - } - xf86DrvMsg( pScreen->myNum, X_INFO, - "[agp] Status page mapped at 0x%08lx\n", - (unsigned long)pMGADRIServer->status.map ); - return TRUE; } @@ -857,10 +810,10 @@ static Bool MGADRIKernelInit( ScreenPtr pScreen ) ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; MGAPtr pMga = MGAPTR(pScrn); MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; - drmMGAInit init; + drm_mga_init_t init; int ret; - memset( &init, 0, sizeof(drmMGAInit) ); + memset( &init, 0, sizeof(drm_mga_init_t) ); init.func = MGA_INIT_DMA; init.sarea_priv_offset = sizeof(XF86DRISAREARec); @@ -905,19 +858,13 @@ static Bool MGADRIKernelInit( ScreenPtr pScreen ) init.texture_offset[1] = pMGADRIServer->agpTextures.handle; init.texture_size[1] = pMGADRIServer->agpTextures.size; - ret = drmCommandWrite( pMga->drmFD, DRM_MGA_INIT, &init, sizeof(drmMGAInit)); + ret = drmCommandWrite( pMga->drmFD, DRM_MGA_INIT, &init, sizeof(drm_mga_init_t)); if ( ret < 0 ) { xf86DrvMsg( pScrn->scrnIndex, X_ERROR, "[drm] Failed to initialize DMA! (%d)\n", ret ); return FALSE; } -#if 0 - /* FIXME: This is just here to clean up after the engine reset test - * in the kernel module. Please remove it later... - */ - pMga->GetQuiescence( pScrn ); -#endif return TRUE; } @@ -1215,33 +1162,11 @@ Bool MGADRIScreenInit( ScreenPtr pScreen ) } } -#if 0 - /* Calculate texture constants for AGP texture space. - * FIXME: move! - */ - { - CARD32 agpTextureOffset = MGA_DMA_BUF_SZ * MGA_DMA_BUF_NR; - CARD32 agpTextureSize = pMGADRI->agp.size - agpTextureOffset; - - i = mylog2(agpTextureSize / MGA_NR_TEX_REGIONS); - if (i < MGA_LOG_MIN_TEX_REGION_SIZE) - i = MGA_LOG_MIN_TEX_REGION_SIZE; - - pMGADRI->logAgpTextureGranularity = i; - pMGADRI->agpTextureSize = (agpTextureSize >> i) << i; - pMGADRI->agpTextureOffset = agpTextureOffset; - } -#endif - - if ( !MGADRIAgpInit( pScreen ) ) { + if ( !MGADRIBootstrapDMA( pScreen ) ) { DRICloseScreen( pScreen ); return FALSE; } - if ( !MGADRIMapInit( pScreen ) ) { - DRICloseScreen( pScreen ); - return FALSE; - } { void *scratch_ptr; int scratch_int; @@ -1311,7 +1236,6 @@ Bool MGADRIFinishScreenInit( ScreenPtr pScreen ) } pMGADRI->width = pScrn->virtualX; pMGADRI->height = pScrn->virtualY; - pMGADRI->mem = pScrn->videoRam * 1024; pMGADRI->cpp = pScrn->bitsPerPixel / 8; pMGADRI->agpMode = pMga->agpMode; @@ -1325,6 +1249,25 @@ Bool MGADRIFinishScreenInit( ScreenPtr pScreen ) pMGADRI->textureOffset = pMGADRIServer->textureOffset; pMGADRI->textureSize = pMGADRIServer->textureSize; + pMGADRI->agpTextureOffset = (unsigned int)pMGADRIServer->agpTextures.handle; + pMGADRI->agpTextureSize = (unsigned int)pMGADRIServer->agpTextures.size; + + pMGADRI->registers.handle = pMGADRIServer->registers.handle; + pMGADRI->registers.size = pMGADRIServer->registers.size; + pMGADRI->primary.handle = pMGADRIServer->primary.handle; + pMGADRI->primary.size = pMGADRIServer->primary.size; + pMGADRI->sarea_priv_offset = sizeof(XF86DRISAREARec); + + + /* These are no longer used by the client-side DRI driver. They should + * be removed in the next release (i.e., 6.9 / 7.0). + */ + + pMGADRI->status.handle = pMGADRIServer->status.handle; + pMGADRI->status.size = pMGADRIServer->status.size; + pMGADRI->buffers.handle = pMGADRIServer->buffers.handle; + pMGADRI->buffers.size = pMGADRIServer->buffers.size; + i = mylog2( pMGADRI->textureSize / MGA_NR_TEX_REGIONS ); if ( i < MGA_LOG_MIN_TEX_REGION_SIZE ) i = MGA_LOG_MIN_TEX_REGION_SIZE; @@ -1337,18 +1280,7 @@ Bool MGADRIFinishScreenInit( ScreenPtr pScreen ) i = MGA_LOG_MIN_TEX_REGION_SIZE; pMGADRI->logAgpTextureGranularity = i; - pMGADRI->agpTextureOffset = (unsigned int)pMGADRIServer->agpTextures.handle; - pMGADRI->agpTextureSize = (unsigned int)pMGADRIServer->agpTextures.size; - pMGADRI->registers.handle = pMGADRIServer->registers.handle; - pMGADRI->registers.size = pMGADRIServer->registers.size; - pMGADRI->status.handle = pMGADRIServer->status.handle; - pMGADRI->status.size = pMGADRIServer->status.size; - pMGADRI->primary.handle = pMGADRIServer->primary.handle; - pMGADRI->primary.size = pMGADRIServer->primary.size; - pMGADRI->buffers.handle = pMGADRIServer->buffers.handle; - pMGADRI->buffers.size = pMGADRIServer->buffers.size; - pMGADRI->sarea_priv_offset = sizeof(XF86DRISAREARec); return TRUE; } @@ -1358,7 +1290,7 @@ void MGADRICloseScreen( ScreenPtr pScreen ) ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum]; MGAPtr pMga = MGAPTR(pScrn); MGADRIServerPrivatePtr pMGADRIServer = pMga->DRIServerInfo; - drmMGAInit init; + drm_mga_init_t init; if ( pMGADRIServer->drmBuffers ) { drmUnmapBufs( pMGADRIServer->drmBuffers ); @@ -1372,31 +1304,9 @@ void MGADRICloseScreen( ScreenPtr pScreen ) } /* Cleanup DMA */ - memset( &init, 0, sizeof(drmMGAInit) ); + memset( &init, 0, sizeof(drm_mga_init_t) ); init.func = MGA_CLEANUP_DMA; - drmCommandWrite( pMga->drmFD, DRM_MGA_INIT, &init, sizeof(drmMGAInit) ); - - if ( pMGADRIServer->status.map ) { - drmUnmap( pMGADRIServer->status.map, pMGADRIServer->status.size ); - pMGADRIServer->status.map = NULL; - } - if ( pMGADRIServer->buffers.map ) { - drmUnmap( pMGADRIServer->buffers.map, pMGADRIServer->buffers.size ); - pMGADRIServer->buffers.map = NULL; - } - if ( pMGADRIServer->primary.map ) { - drmUnmap( pMGADRIServer->primary.map, pMGADRIServer->primary.size ); - pMGADRIServer->primary.map = NULL; - } - if ( pMGADRIServer->warp.map ) { - drmUnmap( pMGADRIServer->warp.map, pMGADRIServer->warp.size ); - pMGADRIServer->warp.map = NULL; - } - - if ( pMGADRIServer->agpTextures.map ) { - drmUnmap( pMGADRIServer->agpTextures.map, pMGADRIServer->agpTextures.size ); - pMGADRIServer->agpTextures.map = NULL; - } + drmCommandWrite( pMga->drmFD, DRM_MGA_INIT, &init, sizeof(drm_mga_init_t) ); if ( pMGADRIServer->agp.handle != DRM_AGP_NO_HANDLE ) { drmAgpUnbind( pMga->drmFD, pMGADRIServer->agp.handle ); |