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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __NOUVEAU_LOCAL_H__
24 #define __NOUVEAU_LOCAL_H__
26 static inline uint32_t
27 PUSH_AVAIL(struct nouveau_pushbuf
*push
)
29 return push
->end
- push
->cur
;
33 PUSH_SPACE(struct nouveau_pushbuf
*push
, uint32_t size
)
35 if (PUSH_AVAIL(push
) < size
)
36 return nouveau_pushbuf_space(push
, size
, 0, 0) == 0;
41 PUSH_DATA(struct nouveau_pushbuf
*push
, uint32_t data
)
47 PUSH_DATAf(struct nouveau_pushbuf
*push
, float v
)
49 union { float f
; uint32_t i
; } d
= { .f
= v
};
54 PUSH_DATAb(struct nouveau_pushbuf
*push
, GLboolean x
)
56 PUSH_DATA(push
, x
? 1 : 0);
60 PUSH_DATAm(struct nouveau_pushbuf
*push
, float m
[16])
64 for (i
= 0; i
< 4; i
++)
65 for (j
= 0; j
< 4; j
++)
66 PUSH_DATAf(push
, m
[4*j
+ i
]);
70 PUSH_DATAp(struct nouveau_pushbuf
*push
, const void *data
, uint32_t size
)
72 memcpy(push
->cur
, data
, size
* 4);
77 PUSH_RELOC(struct nouveau_pushbuf
*push
, struct nouveau_bo
*bo
, uint32_t offset
,
78 uint32_t flags
, uint32_t vor
, uint32_t tor
)
80 nouveau_pushbuf_reloc(push
, bo
, offset
, flags
, vor
, tor
);
84 PUSH_KICK(struct nouveau_pushbuf
*push
)
86 nouveau_pushbuf_kick(push
, push
->channel
);
89 static struct nouveau_bufctx
*
90 BUFCTX(struct nouveau_pushbuf
*push
)
92 return push
->user_priv
;
96 PUSH_RESET(struct nouveau_pushbuf
*push
, int bin
)
98 nouveau_bufctx_reset(BUFCTX(push
), bin
);
102 PUSH_MTHDl(struct nouveau_pushbuf
*push
, int subc
, int mthd
, int bin
,
103 struct nouveau_bo
*bo
, uint32_t offset
, uint32_t access
)
105 nouveau_bufctx_mthd(BUFCTX(push
), bin
, (1 << 18) | (subc
<< 13) | mthd
,
106 bo
, offset
, access
| NOUVEAU_BO_LOW
, 0, 0);
107 PUSH_DATA(push
, bo
->offset
+ offset
);
111 PUSH_MTHDs(struct nouveau_pushbuf
*push
, int subc
, int mthd
, int bin
,
112 struct nouveau_bo
*bo
, uint32_t data
, uint32_t access
,
113 uint32_t vor
, uint32_t tor
)
115 nouveau_bufctx_mthd(BUFCTX(push
), bin
, (1 << 18) | (subc
<< 13) | mthd
,
116 bo
, data
, access
| NOUVEAU_BO_OR
, vor
, tor
);
118 if (bo
->flags
& NOUVEAU_BO_VRAM
)
119 PUSH_DATA(push
, data
| vor
);
121 PUSH_DATA(push
, data
| tor
);
125 PUSH_MTHD(struct nouveau_pushbuf
*push
, int subc
, int mthd
, int bin
,
126 struct nouveau_bo
*bo
, uint32_t data
, uint32_t access
,
127 uint32_t vor
, uint32_t tor
)
129 nouveau_bufctx_mthd(BUFCTX(push
), bin
, (1 << 18) | (subc
<< 13) | mthd
,
130 bo
, data
, access
| NOUVEAU_BO_OR
, vor
, tor
);
132 if (access
& NOUVEAU_BO_LOW
)
135 if (access
& NOUVEAU_BO_OR
) {
136 if (bo
->flags
& NOUVEAU_BO_VRAM
)
142 PUSH_DATA(push
, data
);
146 BEGIN_NV04(struct nouveau_pushbuf
*push
, int subc
, int mthd
, int size
)
148 PUSH_SPACE(push
, size
+ 1);
149 PUSH_DATA (push
, 0x00000000 | (size
<< 18) | (subc
<< 13) | mthd
);
153 BEGIN_NI04(struct nouveau_pushbuf
*push
, int subc
, int mthd
, int size
)
155 PUSH_SPACE(push
, size
+ 1);
156 PUSH_DATA (push
, 0x40000000 | (size
<< 18) | (subc
<< 13) | mthd
);
159 /* subchannel assignment */
160 #define SUBC_M2MF(mthd) 0, (mthd)
161 #define NV03_M2MF(mthd) SUBC_M2MF(NV04_M2MF_##mthd)
162 #define SUBC_NVSW(mthd) 1, (mthd)
163 #define SUBC_SF2D(mthd) 2, (mthd)
164 #define NV04_SF2D(mthd) SUBC_SF2D(NV04_CONTEXT_SURFACES_2D_##mthd)
165 #define NV10_SF2D(mthd) SUBC_SF2D(NV10_CONTEXT_SURFACES_2D_##mthd)
166 #define SUBC_PATT(mthd) 3, (mthd)
167 #define NV01_PATT(mthd) SUBC_PATT(NV04_IMAGE_PATTERN_##mthd)
168 #define NV01_ROP(mthd) SUBC_PATT(NV03_CONTEXT_ROP_##mthd)
169 #define SUBC_GDI(mthd) 4, (mthd)
170 #define NV04_GDI(mthd) SUBC_GDI(NV04_GDI_RECTANGLE_TEXT_##mthd)
171 #define SUBC_SIFM(mthd) 5, (mthd)
172 #define NV03_SIFM(mthd) SUBC_SIFM(NV03_SCALED_IMAGE_FROM_MEMORY_##mthd)
173 #define NV05_SIFM(mthd) SUBC_SIFM(NV05_SCALED_IMAGE_FROM_MEMORY_##mthd)
174 #define SUBC_SURF(mthd) 6, (mthd)
175 #define NV04_SSWZ(mthd) SUBC_SURF(NV04_SWIZZLED_SURFACE_##mthd)
176 #define NV04_SF3D(mthd) SUBC_SURF(NV04_CONTEXT_SURFACES_3D_##mthd)
177 #define SUBC_3D(mthd) 7, (mthd)
178 #define NV04_TTRI(mthd) SUBC_3D(NV04_TEXTURED_TRIANGLE_##mthd)
179 #define NV04_MTRI(mthd) SUBC_3D(NV04_MULTITEX_TRIANGLE_##mthd)
180 #define NV10_3D(mthd) SUBC_3D(NV10_3D_##mthd)
181 #define NV11_3D(mthd) SUBC_3D(NV11_3D_##mthd)
182 #define NV17_3D(mthd) SUBC_3D(NV17_3D_##mthd)
183 #define NV20_3D(mthd) SUBC_3D(NV20_3D_##mthd)
184 #define NV25_3D(mthd) SUBC_3D(NV25_3D_##mthd)
186 #define NV01_SUBC(subc, mthd) SUBC_##subc((NV01_SUBCHAN_##mthd))
187 #define NV11_SUBC(subc, mthd) SUBC_##subc((NV11_SUBCHAN_##mthd))
189 #define NV04_GRAPH(subc, mthd) SUBC_##subc((NV04_GRAPH_##mthd))