]>
Commit | Line | Data |
---|---|---|
6ee73861 BS |
1 | /* |
2 | * Copyright (C) 2007 Ben Skeggs. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * Permission is hereby granted, free of charge, to any person obtaining | |
6 | * a copy of this software and associated documentation files (the | |
7 | * "Software"), to deal in the Software without restriction, including | |
8 | * without limitation the rights to use, copy, modify, merge, publish, | |
9 | * distribute, sublicense, and/or sell copies of the Software, and to | |
10 | * permit persons to whom the Software is furnished to do so, subject to | |
11 | * the following conditions: | |
12 | * | |
13 | * The above copyright notice and this permission notice (including the | |
14 | * next paragraph) shall be included in all copies or substantial | |
15 | * portions of the Software. | |
16 | * | |
17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
20 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE | |
21 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
22 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
24 | * | |
25 | */ | |
26 | ||
6ee73861 BS |
27 | #include "drmP.h" |
28 | #include "drm.h" | |
29 | #include "nouveau_drv.h" | |
054b93e4 | 30 | #include "nouveau_grctx.h" |
6ee73861 BS |
31 | |
32 | struct nouveau_channel * | |
33 | nv40_graph_channel(struct drm_device *dev) | |
34 | { | |
35 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
36 | uint32_t inst; | |
37 | int i; | |
38 | ||
39 | inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR); | |
40 | if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED)) | |
41 | return NULL; | |
42 | inst = (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) << 4; | |
43 | ||
44 | for (i = 0; i < dev_priv->engine.fifo.channels; i++) { | |
45 | struct nouveau_channel *chan = dev_priv->fifos[i]; | |
46 | ||
47 | if (chan && chan->ramin_grctx && | |
48 | chan->ramin_grctx->instance == inst) | |
49 | return chan; | |
50 | } | |
51 | ||
52 | return NULL; | |
53 | } | |
54 | ||
55 | int | |
56 | nv40_graph_create_context(struct nouveau_channel *chan) | |
57 | { | |
58 | struct drm_device *dev = chan->dev; | |
59 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
054b93e4 | 60 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; |
6ee73861 BS |
61 | int ret; |
62 | ||
054b93e4 BS |
63 | ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, pgraph->grctx_size, |
64 | 16, NVOBJ_FLAG_ZERO_ALLOC, | |
65 | &chan->ramin_grctx); | |
6ee73861 BS |
66 | if (ret) |
67 | return ret; | |
6ee73861 BS |
68 | |
69 | /* Initialise default context values */ | |
054b93e4 BS |
70 | if (!pgraph->ctxprog) { |
71 | struct nouveau_grctx ctx = {}; | |
6ee73861 | 72 | |
054b93e4 BS |
73 | ctx.dev = chan->dev; |
74 | ctx.mode = NOUVEAU_GRCTX_VALS; | |
75 | ctx.data = chan->ramin_grctx->gpuobj; | |
76 | nv40_grctx_init(&ctx); | |
77 | } else { | |
78 | nouveau_grctx_vals_load(dev, chan->ramin_grctx->gpuobj); | |
79 | } | |
80 | nv_wo32(dev, chan->ramin_grctx->gpuobj, 0, | |
81 | chan->ramin_grctx->gpuobj->im_pramin->start); | |
6ee73861 BS |
82 | return 0; |
83 | } | |
84 | ||
85 | void | |
86 | nv40_graph_destroy_context(struct nouveau_channel *chan) | |
87 | { | |
88 | nouveau_gpuobj_ref_del(chan->dev, &chan->ramin_grctx); | |
89 | } | |
90 | ||
91 | static int | |
92 | nv40_graph_transfer_context(struct drm_device *dev, uint32_t inst, int save) | |
93 | { | |
94 | uint32_t old_cp, tv = 1000, tmp; | |
95 | int i; | |
96 | ||
97 | old_cp = nv_rd32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER); | |
98 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst); | |
99 | ||
100 | tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0310); | |
101 | tmp |= save ? NV40_PGRAPH_CTXCTL_0310_XFER_SAVE : | |
102 | NV40_PGRAPH_CTXCTL_0310_XFER_LOAD; | |
103 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_0310, tmp); | |
104 | ||
105 | tmp = nv_rd32(dev, NV40_PGRAPH_CTXCTL_0304); | |
106 | tmp |= NV40_PGRAPH_CTXCTL_0304_XFER_CTX; | |
107 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_0304, tmp); | |
108 | ||
109 | nouveau_wait_for_idle(dev); | |
110 | ||
111 | for (i = 0; i < tv; i++) { | |
112 | if (nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C) == 0) | |
113 | break; | |
114 | } | |
115 | ||
116 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, old_cp); | |
117 | ||
118 | if (i == tv) { | |
119 | uint32_t ucstat = nv_rd32(dev, NV40_PGRAPH_CTXCTL_UCODE_STAT); | |
120 | NV_ERROR(dev, "Failed: Instance=0x%08x Save=%d\n", inst, save); | |
121 | NV_ERROR(dev, "IP: 0x%02x, Opcode: 0x%08x\n", | |
122 | ucstat >> NV40_PGRAPH_CTXCTL_UCODE_STAT_IP_SHIFT, | |
123 | ucstat & NV40_PGRAPH_CTXCTL_UCODE_STAT_OP_MASK); | |
124 | NV_ERROR(dev, "0x40030C = 0x%08x\n", | |
125 | nv_rd32(dev, NV40_PGRAPH_CTXCTL_030C)); | |
126 | return -EBUSY; | |
127 | } | |
128 | ||
129 | return 0; | |
130 | } | |
131 | ||
132 | /* Restore the context for a specific channel into PGRAPH */ | |
133 | int | |
134 | nv40_graph_load_context(struct nouveau_channel *chan) | |
135 | { | |
136 | struct drm_device *dev = chan->dev; | |
137 | uint32_t inst; | |
138 | int ret; | |
139 | ||
140 | if (!chan->ramin_grctx) | |
141 | return -EINVAL; | |
142 | inst = chan->ramin_grctx->instance >> 4; | |
143 | ||
144 | ret = nv40_graph_transfer_context(dev, inst, 0); | |
145 | if (ret) | |
146 | return ret; | |
147 | ||
148 | /* 0x40032C, no idea of it's exact function. Could simply be a | |
149 | * record of the currently active PGRAPH context. It's currently | |
150 | * unknown as to what bit 24 does. The nv ddx has it set, so we will | |
151 | * set it here too. | |
152 | */ | |
153 | nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst); | |
154 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, | |
155 | (inst & NV40_PGRAPH_CTXCTL_CUR_INSTANCE) | | |
156 | NV40_PGRAPH_CTXCTL_CUR_LOADED); | |
157 | /* 0x32E0 records the instance address of the active FIFO's PGRAPH | |
158 | * context. If at any time this doesn't match 0x40032C, you will | |
159 | * recieve PGRAPH_INTR_CONTEXT_SWITCH | |
160 | */ | |
161 | nv_wr32(dev, NV40_PFIFO_GRCTX_INSTANCE, inst); | |
162 | return 0; | |
163 | } | |
164 | ||
165 | int | |
166 | nv40_graph_unload_context(struct drm_device *dev) | |
167 | { | |
168 | uint32_t inst; | |
169 | int ret; | |
170 | ||
171 | inst = nv_rd32(dev, NV40_PGRAPH_CTXCTL_CUR); | |
172 | if (!(inst & NV40_PGRAPH_CTXCTL_CUR_LOADED)) | |
173 | return 0; | |
174 | inst &= NV40_PGRAPH_CTXCTL_CUR_INSTANCE; | |
175 | ||
176 | ret = nv40_graph_transfer_context(dev, inst, 1); | |
177 | ||
178 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, inst); | |
179 | return ret; | |
180 | } | |
181 | ||
0d87c100 FJ |
182 | void |
183 | nv40_graph_set_region_tiling(struct drm_device *dev, int i, uint32_t addr, | |
184 | uint32_t size, uint32_t pitch) | |
185 | { | |
186 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
187 | uint32_t limit = max(1u, addr + size) - 1; | |
188 | ||
189 | if (pitch) | |
190 | addr |= 1; | |
191 | ||
192 | switch (dev_priv->chipset) { | |
193 | case 0x44: | |
194 | case 0x4a: | |
195 | case 0x4e: | |
196 | nv_wr32(dev, NV20_PGRAPH_TSIZE(i), pitch); | |
197 | nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), limit); | |
198 | nv_wr32(dev, NV20_PGRAPH_TILE(i), addr); | |
199 | break; | |
200 | ||
201 | case 0x46: | |
202 | case 0x47: | |
203 | case 0x49: | |
204 | case 0x4b: | |
205 | nv_wr32(dev, NV47_PGRAPH_TSIZE(i), pitch); | |
206 | nv_wr32(dev, NV47_PGRAPH_TLIMIT(i), limit); | |
207 | nv_wr32(dev, NV47_PGRAPH_TILE(i), addr); | |
208 | nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), pitch); | |
209 | nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), limit); | |
210 | nv_wr32(dev, NV40_PGRAPH_TILE1(i), addr); | |
211 | break; | |
212 | ||
213 | default: | |
214 | nv_wr32(dev, NV20_PGRAPH_TSIZE(i), pitch); | |
215 | nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), limit); | |
216 | nv_wr32(dev, NV20_PGRAPH_TILE(i), addr); | |
217 | nv_wr32(dev, NV40_PGRAPH_TSIZE1(i), pitch); | |
218 | nv_wr32(dev, NV40_PGRAPH_TLIMIT1(i), limit); | |
219 | nv_wr32(dev, NV40_PGRAPH_TILE1(i), addr); | |
220 | break; | |
221 | } | |
222 | } | |
223 | ||
6ee73861 BS |
224 | /* |
225 | * G70 0x47 | |
226 | * G71 0x49 | |
227 | * NV45 0x48 | |
228 | * G72[M] 0x46 | |
229 | * G73 0x4b | |
230 | * C51_G7X 0x4c | |
231 | * C51 0x4e | |
232 | */ | |
233 | int | |
234 | nv40_graph_init(struct drm_device *dev) | |
235 | { | |
236 | struct drm_nouveau_private *dev_priv = | |
237 | (struct drm_nouveau_private *)dev->dev_private; | |
0d87c100 FJ |
238 | struct nouveau_fb_engine *pfb = &dev_priv->engine.fb; |
239 | uint32_t vramsz; | |
6ee73861 BS |
240 | int i, j; |
241 | ||
242 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & | |
243 | ~NV_PMC_ENABLE_PGRAPH); | |
244 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | | |
245 | NV_PMC_ENABLE_PGRAPH); | |
246 | ||
054b93e4 BS |
247 | if (nouveau_ctxfw) { |
248 | nouveau_grctx_prog_load(dev); | |
249 | dev_priv->engine.graph.grctx_size = 175 * 1024; | |
250 | } | |
251 | ||
252 | if (!dev_priv->engine.graph.ctxprog) { | |
253 | struct nouveau_grctx ctx = {}; | |
f49d273d PB |
254 | uint32_t *cp; |
255 | ||
256 | cp = kmalloc(sizeof(*cp) * 256, GFP_KERNEL); | |
257 | if (!cp) | |
258 | return -ENOMEM; | |
054b93e4 BS |
259 | |
260 | ctx.dev = dev; | |
261 | ctx.mode = NOUVEAU_GRCTX_PROG; | |
262 | ctx.data = cp; | |
263 | ctx.ctxprog_max = 256; | |
264 | nv40_grctx_init(&ctx); | |
265 | dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4; | |
266 | ||
267 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0); | |
268 | for (i = 0; i < ctx.ctxprog_len; i++) | |
269 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]); | |
f49d273d PB |
270 | |
271 | kfree(cp); | |
054b93e4 | 272 | } |
6ee73861 BS |
273 | |
274 | /* No context present currently */ | |
275 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0x00000000); | |
276 | ||
277 | nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF); | |
278 | nv_wr32(dev, NV40_PGRAPH_INTR_EN, 0xFFFFFFFF); | |
279 | ||
280 | nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF); | |
281 | nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000); | |
282 | nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x401287c0); | |
283 | nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xe0de8055); | |
284 | nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00008000); | |
285 | nv_wr32(dev, NV04_PGRAPH_LIMIT_VIOL_PIX, 0x00be3c5f); | |
286 | ||
287 | nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100); | |
288 | nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF); | |
289 | ||
290 | j = nv_rd32(dev, 0x1540) & 0xff; | |
291 | if (j) { | |
292 | for (i = 0; !(j & 1); j >>= 1, i++) | |
293 | ; | |
294 | nv_wr32(dev, 0x405000, i); | |
295 | } | |
296 | ||
297 | if (dev_priv->chipset == 0x40) { | |
298 | nv_wr32(dev, 0x4009b0, 0x83280fff); | |
299 | nv_wr32(dev, 0x4009b4, 0x000000a0); | |
300 | } else { | |
301 | nv_wr32(dev, 0x400820, 0x83280eff); | |
302 | nv_wr32(dev, 0x400824, 0x000000a0); | |
303 | } | |
304 | ||
305 | switch (dev_priv->chipset) { | |
306 | case 0x40: | |
307 | case 0x45: | |
308 | nv_wr32(dev, 0x4009b8, 0x0078e366); | |
309 | nv_wr32(dev, 0x4009bc, 0x0000014c); | |
310 | break; | |
311 | case 0x41: | |
312 | case 0x42: /* pciid also 0x00Cx */ | |
313 | /* case 0x0120: XXX (pciid) */ | |
314 | nv_wr32(dev, 0x400828, 0x007596ff); | |
315 | nv_wr32(dev, 0x40082c, 0x00000108); | |
316 | break; | |
317 | case 0x43: | |
318 | nv_wr32(dev, 0x400828, 0x0072cb77); | |
319 | nv_wr32(dev, 0x40082c, 0x00000108); | |
320 | break; | |
321 | case 0x44: | |
322 | case 0x46: /* G72 */ | |
323 | case 0x4a: | |
324 | case 0x4c: /* G7x-based C51 */ | |
325 | case 0x4e: | |
326 | nv_wr32(dev, 0x400860, 0); | |
327 | nv_wr32(dev, 0x400864, 0); | |
328 | break; | |
329 | case 0x47: /* G70 */ | |
330 | case 0x49: /* G71 */ | |
331 | case 0x4b: /* G73 */ | |
332 | nv_wr32(dev, 0x400828, 0x07830610); | |
333 | nv_wr32(dev, 0x40082c, 0x0000016A); | |
334 | break; | |
335 | default: | |
336 | break; | |
337 | } | |
338 | ||
339 | nv_wr32(dev, 0x400b38, 0x2ffff800); | |
340 | nv_wr32(dev, 0x400b3c, 0x00006000); | |
341 | ||
2295e17a FJ |
342 | /* Tiling related stuff. */ |
343 | switch (dev_priv->chipset) { | |
344 | case 0x44: | |
345 | case 0x4a: | |
346 | nv_wr32(dev, 0x400bc4, 0x1003d888); | |
347 | nv_wr32(dev, 0x400bbc, 0xb7a7b500); | |
348 | break; | |
349 | case 0x46: | |
350 | nv_wr32(dev, 0x400bc4, 0x0000e024); | |
351 | nv_wr32(dev, 0x400bbc, 0xb7a7b520); | |
352 | break; | |
353 | case 0x4c: | |
354 | case 0x4e: | |
355 | case 0x67: | |
356 | nv_wr32(dev, 0x400bc4, 0x1003d888); | |
357 | nv_wr32(dev, 0x400bbc, 0xb7a7b540); | |
358 | break; | |
359 | default: | |
360 | break; | |
361 | } | |
362 | ||
0d87c100 FJ |
363 | /* Turn all the tiling regions off. */ |
364 | for (i = 0; i < pfb->num_tiles; i++) | |
365 | nv40_graph_set_region_tiling(dev, i, 0, 0, 0); | |
6ee73861 BS |
366 | |
367 | /* begin RAM config */ | |
01d73a69 | 368 | vramsz = pci_resource_len(dev->pdev, 0) - 1; |
6ee73861 BS |
369 | switch (dev_priv->chipset) { |
370 | case 0x40: | |
371 | nv_wr32(dev, 0x4009A4, nv_rd32(dev, NV04_PFB_CFG0)); | |
372 | nv_wr32(dev, 0x4009A8, nv_rd32(dev, NV04_PFB_CFG1)); | |
373 | nv_wr32(dev, 0x4069A4, nv_rd32(dev, NV04_PFB_CFG0)); | |
374 | nv_wr32(dev, 0x4069A8, nv_rd32(dev, NV04_PFB_CFG1)); | |
375 | nv_wr32(dev, 0x400820, 0); | |
376 | nv_wr32(dev, 0x400824, 0); | |
377 | nv_wr32(dev, 0x400864, vramsz); | |
378 | nv_wr32(dev, 0x400868, vramsz); | |
379 | break; | |
380 | default: | |
381 | switch (dev_priv->chipset) { | |
382 | case 0x46: | |
383 | case 0x47: | |
384 | case 0x49: | |
385 | case 0x4b: | |
386 | nv_wr32(dev, 0x400DF0, nv_rd32(dev, NV04_PFB_CFG0)); | |
387 | nv_wr32(dev, 0x400DF4, nv_rd32(dev, NV04_PFB_CFG1)); | |
388 | break; | |
389 | default: | |
390 | nv_wr32(dev, 0x4009F0, nv_rd32(dev, NV04_PFB_CFG0)); | |
391 | nv_wr32(dev, 0x4009F4, nv_rd32(dev, NV04_PFB_CFG1)); | |
392 | break; | |
393 | } | |
394 | nv_wr32(dev, 0x4069F0, nv_rd32(dev, NV04_PFB_CFG0)); | |
395 | nv_wr32(dev, 0x4069F4, nv_rd32(dev, NV04_PFB_CFG1)); | |
396 | nv_wr32(dev, 0x400840, 0); | |
397 | nv_wr32(dev, 0x400844, 0); | |
398 | nv_wr32(dev, 0x4008A0, vramsz); | |
399 | nv_wr32(dev, 0x4008A4, vramsz); | |
400 | break; | |
401 | } | |
402 | ||
403 | return 0; | |
404 | } | |
405 | ||
406 | void nv40_graph_takedown(struct drm_device *dev) | |
407 | { | |
054b93e4 | 408 | nouveau_grctx_fini(dev); |
6ee73861 BS |
409 | } |
410 | ||
411 | struct nouveau_pgraph_object_class nv40_graph_grclass[] = { | |
412 | { 0x0030, false, NULL }, /* null */ | |
413 | { 0x0039, false, NULL }, /* m2mf */ | |
414 | { 0x004a, false, NULL }, /* gdirect */ | |
415 | { 0x009f, false, NULL }, /* imageblit (nv12) */ | |
416 | { 0x008a, false, NULL }, /* ifc */ | |
417 | { 0x0089, false, NULL }, /* sifm */ | |
418 | { 0x3089, false, NULL }, /* sifm (nv40) */ | |
419 | { 0x0062, false, NULL }, /* surf2d */ | |
420 | { 0x3062, false, NULL }, /* surf2d (nv40) */ | |
421 | { 0x0043, false, NULL }, /* rop */ | |
422 | { 0x0012, false, NULL }, /* beta1 */ | |
423 | { 0x0072, false, NULL }, /* beta4 */ | |
424 | { 0x0019, false, NULL }, /* cliprect */ | |
425 | { 0x0044, false, NULL }, /* pattern */ | |
426 | { 0x309e, false, NULL }, /* swzsurf */ | |
427 | { 0x4097, false, NULL }, /* curie (nv40) */ | |
428 | { 0x4497, false, NULL }, /* curie (nv44) */ | |
429 | {} | |
430 | }; | |
431 |