1 /* fuc microcode for nvc0 PGRAPH/HUB
3 * Copyright 2011 Red Hat Inc.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
27 * m4 nvc0_grhub.fuc | envyas -a -w -m fuc -V nva3 -o nvc0_grhub.fuc.h
30 .section nvc0_grhub_data
31 include(`nvc0_graph.fuc')
35 hub_mmio_list_head: .b32 0
36 hub_mmio_list_tail: .b32 0
42 .b16 nvc0_hub_mmio_head
43 .b16 nvc0_hub_mmio_tail
45 .b16 nvc0_hub_mmio_head
46 .b16 nvc1_hub_mmio_tail
48 .b16 nvc0_hub_mmio_head
49 .b16 nvc0_hub_mmio_tail
51 .b16 nvc0_hub_mmio_head
52 .b16 nvc0_hub_mmio_tail
54 .b16 nvc0_hub_mmio_head
55 .b16 nvc0_hub_mmio_tail
57 .b16 nvc0_hub_mmio_head
58 .b16 nvc0_hub_mmio_tail
62 mmctx_data(0x17e91c, 2)
63 mmctx_data(0x400204, 2)
64 mmctx_data(0x404004, 11)
65 mmctx_data(0x404044, 1)
66 mmctx_data(0x404094, 14)
67 mmctx_data(0x4040d0, 7)
68 mmctx_data(0x4040f8, 1)
69 mmctx_data(0x404130, 3)
70 mmctx_data(0x404150, 3)
71 mmctx_data(0x404164, 2)
72 mmctx_data(0x404174, 3)
73 mmctx_data(0x404200, 8)
74 mmctx_data(0x404404, 14)
75 mmctx_data(0x404460, 4)
76 mmctx_data(0x404480, 1)
77 mmctx_data(0x404498, 1)
78 mmctx_data(0x404604, 4)
79 mmctx_data(0x404618, 32)
80 mmctx_data(0x404698, 21)
81 mmctx_data(0x4046f0, 2)
82 mmctx_data(0x404700, 22)
83 mmctx_data(0x405800, 1)
84 mmctx_data(0x405830, 3)
85 mmctx_data(0x405854, 1)
86 mmctx_data(0x405870, 4)
87 mmctx_data(0x405a00, 2)
88 mmctx_data(0x405a18, 1)
89 mmctx_data(0x406020, 1)
90 mmctx_data(0x406028, 4)
91 mmctx_data(0x4064a8, 2)
92 mmctx_data(0x4064b4, 2)
93 mmctx_data(0x407804, 1)
94 mmctx_data(0x40780c, 6)
95 mmctx_data(0x4078bc, 1)
96 mmctx_data(0x408000, 7)
97 mmctx_data(0x408064, 1)
98 mmctx_data(0x408800, 3)
99 mmctx_data(0x408900, 4)
100 mmctx_data(0x408980, 1)
102 mmctx_data(0x4064c0, 2)
107 chan_mmio_count: .b32 0
108 chan_mmio_address: .b32 0
113 .section nvc0_grhub_code
115 define(`include_code')
116 include(`nvc0_graph.fuc')
118 // reports an exception to the host
120 // In: $r15 error code (see nvc0_graph.fuc)
126 iowr I[$r14 + 0x000] $r15 // CC_SCRATCH[5] = error code
130 iowr I[$r14 + 0x000] $r15 // INTR_UP_SET
134 // HUB fuc initialisation, executed by triggering ucode start, will
135 // fall through to main loop after completion.
138 // CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
142 // 31:31: set to signal completion
144 // 31:0: total PGRAPH context size
151 // enable fifo access
154 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
156 // setup i0 handler, and route all interrupts to it
160 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
162 // route HUB_CHANNEL_SWITCH to fuc interrupt 8
165 mov $r2 0x2003 // { HUB_CHANNEL_SWITCH, ZERO } -> intr 8
166 iowr I[$r3 + 0x000] $r2
168 // not sure what these are, route them because NVIDIA does, and
169 // the IRQ handler will signal the host if we ever get one.. we
170 // may find out if/why we need to handle these if so..
173 iowr I[$r3 + 0x004] $r2 // { 0x04, ZERO } -> intr 9
175 iowr I[$r3 + 0x008] $r2 // { 0x0b, ZERO } -> intr 10
177 iowr I[$r3 + 0x01c] $r2 // { 0x0c, ZERO } -> intr 15
179 // enable all INTR_UP interrupts
185 // enable fifo, ctxsw, 9, 10, 15 interrupts
186 mov $r2 -0x78fc // 0x8704
188 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
190 // fifo level triggered, rest edge
198 // fetch enabled GPC/ROP counts
199 mov $r14 -0x69fc // 0x409604
203 st b32 D[$r0 + rop_count] $r1
205 st b32 D[$r0 + gpc_count] $r15
207 // set BAR_REQMASK to GPC mask
213 iowr I[$r2 + 0x000] $r1
214 iowr I[$r2 + 0x100] $r1
216 // find context data for this chipset
219 iord $r2 I[$r2 + 0x000] // CC_SCRATCH[0]
220 mov $r15 chipsets - 8
223 ld b32 $r3 D[$r15 + 0x00]
227 bra ne init_find_chipset
231 // context size calculation, reserve first 256 bytes for use by fuc
235 // calculate size of mmio context data
236 ld b16 $r14 D[$r15 + 4]
237 ld b16 $r15 D[$r15 + 6]
239 st b32 D[$r0 + hub_mmio_list_head] $r14
240 st b32 D[$r0 + hub_mmio_list_tail] $r15
243 // set mmctx base addresses now so we don't have to do it later,
244 // they don't (currently) ever change
248 iowr I[$r3 + 0x000] $r4 // MMCTX_SAVE_SWBASE
249 iowr I[$r3 + 0x100] $r4 // MMCTX_LOAD_SWBASE
253 iowr I[$r3 + 0x000] $r15 // MMCTX_LOAD_COUNT, wtf for?!?
255 // strands, base offset needs to be aligned to 256 bytes
263 // initialise each GPC in sequence by passing in the offset of its
264 // context data in GPCn_CC_SCRATCH[1], and starting its FUC (which
265 // has previously been uploaded by the host) running.
267 // the GPC fuc init sequence will set GPCn_CC_SCRATCH[0] bit 31
268 // when it has completed, and return the size of its context data
269 // in GPCn_CC_SCRATCH[1]
271 ld b32 $r3 D[$r0 + gpc_count]
275 // setup, and start GPC ucode running
276 add b32 $r14 $r4 0x804
278 call nv_wr32 // CC_SCRATCH[1] = ctx offset
279 add b32 $r14 $r4 0x800
281 call nv_wr32 // CC_SCRATCH[0] = chipset
282 add b32 $r14 $r4 0x10c
285 add b32 $r14 $r4 0x104
286 call nv_wr32 // ENTRY
287 add b32 $r14 $r4 0x100
288 mov $r15 2 // CTRL_START_TRIGGER
291 // wait for it to complete, and adjust context size
292 add b32 $r14 $r4 0x800
297 add b32 $r14 $r4 0x804
306 // save context size, and tell host we're ready
309 iowr I[$r2 + 0x100] $r1 // CC_SCRATCH[1] = context size
313 iowr I[$r2 + 0x000] $r1 // CC_SCRATCH[0] |= 0x80000000
315 // Main program loop, very simple, sleeps until woken up by the interrupt
316 // handler, pulls a command from the queue and executes its handler
319 // sleep until we have something to do
326 // context switch, requested by GPU?
328 bra ne main_not_ctx_switch
332 iord $r2 I[$r1 + 0x100] // CHAN_NEXT
333 iord $r1 I[$r1 + 0x000] // CHAN_CUR
338 bra e chsw_prev_no_next
370 // ack the context switch request
375 iowr I[$r1 + 0x000] $r2 // 0x409b0c
379 // request to set current channel? (*not* a context switch)
382 bra ne main_not_ctx_chan
387 // request to store current channel context?
390 bra ne main_not_ctx_save
400 or $r15 E_BAD_COMMAND
409 iowr I[$r1 + 0x000] $r2 // CC_SCRATCH[0] |= 0x80000000
424 // incoming fifo command?
425 iord $r10 I[$r0 + 0x200] // INTR
426 and $r11 $r10 0x00000004
428 // queue incoming fifo command for later processing
431 iord $r14 I[$r11 + 0x100] // FIFO_CMD
432 iord $r15 I[$r11 + 0x000] // FIFO_DATA
436 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
438 // context switch request?
440 and $r11 $r10 0x00000100
442 // enqueue a context switch for later processing
447 // anything we didn't handle, bring it to the host's attention
455 iowr I[$r10] $r11 // INTR_UP_SET
457 // ack, and wake up main()
459 iowr I[$r0 + 0x100] $r10 // INTR_ACK
473 // Not real sure, but, MEM_CMD 7 will hang forever if this isn't done
485 // Without clearing again at end of xfer, some things cause PGRAPH
486 // to hang with STATUS=0x00000007 until it's cleared.. fbcon can
487 // still function with it set however...
495 // Again, not real sure
497 // In: $r15 value to set 0x404170 to
506 // Waits for a ctx_4170s() call to complete
516 // Disables various things, waits a bit, and re-enables them..
518 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
519 // good description for the bits we turn off? Anyways, without this,
520 // funny things happen.
526 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_GPC, POWER_ALL
530 bra ne ctx_redswitch_delay
532 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_ALL, POWER_ALL
535 // Not a clue what this is for, except that unless the value is 0x10, the
536 // strand context is saved (and presumably restored) incorrectly..
538 // In: $r15 value to set to (0x00/0x10 are used)
543 iowr I[$r14] $r15 // HUB(0x86c) = val
546 call nv_wr32 // ROP(0xa14) = val
549 call nv_wr32 // GPC(0x86c) = val
552 // ctx_load - load's a channel's ctxctl data, and selects its vm
554 // In: $r2 channel address
559 // switch to channel, somewhat magic in parts..
560 mov $r10 12 // DONE_UNK12
564 iowr I[$r1 + 0x000] $r0 // 0x409a24
567 iowr I[$r3 + 0x100] $r2 // CHAN_NEXT
571 iowr I[$r1 + 0x000] $r2 // MEM_CHAN
572 iowr I[$r1 + 0x100] $r4 // MEM_CMD
574 iord $r4 I[$r1 + 0x100]
576 bra ne ctx_chan_wait_0
577 iowr I[$r3 + 0x000] $r2 // CHAN_CUR
579 // load channel header, fetch PGRAPH context pointer
588 iowr I[$r1 + 0x000] $r2 // MEM_BASE
593 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vram
594 mov $r1 0x10 // chan + 0x0210
596 sethi $r2 0x00020000 // 16 bytes
601 // update current context
602 ld b32 $r1 D[$r0 + xfer_data + 4]
604 ld b32 $r2 D[$r0 + xfer_data + 0]
607 st b32 D[$r0 + ctx_current] $r1
609 // set transfer base to start of context, and fetch context header
613 iowr I[$r2 + 0x000] $r1 // MEM_BASE
617 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vm
619 sethi $r1 0x00060000 // 256 bytes
627 // ctx_chan - handler for HUB_SET_CHAN command, will set a channel as
628 // the active channel for ctxctl, but not actually transfer
629 // any context data. intended for use only during initial
630 // context construction.
632 // In: $r2 channel address
637 mov $r10 12 // DONE_UNK12
642 iowr I[$r1 + 0x000] $r2 // MEM_CMD = 5 (???)
644 iord $r2 I[$r1 + 0x000]
650 // Execute per-context state overrides list
652 // Only executed on the first load of a channel. Might want to look into
653 // removing this and having the host directly modify the channel's context
654 // to change this state... The nouveau DRM already builds this list as
655 // it's definitely needed for NVIDIA's, so we may as well use it for now
657 // Input: $r1 mmio list length
660 // set transfer base to be the mmio list
661 ld b32 $r3 D[$r0 + chan_mmio_address]
664 iowr I[$r2 + 0x000] $r3 // MEM_BASE
668 // fetch next 256 bytes of mmio list if necessary
672 sethi $r5 0x00060000 // 256 bytes
676 // execute a single list entry
678 ld b32 $r14 D[$r4 + xfer_data + 0x00]
679 ld b32 $r15 D[$r4 + xfer_data + 0x04]
687 // set transfer base back to the current context
689 ld b32 $r3 D[$r0 + ctx_current]
690 iowr I[$r2 + 0x000] $r3 // MEM_BASE
692 // disable the mmio list now, we don't need/want to execute it again
693 st b32 D[$r0 + chan_mmio_count] $r0
695 sethi $r1 0x00060000 // 256 bytes
700 // Transfer HUB context data between GPU and storage area
702 // In: $r2 channel address
703 // $p1 clear on save, set on load
704 // $p2 set if opposite direction done/will be done, so:
705 // on save it means: "a load will follow this save"
706 // on load it means: "a save preceeded this load"
709 bra not $p1 ctx_xfer_pre
710 bra $p2 ctx_xfer_pre_load
715 bra not $p1 ctx_xfer_exec
726 // fetch context pointer, and initiate xfer on all GPCs
728 ld b32 $r1 D[$r0 + ctx_current]
731 iowr I[$r2 + 0x000] $r0 // BAR_STATUS = reset
735 call nv_wr32 // GPC_BCAST_WRCMD_DATA = ctx pointer
741 call nv_wr32 // GPC_BCAST_WRCMD_CMD = GPC_XFER(type)
747 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
751 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
754 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
757 xbit $r10 $flags $p1 // direction
758 or $r10 6 // first, last
759 mov $r11 0 // base = 0
760 ld b32 $r12 D[$r0 + hub_mmio_list_head]
761 ld b32 $r13 D[$r0 + hub_mmio_list_tail]
762 mov $r14 0 // not multi
765 // wait for GPCs to all complete
766 mov $r10 8 // DONE_BAR
769 // wait for strand xfer to complete
773 bra $p1 ctx_xfer_post
774 mov $r10 12 // DONE_UNK12
779 iowr I[$r1] $r2 // MEM_CMD
780 ctx_xfer_post_save_wait:
783 bra ne ctx_xfer_post_save_wait
785 bra $p2 ctx_xfer_done
796 bra not $p1 ctx_xfer_no_post_mmio
797 ld b32 $r1 D[$r0 + chan_mmio_count]
799 bra e ctx_xfer_no_post_mmio
802 ctx_xfer_no_post_mmio: