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 hub_mmio_list_head: .b32 #hub_mmio_list_base
28 hub_mmio_list_tail: .b32 #hub_mmio_list_next
38 chan_mmio_count: .b32 0
39 chan_mmio_address: .b32 0
45 .b32 0x0417e91c // 0x17e91c, 2
50 // reports an exception to the host
52 // In: $r15 error code (see nvc0.fuc)
55 nv_iowr(NV_PGRAPH_FECS_CC_SCRATCH_VAL(5), 0, $r15)
57 nv_iowr(NV_PGRAPH_FECS_INTR_UP_SET, 0, $r15)
60 // HUB fuc initialisation, executed by triggering ucode start, will
61 // fall through to main loop after completion.
65 // 31:31: set to signal completion
67 // 31:0: total PGRAPH context size
77 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
79 // setup i0 handler, and route all interrupts to it
83 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
85 // route HUB_CHANNEL_SWITCH to fuc interrupt 8
88 mov $r2 0x2003 // { HUB_CHANNEL_SWITCH, ZERO } -> intr 8
89 iowr I[$r3 + 0x000] $r2
91 // not sure what these are, route them because NVIDIA does, and
92 // the IRQ handler will signal the host if we ever get one.. we
93 // may find out if/why we need to handle these if so..
96 iowr I[$r3 + 0x004] $r2 // { 0x04, ZERO } -> intr 9
98 iowr I[$r3 + 0x008] $r2 // { 0x0b, ZERO } -> intr 10
100 iowr I[$r3 + 0x01c] $r2 // { 0x0c, ZERO } -> intr 15
102 // enable all INTR_UP interrupts
108 // enable fifo, ctxsw, 9, 10, 15 interrupts
109 mov $r2 -0x78fc // 0x8704
111 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
113 // fifo level triggered, rest edge
121 // fetch enabled GPC/ROP counts
122 mov $r14 -0x69fc // 0x409604
126 st b32 D[$r0 + #rop_count] $r1
128 st b32 D[$r0 + #gpc_count] $r15
130 // set BAR_REQMASK to GPC mask
136 iowr I[$r2 + 0x000] $r1
137 iowr I[$r2 + 0x100] $r1
139 // context size calculation, reserve first 256 bytes for use by fuc
142 // calculate size of mmio context data
143 ld b32 $r14 D[$r0 + #hub_mmio_list_head]
144 ld b32 $r15 D[$r0 + #hub_mmio_list_tail]
147 // set mmctx base addresses now so we don't have to do it later,
148 // they don't (currently) ever change
152 iowr I[$r3 + 0x000] $r4 // MMCTX_SAVE_SWBASE
153 iowr I[$r3 + 0x100] $r4 // MMCTX_LOAD_SWBASE
157 iowr I[$r3 + 0x000] $r15 // MMCTX_LOAD_COUNT, wtf for?!?
159 // strands, base offset needs to be aligned to 256 bytes
164 call #strand_ctx_init
167 // initialise each GPC in sequence by passing in the offset of its
168 // context data in GPCn_CC_SCRATCH[1], and starting its FUC (which
169 // has previously been uploaded by the host) running.
171 // the GPC fuc init sequence will set GPCn_CC_SCRATCH[0] bit 31
172 // when it has completed, and return the size of its context data
173 // in GPCn_CC_SCRATCH[1]
175 ld b32 $r3 D[$r0 + #gpc_count]
179 // setup, and start GPC ucode running
180 add b32 $r14 $r4 0x804
182 call #nv_wr32 // CC_SCRATCH[1] = ctx offset
183 add b32 $r14 $r4 0x10c
186 add b32 $r14 $r4 0x104
187 call #nv_wr32 // ENTRY
188 add b32 $r14 $r4 0x100
189 mov $r15 2 // CTRL_START_TRIGGER
190 call #nv_wr32 // CTRL
192 // wait for it to complete, and adjust context size
193 add b32 $r14 $r4 0x800
198 add b32 $r14 $r4 0x804
207 // save context size, and tell host we're ready
208 nv_iowr(NV_PGRAPH_FECS_CC_SCRATCH_VAL(1), 0, $r1)
211 nv_iowr(NV_PGRAPH_FECS_CC_SCRATCH_SET(0), 0, $r1)
213 // Main program loop, very simple, sleeps until woken up by the interrupt
214 // handler, pulls a command from the queue and executes its handler
217 // sleep until we have something to do
224 // context switch, requested by GPU?
226 bra ne #main_not_ctx_switch
230 iord $r2 I[$r1 + 0x100] // CHAN_NEXT
231 iord $r1 I[$r1 + 0x000] // CHAN_CUR
236 bra e #chsw_prev_no_next
268 // ack the context switch request
273 iowr I[$r1 + 0x000] $r2 // 0x409b0c
277 // request to set current channel? (*not* a context switch)
280 bra ne #main_not_ctx_chan
285 // request to store current channel context?
288 bra ne #main_not_ctx_save
298 or $r15 E_BAD_COMMAND
305 nv_iowr(NV_PGRAPH_FECS_CC_SCRATCH_SET(0), 0, $r2)
321 // incoming fifo command?
322 iord $r10 I[$r0 + 0x200] // INTR
323 and $r11 $r10 0x00000004
325 // queue incoming fifo command for later processing
328 iord $r14 I[$r11 + 0x100] // FIFO_CMD
329 iord $r15 I[$r11 + 0x000] // FIFO_DATA
333 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
335 // context switch request?
337 and $r11 $r10 0x00000100
339 // enqueue a context switch for later processing
344 // anything we didn't handle, bring it to the host's attention
352 iowr I[$r10] $r11 // INTR_UP_SET
354 // ack, and wake up main()
356 iowr I[$r0 + 0x100] $r10 // INTR_ACK
371 // Not real sure, but, MEM_CMD 7 will hang forever if this isn't done
380 bra e #ctx_4160s_wait
383 // Without clearing again at end of xfer, some things cause PGRAPH
384 // to hang with STATUS=0x00000007 until it's cleared.. fbcon can
385 // still function with it set however...
394 // Again, not real sure
396 // In: $r15 value to set 0x404170 to
405 // Waits for a ctx_4170s() call to complete
415 // Disables various things, waits a bit, and re-enables them..
417 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
418 // good description for the bits we turn off? Anyways, without this,
419 // funny things happen.
425 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_GPC, POWER_ALL
429 bra ne #ctx_redswitch_delay
431 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_ALL, POWER_ALL
434 // Not a clue what this is for, except that unless the value is 0x10, the
435 // strand context is saved (and presumably restored) incorrectly..
437 // In: $r15 value to set to (0x00/0x10 are used)
442 iowr I[$r14] $r15 // HUB(0x86c) = val
445 call #nv_wr32 // ROP(0xa14) = val
448 call #nv_wr32 // GPC(0x86c) = val
451 // ctx_load - load's a channel's ctxctl data, and selects its vm
453 // In: $r2 channel address
458 // switch to channel, somewhat magic in parts..
459 mov $r10 12 // DONE_UNK12
463 iowr I[$r1 + 0x000] $r0 // 0x409a24
466 iowr I[$r3 + 0x100] $r2 // CHAN_NEXT
470 iowr I[$r1 + 0x000] $r2 // MEM_CHAN
471 iowr I[$r1 + 0x100] $r4 // MEM_CMD
473 iord $r4 I[$r1 + 0x100]
475 bra ne #ctx_chan_wait_0
476 iowr I[$r3 + 0x000] $r2 // CHAN_CUR
478 // load channel header, fetch PGRAPH context pointer
487 iowr I[$r1 + 0x000] $r2 // MEM_BASE
492 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vram
493 mov $r1 0x10 // chan + 0x0210
495 sethi $r2 0x00020000 // 16 bytes
500 // update current context
501 ld b32 $r1 D[$r0 + #xfer_data + 4]
503 ld b32 $r2 D[$r0 + #xfer_data + 0]
506 st b32 D[$r0 + #ctx_current] $r1
508 // set transfer base to start of context, and fetch context header
512 iowr I[$r2 + 0x000] $r1 // MEM_BASE
516 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vm
518 sethi $r1 0x00060000 // 256 bytes
526 // ctx_chan - handler for HUB_SET_CHAN command, will set a channel as
527 // the active channel for ctxctl, but not actually transfer
528 // any context data. intended for use only during initial
529 // context construction.
531 // In: $r2 channel address
538 mov $r10 12 // DONE_UNK12
543 iowr I[$r1 + 0x000] $r2 // MEM_CMD = 5 (???)
545 iord $r2 I[$r1 + 0x000]
547 bra ne #ctx_chan_wait
553 // Execute per-context state overrides list
555 // Only executed on the first load of a channel. Might want to look into
556 // removing this and having the host directly modify the channel's context
557 // to change this state... The nouveau DRM already builds this list as
558 // it's definitely needed for NVIDIA's, so we may as well use it for now
560 // Input: $r1 mmio list length
563 // set transfer base to be the mmio list
564 ld b32 $r3 D[$r0 + #chan_mmio_address]
567 iowr I[$r2 + 0x000] $r3 // MEM_BASE
571 // fetch next 256 bytes of mmio list if necessary
573 bra ne #ctx_mmio_pull
575 sethi $r5 0x00060000 // 256 bytes
579 // execute a single list entry
581 ld b32 $r14 D[$r4 + #xfer_data + 0x00]
582 ld b32 $r15 D[$r4 + #xfer_data + 0x04]
588 bra ne #ctx_mmio_loop
590 // set transfer base back to the current context
592 ld b32 $r3 D[$r0 + #ctx_current]
593 iowr I[$r2 + 0x000] $r3 // MEM_BASE
595 // disable the mmio list now, we don't need/want to execute it again
596 st b32 D[$r0 + #chan_mmio_count] $r0
598 sethi $r1 0x00060000 // 256 bytes
603 // Transfer HUB context data between GPU and storage area
605 // In: $r2 channel address
606 // $p1 clear on save, set on load
607 // $p2 set if opposite direction done/will be done, so:
608 // on save it means: "a load will follow this save"
609 // on load it means: "a save preceeded this load"
612 // according to mwk, some kind of wait for idle
616 iowr I[$r15 + 0x200] $r14
618 iord $r14 I[$r15 + 0x000]
620 bra ne #ctx_xfer_idle
622 bra not $p1 #ctx_xfer_pre
623 bra $p2 #ctx_xfer_pre_load
630 bra not $p1 #ctx_xfer_exec
641 // fetch context pointer, and initiate xfer on all GPCs
643 ld b32 $r1 D[$r0 + #ctx_current]
646 iowr I[$r2 + 0x000] $r0 // BAR_STATUS = reset
650 call #nv_wr32 // GPC_BCAST_WRCMD_DATA = ctx pointer
656 call #nv_wr32 // GPC_BCAST_WRCMD_CMD = GPC_XFER(type)
662 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
666 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
669 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
672 xbit $r10 $flags $p1 // direction
673 or $r10 6 // first, last
674 mov $r11 0 // base = 0
675 ld b32 $r12 D[$r0 + #hub_mmio_list_head]
676 ld b32 $r13 D[$r0 + #hub_mmio_list_tail]
677 mov $r14 0 // not multi
680 // wait for GPCs to all complete
681 mov $r10 8 // DONE_BAR
684 // wait for strand xfer to complete
688 bra $p1 #ctx_xfer_post
689 mov $r10 12 // DONE_UNK12
694 iowr I[$r1] $r2 // MEM_CMD
695 ctx_xfer_post_save_wait:
698 bra ne #ctx_xfer_post_save_wait
700 bra $p2 #ctx_xfer_done
711 bra not $p1 #ctx_xfer_no_post_mmio
712 ld b32 $r1 D[$r0 + #chan_mmio_count]
714 bra e #ctx_xfer_no_post_mmio
717 ctx_xfer_no_post_mmio: