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 * m4 nvc0_grgpc.fuc | envyas -a -w -m fuc -V nva3 -o nvc0_grgpc.fuc.h
31 * - bracket certain functions with scratch writes, useful for debugging
32 * - watchdog timer around ctx operations
35 .section #nvc0_grgpc_data
36 include(`nvc0_graph.fuc')
38 gpc_mmio_list_head: .b32 0
39 gpc_mmio_list_tail: .b32 0
43 tpc_mmio_list_head: .b32 0
44 tpc_mmio_list_tail: .b32 0
48 // chipset descriptions
51 .b16 #nvc0_gpc_mmio_head
52 .b16 #nvc0_gpc_mmio_tail
53 .b16 #nvc0_tpc_mmio_head
54 .b16 #nvc0_tpc_mmio_tail
56 .b16 #nvc0_gpc_mmio_head
57 .b16 #nvc1_gpc_mmio_tail
58 .b16 #nvc0_tpc_mmio_head
59 .b16 #nvc1_tpc_mmio_tail
61 .b16 #nvc0_gpc_mmio_head
62 .b16 #nvc0_gpc_mmio_tail
63 .b16 #nvc0_tpc_mmio_head
64 .b16 #nvc3_tpc_mmio_tail
66 .b16 #nvc0_gpc_mmio_head
67 .b16 #nvc0_gpc_mmio_tail
68 .b16 #nvc0_tpc_mmio_head
69 .b16 #nvc3_tpc_mmio_tail
71 .b16 #nvc0_gpc_mmio_head
72 .b16 #nvc0_gpc_mmio_tail
73 .b16 #nvc0_tpc_mmio_head
74 .b16 #nvc0_tpc_mmio_tail
76 .b16 #nvc0_gpc_mmio_head
77 .b16 #nvc0_gpc_mmio_tail
78 .b16 #nvc0_tpc_mmio_head
79 .b16 #nvc3_tpc_mmio_tail
81 .b16 #nvc0_gpc_mmio_head
82 .b16 #nvc0_gpc_mmio_tail
83 .b16 #nvc0_tpc_mmio_head
84 .b16 #nvcf_tpc_mmio_tail
86 .b16 #nvd9_gpc_mmio_head
87 .b16 #nvd9_gpc_mmio_tail
88 .b16 #nvd9_tpc_mmio_head
89 .b16 #nvd9_tpc_mmio_tail
94 mmctx_data(0x000380, 1)
95 mmctx_data(0x000400, 6)
96 mmctx_data(0x000450, 9)
97 mmctx_data(0x000600, 1)
98 mmctx_data(0x000684, 1)
99 mmctx_data(0x000700, 5)
100 mmctx_data(0x000800, 1)
101 mmctx_data(0x000808, 3)
102 mmctx_data(0x000828, 1)
103 mmctx_data(0x000830, 1)
104 mmctx_data(0x0008d8, 1)
105 mmctx_data(0x0008e0, 1)
106 mmctx_data(0x0008e8, 6)
107 mmctx_data(0x00091c, 1)
108 mmctx_data(0x000924, 3)
109 mmctx_data(0x000b00, 1)
110 mmctx_data(0x000b08, 6)
111 mmctx_data(0x000bb8, 1)
112 mmctx_data(0x000c08, 1)
113 mmctx_data(0x000c10, 8)
114 mmctx_data(0x000c80, 1)
115 mmctx_data(0x000c8c, 1)
116 mmctx_data(0x001000, 3)
117 mmctx_data(0x001014, 1)
119 mmctx_data(0x000c6c, 1);
123 mmctx_data(0x000380, 1)
124 mmctx_data(0x000400, 2)
125 mmctx_data(0x00040c, 3)
126 mmctx_data(0x000450, 9)
127 mmctx_data(0x000600, 1)
128 mmctx_data(0x000684, 1)
129 mmctx_data(0x000700, 5)
130 mmctx_data(0x000800, 1)
131 mmctx_data(0x000808, 3)
132 mmctx_data(0x000828, 1)
133 mmctx_data(0x000830, 1)
134 mmctx_data(0x0008d8, 1)
135 mmctx_data(0x0008e0, 1)
136 mmctx_data(0x0008e8, 6)
137 mmctx_data(0x00091c, 1)
138 mmctx_data(0x000924, 3)
139 mmctx_data(0x000b00, 1)
140 mmctx_data(0x000b08, 6)
141 mmctx_data(0x000bb8, 1)
142 mmctx_data(0x000c08, 1)
143 mmctx_data(0x000c10, 8)
144 mmctx_data(0x000c6c, 1)
145 mmctx_data(0x000c80, 1)
146 mmctx_data(0x000c8c, 1)
147 mmctx_data(0x001000, 3)
148 mmctx_data(0x001014, 1)
153 mmctx_data(0x000018, 1)
154 mmctx_data(0x00003c, 1)
155 mmctx_data(0x000048, 1)
156 mmctx_data(0x000064, 1)
157 mmctx_data(0x000088, 1)
158 mmctx_data(0x000200, 6)
159 mmctx_data(0x00021c, 2)
160 mmctx_data(0x000300, 6)
161 mmctx_data(0x0003d0, 1)
162 mmctx_data(0x0003e0, 2)
163 mmctx_data(0x000400, 3)
164 mmctx_data(0x000420, 1)
165 mmctx_data(0x0004b0, 1)
166 mmctx_data(0x0004e8, 1)
167 mmctx_data(0x0004f4, 1)
168 mmctx_data(0x000520, 2)
169 mmctx_data(0x000604, 4)
170 mmctx_data(0x000644, 20)
171 mmctx_data(0x000698, 1)
172 mmctx_data(0x000750, 2)
174 mmctx_data(0x000758, 1)
175 mmctx_data(0x0002c4, 1)
176 mmctx_data(0x0006e0, 1)
178 mmctx_data(0x0004bc, 1)
180 mmctx_data(0x000544, 1)
184 mmctx_data(0x000018, 1)
185 mmctx_data(0x00003c, 1)
186 mmctx_data(0x000048, 1)
187 mmctx_data(0x000064, 1)
188 mmctx_data(0x000088, 1)
189 mmctx_data(0x000200, 6)
190 mmctx_data(0x00021c, 2)
191 mmctx_data(0x0002c4, 1)
192 mmctx_data(0x000300, 6)
193 mmctx_data(0x0003d0, 1)
194 mmctx_data(0x0003e0, 2)
195 mmctx_data(0x000400, 3)
196 mmctx_data(0x000420, 3)
197 mmctx_data(0x0004b0, 1)
198 mmctx_data(0x0004e8, 1)
199 mmctx_data(0x0004f4, 1)
200 mmctx_data(0x000520, 2)
201 mmctx_data(0x000544, 1)
202 mmctx_data(0x000604, 4)
203 mmctx_data(0x000644, 20)
204 mmctx_data(0x000698, 1)
205 mmctx_data(0x0006e0, 1)
206 mmctx_data(0x000750, 3)
209 .section #nvc0_grgpc_code
211 define(`include_code')
212 include(`nvc0_graph.fuc')
214 // reports an exception to the host
216 // In: $r15 error code (see nvc0_graph.fuc)
220 mov $r14 -0x67ec // 0x9814
222 call #nv_wr32 // HUB_CTXCTL_CC_SCRATCH[5] = error code
225 call #nv_wr32 // HUB_CTXCTL_INTR_UP_SET
229 // GPC fuc initialisation, executed by triggering ucode start, will
230 // fall through to main loop after completion.
233 // CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
234 // CC_SCRATCH[1]: context base
238 // 31:31: set to signal completion
240 // 31:0: GPC context size
246 // enable fifo access
249 iowr I[$r1 + 0x000] $r2 // FIFO_ENABLE
251 // setup i0 handler, and route all interrupts to it
255 iowr I[$r1 + 0x300] $r0 // INTR_DISPATCH
257 // enable fifo interrupt
259 iowr I[$r1 + 0x000] $r2 // INTR_EN_SET
264 // figure out which GPC we are, and how many TPCs we have
267 iord $r2 I[$r1 + 0x000] // UNITS
272 st b32 D[$r0 + #tpc_count] $r2
273 st b32 D[$r0 + #tpc_mask] $r3
275 iord $r2 I[$r1 + 0x000] // MYINDEX
276 st b32 D[$r0 + #gpc_id] $r2
278 // find context data for this chipset
281 iord $r2 I[$r2 + 0x000] // CC_SCRATCH[0]
282 mov $r1 #chipsets - 12
285 ld b32 $r3 D[$r1 + 0x00]
289 bra ne #init_find_chipset
293 // initialise context base, and size tracking
297 iord $r2 I[$r2 + 0x100] // CC_SCRATCH[1], initial base
298 clear b32 $r3 // track GPC context size here
300 // set mmctx base addresses now so we don't have to do it later,
301 // they don't currently ever change
305 iowr I[$r4 + 0x000] $r5 // MMCTX_SAVE_SWBASE
306 iowr I[$r4 + 0x100] $r5 // MMCTX_LOAD_SWBASE
308 // calculate GPC mmio context size, store the chipset-specific
309 // mmio list pointers somewhere we can get at them later without
310 // re-parsing the chipset list
313 ld b16 $r14 D[$r1 + 4]
314 ld b16 $r15 D[$r1 + 6]
315 st b16 D[$r0 + #gpc_mmio_list_head] $r14
316 st b16 D[$r0 + #gpc_mmio_list_tail] $r15
321 // calculate per-TPC mmio context size, store the list pointers
322 ld b16 $r14 D[$r1 + 8]
323 ld b16 $r15 D[$r1 + 10]
324 st b16 D[$r0 + #tpc_mmio_list_head] $r14
325 st b16 D[$r0 + #tpc_mmio_list_tail] $r15
327 ld b32 $r14 D[$r0 + #tpc_count]
332 // round up base/size to 256 byte boundary (for strand SWBASE)
335 iowr I[$r4 + 0x000] $r3 // MMCTX_LOAD_COUNT, wtf for?!?
343 // calculate size of strand context data
345 call #strand_ctx_init
348 // save context size, and tell HUB we're done
351 iowr I[$r1 + 0x100] $r3 // CC_SCRATCH[1] = context size
355 iowr I[$r1 + 0x000] $r2 // CC_SCRATCH[0] |= 0x80000000
357 // Main program loop, very simple, sleeps until woken up by the interrupt
358 // handler, pulls a command from the queue and executes its handler
367 // 0x0000-0x0003 are all context transfers
369 bra nc #main_not_ctx_xfer
370 // fetch $flags and mask off $p1/$p2
375 // set $p1/$p2 according to transfer type
379 // transfer context data
385 or $r15 E_BAD_COMMAND
401 // incoming fifo command?
402 iord $r10 I[$r0 + 0x200] // INTR
403 and $r11 $r10 0x00000004
405 // queue incoming fifo command for later processing
408 iord $r14 I[$r11 + 0x100] // FIFO_CMD
409 iord $r15 I[$r11 + 0x000] // FIFO_DATA
413 iowr I[$r11 + 0x000] $r14 // FIFO_ACK
415 // ack, and wake up main()
417 iowr I[$r0 + 0x100] $r10 // INTR_ACK
431 // Set this GPC's bit in HUB_BAR, used to signal completion of various
432 // activities to the HUB fuc
436 ld b32 $r14 D[$r0 + #gpc_id]
438 mov $r14 -0x6be8 // 0x409418 - HUB_BAR_SET
443 // Disables various things, waits a bit, and re-enables them..
445 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
446 // good description for the bits we turn off? Anyways, without this,
447 // funny things happen.
453 iowr I[$r14] $r15 // GPC_RED_SWITCH = POWER
457 bra ne #ctx_redswitch_delay
459 iowr I[$r14] $r15 // GPC_RED_SWITCH = UNK11, ENABLE, POWER
462 // Transfer GPC context data between GPU and storage area
464 // In: $r15 context base address
465 // $p1 clear on save, set on load
466 // $p2 set if opposite direction done/will be done, so:
467 // on save it means: "a load will follow this save"
468 // on load it means: "a save preceeded this load"
471 // set context base address
474 iowr I[$r1 + 0x000] $r15// MEM_BASE
475 bra not $p1 #ctx_xfer_not_load
483 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0c
487 iowr I[$r2] $r0 // STRAND_FIRST_GENE(0x3f) = 0x00
490 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
493 xbit $r10 $flags $p1 // direction
497 ld b32 $r12 D[$r0 + #gpc_id]
499 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn
500 ld b32 $r12 D[$r0 + #gpc_mmio_list_head]
501 ld b32 $r13 D[$r0 + #gpc_mmio_list_tail]
502 mov $r14 0 // not multi
505 // per-TPC mmio context
506 xbit $r10 $flags $p1 // direction
509 sethi $r11 0x500000 // base = NV_PGRAPH_GPC0_TPC0
510 ld b32 $r12 D[$r0 + #gpc_id]
512 add b32 $r11 $r12 // base = NV_PGRAPH_GPCn_TPC0
513 ld b32 $r12 D[$r0 + #tpc_mmio_list_head]
514 ld b32 $r13 D[$r0 + #tpc_mmio_list_tail]
515 ld b32 $r15 D[$r0 + #tpc_mask]
516 mov $r14 0x800 // stride = 0x800
519 // wait for strands to finish
522 // if load, or a save without a load following, do some
523 // unknown stuff that's done after finishing a block of
525 bra $p1 #ctx_xfer_post
526 bra not $p2 #ctx_xfer_done
531 iowr I[$r1] $r2 // STRAND_CMD(0x3f) = 0x0d
534 // mark completion in HUB's barrier
536 call #hub_barrier_done