1
/**************************************************************************
3
Copyright 2006 Stephane Marchesin
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:
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
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.
25
**************************************************************************/
29
#ifndef __NOUVEAU_FIFO_H__
30
#define __NOUVEAU_FIFO_H__
32
#include "nouveau_context.h"
33
#include "nouveau_ctrlreg.h"
34
#include "nouveau_state_cache.h"
36
//#define NOUVEAU_RING_TRACE
37
//#define NOUVEAU_RING_DEBUG
38
//#define NOUVEAU_STATE_CACHE_DISABLE
40
#ifndef NOUVEAU_RING_TRACE
41
#define NOUVEAU_RING_TRACE 0
43
#undef NOUVEAU_RING_TRACE
44
#define NOUVEAU_RING_TRACE 1
47
#define NV_READ(reg) *(volatile u_int32_t *)(nmesa->mmio + (reg))
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); \
58
NV_FIFO_WRITE(NV03_FIFO_REGS_DMAPUT, ((val)<<2) + nmesa->fifo.put_base); \
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
72
/* Enable for ring debugging. Prints out writes to the ring buffer
73
* but does not actually write to it.
75
#ifdef NOUVEAU_RING_DEBUG
77
extern int nouveau_fifo_remaining;
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; \
85
#define OUT_RING(n) do { \
86
printf("OUT_RINGn: 0x%08x (%s)\n", n, __func__); \
87
nouveau_fifo_remaining--; \
90
#define OUT_RINGf(n) do { \
91
printf("OUT_RINGf: %.04f (%s)\n", n, __func__); \
92
nouveau_fifo_remaining--; \
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; \
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))); \
113
memcpy(nmesa->fifo.buffer+nmesa->fifo.current,ptr,(sz)*4); \
114
nmesa->fifo.current+=(sz); \
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); \
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); \
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); \
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);
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))
149
#define BEGIN_RING_CACHE(subchannel,tag,size) do { \
150
nmesa->state_cache.dirty=1; \
151
nmesa->state_cache.current_pos=((tag)/4); \
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); \
160
nmesa->state_cache.current_pos++; \
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);\
169
nmesa->state_cache.current_pos++; \
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)); \
178
#define RING_AVAILABLE() (nmesa->fifo.free-1)
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)
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); \
189
extern void nouveauWaitForIdle(nouveauContextPtr nmesa);
190
extern void nouveauWaitForIdleLocked(nouveauContextPtr nmesa);
191
extern GLboolean nouveauFifoInit(nouveauContextPtr nmesa);
193
#endif /* __NOUVEAU_FIFO_H__ */