remove use of implicit variables from pushbuf macros
[nouveau] / src / nouveau_local.h
1 /*
2  * Copyright 2007 Nouveau Project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22
23 #ifndef __NOUVEAU_LOCAL_H__
24 #define __NOUVEAU_LOCAL_H__
25
26 #include "compiler.h"
27 #include "xf86_OSproc.h"
28
29 #define NOUVEAU_PRIVATE _X_HIDDEN
30 #define NOUVEAU_PUBLIC _X_EXPORT
31
32 #if EXA_VERSION_MINOR >= 4
33 #define NOUVEAU_EXA_PIXMAPS 0
34 struct nouveau_pixmap {
35         struct nouveau_bo *bo;
36         int mapped;
37 };
38 #endif
39
40 /* Debug output */
41 #define NOUVEAU_MSG(fmt,args...) ErrorF(fmt, ##args)
42 #define NOUVEAU_ERR(fmt,args...) \
43         ErrorF("%s:%d - "fmt, __func__, __LINE__, ##args)
44 #if 0
45 #define NOUVEAU_FALLBACK(fmt,args...) do {    \
46         NOUVEAU_ERR("FALLBACK: "fmt, ##args); \
47         return FALSE;                         \
48 } while(0)
49 #else
50 #define NOUVEAU_FALLBACK(fmt,args...) do {    \
51         return FALSE;                         \
52 } while(0)
53 #endif
54
55 #define NOUVEAU_TIME_MSEC() GetTimeInMillis()
56
57 #define NOUVEAU_ALIGN(x,bytes) (((x) + ((bytes) - 1)) & ~((bytes) - 1))
58
59 /* User FIFO control */
60 //#define NOUVEAU_DMA_TRACE
61 //#define NOUVEAU_DMA_DEBUG
62 #define NOUVEAU_DMA_SUBCHAN_LRU
63 #define NOUVEAU_DMA_BARRIER mem_barrier();
64 #define NOUVEAU_DMA_TIMEOUT 2000
65
66 /* Push buffer access macros */
67 #define BEGIN_RING(chan,obj,mthd,size) do {                                    \
68         BEGIN_RING_CH((chan), (obj), (mthd), (size));                          \
69 } while(0)
70
71 #define OUT_RING(chan,data) do {                                               \
72         OUT_RING_CH((chan), (data));                                           \
73 } while(0)
74
75 #define OUT_RINGp(chan,src,size) do {                                          \
76         OUT_RINGp_CH((chan), (src), (size));                                   \
77 } while(0)
78
79 #define OUT_RINGf(chan,data) do {                                              \
80         union { float v; uint32_t u; } c;                                      \
81         c.v = (data);                                                          \
82         OUT_RING((chan), c.u);                                                 \
83 } while(0)
84
85 #define WAIT_RING(chan,size) do {                                              \
86         WAIT_RING_CH((chan), (size));                                          \
87 } while(0)
88
89 #define FIRE_RING(chan) do {                                                   \
90         FIRE_RING_CH((chan));                                               \
91 } while(0)
92
93 #define OUT_RELOC(chan,bo,data,flags,vor,tor) do {                             \
94         struct nouveau_channel_priv *nvchan = nouveau_channel(chan);           \
95         nouveau_bo_emit_reloc((chan), &nvchan->pushbuf[nvchan->dma.cur],       \
96                               (bo), (data), (flags), (vor), (tor));            \
97         OUT_RING((chan), 0);                                                   \
98 } while(0)
99
100 /* Raw data + flags depending on FB/TT buffer */
101 #define OUT_RELOCd(chan,bo,data,flags,vor,tor) do {                            \
102         OUT_RELOC((chan), (bo), (data), (flags) | NOUVEAU_BO_OR, (vor), (tor));\
103 } while(0)
104
105 /* FB/TT object handle */
106 #define OUT_RELOCo(chan,bo,flags) do {                                         \
107         OUT_RELOC((chan), (bo), 0, (flags) | NOUVEAU_BO_OR,                    \
108                   (chan)->vram->handle, (chan)->gart->handle);                 \
109 } while(0)
110
111 /* Low 32-bits of offset */
112 #define OUT_RELOCl(chan,bo,delta,flags) do {                                   \
113         OUT_RELOC((chan), (bo), (delta), (flags) | NOUVEAU_BO_LOW, 0, 0);      \
114 } while(0)
115
116 /* High 32-bits of offset */
117 #define OUT_RELOCh(chan,bo,delta,flags) do {                                   \
118         OUT_RELOC((chan), (bo), (delta), (flags) | NOUVEAU_BO_HIGH, 0, 0);     \
119 } while(0)
120
121
122 /* Alternate versions of OUT_RELOCx above, takes pixmaps instead of BOs */
123 #if NOUVEAU_EXA_PIXMAPS
124 #define OUT_PIXMAPd(chan,pm,data,flags,vor,tor) do {                           \
125         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
126         struct nouveau_bo *pmo = nvpix->bo;                                    \
127         OUT_RELOCd((chan), pmo, (data), (flags), (vor), (tor));                \
128 } while(0)
129 #define OUT_PIXMAPo(chan,pm,flags) do {                                        \
130         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
131         struct nouveau_bo *pmo = nvpix->bo;                                    \
132         OUT_RELOCo((chan), pmo, (flags));                                      \
133 } while(0)
134 #define OUT_PIXMAPl(chan,pm,delta,flags) do {                                  \
135         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
136         struct nouveau_bo *pmo = nvpix->bo;                                    \
137         OUT_RELOCl((chan), pmo, (delta), (flags));                             \
138 } while(0)
139 #define OUT_PIXMAPh(chan,pm,delta,flags) do {                                  \
140         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
141         struct nouveau_bo *pmo = nvpix->bo;                                    \
142         OUT_RELOCh((chan), pmo, (delta), (flags));                             \
143 } while(0)
144 #else
145 #define OUT_PIXMAPd(chan,pm,data,flags,vor,tor) do {                           \
146         OUT_RELOCd((chan), pNv->FB, (data), (flags), (vor), (tor));            \
147 } while(0)
148 #define OUT_PIXMAPo(chan,pm,flags) do {                                        \
149         OUT_RELOCo((chan), pNv->FB, (flags));                                  \
150 } while(0)
151 #define OUT_PIXMAPl(chan,pm,delta,flags) do {                                  \
152         OUT_RELOCl((chan), pNv->FB, exaGetPixmapOffset(pm) + (delta), (flags));\
153 } while(0)
154 #define OUT_PIXMAPh(chan,pm,delta,flags) do {                                  \
155         OUT_RELOCh((chan), pNv->FB, exaGetPixmapOffset(pm) + (delta), (flags));\
156 } while(0)
157 #endif
158
159 #endif