~ubuntu-branches/ubuntu/quantal/mesa-glw/quantal

« back to all changes in this revision

Viewing changes to src/mesa/drivers/dri/nouveau/nouveau_fifo.h

  • Committer: Bazaar Package Importer
  • Author(s): Morten Kjeldgaard
  • Date: 2008-05-06 16:19:15 UTC
  • Revision ID: james.westby@ubuntu.com-20080506161915-uynz7nftmfixu6bq
Tags: upstream-7.0.3
ImportĀ upstreamĀ versionĀ 7.0.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 
 
3
Copyright 2006 Stephane Marchesin
 
4
All Rights Reserved.
 
5
 
 
6
Permission is hereby granted, free of charge, to any person obtaining a
 
7
copy of this software and associated documentation files (the "Software"),
 
8
to deal in the Software without restriction, including without limitation
 
9
on the rights to use, copy, modify, merge, publish, distribute, sub
 
10
license, and/or sell copies of the Software, and to permit persons to whom
 
11
the Software is furnished to do so, subject to the following conditions:
 
12
 
 
13
The above copyright notice and this permission notice (including the next
 
14
paragraph) shall be included in all copies or substantial portions of the
 
15
Software.
 
16
 
 
17
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
18
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
19
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 
20
ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
 
21
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
22
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 
23
USE OR OTHER DEALINGS IN THE SOFTWARE.
 
24
 
 
25
**************************************************************************/
 
26
 
 
27
 
 
28
 
 
29
#ifndef __NOUVEAU_FIFO_H__
 
30
#define __NOUVEAU_FIFO_H__
 
31
 
 
32
#include "nouveau_context.h"
 
33
#include "nouveau_ctrlreg.h"
 
34
#include "nouveau_state_cache.h"
 
35
 
 
36
//#define NOUVEAU_RING_TRACE
 
37
//#define NOUVEAU_RING_DEBUG
 
38
//#define NOUVEAU_STATE_CACHE_DISABLE
 
39
 
 
40
#ifndef NOUVEAU_RING_TRACE
 
41
#define NOUVEAU_RING_TRACE 0
 
42
#else
 
43
#undef NOUVEAU_RING_TRACE
 
44
#define NOUVEAU_RING_TRACE 1
 
45
#endif
 
46
 
 
47
#define NV_READ(reg) *(volatile u_int32_t *)(nmesa->mmio + (reg))
 
48
 
 
49
#define NV_FIFO_READ(reg) *(volatile u_int32_t *)(nmesa->fifo.mmio + (reg/4))
 
50
#define NV_FIFO_WRITE(reg,value) *(volatile u_int32_t *)(nmesa->fifo.mmio + (reg/4)) = value;
 
51
#define NV_FIFO_READ_GET() ((NV_FIFO_READ(NV03_FIFO_REGS_DMAGET) - nmesa->fifo.put_base) >> 2)
 
52
#define NV_FIFO_WRITE_PUT(val) do { \
 
53
        if (NOUVEAU_RING_TRACE) {\
 
54
                printf("FIRE_RING : 0x%08x\n", nmesa->fifo.current << 2); \
 
55
                fflush(stdout); \
 
56
                sleep(1); \
 
57
        } \
 
58
        NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT, ((val)<<2) + nmesa->fifo.put_base); \
 
59
} while(0)
 
60
 
 
61
/* 
 
62
 * Ring/fifo interface
 
63
 *
 
64
 * - Begin a ring section with BEGIN_RING_SIZE (if you know the full size in advance)
 
65
 * - Output stuff to the ring with either OUT_RINGp (outputs a raw mem chunk), OUT_RING (1 uint32_t) or OUT_RINGf (1 float)
 
66
 * - RING_AVAILABLE returns the available fifo (in uint32_ts)
 
67
 * - RING_AHEAD returns how much ahead of the last submission point we are
 
68
 * - FIRE_RING fires whatever we have that wasn't fired before
 
69
 * - WAIT_RING waits for size (in uint32_ts) to be available in the fifo
 
70
 */
 
