OSDN Git Service

nouveau: interface changes for 0.0.16 DRM
[android-x86/external-libdrm.git] / nouveau / nouveau_pushbuf.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_PUSHBUF_H__
24 #define __NOUVEAU_PUSHBUF_H__
25
26 #include <assert.h>
27 #include <string.h>
28
29 #include "nouveau_bo.h"
30 #include "nouveau_grobj.h"
31
32 int
33 nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
34
35 int
36 nouveau_pushbuf_marker_emit(struct nouveau_channel *chan,
37                             unsigned wait_dwords, unsigned wait_relocs);
38
39 void
40 nouveau_pushbuf_marker_undo(struct nouveau_channel *chan);
41
42 int
43 nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
44                            struct nouveau_bo *, uint32_t data, uint32_t data2,
45                            uint32_t flags, uint32_t vor, uint32_t tor);
46
47 int
48 nouveau_pushbuf_submit(struct nouveau_channel *chan, struct nouveau_bo *bo,
49                        unsigned offset, unsigned length);
50
51 /* Push buffer access macros */
52 static __inline__ int
53 MARK_RING(struct nouveau_channel *chan, unsigned dwords, unsigned relocs)
54 {
55         return nouveau_pushbuf_marker_emit(chan, dwords, relocs);
56 }
57
58 static __inline__ void
59 MARK_UNDO(struct nouveau_channel *chan)
60 {
61         nouveau_pushbuf_marker_undo(chan);
62 }
63
64 static __inline__ void
65 OUT_RING(struct nouveau_channel *chan, unsigned data)
66 {
67         *(chan->cur++) = (data);
68 }
69
70 static __inline__ void
71 OUT_RINGp(struct nouveau_channel *chan, const void *data, unsigned size)
72 {
73         memcpy(chan->cur, data, size * 4);
74         chan->cur += size;
75 }
76
77 static __inline__ void
78 OUT_RINGf(struct nouveau_channel *chan, float f)
79 {
80         union { uint32_t i; float f; } c;
81         c.f = f;
82         OUT_RING(chan, c.i);
83 }
84
85 static __inline__ unsigned
86 AVAIL_RING(struct nouveau_channel *chan)
87 {
88         return chan->end - chan->cur;
89 }
90
91 static __inline__ void
92 WAIT_RING(struct nouveau_channel *chan, unsigned size)
93 {
94         if (chan->cur + size > chan->end)
95                 nouveau_pushbuf_flush(chan, size);
96 }
97
98 static __inline__ void
99 BEGIN_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr,
100            unsigned mthd, unsigned size)
101 {
102         if (gr->bound == NOUVEAU_GROBJ_UNBOUND)
103                 nouveau_grobj_autobind(gr);
104         chan->subc[gr->subc].sequence = chan->subc_sequence++;
105
106         WAIT_RING(chan, size + 1);
107         OUT_RING(chan, (gr->subc << 13) | (size << 18) | mthd);
108 }
109
110 /* non-incrementing BEGIN_RING */
111 static __inline__ void
112 BEGIN_RING_NI(struct nouveau_channel *chan, struct nouveau_grobj *gr,
113            unsigned mthd, unsigned size)
114 {
115         BEGIN_RING(chan, gr, mthd | 0x40000000, size);
116 }
117
118 static __inline__ void
119 FIRE_RING(struct nouveau_channel *chan)
120 {
121         nouveau_pushbuf_flush(chan, 0);
122 }
123
124 static __inline__ void
125 BIND_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr, unsigned sc)
126 {
127         struct nouveau_subchannel *subc = &gr->channel->subc[sc];
128         
129         if (subc->gr) {
130                 if (subc->gr->bound == NOUVEAU_GROBJ_BOUND_EXPLICIT)
131                         assert(0);
132                 subc->gr->bound = NOUVEAU_GROBJ_UNBOUND;
133         }
134         subc->gr = gr;
135         subc->gr->subc = sc;
136         subc->gr->bound = NOUVEAU_GROBJ_BOUND_EXPLICIT;
137
138         BEGIN_RING(chan, gr, 0x0000, 1);
139         OUT_RING  (chan, gr->handle);
140 }
141
142 static __inline__ int
143 OUT_RELOC(struct nouveau_channel *chan, struct nouveau_bo *bo,
144           unsigned data, unsigned flags, unsigned vor, unsigned tor)
145 {
146         return nouveau_pushbuf_emit_reloc(chan, chan->cur++, bo,
147                                           data, 0, flags, vor, tor);
148 }
149
150 static __inline__ int
151 OUT_RELOC2(struct nouveau_channel *chan, struct nouveau_bo *bo,
152            unsigned data, unsigned data2, unsigned flags,
153            unsigned vor, unsigned tor)
154 {
155         return nouveau_pushbuf_emit_reloc(chan, chan->cur++, bo,
156                                           data, data2, flags, vor, tor);
157 }
158
159 /* Raw data + flags depending on FB/TT buffer */
160 static __inline__ int
161 OUT_RELOCd(struct nouveau_channel *chan, struct nouveau_bo *bo,
162            unsigned data, unsigned flags, unsigned vor, unsigned tor)
163 {
164         return OUT_RELOC(chan, bo, data, flags | NOUVEAU_BO_OR, vor, tor);
165 }
166
167 /* FB/TT object handle */
168 static __inline__ int
169 OUT_RELOCo(struct nouveau_channel *chan, struct nouveau_bo *bo,
170            unsigned flags)
171 {
172         return OUT_RELOC(chan, bo, 0, flags | NOUVEAU_BO_OR,
173                          chan->vram->handle, chan->gart->handle);
174 }
175
176 /* Low 32-bits of offset */
177 static __inline__ int
178 OUT_RELOCl(struct nouveau_channel *chan, struct nouveau_bo *bo,
179            unsigned delta, unsigned flags)
180 {
181         return OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_LOW, 0, 0);
182 }
183
184 /* Low 32-bits of offset + GPU linear access range info */
185 static __inline__ int
186 OUT_RELOCr(struct nouveau_channel *chan, struct nouveau_bo *bo,
187            unsigned delta, unsigned size, unsigned flags)
188 {
189         return OUT_RELOC2(chan, bo, delta, size, flags | NOUVEAU_BO_LOW, 0, 0);
190 }
191
192 /* High 32-bits of offset */
193 static __inline__ int
194 OUT_RELOCh(struct nouveau_channel *chan, struct nouveau_bo *bo,
195            unsigned delta, unsigned flags)
196 {
197         return OUT_RELOC(chan, bo, delta, flags | NOUVEAU_BO_HIGH, 0, 0);
198 }
199
200 #endif