2 * Copyright 2007 Nouveau Project
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #ifndef __NOUVEAU_LOCAL_H__
24 #define __NOUVEAU_LOCAL_H__
27 #include "xf86_OSproc.h"
29 #define NOUVEAU_PRIVATE _X_HIDDEN
30 #define NOUVEAU_PUBLIC _X_EXPORT
32 struct nouveau_pixmap {
33 struct nouveau_bo *bo;
38 #define NOUVEAU_MSG(fmt,args...) ErrorF(fmt, ##args)
39 #define NOUVEAU_ERR(fmt,args...) \
40 ErrorF("%s:%d - "fmt, __func__, __LINE__, ##args)
42 #define NOUVEAU_FALLBACK(fmt,args...) do { \
43 NOUVEAU_ERR("FALLBACK: "fmt, ##args); \
47 #define NOUVEAU_FALLBACK(fmt,args...) do { \
52 #define NOUVEAU_TIME_MSEC() GetTimeInMillis()
54 #define NOUVEAU_ALIGN(x,bytes) (((x) + ((bytes) - 1)) & ~((bytes) - 1))
56 /* User FIFO control */
57 //#define NOUVEAU_DMA_TRACE
58 //#define NOUVEAU_DMA_DEBUG
59 //#define NOUVEAU_DMA_DUMP_POSTRELOC_PUSHBUF
60 #define NOUVEAU_DMA_BARRIER mem_barrier();
61 #define NOUVEAU_DMA_TIMEOUT 2000
63 #include "nouveau_channel.h"
64 #include "nouveau_pushbuf.h"
65 #include "nouveau_grobj.h"
66 #include "nouveau_bo.h"
69 nouveau_pushbuf_flush(struct nouveau_channel *, unsigned);
71 nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
72 struct nouveau_bo *, uint32_t data, uint32_t flags,
73 uint32_t vor, uint32_t tor);
75 nouveau_grobj_autobind(struct nouveau_grobj *);
77 /* Push buffer access macros */
78 static __inline__ void
79 OUT_RING(struct nouveau_channel *chan, unsigned data)
81 *(chan->pushbuf->cur++) = (data);
84 static __inline__ void
85 OUT_RINGp(struct nouveau_channel *chan, const void *data, unsigned size)
87 memcpy(chan->pushbuf->cur, data, size * 4);
88 chan->pushbuf->cur += size;
91 static __inline__ void
92 OUT_RINGf(struct nouveau_channel *chan, float f)
94 union { uint32_t i; float f; } c;
99 static __inline__ void
100 RING_SPACE(struct nouveau_channel *chan, unsigned size)
102 if (chan->pushbuf->remaining < size)
103 nouveau_pushbuf_flush(chan, size);
106 static __inline__ void
107 BEGIN_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr,
108 unsigned mthd, unsigned size)
110 if (gr->bound == NOUVEAU_GROBJ_UNBOUND)
111 nouveau_grobj_autobind(gr);
112 chan->subc[gr->subc].sequence = chan->subc_sequence++;
114 RING_SPACE(chan, size + 1);
115 OUT_RING(chan, (gr->subc << 13) | (size << 18) | mthd);
116 chan->pushbuf->remaining -= (size + 1);
119 static __inline__ void
120 FIRE_RING(struct nouveau_channel *chan)
122 nouveau_pushbuf_flush(chan, 0);
125 static __inline__ void
126 BIND_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr, unsigned sc)
128 struct nouveau_subchannel *subc = &gr->channel->subc[sc];
131 if (subc->gr->bound == NOUVEAU_GROBJ_BOUND_EXPLICIT)
133 subc->gr->bound = NOUVEAU_GROBJ_UNBOUND;
137 subc->gr->bound = NOUVEAU_GROBJ_BOUND_EXPLICIT;
139 BEGIN_RING(chan, gr, 0x0000, 1);
140 OUT_RING (chan, gr->handle);
143 static __inline__ void
144 OUT_RELOC(struct nouveau_channel *chan, struct nouveau_bo *bo,
145 unsigned data, unsigned flags, unsigned vor, unsigned tor)
147 nouveau_pushbuf_emit_reloc(chan, chan->pushbuf->cur++, bo,
148 data, flags, vor, tor);
151 /* Raw data + flags depending on FB/TT buffer */
152 static __inline__ void
153 OUT_RELOCd(struct nouveau_channel *chan, struct nouveau_bo *bo,
154 unsigned data, unsigned flags, unsigned vor, unsigned tor)
156 OUT_RELOC(chan, bo, data, flags | NOUVEAU_BO_OR, vor, tor);
159 /* FB/TT object handle */
160 static __inline__ void
161 OUT_RELOCo(struct nouveau_channel *chan, struct nouveau_bo *bo,
164 OUT_RELOC(chan, bo, 0, flags | NOUVEAU_BO_OR,
165 chan->vram->handle, chan->gart->handle);
168 /* Low 32-bits of offset */
169 static __inline__ void
170 OUT_RELOCl(struct nouveau_channel *chan, struct nouveau_bo *bo,
171 unsigned delta, unsigned flags)
173 OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_LOW, 0, 0);
176 /* High 32-bits of offset */
177 static __inline__ void
178 OUT_RELOCh(struct nouveau_channel *chan, struct nouveau_bo *bo,
179 unsigned delta, unsigned flags)
181 OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_HIGH, 0, 0);
184 /* Alternate versions of OUT_RELOCx above, takes pixmaps instead of BOs */
185 #define OUT_PIXMAPd(chan,pm,data,flags,vor,tor) do { \
186 struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm)); \
187 struct nouveau_bo *pmo = nvpix->bo; \
188 OUT_RELOCd((chan), pmo, (data), (flags), (vor), (tor)); \
190 #define OUT_PIXMAPo(chan,pm,flags) do { \
191 struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm)); \
192 struct nouveau_bo *pmo = nvpix->bo; \
193 OUT_RELOCo((chan), pmo, (flags)); \
195 #define OUT_PIXMAPl(chan,pm,delta,flags) do { \
196 struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm)); \
197 struct nouveau_bo *pmo = nvpix->bo; \
198 OUT_RELOCl((chan), pmo, (delta), (flags)); \
200 #define OUT_PIXMAPh(chan,pm,delta,flags) do { \
201 struct nouveau_pixmap *nvpix = exaGetPixmapDriverPrivate((pm)); \
202 struct nouveau_bo *pmo = nvpix->bo; \
203 OUT_RELOCh((chan), pmo, (delta), (flags)); \