71
 
 
72
/* Enable for ring debugging.  Prints out writes to the ring buffer
 
73
 * but does not actually write to it.
 
74
 */
 
75
#ifdef NOUVEAU_RING_DEBUG
 
76
 
 
77
extern int nouveau_fifo_remaining;
 
78
 
 
79
#define OUT_RINGp(ptr,sz) do {                                                  \
 
80
uint32_t* p=(uint32_t*)(ptr);                                                   \
 
81
int i; printf("OUT_RINGp: (size 0x%x dwords)\n",sz); for(i=0;i<sz;i++) printf(" 0x%08x   %f\n", *(p+i), *((float*)(p+i)));      \
 
82
nouveau_fifo_remaining-=sz;                                                     \
 
83
}while(0)
 
84
 
 
85
#define OUT_RING(n) do {                                                        \
 
86
    printf("OUT_RINGn: 0x%08x (%s)\n", n, __func__);                            \
 
87
    nouveau_fifo_remaining--;                                                   \
 
88
}while(0)
 
89
 
 
90
#define OUT_RINGf(n) do {                                                       \
 
91
    printf("OUT_RINGf: %.04f (%s)\n", n, __func__);                             \
 
92
    nouveau_fifo_remaining--;                                                   \
 
93
}while(0)
 
94
 
 
95
#define BEGIN_RING_SIZE(subchannel,tag,size) do {                                       \
 
96
        if (nouveau_fifo_remaining!=0)                                                  \
 
97
                printf("RING ERROR : remaining %d\n",nouveau_fifo_remaining);           \
 
98
        nouveau_state_cache_flush(nmesa);                                               \
 
99
        if (nmesa->fifo.free <= (size))                                                 \
 
100
                WAIT_RING(nmesa,(size));                                                \
 
101
        OUT_RING( ((size)<<18) | ((subchannel) << 13) | (tag));                         \
 
102
        nmesa->fifo.free -= ((size) + 1);                                               \
 
103
        nouveau_fifo_remaining=size;                                                    \
 
104
}while(0)
 
105
 
 
106
#else
 
107
 
 
108
#define OUT_RINGp(ptr,sz) do{                                                   \
 
109
        if (NOUVEAU_RING_TRACE) { \
 
110
                uint32_t* p=(uint32_t*)(ptr);                                                   \
 
111
                int i; printf("OUT_RINGp: (size 0x%x dwords) (%s)\n",sz, __func__); for(i=0;i<sz;i++) printf(" [0x%08x] 0x%08x   %f\n", (nmesa->fifo.current+i) << 2, *(p+i), *((float*)(p+i)));        \
 
112
        } \
 
113
        memcpy(nmesa->fifo.buffer+nmesa->fifo.current,ptr,(sz)*4);              \
 
114
        nmesa->fifo.current+=(sz);                                              \
 
115
}while(0)
 
116
 
 
117
#define OUT_RING(n) do {                                                        \
 
118
if (NOUVEAU_RING_TRACE) \
 
119
    printf("OUT_RINGn: [0x%08x] 0x%08x (%s)\n", nmesa->fifo.current << 2, n, __func__);        \
 
120
nmesa->fifo.buffer[nmesa->fifo.current++]=(n);                                  \
 
121
}while(0)
 
122
 
 
123
#define OUT_RINGf(n) do {                                                       \
 
124
if (NOUVEAU_RING_TRACE) \
 
125
    printf("OUT_RINGf: [0x%08x] %.04f (%s)\n", nmesa->fifo.current << 2, n, __func__);        \
 
126
*((float*)(nmesa->fifo.buffer+nmesa->fifo.current++))=(n);                      \
 
127
}while(0)
 
128
 
 
129
#define BEGIN_RING_SIZE(subchannel,tag,size) do {                                       \
 
130
        nouveau_state_cache_flush(nmesa);                                               \
 
131
        if (nmesa->fifo.free <= (size))                                                 \
 
132
                WAIT_RING(nmesa,(size));                                                \
 
133
        OUT_RING( ((size)<<18) | ((subchannel) << 13) | (tag));                         \
 
134
        nmesa->fifo.free -= ((size) + 1);                                               \
 
135
}while(0)
 
136
 
 
137
#endif
 
138
 
 
139
extern void WAIT_RING(nouveauContextPtr nmesa,u_int32_t size);
 
140
extern void nouveau_state_cache_flush(nouveauContextPtr nmesa);
 
141
extern void nouveau_state_cache_init(nouveauContextPtr nmesa);
 
142
 
 
143
#ifdef NOUVEAU_STATE_CACHE_DISABLE
 
144
#define BEGIN_RING_CACHE(subc,tag,size) BEGIN_RING_SIZE((subc), (tag), (size))
 
145
#define OUT_RING_CACHE(n) OUT_RING((n))
 
146
#define OUT_RING_CACHEf(n) OUT_RINGf((n))
 
147
#define OUT_RING_CACHEp(ptr, sz) OUT_RINGp((ptr), (sz))
 
148
#else
 
149
#define BEGIN_RING_CACHE(subchannel,tag,size) do {                                      \
 
150
        nmesa->state_cache.dirty=1;                                                     \
 
151
        nmesa->state_cache.current_pos=((tag)/4);                                       \
 
152
}while(0)
 
153
 
 
154
#define OUT_RING_CACHE(n) do {                                                                  \
 
155
        if (nmesa->state_cache.atoms[nmesa->state_cache.current_pos].value!=(n))        {       \
 
156
                nmesa->state_cache.atoms[nmesa->state_cache.current_pos].dirty=1;               \
 
157
                nmesa->state_cache.hdirty[nmesa->state_cache.current_pos/NOUVEAU_STATE_CACHE_HIER_SIZE]=1;              \
 
158
                nmesa->state_cache.atoms[nmesa->state_cache.current_pos].value=(n);             \
 
159
        }                                                                                       \
 
160
        nmesa->state_cache.current_pos++;                                                       \
 
161
}while(0)
 
162
 
 
163
#define OUT_RING_CACHEf(n) do {                                                                 \
 
164
        if ((*(float*)(&nmesa->state_cache.atoms[nmesa->state_cache.current_pos].value))!=(n)){ \
 
165
                nmesa->state_cache.atoms[nmesa->state_cache.current_pos].dirty=1;               \
 
166
                nmesa->state_cache.hdirty[nmesa->state_cache.current_pos/NOUVEAU_STATE_CACHE_HIER_SIZE]=1;              \
 
167
                (*(float*)(&nmesa->state_cache.atoms[nmesa->state_cache.current_pos].value))=(n);\
 
168
        }                                                                                       \
 
169
        nmesa->state_cache.current_pos++;                                                       \
 
170
}while(0)
 
171
 
 
172
#define OUT_RING_CACHEp(ptr,sz) do {                                                    \
 
173
uint32_t* p=(uint32_t*)(ptr);                                                           \
 
174
int i; for(i=0;i<sz;i++) OUT_RING_CACHE(*(p+i));                                        \
 
175
}while(0)
 
176
#endif
 
177
 
 
178
#define RING_AVAILABLE() (nmesa->fifo.free-1)
 
179
 
 
180
#define RING_AHEAD() ((nmesa->fifo.put<=nmesa->fifo.current)?(nmesa->fifo.current-nmesa->fifo.put):nmesa->fifo.max-nmesa->fifo.put+nmesa->fifo.current)
 
181
 
 
182
#define FIRE_RING() do {                             \
 
183
        if (nmesa->fifo.current!=nmesa->fifo.put) {  \
 
184
                nmesa->fifo.put=nmesa->fifo.current; \
 
185
                NV_FIFO_WRITE_PUT(nmesa->fifo.put);  \
 
186
        }                                            \
 
187
}while(0)
 
188
 
 
189
extern void nouveauWaitForIdle(nouveauContextPtr nmesa);
 
190
extern void nouveauWaitForIdleLocked(nouveauContextPtr nmesa);
 
191
extern GLboolean nouveauFifoInit(nouveauContextPtr nmesa);
 
192
 
 
193
#endif /* __NOUVEAU_FIFO_H__ */
 
194
 
 
195