Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / unichrome / via_ioctl.h
1 /*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef _VIAIOCTL_H
26 #define _VIAIOCTL_H
27
28 #include "via_context.h"
29
30
31 void viaFinishPrimitive(struct via_context *vmesa);
32 void viaFlushDma(struct via_context *vmesa);
33 void viaFlushDmaLocked(struct via_context *vmesa, GLuint flags);
34
35 void viaInitIoctlFuncs(GLcontext *ctx);
36 void viaCopyBuffer(__DRIdrawable *dpriv);
37 void viaPageFlip(__DRIdrawable *dpriv);
38 void viaCheckDma(struct via_context *vmesa, GLuint bytes);
39 void viaResetPageFlippingLocked(struct via_context *vmesa);
40 void viaWaitIdle(struct via_context *vmesa, GLboolean light);
41 void viaWaitIdleLocked(struct via_context *vmesa, GLboolean light);
42
43 GLboolean viaCheckBreadcrumb( struct via_context *vmesa, GLuint value );
44 void viaEmitBreadcrumb( struct via_context *vmesa );
45
46
47 #define VIA_FINISH_PRIM(vmesa) do { \
48 if (vmesa->dmaLastPrim) \
49 viaFinishPrimitive( vmesa ); \
50 } while (0)
51
52 #define VIA_FLUSH_DMA(vmesa) do { \
53 VIA_FINISH_PRIM(vmesa); \
54 if (vmesa->dmaLow) \
55 viaFlushDma(vmesa); \
56 } while (0)
57
58
59 void viaWrapPrimitive( struct via_context *vmesa );
60
61 static INLINE GLuint *viaAllocDma(struct via_context *vmesa, int bytes)
62 {
63 if (vmesa->dmaLow + bytes > VIA_DMA_HIGHWATER) {
64 viaFlushDma(vmesa);
65 }
66
67 {
68 GLuint *start = (GLuint *)(vmesa->dma + vmesa->dmaLow);
69 vmesa->dmaLow += bytes;
70 return start;
71 }
72 }
73
74
75 static GLuint INLINE *viaExtendPrimitive(struct via_context *vmesa, int bytes)
76 {
77 if (vmesa->dmaLow + bytes > VIA_DMA_HIGHWATER) {
78 viaWrapPrimitive(vmesa);
79 }
80
81 {
82 GLuint *start = (GLuint *)(vmesa->dma + vmesa->dmaLow);
83 vmesa->dmaLow += bytes;
84 return start;
85 }
86 }
87
88
89
90
91 #define RING_VARS GLuint *_vb = 0, _nr, _x;
92
93 #define BEGIN_RING(n) do { \
94 if (_vb != 0) abort(); \
95 _vb = viaAllocDma(vmesa, (n) * sizeof(GLuint)); \
96 _nr = (n); \
97 _x = 0; \
98 } while (0)
99
100 #define BEGIN_RING_NOCHECK(n) do { \
101 if (_vb != 0) abort(); \
102 _vb = (GLuint *)(vmesa->dma + vmesa->dmaLow); \
103 vmesa->dmaLow += (n) * sizeof(GLuint); \
104 _nr = (n); \
105 _x = 0; \
106 } while (0)
107
108 #define OUT_RING(n) _vb[_x++] = (n)
109
110 #define ADVANCE_RING() do { \
111 if (_x != _nr) abort(); \
112 _vb = 0; \
113 } while (0)
114
115 #define ADVANCE_RING_VARIABLE() do { \
116 if (_x > _nr) abort(); \
117 vmesa->dmaLow -= (_nr - _x) * sizeof(GLuint); \
118 _vb = 0; \
119 } while (0)
120
121
122 #define QWORD_PAD_RING() do { \
123 if (vmesa->dmaLow & 0x4) { \
124 BEGIN_RING(1); \
125 OUT_RING(HC_DUMMY); \
126 ADVANCE_RING(); \
127 } \
128 } while (0)
129
130 #define VIA_GEQ_WRAP(left, right) \
131 (((left) - (right)) < ( 1 << 23))
132
133 #endif