mesa: remove _mesa_create_context_for_api()
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_ioctl.h
1 /* -*- 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 <stdio.h>
36 #include <stdlib.h>
37
38 #include "mach64_dri.h"
39 #include "mach64_reg.h"
40 #include "mach64_lock.h"
41
42 #define MACH64_BUFFER_MAX_DWORDS (MACH64_BUFFER_SIZE / sizeof(CARD32))
43
44
45 extern drmBufPtr mach64GetBufferLocked( mach64ContextPtr mmesa );
46 extern void mach64FlushVerticesLocked( mach64ContextPtr mmesa );
47 extern void mach64FlushDMALocked( mach64ContextPtr mmesa );
48 extern void mach64UploadHwStateLocked( mach64ContextPtr mmesa );
49
50 static INLINE void *mach64AllocDmaLow( mach64ContextPtr mmesa, int bytes )
51 {
52 CARD32 *head;
53
54 if ( mmesa->vert_used + bytes > mmesa->vert_total ) {
55 LOCK_HARDWARE( mmesa );
56 mach64FlushVerticesLocked( mmesa );
57 UNLOCK_HARDWARE( mmesa );
58 }
59
60 head = (CARD32 *)((char *)mmesa->vert_buf + mmesa->vert_used);
61 mmesa->vert_used += bytes;
62
63 return head;
64 }
65
66 static INLINE void *mach64AllocDmaLocked( mach64ContextPtr mmesa, int bytes )
67 {
68 CARD32 *head;
69
70 if ( mmesa->vert_used + bytes > mmesa->vert_total ) {
71 mach64FlushVerticesLocked( mmesa );
72 }
73
74 head = (CARD32 *)((char *)mmesa->vert_buf + mmesa->vert_used);
75 mmesa->vert_used += bytes;
76
77 return head;
78 }
79
80 extern void mach64FireBlitLocked( mach64ContextPtr mmesa, void *buffer,
81 GLint offset, GLint pitch, GLint format,
82 GLint x, GLint y, GLint width, GLint height );
83
84 extern void mach64CopyBuffer( __DRIdrawable *dPriv );
85 #if ENABLE_PERF_BOXES
86 extern void mach64PerformanceCounters( mach64ContextPtr mmesa );
87 extern void mach64PerformanceBoxesLocked( mach64ContextPtr mmesa );
88 #endif
89 extern void mach64WaitForIdleLocked( mach64ContextPtr mmesa );
90
91 extern void mach64InitIoctlFuncs( struct dd_function_table *functions );
92
93 /* ================================================================
94 * Helper macros:
95 */
96
97 #define FLUSH_BATCH( mmesa ) \
98 do { \
99 if ( MACH64_DEBUG & DEBUG_VERBOSE_IOCTL ) \
100 fprintf( stderr, "FLUSH_BATCH in %s\n", __FUNCTION__ ); \
101 if ( mmesa->vert_used ) { \
102 mach64FlushVertices( mmesa ); \
103 } \
104 } while (0)
105
106 /* According to a comment in ATIMach64Sync (atimach64.c) in the DDX:
107 *
108 * "For VTB's and later, the first CPU read of the framebuffer will return
109 * zeroes [...] This appears to be due to some kind of engine
110 * caching of framebuffer data I haven't found any way of disabling, or
111 * otherwise circumventing."
112 */
113 #define FINISH_DMA_LOCKED( mmesa ) \
114 do { \
115 CARD32 _tmp; \
116 if ( MACH64_DEBUG & DEBUG_VERBOSE_IOCTL ) \
117 fprintf( stderr, "FINISH_DMA_LOCKED in %s\n", __FUNCTION__ ); \
118 if ( mmesa->vert_used ) { \
119 mach64FlushVerticesLocked( mmesa ); \
120 } \
121 mach64WaitForIdleLocked( mmesa ); \
122 /* pre-read framebuffer to counter caching problem */ \
123 _tmp = *(volatile CARD32 *)mmesa->driScreen->pFB; \
124 } while (0)
125
126 #define FLUSH_DMA_LOCKED( mmesa ) \
127 do { \
128 if ( MACH64_DEBUG & DEBUG_VERBOSE_IOCTL ) \
129 fprintf( stderr, "FLUSH_DMA_LOCKED in %s\n", __FUNCTION__ ); \
130 if ( mmesa->vert_used ) { \
131 mach64FlushVerticesLocked( mmesa ); \
132 } \
133 mach64FlushDMALocked( mmesa ); \
134 } while (0)
135
136 #define mach64FlushVertices( mmesa ) \
137 do { \
138 LOCK_HARDWARE( mmesa ); \
139 mach64FlushVerticesLocked( mmesa ); \
140 UNLOCK_HARDWARE( mmesa ); \
141 } while (0)
142
143 #define mach64WaitForIdle( mmesa ) \
144 do { \
145 LOCK_HARDWARE( mmesa ); \
146 mach64WaitForIdleLocked( mmesa ); \
147 UNLOCK_HARDWARE( mmesa ); \
148 } while (0)
149
150
151 #endif /* __MACH64_IOCTL_H__ */