1 /* fuc microcode for gf100 PGRAPH/GPC
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 * - bracket certain functions with scratch writes, useful for debugging
28 * - watchdog timer around ctx operations
32 gpc_mmio_list_head: .b32 #mmio_list_base
34 tpc_mmio_list_head: .b32 #mmio_list_base
36 unk_mmio_list_head: .b32 #mmio_list_base
37 unk_mmio_list_tail: .b32 #mmio_list_base
44 #if NV_PGRAPH_GPCX_UNK__SIZE > 0
55 #define gpc_addr(reg,addr) /*
57 */ or reg NV_PGRAPH_GPCX_GPCCS_MMIO_CTRL_BASE_ENABLE
58 #define gpc_wr32(addr,reg) /*
59 */ gpc_addr($r14,addr) /*
60 */ mov b32 $r15 reg /*
63 // reports an exception to the host
65 // In: $r15 error code (see os.h)
69 nv_wr32(NV_PGRAPH_FECS_CC_SCRATCH_VAL(5), $r15)
71 nv_wr32(NV_PGRAPH_FECS_INTR_UP_SET, $r15)
80 nv_iord($r9, NV_PGRAPH_GPCX_GPCCS_TPC_STATUS, 0)
81 bra b32 $r9 0x0 ne #tpc_strand_busy
86 #define tpc_strand_wait() call(tpc_strand_wait)
87 #define tpc_strand_enable() /*
88 */ mov $r15 NV_PGRAPH_GPC0_TPCX_STRAND_CMD_ENABLE /*
89 */ gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_CMD, $r15) /*
91 #define tpc_strand_disable() /*
92 */ mov $r15 NV_PGRAPH_GPC0_TPCX_STRAND_CMD_DISABLE /*
93 */ gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_CMD, $r15) /*
95 #define tpc_strand_seek(p) /*
96 */ mov $r15 NV_PGRAPH_GPC0_TPCX_STRAND_INDEX_ALL /*
97 */ gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_INDEX, $r15) /*
99 */ gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_SELECT, $r15) /*
100 */ mov $r15 NV_PGRAPH_GPC0_TPCX_STRAND_CMD_SEEK /*
102 #define tpc_strand_info(m) /*
103 */ gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_CMD, $r15) /*
105 */ gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_DATA, $r15) /*
106 */ mov $r15 NV_PGRAPH_GPC0_TPCX_STRAND_CMD_GET_INFO /*
107 */ gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_CMD, $r15) /*
112 // GPC fuc initialisation, executed by triggering ucode start, will
113 // fall through to main loop after completion.
116 // CC_SCRATCH[1]: context base
120 // 31:31: set to signal completion
122 // 31:0: GPC context size
128 nv_iord($r1, NV_PGRAPH_GPCX_GPCCS_CAPS, 0)
133 // enable fifo access
134 mov $r2 NV_PGRAPH_GPCX_GPCCS_ACCESS_FIFO
135 nv_iowr(NV_PGRAPH_GPCX_GPCCS_ACCESS, 0, $r2)
137 // setup i0 handler, and route all interrupts to it
140 nv_iowr(NV_PGRAPH_GPCX_GPCCS_INTR_ROUTE, 0, $r0)
142 // enable fifo interrupt
143 mov $r2 NV_PGRAPH_GPCX_GPCCS_INTR_EN_SET_FIFO
144 nv_iowr(NV_PGRAPH_GPCX_GPCCS_INTR_EN_SET, 0, $r2)
149 // how many TPCs do we have?
150 nv_iord($r2, NV_PGRAPH_GPCX_GPCCS_UNITS, 0)
155 st b32 D[$r0 + #tpc_count] $r2
156 st b32 D[$r0 + #tpc_mask] $r3
158 // determine which GPC we are, setup (optional) mmio access offset
159 nv_iord($r2, NV_PGRAPH_GPCX_GPCCS_MYINDEX, 0)
160 st b32 D[$r0 + #gpc_id] $r2
162 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MMIO_BASE, 0, $r2)
164 #if NV_PGRAPH_GPCX_UNK__SIZE > 0
165 // figure out which, and how many, UNKs are actually present
166 gpc_addr($r14, 0x500c30)
181 cmp b32 $r2 NV_PGRAPH_GPCX_UNK__SIZE
182 bra ne #init_unk_loop
184 st b32 D[$r0 + #unk_count] $r3
185 st b32 D[$r0 + #unk_mask] $r4
188 // initialise context base, and size tracking
189 nv_iord($r2, NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_VAL(1), 0)
190 clear b32 $r3 // track GPC context size here
192 // set mmctx base addresses now so we don't have to do it later,
193 // they don't currently ever change
195 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MMCTX_SAVE_SWBASE, 0, $r5)
196 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MMCTX_LOAD_SWBASE, 0, $r5)
198 // calculate GPC mmio context size
199 ld b32 $r14 D[$r0 + #gpc_mmio_list_head]
200 ld b32 $r15 D[$r0 + #gpc_mmio_list_tail]
205 // calculate per-TPC mmio context size
206 ld b32 $r14 D[$r0 + #tpc_mmio_list_head]
207 ld b32 $r15 D[$r0 + #tpc_mmio_list_tail]
209 ld b32 $r14 D[$r0 + #tpc_count]
214 #if NV_PGRAPH_GPCX_UNK__SIZE > 0
215 // calculate per-UNK mmio context size
216 ld b32 $r14 D[$r0 + #unk_mmio_list_head]
217 ld b32 $r15 D[$r0 + #unk_mmio_list_tail]
219 ld b32 $r14 D[$r0 + #unk_count]
225 // round up base/size to 256 byte boundary (for strand SWBASE)
227 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MMCTX_LOAD_COUNT, 0, $r3) // wtf for?!
235 // calculate size of strand context data
237 call(strand_ctx_init)
242 // calculate size of tpc strand context data
243 mov $r15 NV_PGRAPH_GPC0_TPCX_STRAND_INDEX_ALL
244 gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_INDEX, $r15)
249 ld b32 $r4 D[$r0 + #tpc_count]
250 gpc_addr($r5, NV_PGRAPH_GPC0_TPC0)
251 tpc_strand_init_tpc_loop:
252 add b32 $r14 $r5 NV_TPC_STRAND_CNT
256 tpc_strand_init_idx_loop:
257 add b32 $r14 $r5 NV_TPC_STRAND_INDEX
260 add b32 $r14 $r5 NV_TPC_STRAND_SAVE_SWBASE
263 add b32 $r14 $r5 NV_TPC_STRAND_LOAD_SWBASE
266 add b32 $r14 $r5 NV_TPC_STRAND_WORDS
275 bra nz #tpc_strand_init_idx_loop
276 add b32 $r5 NV_PGRAPH_GPC0_TPC0__SIZE
278 bra nz #tpc_strand_init_tpc_loop
280 mov $r15 NV_PGRAPH_GPC0_TPCX_STRAND_INDEX_ALL
281 gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_INDEX, $r15)
282 tpc_strand_disable();
285 // save context size, and tell HUB we're done
286 nv_iowr(NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_VAL(1), 0, $r3)
289 nv_iowr(NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_SET(0), 0, $r2)
291 // Main program loop, very simple, sleeps until woken up by the interrupt
292 // handler, pulls a command from the queue and executes its handler
302 // 0x0000-0x0003 are all context transfers
304 bra nc #main_not_ctx_xfer
305 // fetch $flags and mask off $p1/$p2
310 // set $p1/$p2 according to transfer type
314 // transfer context data
320 or $r15 E_BAD_COMMAND
338 // incoming fifo command?
339 nv_iord($r10, NV_PGRAPH_GPCX_GPCCS_INTR, 0)
340 and $r11 $r10 NV_PGRAPH_GPCX_GPCCS_INTR_FIFO
342 // queue incoming fifo command for later processing
344 nv_iord($r14, NV_PGRAPH_GPCX_GPCCS_FIFO_CMD, 0)
345 nv_iord($r15, NV_PGRAPH_GPCX_GPCCS_FIFO_DATA, 0)
348 nv_iowr(NV_PGRAPH_GPCX_GPCCS_FIFO_ACK, 0, $r14)
350 // ack, and wake up main()
352 nv_iowr(NV_PGRAPH_GPCX_GPCCS_INTR_ACK, 0, $r10)
367 // Set this GPC's bit in HUB_BAR, used to signal completion of various
368 // activities to the HUB fuc
372 ld b32 $r14 D[$r0 + #gpc_id]
374 nv_wr32(0x409418, $r15) // 0x409418 - HUB_BAR_SET
377 // Disables various things, waits a bit, and re-enables them..
379 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
380 // good description for the bits we turn off? Anyways, without this,
381 // funny things happen.
384 mov $r15 NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_POWER
385 nv_iowr(NV_PGRAPH_GPCX_GPCCS_RED_SWITCH, 0, $r15)
389 bra ne #ctx_redswitch_delay
390 or $r15 NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_UNK11
391 or $r15 NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_ENABLE
392 nv_iowr(NV_PGRAPH_GPCX_GPCCS_RED_SWITCH, 0, $r15)
395 // Transfer GPC context data between GPU and storage area
397 // In: $r15 context base address
398 // $p1 clear on save, set on load
399 // $p2 set if opposite direction done/will be done, so:
400 // on save it means: "a load will follow this save"
401 // on load it means: "a save preceeded this load"
404 // set context base address
405 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MEM_BASE, 0, $r15)
407 gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_MEM_BASE, $r15)
409 bra not $p1 #ctx_xfer_not_load
416 nv_iowr(NV_PGRAPH_GPCX_GPCCS_STRAND_SELECT, 0x3f, $r2)
417 xbit $r2 $flags $p1 // SAVE/LOAD
418 add b32 $r2 NV_PGRAPH_GPCX_GPCCS_STRAND_CMD_SAVE
419 nv_iowr(NV_PGRAPH_GPCX_GPCCS_STRAND_CMD, 0x3f, $r2)
424 xbit $r15 $flags $p1 // SAVE/LOAD
425 add b32 $r15 NV_PGRAPH_GPC0_TPCX_STRAND_CMD_SAVE
426 gpc_wr32(NV_PGRAPH_GPC0_TPCX_STRAND_CMD, $r15)
430 xbit $r10 $flags $p1 // direction
433 ld b32 $r12 D[$r0 + #gpc_id]
435 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn
436 ld b32 $r12 D[$r0 + #gpc_mmio_list_head]
437 ld b32 $r13 D[$r0 + #gpc_mmio_list_tail]
438 mov $r14 0 // not multi
441 // per-TPC mmio context
442 xbit $r10 $flags $p1 // direction
443 #if !NV_PGRAPH_GPCX_UNK__SIZE
446 imm32($r11, 0x504000)
447 ld b32 $r12 D[$r0 + #gpc_id]
449 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn_TPC0
450 ld b32 $r12 D[$r0 + #tpc_mmio_list_head]
451 ld b32 $r13 D[$r0 + #tpc_mmio_list_tail]
452 ld b32 $r15 D[$r0 + #tpc_mask]
453 mov $r14 0x800 // stride = 0x800
456 #if NV_PGRAPH_GPCX_UNK__SIZE > 0
457 // per-UNK mmio context
458 xbit $r10 $flags $p1 // direction
460 imm32($r11, 0x503000)
461 ld b32 $r12 D[$r0 + #gpc_id]
463 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn_UNK0
464 ld b32 $r12 D[$r0 + #unk_mmio_list_head]
465 ld b32 $r13 D[$r0 + #unk_mmio_list_tail]
466 ld b32 $r15 D[$r0 + #unk_mask]
467 mov $r14 0x200 // stride = 0x200
471 // wait for strands to finish
477 // if load, or a save without a load following, do some
478 // unknown stuff that's done after finishing a block of
480 bra $p1 #ctx_xfer_post
481 bra not $p2 #ctx_xfer_done
488 // mark completion in HUB's barrier
490 call(hub_barrier_done)