First import
[xorg_rtime.git] / xorg-server-1.4 / hw / kdrive / ati / ati_dma.h
blob4c2092b2c6a6f7038ca0a8fceb80735478134a19
1 /*
2 * Copyright © 2004 Eric Anholt
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Eric Anholt not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Eric Anholt makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * ERIC ANHOLT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL ERIC ANHOLT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifndef _ATI_DMA_H_
24 #define _ATI_DMA_H_
26 #define CCE_DEBUG 1
28 #if !CCE_DEBUG
29 #define DMA_PACKET0(reg, count) \
30 (ATI_CCE_PACKET0 | (((count) - 1) << 16) | ((reg) >> 2))
31 #else
32 #define DMA_PACKET0(reg, count) \
33 (__packet0count = (count), __reg = (reg), \
34 ATI_CCE_PACKET0 | (((count) - 1) << 16) | ((reg) >> 2))
35 #endif
36 #define DMA_PACKET1(reg1, reg2) \
37 (ATI_CCE_PACKET1 | \
38 (((reg2) >> 2) << ATI_CCE_PACKET1_REG_2_SHIFT) | ((reg1) >> 2))
39 #define DMA_PACKET3(type, count) \
40 ((type) | (((count) - 1) << 16))
42 #if !CCE_DEBUG
44 #define RING_LOCALS CARD32 *__head; int __count
45 #define BEGIN_DMA(n) \
46 do { \
47 if ((atis->indirectBuffer->used + 4*(n)) > \
48 atis->indirectBuffer->size) { \
49 ATIFlushIndirect(atis, 1); \
50 } \
51 __head = (CARD32 *)((char *)atis->indirectBuffer->address + \
52 atis->indirectBuffer->used); \
53 __count = 0; \
54 } while (0)
55 #define END_DMA() do { \
56 atis->indirectBuffer->used += __count * 4; \
57 } while (0)
59 #else
61 #define RING_LOCALS \
62 CARD32 *__head; int __count, __total, __reg, __packet0count
63 #define BEGIN_DMA(n) \
64 do { \
65 if ((atis->indirectBuffer->used + 4*(n)) > \
66 atis->indirectBuffer->size) { \
67 ATIFlushIndirect(atis, 1); \
68 } \
69 __head = (CARD32 *)((char *)atis->indirectBuffer->address + \
70 atis->indirectBuffer->used); \
71 __count = 0; \
72 __total = n; \
73 __reg = 0; \
74 __packet0count = 0; \
75 } while (0)
76 #define END_DMA() do { \
77 if (__count != __total) \
78 FatalError("count != total (%d vs %d) at %s:%d\n", \
79 __count, __total, __FILE__, __LINE__); \
80 atis->indirectBuffer->used += __count * 4; \
81 } while (0)
83 #endif
85 #define OUT_RING(val) do { \
86 __head[__count++] = (val); \
87 } while (0)
89 #define OUT_RING_REG(reg, val) do { \
90 if (__reg != reg) \
91 FatalError("unexpected reg (0x%x vs 0x%x) at %s:%d\n", \
92 reg, __reg, __FILE__, __LINE__); \
93 if (__packet0count-- <= 0) \
94 FatalError("overrun of packet0 at %s:%d\n", \
95 __FILE__, __LINE__); \
96 __head[__count++] = (val); \
97 __reg += 4; \
98 } while (0)
100 #define OUT_RING_F(x) OUT_RING(GET_FLOAT_BITS(x))
102 #define OUT_REG(reg, val) \
103 do { \
104 OUT_RING(DMA_PACKET0(reg, 1)); \
105 OUT_RING(val); \
106 } while (0)
108 #define TIMEOUT_LOCALS struct timeval _target, _curtime
110 static inline Bool
111 tv_le(struct timeval *tv1, struct timeval *tv2)
113 if (tv1->tv_sec < tv2->tv_sec ||
114 (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec < tv2->tv_usec))
115 return TRUE;
116 else
117 return FALSE;
120 #define WHILE_NOT_TIMEOUT(_timeout) \
121 gettimeofday(&_target, NULL); \
122 _target.tv_usec += ((_timeout) * 1000000); \
123 _target.tv_sec += _target.tv_usec / 1000000; \
124 _target.tv_usec = _target.tv_usec % 1000000; \
125 while (gettimeofday(&_curtime, NULL), tv_le(&_curtime, &_target))
127 #define TIMEDOUT() (!tv_le(&_curtime, &_target))
129 dmaBuf *
130 ATIGetDMABuffer(ATIScreenInfo *atis);
132 void
133 ATIFlushIndirect(ATIScreenInfo *atis, Bool discard);
135 void
136 ATIDMASetup(ScreenPtr pScreen);
138 void
139 ATIDMATeardown(ScreenPtr pScreen);
141 #endif /* _ATI_DMA_H_ */