1 /* fuc microcode for nvc0 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 // reports an exception to the host
57 // In: $r15 error code (see os.h)
61 nv_wr32(NV_PGRAPH_FECS_CC_SCRATCH_VAL(5), $r15)
63 nv_wr32(NV_PGRAPH_FECS_INTR_UP_SET, $r15)
67 // GPC fuc initialisation, executed by triggering ucode start, will
68 // fall through to main loop after completion.
71 // CC_SCRATCH[1]: context base
75 // 31:31: set to signal completion
77 // 31:0: GPC context size
83 nv_iord($r1, NV_PGRAPH_GPCX_GPCCS_CAPS, 0)
89 mov $r2 NV_PGRAPH_GPCX_GPCCS_ACCESS_FIFO
90 nv_iowr(NV_PGRAPH_GPCX_GPCCS_ACCESS, 0, $r2)
92 // setup i0 handler, and route all interrupts to it
95 nv_iowr(NV_PGRAPH_GPCX_GPCCS_INTR_ROUTE, 0, $r0)
97 // enable fifo interrupt
98 mov $r2 NV_PGRAPH_GPCX_GPCCS_INTR_EN_SET_FIFO
99 nv_iowr(NV_PGRAPH_GPCX_GPCCS_INTR_EN_SET, 0, $r2)
104 // figure out which GPC we are, and how many TPCs we have
105 nv_iord($r2, NV_PGRAPH_GPCX_GPCCS_UNITS, 0)
110 st b32 D[$r0 + #tpc_count] $r2
111 st b32 D[$r0 + #tpc_mask] $r3
112 nv_iord($r2, NV_PGRAPH_GPCX_GPCCS_MYINDEX, 0)
113 st b32 D[$r0 + #gpc_id] $r2
115 #if NV_PGRAPH_GPCX_UNK__SIZE > 0
116 // figure out which, and how many, UNKs are actually present
117 imm32($r14, 0x500c30)
132 cmp b32 $r2 NV_PGRAPH_GPCX_UNK__SIZE
133 bra ne #init_unk_loop
135 st b32 D[$r0 + #unk_count] $r3
136 st b32 D[$r0 + #unk_mask] $r4
139 // initialise context base, and size tracking
140 nv_iord($r2, NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_VAL(1), 0)
141 clear b32 $r3 // track GPC context size here
143 // set mmctx base addresses now so we don't have to do it later,
144 // they don't currently ever change
146 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MMCTX_SAVE_SWBASE, 0, $r5)
147 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MMCTX_LOAD_SWBASE, 0, $r5)
149 // calculate GPC mmio context size
150 ld b32 $r14 D[$r0 + #gpc_mmio_list_head]
151 ld b32 $r15 D[$r0 + #gpc_mmio_list_tail]
156 // calculate per-TPC mmio context size
157 ld b32 $r14 D[$r0 + #tpc_mmio_list_head]
158 ld b32 $r15 D[$r0 + #tpc_mmio_list_tail]
160 ld b32 $r14 D[$r0 + #tpc_count]
165 #if NV_PGRAPH_GPCX_UNK__SIZE > 0
166 // calculate per-UNK mmio context size
167 ld b32 $r14 D[$r0 + #unk_mmio_list_head]
168 ld b32 $r15 D[$r0 + #unk_mmio_list_tail]
170 ld b32 $r14 D[$r0 + #unk_count]
176 // round up base/size to 256 byte boundary (for strand SWBASE)
178 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MMCTX_LOAD_COUNT, 0, $r3) // wtf for?!
186 // calculate size of strand context data
188 call(strand_ctx_init)
191 // save context size, and tell HUB we're done
192 nv_iowr(NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_VAL(1), 0, $r3)
195 nv_iowr(NV_PGRAPH_GPCX_GPCCS_CC_SCRATCH_SET(0), 0, $r2)
197 // Main program loop, very simple, sleeps until woken up by the interrupt
198 // handler, pulls a command from the queue and executes its handler
207 // 0x0000-0x0003 are all context transfers
209 bra nc #main_not_ctx_xfer
210 // fetch $flags and mask off $p1/$p2
215 // set $p1/$p2 according to transfer type
219 // transfer context data
225 or $r15 E_BAD_COMMAND
242 // incoming fifo command?
243 nv_iord($r10, NV_PGRAPH_GPCX_GPCCS_INTR, 0)
244 and $r11 $r10 NV_PGRAPH_GPCX_GPCCS_INTR_FIFO
246 // queue incoming fifo command for later processing
248 nv_iord($r14, NV_PGRAPH_GPCX_GPCCS_FIFO_CMD, 0)
249 nv_iord($r15, NV_PGRAPH_GPCX_GPCCS_FIFO_DATA, 0)
252 nv_iowr(NV_PGRAPH_GPCX_GPCCS_FIFO_ACK, 0, $r14)
254 // ack, and wake up main()
256 nv_iowr(NV_PGRAPH_GPCX_GPCCS_INTR_ACK, 0, $r10)
270 // Set this GPC's bit in HUB_BAR, used to signal completion of various
271 // activities to the HUB fuc
275 ld b32 $r14 D[$r0 + #gpc_id]
277 nv_wr32(0x409418, $r15) // 0x409418 - HUB_BAR_SET
280 // Disables various things, waits a bit, and re-enables them..
282 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
283 // good description for the bits we turn off? Anyways, without this,
284 // funny things happen.
287 mov $r15 NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_POWER
288 nv_iowr(NV_PGRAPH_GPCX_GPCCS_RED_SWITCH, 0, $r15)
292 bra ne #ctx_redswitch_delay
293 or $r15 NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_UNK11
294 or $r15 NV_PGRAPH_GPCX_GPCCS_RED_SWITCH_ENABLE
295 nv_iowr(NV_PGRAPH_GPCX_GPCCS_RED_SWITCH, 0, $r15)
298 // Transfer GPC context data between GPU and storage area
300 // In: $r15 context base address
301 // $p1 clear on save, set on load
302 // $p2 set if opposite direction done/will be done, so:
303 // on save it means: "a load will follow this save"
304 // on load it means: "a save preceeded this load"
307 // set context base address
308 nv_iowr(NV_PGRAPH_GPCX_GPCCS_MEM_BASE, 0, $r15)
309 bra not $p1 #ctx_xfer_not_load
316 nv_iowr(NV_PGRAPH_GPCX_GPCCS_STRAND_SELECT, 0x3f, $r2)
317 xbit $r2 $flags $p1 // SAVE/LOAD
318 add b32 $r2 NV_PGRAPH_GPCX_GPCCS_STRAND_CMD_SAVE
319 nv_iowr(NV_PGRAPH_GPCX_GPCCS_STRAND_CMD, 0x3f, $r2)
322 xbit $r10 $flags $p1 // direction
325 ld b32 $r12 D[$r0 + #gpc_id]
327 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn
328 ld b32 $r12 D[$r0 + #gpc_mmio_list_head]
329 ld b32 $r13 D[$r0 + #gpc_mmio_list_tail]
330 mov $r14 0 // not multi
333 // per-TPC mmio context
334 xbit $r10 $flags $p1 // direction
335 #if !NV_PGRAPH_GPCX_UNK__SIZE
338 imm32($r11, 0x504000)
339 ld b32 $r12 D[$r0 + #gpc_id]
341 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn_TPC0
342 ld b32 $r12 D[$r0 + #tpc_mmio_list_head]
343 ld b32 $r13 D[$r0 + #tpc_mmio_list_tail]
344 ld b32 $r15 D[$r0 + #tpc_mask]
345 mov $r14 0x800 // stride = 0x800
348 #if NV_PGRAPH_GPCX_UNK__SIZE > 0
349 // per-UNK mmio context
350 xbit $r10 $flags $p1 // direction
352 imm32($r11, 0x503000)
353 ld b32 $r12 D[$r0 + #gpc_id]
355 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn_UNK0
356 ld b32 $r12 D[$r0 + #unk_mmio_list_head]
357 ld b32 $r13 D[$r0 + #unk_mmio_list_tail]
358 ld b32 $r15 D[$r0 + #unk_mask]
359 mov $r14 0x200 // stride = 0x200
363 // wait for strands to finish
366 // if load, or a save without a load following, do some
367 // unknown stuff that's done after finishing a block of
369 bra $p1 #ctx_xfer_post
370 bra not $p2 #ctx_xfer_done
374 // mark completion in HUB's barrier
376 call(hub_barrier_done)