2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
28 #include "via_context.h"
31 void viaFinishPrimitive(struct via_context
*vmesa
);
32 void viaFlushDma(struct via_context
*vmesa
);
33 void viaFlushDmaLocked(struct via_context
*vmesa
, GLuint flags
);
35 void viaInitIoctlFuncs(GLcontext
*ctx
);
36 void viaCopyBuffer(__DRIdrawablePrivate
*dpriv
);
37 void viaPageFlip(__DRIdrawablePrivate
*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
);
43 GLboolean
viaCheckBreadcrumb( struct via_context
*vmesa
, GLuint value
);
44 void viaEmitBreadcrumb( struct via_context
*vmesa
);
47 #define VIA_FINISH_PRIM(vmesa) do { \
48 if (vmesa->dmaLastPrim) \
49 viaFinishPrimitive( vmesa ); \
52 #define VIA_FLUSH_DMA(vmesa) do { \
53 VIA_FINISH_PRIM(vmesa); \
59 void viaWrapPrimitive( struct via_context
*vmesa
);
61 static INLINE GLuint
*viaAllocDma(struct via_context
*vmesa
, int bytes
)
63 if (vmesa
->dmaLow
+ bytes
> VIA_DMA_HIGHWATER
) {
68 GLuint
*start
= (GLuint
*)(vmesa
->dma
+ vmesa
->dmaLow
);
69 vmesa
->dmaLow
+= bytes
;
75 static GLuint INLINE
*viaExtendPrimitive(struct via_context
*vmesa
, int bytes
)
77 if (vmesa
->dmaLow
+ bytes
> VIA_DMA_HIGHWATER
) {
78 viaWrapPrimitive(vmesa
);
82 GLuint
*start
= (GLuint
*)(vmesa
->dma
+ vmesa
->dmaLow
);
83 vmesa
->dmaLow
+= bytes
;
91 #define RING_VARS GLuint *_vb = 0, _nr, _x;
93 #define BEGIN_RING(n) do { \
94 if (_vb != 0) abort(); \
95 _vb = viaAllocDma(vmesa, (n) * sizeof(GLuint)); \
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); \
108 #define OUT_RING(n) _vb[_x++] = (n)
110 #define ADVANCE_RING() do { \
111 if (_x != _nr) abort(); \
115 #define ADVANCE_RING_VARIABLE() do { \
116 if (_x > _nr) abort(); \
117 vmesa->dmaLow -= (_nr - _x) * sizeof(GLuint); \
122 #define QWORD_PAD_RING() do { \
123 if (vmesa->dmaLow & 0x4) { \
125 OUT_RING(HC_DUMMY); \
130 #define VIA_GEQ_WRAP(left, right) \
131 (((left) - (right)) < ( 1 << 23))