2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
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.
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:
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.
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.
28 **************************************************************************/
32 * Keith Whitwell <keith@tungstengraphics.com>
35 #ifndef __R200_IOCTL_H__
36 #define __R200_IOCTL_H__
38 #include "main/simple_list.h"
39 #include "radeon_dri.h"
40 #include "r200_lock.h"
44 #include "radeon_drm.h"
46 extern void r200EmitState( r200ContextPtr rmesa
);
47 extern void r200EmitVertexAOS( r200ContextPtr rmesa
,
52 extern void r200EmitVbufPrim( r200ContextPtr rmesa
,
56 extern void r200FlushElts(r200ContextPtr rmesa
);
59 extern GLushort
*r200AllocEltsOpenEnded( r200ContextPtr rmesa
,
63 extern void r200EmitAOS(r200ContextPtr rmesa
, GLuint nr
, GLuint offset
);
65 extern void r200EmitBlit( r200ContextPtr rmesa
,
71 GLint srcx
, GLint srcy
,
72 GLint dstx
, GLint dsty
,
75 extern void r200EmitWait( r200ContextPtr rmesa
, GLuint flags
);
77 //extern void r200FlushCmdBuf( r200ContextPtr rmesa, const char * );
78 //extern int r200FlushCmdBufLocked( r200ContextPtr rmesa, const char * caller );
80 extern void r200RefillCurrentDmaRegion( r200ContextPtr rmesa
);
82 extern void r200AllocDmaRegion( r200ContextPtr rmesa
,
83 struct radeon_dma_region
*region
,
87 extern void r200ReleaseDmaRegion( r200ContextPtr rmesa
,
88 struct radeon_dma_region
*region
,
91 extern void r200Flush( GLcontext
*ctx
);
92 extern void r200Finish( GLcontext
*ctx
);
93 extern void r200InitIoctlFuncs( struct dd_function_table
*functions
);
95 extern void *r200AllocateMemoryMESA( __DRIscreen
*screen
, GLsizei size
, GLfloat readfreq
,
96 GLfloat writefreq
, GLfloat priority
);
97 extern void r200FreeMemoryMESA( __DRIscreen
*screen
, GLvoid
*pointer
);
98 extern GLuint
r200GetMemoryOffsetMESA( __DRIscreen
*screen
, const GLvoid
*pointer
);
100 extern GLboolean
r200IsGartMemory( r200ContextPtr rmesa
, const GLvoid
*pointer
,
103 extern GLuint
r200GartOffsetFromVirtual( r200ContextPtr rmesa
,
104 const GLvoid
*pointer
);
106 void r200SetUpAtomList( r200ContextPtr rmesa
);
108 /* ================================================================
112 /* Close off the last primitive, if it exists.
114 #define R200_NEWPRIM( rmesa ) \
116 if ( rmesa->dma.flush ) \
117 rmesa->dma.flush( rmesa->radeon.glCtx ); \
120 /* Can accomodate several state changes and primitive changes without
121 * actually firing the buffer.
123 #define R200_STATECHANGE( rmesa, ATOM ) \
125 R200_NEWPRIM( rmesa ); \
126 rmesa->hw.ATOM.dirty = GL_TRUE; \
127 rmesa->hw.is_dirty = GL_TRUE; \
130 #define R200_DB_STATE( ATOM ) \
131 memcpy( rmesa->hw.ATOM.lastcmd, rmesa->hw.ATOM.cmd, \
132 rmesa->hw.ATOM.cmd_size * 4)
134 static INLINE
int R200_DB_STATECHANGE(
135 r200ContextPtr rmesa
,
136 struct radeon_state_atom
*atom
)
138 if (memcmp(atom
->cmd
, atom
->lastcmd
, atom
->cmd_size
*4)) {
140 R200_NEWPRIM( rmesa
);
141 atom
->dirty
= GL_TRUE
;
142 rmesa
->hw
.is_dirty
= GL_TRUE
;
144 atom
->cmd
= atom
->lastcmd
;
153 /* Fire the buffered vertices no matter what.
155 #define R200_FIREVERTICES( rmesa ) \
157 if ( rmesa->store.cmd_used || rmesa->dma.flush ) { \
158 r200Flush( rmesa->radeon.glCtx ); \
162 /* Command lengths. Note that any time you ensure ELTS_BUFSZ or VBUF_BUFSZ
163 * are available, you will also be adding an rmesa->state.max_state_size because
164 * r200EmitState is called from within r200EmitVbufPrim and r200FlushElts.
166 #define AOS_BUFSZ(nr) ((3 + ((nr / 2) * 3) + ((nr & 1) * 2)) * sizeof(int))
167 #define VERT_AOS_BUFSZ (5 * sizeof(int))
168 #define ELTS_BUFSZ(nr) (12 + nr * 2)
169 #define VBUF_BUFSZ (3 * sizeof(int))
171 /* Ensure that a minimum amount of space is available in the command buffer.
172 * This is used to ensure atomicity of state updates with the rendering requests
175 * An alternative would be to implement a "soft lock" such that when the buffer
176 * wraps at an inopportune time, we grab the lock, flush the current buffer,
177 * and hang on to the lock until the critical section is finished and we flush
178 * the buffer again and unlock.
181 static INLINE
void r200EnsureCmdBufSpace( r200ContextPtr rmesa
, int bytes
)
183 if (rmesa
->store
.cmd_used
+ bytes
> R200_CMD_BUF_SZ
)
184 rcommonFlushCmdBuf( rmesa
, __FUNCTION__
);
185 assert( bytes
<= R200_CMD_BUF_SZ
);
188 /* Alloc space in the command buffer
190 static INLINE
char *r200AllocCmdBuf( r200ContextPtr rmesa
,
191 int bytes
, const char *where
)
195 if (rmesa
->store
.cmd_used
+ bytes
> R200_CMD_BUF_SZ
)
196 r200FlushCmdBuf( rmesa
, where
);
198 head
= rmesa
->store
.cmd_buf
+ rmesa
->store
.cmd_used
;
199 rmesa
->store
.cmd_used
+= bytes
;
200 assert( rmesa
->store
.cmd_used
<= R200_CMD_BUF_SZ
);
205 static inline uint32_t cmdpacket3(int cmd_type
)
207 drm_radeon_cmd_header_t cmd
;
210 cmd
.header
.cmd_type
= cmd_type
;
212 return (uint32_t)cmd
.i
;
216 #define OUT_BATCH_PACKET3(packet, num_extra) do { \
217 if (!b_l_rmesa->radeonScreen->kernel_mm) { \
218 OUT_BATCH(cmdpacket3(RADEON_CMD_PACKET3)); \
219 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
221 OUT_BATCH(CP_PACKET2); \
222 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
226 #define OUT_BATCH_PACKET3_CLIP(packet, num_extra) do { \
227 if (!b_l_rmesa->radeonScreen->kernel_mm) { \
228 OUT_BATCH(cmdpacket3(RADEON_CMD_PACKET3_CLIP)); \
229 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
231 OUT_BATCH(CP_PACKET2); \
232 OUT_BATCH(CP_PACKET3((packet), (num_extra))); \
237 #endif /* __R200_IOCTL_H__ */