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 chan_mmio_count: .b32 0
43 chan_mmio_address: .b32 0
51 .b16 #nve4_hub_mmio_head
52 .b16 #nve4_hub_mmio_tail
54 .b16 #nve4_hub_mmio_head
55 .b16 #nve4_hub_mmio_tail
57 .b16 #nve4_hub_mmio_head
58 .b16 #nve4_hub_mmio_tail
60 .b16 #nvf0_hub_mmio_head
61 .b16 #nvf0_hub_mmio_tail
65 mmctx_data(0x17e91c, 2)
66 mmctx_data(0x400204, 2)
67 mmctx_data(0x404010, 7)
68 mmctx_data(0x4040a8, 9)
69 mmctx_data(0x4040d0, 7)
70 mmctx_data(0x4040f8, 1)
71 mmctx_data(0x404130, 3)
72 mmctx_data(0x404150, 3)
73 mmctx_data(0x404164, 1)
74 mmctx_data(0x4041a0, 4)
75 mmctx_data(0x404200, 4)
76 mmctx_data(0x404404, 14)
77 mmctx_data(0x404460, 4)
78 mmctx_data(0x404480, 1)
79 mmctx_data(0x404498, 1)
80 mmctx_data(0x404604, 4)
81 mmctx_data(0x404618, 4)
82 mmctx_data(0x40462c, 2)
83 mmctx_data(0x404640, 1)
84 mmctx_data(0x404654, 1)
85 mmctx_data(0x404660, 1)
86 mmctx_data(0x404678, 19)
87 mmctx_data(0x4046c8, 3)
88 mmctx_data(0x404700, 3)
89 mmctx_data(0x404718, 10)
90 mmctx_data(0x404744, 2)
91 mmctx_data(0x404754, 1)
92 mmctx_data(0x405800, 1)
93 mmctx_data(0x405830, 3)
94 mmctx_data(0x405854, 1)
95 mmctx_data(0x405870, 4)
96 mmctx_data(0x405a00, 2)
97 mmctx_data(0x405a18, 1)
98 mmctx_data(0x405b00, 1)
99 mmctx_data(0x405b10, 1)
100 mmctx_data(0x406020, 1)
101 mmctx_data(0x406028, 4)
102 mmctx_data(0x4064a8, 2)
103 mmctx_data(0x4064b4, 2)
104 mmctx_data(0x4064c0, 12)
105 mmctx_data(0x4064fc, 1)
106 mmctx_data(0x407040, 1)
107 mmctx_data(0x407804, 1)
108 mmctx_data(0x40780c, 6)
109 mmctx_data(0x4078bc, 1)
110 mmctx_data(0x408000, 7)
111 mmctx_data(0x408064, 1)
112 mmctx_data(0x408800, 3)
113 mmctx_data(0x408840, 1)
114 mmctx_data(0x408900, 3)
115 mmctx_data(0x408980, 1)
119 mmctx_data(0x17e91c, 2)
120 mmctx_data(0x400204, 2)
121 mmctx_data(0x404004, 17)
122 mmctx_data(0x4040a8, 9)
123 mmctx_data(0x4040d0, 7)
124 mmctx_data(0x4040f8, 1)
125 mmctx_data(0x404100, 10)
126 mmctx_data(0x404130, 3)
127 mmctx_data(0x404150, 3)
128 mmctx_data(0x404164, 1)
129 mmctx_data(0x40417c, 2)
130 mmctx_data(0x4041a0, 4)
131 mmctx_data(0x404200, 4)
132 mmctx_data(0x404404, 12)
133 mmctx_data(0x404438, 1)
134 mmctx_data(0x404460, 4)
135 mmctx_data(0x404480, 1)
136 mmctx_data(0x404498, 1)
137 mmctx_data(0x404604, 4)
138 mmctx_data(0x404618, 4)
139 mmctx_data(0x40462c, 2)
140 mmctx_data(0x404640, 1)
141 mmctx_data(0x404654, 1)
142 mmctx_data(0x404660, 1)
143 mmctx_data(0x404678, 19)
144 mmctx_data(0x4046c8, 3)
145 mmctx_data(0x404700, 3)
146 mmctx_data(0x404718, 10)
147 mmctx_data(0x404744, 2)
148 mmctx_data(0x404754, 1)
149 mmctx_data(0x405800, 1)
150 mmctx_data(0x405830, 3)
151 mmctx_data(0x405854, 1)
152 mmctx_data(0x405870, 4)
153 mmctx_data(0x405a00, 2)
154 mmctx_data(0x405a18, 1)
155 mmctx_data(0x405b00, 1)
156 mmctx_data(0x405b10, 1)
157 mmctx_data(0x405b20, 1)
158 mmctx_data(0x406020, 1)
159 mmctx_data(0x406028, 4)
160 mmctx_data(0x4064a8, 5)
161 mmctx_data(0x4064c0, 12)
162 mmctx_data(0x4064fc, 1)
163 mmctx_data(0x407804, 1)
164 mmctx_data(0x40780c, 6)
165 mmctx_data(0x4078bc, 1)
166 mmctx_data(0x408000, 7)
167 mmctx_data(0x408064, 1)
168 mmctx_data(0x408800, 3)
169 mmctx_data(0x408840, 1)
170 mmctx_data(0x408900, 3)
171 mmctx_data(0x408980, 1)
174 .section #nve0_grhub_code
176 define(`include_code')
179 // reports an exception to the host
181 // In: $r15 error code (see nve0.fuc)
187 iowr I[$r14 + 0x000] $r15 // CC_SCRATCH[5] = error code
191 iowr I[$r14 + 0x000] $r15 // INTR_UP_SET
195 // HUB fuc initialisation, executed by triggering ucode start, will
196 // fall through to main loop after completion.
199 // CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
203 // 31:31: set to signal completion
205 // 31:0: total PGRAPH context size
212 // enable fifo access
215 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
217 // setup i0 handler, and route all interrupts to it
221 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
223 // route HUB_CHANNEL_SWITCH to fuc interrupt 8
226 mov $r2 0x2003 // { HUB_CHANNEL_SWITCH, ZERO } -> intr 8
227 iowr I[$r3 + 0x000] $r2
229 // not sure what these are, route them because NVIDIA does, and
230 // the IRQ handler will signal the host if we ever get one.. we
231 // may find out if/why we need to handle these if so..
234 iowr I[$r3 + 0x004] $r2 // { 0x04, ZERO } -> intr 9
236 iowr I[$r3 + 0x008] $r2 // { 0x0b, ZERO } -> intr 10
238 iowr I[$r3 + 0x01c] $r2 // { 0x0c, ZERO } -> intr 15
240 // enable all INTR_UP interrupts
246 // enable fifo, ctxsw, 9, 10, 15 interrupts
247 mov $r2 -0x78fc // 0x8704
249 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
251 // fifo level triggered, rest edge
259 // fetch enabled GPC/ROP counts
260 mov $r14 -0x69fc // 0x409604
264 st b32 D[$r0 + #rop_count] $r1
266 st b32 D[$r0 + #gpc_count] $r15
268 // set BAR_REQMASK to GPC mask
274 iowr I[$r2 + 0x000] $r1
275 iowr I[$r2 + 0x100] $r1
277 // find context data for this chipset
280 iord $r2 I[$r2 + 0x000] // CC_SCRATCH[0]
281 mov $r15 #chipsets - 8
284 ld b32 $r3 D[$r15 + 0x00]
288 bra ne #init_find_chipset
292 // context size calculation, reserve first 256 bytes for use by fuc
296 // calculate size of mmio context data
297 ld b16 $r14 D[$r15 + 4]
298 ld b16 $r15 D[$r15 + 6]
300 st b32 D[$r0 + #hub_mmio_list_head] $r14
301 st b32 D[$r0 + #hub_mmio_list_tail] $r15
304 // set mmctx base addresses now so we don't have to do it later,
305 // they don't (currently) ever change
309 iowr I[$r3 + 0x000] $r4 // MMCTX_SAVE_SWBASE
310 iowr I[$r3 + 0x100] $r4 // MMCTX_LOAD_SWBASE
314 iowr I[$r3 + 0x000] $r15 // MMCTX_LOAD_COUNT, wtf for?!?
316 // strands, base offset needs to be aligned to 256 bytes
321 call #strand_ctx_init
324 // initialise each GPC in sequence by passing in the offset of its
325 // context data in GPCn_CC_SCRATCH[1], and starting its FUC (which
326 // has previously been uploaded by the host) running.
328 // the GPC fuc init sequence will set GPCn_CC_SCRATCH[0] bit 31
329 // when it has completed, and return the size of its context data
330 // in GPCn_CC_SCRATCH[1]
332 ld b32 $r3 D[$r0 + #gpc_count]
336 // setup, and start GPC ucode running
337 add b32 $r14 $r4 0x804
339 call #nv_wr32 // CC_SCRATCH[1] = ctx offset
340 add b32 $r14 $r4 0x800
342 call #nv_wr32 // CC_SCRATCH[0] = chipset
343 add b32 $r14 $r4 0x10c
346 add b32 $r14 $r4 0x104
347 call #nv_wr32 // ENTRY
348 add b32 $r14 $r4 0x100
349 mov $r15 2 // CTRL_START_TRIGGER
350 call #nv_wr32 // CTRL
352 // wait for it to complete, and adjust context size
353 add b32 $r14 $r4 0x800
358 add b32 $r14 $r4 0x804
367 // save context size, and tell host we're ready
370 iowr I[$r2 + 0x100] $r1 // CC_SCRATCH[1] = context size
374 iowr I[$r2 + 0x000] $r1 // CC_SCRATCH[0] |= 0x80000000
376 // Main program loop, very simple, sleeps until woken up by the interrupt
377 // handler, pulls a command from the queue and executes its handler
380 // sleep until we have something to do
387 // context switch, requested by GPU?
389 bra ne #main_not_ctx_switch
393 iord $r2 I[$r1 + 0x100] // CHAN_NEXT
394 iord $r1 I[$r1 + 0x000] // CHAN_CUR
399 bra e #chsw_prev_no_next
431 // ack the context switch request
436 iowr I[$r1 + 0x000] $r2 // 0x409b0c
440 // request to set current channel? (*not* a context switch)
443 bra ne #main_not_ctx_chan
448 // request to store current channel context?
451 bra ne #main_not_ctx_save
461 or $r15 E_BAD_COMMAND
470 iowr I[$r1 + 0x000] $r2 // CC_SCRATCH[0] |= 0x80000000
485 // incoming fifo command?
486 iord $r10 I[$r0 + 0x200] // INTR
487 and $r11 $r10 0x00000004
489 // queue incoming fifo command for later processing
492 iord $r14 I[$r11 + 0x100] // FIFO_CMD
493 iord $r15 I[$r11 + 0x000] // FIFO_DATA
497 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
499 // context switch request?
501 and $r11 $r10 0x00000100
503 // enqueue a context switch for later processing
508 // anything we didn't handle, bring it to the host's attention
516 iowr I[$r10] $r11 // INTR_UP_SET
518 // ack, and wake up main()
520 iowr I[$r0 + 0x100] $r10 // INTR_ACK
534 // Again, not real sure
536 // In: $r15 value to set 0x404170 to
545 // Waits for a ctx_4170s() call to complete
555 // Disables various things, waits a bit, and re-enables them..
557 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
558 // good description for the bits we turn off? Anyways, without this,
559 // funny things happen.
565 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_GPC, POWER_ALL
569 bra ne #ctx_redswitch_delay
571 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_ALL, POWER_ALL
574 // Not a clue what this is for, except that unless the value is 0x10, the
575 // strand context is saved (and presumably restored) incorrectly..
577 // In: $r15 value to set to (0x00/0x10 are used)
582 iowr I[$r14] $r15 // HUB(0x86c) = val
585 call #nv_wr32 // ROP(0xa14) = val
588 call #nv_wr32 // GPC(0x86c) = val
591 // ctx_load - load's a channel's ctxctl data, and selects its vm
593 // In: $r2 channel address
598 // switch to channel, somewhat magic in parts..
599 mov $r10 12 // DONE_UNK12
603 iowr I[$r1 + 0x000] $r0 // 0x409a24
606 iowr I[$r3 + 0x100] $r2 // CHAN_NEXT
610 iowr I[$r1 + 0x000] $r2 // MEM_CHAN
611 iowr I[$r1 + 0x100] $r4 // MEM_CMD
613 iord $r4 I[$r1 + 0x100]
615 bra ne #ctx_chan_wait_0
616 iowr I[$r3 + 0x000] $r2 // CHAN_CUR
618 // load channel header, fetch PGRAPH context pointer
627 iowr I[$r1 + 0x000] $r2 // MEM_BASE
632 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vram
633 mov $r1 0x10 // chan + 0x0210
635 sethi $r2 0x00020000 // 16 bytes
640 // update current context
641 ld b32 $r1 D[$r0 + #xfer_data + 4]
643 ld b32 $r2 D[$r0 + #xfer_data + 0]
646 st b32 D[$r0 + #ctx_current] $r1
648 // set transfer base to start of context, and fetch context header
652 iowr I[$r2 + 0x000] $r1 // MEM_BASE
656 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vm
658 sethi $r1 0x00060000 // 256 bytes
666 // ctx_chan - handler for HUB_SET_CHAN command, will set a channel as
667 // the active channel for ctxctl, but not actually transfer
668 // any context data. intended for use only during initial
669 // context construction.
671 // In: $r2 channel address
675 mov $r10 12 // DONE_UNK12
680 iowr I[$r1 + 0x000] $r2 // MEM_CMD = 5 (???)
682 iord $r2 I[$r1 + 0x000]
684 bra ne #ctx_chan_wait
687 // Execute per-context state overrides list
689 // Only executed on the first load of a channel. Might want to look into
690 // removing this and having the host directly modify the channel's context
691 // to change this state... The nouveau DRM already builds this list as
692 // it's definitely needed for NVIDIA's, so we may as well use it for now
694 // Input: $r1 mmio list length
697 // set transfer base to be the mmio list
698 ld b32 $r3 D[$r0 + #chan_mmio_address]
701 iowr I[$r2 + 0x000] $r3 // MEM_BASE
705 // fetch next 256 bytes of mmio list if necessary
707 bra ne #ctx_mmio_pull
709 sethi $r5 0x00060000 // 256 bytes
713 // execute a single list entry
715 ld b32 $r14 D[$r4 + #xfer_data + 0x00]
716 ld b32 $r15 D[$r4 + #xfer_data + 0x04]
722 bra ne #ctx_mmio_loop
724 // set transfer base back to the current context
726 ld b32 $r3 D[$r0 + #ctx_current]
727 iowr I[$r2 + 0x000] $r3 // MEM_BASE
729 // disable the mmio list now, we don't need/want to execute it again
730 st b32 D[$r0 + #chan_mmio_count] $r0
732 sethi $r1 0x00060000 // 256 bytes
737 // Transfer HUB context data between GPU and storage area
739 // In: $r2 channel address
740 // $p1 clear on save, set on load
741 // $p2 set if opposite direction done/will be done, so:
742 // on save it means: "a load will follow this save"
743 // on load it means: "a save preceeded this load"
746 // according to mwk, some kind of wait for idle
750 iowr I[$r15 + 0x200] $r14
752 iord $r14 I[$r15 + 0x000]
754 bra ne #ctx_xfer_idle
756 bra not $p1 #ctx_xfer_pre
757 bra $p2 #ctx_xfer_pre_load
761 bra not $p1 #ctx_xfer_exec
772 // fetch context pointer, and initiate xfer on all GPCs
774 ld b32 $r1 D[$r0 + #ctx_current]
777 iowr I[$r2 + 0x000] $r0 // BAR_STATUS = reset
781 call #nv_wr32 // GPC_BCAST_WRCMD_DATA = ctx pointer
787 call #nv_wr32 // GPC_BCAST_WRCMD_CMD = GPC_XFER(type)
793 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
797 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
800 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
803 xbit $r10 $flags $p1 // direction
804 or $r10 6 // first, last
805 mov $r11 0 // base = 0
806 ld b32 $r12 D[$r0 + #hub_mmio_list_head]
807 ld b32 $r13 D[$r0 + #hub_mmio_list_tail]
808 mov $r14 0 // not multi
811 // wait for GPCs to all complete
812 mov $r10 8 // DONE_BAR
815 // wait for strand xfer to complete
819 bra $p1 #ctx_xfer_post
820 mov $r10 12 // DONE_UNK12
825 iowr I[$r1] $r2 // MEM_CMD
826 ctx_xfer_post_save_wait:
829 bra ne #ctx_xfer_post_save_wait
831 bra $p2 #ctx_xfer_done
842 bra not $p1 #ctx_xfer_no_post_mmio
843 ld b32 $r1 D[$r0 + #chan_mmio_count]
845 bra e #ctx_xfer_no_post_mmio
848 ctx_xfer_no_post_mmio: