#ifndef MGA_IOCTL_H
#define MGA_IOCTL_H
#include "mgacontext.h"
#include "mga_xmesa.h"
void mgaCopyBuffer( const __DRIdrawablePrivate *dPriv );
void mgaWaitForVBlank( mgaContextPtr mmesa );
GLuint *mgaAllocVertexDwords( mgaContextPtr mmesa, int dwords );
void mgaGetILoadBufferLocked( mgaContextPtr mmesa );
drmBufPtr mgaGetBufferLocked( mgaContextPtr mmesa );
void mgaFireILoadLocked( mgaContextPtr mmesa,
GLuint offset, GLuint length );
void mgaWaitAgeLocked( mgaContextPtr mmesa, int age );
void mgaWaitAge( mgaContextPtr mmesa, int age );
void mgaFlushVertices( mgaContextPtr mmesa );
void mgaFlushVerticesLocked( mgaContextPtr mmesa );
void mgaReleaseBufLocked( mgaContextPtr mmesa, drmBufPtr buffer );
int mgaFlushDMA( int fd, drmLockFlags flags );
void mgaDDFlush( GLcontext *ctx );
void mgaDDFinish( GLcontext *ctx );
void mgaDDInitIoctlFuncs( GLcontext *ctx );
#define FLUSH_BATCH(mmesa) do { \
if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) \
fprintf(stderr, "FLUSH_BATCH in %s\n", __FUNCTION__); \
if (mmesa->vertex_dma_buffer) mgaFlushVertices(mmesa); \
} while (0)
#define MGA_STATECHANGE(mmesa, flag) do { \
FLUSH_BATCH(mmesa); \
mmesa->dirty |= flag; \
} while (0)
extern drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa );
static __inline
GLuint *mgaAllocDmaLow( mgaContextPtr mmesa, int bytes )
{
GLuint *head;
if (!mmesa->vertex_dma_buffer) {
LOCK_HARDWARE( mmesa );
mmesa->vertex_dma_buffer = mga_get_buffer_ioctl( mmesa );
UNLOCK_HARDWARE( mmesa );
} else if (mmesa->vertex_dma_buffer->used + bytes >
mmesa->vertex_dma_buffer->total) {
LOCK_HARDWARE( mmesa );
mgaFlushVerticesLocked( mmesa );
mmesa->vertex_dma_buffer = mga_get_buffer_ioctl( mmesa );
UNLOCK_HARDWARE( mmesa );
}
head = (GLuint *)((char *)mmesa->vertex_dma_buffer->address +
mmesa->vertex_dma_buffer->used);
mmesa->vertex_dma_buffer->used += bytes;
return head;
}
#define UPDATE_LOCK( mmesa, flags ) \
do { \
GLint ret = mgaFlushDMA( mmesa->driFd, flags ); \
if ( ret < 0 ) { \
drmCommandNone( mmesa->driFd, DRM_MGA_RESET ); \
UNLOCK_HARDWARE( mmesa ); \
fprintf( stderr, "%s: flush return = %s (%d), flags = 0x%08x\n", \
__FUNCTION__, strerror( -ret ), -ret, \
(unsigned)(flags) ); \
exit( 1 ); \
} \
} while (0)
#endif