52fe86348456f90e570644a9e651345159f48678
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_ioctl.h
1 /* $XFree86$ */ /* -*- mode: c; c-basic-offset: 3 -*- */
2 /*
3 * Copyright 2000 Gareth Hughes
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * GARETH HUGHES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * Authors:
27 * Gareth Hughes <gareth@valinux.com>
28 * Leif Delgass <ldelgass@retinalburn.net>
29 * José Fonseca <j_r_fonseca@yahoo.co.uk>
30 */
31
32 #ifndef __MACH64_IOCTL_H__
33 #define __MACH64_IOCTL_H__
34
35 #include "mach64_dri.h"
36 #include "mach64_reg.h"
37 #include "mach64_lock.h"
38
39 #define MACH64_BUFFER_MAX_DWORDS (MACH64_BUFFER_SIZE / sizeof(CARD32))
40
41
42 extern drmBufPtr mach64GetBufferLocked( mach64ContextPtr mmesa );
43 extern void mach64FlushVerticesLocked( mach64ContextPtr mmesa );
44 extern void mach64FlushDMALocked( mach64ContextPtr mmesa );
45 extern void mach64UploadHwStateLocked( mach64ContextPtr mmesa );
46
47 static __inline void *mach64AllocDmaLow( mach64ContextPtr mmesa, int bytes )
48 {
49 CARD32 *head;
50
51 if ( mmesa->vert_used + bytes > mmesa->vert_total ) {
52 LOCK_HARDWARE( mmesa );
53 mach64FlushVerticesLocked( mmesa );
54 UNLOCK_HARDWARE( mmesa );
55 }
56
57 head = (CARD32 *)((char *)mmesa->vert_buf + mmesa->vert_used);
58 mmesa->vert_used += bytes;
59
60 return head;
61 }
62
63 static __inline void *mach64AllocDmaLocked( mach64ContextPtr mmesa, int bytes )
64 {
65 CARD32 *head;
66
67 if ( mmesa->vert_used + bytes > mmesa->vert_total ) {
68 mach64FlushVerticesLocked( mmesa );
69 }
70
71 head = (CARD32 *)((char *)mmesa->vert_buf + mmesa->vert_used);
72 mmesa->vert_used += bytes;
73
74 return head;
75 }
76
77 extern void mach64FireBlitLocked( mach64ContextPtr mmesa, void *buffer,
78 GLint offset, GLint pitch, GLint format,
79 GLint x, GLint y, GLint width, GLint height );
80
81 extern void mach64CopyBuffer( const __DRIdrawablePrivate *dPriv );
82 #if ENABLE_PERF_BOXES
83 extern void mach64PerformanceCounters( mach64ContextPtr mmesa );
84 extern void mach64PerformanceBoxesLocked( mach64ContextPtr mmesa );
85 #endif
86 extern void mach64WaitForIdleLocked( mach64ContextPtr mmesa );
87
88 extern void mach64InitIoctlFuncs( struct dd_function_table *functions );
89
90 /* ================================================================
91 * Helper macros:
92 */
93
94 #define FLUSH_BATCH( mmesa ) \
95 do { \
96 if ( MACH64_DEBUG & DEBUG_VERBOSE_IOCTL ) \
97 fprintf( stderr, "FLUSH_BATCH in %s\n", __FUNCTION__ ); \
98 if ( mmesa->vert_used ) { \
99 mach64FlushVertices( mmesa ); \
100 } \
101 } while (0)
102
103 /* According to a comment in ATIMach64Sync (atimach64.c) in the DDX:
104 *
105 * "For VTB's and later, the first CPU read of the framebuffer will return
106 * zeroes [...] This appears to be due to some kind of engine
107 * caching of framebuffer data I haven't found any way of disabling, or
108 * otherwise circumventing."
109 */
110 #define FINISH_DMA_LOCKED( mmesa ) \
111 do { \
112 CARD32 _tmp; \
113 if ( MACH64_DEBUG & DEBUG_VERBOSE_IOCTL ) \
114 fprintf( stderr, "FINISH_DMA_LOCKED in %s\n", __FUNCTION__ ); \
115 if ( mmesa->vert_used ) { \
116 mach64FlushVerticesLocked( mmesa ); \
117 } \
118 mach64WaitForIdleLocked( mmesa ); \
119 /* pre-read framebuffer to counter caching problem */ \
120 _tmp = *(volatile CARD32 *)mmesa->driScreen->pFB; \
121 } while (0)
122
123 #define FLUSH_DMA_LOCKED( mmesa ) \
124 do { \
125 if ( MACH64_DEBUG & DEBUG_VERBOSE_IOCTL ) \
126 fprintf( stderr, "FLUSH_DMA_LOCKED in %s\n", __FUNCTION__ ); \
127 if ( mmesa->vert_used ) { \
128 mach64FlushVerticesLocked( mmesa ); \
129 } \
130 mach64FlushDMALocked( mmesa ); \
131 } while (0)
132
133 #define mach64FlushVertices( mmesa ) \
134 do { \
135 LOCK_HARDWARE( mmesa ); \
136 mach64FlushVerticesLocked( mmesa ); \
137 UNLOCK_HARDWARE( mmesa ); \
138 } while (0)
139
140 #define mach64WaitForIdle( mmesa ) \
141 do { \
142 LOCK_HARDWARE( mmesa ); \
143 mach64WaitForIdleLocked( mmesa ); \
144 UNLOCK_HARDWARE( mmesa ); \
145 } while (0)
146
147
148 #endif /* __MACH64_IOCTL_H__ */