locking fixes (Martijn Van Oosterhout)
[mesa.git] / src / mesa / drivers / dri / r128 / r128_ioctl.h
1 /* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_ioctl.h,v 1.6 2002/12/16 16:18:53 dawes Exp $ */
2 /**************************************************************************
3
4 Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc.,
5 Cedar Park, Texas.
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files (the "Software"),
10 to deal in the Software without restriction, including without limitation
11 on the rights to use, copy, modify, merge, publish, distribute, sub
12 license, and/or sell copies of the Software, and to permit persons to whom
13 the Software is furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice (including the next
16 paragraph) shall be included in all copies or substantial portions of the
17 Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 ATI, PRECISION INSIGHT AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
26
27 **************************************************************************/
28
29 /*
30 * Authors:
31 * Gareth Hughes <gareth@valinux.com>
32 *
33 */
34
35 #ifndef __R128_IOCTL_H__
36 #define __R128_IOCTL_H__
37
38 #include "r128_dri.h"
39 #include "r128_reg.h"
40 #include "r128_lock.h"
41
42 #define R128_BUFFER_MAX_DWORDS (R128_BUFFER_SIZE / sizeof(u_int32_t))
43
44
45 extern drmBufPtr r128GetBufferLocked( r128ContextPtr rmesa );
46 extern void r128FlushVerticesLocked( r128ContextPtr rmesa );
47
48 static __inline void *r128AllocDmaLow( r128ContextPtr rmesa, int count,
49 int vert_size )
50 {
51 u_int32_t *head;
52 int bytes = count * vert_size;
53
54 if ( !rmesa->vert_buf ) {
55 LOCK_HARDWARE( rmesa );
56 rmesa->vert_buf = r128GetBufferLocked( rmesa );
57 UNLOCK_HARDWARE( rmesa );
58 } else if ( rmesa->vert_buf->used + bytes > rmesa->vert_buf->total ) {
59 LOCK_HARDWARE( rmesa );
60 r128FlushVerticesLocked( rmesa );
61 rmesa->vert_buf = r128GetBufferLocked( rmesa );
62 UNLOCK_HARDWARE( rmesa );
63 }
64
65 head = (u_int32_t *)((char *)rmesa->vert_buf->address + rmesa->vert_buf->used);
66 rmesa->vert_buf->used += bytes;
67 rmesa->num_verts += count;
68
69 return head;
70 }
71
72 extern void r128FireBlitLocked( r128ContextPtr rmesa, drmBufPtr buffer,
73 GLint offset, GLint pitch, GLint format,
74 GLint x, GLint y, GLint width, GLint height );
75
76 extern void r128WriteDepthSpanLocked( r128ContextPtr rmesa,
77 GLuint n, GLint x, GLint y,
78 const GLuint depth[],
79 const GLubyte mask[] );
80 extern void r128WriteDepthPixelsLocked( r128ContextPtr rmesa, GLuint n,
81 const GLint x[], const GLint y[],
82 const GLuint depth[],
83 const GLubyte mask[] );
84 extern void r128ReadDepthSpanLocked( r128ContextPtr rmesa,
85 GLuint n, GLint x, GLint y );
86 extern void r128ReadDepthPixelsLocked( r128ContextPtr rmesa, GLuint n,
87 const GLint x[], const GLint y[] );
88
89 extern void r128CopyBuffer( const __DRIdrawablePrivate *dPriv );
90 extern void r128PageFlip( const __DRIdrawablePrivate *dPriv );
91 void r128WaitForVBlank( r128ContextPtr rmesa );
92
93 extern void r128WaitForIdleLocked( r128ContextPtr rmesa );
94
95
96 extern void r128InitIoctlFuncs( struct dd_function_table *functions );
97
98
99 /* ================================================================
100 * Helper macros:
101 */
102
103 #define FLUSH_BATCH( rmesa ) \
104 do { \
105 if ( R128_DEBUG & DEBUG_VERBOSE_IOCTL ) \
106 fprintf( stderr, "FLUSH_BATCH in %s\n", __FUNCTION__ ); \
107 if ( rmesa->vert_buf ) { \
108 r128FlushVertices( rmesa ); \
109 } \
110 } while (0)
111
112 /* 64-bit align the next element address, and then make room for the
113 * next indexed prim packet header.
114 */
115 #define ALIGN_NEXT_ELT( rmesa ) \
116 do { \
117 rmesa->next_elt = (GLushort *) \
118 (((GLuint)rmesa->next_elt + 7) & ~0x7); \
119 rmesa->next_elt = (GLushort *) \
120 ((GLubyte *)rmesa->next_elt + R128_INDEX_PRIM_OFFSET); \
121 } while (0)
122
123 #define r128FlushVertices( rmesa ) \
124 do { \
125 LOCK_HARDWARE( rmesa ); \
126 r128FlushVerticesLocked( rmesa ); \
127 UNLOCK_HARDWARE( rmesa ); \
128 } while (0)
129
130 #define r128FlushElts( rmesa ) \
131 do { \
132 LOCK_HARDWARE( rmesa ); \
133 r128FlushEltsLocked( rmesa ); \
134 UNLOCK_HARDWARE( rmesa ); \
135 } while (0)
136
137 #define r128WaitForIdle( rmesa ) \
138 do { \
139 LOCK_HARDWARE( rmesa ); \
140 r128WaitForIdleLocked( rmesa ); \
141 UNLOCK_HARDWARE( rmesa ); \
142 } while (0)
143
144 #endif /* __R128_IOCTL_H__ */