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 hubnvc0.fuc | envyas -a -w -m fuc -V fuc3 -o hubnvc0.fuc.h
30 .section #nvc0_grhub_data
35 hub_mmio_list_head: .b32 0
36 hub_mmio_list_tail: .b32 0
42 chan_mmio_count: .b32 0
43 chan_mmio_address: .b32 0
51 .b16 #nnvc0_hub_mmio_head
52 .b16 #nnvc0_hub_mmio_tail
54 .b16 #nvc0_hub_mmio_head
55 .b16 #nvc1_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 #nvc0_hub_mmio_head
64 .b16 #nvc0_hub_mmio_tail
66 .b16 #nvc0_hub_mmio_head
67 .b16 #nvc0_hub_mmio_tail
69 .b16 #nvc0_hub_mmio_head
70 .b16 #nvc0_hub_mmio_tail
72 .b16 #nvd9_hub_mmio_head
73 .b16 #nvd9_hub_mmio_tail
75 .b16 #nvd9_hub_mmio_head
76 .b16 #nvd9_hub_mmio_tail
80 mmctx_data(0x17e91c, 2)
81 mmctx_data(0x400204, 2)
82 mmctx_data(0x404004, 11)
83 mmctx_data(0x404044, 1)
84 mmctx_data(0x404094, 14)
85 mmctx_data(0x4040d0, 7)
86 mmctx_data(0x4040f8, 1)
87 mmctx_data(0x404130, 3)
88 mmctx_data(0x404150, 3)
89 mmctx_data(0x404164, 2)
90 mmctx_data(0x404174, 3)
91 mmctx_data(0x404200, 8)
92 mmctx_data(0x404404, 14)
93 mmctx_data(0x404460, 4)
94 mmctx_data(0x404480, 1)
95 mmctx_data(0x404498, 1)
96 mmctx_data(0x404604, 4)
97 mmctx_data(0x404618, 32)
98 mmctx_data(0x404698, 21)
99 mmctx_data(0x4046f0, 2)
100 mmctx_data(0x404700, 22)
101 mmctx_data(0x405800, 1)
102 mmctx_data(0x405830, 3)
103 mmctx_data(0x405854, 1)
104 mmctx_data(0x405870, 4)
105 mmctx_data(0x405a00, 2)
106 mmctx_data(0x405a18, 1)
107 mmctx_data(0x406020, 1)
108 mmctx_data(0x406028, 4)
109 mmctx_data(0x4064a8, 2)
110 mmctx_data(0x4064b4, 2)
111 mmctx_data(0x407804, 1)
112 mmctx_data(0x40780c, 6)
113 mmctx_data(0x4078bc, 1)
114 mmctx_data(0x408000, 7)
115 mmctx_data(0x408064, 1)
116 mmctx_data(0x408800, 3)
117 mmctx_data(0x408900, 4)
118 mmctx_data(0x408980, 1)
120 mmctx_data(0x4064c0, 2)
124 mmctx_data(0x17e91c, 2)
125 mmctx_data(0x400204, 2)
126 mmctx_data(0x404004, 11)
127 mmctx_data(0x404044, 1)
128 mmctx_data(0x404094, 14)
129 mmctx_data(0x4040d0, 7)
130 mmctx_data(0x4040f8, 1)
131 mmctx_data(0x404130, 3)
132 mmctx_data(0x404150, 3)
133 mmctx_data(0x404164, 2)
134 mmctx_data(0x404174, 3)
135 mmctx_data(0x404200, 8)
136 mmctx_data(0x404404, 14)
137 mmctx_data(0x404460, 4)
138 mmctx_data(0x404480, 1)
139 mmctx_data(0x404498, 1)
140 mmctx_data(0x404604, 4)
141 mmctx_data(0x404618, 32)
142 mmctx_data(0x404698, 21)
143 mmctx_data(0x4046f0, 2)
144 mmctx_data(0x404700, 22)
145 mmctx_data(0x405800, 1)
146 mmctx_data(0x405830, 3)
147 mmctx_data(0x405854, 1)
148 mmctx_data(0x405870, 4)
149 mmctx_data(0x405a00, 2)
150 mmctx_data(0x405a18, 1)
151 mmctx_data(0x406020, 1)
152 mmctx_data(0x406028, 4)
153 mmctx_data(0x4064a8, 2)
154 mmctx_data(0x4064b4, 2)
155 mmctx_data(0x407804, 1)
156 mmctx_data(0x40780c, 6)
157 mmctx_data(0x4078bc, 1)
158 mmctx_data(0x408000, 7)
159 mmctx_data(0x408064, 1)
160 mmctx_data(0x408800, 3)
161 mmctx_data(0x408900, 3)
162 mmctx_data(0x408980, 1)
166 mmctx_data(0x17e91c, 2)
167 mmctx_data(0x400204, 2)
168 mmctx_data(0x404004, 10)
169 mmctx_data(0x404044, 1)
170 mmctx_data(0x404094, 14)
171 mmctx_data(0x4040d0, 7)
172 mmctx_data(0x4040f8, 1)
173 mmctx_data(0x404130, 3)
174 mmctx_data(0x404150, 3)
175 mmctx_data(0x404164, 2)
176 mmctx_data(0x404178, 2)
177 mmctx_data(0x404200, 8)
178 mmctx_data(0x404404, 14)
179 mmctx_data(0x404460, 4)
180 mmctx_data(0x404480, 1)
181 mmctx_data(0x404498, 1)
182 mmctx_data(0x404604, 4)
183 mmctx_data(0x404618, 32)
184 mmctx_data(0x404698, 21)
185 mmctx_data(0x4046f0, 2)
186 mmctx_data(0x404700, 22)
187 mmctx_data(0x405800, 1)
188 mmctx_data(0x405830, 3)
189 mmctx_data(0x405854, 1)
190 mmctx_data(0x405870, 4)
191 mmctx_data(0x405a00, 2)
192 mmctx_data(0x405a18, 1)
193 mmctx_data(0x406020, 1)
194 mmctx_data(0x406028, 4)
195 mmctx_data(0x4064a8, 2)
196 mmctx_data(0x4064b4, 5)
197 mmctx_data(0x407804, 1)
198 mmctx_data(0x40780c, 6)
199 mmctx_data(0x4078bc, 1)
200 mmctx_data(0x408000, 7)
201 mmctx_data(0x408064, 1)
202 mmctx_data(0x408800, 3)
203 mmctx_data(0x408900, 3)
204 mmctx_data(0x408980, 1)
207 .section #nvc0_grhub_code
209 define(`include_code')
212 // reports an exception to the host
214 // In: $r15 error code (see nvc0.fuc)
220 iowr I[$r14 + 0x000] $r15 // CC_SCRATCH[5] = error code
224 iowr I[$r14 + 0x000] $r15 // INTR_UP_SET
228 // HUB fuc initialisation, executed by triggering ucode start, will
229 // fall through to main loop after completion.
232 // CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
236 // 31:31: set to signal completion
238 // 31:0: total PGRAPH context size
245 // enable fifo access
248 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
250 // setup i0 handler, and route all interrupts to it
254 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
256 // route HUB_CHANNEL_SWITCH to fuc interrupt 8
259 mov $r2 0x2003 // { HUB_CHANNEL_SWITCH, ZERO } -> intr 8
260 iowr I[$r3 + 0x000] $r2
262 // not sure what these are, route them because NVIDIA does, and
263 // the IRQ handler will signal the host if we ever get one.. we
264 // may find out if/why we need to handle these if so..
267 iowr I[$r3 + 0x004] $r2 // { 0x04, ZERO } -> intr 9
269 iowr I[$r3 + 0x008] $r2 // { 0x0b, ZERO } -> intr 10
271 iowr I[$r3 + 0x01c] $r2 // { 0x0c, ZERO } -> intr 15
273 // enable all INTR_UP interrupts
279 // enable fifo, ctxsw, 9, 10, 15 interrupts
280 mov $r2 -0x78fc // 0x8704
282 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
284 // fifo level triggered, rest edge
292 // fetch enabled GPC/ROP counts
293 mov $r14 -0x69fc // 0x409604
297 st b32 D[$r0 + #rop_count] $r1
299 st b32 D[$r0 + #gpc_count] $r15
301 // set BAR_REQMASK to GPC mask
307 iowr I[$r2 + 0x000] $r1
308 iowr I[$r2 + 0x100] $r1
310 // find context data for this chipset
313 iord $r2 I[$r2 + 0x000] // CC_SCRATCH[0]
314 mov $r15 #chipsets - 8
317 ld b32 $r3 D[$r15 + 0x00]
321 bra ne #init_find_chipset
325 // context size calculation, reserve first 256 bytes for use by fuc
329 // calculate size of mmio context data
330 ld b16 $r14 D[$r15 + 4]
331 ld b16 $r15 D[$r15 + 6]
333 st b32 D[$r0 + #hub_mmio_list_head] $r14
334 st b32 D[$r0 + #hub_mmio_list_tail] $r15
337 // set mmctx base addresses now so we don't have to do it later,
338 // they don't (currently) ever change
342 iowr I[$r3 + 0x000] $r4 // MMCTX_SAVE_SWBASE
343 iowr I[$r3 + 0x100] $r4 // MMCTX_LOAD_SWBASE
347 iowr I[$r3 + 0x000] $r15 // MMCTX_LOAD_COUNT, wtf for?!?
349 // strands, base offset needs to be aligned to 256 bytes
354 call #strand_ctx_init
357 // initialise each GPC in sequence by passing in the offset of its
358 // context data in GPCn_CC_SCRATCH[1], and starting its FUC (which
359 // has previously been uploaded by the host) running.
361 // the GPC fuc init sequence will set GPCn_CC_SCRATCH[0] bit 31
362 // when it has completed, and return the size of its context data
363 // in GPCn_CC_SCRATCH[1]
365 ld b32 $r3 D[$r0 + #gpc_count]
369 // setup, and start GPC ucode running
370 add b32 $r14 $r4 0x804
372 call #nv_wr32 // CC_SCRATCH[1] = ctx offset
373 add b32 $r14 $r4 0x800
375 call #nv_wr32 // CC_SCRATCH[0] = chipset
376 add b32 $r14 $r4 0x10c
379 add b32 $r14 $r4 0x104
380 call #nv_wr32 // ENTRY
381 add b32 $r14 $r4 0x100
382 mov $r15 2 // CTRL_START_TRIGGER
383 call #nv_wr32 // CTRL
385 // wait for it to complete, and adjust context size
386 add b32 $r14 $r4 0x800
391 add b32 $r14 $r4 0x804
400 // save context size, and tell host we're ready
403 iowr I[$r2 + 0x100] $r1 // CC_SCRATCH[1] = context size
407 iowr I[$r2 + 0x000] $r1 // CC_SCRATCH[0] |= 0x80000000
409 // Main program loop, very simple, sleeps until woken up by the interrupt
410 // handler, pulls a command from the queue and executes its handler
413 // sleep until we have something to do
420 // context switch, requested by GPU?
422 bra ne #main_not_ctx_switch
426 iord $r2 I[$r1 + 0x100] // CHAN_NEXT
427 iord $r1 I[$r1 + 0x000] // CHAN_CUR
432 bra e #chsw_prev_no_next
464 // ack the context switch request
469 iowr I[$r1 + 0x000] $r2 // 0x409b0c
473 // request to set current channel? (*not* a context switch)
476 bra ne #main_not_ctx_chan
481 // request to store current channel context?
484 bra ne #main_not_ctx_save
494 or $r15 E_BAD_COMMAND
503 iowr I[$r1 + 0x000] $r2 // CC_SCRATCH[0] |= 0x80000000
518 // incoming fifo command?
519 iord $r10 I[$r0 + 0x200] // INTR
520 and $r11 $r10 0x00000004
522 // queue incoming fifo command for later processing
525 iord $r14 I[$r11 + 0x100] // FIFO_CMD
526 iord $r15 I[$r11 + 0x000] // FIFO_DATA
530 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
532 // context switch request?
534 and $r11 $r10 0x00000100
536 // enqueue a context switch for later processing
541 // anything we didn't handle, bring it to the host's attention
549 iowr I[$r10] $r11 // INTR_UP_SET
551 // ack, and wake up main()
553 iowr I[$r0 + 0x100] $r10 // INTR_ACK
567 // Not real sure, but, MEM_CMD 7 will hang forever if this isn't done
576 bra e #ctx_4160s_wait
579 // Without clearing again at end of xfer, some things cause PGRAPH
580 // to hang with STATUS=0x00000007 until it's cleared.. fbcon can
581 // still function with it set however...
589 // Again, not real sure
591 // In: $r15 value to set 0x404170 to
600 // Waits for a ctx_4170s() call to complete
610 // Disables various things, waits a bit, and re-enables them..
612 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
613 // good description for the bits we turn off? Anyways, without this,
614 // funny things happen.
620 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_GPC, POWER_ALL
624 bra ne #ctx_redswitch_delay
626 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_ALL, POWER_ALL
629 // Not a clue what this is for, except that unless the value is 0x10, the
630 // strand context is saved (and presumably restored) incorrectly..
632 // In: $r15 value to set to (0x00/0x10 are used)
637 iowr I[$r14] $r15 // HUB(0x86c) = val
640 call #nv_wr32 // ROP(0xa14) = val
643 call #nv_wr32 // GPC(0x86c) = val
646 // ctx_load - load's a channel's ctxctl data, and selects its vm
648 // In: $r2 channel address
653 // switch to channel, somewhat magic in parts..
654 mov $r10 12 // DONE_UNK12
658 iowr I[$r1 + 0x000] $r0 // 0x409a24
661 iowr I[$r3 + 0x100] $r2 // CHAN_NEXT
665 iowr I[$r1 + 0x000] $r2 // MEM_CHAN
666 iowr I[$r1 + 0x100] $r4 // MEM_CMD
668 iord $r4 I[$r1 + 0x100]
670 bra ne #ctx_chan_wait_0
671 iowr I[$r3 + 0x000] $r2 // CHAN_CUR
673 // load channel header, fetch PGRAPH context pointer
682 iowr I[$r1 + 0x000] $r2 // MEM_BASE
687 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vram
688 mov $r1 0x10 // chan + 0x0210
690 sethi $r2 0x00020000 // 16 bytes
695 // update current context
696 ld b32 $r1 D[$r0 + #xfer_data + 4]
698 ld b32 $r2 D[$r0 + #xfer_data + 0]
701 st b32 D[$r0 + #ctx_current] $r1
703 // set transfer base to start of context, and fetch context header
707 iowr I[$r2 + 0x000] $r1 // MEM_BASE
711 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vm
713 sethi $r1 0x00060000 // 256 bytes
721 // ctx_chan - handler for HUB_SET_CHAN command, will set a channel as
722 // the active channel for ctxctl, but not actually transfer
723 // any context data. intended for use only during initial
724 // context construction.
726 // In: $r2 channel address
731 mov $r10 12 // DONE_UNK12
736 iowr I[$r1 + 0x000] $r2 // MEM_CMD = 5 (???)
738 iord $r2 I[$r1 + 0x000]
740 bra ne #ctx_chan_wait
744 // Execute per-context state overrides list
746 // Only executed on the first load of a channel. Might want to look into
747 // removing this and having the host directly modify the channel's context
748 // to change this state... The nouveau DRM already builds this list as
749 // it's definitely needed for NVIDIA's, so we may as well use it for now
751 // Input: $r1 mmio list length
754 // set transfer base to be the mmio list
755 ld b32 $r3 D[$r0 + #chan_mmio_address]
758 iowr I[$r2 + 0x000] $r3 // MEM_BASE
762 // fetch next 256 bytes of mmio list if necessary
764 bra ne #ctx_mmio_pull
766 sethi $r5 0x00060000 // 256 bytes
770 // execute a single list entry
772 ld b32 $r14 D[$r4 + #xfer_data + 0x00]
773 ld b32 $r15 D[$r4 + #xfer_data + 0x04]
779 bra ne #ctx_mmio_loop
781 // set transfer base back to the current context
783 ld b32 $r3 D[$r0 + #ctx_current]
784 iowr I[$r2 + 0x000] $r3 // MEM_BASE
786 // disable the mmio list now, we don't need/want to execute it again
787 st b32 D[$r0 + #chan_mmio_count] $r0
789 sethi $r1 0x00060000 // 256 bytes
794 // Transfer HUB context data between GPU and storage area
796 // In: $r2 channel address
797 // $p1 clear on save, set on load
798 // $p2 set if opposite direction done/will be done, so:
799 // on save it means: "a load will follow this save"
800 // on load it means: "a save preceeded this load"
803 // according to mwk, some kind of wait for idle
807 iowr I[$r15 + 0x200] $r14
809 iord $r14 I[$r15 + 0x000]
811 bra ne #ctx_xfer_idle
813 bra not $p1 #ctx_xfer_pre
814 bra $p2 #ctx_xfer_pre_load
819 bra not $p1 #ctx_xfer_exec
830 // fetch context pointer, and initiate xfer on all GPCs
832 ld b32 $r1 D[$r0 + #ctx_current]
835 iowr I[$r2 + 0x000] $r0 // BAR_STATUS = reset
839 call #nv_wr32 // GPC_BCAST_WRCMD_DATA = ctx pointer
845 call #nv_wr32 // GPC_BCAST_WRCMD_CMD = GPC_XFER(type)
851 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
855 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
858 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
861 xbit $r10 $flags $p1 // direction
862 or $r10 6 // first, last
863 mov $r11 0 // base = 0
864 ld b32 $r12 D[$r0 + #hub_mmio_list_head]
865 ld b32 $r13 D[$r0 + #hub_mmio_list_tail]
866 mov $r14 0 // not multi
869 // wait for GPCs to all complete
870 mov $r10 8 // DONE_BAR
873 // wait for strand xfer to complete
877 bra $p1 #ctx_xfer_post
878 mov $r10 12 // DONE_UNK12
883 iowr I[$r1] $r2 // MEM_CMD
884 ctx_xfer_post_save_wait:
887 bra ne #ctx_xfer_post_save_wait
889 bra $p2 #ctx_xfer_done
900 bra not $p1 #ctx_xfer_no_post_mmio
901 ld b32 $r1 D[$r0 + #chan_mmio_count]
903 bra e #ctx_xfer_no_post_mmio
906 ctx_xfer_no_post_mmio: