1 /* fuc microcode for nve0 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 nve0_grhub.fuc | envyas -a -w -m fuc -V nva3 -o nve0_grhub.fuc.h
30 .section #nve0_grhub_data
35 hub_mmio_list_head: .b32 0
36 hub_mmio_list_tail: .b32 0
42 .b16 #nve4_hub_mmio_head
43 .b16 #nve4_hub_mmio_tail
45 .b16 #nve4_hub_mmio_head
46 .b16 #nve4_hub_mmio_tail
48 .b16 #nve4_hub_mmio_head
49 .b16 #nve4_hub_mmio_tail
53 mmctx_data(0x17e91c, 2)
54 mmctx_data(0x400204, 2)
55 mmctx_data(0x404010, 7)
56 mmctx_data(0x4040a8, 9)
57 mmctx_data(0x4040d0, 7)
58 mmctx_data(0x4040f8, 1)
59 mmctx_data(0x404130, 3)
60 mmctx_data(0x404150, 3)
61 mmctx_data(0x404164, 1)
62 mmctx_data(0x4041a0, 4)
63 mmctx_data(0x404200, 4)
64 mmctx_data(0x404404, 14)
65 mmctx_data(0x404460, 4)
66 mmctx_data(0x404480, 1)
67 mmctx_data(0x404498, 1)
68 mmctx_data(0x404604, 4)
69 mmctx_data(0x404618, 4)
70 mmctx_data(0x40462c, 2)
71 mmctx_data(0x404640, 1)
72 mmctx_data(0x404654, 1)
73 mmctx_data(0x404660, 1)
74 mmctx_data(0x404678, 19)
75 mmctx_data(0x4046c8, 3)
76 mmctx_data(0x404700, 3)
77 mmctx_data(0x404718, 10)
78 mmctx_data(0x404744, 2)
79 mmctx_data(0x404754, 1)
80 mmctx_data(0x405800, 1)
81 mmctx_data(0x405830, 3)
82 mmctx_data(0x405854, 1)
83 mmctx_data(0x405870, 4)
84 mmctx_data(0x405a00, 2)
85 mmctx_data(0x405a18, 1)
86 mmctx_data(0x405b00, 1)
87 mmctx_data(0x405b10, 1)
88 mmctx_data(0x406020, 1)
89 mmctx_data(0x406028, 4)
90 mmctx_data(0x4064a8, 2)
91 mmctx_data(0x4064b4, 2)
92 mmctx_data(0x4064c0, 12)
93 mmctx_data(0x4064fc, 1)
94 mmctx_data(0x407040, 1)
95 mmctx_data(0x407804, 1)
96 mmctx_data(0x40780c, 6)
97 mmctx_data(0x4078bc, 1)
98 mmctx_data(0x408000, 7)
99 mmctx_data(0x408064, 1)
100 mmctx_data(0x408800, 3)
101 mmctx_data(0x408840, 1)
102 mmctx_data(0x408900, 3)
103 mmctx_data(0x408980, 1)
108 chan_mmio_count: .b32 0
109 chan_mmio_address: .b32 0
114 .section #nve0_grhub_code
116 define(`include_code')
119 // reports an exception to the host
121 // In: $r15 error code (see nve0.fuc)
127 iowr I[$r14 + 0x000] $r15 // CC_SCRATCH[5] = error code
131 iowr I[$r14 + 0x000] $r15 // INTR_UP_SET
135 // HUB fuc initialisation, executed by triggering ucode start, will
136 // fall through to main loop after completion.
139 // CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
143 // 31:31: set to signal completion
145 // 31:0: total PGRAPH context size
152 // enable fifo access
155 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
157 // setup i0 handler, and route all interrupts to it
161 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
163 // route HUB_CHANNEL_SWITCH to fuc interrupt 8
166 mov $r2 0x2003 // { HUB_CHANNEL_SWITCH, ZERO } -> intr 8
167 iowr I[$r3 + 0x000] $r2
169 // not sure what these are, route them because NVIDIA does, and
170 // the IRQ handler will signal the host if we ever get one.. we
171 // may find out if/why we need to handle these if so..
174 iowr I[$r3 + 0x004] $r2 // { 0x04, ZERO } -> intr 9
176 iowr I[$r3 + 0x008] $r2 // { 0x0b, ZERO } -> intr 10
178 iowr I[$r3 + 0x01c] $r2 // { 0x0c, ZERO } -> intr 15
180 // enable all INTR_UP interrupts
186 // enable fifo, ctxsw, 9, 10, 15 interrupts
187 mov $r2 -0x78fc // 0x8704
189 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
191 // fifo level triggered, rest edge
199 // fetch enabled GPC/ROP counts
200 mov $r14 -0x69fc // 0x409604
204 st b32 D[$r0 + #rop_count] $r1
206 st b32 D[$r0 + #gpc_count] $r15
208 // set BAR_REQMASK to GPC mask
214 iowr I[$r2 + 0x000] $r1
215 iowr I[$r2 + 0x100] $r1
217 // find context data for this chipset
220 iord $r2 I[$r2 + 0x000] // CC_SCRATCH[0]
221 mov $r15 #chipsets - 8
224 ld b32 $r3 D[$r15 + 0x00]
228 bra ne #init_find_chipset
232 // context size calculation, reserve first 256 bytes for use by fuc
236 // calculate size of mmio context data
237 ld b16 $r14 D[$r15 + 4]
238 ld b16 $r15 D[$r15 + 6]
240 st b32 D[$r0 + #hub_mmio_list_head] $r14
241 st b32 D[$r0 + #hub_mmio_list_tail] $r15
244 // set mmctx base addresses now so we don't have to do it later,
245 // they don't (currently) ever change
249 iowr I[$r3 + 0x000] $r4 // MMCTX_SAVE_SWBASE
250 iowr I[$r3 + 0x100] $r4 // MMCTX_LOAD_SWBASE
254 iowr I[$r3 + 0x000] $r15 // MMCTX_LOAD_COUNT, wtf for?!?
256 // strands, base offset needs to be aligned to 256 bytes
261 call #strand_ctx_init
264 // initialise each GPC in sequence by passing in the offset of its
265 // context data in GPCn_CC_SCRATCH[1], and starting its FUC (which
266 // has previously been uploaded by the host) running.
268 // the GPC fuc init sequence will set GPCn_CC_SCRATCH[0] bit 31
269 // when it has completed, and return the size of its context data
270 // in GPCn_CC_SCRATCH[1]
272 ld b32 $r3 D[$r0 + #gpc_count]
276 // setup, and start GPC ucode running
277 add b32 $r14 $r4 0x804
279 call #nv_wr32 // CC_SCRATCH[1] = ctx offset
280 add b32 $r14 $r4 0x800
282 call #nv_wr32 // CC_SCRATCH[0] = chipset
283 add b32 $r14 $r4 0x10c
286 add b32 $r14 $r4 0x104
287 call #nv_wr32 // ENTRY
288 add b32 $r14 $r4 0x100
289 mov $r15 2 // CTRL_START_TRIGGER
290 call #nv_wr32 // CTRL
292 // wait for it to complete, and adjust context size
293 add b32 $r14 $r4 0x800
298 add b32 $r14 $r4 0x804
307 // save context size, and tell host we're ready
310 iowr I[$r2 + 0x100] $r1 // CC_SCRATCH[1] = context size
314 iowr I[$r2 + 0x000] $r1 // CC_SCRATCH[0] |= 0x80000000
316 // Main program loop, very simple, sleeps until woken up by the interrupt
317 // handler, pulls a command from the queue and executes its handler
320 // sleep until we have something to do
327 // context switch, requested by GPU?
329 bra ne #main_not_ctx_switch
333 iord $r2 I[$r1 + 0x100] // CHAN_NEXT
334 iord $r1 I[$r1 + 0x000] // CHAN_CUR
339 bra e #chsw_prev_no_next
371 // ack the context switch request
376 iowr I[$r1 + 0x000] $r2 // 0x409b0c
380 // request to set current channel? (*not* a context switch)
383 bra ne #main_not_ctx_chan
388 // request to store current channel context?
391 bra ne #main_not_ctx_save
401 or $r15 E_BAD_COMMAND
410 iowr I[$r1 + 0x000] $r2 // CC_SCRATCH[0] |= 0x80000000
425 // incoming fifo command?
426 iord $r10 I[$r0 + 0x200] // INTR
427 and $r11 $r10 0x00000004
429 // queue incoming fifo command for later processing
432 iord $r14 I[$r11 + 0x100] // FIFO_CMD
433 iord $r15 I[$r11 + 0x000] // FIFO_DATA
437 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
439 // context switch request?
441 and $r11 $r10 0x00000100
443 // enqueue a context switch for later processing
448 // anything we didn't handle, bring it to the host's attention
456 iowr I[$r10] $r11 // INTR_UP_SET
458 // ack, and wake up main()
460 iowr I[$r0 + 0x100] $r10 // INTR_ACK
474 // Again, not real sure
476 // In: $r15 value to set 0x404170 to
485 // Waits for a ctx_4170s() call to complete
495 // Disables various things, waits a bit, and re-enables them..
497 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
498 // good description for the bits we turn off? Anyways, without this,
499 // funny things happen.
505 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_GPC, POWER_ALL
509 bra ne #ctx_redswitch_delay
511 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_ALL, POWER_ALL
514 // Not a clue what this is for, except that unless the value is 0x10, the
515 // strand context is saved (and presumably restored) incorrectly..
517 // In: $r15 value to set to (0x00/0x10 are used)
522 iowr I[$r14] $r15 // HUB(0x86c) = val
525 call #nv_wr32 // ROP(0xa14) = val
528 call #nv_wr32 // GPC(0x86c) = val
531 // ctx_load - load's a channel's ctxctl data, and selects its vm
533 // In: $r2 channel address
538 // switch to channel, somewhat magic in parts..
539 mov $r10 12 // DONE_UNK12
543 iowr I[$r1 + 0x000] $r0 // 0x409a24
546 iowr I[$r3 + 0x100] $r2 // CHAN_NEXT
550 iowr I[$r1 + 0x000] $r2 // MEM_CHAN
551 iowr I[$r1 + 0x100] $r4 // MEM_CMD
553 iord $r4 I[$r1 + 0x100]
555 bra ne #ctx_chan_wait_0
556 iowr I[$r3 + 0x000] $r2 // CHAN_CUR
558 // load channel header, fetch PGRAPH context pointer
567 iowr I[$r1 + 0x000] $r2 // MEM_BASE
572 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vram
573 mov $r1 0x10 // chan + 0x0210
575 sethi $r2 0x00020000 // 16 bytes
580 // update current context
581 ld b32 $r1 D[$r0 + #xfer_data + 4]
583 ld b32 $r2 D[$r0 + #xfer_data + 0]
586 st b32 D[$r0 + #ctx_current] $r1
588 // set transfer base to start of context, and fetch context header
592 iowr I[$r2 + 0x000] $r1 // MEM_BASE
596 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vm
598 sethi $r1 0x00060000 // 256 bytes
606 // ctx_chan - handler for HUB_SET_CHAN command, will set a channel as
607 // the active channel for ctxctl, but not actually transfer
608 // any context data. intended for use only during initial
609 // context construction.
611 // In: $r2 channel address
615 mov $r10 12 // DONE_UNK12
620 iowr I[$r1 + 0x000] $r2 // MEM_CMD = 5 (???)
622 iord $r2 I[$r1 + 0x000]
624 bra ne #ctx_chan_wait
627 // Execute per-context state overrides list
629 // Only executed on the first load of a channel. Might want to look into
630 // removing this and having the host directly modify the channel's context
631 // to change this state... The nouveau DRM already builds this list as
632 // it's definitely needed for NVIDIA's, so we may as well use it for now
634 // Input: $r1 mmio list length
637 // set transfer base to be the mmio list
638 ld b32 $r3 D[$r0 + #chan_mmio_address]
641 iowr I[$r2 + 0x000] $r3 // MEM_BASE
645 // fetch next 256 bytes of mmio list if necessary
647 bra ne #ctx_mmio_pull
649 sethi $r5 0x00060000 // 256 bytes
653 // execute a single list entry
655 ld b32 $r14 D[$r4 + #xfer_data + 0x00]
656 ld b32 $r15 D[$r4 + #xfer_data + 0x04]
662 bra ne #ctx_mmio_loop
664 // set transfer base back to the current context
666 ld b32 $r3 D[$r0 + #ctx_current]
667 iowr I[$r2 + 0x000] $r3 // MEM_BASE
669 // disable the mmio list now, we don't need/want to execute it again
670 st b32 D[$r0 + #chan_mmio_count] $r0
672 sethi $r1 0x00060000 // 256 bytes
677 // Transfer HUB context data between GPU and storage area
679 // In: $r2 channel address
680 // $p1 clear on save, set on load
681 // $p2 set if opposite direction done/will be done, so:
682 // on save it means: "a load will follow this save"
683 // on load it means: "a save preceeded this load"
686 // according to mwk, some kind of wait for idle
690 iowr I[$r15 + 0x200] $r14
692 iord $r14 I[$r15 + 0x000]
694 bra ne #ctx_xfer_idle
696 bra not $p1 #ctx_xfer_pre
697 bra $p2 #ctx_xfer_pre_load
701 bra not $p1 #ctx_xfer_exec
712 // fetch context pointer, and initiate xfer on all GPCs
714 ld b32 $r1 D[$r0 + #ctx_current]
717 iowr I[$r2 + 0x000] $r0 // BAR_STATUS = reset
721 call #nv_wr32 // GPC_BCAST_WRCMD_DATA = ctx pointer
727 call #nv_wr32 // GPC_BCAST_WRCMD_CMD = GPC_XFER(type)
733 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
737 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
740 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
743 xbit $r10 $flags $p1 // direction
744 or $r10 6 // first, last
745 mov $r11 0 // base = 0
746 ld b32 $r12 D[$r0 + #hub_mmio_list_head]
747 ld b32 $r13 D[$r0 + #hub_mmio_list_tail]
748 mov $r14 0 // not multi
751 // wait for GPCs to all complete
752 mov $r10 8 // DONE_BAR
755 // wait for strand xfer to complete
759 bra $p1 #ctx_xfer_post
760 mov $r10 12 // DONE_UNK12
765 iowr I[$r1] $r2 // MEM_CMD
766 ctx_xfer_post_save_wait:
769 bra ne #ctx_xfer_post_save_wait
771 bra $p2 #ctx_xfer_done
782 bra not $p1 #ctx_xfer_no_post_mmio
783 ld b32 $r1 D[$r0 + #chan_mmio_count]
785 bra e #ctx_xfer_no_post_mmio
788 ctx_xfer_no_post_mmio: