patch to import Jon Smirl's work from Bitkeeper
[mesa.git] / src / mesa / drivers / dri / mga / mgaioctl.h
1 /*
2 * Copyright 2000-2001 VA Linux Systems, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Keith Whitwell <keith@tungstengraphics.com>
26 * Gareth Hughes <gareth@valinux.com>
27 */
28 /* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgaioctl.h,v 1.11 2002/10/30 12:51:36 alanh Exp $ */
29
30 #ifndef MGA_IOCTL_H
31 #define MGA_IOCTL_H
32
33 #include "mgacontext.h"
34 #include "mga_xmesa.h"
35
36 void mgaSwapBuffers( __DRIdrawablePrivate *dPriv );
37 void mgaWaitForVBlank( mgaContextPtr mmesa );
38
39 GLuint *mgaAllocVertexDwords( mgaContextPtr mmesa, int dwords );
40
41
42 void mgaGetILoadBufferLocked( mgaContextPtr mmesa );
43 drmBufPtr mgaGetBufferLocked( mgaContextPtr mmesa );
44
45
46 void mgaFireILoadLocked( mgaContextPtr mmesa,
47 GLuint offset, GLuint length );
48
49 void mgaWaitAgeLocked( mgaContextPtr mmesa, int age );
50 void mgaWaitAge( mgaContextPtr mmesa, int age );
51
52 void mgaFlushVertices( mgaContextPtr mmesa );
53 void mgaFlushVerticesLocked( mgaContextPtr mmesa );
54 void mgaReleaseBufLocked( mgaContextPtr mmesa, drmBufPtr buffer );
55 int mgaFlushDMA( int fd, drmLockFlags flags );
56
57 void mgaDDFlush( GLcontext *ctx );
58 void mgaDDFinish( GLcontext *ctx );
59
60 void mgaDDInitIoctlFuncs( GLcontext *ctx );
61
62 #define FLUSH_BATCH(mmesa) do { \
63 if (MGA_DEBUG&DEBUG_VERBOSE_IOCTL) \
64 fprintf(stderr, "FLUSH_BATCH in %s\n", __FUNCTION__); \
65 if (mmesa->vertex_dma_buffer) mgaFlushVertices(mmesa); \
66 } while (0)
67
68 #define MGA_STATECHANGE(mmesa, flag) do { \
69 FLUSH_BATCH(mmesa); \
70 mmesa->dirty |= flag; \
71 } while (0)
72
73
74 extern drmBufPtr mga_get_buffer_ioctl( mgaContextPtr mmesa );
75
76 static __inline
77 GLuint *mgaAllocDmaLow( mgaContextPtr mmesa, int bytes )
78 {
79 GLuint *head;
80
81 if (!mmesa->vertex_dma_buffer) {
82 LOCK_HARDWARE( mmesa );
83 mmesa->vertex_dma_buffer = mga_get_buffer_ioctl( mmesa );
84 UNLOCK_HARDWARE( mmesa );
85 } else if (mmesa->vertex_dma_buffer->used + bytes >
86 mmesa->vertex_dma_buffer->total) {
87 LOCK_HARDWARE( mmesa );
88 mgaFlushVerticesLocked( mmesa );
89 mmesa->vertex_dma_buffer = mga_get_buffer_ioctl( mmesa );
90 UNLOCK_HARDWARE( mmesa );
91 }
92
93 head = (GLuint *)((char *)mmesa->vertex_dma_buffer->address +
94 mmesa->vertex_dma_buffer->used);
95
96 mmesa->vertex_dma_buffer->used += bytes;
97 return head;
98 }
99
100
101 #define UPDATE_LOCK( mmesa, flags ) \
102 do { \
103 GLint ret = mgaFlushDMA( mmesa->driFd, flags ); \
104 if ( ret < 0 ) { \
105 drmCommandNone( mmesa->driFd, DRM_MGA_RESET ); \
106 UNLOCK_HARDWARE( mmesa ); \
107 fprintf( stderr, "%s: flush return = %s (%d), flags = 0x%08x\n", \
108 __FUNCTION__, strerror( -ret ), -ret, \
109 (unsigned)(flags) ); \
110 exit( 1 ); \
111 } \
112 } while (0)
113
114 #endif