Merge branch 'mesa_7_5_branch'
[mesa.git] / src / mesa / drivers / dri / r200 / r200_ioctl.h
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /*
31 * Authors:
32 * Keith Whitwell <keith@tungstengraphics.com>
33 */
34
35 #ifndef __R200_IOCTL_H__
36 #define __R200_IOCTL_H__
37
38 #include "main/simple_list.h"
39 #include "radeon_dri.h"
40 #include "r200_lock.h"
41
42 #include "xf86drm.h"
43 #include "drm.h"
44 #include "radeon_drm.h"
45
46 extern void r200EmitState( r200ContextPtr rmesa );
47 extern void r200EmitVertexAOS( r200ContextPtr rmesa,
48 GLuint vertex_size,
49 GLuint offset );
50
51 extern void r200EmitVbufPrim( r200ContextPtr rmesa,
52 GLuint primitive,
53 GLuint vertex_nr );
54
55 extern void r200FlushElts( r200ContextPtr rmesa );
56
57 extern GLushort *r200AllocEltsOpenEnded( r200ContextPtr rmesa,
58 GLuint primitive,
59 GLuint min_nr );
60
61 extern void r200EmitAOS( r200ContextPtr rmesa,
62 struct r200_dma_region **regions,
63 GLuint n,
64 GLuint offset );
65
66 extern void r200EmitBlit( r200ContextPtr rmesa,
67 GLuint color_fmt,
68 GLuint src_pitch,
69 GLuint src_offset,
70 GLuint dst_pitch,
71 GLuint dst_offset,
72 GLint srcx, GLint srcy,
73 GLint dstx, GLint dsty,
74 GLuint w, GLuint h );
75
76 extern void r200EmitWait( r200ContextPtr rmesa, GLuint flags );
77
78 extern void r200FlushCmdBuf( r200ContextPtr rmesa, const char * );
79 extern int r200FlushCmdBufLocked( r200ContextPtr rmesa, const char * caller );
80
81 extern void r200RefillCurrentDmaRegion( r200ContextPtr rmesa );
82
83 extern void r200AllocDmaRegion( r200ContextPtr rmesa,
84 struct r200_dma_region *region,
85 int bytes,
86 int alignment );
87
88 extern void r200ReleaseDmaRegion( r200ContextPtr rmesa,
89 struct r200_dma_region *region,
90 const char *caller );
91
92 extern void r200CopyBuffer( __DRIdrawablePrivate *drawable,
93 const drm_clip_rect_t *rect);
94 extern void r200PageFlip( __DRIdrawablePrivate *drawable );
95 extern void r200Flush( GLcontext *ctx );
96 extern void r200Finish( GLcontext *ctx );
97 extern void r200WaitForIdleLocked( r200ContextPtr rmesa );
98 extern void r200WaitForVBlank( r200ContextPtr rmesa );
99 extern void r200InitIoctlFuncs( struct dd_function_table *functions );
100
101 extern void *r200AllocateMemoryMESA( __DRIscreen *screen, GLsizei size, GLfloat readfreq,
102 GLfloat writefreq, GLfloat priority );
103 extern void r200FreeMemoryMESA( __DRIscreen *screen, GLvoid *pointer );
104 extern GLuint r200GetMemoryOffsetMESA( __DRIscreen *screen, const GLvoid *pointer );
105
106 extern GLboolean r200IsGartMemory( r200ContextPtr rmesa, const GLvoid *pointer,
107 GLint size );
108
109 extern GLuint r200GartOffsetFromVirtual( r200ContextPtr rmesa,
110 const GLvoid *pointer );
111
112 void r200SetUpAtomList( r200ContextPtr rmesa );
113
114 /* ================================================================
115 * Helper macros:
116 */
117
118 /* Close off the last primitive, if it exists.
119 */
120 #define R200_NEWPRIM( rmesa ) \
121 do { \
122 if ( rmesa->dma.flush ) \
123 rmesa->dma.flush( rmesa ); \
124 } while (0)
125
126 /* Can accomodate several state changes and primitive changes without
127 * actually firing the buffer.
128 */
129 #define R200_STATECHANGE( rmesa, ATOM ) \
130 do { \
131 R200_NEWPRIM( rmesa ); \
132 rmesa->hw.ATOM.dirty = GL_TRUE; \
133 rmesa->hw.is_dirty = GL_TRUE; \
134 } while (0)
135
136 #define R200_DB_STATE( ATOM ) \
137 memcpy( rmesa->hw.ATOM.lastcmd, rmesa->hw.ATOM.cmd, \
138 rmesa->hw.ATOM.cmd_size * 4)
139
140 static INLINE int R200_DB_STATECHANGE(
141 r200ContextPtr rmesa,
142 struct r200_state_atom *atom )
143 {
144 if (memcmp(atom->cmd, atom->lastcmd, atom->cmd_size*4)) {
145 int *tmp;
146 R200_NEWPRIM( rmesa );
147 atom->dirty = GL_TRUE;
148 rmesa->hw.is_dirty = GL_TRUE;
149 tmp = atom->cmd;
150 atom->cmd = atom->lastcmd;
151 atom->lastcmd = tmp;
152 return 1;
153 }
154 else
155 return 0;
156 }
157
158
159 /* Fire the buffered vertices no matter what.
160 */
161 #define R200_FIREVERTICES( rmesa ) \
162 do { \
163 if ( rmesa->store.cmd_used || rmesa->dma.flush ) { \
164 r200Flush( rmesa->glCtx ); \
165 } \
166 } while (0)
167
168 /* Command lengths. Note that any time you ensure ELTS_BUFSZ or VBUF_BUFSZ
169 * are available, you will also be adding an rmesa->state.max_state_size because
170 * r200EmitState is called from within r200EmitVbufPrim and r200FlushElts.
171 */
172 #define AOS_BUFSZ(nr) ((3 + ((nr / 2) * 3) + ((nr & 1) * 2)) * sizeof(int))
173 #define VERT_AOS_BUFSZ (5 * sizeof(int))
174 #define ELTS_BUFSZ(nr) (12 + nr * 2)
175 #define VBUF_BUFSZ (3 * sizeof(int))
176
177 /* Ensure that a minimum amount of space is available in the command buffer.
178 * This is used to ensure atomicity of state updates with the rendering requests
179 * that rely on them.
180 *
181 * An alternative would be to implement a "soft lock" such that when the buffer
182 * wraps at an inopportune time, we grab the lock, flush the current buffer,
183 * and hang on to the lock until the critical section is finished and we flush
184 * the buffer again and unlock.
185 */
186 static INLINE void r200EnsureCmdBufSpace( r200ContextPtr rmesa, int bytes )
187 {
188 if (rmesa->store.cmd_used + bytes > R200_CMD_BUF_SZ)
189 r200FlushCmdBuf( rmesa, __FUNCTION__ );
190 assert( bytes <= R200_CMD_BUF_SZ );
191 }
192
193 /* Alloc space in the command buffer
194 */
195 static INLINE char *r200AllocCmdBuf( r200ContextPtr rmesa,
196 int bytes, const char *where )
197 {
198 char * head;
199
200 if (rmesa->store.cmd_used + bytes > R200_CMD_BUF_SZ)
201 r200FlushCmdBuf( rmesa, where );
202
203 head = rmesa->store.cmd_buf + rmesa->store.cmd_used;
204 rmesa->store.cmd_used += bytes;
205 assert( rmesa->store.cmd_used <= R200_CMD_BUF_SZ );
206 return head;
207 }
208
209 #endif /* __R200_IOCTL_H__ */