1b8bf04e1SBen Skeggs /*
2b8bf04e1SBen Skeggs * Copyright 2007 Stephane Marchesin
3b8bf04e1SBen Skeggs * All Rights Reserved.
4b8bf04e1SBen Skeggs *
5b8bf04e1SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
6b8bf04e1SBen Skeggs * copy of this software and associated documentation files (the "Software"),
7b8bf04e1SBen Skeggs * to deal in the Software without restriction, including without limitation
8b8bf04e1SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9b8bf04e1SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
10b8bf04e1SBen Skeggs * Software is furnished to do so, subject to the following conditions:
11b8bf04e1SBen Skeggs *
12b8bf04e1SBen Skeggs * The above copyright notice and this permission notice (including the next
13b8bf04e1SBen Skeggs * paragr) shall be included in all copies or substantial portions of the
14b8bf04e1SBen Skeggs * Software.
15b8bf04e1SBen Skeggs *
16b8bf04e1SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17b8bf04e1SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18b8bf04e1SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19b8bf04e1SBen Skeggs * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20b8bf04e1SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21b8bf04e1SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22b8bf04e1SBen Skeggs * DEALINGS IN THE SOFTWARE.
23b8bf04e1SBen Skeggs */
2427f3d6cfSBen Skeggs #include "priv.h"
25e3c71eb2SBen Skeggs #include "regs.h"
26b8bf04e1SBen Skeggs
27b8bf04e1SBen Skeggs #include <core/client.h>
2813de7f46SBen Skeggs #include <core/gpuobj.h>
29e3c71eb2SBen Skeggs #include <engine/fifo.h>
309a65a38cSBen Skeggs #include <engine/fifo/chan.h>
31b8bf04e1SBen Skeggs #include <subdev/instmem.h>
32b8bf04e1SBen Skeggs #include <subdev/timer.h>
33b8bf04e1SBen Skeggs
34b8bf04e1SBen Skeggs static u32
35b8bf04e1SBen Skeggs nv04_gr_ctx_regs[] = {
36b8bf04e1SBen Skeggs 0x0040053c,
37b8bf04e1SBen Skeggs 0x00400544,
38b8bf04e1SBen Skeggs 0x00400540,
39b8bf04e1SBen Skeggs 0x00400548,
40b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_SWITCH1,
41b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_SWITCH2,
42b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_SWITCH3,
43b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_SWITCH4,
44b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_CACHE1,
45b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_CACHE2,
46b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_CACHE3,
47b8bf04e1SBen Skeggs NV04_PGRAPH_CTX_CACHE4,
48b8bf04e1SBen Skeggs 0x00400184,
49b8bf04e1SBen Skeggs 0x004001a4,
50b8bf04e1SBen Skeggs 0x004001c4,
51b8bf04e1SBen Skeggs 0x004001e4,
52b8bf04e1SBen Skeggs 0x00400188,
53b8bf04e1SBen Skeggs 0x004001a8,
54b8bf04e1SBen Skeggs 0x004001c8,
55b8bf04e1SBen Skeggs 0x004001e8,
56b8bf04e1SBen Skeggs 0x0040018c,
57b8bf04e1SBen Skeggs 0x004001ac,
58b8bf04e1SBen Skeggs 0x004001cc,
59b8bf04e1SBen Skeggs 0x004001ec,
60b8bf04e1SBen Skeggs 0x00400190,
61b8bf04e1SBen Skeggs 0x004001b0,
62b8bf04e1SBen Skeggs 0x004001d0,
63b8bf04e1SBen Skeggs 0x004001f0,
64b8bf04e1SBen Skeggs 0x00400194,
65b8bf04e1SBen Skeggs 0x004001b4,
66b8bf04e1SBen Skeggs 0x004001d4,
67b8bf04e1SBen Skeggs 0x004001f4,
68b8bf04e1SBen Skeggs 0x00400198,
69b8bf04e1SBen Skeggs 0x004001b8,
70b8bf04e1SBen Skeggs 0x004001d8,
71b8bf04e1SBen Skeggs 0x004001f8,
72b8bf04e1SBen Skeggs 0x0040019c,
73b8bf04e1SBen Skeggs 0x004001bc,
74b8bf04e1SBen Skeggs 0x004001dc,
75b8bf04e1SBen Skeggs 0x004001fc,
76b8bf04e1SBen Skeggs 0x00400174,
77b8bf04e1SBen Skeggs NV04_PGRAPH_DMA_START_0,
78b8bf04e1SBen Skeggs NV04_PGRAPH_DMA_START_1,
79b8bf04e1SBen Skeggs NV04_PGRAPH_DMA_LENGTH,
80b8bf04e1SBen Skeggs NV04_PGRAPH_DMA_MISC,
81b8bf04e1SBen Skeggs NV04_PGRAPH_DMA_PITCH,
82b8bf04e1SBen Skeggs NV04_PGRAPH_BOFFSET0,
83b8bf04e1SBen Skeggs NV04_PGRAPH_BBASE0,
84b8bf04e1SBen Skeggs NV04_PGRAPH_BLIMIT0,
85b8bf04e1SBen Skeggs NV04_PGRAPH_BOFFSET1,
86b8bf04e1SBen Skeggs NV04_PGRAPH_BBASE1,
87b8bf04e1SBen Skeggs NV04_PGRAPH_BLIMIT1,
88b8bf04e1SBen Skeggs NV04_PGRAPH_BOFFSET2,
89b8bf04e1SBen Skeggs NV04_PGRAPH_BBASE2,
90b8bf04e1SBen Skeggs NV04_PGRAPH_BLIMIT2,
91b8bf04e1SBen Skeggs NV04_PGRAPH_BOFFSET3,
92b8bf04e1SBen Skeggs NV04_PGRAPH_BBASE3,
93b8bf04e1SBen Skeggs NV04_PGRAPH_BLIMIT3,
94b8bf04e1SBen Skeggs NV04_PGRAPH_BOFFSET4,
95b8bf04e1SBen Skeggs NV04_PGRAPH_BBASE4,
96b8bf04e1SBen Skeggs NV04_PGRAPH_BLIMIT4,
97b8bf04e1SBen Skeggs NV04_PGRAPH_BOFFSET5,
98b8bf04e1SBen Skeggs NV04_PGRAPH_BBASE5,
99b8bf04e1SBen Skeggs NV04_PGRAPH_BLIMIT5,
100b8bf04e1SBen Skeggs NV04_PGRAPH_BPITCH0,
101b8bf04e1SBen Skeggs NV04_PGRAPH_BPITCH1,
102b8bf04e1SBen Skeggs NV04_PGRAPH_BPITCH2,
103b8bf04e1SBen Skeggs NV04_PGRAPH_BPITCH3,
104b8bf04e1SBen Skeggs NV04_PGRAPH_BPITCH4,
105b8bf04e1SBen Skeggs NV04_PGRAPH_SURFACE,
106b8bf04e1SBen Skeggs NV04_PGRAPH_STATE,
107b8bf04e1SBen Skeggs NV04_PGRAPH_BSWIZZLE2,
108b8bf04e1SBen Skeggs NV04_PGRAPH_BSWIZZLE5,
109b8bf04e1SBen Skeggs NV04_PGRAPH_BPIXEL,
110b8bf04e1SBen Skeggs NV04_PGRAPH_NOTIFY,
111b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLOR0,
112b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLOR1,
113b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x00,
114b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x04,
115b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x08,
116b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x0c,
117b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x10,
118b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x14,
119b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x18,
120b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x1c,
121b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x20,
122b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x24,
123b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x28,
124b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x2c,
125b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x30,
126b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x34,
127b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x38,
128b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x3c,
129b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x40,
130b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x44,
131b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x48,
132b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x4c,
133b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x50,
134b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x54,
135b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x58,
136b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x5c,
137b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x60,
138b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x64,
139b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x68,
140b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x6c,
141b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x70,
142b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x74,
143b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x78,
144b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x7c,
145b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x80,
146b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x84,
147b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x88,
148b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x8c,
149b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x90,
150b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x94,
151b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x98,
152b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0x9c,
153b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xa0,
154b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xa4,
155b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xa8,
156b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xac,
157b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xb0,
158b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xb4,
159b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xb8,
160b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xbc,
161b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xc0,
162b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xc4,
163b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xc8,
164b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xcc,
165b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xd0,
166b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xd4,
167b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xd8,
168b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xdc,
169b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xe0,
170b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xe4,
171b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xe8,
172b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xec,
173b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xf0,
174b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xf4,
175b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xf8,
176b8bf04e1SBen Skeggs NV04_PGRAPH_PATT_COLORRAM+0xfc,
177b8bf04e1SBen Skeggs NV04_PGRAPH_PATTERN,
178b8bf04e1SBen Skeggs 0x0040080c,
179b8bf04e1SBen Skeggs NV04_PGRAPH_PATTERN_SHAPE,
180b8bf04e1SBen Skeggs 0x00400600,
181b8bf04e1SBen Skeggs NV04_PGRAPH_ROP3,
182b8bf04e1SBen Skeggs NV04_PGRAPH_CHROMA,
183b8bf04e1SBen Skeggs NV04_PGRAPH_BETA_AND,
184b8bf04e1SBen Skeggs NV04_PGRAPH_BETA_PREMULT,
185b8bf04e1SBen Skeggs NV04_PGRAPH_CONTROL0,
186b8bf04e1SBen Skeggs NV04_PGRAPH_CONTROL1,
187b8bf04e1SBen Skeggs NV04_PGRAPH_CONTROL2,
188b8bf04e1SBen Skeggs NV04_PGRAPH_BLEND,
189b8bf04e1SBen Skeggs NV04_PGRAPH_STORED_FMT,
190b8bf04e1SBen Skeggs NV04_PGRAPH_SOURCE_COLOR,
191b8bf04e1SBen Skeggs 0x00400560,
192b8bf04e1SBen Skeggs 0x00400568,
193b8bf04e1SBen Skeggs 0x00400564,
194b8bf04e1SBen Skeggs 0x0040056c,
195b8bf04e1SBen Skeggs 0x00400400,
196b8bf04e1SBen Skeggs 0x00400480,
197b8bf04e1SBen Skeggs 0x00400404,
198b8bf04e1SBen Skeggs 0x00400484,
199b8bf04e1SBen Skeggs 0x00400408,
200b8bf04e1SBen Skeggs 0x00400488,
201b8bf04e1SBen Skeggs 0x0040040c,
202b8bf04e1SBen Skeggs 0x0040048c,
203b8bf04e1SBen Skeggs 0x00400410,
204b8bf04e1SBen Skeggs 0x00400490,
205b8bf04e1SBen Skeggs 0x00400414,
206b8bf04e1SBen Skeggs 0x00400494,
207b8bf04e1SBen Skeggs 0x00400418,
208b8bf04e1SBen Skeggs 0x00400498,
209b8bf04e1SBen Skeggs 0x0040041c,
210b8bf04e1SBen Skeggs 0x0040049c,
211b8bf04e1SBen Skeggs 0x00400420,
212b8bf04e1SBen Skeggs 0x004004a0,
213b8bf04e1SBen Skeggs 0x00400424,
214b8bf04e1SBen Skeggs 0x004004a4,
215b8bf04e1SBen Skeggs 0x00400428,
216b8bf04e1SBen Skeggs 0x004004a8,
217b8bf04e1SBen Skeggs 0x0040042c,
218b8bf04e1SBen Skeggs 0x004004ac,
219b8bf04e1SBen Skeggs 0x00400430,
220b8bf04e1SBen Skeggs 0x004004b0,
221b8bf04e1SBen Skeggs 0x00400434,
222b8bf04e1SBen Skeggs 0x004004b4,
223b8bf04e1SBen Skeggs 0x00400438,
224b8bf04e1SBen Skeggs 0x004004b8,
225b8bf04e1SBen Skeggs 0x0040043c,
226b8bf04e1SBen Skeggs 0x004004bc,
227b8bf04e1SBen Skeggs 0x00400440,
228b8bf04e1SBen Skeggs 0x004004c0,
229b8bf04e1SBen Skeggs 0x00400444,
230b8bf04e1SBen Skeggs 0x004004c4,
231b8bf04e1SBen Skeggs 0x00400448,
232b8bf04e1SBen Skeggs 0x004004c8,
233b8bf04e1SBen Skeggs 0x0040044c,
234b8bf04e1SBen Skeggs 0x004004cc,
235b8bf04e1SBen Skeggs 0x00400450,
236b8bf04e1SBen Skeggs 0x004004d0,
237b8bf04e1SBen Skeggs 0x00400454,
238b8bf04e1SBen Skeggs 0x004004d4,
239b8bf04e1SBen Skeggs 0x00400458,
240b8bf04e1SBen Skeggs 0x004004d8,
241b8bf04e1SBen Skeggs 0x0040045c,
242b8bf04e1SBen Skeggs 0x004004dc,
243b8bf04e1SBen Skeggs 0x00400460,
244b8bf04e1SBen Skeggs 0x004004e0,
245b8bf04e1SBen Skeggs 0x00400464,
246b8bf04e1SBen Skeggs 0x004004e4,
247b8bf04e1SBen Skeggs 0x00400468,
248b8bf04e1SBen Skeggs 0x004004e8,
249b8bf04e1SBen Skeggs 0x0040046c,
250b8bf04e1SBen Skeggs 0x004004ec,
251b8bf04e1SBen Skeggs 0x00400470,
252b8bf04e1SBen Skeggs 0x004004f0,
253b8bf04e1SBen Skeggs 0x00400474,
254b8bf04e1SBen Skeggs 0x004004f4,
255b8bf04e1SBen Skeggs 0x00400478,
256b8bf04e1SBen Skeggs 0x004004f8,
257b8bf04e1SBen Skeggs 0x0040047c,
258b8bf04e1SBen Skeggs 0x004004fc,
259b8bf04e1SBen Skeggs 0x00400534,
260b8bf04e1SBen Skeggs 0x00400538,
261b8bf04e1SBen Skeggs 0x00400514,
262b8bf04e1SBen Skeggs 0x00400518,
263b8bf04e1SBen Skeggs 0x0040051c,
264b8bf04e1SBen Skeggs 0x00400520,
265b8bf04e1SBen Skeggs 0x00400524,
266b8bf04e1SBen Skeggs 0x00400528,
267b8bf04e1SBen Skeggs 0x0040052c,
268b8bf04e1SBen Skeggs 0x00400530,
269b8bf04e1SBen Skeggs 0x00400d00,
270b8bf04e1SBen Skeggs 0x00400d40,
271b8bf04e1SBen Skeggs 0x00400d80,
272b8bf04e1SBen Skeggs 0x00400d04,
273b8bf04e1SBen Skeggs 0x00400d44,
274b8bf04e1SBen Skeggs 0x00400d84,
275b8bf04e1SBen Skeggs 0x00400d08,
276b8bf04e1SBen Skeggs 0x00400d48,
277b8bf04e1SBen Skeggs 0x00400d88,
278b8bf04e1SBen Skeggs 0x00400d0c,
279b8bf04e1SBen Skeggs 0x00400d4c,
280b8bf04e1SBen Skeggs 0x00400d8c,
281b8bf04e1SBen Skeggs 0x00400d10,
282b8bf04e1SBen Skeggs 0x00400d50,
283b8bf04e1SBen Skeggs 0x00400d90,
284b8bf04e1SBen Skeggs 0x00400d14,
285b8bf04e1SBen Skeggs 0x00400d54,
286b8bf04e1SBen Skeggs 0x00400d94,
287b8bf04e1SBen Skeggs 0x00400d18,
288b8bf04e1SBen Skeggs 0x00400d58,
289b8bf04e1SBen Skeggs 0x00400d98,
290b8bf04e1SBen Skeggs 0x00400d1c,
291b8bf04e1SBen Skeggs 0x00400d5c,
292b8bf04e1SBen Skeggs 0x00400d9c,
293b8bf04e1SBen Skeggs 0x00400d20,
294b8bf04e1SBen Skeggs 0x00400d60,
295b8bf04e1SBen Skeggs 0x00400da0,
296b8bf04e1SBen Skeggs 0x00400d24,
297b8bf04e1SBen Skeggs 0x00400d64,
298b8bf04e1SBen Skeggs 0x00400da4,
299b8bf04e1SBen Skeggs 0x00400d28,
300b8bf04e1SBen Skeggs 0x00400d68,
301b8bf04e1SBen Skeggs 0x00400da8,
302b8bf04e1SBen Skeggs 0x00400d2c,
303b8bf04e1SBen Skeggs 0x00400d6c,
304b8bf04e1SBen Skeggs 0x00400dac,
305b8bf04e1SBen Skeggs 0x00400d30,
306b8bf04e1SBen Skeggs 0x00400d70,
307b8bf04e1SBen Skeggs 0x00400db0,
308b8bf04e1SBen Skeggs 0x00400d34,
309b8bf04e1SBen Skeggs 0x00400d74,
310b8bf04e1SBen Skeggs 0x00400db4,
311b8bf04e1SBen Skeggs 0x00400d38,
312b8bf04e1SBen Skeggs 0x00400d78,
313b8bf04e1SBen Skeggs 0x00400db8,
314b8bf04e1SBen Skeggs 0x00400d3c,
315b8bf04e1SBen Skeggs 0x00400d7c,
316b8bf04e1SBen Skeggs 0x00400dbc,
317b8bf04e1SBen Skeggs 0x00400590,
318b8bf04e1SBen Skeggs 0x00400594,
319b8bf04e1SBen Skeggs 0x00400598,
320b8bf04e1SBen Skeggs 0x0040059c,
321b8bf04e1SBen Skeggs 0x004005a8,
322b8bf04e1SBen Skeggs 0x004005ac,
323b8bf04e1SBen Skeggs 0x004005b0,
324b8bf04e1SBen Skeggs 0x004005b4,
325b8bf04e1SBen Skeggs 0x004005c0,
326b8bf04e1SBen Skeggs 0x004005c4,
327b8bf04e1SBen Skeggs 0x004005c8,
328b8bf04e1SBen Skeggs 0x004005cc,
329b8bf04e1SBen Skeggs 0x004005d0,
330b8bf04e1SBen Skeggs 0x004005d4,
331b8bf04e1SBen Skeggs 0x004005d8,
332b8bf04e1SBen Skeggs 0x004005dc,
333b8bf04e1SBen Skeggs 0x004005e0,
334b8bf04e1SBen Skeggs NV04_PGRAPH_PASSTHRU_0,
335b8bf04e1SBen Skeggs NV04_PGRAPH_PASSTHRU_1,
336b8bf04e1SBen Skeggs NV04_PGRAPH_PASSTHRU_2,
337b8bf04e1SBen Skeggs NV04_PGRAPH_DVD_COLORFMT,
338b8bf04e1SBen Skeggs NV04_PGRAPH_SCALED_FORMAT,
339b8bf04e1SBen Skeggs NV04_PGRAPH_MISC24_0,
340b8bf04e1SBen Skeggs NV04_PGRAPH_MISC24_1,
341b8bf04e1SBen Skeggs NV04_PGRAPH_MISC24_2,
342b8bf04e1SBen Skeggs 0x00400500,
343b8bf04e1SBen Skeggs 0x00400504,
344b8bf04e1SBen Skeggs NV04_PGRAPH_VALID1,
345b8bf04e1SBen Skeggs NV04_PGRAPH_VALID2,
346b8bf04e1SBen Skeggs NV04_PGRAPH_DEBUG_3
347b8bf04e1SBen Skeggs };
348b8bf04e1SBen Skeggs
34927f3d6cfSBen Skeggs #define nv04_gr(p) container_of((p), struct nv04_gr, base)
35027f3d6cfSBen Skeggs
351bfee3f3dSBen Skeggs struct nv04_gr {
352e3c71eb2SBen Skeggs struct nvkm_gr base;
353b8bf04e1SBen Skeggs struct nv04_gr_chan *chan[16];
354b8bf04e1SBen Skeggs spinlock_t lock;
355b8bf04e1SBen Skeggs };
356b8bf04e1SBen Skeggs
35727f3d6cfSBen Skeggs #define nv04_gr_chan(p) container_of((p), struct nv04_gr_chan, object)
35827f3d6cfSBen Skeggs
359b8bf04e1SBen Skeggs struct nv04_gr_chan {
36027f3d6cfSBen Skeggs struct nvkm_object object;
36127f3d6cfSBen Skeggs struct nv04_gr *gr;
362b8bf04e1SBen Skeggs int chid;
363b8bf04e1SBen Skeggs u32 nv04[ARRAY_SIZE(nv04_gr_ctx_regs)];
364b8bf04e1SBen Skeggs };
365b8bf04e1SBen Skeggs
366b8bf04e1SBen Skeggs /*******************************************************************************
367b8bf04e1SBen Skeggs * Graphics object classes
368b8bf04e1SBen Skeggs ******************************************************************************/
369b8bf04e1SBen Skeggs
370b8bf04e1SBen Skeggs /*
371b8bf04e1SBen Skeggs * Software methods, why they are needed, and how they all work:
372b8bf04e1SBen Skeggs *
373b8bf04e1SBen Skeggs * NV04 and NV05 keep most of the state in PGRAPH context itself, but some
374b8bf04e1SBen Skeggs * 2d engine settings are kept inside the grobjs themselves. The grobjs are
375b8bf04e1SBen Skeggs * 3 words long on both. grobj format on NV04 is:
376b8bf04e1SBen Skeggs *
377b8bf04e1SBen Skeggs * word 0:
378b8bf04e1SBen Skeggs * - bits 0-7: class
379b8bf04e1SBen Skeggs * - bit 12: color key active
380b8bf04e1SBen Skeggs * - bit 13: clip rect active
381b8bf04e1SBen Skeggs * - bit 14: if set, destination surface is swizzled and taken from buffer 5
382b8bf04e1SBen Skeggs * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
383b8bf04e1SBen Skeggs * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
384b8bf04e1SBen Skeggs * NV03_CONTEXT_SURFACE_DST].
385b8bf04e1SBen Skeggs * - bits 15-17: 2d operation [aka patch config]
386b8bf04e1SBen Skeggs * - bit 24: patch valid [enables rendering using this object]
387b8bf04e1SBen Skeggs * - bit 25: surf3d valid [for tex_tri and multitex_tri only]
388b8bf04e1SBen Skeggs * word 1:
389b8bf04e1SBen Skeggs * - bits 0-1: mono format
390b8bf04e1SBen Skeggs * - bits 8-13: color format
391b8bf04e1SBen Skeggs * - bits 16-31: DMA_NOTIFY instance
392b8bf04e1SBen Skeggs * word 2:
393b8bf04e1SBen Skeggs * - bits 0-15: DMA_A instance
394b8bf04e1SBen Skeggs * - bits 16-31: DMA_B instance
395b8bf04e1SBen Skeggs *
396b8bf04e1SBen Skeggs * On NV05 it's:
397b8bf04e1SBen Skeggs *
398b8bf04e1SBen Skeggs * word 0:
399b8bf04e1SBen Skeggs * - bits 0-7: class
400b8bf04e1SBen Skeggs * - bit 12: color key active
401b8bf04e1SBen Skeggs * - bit 13: clip rect active
402b8bf04e1SBen Skeggs * - bit 14: if set, destination surface is swizzled and taken from buffer 5
403b8bf04e1SBen Skeggs * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
404b8bf04e1SBen Skeggs * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
405b8bf04e1SBen Skeggs * NV03_CONTEXT_SURFACE_DST].
406b8bf04e1SBen Skeggs * - bits 15-17: 2d operation [aka patch config]
407b8bf04e1SBen Skeggs * - bits 20-22: dither mode
408b8bf04e1SBen Skeggs * - bit 24: patch valid [enables rendering using this object]
409b8bf04e1SBen Skeggs * - bit 25: surface_dst/surface_color/surf2d/surf3d valid
410b8bf04e1SBen Skeggs * - bit 26: surface_src/surface_zeta valid
411b8bf04e1SBen Skeggs * - bit 27: pattern valid
412b8bf04e1SBen Skeggs * - bit 28: rop valid
413b8bf04e1SBen Skeggs * - bit 29: beta1 valid
414b8bf04e1SBen Skeggs * - bit 30: beta4 valid
415b8bf04e1SBen Skeggs * word 1:
416b8bf04e1SBen Skeggs * - bits 0-1: mono format
417b8bf04e1SBen Skeggs * - bits 8-13: color format
418b8bf04e1SBen Skeggs * - bits 16-31: DMA_NOTIFY instance
419b8bf04e1SBen Skeggs * word 2:
420b8bf04e1SBen Skeggs * - bits 0-15: DMA_A instance
421b8bf04e1SBen Skeggs * - bits 16-31: DMA_B instance
422b8bf04e1SBen Skeggs *
423b8bf04e1SBen Skeggs * NV05 will set/unset the relevant valid bits when you poke the relevant
424b8bf04e1SBen Skeggs * object-binding methods with object of the proper type, or with the NULL
425b8bf04e1SBen Skeggs * type. It'll only allow rendering using the grobj if all needed objects
426b8bf04e1SBen Skeggs * are bound. The needed set of objects depends on selected operation: for
427b8bf04e1SBen Skeggs * example rop object is needed by ROP_AND, but not by SRCCOPY_AND.
428b8bf04e1SBen Skeggs *
429b8bf04e1SBen Skeggs * NV04 doesn't have these methods implemented at all, and doesn't have the
430b8bf04e1SBen Skeggs * relevant bits in grobj. Instead, it'll allow rendering whenever bit 24
431b8bf04e1SBen Skeggs * is set. So we have to emulate them in software, internally keeping the
432b8bf04e1SBen Skeggs * same bits as NV05 does. Since grobjs are aligned to 16 bytes on nv04,
433b8bf04e1SBen Skeggs * but the last word isn't actually used for anything, we abuse it for this
434b8bf04e1SBen Skeggs * purpose.
435b8bf04e1SBen Skeggs *
436b8bf04e1SBen Skeggs * Actually, NV05 can optionally check bit 24 too, but we disable this since
437b8bf04e1SBen Skeggs * there's no use for it.
438b8bf04e1SBen Skeggs *
439b8bf04e1SBen Skeggs * For unknown reasons, NV04 implements surf3d binding in hardware as an
440b8bf04e1SBen Skeggs * exception. Also for unknown reasons, NV04 doesn't implement the clipping
441b8bf04e1SBen Skeggs * methods on the surf3d object, so we have to emulate them too.
442b8bf04e1SBen Skeggs */
443b8bf04e1SBen Skeggs
444b8bf04e1SBen Skeggs static void
nv04_gr_set_ctx1(struct nvkm_device * device,u32 inst,u32 mask,u32 value)445a65955e1SBen Skeggs nv04_gr_set_ctx1(struct nvkm_device *device, u32 inst, u32 mask, u32 value)
446b8bf04e1SBen Skeggs {
447276836d4SBen Skeggs int subc = (nvkm_rd32(device, NV04_PGRAPH_TRAPPED_ADDR) >> 13) & 0x7;
448b8bf04e1SBen Skeggs u32 tmp;
449b8bf04e1SBen Skeggs
450a65955e1SBen Skeggs tmp = nvkm_rd32(device, 0x700000 + inst);
451b8bf04e1SBen Skeggs tmp &= ~mask;
452b8bf04e1SBen Skeggs tmp |= value;
453a65955e1SBen Skeggs nvkm_wr32(device, 0x700000 + inst, tmp);
454b8bf04e1SBen Skeggs
455276836d4SBen Skeggs nvkm_wr32(device, NV04_PGRAPH_CTX_SWITCH1, tmp);
456276836d4SBen Skeggs nvkm_wr32(device, NV04_PGRAPH_CTX_CACHE1 + (subc << 2), tmp);
457b8bf04e1SBen Skeggs }
458b8bf04e1SBen Skeggs
459b8bf04e1SBen Skeggs static void
nv04_gr_set_ctx_val(struct nvkm_device * device,u32 inst,u32 mask,u32 value)460a65955e1SBen Skeggs nv04_gr_set_ctx_val(struct nvkm_device *device, u32 inst, u32 mask, u32 value)
461b8bf04e1SBen Skeggs {
462b8bf04e1SBen Skeggs int class, op, valid = 1;
463b8bf04e1SBen Skeggs u32 tmp, ctx1;
464b8bf04e1SBen Skeggs
465a65955e1SBen Skeggs ctx1 = nvkm_rd32(device, 0x700000 + inst);
466b8bf04e1SBen Skeggs class = ctx1 & 0xff;
467b8bf04e1SBen Skeggs op = (ctx1 >> 15) & 7;
468b8bf04e1SBen Skeggs
469a65955e1SBen Skeggs tmp = nvkm_rd32(device, 0x70000c + inst);
470b8bf04e1SBen Skeggs tmp &= ~mask;
471b8bf04e1SBen Skeggs tmp |= value;
472a65955e1SBen Skeggs nvkm_wr32(device, 0x70000c + inst, tmp);
473b8bf04e1SBen Skeggs
474b8bf04e1SBen Skeggs /* check for valid surf2d/surf_dst/surf_color */
475b8bf04e1SBen Skeggs if (!(tmp & 0x02000000))
476b8bf04e1SBen Skeggs valid = 0;
477b8bf04e1SBen Skeggs /* check for valid surf_src/surf_zeta */
478b8bf04e1SBen Skeggs if ((class == 0x1f || class == 0x48) && !(tmp & 0x04000000))
479b8bf04e1SBen Skeggs valid = 0;
480b8bf04e1SBen Skeggs
481b8bf04e1SBen Skeggs switch (op) {
482b8bf04e1SBen Skeggs /* SRCCOPY_AND, SRCCOPY: no extra objects required */
483b8bf04e1SBen Skeggs case 0:
484b8bf04e1SBen Skeggs case 3:
485b8bf04e1SBen Skeggs break;
486b8bf04e1SBen Skeggs /* ROP_AND: requires pattern and rop */
487b8bf04e1SBen Skeggs case 1:
488b8bf04e1SBen Skeggs if (!(tmp & 0x18000000))
489b8bf04e1SBen Skeggs valid = 0;
490b8bf04e1SBen Skeggs break;
491b8bf04e1SBen Skeggs /* BLEND_AND: requires beta1 */
492b8bf04e1SBen Skeggs case 2:
493b8bf04e1SBen Skeggs if (!(tmp & 0x20000000))
494b8bf04e1SBen Skeggs valid = 0;
495b8bf04e1SBen Skeggs break;
496b8bf04e1SBen Skeggs /* SRCCOPY_PREMULT, BLEND_PREMULT: beta4 required */
497b8bf04e1SBen Skeggs case 4:
498b8bf04e1SBen Skeggs case 5:
499b8bf04e1SBen Skeggs if (!(tmp & 0x40000000))
500b8bf04e1SBen Skeggs valid = 0;
501b8bf04e1SBen Skeggs break;
502b8bf04e1SBen Skeggs }
503b8bf04e1SBen Skeggs
504a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x01000000, valid << 24);
505b8bf04e1SBen Skeggs }
506b8bf04e1SBen Skeggs
507a65955e1SBen Skeggs static bool
nv04_gr_mthd_set_operation(struct nvkm_device * device,u32 inst,u32 data)508a65955e1SBen Skeggs nv04_gr_mthd_set_operation(struct nvkm_device *device, u32 inst, u32 data)
509b8bf04e1SBen Skeggs {
510a65955e1SBen Skeggs u8 class = nvkm_rd32(device, 0x700000) & 0x000000ff;
511b8bf04e1SBen Skeggs if (data > 5)
512a65955e1SBen Skeggs return false;
513b8bf04e1SBen Skeggs /* Old versions of the objects only accept first three operations. */
514b8bf04e1SBen Skeggs if (data > 2 && class < 0x40)
515a65955e1SBen Skeggs return false;
516a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x00038000, data << 15);
517b8bf04e1SBen Skeggs /* changing operation changes set of objects needed for validation */
518a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0, 0);
519a65955e1SBen Skeggs return true;
520b8bf04e1SBen Skeggs }
521b8bf04e1SBen Skeggs
522a65955e1SBen Skeggs static bool
nv04_gr_mthd_surf3d_clip_h(struct nvkm_device * device,u32 inst,u32 data)523a65955e1SBen Skeggs nv04_gr_mthd_surf3d_clip_h(struct nvkm_device *device, u32 inst, u32 data)
524b8bf04e1SBen Skeggs {
525b8bf04e1SBen Skeggs u32 min = data & 0xffff, max;
526b8bf04e1SBen Skeggs u32 w = data >> 16;
527b8bf04e1SBen Skeggs if (min & 0x8000)
528b8bf04e1SBen Skeggs /* too large */
529a65955e1SBen Skeggs return false;
530b8bf04e1SBen Skeggs if (w & 0x8000)
531b8bf04e1SBen Skeggs /* yes, it accepts negative for some reason. */
532b8bf04e1SBen Skeggs w |= 0xffff0000;
533b8bf04e1SBen Skeggs max = min + w;
534b8bf04e1SBen Skeggs max &= 0x3ffff;
535276836d4SBen Skeggs nvkm_wr32(device, 0x40053c, min);
536276836d4SBen Skeggs nvkm_wr32(device, 0x400544, max);
537a65955e1SBen Skeggs return true;
538b8bf04e1SBen Skeggs }
539b8bf04e1SBen Skeggs
540a65955e1SBen Skeggs static bool
nv04_gr_mthd_surf3d_clip_v(struct nvkm_device * device,u32 inst,u32 data)541a65955e1SBen Skeggs nv04_gr_mthd_surf3d_clip_v(struct nvkm_device *device, u32 inst, u32 data)
542b8bf04e1SBen Skeggs {
543b8bf04e1SBen Skeggs u32 min = data & 0xffff, max;
544b8bf04e1SBen Skeggs u32 w = data >> 16;
545b8bf04e1SBen Skeggs if (min & 0x8000)
546b8bf04e1SBen Skeggs /* too large */
547a65955e1SBen Skeggs return false;
548b8bf04e1SBen Skeggs if (w & 0x8000)
549b8bf04e1SBen Skeggs /* yes, it accepts negative for some reason. */
550b8bf04e1SBen Skeggs w |= 0xffff0000;
551b8bf04e1SBen Skeggs max = min + w;
552b8bf04e1SBen Skeggs max &= 0x3ffff;
553276836d4SBen Skeggs nvkm_wr32(device, 0x400540, min);
554276836d4SBen Skeggs nvkm_wr32(device, 0x400548, max);
555a65955e1SBen Skeggs return true;
556b8bf04e1SBen Skeggs }
557b8bf04e1SBen Skeggs
558a65955e1SBen Skeggs static u8
nv04_gr_mthd_bind_class(struct nvkm_device * device,u32 inst)559a65955e1SBen Skeggs nv04_gr_mthd_bind_class(struct nvkm_device *device, u32 inst)
560b8bf04e1SBen Skeggs {
561a65955e1SBen Skeggs return nvkm_rd32(device, 0x700000 + (inst << 4));
562b8bf04e1SBen Skeggs }
563b8bf04e1SBen Skeggs
564a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_surf2d(struct nvkm_device * device,u32 inst,u32 data)565a65955e1SBen Skeggs nv04_gr_mthd_bind_surf2d(struct nvkm_device *device, u32 inst, u32 data)
566b8bf04e1SBen Skeggs {
567a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
568b8bf04e1SBen Skeggs case 0x30:
569a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x00004000, 0);
570a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0);
571a65955e1SBen Skeggs return true;
572b8bf04e1SBen Skeggs case 0x42:
573a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x00004000, 0);
574a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0x02000000);
575a65955e1SBen Skeggs return true;
576b8bf04e1SBen Skeggs }
577a65955e1SBen Skeggs return false;
578b8bf04e1SBen Skeggs }
579b8bf04e1SBen Skeggs
580a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_surf2d_swzsurf(struct nvkm_device * device,u32 inst,u32 data)581a65955e1SBen Skeggs nv04_gr_mthd_bind_surf2d_swzsurf(struct nvkm_device *device, u32 inst, u32 data)
582b8bf04e1SBen Skeggs {
583a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
584b8bf04e1SBen Skeggs case 0x30:
585a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x00004000, 0);
586a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0);
587a65955e1SBen Skeggs return true;
588b8bf04e1SBen Skeggs case 0x42:
589a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x00004000, 0);
590a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0x02000000);
591a65955e1SBen Skeggs return true;
592b8bf04e1SBen Skeggs case 0x52:
593a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x00004000, 0x00004000);
594a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0x02000000);
595a65955e1SBen Skeggs return true;
596b8bf04e1SBen Skeggs }
597a65955e1SBen Skeggs return false;
598b8bf04e1SBen Skeggs }
599b8bf04e1SBen Skeggs
600a65955e1SBen Skeggs static bool
nv01_gr_mthd_bind_patt(struct nvkm_device * device,u32 inst,u32 data)601a65955e1SBen Skeggs nv01_gr_mthd_bind_patt(struct nvkm_device *device, u32 inst, u32 data)
602b8bf04e1SBen Skeggs {
603a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
604b8bf04e1SBen Skeggs case 0x30:
605a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x08000000, 0);
606a65955e1SBen Skeggs return true;
607b8bf04e1SBen Skeggs case 0x18:
608a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x08000000, 0x08000000);
609a65955e1SBen Skeggs return true;
610b8bf04e1SBen Skeggs }
611a65955e1SBen Skeggs return false;
612b8bf04e1SBen Skeggs }
613b8bf04e1SBen Skeggs
614a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_patt(struct nvkm_device * device,u32 inst,u32 data)615a65955e1SBen Skeggs nv04_gr_mthd_bind_patt(struct nvkm_device *device, u32 inst, u32 data)
616b8bf04e1SBen Skeggs {
617a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
618b8bf04e1SBen Skeggs case 0x30:
619a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x08000000, 0);
620a65955e1SBen Skeggs return true;
621b8bf04e1SBen Skeggs case 0x44:
622a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x08000000, 0x08000000);
623a65955e1SBen Skeggs return true;
624b8bf04e1SBen Skeggs }
625a65955e1SBen Skeggs return false;
626b8bf04e1SBen Skeggs }
627b8bf04e1SBen Skeggs
628a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_rop(struct nvkm_device * device,u32 inst,u32 data)629a65955e1SBen Skeggs nv04_gr_mthd_bind_rop(struct nvkm_device *device, u32 inst, u32 data)
630b8bf04e1SBen Skeggs {
631a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
632b8bf04e1SBen Skeggs case 0x30:
633a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x10000000, 0);
634a65955e1SBen Skeggs return true;
635b8bf04e1SBen Skeggs case 0x43:
636a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x10000000, 0x10000000);
637a65955e1SBen Skeggs return true;
638b8bf04e1SBen Skeggs }
639a65955e1SBen Skeggs return false;
640b8bf04e1SBen Skeggs }
641b8bf04e1SBen Skeggs
642a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_beta1(struct nvkm_device * device,u32 inst,u32 data)643a65955e1SBen Skeggs nv04_gr_mthd_bind_beta1(struct nvkm_device *device, u32 inst, u32 data)
644b8bf04e1SBen Skeggs {
645a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
646b8bf04e1SBen Skeggs case 0x30:
647a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x20000000, 0);
648a65955e1SBen Skeggs return true;
649b8bf04e1SBen Skeggs case 0x12:
650a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x20000000, 0x20000000);
651a65955e1SBen Skeggs return true;
652b8bf04e1SBen Skeggs }
653a65955e1SBen Skeggs return false;
654b8bf04e1SBen Skeggs }
655b8bf04e1SBen Skeggs
656a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_beta4(struct nvkm_device * device,u32 inst,u32 data)657a65955e1SBen Skeggs nv04_gr_mthd_bind_beta4(struct nvkm_device *device, u32 inst, u32 data)
658b8bf04e1SBen Skeggs {
659a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
660b8bf04e1SBen Skeggs case 0x30:
661a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x40000000, 0);
662a65955e1SBen Skeggs return true;
663b8bf04e1SBen Skeggs case 0x72:
664a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x40000000, 0x40000000);
665a65955e1SBen Skeggs return true;
666b8bf04e1SBen Skeggs }
667a65955e1SBen Skeggs return false;
668b8bf04e1SBen Skeggs }
669b8bf04e1SBen Skeggs
670a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_surf_dst(struct nvkm_device * device,u32 inst,u32 data)671a65955e1SBen Skeggs nv04_gr_mthd_bind_surf_dst(struct nvkm_device *device, u32 inst, u32 data)
672b8bf04e1SBen Skeggs {
673a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
674b8bf04e1SBen Skeggs case 0x30:
675a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0);
676a65955e1SBen Skeggs return true;
677b8bf04e1SBen Skeggs case 0x58:
678a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0x02000000);
679a65955e1SBen Skeggs return true;
680b8bf04e1SBen Skeggs }
681a65955e1SBen Skeggs return false;
682b8bf04e1SBen Skeggs }
683b8bf04e1SBen Skeggs
684a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_surf_src(struct nvkm_device * device,u32 inst,u32 data)685a65955e1SBen Skeggs nv04_gr_mthd_bind_surf_src(struct nvkm_device *device, u32 inst, u32 data)
686b8bf04e1SBen Skeggs {
687a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
688b8bf04e1SBen Skeggs case 0x30:
689a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x04000000, 0);
690a65955e1SBen Skeggs return true;
691b8bf04e1SBen Skeggs case 0x59:
692a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x04000000, 0x04000000);
693a65955e1SBen Skeggs return true;
694b8bf04e1SBen Skeggs }
695a65955e1SBen Skeggs return false;
696b8bf04e1SBen Skeggs }
697b8bf04e1SBen Skeggs
698a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_surf_color(struct nvkm_device * device,u32 inst,u32 data)699a65955e1SBen Skeggs nv04_gr_mthd_bind_surf_color(struct nvkm_device *device, u32 inst, u32 data)
700b8bf04e1SBen Skeggs {
701a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
702b8bf04e1SBen Skeggs case 0x30:
703a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0);
704a65955e1SBen Skeggs return true;
705b8bf04e1SBen Skeggs case 0x5a:
706a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x02000000, 0x02000000);
707a65955e1SBen Skeggs return true;
708b8bf04e1SBen Skeggs }
709a65955e1SBen Skeggs return false;
710b8bf04e1SBen Skeggs }
711b8bf04e1SBen Skeggs
712a65955e1SBen Skeggs static bool
nv04_gr_mthd_bind_surf_zeta(struct nvkm_device * device,u32 inst,u32 data)713a65955e1SBen Skeggs nv04_gr_mthd_bind_surf_zeta(struct nvkm_device *device, u32 inst, u32 data)
714b8bf04e1SBen Skeggs {
715a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
716b8bf04e1SBen Skeggs case 0x30:
717a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x04000000, 0);
718a65955e1SBen Skeggs return true;
719b8bf04e1SBen Skeggs case 0x5b:
720a65955e1SBen Skeggs nv04_gr_set_ctx_val(device, inst, 0x04000000, 0x04000000);
721a65955e1SBen Skeggs return true;
722b8bf04e1SBen Skeggs }
723a65955e1SBen Skeggs return false;
724b8bf04e1SBen Skeggs }
725b8bf04e1SBen Skeggs
726a65955e1SBen Skeggs static bool
nv01_gr_mthd_bind_clip(struct nvkm_device * device,u32 inst,u32 data)727a65955e1SBen Skeggs nv01_gr_mthd_bind_clip(struct nvkm_device *device, u32 inst, u32 data)
728b8bf04e1SBen Skeggs {
729a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
730b8bf04e1SBen Skeggs case 0x30:
731a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x2000, 0);
732a65955e1SBen Skeggs return true;
733b8bf04e1SBen Skeggs case 0x19:
734a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x2000, 0x2000);
735a65955e1SBen Skeggs return true;
736b8bf04e1SBen Skeggs }
737a65955e1SBen Skeggs return false;
738b8bf04e1SBen Skeggs }
739b8bf04e1SBen Skeggs
740a65955e1SBen Skeggs static bool
nv01_gr_mthd_bind_chroma(struct nvkm_device * device,u32 inst,u32 data)741a65955e1SBen Skeggs nv01_gr_mthd_bind_chroma(struct nvkm_device *device, u32 inst, u32 data)
742b8bf04e1SBen Skeggs {
743a65955e1SBen Skeggs switch (nv04_gr_mthd_bind_class(device, data)) {
744b8bf04e1SBen Skeggs case 0x30:
745a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x1000, 0);
746a65955e1SBen Skeggs return true;
747b8bf04e1SBen Skeggs /* Yes, for some reason even the old versions of objects
748b8bf04e1SBen Skeggs * accept 0x57 and not 0x17. Consistency be damned.
749b8bf04e1SBen Skeggs */
750b8bf04e1SBen Skeggs case 0x57:
751a65955e1SBen Skeggs nv04_gr_set_ctx1(device, inst, 0x1000, 0x1000);
752a65955e1SBen Skeggs return true;
753b8bf04e1SBen Skeggs }
754a65955e1SBen Skeggs return false;
755b8bf04e1SBen Skeggs }
756b8bf04e1SBen Skeggs
757a65955e1SBen Skeggs static bool
nv03_gr_mthd_gdi(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)758a65955e1SBen Skeggs nv03_gr_mthd_gdi(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
759a65955e1SBen Skeggs {
760a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
761a65955e1SBen Skeggs switch (mthd) {
762a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_patt; break;
763a65955e1SBen Skeggs case 0x0188: func = nv04_gr_mthd_bind_rop; break;
764a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_beta1; break;
765a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_surf_dst; break;
766a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
767a65955e1SBen Skeggs default:
768a65955e1SBen Skeggs return false;
769a65955e1SBen Skeggs }
770a65955e1SBen Skeggs return func(device, inst, data);
771a65955e1SBen Skeggs }
772b8bf04e1SBen Skeggs
773a65955e1SBen Skeggs static bool
nv04_gr_mthd_gdi(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)774a65955e1SBen Skeggs nv04_gr_mthd_gdi(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
775a65955e1SBen Skeggs {
776a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
777a65955e1SBen Skeggs switch (mthd) {
778a65955e1SBen Skeggs case 0x0188: func = nv04_gr_mthd_bind_patt; break;
779a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_rop; break;
780a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_beta1; break;
781a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta4; break;
782a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_surf2d; break;
783a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
784a65955e1SBen Skeggs default:
785a65955e1SBen Skeggs return false;
786a65955e1SBen Skeggs }
787a65955e1SBen Skeggs return func(device, inst, data);
788a65955e1SBen Skeggs }
789b8bf04e1SBen Skeggs
790a65955e1SBen Skeggs static bool
nv01_gr_mthd_blit(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)791a65955e1SBen Skeggs nv01_gr_mthd_blit(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
792a65955e1SBen Skeggs {
793a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
794a65955e1SBen Skeggs switch (mthd) {
795a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_chroma; break;
796a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_clip; break;
797a65955e1SBen Skeggs case 0x018c: func = nv01_gr_mthd_bind_patt; break;
798a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_rop; break;
799a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta1; break;
800a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_surf_dst; break;
801a65955e1SBen Skeggs case 0x019c: func = nv04_gr_mthd_bind_surf_src; break;
802a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
803a65955e1SBen Skeggs default:
804a65955e1SBen Skeggs return false;
805a65955e1SBen Skeggs }
806a65955e1SBen Skeggs return func(device, inst, data);
807a65955e1SBen Skeggs }
808b8bf04e1SBen Skeggs
809a65955e1SBen Skeggs static bool
nv04_gr_mthd_blit(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)810a65955e1SBen Skeggs nv04_gr_mthd_blit(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
811a65955e1SBen Skeggs {
812a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
813a65955e1SBen Skeggs switch (mthd) {
814a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_chroma; break;
815a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_clip; break;
816a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_patt; break;
817a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_rop; break;
818a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta1; break;
819a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_beta4; break;
820a65955e1SBen Skeggs case 0x019c: func = nv04_gr_mthd_bind_surf2d; break;
821a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
822a65955e1SBen Skeggs default:
823a65955e1SBen Skeggs return false;
824a65955e1SBen Skeggs }
825a65955e1SBen Skeggs return func(device, inst, data);
826a65955e1SBen Skeggs }
827b8bf04e1SBen Skeggs
828a65955e1SBen Skeggs static bool
nv04_gr_mthd_iifc(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)829a65955e1SBen Skeggs nv04_gr_mthd_iifc(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
830a65955e1SBen Skeggs {
831a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
832a65955e1SBen Skeggs switch (mthd) {
833a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_chroma; break;
834a65955e1SBen Skeggs case 0x018c: func = nv01_gr_mthd_bind_clip; break;
835a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_patt; break;
836a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_rop; break;
837a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_beta1; break;
838a65955e1SBen Skeggs case 0x019c: func = nv04_gr_mthd_bind_beta4; break;
839a65955e1SBen Skeggs case 0x01a0: func = nv04_gr_mthd_bind_surf2d_swzsurf; break;
840a65955e1SBen Skeggs case 0x03e4: func = nv04_gr_mthd_set_operation; break;
841a65955e1SBen Skeggs default:
842a65955e1SBen Skeggs return false;
843a65955e1SBen Skeggs }
844a65955e1SBen Skeggs return func(device, inst, data);
845a65955e1SBen Skeggs }
846b8bf04e1SBen Skeggs
847a65955e1SBen Skeggs static bool
nv01_gr_mthd_ifc(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)848a65955e1SBen Skeggs nv01_gr_mthd_ifc(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
849a65955e1SBen Skeggs {
850a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
851a65955e1SBen Skeggs switch (mthd) {
852a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_chroma; break;
853a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_clip; break;
854a65955e1SBen Skeggs case 0x018c: func = nv01_gr_mthd_bind_patt; break;
855a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_rop; break;
856a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta1; break;
857a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_surf_dst; break;
858a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
859a65955e1SBen Skeggs default:
860a65955e1SBen Skeggs return false;
861a65955e1SBen Skeggs }
862a65955e1SBen Skeggs return func(device, inst, data);
863a65955e1SBen Skeggs }
864b8bf04e1SBen Skeggs
865a65955e1SBen Skeggs static bool
nv04_gr_mthd_ifc(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)866a65955e1SBen Skeggs nv04_gr_mthd_ifc(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
867a65955e1SBen Skeggs {
868a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
869a65955e1SBen Skeggs switch (mthd) {
870a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_chroma; break;
871a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_clip; break;
872a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_patt; break;
873a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_rop; break;
874a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta1; break;
875a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_beta4; break;
876a65955e1SBen Skeggs case 0x019c: func = nv04_gr_mthd_bind_surf2d; break;
877a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
878a65955e1SBen Skeggs default:
879a65955e1SBen Skeggs return false;
880a65955e1SBen Skeggs }
881a65955e1SBen Skeggs return func(device, inst, data);
882a65955e1SBen Skeggs }
883b8bf04e1SBen Skeggs
884a65955e1SBen Skeggs static bool
nv03_gr_mthd_sifc(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)885a65955e1SBen Skeggs nv03_gr_mthd_sifc(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
886a65955e1SBen Skeggs {
887a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
888a65955e1SBen Skeggs switch (mthd) {
889a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_chroma; break;
890a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_patt; break;
891a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_rop; break;
892a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_beta1; break;
893a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_surf_dst; break;
894a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
895a65955e1SBen Skeggs default:
896a65955e1SBen Skeggs return false;
897a65955e1SBen Skeggs }
898a65955e1SBen Skeggs return func(device, inst, data);
899a65955e1SBen Skeggs }
900b8bf04e1SBen Skeggs
901a65955e1SBen Skeggs static bool
nv04_gr_mthd_sifc(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)902a65955e1SBen Skeggs nv04_gr_mthd_sifc(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
903a65955e1SBen Skeggs {
904a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
905a65955e1SBen Skeggs switch (mthd) {
906a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_chroma; break;
907a65955e1SBen Skeggs case 0x0188: func = nv04_gr_mthd_bind_patt; break;
908a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_rop; break;
909a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_beta1; break;
910a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta4; break;
911a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_surf2d; break;
912a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
913a65955e1SBen Skeggs default:
914a65955e1SBen Skeggs return false;
915a65955e1SBen Skeggs }
916a65955e1SBen Skeggs return func(device, inst, data);
917a65955e1SBen Skeggs }
918b8bf04e1SBen Skeggs
919a65955e1SBen Skeggs static bool
nv03_gr_mthd_sifm(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)920a65955e1SBen Skeggs nv03_gr_mthd_sifm(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
921a65955e1SBen Skeggs {
922a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
923a65955e1SBen Skeggs switch (mthd) {
924a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_patt; break;
925a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_rop; break;
926a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_beta1; break;
927a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_surf_dst; break;
928a65955e1SBen Skeggs case 0x0304: func = nv04_gr_mthd_set_operation; break;
929a65955e1SBen Skeggs default:
930a65955e1SBen Skeggs return false;
931a65955e1SBen Skeggs }
932a65955e1SBen Skeggs return func(device, inst, data);
933a65955e1SBen Skeggs }
934b8bf04e1SBen Skeggs
935a65955e1SBen Skeggs static bool
nv04_gr_mthd_sifm(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)936a65955e1SBen Skeggs nv04_gr_mthd_sifm(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
937a65955e1SBen Skeggs {
938a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
939a65955e1SBen Skeggs switch (mthd) {
940a65955e1SBen Skeggs case 0x0188: func = nv04_gr_mthd_bind_patt; break;
941a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_rop; break;
942a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_beta1; break;
943a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta4; break;
944a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_surf2d; break;
945a65955e1SBen Skeggs case 0x0304: func = nv04_gr_mthd_set_operation; break;
946a65955e1SBen Skeggs default:
947a65955e1SBen Skeggs return false;
948a65955e1SBen Skeggs }
949a65955e1SBen Skeggs return func(device, inst, data);
950a65955e1SBen Skeggs }
951b8bf04e1SBen Skeggs
952a65955e1SBen Skeggs static bool
nv04_gr_mthd_surf3d(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)953a65955e1SBen Skeggs nv04_gr_mthd_surf3d(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
954a65955e1SBen Skeggs {
955a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
956a65955e1SBen Skeggs switch (mthd) {
957a65955e1SBen Skeggs case 0x02f8: func = nv04_gr_mthd_surf3d_clip_h; break;
958a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_surf3d_clip_v; break;
959a65955e1SBen Skeggs default:
960a65955e1SBen Skeggs return false;
961a65955e1SBen Skeggs }
962a65955e1SBen Skeggs return func(device, inst, data);
963a65955e1SBen Skeggs }
964b8bf04e1SBen Skeggs
965a65955e1SBen Skeggs static bool
nv03_gr_mthd_ttri(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)966a65955e1SBen Skeggs nv03_gr_mthd_ttri(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
967a65955e1SBen Skeggs {
968a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
969a65955e1SBen Skeggs switch (mthd) {
970a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_clip; break;
971a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_surf_color; break;
972a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_surf_zeta; break;
973a65955e1SBen Skeggs default:
974a65955e1SBen Skeggs return false;
975a65955e1SBen Skeggs }
976a65955e1SBen Skeggs return func(device, inst, data);
977a65955e1SBen Skeggs }
978b8bf04e1SBen Skeggs
979a65955e1SBen Skeggs static bool
nv01_gr_mthd_prim(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)980a65955e1SBen Skeggs nv01_gr_mthd_prim(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
981a65955e1SBen Skeggs {
982a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
983a65955e1SBen Skeggs switch (mthd) {
984a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_clip; break;
985a65955e1SBen Skeggs case 0x0188: func = nv01_gr_mthd_bind_patt; break;
986a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_rop; break;
987a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_beta1; break;
988a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_surf_dst; break;
989a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
990a65955e1SBen Skeggs default:
991a65955e1SBen Skeggs return false;
992a65955e1SBen Skeggs }
993a65955e1SBen Skeggs return func(device, inst, data);
994a65955e1SBen Skeggs }
995b8bf04e1SBen Skeggs
996a65955e1SBen Skeggs static bool
nv04_gr_mthd_prim(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)997a65955e1SBen Skeggs nv04_gr_mthd_prim(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
998a65955e1SBen Skeggs {
999a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32);
1000a65955e1SBen Skeggs switch (mthd) {
1001a65955e1SBen Skeggs case 0x0184: func = nv01_gr_mthd_bind_clip; break;
1002a65955e1SBen Skeggs case 0x0188: func = nv04_gr_mthd_bind_patt; break;
1003a65955e1SBen Skeggs case 0x018c: func = nv04_gr_mthd_bind_rop; break;
1004a65955e1SBen Skeggs case 0x0190: func = nv04_gr_mthd_bind_beta1; break;
1005a65955e1SBen Skeggs case 0x0194: func = nv04_gr_mthd_bind_beta4; break;
1006a65955e1SBen Skeggs case 0x0198: func = nv04_gr_mthd_bind_surf2d; break;
1007a65955e1SBen Skeggs case 0x02fc: func = nv04_gr_mthd_set_operation; break;
1008a65955e1SBen Skeggs default:
1009a65955e1SBen Skeggs return false;
1010a65955e1SBen Skeggs }
1011a65955e1SBen Skeggs return func(device, inst, data);
1012a65955e1SBen Skeggs }
1013a65955e1SBen Skeggs
1014a65955e1SBen Skeggs static bool
nv04_gr_mthd(struct nvkm_device * device,u32 inst,u32 mthd,u32 data)1015a65955e1SBen Skeggs nv04_gr_mthd(struct nvkm_device *device, u32 inst, u32 mthd, u32 data)
1016a65955e1SBen Skeggs {
1017a65955e1SBen Skeggs bool (*func)(struct nvkm_device *, u32, u32, u32);
1018a65955e1SBen Skeggs switch (nvkm_rd32(device, 0x700000 + inst) & 0x000000ff) {
1019a65955e1SBen Skeggs case 0x1c ... 0x1e:
1020a65955e1SBen Skeggs func = nv01_gr_mthd_prim; break;
1021a65955e1SBen Skeggs case 0x1f: func = nv01_gr_mthd_blit; break;
1022a65955e1SBen Skeggs case 0x21: func = nv01_gr_mthd_ifc; break;
1023a65955e1SBen Skeggs case 0x36: func = nv03_gr_mthd_sifc; break;
1024a65955e1SBen Skeggs case 0x37: func = nv03_gr_mthd_sifm; break;
1025a65955e1SBen Skeggs case 0x48: func = nv03_gr_mthd_ttri; break;
1026a65955e1SBen Skeggs case 0x4a: func = nv04_gr_mthd_gdi; break;
1027a65955e1SBen Skeggs case 0x4b: func = nv03_gr_mthd_gdi; break;
1028a65955e1SBen Skeggs case 0x53: func = nv04_gr_mthd_surf3d; break;
1029a65955e1SBen Skeggs case 0x5c ... 0x5e:
1030a65955e1SBen Skeggs func = nv04_gr_mthd_prim; break;
1031a65955e1SBen Skeggs case 0x5f: func = nv04_gr_mthd_blit; break;
1032a65955e1SBen Skeggs case 0x60: func = nv04_gr_mthd_iifc; break;
1033a65955e1SBen Skeggs case 0x61: func = nv04_gr_mthd_ifc; break;
1034a65955e1SBen Skeggs case 0x76: func = nv04_gr_mthd_sifc; break;
1035a65955e1SBen Skeggs case 0x77: func = nv04_gr_mthd_sifm; break;
1036a65955e1SBen Skeggs default:
1037a65955e1SBen Skeggs return false;
1038a65955e1SBen Skeggs }
1039a65955e1SBen Skeggs return func(device, inst, mthd, data);
1040a65955e1SBen Skeggs }
1041b8bf04e1SBen Skeggs
1042b8bf04e1SBen Skeggs static int
nv04_gr_object_bind(struct nvkm_object * object,struct nvkm_gpuobj * parent,int align,struct nvkm_gpuobj ** pgpuobj)104327f3d6cfSBen Skeggs nv04_gr_object_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
104427f3d6cfSBen Skeggs int align, struct nvkm_gpuobj **pgpuobj)
1045b8bf04e1SBen Skeggs {
104627f3d6cfSBen Skeggs int ret = nvkm_gpuobj_new(object->engine->subdev.device, 16, align,
104727f3d6cfSBen Skeggs false, parent, pgpuobj);
104827f3d6cfSBen Skeggs if (ret == 0) {
104927f3d6cfSBen Skeggs nvkm_kmap(*pgpuobj);
105068f3f702SBen Skeggs nvkm_wo32(*pgpuobj, 0x00, object->oclass);
105115ee0058SIlia Mirkin #ifdef __BIG_ENDIAN
105215ee0058SIlia Mirkin nvkm_mo32(*pgpuobj, 0x00, 0x00080000, 0x00080000);
105315ee0058SIlia Mirkin #endif
105427f3d6cfSBen Skeggs nvkm_wo32(*pgpuobj, 0x04, 0x00000000);
105527f3d6cfSBen Skeggs nvkm_wo32(*pgpuobj, 0x08, 0x00000000);
105627f3d6cfSBen Skeggs nvkm_wo32(*pgpuobj, 0x0c, 0x00000000);
105727f3d6cfSBen Skeggs nvkm_done(*pgpuobj);
105827f3d6cfSBen Skeggs }
105927f3d6cfSBen Skeggs return ret;
1060b8bf04e1SBen Skeggs }
1061b8bf04e1SBen Skeggs
106227f3d6cfSBen Skeggs const struct nvkm_object_func
106327f3d6cfSBen Skeggs nv04_gr_object = {
106427f3d6cfSBen Skeggs .bind = nv04_gr_object_bind,
1065b8bf04e1SBen Skeggs };
1066b8bf04e1SBen Skeggs
1067b8bf04e1SBen Skeggs /*******************************************************************************
1068b8bf04e1SBen Skeggs * PGRAPH context
1069b8bf04e1SBen Skeggs ******************************************************************************/
1070b8bf04e1SBen Skeggs
1071b8bf04e1SBen Skeggs static struct nv04_gr_chan *
nv04_gr_channel(struct nv04_gr * gr)1072bfee3f3dSBen Skeggs nv04_gr_channel(struct nv04_gr *gr)
1073b8bf04e1SBen Skeggs {
1074276836d4SBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
1075b8bf04e1SBen Skeggs struct nv04_gr_chan *chan = NULL;
1076276836d4SBen Skeggs if (nvkm_rd32(device, NV04_PGRAPH_CTX_CONTROL) & 0x00010000) {
1077276836d4SBen Skeggs int chid = nvkm_rd32(device, NV04_PGRAPH_CTX_USER) >> 24;
1078bfee3f3dSBen Skeggs if (chid < ARRAY_SIZE(gr->chan))
1079bfee3f3dSBen Skeggs chan = gr->chan[chid];
1080b8bf04e1SBen Skeggs }
1081b8bf04e1SBen Skeggs return chan;
1082b8bf04e1SBen Skeggs }
1083b8bf04e1SBen Skeggs
1084b8bf04e1SBen Skeggs static int
nv04_gr_load_context(struct nv04_gr_chan * chan,int chid)1085b8bf04e1SBen Skeggs nv04_gr_load_context(struct nv04_gr_chan *chan, int chid)
1086b8bf04e1SBen Skeggs {
108727f3d6cfSBen Skeggs struct nvkm_device *device = chan->gr->base.engine.subdev.device;
1088b8bf04e1SBen Skeggs int i;
1089b8bf04e1SBen Skeggs
1090b8bf04e1SBen Skeggs for (i = 0; i < ARRAY_SIZE(nv04_gr_ctx_regs); i++)
1091276836d4SBen Skeggs nvkm_wr32(device, nv04_gr_ctx_regs[i], chan->nv04[i]);
1092b8bf04e1SBen Skeggs
1093276836d4SBen Skeggs nvkm_wr32(device, NV04_PGRAPH_CTX_CONTROL, 0x10010100);
1094276836d4SBen Skeggs nvkm_mask(device, NV04_PGRAPH_CTX_USER, 0xff000000, chid << 24);
1095276836d4SBen Skeggs nvkm_mask(device, NV04_PGRAPH_FFINTFC_ST2, 0xfff00000, 0x00000000);
1096b8bf04e1SBen Skeggs return 0;
1097b8bf04e1SBen Skeggs }
1098b8bf04e1SBen Skeggs
1099b8bf04e1SBen Skeggs static int
nv04_gr_unload_context(struct nv04_gr_chan * chan)1100b8bf04e1SBen Skeggs nv04_gr_unload_context(struct nv04_gr_chan *chan)
1101b8bf04e1SBen Skeggs {
110227f3d6cfSBen Skeggs struct nvkm_device *device = chan->gr->base.engine.subdev.device;
1103b8bf04e1SBen Skeggs int i;
1104b8bf04e1SBen Skeggs
1105b8bf04e1SBen Skeggs for (i = 0; i < ARRAY_SIZE(nv04_gr_ctx_regs); i++)
1106276836d4SBen Skeggs chan->nv04[i] = nvkm_rd32(device, nv04_gr_ctx_regs[i]);
1107b8bf04e1SBen Skeggs
1108276836d4SBen Skeggs nvkm_wr32(device, NV04_PGRAPH_CTX_CONTROL, 0x10000000);
1109276836d4SBen Skeggs nvkm_mask(device, NV04_PGRAPH_CTX_USER, 0xff000000, 0x0f000000);
1110b8bf04e1SBen Skeggs return 0;
1111b8bf04e1SBen Skeggs }
1112b8bf04e1SBen Skeggs
1113b8bf04e1SBen Skeggs static void
nv04_gr_context_switch(struct nv04_gr * gr)1114bfee3f3dSBen Skeggs nv04_gr_context_switch(struct nv04_gr *gr)
1115b8bf04e1SBen Skeggs {
1116276836d4SBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
1117b8bf04e1SBen Skeggs struct nv04_gr_chan *prev = NULL;
1118b8bf04e1SBen Skeggs struct nv04_gr_chan *next = NULL;
1119b8bf04e1SBen Skeggs int chid;
1120b8bf04e1SBen Skeggs
112127f3d6cfSBen Skeggs nv04_gr_idle(&gr->base);
1122b8bf04e1SBen Skeggs
1123b8bf04e1SBen Skeggs /* If previous context is valid, we need to save it */
1124bfee3f3dSBen Skeggs prev = nv04_gr_channel(gr);
1125b8bf04e1SBen Skeggs if (prev)
1126b8bf04e1SBen Skeggs nv04_gr_unload_context(prev);
1127b8bf04e1SBen Skeggs
1128b8bf04e1SBen Skeggs /* load context for next channel */
1129276836d4SBen Skeggs chid = (nvkm_rd32(device, NV04_PGRAPH_TRAPPED_ADDR) >> 24) & 0x0f;
1130bfee3f3dSBen Skeggs next = gr->chan[chid];
1131b8bf04e1SBen Skeggs if (next)
1132b8bf04e1SBen Skeggs nv04_gr_load_context(next, chid);
1133b8bf04e1SBen Skeggs }
1134b8bf04e1SBen Skeggs
ctx_reg(struct nv04_gr_chan * chan,u32 reg)1135b8bf04e1SBen Skeggs static u32 *ctx_reg(struct nv04_gr_chan *chan, u32 reg)
1136b8bf04e1SBen Skeggs {
1137b8bf04e1SBen Skeggs int i;
1138b8bf04e1SBen Skeggs
1139b8bf04e1SBen Skeggs for (i = 0; i < ARRAY_SIZE(nv04_gr_ctx_regs); i++) {
1140b8bf04e1SBen Skeggs if (nv04_gr_ctx_regs[i] == reg)
1141b8bf04e1SBen Skeggs return &chan->nv04[i];
1142b8bf04e1SBen Skeggs }
1143b8bf04e1SBen Skeggs
1144b8bf04e1SBen Skeggs return NULL;
1145b8bf04e1SBen Skeggs }
1146b8bf04e1SBen Skeggs
114727f3d6cfSBen Skeggs static void *
nv04_gr_chan_dtor(struct nvkm_object * object)114827f3d6cfSBen Skeggs nv04_gr_chan_dtor(struct nvkm_object *object)
1149b8bf04e1SBen Skeggs {
115027f3d6cfSBen Skeggs struct nv04_gr_chan *chan = nv04_gr_chan(object);
115127f3d6cfSBen Skeggs struct nv04_gr *gr = chan->gr;
1152b8bf04e1SBen Skeggs unsigned long flags;
1153b8bf04e1SBen Skeggs
1154bfee3f3dSBen Skeggs spin_lock_irqsave(&gr->lock, flags);
1155bfee3f3dSBen Skeggs gr->chan[chan->chid] = NULL;
1156bfee3f3dSBen Skeggs spin_unlock_irqrestore(&gr->lock, flags);
115727f3d6cfSBen Skeggs return chan;
1158b8bf04e1SBen Skeggs }
1159b8bf04e1SBen Skeggs
1160b8bf04e1SBen Skeggs static int
nv04_gr_chan_fini(struct nvkm_object * object,bool suspend)116127f3d6cfSBen Skeggs nv04_gr_chan_fini(struct nvkm_object *object, bool suspend)
1162b8bf04e1SBen Skeggs {
116327f3d6cfSBen Skeggs struct nv04_gr_chan *chan = nv04_gr_chan(object);
116427f3d6cfSBen Skeggs struct nv04_gr *gr = chan->gr;
1165276836d4SBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
1166b8bf04e1SBen Skeggs unsigned long flags;
1167b8bf04e1SBen Skeggs
1168bfee3f3dSBen Skeggs spin_lock_irqsave(&gr->lock, flags);
1169276836d4SBen Skeggs nvkm_mask(device, NV04_PGRAPH_FIFO, 0x00000001, 0x00000000);
1170bfee3f3dSBen Skeggs if (nv04_gr_channel(gr) == chan)
1171b8bf04e1SBen Skeggs nv04_gr_unload_context(chan);
1172276836d4SBen Skeggs nvkm_mask(device, NV04_PGRAPH_FIFO, 0x00000001, 0x00000001);
1173bfee3f3dSBen Skeggs spin_unlock_irqrestore(&gr->lock, flags);
117427f3d6cfSBen Skeggs return 0;
1175b8bf04e1SBen Skeggs }
1176b8bf04e1SBen Skeggs
117727f3d6cfSBen Skeggs static const struct nvkm_object_func
117827f3d6cfSBen Skeggs nv04_gr_chan = {
117927f3d6cfSBen Skeggs .dtor = nv04_gr_chan_dtor,
118027f3d6cfSBen Skeggs .fini = nv04_gr_chan_fini,
1181b8bf04e1SBen Skeggs };
1182b8bf04e1SBen Skeggs
118327f3d6cfSBen Skeggs static int
nv04_gr_chan_new(struct nvkm_gr * base,struct nvkm_chan * fifoch,const struct nvkm_oclass * oclass,struct nvkm_object ** pobject)1184*c546656fSBen Skeggs nv04_gr_chan_new(struct nvkm_gr *base, struct nvkm_chan *fifoch,
118527f3d6cfSBen Skeggs const struct nvkm_oclass *oclass, struct nvkm_object **pobject)
118627f3d6cfSBen Skeggs {
118727f3d6cfSBen Skeggs struct nv04_gr *gr = nv04_gr(base);
118827f3d6cfSBen Skeggs struct nv04_gr_chan *chan;
118927f3d6cfSBen Skeggs unsigned long flags;
119027f3d6cfSBen Skeggs
119127f3d6cfSBen Skeggs if (!(chan = kzalloc(sizeof(*chan), GFP_KERNEL)))
119227f3d6cfSBen Skeggs return -ENOMEM;
119327f3d6cfSBen Skeggs nvkm_object_ctor(&nv04_gr_chan, oclass, &chan->object);
119427f3d6cfSBen Skeggs chan->gr = gr;
1195c358f538SBen Skeggs chan->chid = fifoch->id;
119627f3d6cfSBen Skeggs *pobject = &chan->object;
119727f3d6cfSBen Skeggs
119827f3d6cfSBen Skeggs *ctx_reg(chan, NV04_PGRAPH_DEBUG_3) = 0xfad4ff31;
119927f3d6cfSBen Skeggs
120027f3d6cfSBen Skeggs spin_lock_irqsave(&gr->lock, flags);
120127f3d6cfSBen Skeggs gr->chan[chan->chid] = chan;
120227f3d6cfSBen Skeggs spin_unlock_irqrestore(&gr->lock, flags);
120327f3d6cfSBen Skeggs return 0;
120427f3d6cfSBen Skeggs }
120527f3d6cfSBen Skeggs
1206b8bf04e1SBen Skeggs /*******************************************************************************
1207b8bf04e1SBen Skeggs * PGRAPH engine/subdev functions
1208b8bf04e1SBen Skeggs ******************************************************************************/
1209b8bf04e1SBen Skeggs
1210b8bf04e1SBen Skeggs bool
nv04_gr_idle(struct nvkm_gr * gr)121127f3d6cfSBen Skeggs nv04_gr_idle(struct nvkm_gr *gr)
1212b8bf04e1SBen Skeggs {
1213109c2f2fSBen Skeggs struct nvkm_subdev *subdev = &gr->engine.subdev;
1214109c2f2fSBen Skeggs struct nvkm_device *device = subdev->device;
1215b8bf04e1SBen Skeggs u32 mask = 0xffffffff;
1216b8bf04e1SBen Skeggs
121727f3d6cfSBen Skeggs if (device->card_type == NV_40)
1218b8bf04e1SBen Skeggs mask &= ~NV40_PGRAPH_STATUS_SYNC_STALL;
1219b8bf04e1SBen Skeggs
1220c4584adcSBen Skeggs if (nvkm_msec(device, 2000,
1221c4584adcSBen Skeggs if (!(nvkm_rd32(device, NV04_PGRAPH_STATUS) & mask))
1222c4584adcSBen Skeggs break;
1223c4584adcSBen Skeggs ) < 0) {
1224109c2f2fSBen Skeggs nvkm_error(subdev, "idle timed out with status %08x\n",
1225276836d4SBen Skeggs nvkm_rd32(device, NV04_PGRAPH_STATUS));
1226b8bf04e1SBen Skeggs return false;
1227b8bf04e1SBen Skeggs }
1228b8bf04e1SBen Skeggs
1229b8bf04e1SBen Skeggs return true;
1230b8bf04e1SBen Skeggs }
1231b8bf04e1SBen Skeggs
1232e3c71eb2SBen Skeggs static const struct nvkm_bitfield
1233b8bf04e1SBen Skeggs nv04_gr_intr_name[] = {
1234b8bf04e1SBen Skeggs { NV_PGRAPH_INTR_NOTIFY, "NOTIFY" },
1235b8bf04e1SBen Skeggs {}
1236b8bf04e1SBen Skeggs };
1237b8bf04e1SBen Skeggs
1238e3c71eb2SBen Skeggs static const struct nvkm_bitfield
1239b8bf04e1SBen Skeggs nv04_gr_nstatus[] = {
1240b8bf04e1SBen Skeggs { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
1241b8bf04e1SBen Skeggs { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
1242b8bf04e1SBen Skeggs { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
1243b8bf04e1SBen Skeggs { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" },
1244b8bf04e1SBen Skeggs {}
1245b8bf04e1SBen Skeggs };
1246b8bf04e1SBen Skeggs
1247e3c71eb2SBen Skeggs const struct nvkm_bitfield
1248b8bf04e1SBen Skeggs nv04_gr_nsource[] = {
1249b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" },
1250b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" },
1251b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_PROTECTION_ERROR, "PROTECTION_ERROR" },
1252b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_RANGE_EXCEPTION, "RANGE_EXCEPTION" },
1253b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_LIMIT_COLOR, "LIMIT_COLOR" },
1254b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_LIMIT_ZETA, "LIMIT_ZETA" },
1255b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD, "ILLEGAL_MTHD" },
1256b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_DMA_R_PROTECTION, "DMA_R_PROTECTION" },
1257b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_DMA_W_PROTECTION, "DMA_W_PROTECTION" },
1258b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_FORMAT_EXCEPTION, "FORMAT_EXCEPTION" },
1259b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_PATCH_EXCEPTION, "PATCH_EXCEPTION" },
1260b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_STATE_INVALID, "STATE_INVALID" },
1261b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_DOUBLE_NOTIFY, "DOUBLE_NOTIFY" },
1262b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_NOTIFY_IN_USE, "NOTIFY_IN_USE" },
1263b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_METHOD_CNT, "METHOD_CNT" },
1264b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_BFR_NOTIFICATION, "BFR_NOTIFICATION" },
1265b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" },
1266b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" },
1267b8bf04e1SBen Skeggs { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" },
1268b8bf04e1SBen Skeggs {}
1269b8bf04e1SBen Skeggs };
1270b8bf04e1SBen Skeggs
1271b8bf04e1SBen Skeggs static void
nv04_gr_intr(struct nvkm_gr * base)1272c85ee6caSBen Skeggs nv04_gr_intr(struct nvkm_gr *base)
1273b8bf04e1SBen Skeggs {
1274c85ee6caSBen Skeggs struct nv04_gr *gr = nv04_gr(base);
1275c85ee6caSBen Skeggs struct nvkm_subdev *subdev = &gr->base.engine.subdev;
1276c85ee6caSBen Skeggs struct nvkm_device *device = subdev->device;
1277276836d4SBen Skeggs u32 stat = nvkm_rd32(device, NV03_PGRAPH_INTR);
1278276836d4SBen Skeggs u32 nsource = nvkm_rd32(device, NV03_PGRAPH_NSOURCE);
1279276836d4SBen Skeggs u32 nstatus = nvkm_rd32(device, NV03_PGRAPH_NSTATUS);
1280276836d4SBen Skeggs u32 addr = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_ADDR);
1281b8bf04e1SBen Skeggs u32 chid = (addr & 0x0f000000) >> 24;
1282b8bf04e1SBen Skeggs u32 subc = (addr & 0x0000e000) >> 13;
1283b8bf04e1SBen Skeggs u32 mthd = (addr & 0x00001ffc);
1284276836d4SBen Skeggs u32 data = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_DATA);
1285276836d4SBen Skeggs u32 class = nvkm_rd32(device, 0x400180 + subc * 4) & 0xff;
1286276836d4SBen Skeggs u32 inst = (nvkm_rd32(device, 0x40016c) & 0xffff) << 4;
1287b8bf04e1SBen Skeggs u32 show = stat;
1288109c2f2fSBen Skeggs char msg[128], src[128], sta[128];
1289c85ee6caSBen Skeggs struct nv04_gr_chan *chan;
1290b8bf04e1SBen Skeggs unsigned long flags;
1291b8bf04e1SBen Skeggs
1292bfee3f3dSBen Skeggs spin_lock_irqsave(&gr->lock, flags);
1293bfee3f3dSBen Skeggs chan = gr->chan[chid];
1294b8bf04e1SBen Skeggs
1295b8bf04e1SBen Skeggs if (stat & NV_PGRAPH_INTR_NOTIFY) {
1296b8bf04e1SBen Skeggs if (chan && (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD)) {
1297a65955e1SBen Skeggs if (!nv04_gr_mthd(device, inst, mthd, data))
1298b8bf04e1SBen Skeggs show &= ~NV_PGRAPH_INTR_NOTIFY;
1299b8bf04e1SBen Skeggs }
1300b8bf04e1SBen Skeggs }
1301b8bf04e1SBen Skeggs
1302b8bf04e1SBen Skeggs if (stat & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
1303276836d4SBen Skeggs nvkm_wr32(device, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_CONTEXT_SWITCH);
1304b8bf04e1SBen Skeggs stat &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
1305b8bf04e1SBen Skeggs show &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
1306bfee3f3dSBen Skeggs nv04_gr_context_switch(gr);
1307b8bf04e1SBen Skeggs }
1308b8bf04e1SBen Skeggs
1309276836d4SBen Skeggs nvkm_wr32(device, NV03_PGRAPH_INTR, stat);
1310276836d4SBen Skeggs nvkm_wr32(device, NV04_PGRAPH_FIFO, 0x00000001);
1311b8bf04e1SBen Skeggs
1312b8bf04e1SBen Skeggs if (show) {
1313109c2f2fSBen Skeggs nvkm_snprintbf(msg, sizeof(msg), nv04_gr_intr_name, show);
1314109c2f2fSBen Skeggs nvkm_snprintbf(src, sizeof(src), nv04_gr_nsource, nsource);
1315109c2f2fSBen Skeggs nvkm_snprintbf(sta, sizeof(sta), nv04_gr_nstatus, nstatus);
1316109c2f2fSBen Skeggs nvkm_error(subdev, "intr %08x [%s] nsource %08x [%s] "
1317109c2f2fSBen Skeggs "nstatus %08x [%s] ch %d [%s] subc %d "
1318109c2f2fSBen Skeggs "class %04x mthd %04x data %08x\n",
1319109c2f2fSBen Skeggs show, msg, nsource, src, nstatus, sta, chid,
132027f3d6cfSBen Skeggs chan ? chan->object.client->name : "unknown",
132127f3d6cfSBen Skeggs subc, class, mthd, data);
1322b8bf04e1SBen Skeggs }
1323b8bf04e1SBen Skeggs
1324a65955e1SBen Skeggs spin_unlock_irqrestore(&gr->lock, flags);
1325b8bf04e1SBen Skeggs }
1326b8bf04e1SBen Skeggs
1327c85ee6caSBen Skeggs static int
nv04_gr_init(struct nvkm_gr * base)1328c85ee6caSBen Skeggs nv04_gr_init(struct nvkm_gr *base)
1329c85ee6caSBen Skeggs {
1330c85ee6caSBen Skeggs struct nv04_gr *gr = nv04_gr(base);
1331c85ee6caSBen Skeggs struct nvkm_device *device = gr->base.engine.subdev.device;
1332c85ee6caSBen Skeggs
1333c85ee6caSBen Skeggs /* Enable PGRAPH interrupts */
1334c85ee6caSBen Skeggs nvkm_wr32(device, NV03_PGRAPH_INTR, 0xFFFFFFFF);
1335c85ee6caSBen Skeggs nvkm_wr32(device, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
1336c85ee6caSBen Skeggs
1337c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_VALID1, 0);
1338c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_VALID2, 0);
1339c85ee6caSBen Skeggs /*nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0x000001FF);
1340c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0x001FFFFF);*/
1341c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0x1231c000);
1342c85ee6caSBen Skeggs /*1231C000 blob, 001 haiku*/
1343c85ee6caSBen Skeggs /*V_WRITE(NV04_PGRAPH_DEBUG_1, 0xf2d91100);*/
1344c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_DEBUG_1, 0x72111100);
1345c85ee6caSBen Skeggs /*0x72111100 blob , 01 haiku*/
1346c85ee6caSBen Skeggs /*nvkm_wr32(device, NV04_PGRAPH_DEBUG_2, 0x11d5f870);*/
1347c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_DEBUG_2, 0x11d5f071);
1348c85ee6caSBen Skeggs /*haiku same*/
1349c85ee6caSBen Skeggs
1350c85ee6caSBen Skeggs /*nvkm_wr32(device, NV04_PGRAPH_DEBUG_3, 0xfad4ff31);*/
1351c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_DEBUG_3, 0xf0d4ff31);
1352c85ee6caSBen Skeggs /*haiku and blob 10d4*/
1353c85ee6caSBen Skeggs
1354c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_STATE , 0xFFFFFFFF);
1355c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_CTX_CONTROL , 0x10000100);
1356c85ee6caSBen Skeggs nvkm_mask(device, NV04_PGRAPH_CTX_USER, 0xff000000, 0x0f000000);
1357c85ee6caSBen Skeggs
1358c85ee6caSBen Skeggs /* These don't belong here, they're part of a per-channel context */
1359c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_PATTERN_SHAPE, 0x00000000);
1360c85ee6caSBen Skeggs nvkm_wr32(device, NV04_PGRAPH_BETA_AND , 0xFFFFFFFF);
1361c85ee6caSBen Skeggs return 0;
1362c85ee6caSBen Skeggs }
1363c85ee6caSBen Skeggs
136427f3d6cfSBen Skeggs static const struct nvkm_gr_func
136527f3d6cfSBen Skeggs nv04_gr = {
1366c85ee6caSBen Skeggs .init = nv04_gr_init,
1367c85ee6caSBen Skeggs .intr = nv04_gr_intr,
136827f3d6cfSBen Skeggs .chan_new = nv04_gr_chan_new,
136927f3d6cfSBen Skeggs .sclass = {
137027f3d6cfSBen Skeggs { -1, -1, 0x0012, &nv04_gr_object }, /* beta1 */
137127f3d6cfSBen Skeggs { -1, -1, 0x0017, &nv04_gr_object }, /* chroma */
137227f3d6cfSBen Skeggs { -1, -1, 0x0018, &nv04_gr_object }, /* pattern (nv01) */
137327f3d6cfSBen Skeggs { -1, -1, 0x0019, &nv04_gr_object }, /* clip */
137427f3d6cfSBen Skeggs { -1, -1, 0x001c, &nv04_gr_object }, /* line */
137527f3d6cfSBen Skeggs { -1, -1, 0x001d, &nv04_gr_object }, /* tri */
137627f3d6cfSBen Skeggs { -1, -1, 0x001e, &nv04_gr_object }, /* rect */
137727f3d6cfSBen Skeggs { -1, -1, 0x001f, &nv04_gr_object },
137827f3d6cfSBen Skeggs { -1, -1, 0x0021, &nv04_gr_object },
137927f3d6cfSBen Skeggs { -1, -1, 0x0030, &nv04_gr_object }, /* null */
138027f3d6cfSBen Skeggs { -1, -1, 0x0036, &nv04_gr_object },
138127f3d6cfSBen Skeggs { -1, -1, 0x0037, &nv04_gr_object },
138227f3d6cfSBen Skeggs { -1, -1, 0x0038, &nv04_gr_object }, /* dvd subpicture */
138327f3d6cfSBen Skeggs { -1, -1, 0x0039, &nv04_gr_object }, /* m2mf */
138427f3d6cfSBen Skeggs { -1, -1, 0x0042, &nv04_gr_object }, /* surf2d */
138527f3d6cfSBen Skeggs { -1, -1, 0x0043, &nv04_gr_object }, /* rop */
138627f3d6cfSBen Skeggs { -1, -1, 0x0044, &nv04_gr_object }, /* pattern */
138727f3d6cfSBen Skeggs { -1, -1, 0x0048, &nv04_gr_object },
138827f3d6cfSBen Skeggs { -1, -1, 0x004a, &nv04_gr_object },
138927f3d6cfSBen Skeggs { -1, -1, 0x004b, &nv04_gr_object },
139027f3d6cfSBen Skeggs { -1, -1, 0x0052, &nv04_gr_object }, /* swzsurf */
139127f3d6cfSBen Skeggs { -1, -1, 0x0053, &nv04_gr_object },
139227f3d6cfSBen Skeggs { -1, -1, 0x0054, &nv04_gr_object }, /* ttri */
139327f3d6cfSBen Skeggs { -1, -1, 0x0055, &nv04_gr_object }, /* mtri */
139427f3d6cfSBen Skeggs { -1, -1, 0x0057, &nv04_gr_object }, /* chroma */
139527f3d6cfSBen Skeggs { -1, -1, 0x0058, &nv04_gr_object }, /* surf_dst */
139627f3d6cfSBen Skeggs { -1, -1, 0x0059, &nv04_gr_object }, /* surf_src */
139727f3d6cfSBen Skeggs { -1, -1, 0x005a, &nv04_gr_object }, /* surf_color */
139827f3d6cfSBen Skeggs { -1, -1, 0x005b, &nv04_gr_object }, /* surf_zeta */
139927f3d6cfSBen Skeggs { -1, -1, 0x005c, &nv04_gr_object }, /* line */
140027f3d6cfSBen Skeggs { -1, -1, 0x005d, &nv04_gr_object }, /* tri */
140127f3d6cfSBen Skeggs { -1, -1, 0x005e, &nv04_gr_object }, /* rect */
140227f3d6cfSBen Skeggs { -1, -1, 0x005f, &nv04_gr_object },
140327f3d6cfSBen Skeggs { -1, -1, 0x0060, &nv04_gr_object },
140427f3d6cfSBen Skeggs { -1, -1, 0x0061, &nv04_gr_object },
140527f3d6cfSBen Skeggs { -1, -1, 0x0064, &nv04_gr_object }, /* iifc (nv05) */
140627f3d6cfSBen Skeggs { -1, -1, 0x0065, &nv04_gr_object }, /* ifc (nv05) */
140727f3d6cfSBen Skeggs { -1, -1, 0x0066, &nv04_gr_object }, /* sifc (nv05) */
140827f3d6cfSBen Skeggs { -1, -1, 0x0072, &nv04_gr_object }, /* beta4 */
140927f3d6cfSBen Skeggs { -1, -1, 0x0076, &nv04_gr_object },
141027f3d6cfSBen Skeggs { -1, -1, 0x0077, &nv04_gr_object },
141127f3d6cfSBen Skeggs {}
141227f3d6cfSBen Skeggs }
141327f3d6cfSBen Skeggs };
141427f3d6cfSBen Skeggs
1415c85ee6caSBen Skeggs int
nv04_gr_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_gr ** pgr)1416864d37c3SBen Skeggs nv04_gr_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_gr **pgr)
1417b8bf04e1SBen Skeggs {
1418bfee3f3dSBen Skeggs struct nv04_gr *gr;
1419b8bf04e1SBen Skeggs
1420c85ee6caSBen Skeggs if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL)))
1421c85ee6caSBen Skeggs return -ENOMEM;
1422bfee3f3dSBen Skeggs spin_lock_init(&gr->lock);
1423c85ee6caSBen Skeggs *pgr = &gr->base;
1424c85ee6caSBen Skeggs
1425864d37c3SBen Skeggs return nvkm_gr_ctor(&nv04_gr, device, type, inst, true, &gr->base);
1426b8bf04e1SBen Skeggs }
1427