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
65 mmctx_data(0x17e91c, 2)
66 mmctx_data(0x400204, 2)
67 mmctx_data(0x404004, 11)
68 mmctx_data(0x404044, 1)
69 mmctx_data(0x404094, 14)
70 mmctx_data(0x4040d0, 7)
71 mmctx_data(0x4040f8, 1)
72 mmctx_data(0x404130, 3)
73 mmctx_data(0x404150, 3)
74 mmctx_data(0x404164, 2)
75 mmctx_data(0x404174, 3)
76 mmctx_data(0x404200, 8)
77 mmctx_data(0x404404, 14)
78 mmctx_data(0x404460, 4)
79 mmctx_data(0x404480, 1)
80 mmctx_data(0x404498, 1)
81 mmctx_data(0x404604, 4)
82 mmctx_data(0x404618, 32)
83 mmctx_data(0x404698, 21)
84 mmctx_data(0x4046f0, 2)
85 mmctx_data(0x404700, 22)
86 mmctx_data(0x405800, 1)
87 mmctx_data(0x405830, 3)
88 mmctx_data(0x405854, 1)
89 mmctx_data(0x405870, 4)
90 mmctx_data(0x405a00, 2)
91 mmctx_data(0x405a18, 1)
92 mmctx_data(0x406020, 1)
93 mmctx_data(0x406028, 4)
94 mmctx_data(0x4064a8, 2)
95 mmctx_data(0x4064b4, 2)
96 mmctx_data(0x407804, 1)
97 mmctx_data(0x40780c, 6)
98 mmctx_data(0x4078bc, 1)
99 mmctx_data(0x408000, 7)
100 mmctx_data(0x408064, 1)
101 mmctx_data(0x408800, 3)
102 mmctx_data(0x408900, 4)
103 mmctx_data(0x408980, 1)
105 mmctx_data(0x4064c0, 2)
110 chan_mmio_count: .b32 0
111 chan_mmio_address: .b32 0
116 .section nvc0_grhub_code
118 define(`include_code')
119 include(`nvc0_graph.fuc')
121 // reports an exception to the host
123 // In: $r15 error code (see nvc0_graph.fuc)
129 iowr I[$r14 + 0x000] $r15 // CC_SCRATCH[5] = error code
133 iowr I[$r14 + 0x000] $r15 // INTR_UP_SET
137 // HUB fuc initialisation, executed by triggering ucode start, will
138 // fall through to main loop after completion.
141 // CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
145 // 31:31: set to signal completion
147 // 31:0: total PGRAPH context size
154 // enable fifo access
157 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
159 // setup i0 handler, and route all interrupts to it
163 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
165 // route HUB_CHANNEL_SWITCH to fuc interrupt 8
168 mov $r2 0x2003 // { HUB_CHANNEL_SWITCH, ZERO } -> intr 8
169 iowr I[$r3 + 0x000] $r2
171 // not sure what these are, route them because NVIDIA does, and
172 // the IRQ handler will signal the host if we ever get one.. we
173 // may find out if/why we need to handle these if so..
176 iowr I[$r3 + 0x004] $r2 // { 0x04, ZERO } -> intr 9
178 iowr I[$r3 + 0x008] $r2 // { 0x0b, ZERO } -> intr 10
180 iowr I[$r3 + 0x01c] $r2 // { 0x0c, ZERO } -> intr 15
182 // enable all INTR_UP interrupts
188 // enable fifo, ctxsw, 9, 10, 15 interrupts
189 mov $r2 -0x78fc // 0x8704
191 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
193 // fifo level triggered, rest edge
201 // fetch enabled GPC/ROP counts
202 mov $r14 -0x69fc // 0x409604
206 st b32 D[$r0 + rop_count] $r1
208 st b32 D[$r0 + gpc_count] $r15
210 // set BAR_REQMASK to GPC mask
216 iowr I[$r2 + 0x000] $r1
217 iowr I[$r2 + 0x100] $r1
219 // find context data for this chipset
222 iord $r2 I[$r2 + 0x000] // CC_SCRATCH[0]
223 mov $r15 chipsets - 8
226 ld b32 $r3 D[$r15 + 0x00]
230 bra ne init_find_chipset
234 // context size calculation, reserve first 256 bytes for use by fuc
238 // calculate size of mmio context data
239 ld b16 $r14 D[$r15 + 4]
240 ld b16 $r15 D[$r15 + 6]
242 st b32 D[$r0 + hub_mmio_list_head] $r14
243 st b32 D[$r0 + hub_mmio_list_tail] $r15
246 // set mmctx base addresses now so we don't have to do it later,
247 // they don't (currently) ever change
251 iowr I[$r3 + 0x000] $r4 // MMCTX_SAVE_SWBASE
252 iowr I[$r3 + 0x100] $r4 // MMCTX_LOAD_SWBASE
256 iowr I[$r3 + 0x000] $r15 // MMCTX_LOAD_COUNT, wtf for?!?
258 // strands, base offset needs to be aligned to 256 bytes
266 // initialise each GPC in sequence by passing in the offset of its
267 // context data in GPCn_CC_SCRATCH[1], and starting its FUC (which
268 // has previously been uploaded by the host) running.
270 // the GPC fuc init sequence will set GPCn_CC_SCRATCH[0] bit 31
271 // when it has completed, and return the size of its context data
272 // in GPCn_CC_SCRATCH[1]
274 ld b32 $r3 D[$r0 + gpc_count]
278 // setup, and start GPC ucode running
279 add b32 $r14 $r4 0x804
281 call nv_wr32 // CC_SCRATCH[1] = ctx offset
282 add b32 $r14 $r4 0x800
284 call nv_wr32 // CC_SCRATCH[0] = chipset
285 add b32 $r14 $r4 0x10c
288 add b32 $r14 $r4 0x104
289 call nv_wr32 // ENTRY
290 add b32 $r14 $r4 0x100
291 mov $r15 2 // CTRL_START_TRIGGER
294 // wait for it to complete, and adjust context size
295 add b32 $r14 $r4 0x800
300 add b32 $r14 $r4 0x804
309 // save context size, and tell host we're ready
312 iowr I[$r2 + 0x100] $r1 // CC_SCRATCH[1] = context size
316 iowr I[$r2 + 0x000] $r1 // CC_SCRATCH[0] |= 0x80000000
318 // Main program loop, very simple, sleeps until woken up by the interrupt
319 // handler, pulls a command from the queue and executes its handler
322 // sleep until we have something to do
329 // context switch, requested by GPU?
331 bra ne main_not_ctx_switch
335 iord $r2 I[$r1 + 0x100] // CHAN_NEXT
336 iord $r1 I[$r1 + 0x000] // CHAN_CUR
341 bra e chsw_prev_no_next
373 // ack the context switch request
378 iowr I[$r1 + 0x000] $r2 // 0x409b0c
382 // request to set current channel? (*not* a context switch)
385 bra ne main_not_ctx_chan
390 // request to store current channel context?
393 bra ne main_not_ctx_save
403 or $r15 E_BAD_COMMAND
412 iowr I[$r1 + 0x000] $r2 // CC_SCRATCH[0] |= 0x80000000
427 // incoming fifo command?
428 iord $r10 I[$r0 + 0x200] // INTR
429 and $r11 $r10 0x00000004
431 // queue incoming fifo command for later processing
434 iord $r14 I[$r11 + 0x100] // FIFO_CMD
435 iord $r15 I[$r11 + 0x000] // FIFO_DATA
439 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
441 // context switch request?
443 and $r11 $r10 0x00000100
445 // enqueue a context switch for later processing
450 // anything we didn't handle, bring it to the host's attention
458 iowr I[$r10] $r11 // INTR_UP_SET
460 // ack, and wake up main()
462 iowr I[$r0 + 0x100] $r10 // INTR_ACK
476 // Not real sure, but, MEM_CMD 7 will hang forever if this isn't done
488 // Without clearing again at end of xfer, some things cause PGRAPH
489 // to hang with STATUS=0x00000007 until it's cleared.. fbcon can
490 // still function with it set however...
498 // Again, not real sure
500 // In: $r15 value to set 0x404170 to
509 // Waits for a ctx_4170s() call to complete
519 // Disables various things, waits a bit, and re-enables them..
521 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
522 // good description for the bits we turn off? Anyways, without this,
523 // funny things happen.
529 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_GPC, POWER_ALL
533 bra ne ctx_redswitch_delay
535 iowr I[$r14] $r15 // HUB_RED_SWITCH = ENABLE_ALL, POWER_ALL
538 // Not a clue what this is for, except that unless the value is 0x10, the
539 // strand context is saved (and presumably restored) incorrectly..
541 // In: $r15 value to set to (0x00/0x10 are used)
546 iowr I[$r14] $r15 // HUB(0x86c) = val
549 call nv_wr32 // ROP(0xa14) = val
552 call nv_wr32 // GPC(0x86c) = val
555 // ctx_load - load's a channel's ctxctl data, and selects its vm
557 // In: $r2 channel address
562 // switch to channel, somewhat magic in parts..
563 mov $r10 12 // DONE_UNK12
567 iowr I[$r1 + 0x000] $r0 // 0x409a24
570 iowr I[$r3 + 0x100] $r2 // CHAN_NEXT
574 iowr I[$r1 + 0x000] $r2 // MEM_CHAN
575 iowr I[$r1 + 0x100] $r4 // MEM_CMD
577 iord $r4 I[$r1 + 0x100]
579 bra ne ctx_chan_wait_0
580 iowr I[$r3 + 0x000] $r2 // CHAN_CUR
582 // load channel header, fetch PGRAPH context pointer
591 iowr I[$r1 + 0x000] $r2 // MEM_BASE
596 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vram
597 mov $r1 0x10 // chan + 0x0210
599 sethi $r2 0x00020000 // 16 bytes
604 // update current context
605 ld b32 $r1 D[$r0 + xfer_data + 4]
607 ld b32 $r2 D[$r0 + xfer_data + 0]
610 st b32 D[$r0 + ctx_current] $r1
612 // set transfer base to start of context, and fetch context header
616 iowr I[$r2 + 0x000] $r1 // MEM_BASE
620 iowr I[$r1 + 0x000] $r2 // MEM_TARGET = vm
622 sethi $r1 0x00060000 // 256 bytes
630 // ctx_chan - handler for HUB_SET_CHAN command, will set a channel as
631 // the active channel for ctxctl, but not actually transfer
632 // any context data. intended for use only during initial
633 // context construction.
635 // In: $r2 channel address
640 mov $r10 12 // DONE_UNK12
645 iowr I[$r1 + 0x000] $r2 // MEM_CMD = 5 (???)
647 iord $r2 I[$r1 + 0x000]
653 // Execute per-context state overrides list
655 // Only executed on the first load of a channel. Might want to look into
656 // removing this and having the host directly modify the channel's context
657 // to change this state... The nouveau DRM already builds this list as
658 // it's definitely needed for NVIDIA's, so we may as well use it for now
660 // Input: $r1 mmio list length
663 // set transfer base to be the mmio list
664 ld b32 $r3 D[$r0 + chan_mmio_address]
667 iowr I[$r2 + 0x000] $r3 // MEM_BASE
671 // fetch next 256 bytes of mmio list if necessary
675 sethi $r5 0x00060000 // 256 bytes
679 // execute a single list entry
681 ld b32 $r14 D[$r4 + xfer_data + 0x00]
682 ld b32 $r15 D[$r4 + xfer_data + 0x04]
690 // set transfer base back to the current context
692 ld b32 $r3 D[$r0 + ctx_current]
693 iowr I[$r2 + 0x000] $r3 // MEM_BASE
695 // disable the mmio list now, we don't need/want to execute it again
696 st b32 D[$r0 + chan_mmio_count] $r0
698 sethi $r1 0x00060000 // 256 bytes
703 // Transfer HUB context data between GPU and storage area
705 // In: $r2 channel address
706 // $p1 clear on save, set on load
707 // $p2 set if opposite direction done/will be done, so:
708 // on save it means: "a load will follow this save"
709 // on load it means: "a save preceeded this load"
712 bra not $p1 ctx_xfer_pre
713 bra $p2 ctx_xfer_pre_load
718 bra not $p1 ctx_xfer_exec
729 // fetch context pointer, and initiate xfer on all GPCs
731 ld b32 $r1 D[$r0 + ctx_current]
734 iowr I[$r2 + 0x000] $r0 // BAR_STATUS = reset
738 call nv_wr32 // GPC_BCAST_WRCMD_DATA = ctx pointer
744 call nv_wr32 // GPC_BCAST_WRCMD_CMD = GPC_XFER(type)
750 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
754 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
757 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
760 xbit $r10 $flags $p1 // direction
761 or $r10 6 // first, last
762 mov $r11 0 // base = 0
763 ld b32 $r12 D[$r0 + hub_mmio_list_head]
764 ld b32 $r13 D[$r0 + hub_mmio_list_tail]
765 mov $r14 0 // not multi
768 // wait for GPCs to all complete
769 mov $r10 8 // DONE_BAR
772 // wait for strand xfer to complete
776 bra $p1 ctx_xfer_post
777 mov $r10 12 // DONE_UNK12
782 iowr I[$r1] $r2 // MEM_CMD
783 ctx_xfer_post_save_wait:
786 bra ne ctx_xfer_post_save_wait
788 bra $p2 ctx_xfer_done
799 bra not $p1 ctx_xfer_no_post_mmio
800 ld b32 $r1 D[$r0 + chan_mmio_count]
802 bra e ctx_xfer_no_post_mmio
805 ctx_xfer_no_post_mmio: