randr12: Intermediate commit.
[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
45 #define NOUVEAU_TIME_MSEC() GetTimeInMillis()
46
47 #define NOUVEAU_ALIGN(x,bytes) (((x) + ((bytes) - 1)) & ~((bytes) - 1))
48
49 #define NOUVEAU_MODESET_TRACE
50
51 /* User FIFO control */
52 //#define NOUVEAU_DMA_TRACE
53 //#define NOUVEAU_DMA_DEBUG
54 #define NOUVEAU_DMA_SUBCHAN_LRU
55 #define NOUVEAU_DMA_BARRIER mem_barrier();
56 #define NOUVEAU_DMA_TIMEOUT 2000
57
58 /* Push buffer access macros */
59 #define BEGIN_RING(obj,mthd,size) do {                                         \
60         BEGIN_RING_CH(pNv->chan, pNv->obj, (mthd), (size));                    \
61 } while(0)
62
63 #define OUT_RING(data) do {                                                    \
64         OUT_RING_CH(pNv->chan, (data));                                        \
65 } while(0)
66
67 #define OUT_RINGp(src,size) do {                                               \
68         OUT_RINGp_CH(pNv->chan, (src), (size));                                \
69 } while(0)
70
71 #define OUT_RINGf(data) do {                                                   \
72         union { float v; uint32_t u; } c;                                      \
73         c.v = (data);                                                          \
74         OUT_RING(c.u);                                                         \
75 } while(0)
76
77 #define WAIT_RING(size) do {                                                   \
78         WAIT_RING_CH(pNv->chan, (size));                                       \
79 } while(0)
80
81 #define FIRE_RING() do {                                                       \
82         FIRE_RING_CH(pNv->chan);                                               \
83 } while(0)
84
85 #define OUT_RELOC(bo,data,flags,vor,tor) do {                                  \
86         struct nouveau_channel_priv *chan = nouveau_channel(pNv->chan);        \
87         nouveau_bo_emit_reloc(&chan->base, &chan->pushbuf[chan->dma.cur],      \
88                               (bo), (data), (flags), (vor), (tor));            \
89         OUT_RING(0);                                                           \
90 } while(0)
91
92 /* Raw data + flags depending on FB/TT buffer */
93 #define OUT_RELOCd(bo,data,flags,vor,tor) do {                                 \
94         OUT_RELOC((bo), (data), (flags) | NOUVEAU_BO_OR, (vor), (tor));        \
95 } while(0)
96
97 /* FB/TT object handle */
98 #define OUT_RELOCo(bo,flags) do {                                              \
99         OUT_RELOC((bo), 0, (flags) | NOUVEAU_BO_OR,                            \
100                   pNv->chan->vram->handle, pNv->chan->gart->handle);           \
101 } while(0)
102
103 /* Low 32-bits of offset */
104 #define OUT_RELOCl(bo,delta,flags) do {                                        \
105         OUT_RELOC((bo), (delta), (flags) | NOUVEAU_BO_LOW, 0, 0);              \
106 } while(0)
107
108 /* High 32-bits of offset */
109 #define OUT_RELOCh(bo,delta,flags) do {                                        \
110         OUT_RELOC((bo), (delta), (flags) | NOUVEAU_BO_HIGH, 0, 0);             \
111 } while(0)
112
113
114 /* Alternate versions of OUT_RELOCx above, takes pixmaps instead of BOs */
115 #if NOUVEAU_EXA_PIXMAPS
116 #define OUT_PIXMAPd(pm,data,flags,vor,tor) do {                                \
117         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
118         struct nouveau_bo *pmo = nvpix->bo;                                    \
119         OUT_RELOCd(pmo, (data), (flags), (vor), (tor));                        \
120 } while(0)
121 #define OUT_PIXMAPo(pm,flags) do {                                             \
122         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
123         struct nouveau_bo *pmo = nvpix->bo;                                    \
124         OUT_RELOCo(pmo, (flags));                                              \
125 } while(0)
126 #define OUT_PIXMAPl(pm,delta,flags) do {                                       \
127         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
128         struct nouveau_bo *pmo = nvpix->bo;                                    \
129         OUT_RELOCl(pmo, (delta), (flags));                                     \
130 } while(0)
131 #define OUT_PIXMAPh(pm,delta,flags) do {                                       \
132         struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm));        \
133         struct nouveau_bo *pmo = nvpix->bo;                                    \
134         OUT_RELOCh(pmo, (delta), (flags));                                     \
135 } while(0)
136 #else
137 #define OUT_PIXMAPd(pm,data,flags,vor,tor) do {                                \
138         OUT_RELOCd(pNv->FB, (data), (flags), (vor), (tor));                    \
139 } while(0)
140 #define OUT_PIXMAPo(pm,flags) do {                                             \
141         OUT_RELOCo(pNv->FB, (flags));                                          \
142 } while(0)
143 #define OUT_PIXMAPl(pm,delta,flags) do {                                       \
144         OUT_RELOCl(pNv->FB, exaGetPixmapOffset(pm) + (delta), (flags));        \
145 } while(0)
146 #define OUT_PIXMAPh(pm,delta,flags) do {                                       \
147         OUT_RELOCh(pNv->FB, exaGetPixmapOffset(pm) + (delta), (flags));        \
148 } while(0)
149 #endif
150
151 #endif