• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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.
21  */
22 
23 #ifndef __NOUVEAU_LOCAL_H__
24 #define __NOUVEAU_LOCAL_H__
25 
26 static inline uint32_t
PUSH_AVAIL(struct nouveau_pushbuf * push)27 PUSH_AVAIL(struct nouveau_pushbuf *push)
28 {
29 	return push->end - push->cur;
30 }
31 
32 static inline int
PUSH_SPACE(struct nouveau_pushbuf * push,uint32_t size)33 PUSH_SPACE(struct nouveau_pushbuf *push, uint32_t size)
34 {
35 	if (PUSH_AVAIL(push) < size)
36 		return nouveau_pushbuf_space(push, size, 0, 0) == 0;
37 	return 1;
38 }
39 
40 static inline void
PUSH_DATA(struct nouveau_pushbuf * push,uint32_t data)41 PUSH_DATA(struct nouveau_pushbuf *push, uint32_t data)
42 {
43 	*push->cur++ = data;
44 }
45 
46 static inline void
PUSH_DATAf(struct nouveau_pushbuf * push,float v)47 PUSH_DATAf(struct nouveau_pushbuf *push, float v)
48 {
49 	union { float f; uint32_t i; } d = { .f = v };
50 	PUSH_DATA(push, d.i);
51 }
52 
53 static inline void
PUSH_DATAb(struct nouveau_pushbuf * push,GLboolean x)54 PUSH_DATAb(struct nouveau_pushbuf *push, GLboolean x)
55 {
56 	PUSH_DATA(push, x ? 1 : 0);
57 }
58 
59 static inline void
PUSH_DATAm(struct nouveau_pushbuf * push,float m[16])60 PUSH_DATAm(struct nouveau_pushbuf *push, float m[16])
61 {
62 	int i, j;
63 
64 	for (i = 0; i < 4; i++)
65 		for (j = 0; j < 4; j++)
66 			PUSH_DATAf(push, m[4*j + i]);
67 }
68 
69 static inline void
PUSH_DATAp(struct nouveau_pushbuf * push,const void * data,uint32_t size)70 PUSH_DATAp(struct nouveau_pushbuf *push, const void *data, uint32_t size)
71 {
72 	memcpy(push->cur, data, size * 4);
73 	push->cur += size;
74 }
75 
76 static inline void
PUSH_RELOC(struct nouveau_pushbuf * push,struct nouveau_bo * bo,uint32_t offset,uint32_t flags,uint32_t vor,uint32_t tor)77 PUSH_RELOC(struct nouveau_pushbuf *push, struct nouveau_bo *bo, uint32_t offset,
78 	   uint32_t flags, uint32_t vor, uint32_t tor)
79 {
80 	nouveau_pushbuf_reloc(push, bo, offset, flags, vor, tor);
81 }
82 
83 static inline void
PUSH_KICK(struct nouveau_pushbuf * push)84 PUSH_KICK(struct nouveau_pushbuf *push)
85 {
86 	nouveau_pushbuf_kick(push, push->channel);
87 }
88 
89 static struct nouveau_bufctx *
BUFCTX(struct nouveau_pushbuf * push)90 BUFCTX(struct nouveau_pushbuf *push)
91 {
92 	return push->user_priv;
93 }
94 
95 static inline void
PUSH_RESET(struct nouveau_pushbuf * push,int bin)96 PUSH_RESET(struct nouveau_pushbuf *push, int bin)
97 {
98 	nouveau_bufctx_reset(BUFCTX(push), bin);
99 }
100 
101 static inline void
PUSH_MTHDl(struct nouveau_pushbuf * push,int subc,int mthd,int bin,struct nouveau_bo * bo,uint32_t offset,uint32_t access)102 PUSH_MTHDl(struct nouveau_pushbuf *push, int subc, int mthd, int bin,
103 	   struct nouveau_bo *bo, uint32_t offset, uint32_t access)
104 {
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);
108 }
109 
110 static inline void
PUSH_MTHDs(struct nouveau_pushbuf * push,int subc,int mthd,int bin,struct nouveau_bo * bo,uint32_t data,uint32_t access,uint32_t vor,uint32_t tor)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)
114 {
115 	nouveau_bufctx_mthd(BUFCTX(push), bin, (1 << 18) | (subc << 13) | mthd,
116 			    bo, data, access | NOUVEAU_BO_OR, vor, tor);
117 
118 	if (bo->flags & NOUVEAU_BO_VRAM)
119 		PUSH_DATA(push, data | vor);
120 	else
121 		PUSH_DATA(push, data | tor);
122 }
123 
124 static inline void
PUSH_MTHD(struct nouveau_pushbuf * push,int subc,int mthd,int bin,struct nouveau_bo * bo,uint32_t data,uint32_t access,uint32_t vor,uint32_t 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)
128 {
129 	nouveau_bufctx_mthd(BUFCTX(push), bin, (1 << 18) | (subc << 13) | mthd,
130 			    bo, data, access | NOUVEAU_BO_OR, vor, tor);
131 
132 	if (access & NOUVEAU_BO_LOW)
133 		data += bo->offset;
134 
135 	if (access & NOUVEAU_BO_OR) {
136 		if (bo->flags & NOUVEAU_BO_VRAM)
137 			data |= vor;
138 		else
139 			data |= tor;
140 	}
141 
142 	PUSH_DATA(push, data);
143 }
144 
145 static inline void
BEGIN_NV04(struct nouveau_pushbuf * push,int subc,int mthd,int size)146 BEGIN_NV04(struct nouveau_pushbuf *push, int subc, int mthd, int size)
147 {
148 	PUSH_SPACE(push, size + 1);
149 	PUSH_DATA (push, 0x00000000 | (size << 18) | (subc << 13) | mthd);
150 }
151 
152 static inline void
BEGIN_NI04(struct nouveau_pushbuf * push,int subc,int mthd,int size)153 BEGIN_NI04(struct nouveau_pushbuf *push, int subc, int mthd, int size)
154 {
155 	PUSH_SPACE(push, size + 1);
156 	PUSH_DATA (push, 0x40000000 | (size << 18) | (subc << 13) | mthd);
157 }
158 
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)
185 
186 #define NV01_SUBC(subc, mthd) SUBC_##subc((NV01_SUBCHAN_##mthd))
187 #define NV11_SUBC(subc, mthd) SUBC_##subc((NV11_SUBCHAN_##mthd))
188 
189 #define NV04_GRAPH(subc, mthd) SUBC_##subc((NV04_GRAPH_##mthd))
190 
191 #endif
192