]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/engine/graph/fuc/gpcnvc0.fuc
a9f499c6729b0ec7898c73556de1b767d6528618
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / engine / graph / fuc / gpcnvc0.fuc
1 /* fuc microcode for nvc0 PGRAPH/GPC
2  *
3  * Copyright 2011 Red Hat Inc.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  * Authors: Ben Skeggs
24  */
25
26 /* To build:
27  *    m4 gpcnvc0.fuc | envyas -a -w -m fuc -V fuc3 -o gpcnvc0.fuc.h
28  */
29
30 /* TODO
31  * - bracket certain functions with scratch writes, useful for debugging
32  * - watchdog timer around ctx operations
33  */
34
35 .section #nvc0_grgpc_data
36 include(`nvc0.fuc')
37 gpc_id:                 .b32 0
38 gpc_mmio_list_head:     .b32 0
39 gpc_mmio_list_tail:     .b32 0
40
41 tpc_count:              .b32 0
42 tpc_mask:               .b32 0
43 tpc_mmio_list_head:     .b32 0
44 tpc_mmio_list_tail:     .b32 0
45
46 cmd_queue:              queue_init
47
48 // chipset descriptions
49 chipsets:
50 .b8  0xc0 0 0 0
51 .b16 #nvc0_gpc_mmio_head
52 .b16 #nvc0_gpc_mmio_tail
53 .b16 #nvc0_tpc_mmio_head
54 .b16 #nvc0_tpc_mmio_tail
55 .b8  0xc1 0 0 0
56 .b16 #nvc0_gpc_mmio_head
57 .b16 #nvc1_gpc_mmio_tail
58 .b16 #nvc0_tpc_mmio_head
59 .b16 #nvc1_tpc_mmio_tail
60 .b8  0xc3 0 0 0
61 .b16 #nvc0_gpc_mmio_head
62 .b16 #nvc0_gpc_mmio_tail
63 .b16 #nvc0_tpc_mmio_head
64 .b16 #nvc3_tpc_mmio_tail
65 .b8  0xc4 0 0 0
66 .b16 #nvc0_gpc_mmio_head
67 .b16 #nvc0_gpc_mmio_tail
68 .b16 #nvc0_tpc_mmio_head
69 .b16 #nvc3_tpc_mmio_tail
70 .b8  0xc8 0 0 0
71 .b16 #nvc0_gpc_mmio_head
72 .b16 #nvc0_gpc_mmio_tail
73 .b16 #nvc0_tpc_mmio_head
74 .b16 #nvc0_tpc_mmio_tail
75 .b8  0xce 0 0 0
76 .b16 #nvc0_gpc_mmio_head
77 .b16 #nvc0_gpc_mmio_tail
78 .b16 #nvc0_tpc_mmio_head
79 .b16 #nvc3_tpc_mmio_tail
80 .b8  0xcf 0 0 0
81 .b16 #nvc0_gpc_mmio_head
82 .b16 #nvc0_gpc_mmio_tail
83 .b16 #nvc0_tpc_mmio_head
84 .b16 #nvcf_tpc_mmio_tail
85 .b8  0xd9 0 0 0
86 .b16 #nvd9_gpc_mmio_head
87 .b16 #nvd9_gpc_mmio_tail
88 .b16 #nvd9_tpc_mmio_head
89 .b16 #nvd9_tpc_mmio_tail
90 .b8  0xd7 0 0 0
91 .b16 #nvd9_gpc_mmio_head
92 .b16 #nvd9_gpc_mmio_tail
93 .b16 #nvd9_tpc_mmio_head
94 .b16 #nvd9_tpc_mmio_tail
95 .b8  0 0 0 0
96
97 // GPC mmio lists
98 nvc0_gpc_mmio_head:
99 mmctx_data(0x000380, 1)
100 mmctx_data(0x000400, 6)
101 mmctx_data(0x000450, 9)
102 mmctx_data(0x000600, 1)
103 mmctx_data(0x000684, 1)
104 mmctx_data(0x000700, 5)
105 mmctx_data(0x000800, 1)
106 mmctx_data(0x000808, 3)
107 mmctx_data(0x000828, 1)
108 mmctx_data(0x000830, 1)
109 mmctx_data(0x0008d8, 1)
110 mmctx_data(0x0008e0, 1)
111 mmctx_data(0x0008e8, 6)
112 mmctx_data(0x00091c, 1)
113 mmctx_data(0x000924, 3)
114 mmctx_data(0x000b00, 1)
115 mmctx_data(0x000b08, 6)
116 mmctx_data(0x000bb8, 1)
117 mmctx_data(0x000c08, 1)
118 mmctx_data(0x000c10, 8)
119 mmctx_data(0x000c80, 1)
120 mmctx_data(0x000c8c, 1)
121 mmctx_data(0x001000, 3)
122 mmctx_data(0x001014, 1)
123 nvc0_gpc_mmio_tail:
124 mmctx_data(0x000c6c, 1);
125 nvc1_gpc_mmio_tail:
126
127 nvd9_gpc_mmio_head:
128 mmctx_data(0x000380, 1)
129 mmctx_data(0x000400, 2)
130 mmctx_data(0x00040c, 3)
131 mmctx_data(0x000450, 9)
132 mmctx_data(0x000600, 1)
133 mmctx_data(0x000684, 1)
134 mmctx_data(0x000700, 5)
135 mmctx_data(0x000800, 1)
136 mmctx_data(0x000808, 3)
137 mmctx_data(0x000828, 1)
138 mmctx_data(0x000830, 1)
139 mmctx_data(0x0008d8, 1)
140 mmctx_data(0x0008e0, 1)
141 mmctx_data(0x0008e8, 6)
142 mmctx_data(0x00091c, 1)
143 mmctx_data(0x000924, 3)
144 mmctx_data(0x000b00, 1)
145 mmctx_data(0x000b08, 6)
146 mmctx_data(0x000bb8, 1)
147 mmctx_data(0x000c08, 1)
148 mmctx_data(0x000c10, 8)
149 mmctx_data(0x000c6c, 1)
150 mmctx_data(0x000c80, 1)
151 mmctx_data(0x000c8c, 1)
152 mmctx_data(0x001000, 3)
153 mmctx_data(0x001014, 1)
154 nvd9_gpc_mmio_tail:
155
156 // TPC mmio lists
157 nvc0_tpc_mmio_head:
158 mmctx_data(0x000018, 1)
159 mmctx_data(0x00003c, 1)
160 mmctx_data(0x000048, 1)
161 mmctx_data(0x000064, 1)
162 mmctx_data(0x000088, 1)
163 mmctx_data(0x000200, 6)
164 mmctx_data(0x00021c, 2)
165 mmctx_data(0x000300, 6)
166 mmctx_data(0x0003d0, 1)
167 mmctx_data(0x0003e0, 2)
168 mmctx_data(0x000400, 3)
169 mmctx_data(0x000420, 1)
170 mmctx_data(0x0004b0, 1)
171 mmctx_data(0x0004e8, 1)
172 mmctx_data(0x0004f4, 1)
173 mmctx_data(0x000520, 2)
174 mmctx_data(0x000604, 4)
175 mmctx_data(0x000644, 20)
176 mmctx_data(0x000698, 1)
177 mmctx_data(0x000750, 2)
178 nvc0_tpc_mmio_tail:
179 mmctx_data(0x000758, 1)
180 mmctx_data(0x0002c4, 1)
181 mmctx_data(0x0006e0, 1)
182 nvcf_tpc_mmio_tail:
183 mmctx_data(0x0004bc, 1)
184 nvc3_tpc_mmio_tail:
185 mmctx_data(0x000544, 1)
186 nvc1_tpc_mmio_tail:
187
188 nvd9_tpc_mmio_head:
189 mmctx_data(0x000018, 1)
190 mmctx_data(0x00003c, 1)
191 mmctx_data(0x000048, 1)
192 mmctx_data(0x000064, 1)
193 mmctx_data(0x000088, 1)
194 mmctx_data(0x000200, 6)
195 mmctx_data(0x00021c, 2)
196 mmctx_data(0x0002c4, 1)
197 mmctx_data(0x000300, 6)
198 mmctx_data(0x0003d0, 1)
199 mmctx_data(0x0003e0, 2)
200 mmctx_data(0x000400, 3)
201 mmctx_data(0x000420, 3)
202 mmctx_data(0x0004b0, 1)
203 mmctx_data(0x0004e8, 1)
204 mmctx_data(0x0004f4, 1)
205 mmctx_data(0x000520, 2)
206 mmctx_data(0x000544, 1)
207 mmctx_data(0x000604, 4)
208 mmctx_data(0x000644, 20)
209 mmctx_data(0x000698, 1)
210 mmctx_data(0x0006e0, 1)
211 mmctx_data(0x000730, 11)
212 nvd9_tpc_mmio_tail:
213
214 .section #nvc0_grgpc_code
215 bra #init
216 define(`include_code')
217 include(`nvc0.fuc')
218
219 // reports an exception to the host
220 //
221 // In: $r15 error code (see nvc0.fuc)
222 //
223 error:
224         push $r14
225         mov $r14 -0x67ec        // 0x9814
226         sethi $r14 0x400000
227         call #nv_wr32           // HUB_CTXCTL_CC_SCRATCH[5] = error code
228         add b32 $r14 0x41c
229         mov $r15 1
230         call #nv_wr32           // HUB_CTXCTL_INTR_UP_SET
231         pop $r14
232         ret
233
234 // GPC fuc initialisation, executed by triggering ucode start, will
235 // fall through to main loop after completion.
236 //
237 // Input:
238 //   CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
239 //   CC_SCRATCH[1]: context base
240 //
241 // Output:
242 //   CC_SCRATCH[0]:
243 //           31:31: set to signal completion
244 //   CC_SCRATCH[1]:
245 //            31:0: GPC context size
246 //
247 init:
248         clear b32 $r0
249         mov $sp $r0
250
251         // enable fifo access
252         mov $r1 0x1200
253         mov $r2 2
254         iowr I[$r1 + 0x000] $r2         // FIFO_ENABLE
255
256         // setup i0 handler, and route all interrupts to it
257         mov $r1 #ih
258         mov $iv0 $r1
259         mov $r1 0x400
260         iowr I[$r1 + 0x300] $r0         // INTR_DISPATCH
261
262         // enable fifo interrupt
263         mov $r2 4
264         iowr I[$r1 + 0x000] $r2         // INTR_EN_SET
265
266         // enable interrupts
267         bset $flags ie0
268
269         // figure out which GPC we are, and how many TPCs we have
270         mov $r1 0x608
271         shl b32 $r1 6
272         iord $r2 I[$r1 + 0x000]         // UNITS
273         mov $r3 1
274         and $r2 0x1f
275         shl b32 $r3 $r2
276         sub b32 $r3 1
277         st b32 D[$r0 + #tpc_count] $r2
278         st b32 D[$r0 + #tpc_mask] $r3
279         add b32 $r1 0x400
280         iord $r2 I[$r1 + 0x000]         // MYINDEX
281         st b32 D[$r0 + #gpc_id] $r2
282
283         // find context data for this chipset
284         mov $r2 0x800
285         shl b32 $r2 6
286         iord $r2 I[$r2 + 0x000]         // CC_SCRATCH[0]
287         mov $r1 #chipsets - 12
288         init_find_chipset:
289                 add b32 $r1 12
290                 ld b32 $r3 D[$r1 + 0x00]
291                 cmpu b32 $r3 $r2
292                 bra e #init_context
293                 cmpu b32 $r3 0
294                 bra ne #init_find_chipset
295                 // unknown chipset
296                 ret
297
298         // initialise context base, and size tracking
299         init_context:
300         mov $r2 0x800
301         shl b32 $r2 6
302         iord $r2 I[$r2 + 0x100] // CC_SCRATCH[1], initial base
303         clear b32 $r3           // track GPC context size here
304
305         // set mmctx base addresses now so we don't have to do it later,
306         // they don't currently ever change
307         mov $r4 0x700
308         shl b32 $r4 6
309         shr b32 $r5 $r2 8
310         iowr I[$r4 + 0x000] $r5         // MMCTX_SAVE_SWBASE
311         iowr I[$r4 + 0x100] $r5         // MMCTX_LOAD_SWBASE
312
313         // calculate GPC mmio context size, store the chipset-specific
314         // mmio list pointers somewhere we can get at them later without
315         // re-parsing the chipset list
316         clear b32 $r14
317         clear b32 $r15
318         ld b16 $r14 D[$r1 + 4]
319         ld b16 $r15 D[$r1 + 6]
320         st b16 D[$r0 + #gpc_mmio_list_head] $r14
321         st b16 D[$r0 + #gpc_mmio_list_tail] $r15
322         call #mmctx_size
323         add b32 $r2 $r15
324         add b32 $r3 $r15
325
326         // calculate per-TPC mmio context size, store the list pointers
327         ld b16 $r14 D[$r1 + 8]
328         ld b16 $r15 D[$r1 + 10]
329         st b16 D[$r0 + #tpc_mmio_list_head] $r14
330         st b16 D[$r0 + #tpc_mmio_list_tail] $r15
331         call #mmctx_size
332         ld b32 $r14 D[$r0 + #tpc_count]
333         mulu $r14 $r15
334         add b32 $r2 $r14
335         add b32 $r3 $r14
336
337         // round up base/size to 256 byte boundary (for strand SWBASE)
338         add b32 $r4 0x1300
339         shr b32 $r3 2
340         iowr I[$r4 + 0x000] $r3         // MMCTX_LOAD_COUNT, wtf for?!?
341         shr b32 $r2 8
342         shr b32 $r3 6
343         add b32 $r2 1
344         add b32 $r3 1
345         shl b32 $r2 8
346         shl b32 $r3 8
347
348         // calculate size of strand context data
349         mov b32 $r15 $r2
350         call #strand_ctx_init
351         add b32 $r3 $r15
352
353         // save context size, and tell HUB we're done
354         mov $r1 0x800
355         shl b32 $r1 6
356         iowr I[$r1 + 0x100] $r3         // CC_SCRATCH[1]  = context size
357         add b32 $r1 0x800
358         clear b32 $r2
359         bset $r2 31
360         iowr I[$r1 + 0x000] $r2         // CC_SCRATCH[0] |= 0x80000000
361
362 // Main program loop, very simple, sleeps until woken up by the interrupt
363 // handler, pulls a command from the queue and executes its handler
364 //
365 main:
366         bset $flags $p0
367         sleep $p0
368         mov $r13 #cmd_queue
369         call #queue_get
370         bra $p1 #main
371
372         // 0x0000-0x0003 are all context transfers
373         cmpu b32 $r14 0x04
374         bra nc #main_not_ctx_xfer
375                 // fetch $flags and mask off $p1/$p2
376                 mov $r1 $flags
377                 mov $r2 0x0006
378                 not b32 $r2
379                 and $r1 $r2
380                 // set $p1/$p2 according to transfer type
381                 shl b32 $r14 1
382                 or $r1 $r14
383                 mov $flags $r1
384                 // transfer context data
385                 call #ctx_xfer
386                 bra #main
387
388         main_not_ctx_xfer:
389         shl b32 $r15 $r14 16
390         or $r15 E_BAD_COMMAND
391         call #error
392         bra #main
393
394 // interrupt handler
395 ih:
396         push $r8
397         mov $r8 $flags
398         push $r8
399         push $r9
400         push $r10
401         push $r11
402         push $r13
403         push $r14
404         push $r15
405
406         // incoming fifo command?
407         iord $r10 I[$r0 + 0x200]        // INTR
408         and $r11 $r10 0x00000004
409         bra e #ih_no_fifo
410                 // queue incoming fifo command for later processing
411                 mov $r11 0x1900
412                 mov $r13 #cmd_queue
413                 iord $r14 I[$r11 + 0x100]       // FIFO_CMD
414                 iord $r15 I[$r11 + 0x000]       // FIFO_DATA
415                 call #queue_put
416                 add b32 $r11 0x400
417                 mov $r14 1
418                 iowr I[$r11 + 0x000] $r14       // FIFO_ACK
419
420         // ack, and wake up main()
421         ih_no_fifo:
422         iowr I[$r0 + 0x100] $r10        // INTR_ACK
423
424         pop $r15
425         pop $r14
426         pop $r13
427         pop $r11
428         pop $r10
429         pop $r9
430         pop $r8
431         mov $flags $r8
432         pop $r8
433         bclr $flags $p0
434         iret
435
436 // Set this GPC's bit in HUB_BAR, used to signal completion of various
437 // activities to the HUB fuc
438 //
439 hub_barrier_done:
440         mov $r15 1
441         ld b32 $r14 D[$r0 + #gpc_id]
442         shl b32 $r15 $r14
443         mov $r14 -0x6be8        // 0x409418 - HUB_BAR_SET
444         sethi $r14 0x400000
445         call #nv_wr32
446         ret
447
448 // Disables various things, waits a bit, and re-enables them..
449 //
450 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
451 // good description for the bits we turn off?  Anyways, without this,
452 // funny things happen.
453 //
454 ctx_redswitch:
455         mov $r14 0x614
456         shl b32 $r14 6
457         mov $r15 0x020
458         iowr I[$r14] $r15       // GPC_RED_SWITCH = POWER
459         mov $r15 8
460         ctx_redswitch_delay:
461                 sub b32 $r15 1
462                 bra ne #ctx_redswitch_delay
463         mov $r15 0xa20
464         iowr I[$r14] $r15       // GPC_RED_SWITCH = UNK11, ENABLE, POWER
465         ret
466
467 // Transfer GPC context data between GPU and storage area
468 //
469 // In: $r15 context base address
470 //     $p1 clear on save, set on load
471 //     $p2 set if opposite direction done/will be done, so:
472 //              on save it means: "a load will follow this save"
473 //              on load it means: "a save preceeded this load"
474 //
475 ctx_xfer:
476         // set context base address
477         mov $r1 0xa04
478         shl b32 $r1 6
479         iowr I[$r1 + 0x000] $r15// MEM_BASE
480         bra not $p1 #ctx_xfer_not_load
481                 call #ctx_redswitch
482         ctx_xfer_not_load:
483
484         // strands
485         mov $r1 0x4afc
486         sethi $r1 0x20000
487         mov $r2 0xc
488         iowr I[$r1] $r2         // STRAND_CMD(0x3f) = 0x0c
489         call #strand_wait
490         mov $r2 0x47fc
491         sethi $r2 0x20000
492         iowr I[$r2] $r0         // STRAND_FIRST_GENE(0x3f) = 0x00
493         xbit $r2 $flags $p1
494         add b32 $r2 3
495         iowr I[$r1] $r2         // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
496
497         // mmio context
498         xbit $r10 $flags $p1    // direction
499         or $r10 2               // first
500         mov $r11 0x0000
501         sethi $r11 0x500000
502         ld b32 $r12 D[$r0 + #gpc_id]
503         shl b32 $r12 15
504         add b32 $r11 $r12       // base = NV_PGRAPH_GPCn
505         ld b32 $r12 D[$r0 + #gpc_mmio_list_head]
506         ld b32 $r13 D[$r0 + #gpc_mmio_list_tail]
507         mov $r14 0              // not multi
508         call #mmctx_xfer
509
510         // per-TPC mmio context
511         xbit $r10 $flags $p1    // direction
512         or $r10 4               // last
513         mov $r11 0x4000
514         sethi $r11 0x500000     // base = NV_PGRAPH_GPC0_TPC0
515         ld b32 $r12 D[$r0 + #gpc_id]
516         shl b32 $r12 15
517         add b32 $r11 $r12       // base = NV_PGRAPH_GPCn_TPC0
518         ld b32 $r12 D[$r0 + #tpc_mmio_list_head]
519         ld b32 $r13 D[$r0 + #tpc_mmio_list_tail]
520         ld b32 $r15 D[$r0 + #tpc_mask]
521         mov $r14 0x800          // stride = 0x800
522         call #mmctx_xfer
523
524         // wait for strands to finish
525         call #strand_wait
526
527         // if load, or a save without a load following, do some
528         // unknown stuff that's done after finishing a block of
529         // strand commands
530         bra $p1 #ctx_xfer_post
531         bra not $p2 #ctx_xfer_done
532         ctx_xfer_post:
533                 mov $r1 0x4afc
534                 sethi $r1 0x20000
535                 mov $r2 0xd
536                 iowr I[$r1] $r2         // STRAND_CMD(0x3f) = 0x0d
537                 call #strand_wait
538
539         // mark completion in HUB's barrier
540         ctx_xfer_done:
541         call #hub_barrier_done
542         ret
543
544 .align 256