Small optimization for big-endian (e.g., PowerPC) systems.
[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 #ifdef GLX_DIRECT_RENDERING
39
40 #include "r128_dri.h"
41 #include "r128_reg.h"
42 #include "r128_lock.h"
43
44 #define R128_BUFFER_MAX_DWORDS (R128_BUFFER_SIZE / sizeof(uint32_t))
45
46
47 extern drmBufPtr r128GetBufferLocked( r128ContextPtr rmesa );
48 extern void r128FlushVerticesLocked( r128ContextPtr rmesa );
49
50 static __inline void *r128AllocDmaLow( r128ContextPtr rmesa, int count,
51 int vert_size )
52 {
53 uint32_t *head;
54 int bytes = count * vert_size;
55
56 if ( !rmesa->vert_buf ) {
57 LOCK_HARDWARE( rmesa );
58 rmesa->vert_buf = r128GetBufferLocked( rmesa );
59 UNLOCK_HARDWARE( rmesa );
60 } else if ( rmesa->vert_buf->used + bytes > rmesa->vert_buf->total ) {
61 LOCK_HARDWARE( rmesa );
62 r128FlushVerticesLocked( rmesa );
63 rmesa->vert_buf = r128GetBufferLocked( rmesa );
64 UNLOCK_HARDWARE( rmesa );
65 }
66
67 head = (uint32_t *)((char *)rmesa->vert_buf->address + rmesa->vert_buf->used);
68 rmesa->vert_buf->used += bytes;
69 rmesa->num_verts += count;
70
71 return head;
72 }
73
74 extern void r128FireBlitLocked( r128ContextPtr rmesa, drmBufPtr buffer,
75 GLint offset, GLint pitch, GLint format,
76 GLint x, GLint y, GLint width, GLint height );
77
78 extern void r128WriteDepthSpanLocked( r128ContextPtr rmesa,
79 GLuint n, GLint x, GLint y,
80 const GLdepth depth[],
81 const GLubyte mask[] );
82 extern void r128WriteDepthPixelsLocked( r128ContextPtr rmesa, GLuint n,
83 const GLint x[], const GLint y[],
84 const GLdepth depth[],
85 const GLubyte mask[] );
86 extern void r128ReadDepthSpanLocked( r128ContextPtr rmesa,
87 GLuint n, GLint x, GLint y );
88 extern void r128ReadDepthPixelsLocked( r128ContextPtr rmesa, GLuint n,
89 const GLint x[], const GLint y[] );
90
91 extern void r128CopyBuffer( const __DRIdrawablePrivate *dPriv );
92 extern void r128PageFlip( const __DRIdrawablePrivate *dPriv );
93 void r128WaitForVBlank( r128ContextPtr rmesa );
94
95 extern void r128WaitForIdleLocked( r128ContextPtr rmesa );
96
97
98 extern void r128InitIoctlFuncs( struct dd_function_table *functions );
99
100
101 /* ================================================================
102 * Helper macros:
103 */
104
105 #define FLUSH_BATCH( rmesa ) \
106 do { \
107 if ( R128_DEBUG & DEBUG_VERBOSE_IOCTL ) \
108 fprintf( stderr, "FLUSH_BATCH in %s\n", __FUNCTION__ ); \
109 if ( rmesa->vert_buf ) { \
110 r128FlushVertices( rmesa ); \
111 } \
112 } while (0)
113
114 /* 64-bit align the next element address, and then make room for the
115 * next indexed prim packet header.
116 */
117 #define ALIGN_NEXT_ELT( rmesa ) \
118 do { \
119 rmesa->next_elt = (GLushort *) \
120 (((GLuint)rmesa->next_elt + 7) & ~0x7); \
121 rmesa->next_elt = (GLushort *) \
122 ((GLubyte *)rmesa->next_elt + R128_INDEX_PRIM_OFFSET); \
123 } while (0)
124
125 #define r128FlushVertices( rmesa ) \
126 do { \
127 LOCK_HARDWARE( rmesa ); \
128 r128FlushVerticesLocked( rmesa ); \
129 UNLOCK_HARDWARE( rmesa ); \
130 } while (0)
131
132 #define r128FlushElts( rmesa ) \
133 do { \
134 LOCK_HARDWARE( rmesa ); \
135 r128FlushEltsLocked( rmesa ); \
136 UNLOCK_HARDWARE( rmesa ); \
137 } while (0)
138
139 #define r128WaitForIdle( rmesa ) \
140 do { \
141 LOCK_HARDWARE( rmesa ); \
142 r128WaitForIdleLocked( rmesa ); \
143 UNLOCK_HARDWARE( rmesa ); \
144 } while (0)
145
146 #endif
147 #endif /* __R128_IOCTL_H__ */