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
60 .b16 #nvc0_hub_mmio_head
61 .b16 #nvc0_hub_mmio_tail
63 .b16 #nvd9_hub_mmio_head
64 .b16 #nvd9_hub_mmio_tail
68 mmctx_data(0x17e91c, 2)
69 mmctx_data(0x400204, 2)
70 mmctx_data(0x404004, 11)
71 mmctx_data(0x404044, 1)
72 mmctx_data(0x404094, 14)
73 mmctx_data(0x4040d0, 7)
74 mmctx_data(0x4040f8, 1)
75 mmctx_data(0x404130, 3)
76 mmctx_data(0x404150, 3)
77 mmctx_data(0x404164, 2)
78 mmctx_data(0x404174, 3)
79 mmctx_data(0x404200, 8)
80 mmctx_data(0x404404, 14)
81 mmctx_data(0x404460, 4)
82 mmctx_data(0x404480, 1)
83 mmctx_data(0x404498, 1)
84 mmctx_data(0x404604, 4)
85 mmctx_data(0x404618, 32)
86 mmctx_data(0x404698, 21)
87 mmctx_data(0x4046f0, 2)
88 mmctx_data(0x404700, 22)
89 mmctx_data(0x405800, 1)
90 mmctx_data(0x405830, 3)
91 mmctx_data(0x405854, 1)
92 mmctx_data(0x405870, 4)
93 mmctx_data(0x405a00, 2)
94 mmctx_data(0x405a18, 1)
95 mmctx_data(0x406020, 1)
96 mmctx_data(0x406028, 4)
97 mmctx_data(0x4064a8, 2)
98 mmctx_data(0x4064b4, 2)
99 mmctx_data(0x407804, 1)
100 mmctx_data(0x40780c, 6)
101 mmctx_data(0x4078bc, 1)
102 mmctx_data(0x408000, 7)
103 mmctx_data(0x408064, 1)
104 mmctx_data(0x408800, 3)
105 mmctx_data(0x408900, 4)
106 mmctx_data(0x408980, 1)
108 mmctx_data(0x4064c0, 2)
112 mmctx_data(0x17e91c, 2)
113 mmctx_data(0x400204, 2)
114 mmctx_data(0x404004, 10)
115 mmctx_data(0x404044, 1)
116 mmctx_data(0x404094, 14)
117 mmctx_data(0x4040d0, 7)
118 mmctx_data(0x4040f8, 1)
119 mmctx_data(0x404130, 3)
120 mmctx_data(0x404150, 3)
121 mmctx_data(0x404164, 2)
122 mmctx_data(0x404178, 2)
123 mmctx_data(0x404200, 8)
124 mmctx_data(0x404404, 14)
125 mmctx_data(0x404460, 4)
126 mmctx_data(0x404480, 1)
127 mmctx_data(0x404498, 1)
128 mmctx_data(0x404604, 4)
129 mmctx_data(0x404618, 32)
130 mmctx_data(0x404698, 21)
131 mmctx_data(0x4046f0, 2)
132 mmctx_data(0x404700, 22)
133 mmctx_data(0x405800, 1)
134 mmctx_data(0x405830, 3)
135 mmctx_data(0x405854, 1)
136 mmctx_data(0x405870, 4)
137 mmctx_data(0x405a00, 2)
138 mmctx_data(0x405a18, 1)
139 mmctx_data(0x406020, 1)
140 mmctx_data(0x406028, 4)
141 mmctx_data(0x4064a8, 2)
142 mmctx_data(0x4064b4, 5)
143 mmctx_data(0x407804, 1)
144 mmctx_data(0x40780c, 6)
145 mmctx_data(0x4078bc, 1)
146 mmctx_data(0x408000, 7)
147 mmctx_data(0x408064, 1)
148 mmctx_data(0x408800, 3)
149 mmctx_data(0x408900, 4)
150 mmctx_data(0x408980, 1)
155 chan_mmio_count: .b32 0
156 chan_mmio_address: .b32 0
161 .section #nvc0_grhub_code
163 define(`include_code')
164 include(`nvc0_graph.fuc')
166 // reports an exception to the host
168 // In: $r15 error code (see nvc0_graph.fuc)
174 iowr I[$r14 + 0x000] $r15 // CC_SCRATCH[5] = error code
178 iowr I[$r14 + 0x000] $r15 // INTR_UP_SET
182 // HUB fuc initialisation, executed by triggering ucode start, will
183 // fall through to main loop after completion.
186 // CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
190 // 31:31: set to signal completion
192 // 31:0: total PGRAPH context size
199 // enable fifo access
202 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
204 // setup i0 handler, and route all interrupts to it
208 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
210 // route HUB_CHANNEL_SWITCH to fuc interrupt 8
213 mov $r2 0x2003 // { HUB_CHANNEL_SWITCH, ZERO } -> intr 8
214 iowr I[$r3 + 0x000] $r2
216 // not sure what these are, route them because NVIDIA does, and
217 // the IRQ handler will signal the host if we ever get one.. we
218 // may find out if/why we need to handle these if so..
221 iowr I[$r3 + 0x004] $r2 // { 0x04, ZERO } -> intr 9
223 iowr I[$r3 + 0x008] $r2 // { 0x0b, ZERO } -> intr 10
225 iowr I[$r3 + 0x01c] $r2 // { 0x0c, ZERO } -> intr 15
227 // enable all INTR_UP interrupts
233 // enable fifo, ctxsw, 9, 10, 15 interrupts
234 mov $r2 -0x78fc // 0x8704
236 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
238 // fifo level triggered, rest edge
246 // fetch enabled GPC/ROP counts
247 mov $r14 -0x69fc // 0x409604
251 st b32 D[$r0 + #rop_count] $r1
253 st b32 D[$r0 + #gpc_count] $r15
255 // set BAR_REQMASK to GPC mask
261 iowr I[$r2 + 0x000] $r1
262 iowr I[$r2 + 0x100] $r1
264 // find context data for this chipset
267 iord $r2 I[$r2 + 0x000] // CC_SCRATCH[0]
268 mov $r15 #chipsets - 8
271 ld b32 $r3 D[$r15 + 0x00]
275 bra ne #init_find_chipset
279 // context size calculation, reserve first 256 bytes for use by fuc
283 // calculate size of mmio context data
284 ld b16 $r14 D[$r15 + 4]
285 ld b16 $r15 D[$r15 + 6]
287 st b32 D[$r0 + #hub_mmio_list_head] $r14
288 st b32 D[$r0 + #hub_mmio_list_tail] $r15
291 // set mmctx base addresses now so we don't have to do it later,
292 // they don't (currently) ever change
296 iowr I[$r3 + 0x000] $r4 // MMCTX_SAVE_SWBASE
297 iowr I[$r3 + 0x100] $r4 // MMCTX_LOAD_SWBASE
301 iowr I[$r3 + 0x000] $r15 // MMCTX_LOAD_COUNT, wtf for?!?
303 // strands, base offset needs to be aligned to 256 bytes
308 call #strand_ctx_init
311 // initialise each GPC in sequence by passing in the offset of its
312 // context data in GPCn_CC_SCRATCH[1], and starting its FUC (which
313 // has previously been uploaded by the host) running.
315 // the GPC fuc init sequence will set GPCn_CC_SCRATCH[0] bit 31
316 // when it has completed, and return the size of its context data
317 // in GPCn_CC_SCRATCH[1]
319 ld b32 $r3 D[$r0 + #gpc_count]
323 // setup, and start GPC ucode running
324 add b32 $r14 $r4 0x804
326 call #nv_wr32 // CC_SCRATCH[1] = ctx offset
327 add b32 $r14 $r4 0x800
329 call #nv_wr32 // CC_SCRATCH[0] = chipset
330 add b32 $r14 $r4 0x10c
333 add b32 $r14 $r4 0x104
334 call #nv_wr32 // ENTRY
335 add b32 $r14 $r4 0x100
336 mov $r15 2 // CTRL_START_TRIGGER
337 call #nv_wr32 // CTRL
339 // wait for it to complete, and adjust context size
340 add b32 $r14 $r4 0x800
345 add b32 $r14 $r4 0x804
354 // save context size, and tell host we're ready
357 iowr I[$r2 + 0x100] $r1 // CC_SCRATCH[1] = context size
361 iowr I[$r2 + 0x000] $r1 // CC_SCRATCH[0] |= 0x80000000
363 // Main program loop, very simple, sleeps until woken up by the interrupt
364 // handler, pulls a command from the queue and executes its handler
367 // sleep until we have something to do
374 // context switch, requested by GPU?
376 bra ne #main_not_ctx_switch
380 iord $r2 I[$r1 + 0x100] // CHAN_NEXT
381 iord $r1 I[$r1 + 0x000] // CHAN_CUR
386 bra e #chsw_prev_no_next
418 // ack the context switch request
423 iowr I[$r1 + 0x000] $r2 // 0x409b0c
427 // request to set current channel? (*not* a context switch)
430 bra ne #main_not_ctx_chan
435 // request to store current channel context?
438 bra ne #main_not_ctx_save
448 or $r15 E_BAD_COMMAND
457 iowr I[$r1 + 0x000] $r2 // CC_SCRATCH[0] |= 0x80000000
472 // incoming fifo command?
473 iord $r10 I[$r0 + 0x200] // INTR
474 and $r11 $r10 0x00000004
476 // queue incoming fifo command for later processing
479 iord $r14 I[$r11 + 0x100] // FIFO_CMD
480 iord $r15 I[$r11 + 0x000] // FIFO_DATA
484 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
486 // context switch request?
488 and $r11 $r10 0x00000100
490 // enqueue a context switch for later processing
495 // anything we didn't handle, bring it to the host's attention
503 iowr I[$r10] $r11 // INTR_UP_SET
505 // ack, and wake up main()
507 iowr I[$r0 + 0x100] $r10 // INTR_ACK
521 // Not real sure, but, MEM_CMD 7 will hang forever if this isn't done
530 bra e #ctx_4160s_wait
533 // Without clearing again at end of xfer, some things cause PGRAPH
534 // to hang with STATUS=0x00000007 until it's cleared.. fbcon can
535 // still function with it set however...
543 // Again, not real sure
545 // In: $r15 value to set 0x404170 to
554 // Waits for a ctx_4170s() call to complete
564 // Disables various things, waits a bit, and re-enables them..
566 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
567 // good description for the bits we turn off? Anyways, without this,
568 // funny things happen.
574 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_GPC, POWER_ALL
578 bra ne #ctx_redswitch_delay
580 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_ALL, POWER_ALL
583 // Not a clue what this is for, except that unless the value is 0x10, the
584 // strand context is saved (and presumably restored) incorrectly..
586 // In: $r15 value to set to (0x00/0x10 are used)
591 iowr I[$r14] $r15 // HUB(0x86c) = val
594 call #nv_wr32 // ROP(0xa14) = val
597 call #nv_wr32 // GPC(0x86c) = val
600 // ctx_load - load's a channel's ctxctl data, and selects its vm
602 // In: $r2 channel address
607 // switch to channel, somewhat magic in parts..
608 mov $r10 12 // DONE_UNK12
612 iowr I[$r1 + 0x000] $r0 // 0x409a24
615 iowr I[$r3 + 0x100] $r2 // CHAN_NEXT
619 iowr I[$r1 + 0x000] $r2 // MEM_CHAN
620 iowr I[$r1 + 0x100] $r4 // MEM_CMD
622 iord $r4 I[$r1 + 0x100]
624 bra ne #ctx_chan_wait_0
625 iowr I[$r3 + 0x000] $r2 // CHAN_CUR
627 // load channel header, fetch PGRAPH context pointer
636 iowr I[$r1 + 0x000] $r2 // MEM_BASE
641 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vram
642 mov $r1 0x10 // chan + 0x0210
644 sethi $r2 0x00020000 // 16 bytes
649 // update current context
650 ld b32 $r1 D[$r0 + #xfer_data + 4]
652 ld b32 $r2 D[$r0 + #xfer_data + 0]
655 st b32 D[$r0 + #ctx_current] $r1
657 // set transfer base to start of context, and fetch context header
661 iowr I[$r2 + 0x000] $r1 // MEM_BASE
665 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vm
667 sethi $r1 0x00060000 // 256 bytes
675 // ctx_chan - handler for HUB_SET_CHAN command, will set a channel as
676 // the active channel for ctxctl, but not actually transfer
677 // any context data. intended for use only during initial
678 // context construction.
680 // In: $r2 channel address
685 mov $r10 12 // DONE_UNK12
690 iowr I[$r1 + 0x000] $r2 // MEM_CMD = 5 (???)
692 iord $r2 I[$r1 + 0x000]
694 bra ne #ctx_chan_wait
698 // Execute per-context state overrides list
700 // Only executed on the first load of a channel. Might want to look into
701 // removing this and having the host directly modify the channel's context
702 // to change this state... The nouveau DRM already builds this list as
703 // it's definitely needed for NVIDIA's, so we may as well use it for now
705 // Input: $r1 mmio list length
708 // set transfer base to be the mmio list
709 ld b32 $r3 D[$r0 + #chan_mmio_address]
712 iowr I[$r2 + 0x000] $r3 // MEM_BASE
716 // fetch next 256 bytes of mmio list if necessary
718 bra ne #ctx_mmio_pull
720 sethi $r5 0x00060000 // 256 bytes
724 // execute a single list entry
726 ld b32 $r14 D[$r4 + #xfer_data + 0x00]
727 ld b32 $r15 D[$r4 + #xfer_data + 0x04]
733 bra ne #ctx_mmio_loop
735 // set transfer base back to the current context
737 ld b32 $r3 D[$r0 + #ctx_current]
738 iowr I[$r2 + 0x000] $r3 // MEM_BASE
740 // disable the mmio list now, we don't need/want to execute it again
741 st b32 D[$r0 + #chan_mmio_count] $r0
743 sethi $r1 0x00060000 // 256 bytes
748 // Transfer HUB context data between GPU and storage area
750 // In: $r2 channel address
751 // $p1 clear on save, set on load
752 // $p2 set if opposite direction done/will be done, so:
753 // on save it means: "a load will follow this save"
754 // on load it means: "a save preceeded this load"
757 bra not $p1 #ctx_xfer_pre
758 bra $p2 #ctx_xfer_pre_load
763 bra not $p1 #ctx_xfer_exec
774 // fetch context pointer, and initiate xfer on all GPCs
776 ld b32 $r1 D[$r0 + #ctx_current]
779 iowr I[$r2 + 0x000] $r0 // BAR_STATUS = reset
783 call #nv_wr32 // GPC_BCAST_WRCMD_DATA = ctx pointer
789 call #nv_wr32 // GPC_BCAST_WRCMD_CMD = GPC_XFER(type)
795 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
799 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
802 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
805 xbit $r10 $flags $p1 // direction
806 or $r10 6 // first, last
807 mov $r11 0 // base = 0
808 ld b32 $r12 D[$r0 + #hub_mmio_list_head]
809 ld b32 $r13 D[$r0 + #hub_mmio_list_tail]
810 mov $r14 0 // not multi
813 // wait for GPCs to all complete
814 mov $r10 8 // DONE_BAR
817 // wait for strand xfer to complete
821 bra $p1 #ctx_xfer_post
822 mov $r10 12 // DONE_UNK12
827 iowr I[$r1] $r2 // MEM_CMD
828 ctx_xfer_post_save_wait:
831 bra ne #ctx_xfer_post_save_wait
833 bra $p2 #ctx_xfer_done
844 bra not $p1 #ctx_xfer_no_post_mmio
845 ld b32 $r1 D[$r0 + #chan_mmio_count]
847 bra e #ctx_xfer_no_post_mmio
850 ctx_xfer_no_post_mmio: