make alloc-dma functions inline, rearrange some debug
[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(viaContextPtr vmesa);
32 void viaFlushDma(viaContextPtr vmesa);
33 void viaFlushDmaLocked(viaContextPtr vmesa, GLuint flags);
34
35 void viaInitIoctlFuncs(GLcontext *ctx);
36 void viaCopyBuffer(const __DRIdrawablePrivate *dpriv);
37 void viaPageFlip(const __DRIdrawablePrivate *dpriv);
38 void viaCheckDma(viaContextPtr vmesa, GLuint bytes);
39
40 #define VIA_FINISH_PRIM(vmesa) do { \
41 if (vmesa->dmaLastPrim) \
42 viaFinishPrimitive( vmesa ); \
43 } while (0)
44
45 #define VIA_FLUSH_DMA(vmesa) do { \
46 VIA_FINISH_PRIM(vmesa); \
47 if (vmesa->dmaLow) \
48 viaFlushDma(vmesa); \
49 } while (0)
50
51
52 void viaWrapPrimitive( viaContextPtr vmesa );
53
54 static __inline__ GLuint *viaAllocDma(viaContextPtr vmesa, int bytes)
55 {
56 if (vmesa->dmaLow + bytes > VIA_DMA_HIGHWATER) {
57 viaFlushDma(vmesa);
58 }
59
60 {
61 GLuint *start = (GLuint *)(vmesa->dma + vmesa->dmaLow);
62 vmesa->dmaLow += bytes;
63 return start;
64 }
65 }
66
67
68 static GLuint __inline__ *viaExtendPrimitive(viaContextPtr vmesa, int bytes)
69 {
70 if (vmesa->dmaLow + bytes > VIA_DMA_HIGHWATER) {
71 viaWrapPrimitive(vmesa);
72 }
73
74 {
75 GLuint *start = (GLuint *)(vmesa->dma + vmesa->dmaLow);
76 vmesa->dmaLow += bytes;
77 return start;
78 }
79 }
80
81
82
83
84 #define RING_VARS GLuint *_vb = 0, _nr, _x;
85
86 #define BEGIN_RING(n) do { \
87 if (_vb != 0) abort(); \
88 _vb = viaAllocDma(vmesa, (n) * sizeof(GLuint)); \
89 _nr = (n); \
90 _x = 0; \
91 } while (0)
92
93 #define BEGIN_RING_NOCHECK(n) do { \
94 if (_vb != 0) abort(); \
95 _vb = (GLuint *)(vmesa->dma + vmesa->dmaLow); \
96 vmesa->dmaLow += (n) * sizeof(GLuint); \
97 _nr = (n); \
98 _x = 0; \
99 } while (0)
100
101 #define OUT_RING(n) _vb[_x++] = (n)
102
103 #define ADVANCE_RING() do { \
104 if (_x != _nr) abort(); \
105 _vb = 0; \
106 } while (0)
107
108 #define ADVANCE_RING_VARIABLE() do { \
109 if (_x > _nr) abort(); \
110 vmesa->dmaLow -= (_nr - _x) * sizeof(GLuint); \
111 _vb = 0; \
112 } while (0)
113
114
115 #define QWORD_PAD_RING() do { \
116 if (vmesa->dmaLow & 0x4) { \
117 BEGIN_RING(1); \
118 OUT_RING(HC_DUMMY); \
119 ADVANCE_RING(); \
120 } \
121 } while (0)
122
123
124
125
126 #endif