~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/kdrive/ati/ati_dma.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
Import upstream version 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright � 2004 Eric Anholt
 
3
 *
 
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.
 
13
 *
 
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.
 
21
 */
 
22
/* $Header: /cvs/xorg/xserver/xorg/hw/kdrive/ati/ati_dma.h,v 1.6 2005/12/27 08:25:55 ajax Exp $ */
 
23
 
 
24
#ifndef _ATI_DMA_H_
 
25
#define _ATI_DMA_H_
 
26
 
 
27
#define CCE_DEBUG 1
 
28
 
 
29
#if !CCE_DEBUG
 
30
#define DMA_PACKET0(reg, count)                                         \
 
31
        (ATI_CCE_PACKET0 | (((count) - 1) << 16) | ((reg) >> 2))
 
32
#else
 
33
#define DMA_PACKET0(reg, count)                                         \
 
34
        (__packet0count = (count), __reg = (reg),                       \
 
35
        ATI_CCE_PACKET0 | (((count) - 1) << 16) | ((reg) >> 2))
 
36
#endif
 
37
#define DMA_PACKET1(reg1, reg2)                                         \
 
38
        (ATI_CCE_PACKET1 |                                              \
 
39
        (((reg2) >> 2) << ATI_CCE_PACKET1_REG_2_SHIFT) |  ((reg1) >> 2))
 
40
#define DMA_PACKET3(type, count)                                        \
 
41
        ((type) | (((count) - 1) << 16))
 
42
 
 
43
#if !CCE_DEBUG
 
44
 
 
45
#define RING_LOCALS     CARD32 *__head; int __count
 
46
#define BEGIN_DMA(n)                                                    \
 
47
do {                                                                    \
 
48
        if ((atis->indirectBuffer->used + 4*(n)) >                      \
 
49
            atis->indirectBuffer->size) {                               \
 
50
                ATIFlushIndirect(atis, 1);                              \
 
51
        }                                                               \
 
52
        __head = (CARD32 *)((char *)atis->indirectBuffer->address +     \
 
53
            atis->indirectBuffer->used);                                \
 
54
        __count = 0;                                                    \
 
55
} while (0)
 
56
#define END_DMA() do {                                                  \
 
57
        atis->indirectBuffer->used += __count * 4;                      \
 
58
} while (0)
 
59
 
 
60
#else
 
61
 
 
62
#define RING_LOCALS     \
 
63
        CARD32 *__head; int __count, __total, __reg, __packet0count
 
64
#define BEGIN_DMA(n)                                                    \
 
65
do {                                                                    \
 
66
        if ((atis->indirectBuffer->used + 4*(n)) >                      \
 
67
            atis->indirectBuffer->size) {                               \
 
68
                ATIFlushIndirect(atis, 1);                              \
 
69
        }                                                               \
 
70
        __head = (CARD32 *)((char *)atis->indirectBuffer->address +     \
 
71
            atis->indirectBuffer->used);                                \
 
72
        __count = 0;                                                    \
 
73
        __total = n;                                                    \
 
74
        __reg = 0;                                                              \
 
75
        __packet0count = 0;                                                             \
 
76
} while (0)
 
77
#define END_DMA() do {                                                  \
 
78
        if (__count != __total)                                         \
 
79
                FatalError("count != total (%d vs %d) at %s:%d\n",       \
 
80
                     __count, __total, __FILE__, __LINE__);             \
 
81
        atis->indirectBuffer->used += __count * 4;                      \
 
82
} while (0)
 
83
 
 
84
#endif
 
85
 
 
86
#define OUT_RING(val) do {                                              \
 
87
        __head[__count++] = (val);                                      \
 
88
} while (0)
 
89
 
 
90
#define OUT_RING_REG(reg, val) do {                                     \
 
91
        if (__reg != reg)                                               \
 
92
                FatalError("unexpected reg (0x%x vs 0x%x) at %s:%d\n",  \
 
93
                    reg, __reg, __FILE__, __LINE__);                    \
 
94
        if (__packet0count-- <= 0)                                      \
 
95
                FatalError("overrun of packet0 at %s:%d\n",             \
 
96
                    __FILE__, __LINE__);                                \
 
97
        __head[__count++] = (val);                                      \
 
98
        __reg += 4;                                                     \
 
99
} while (0)
 
100
 
 
101
#define OUT_RING_F(x) OUT_RING(GET_FLOAT_BITS(x))
 
102
 
 
103
#define OUT_REG(reg, val)                                               \
 
104
do {                                                                    \
 
105
        OUT_RING(DMA_PACKET0(reg, 1));                                  \
 
106
        OUT_RING(val);                                                  \
 
107
} while (0)
 
108
 
 
109
#define TIMEOUT_LOCALS struct timeval _target, _curtime
 
110
 
 
111
static inline Bool
 
112
tv_le(struct timeval *tv1, struct timeval *tv2)
 
113
{
 
114
        if (tv1->tv_sec < tv2->tv_sec ||
 
115
            (tv1->tv_sec == tv2->tv_sec && tv1->tv_usec < tv2->tv_usec))
 
116
                return TRUE;
 
117
        else
 
118
                return FALSE;
 
119
}
 
120
 
 
121
#define WHILE_NOT_TIMEOUT(_timeout)                                     \
 
122
        gettimeofday(&_target, NULL);                                   \
 
123
        _target.tv_usec += ((_timeout) * 1000000);                      \
 
124
        _target.tv_sec += _target.tv_usec / 1000000;                    \
 
125
        _target.tv_usec = _target.tv_usec % 1000000;                    \
 
126
        while (gettimeofday(&_curtime, NULL), tv_le(&_curtime, &_target))
 
127
 
 
128
#define TIMEDOUT()      (!tv_le(&_curtime, &_target))
 
129
 
 
130
dmaBuf *
 
131
ATIGetDMABuffer(ATIScreenInfo *atis);
 
132
 
 
133
void
 
134
ATIFlushIndirect(ATIScreenInfo *atis, Bool discard);
 
135
 
 
136
void
 
137
ATIDMASetup(ScreenPtr pScreen);
 
138
 
 
139
void
 
140
ATIDMATeardown(ScreenPtr pScreen);
 
141
 
 
142
#endif /* _ATI_DMA_H_ */