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