]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/engine/graph/fuc/gpcnve0.fuc
ARM: delete struct sys_timer
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / engine / graph / fuc / gpcnve0.fuc
1 /* fuc microcode for nve0 PGRAPH/GPC
2  *
3  * Copyright 2011 Red Hat Inc.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
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.
22  *
23  * Authors: Ben Skeggs
24  */
25
26 /* To build:
27  *    m4 nve0_grgpc.fuc | envyas -a -w -m fuc -V nva3 -o nve0_grgpc.fuc.h
28  */
29
30 /* TODO
31  * - bracket certain functions with scratch writes, useful for debugging
32  * - watchdog timer around ctx operations
33  */
34
35 .section #nve0_grgpc_data
36 include(`nve0.fuc')
37 gpc_id:                 .b32 0
38 gpc_mmio_list_head:     .b32 0
39 gpc_mmio_list_tail:     .b32 0
40
41 tpc_count:              .b32 0
42 tpc_mask:               .b32 0
43 tpc_mmio_list_head:     .b32 0
44 tpc_mmio_list_tail:     .b32 0
45
46 cmd_queue:              queue_init
47
48 // chipset descriptions
49 chipsets:
50 .b8  0xe4 0 0 0
51 .b16 #nve4_gpc_mmio_head
52 .b16 #nve4_gpc_mmio_tail
53 .b16 #nve4_tpc_mmio_head
54 .b16 #nve4_tpc_mmio_tail
55 .b8  0xe7 0 0 0
56 .b16 #nve4_gpc_mmio_head
57 .b16 #nve4_gpc_mmio_tail
58 .b16 #nve4_tpc_mmio_head
59 .b16 #nve4_tpc_mmio_tail
60 .b8  0 0 0 0
61
62 // GPC mmio lists
63 nve4_gpc_mmio_head:
64 mmctx_data(0x000380, 1)
65 mmctx_data(0x000400, 2)
66 mmctx_data(0x00040c, 3)
67 mmctx_data(0x000450, 9)
68 mmctx_data(0x000600, 1)
69 mmctx_data(0x000684, 1)
70 mmctx_data(0x000700, 5)
71 mmctx_data(0x000800, 1)
72 mmctx_data(0x000808, 3)
73 mmctx_data(0x000828, 1)
74 mmctx_data(0x000830, 1)
75 mmctx_data(0x0008d8, 1)
76 mmctx_data(0x0008e0, 1)
77 mmctx_data(0x0008e8, 6)
78 mmctx_data(0x00091c, 1)
79 mmctx_data(0x000924, 3)
80 mmctx_data(0x000b00, 1)
81 mmctx_data(0x000b08, 6)
82 mmctx_data(0x000bb8, 1)
83 mmctx_data(0x000c08, 1)
84 mmctx_data(0x000c10, 8)
85 mmctx_data(0x000c40, 1)
86 mmctx_data(0x000c6c, 1)
87 mmctx_data(0x000c80, 1)
88 mmctx_data(0x000c8c, 1)
89 mmctx_data(0x001000, 3)
90 mmctx_data(0x001014, 1)
91 mmctx_data(0x003024, 1)
92 mmctx_data(0x0030c0, 2)
93 mmctx_data(0x0030e4, 1)
94 mmctx_data(0x003100, 6)
95 mmctx_data(0x0031d0, 1)
96 mmctx_data(0x0031e0, 2)
97 nve4_gpc_mmio_tail:
98
99 // TPC mmio lists
100 nve4_tpc_mmio_head:
101 mmctx_data(0x000048, 1)
102 mmctx_data(0x000064, 1)
103 mmctx_data(0x000088, 1)
104 mmctx_data(0x000200, 6)
105 mmctx_data(0x00021c, 2)
106 mmctx_data(0x000230, 1)
107 mmctx_data(0x0002c4, 1)
108 mmctx_data(0x000400, 3)
109 mmctx_data(0x000420, 3)
110 mmctx_data(0x0004e8, 1)
111 mmctx_data(0x0004f4, 1)
112 mmctx_data(0x000604, 4)
113 mmctx_data(0x000644, 22)
114 mmctx_data(0x0006ac, 2)
115 mmctx_data(0x0006c8, 1)
116 mmctx_data(0x000730, 8)
117 mmctx_data(0x000758, 1)
118 mmctx_data(0x000778, 1)
119 nve4_tpc_mmio_tail:
120
121 .section #nve0_grgpc_code
122 bra #init
123 define(`include_code')
124 include(`nve0.fuc')
125
126 // reports an exception to the host
127 //
128 // In: $r15 error code (see nve0.fuc)
129 //
130 error:
131         push $r14
132         mov $r14 -0x67ec        // 0x9814
133         sethi $r14 0x400000
134         call #nv_wr32           // HUB_CTXCTL_CC_SCRATCH[5] = error code
135         add b32 $r14 0x41c
136         mov $r15 1
137         call #nv_wr32           // HUB_CTXCTL_INTR_UP_SET
138         pop $r14
139         ret
140
141 // GPC fuc initialisation, executed by triggering ucode start, will
142 // fall through to main loop after completion.
143 //
144 // Input:
145 //   CC_SCRATCH[0]: chipset (PMC_BOOT_0 read returns 0x0bad0bad... sigh)
146 //   CC_SCRATCH[1]: context base
147 //
148 // Output:
149 //   CC_SCRATCH[0]:
150 //           31:31: set to signal completion
151 //   CC_SCRATCH[1]:
152 //            31:0: GPC context size
153 //
154 init:
155         clear b32 $r0
156         mov $sp $r0
157
158         // enable fifo access
159         mov $r1 0x1200
160         mov $r2 2
161         iowr I[$r1 + 0x000] $r2         // FIFO_ENABLE
162
163         // setup i0 handler, and route all interrupts to it
164         mov $r1 #ih
165         mov $iv0 $r1
166         mov $r1 0x400
167         iowr I[$r1 + 0x300] $r0         // INTR_DISPATCH
168
169         // enable fifo interrupt
170         mov $r2 4
171         iowr I[$r1 + 0x000] $r2         // INTR_EN_SET
172
173         // enable interrupts
174         bset $flags ie0
175
176         // figure out which GPC we are, and how many TPCs we have
177         mov $r1 0x608
178         shl b32 $r1 6
179         iord $r2 I[$r1 + 0x000]         // UNITS
180         mov $r3 1
181         and $r2 0x1f
182         shl b32 $r3 $r2
183         sub b32 $r3 1
184         st b32 D[$r0 + #tpc_count] $r2
185         st b32 D[$r0 + #tpc_mask] $r3
186         add b32 $r1 0x400
187         iord $r2 I[$r1 + 0x000]         // MYINDEX
188         st b32 D[$r0 + #gpc_id] $r2
189
190         // find context data for this chipset
191         mov $r2 0x800
192         shl b32 $r2 6
193         iord $r2 I[$r2 + 0x000]         // CC_SCRATCH[0]
194         mov $r1 #chipsets - 12
195         init_find_chipset:
196                 add b32 $r1 12
197                 ld b32 $r3 D[$r1 + 0x00]
198                 cmpu b32 $r3 $r2
199                 bra e #init_context
200                 cmpu b32 $r3 0
201                 bra ne #init_find_chipset
202                 // unknown chipset
203                 ret
204
205         // initialise context base, and size tracking
206         init_context:
207         mov $r2 0x800
208         shl b32 $r2 6
209         iord $r2 I[$r2 + 0x100] // CC_SCRATCH[1], initial base
210         clear b32 $r3           // track GPC context size here
211
212         // set mmctx base addresses now so we don't have to do it later,
213         // they don't currently ever change
214         mov $r4 0x700
215         shl b32 $r4 6
216         shr b32 $r5 $r2 8
217         iowr I[$r4 + 0x000] $r5         // MMCTX_SAVE_SWBASE
218         iowr I[$r4 + 0x100] $r5         // MMCTX_LOAD_SWBASE
219
220         // calculate GPC mmio context size, store the chipset-specific
221         // mmio list pointers somewhere we can get at them later without
222         // re-parsing the chipset list
223         clear b32 $r14
224         clear b32 $r15
225         ld b16 $r14 D[$r1 + 4]
226         ld b16 $r15 D[$r1 + 6]
227         st b16 D[$r0 + #gpc_mmio_list_head] $r14
228         st b16 D[$r0 + #gpc_mmio_list_tail] $r15
229         call #mmctx_size
230         add b32 $r2 $r15
231         add b32 $r3 $r15
232
233         // calculate per-TPC mmio context size, store the list pointers
234         ld b16 $r14 D[$r1 + 8]
235         ld b16 $r15 D[$r1 + 10]
236         st b16 D[$r0 + #tpc_mmio_list_head] $r14
237         st b16 D[$r0 + #tpc_mmio_list_tail] $r15
238         call #mmctx_size
239         ld b32 $r14 D[$r0 + #tpc_count]
240         mulu $r14 $r15
241         add b32 $r2 $r14
242         add b32 $r3 $r14
243
244         // round up base/size to 256 byte boundary (for strand SWBASE)
245         add b32 $r4 0x1300
246         shr b32 $r3 2
247         iowr I[$r4 + 0x000] $r3         // MMCTX_LOAD_COUNT, wtf for?!?
248         shr b32 $r2 8
249         shr b32 $r3 6
250         add b32 $r2 1
251         add b32 $r3 1
252         shl b32 $r2 8
253         shl b32 $r3 8
254
255         // calculate size of strand context data
256         mov b32 $r15 $r2
257         call #strand_ctx_init
258         add b32 $r3 $r15
259
260         // save context size, and tell HUB we're done
261         mov $r1 0x800
262         shl b32 $r1 6
263         iowr I[$r1 + 0x100] $r3         // CC_SCRATCH[1]  = context size
264         add b32 $r1 0x800
265         clear b32 $r2
266         bset $r2 31
267         iowr I[$r1 + 0x000] $r2         // CC_SCRATCH[0] |= 0x80000000
268
269 // Main program loop, very simple, sleeps until woken up by the interrupt
270 // handler, pulls a command from the queue and executes its handler
271 //
272 main:
273         bset $flags $p0
274         sleep $p0
275         mov $r13 #cmd_queue
276         call #queue_get
277         bra $p1 #main
278
279         // 0x0000-0x0003 are all context transfers
280         cmpu b32 $r14 0x04
281         bra nc #main_not_ctx_xfer
282                 // fetch $flags and mask off $p1/$p2
283                 mov $r1 $flags
284                 mov $r2 0x0006
285                 not b32 $r2
286                 and $r1 $r2
287                 // set $p1/$p2 according to transfer type
288                 shl b32 $r14 1
289                 or $r1 $r14
290                 mov $flags $r1
291                 // transfer context data
292                 call #ctx_xfer
293                 bra #main
294
295         main_not_ctx_xfer:
296         shl b32 $r15 $r14 16
297         or $r15 E_BAD_COMMAND
298         call #error
299         bra #main
300
301 // interrupt handler
302 ih:
303         push $r8
304         mov $r8 $flags
305         push $r8
306         push $r9
307         push $r10
308         push $r11
309         push $r13
310         push $r14
311         push $r15
312
313         // incoming fifo command?
314         iord $r10 I[$r0 + 0x200]        // INTR
315         and $r11 $r10 0x00000004
316         bra e #ih_no_fifo
317                 // queue incoming fifo command for later processing
318                 mov $r11 0x1900
319                 mov $r13 #cmd_queue
320                 iord $r14 I[$r11 + 0x100]       // FIFO_CMD
321                 iord $r15 I[$r11 + 0x000]       // FIFO_DATA
322                 call #queue_put
323                 add b32 $r11 0x400
324                 mov $r14 1
325                 iowr I[$r11 + 0x000] $r14       // FIFO_ACK
326
327         // ack, and wake up main()
328         ih_no_fifo:
329         iowr I[$r0 + 0x100] $r10        // INTR_ACK
330
331         pop $r15
332         pop $r14
333         pop $r13
334         pop $r11
335         pop $r10
336         pop $r9
337         pop $r8
338         mov $flags $r8
339         pop $r8
340         bclr $flags $p0
341         iret
342
343 // Set this GPC's bit in HUB_BAR, used to signal completion of various
344 // activities to the HUB fuc
345 //
346 hub_barrier_done:
347         mov $r15 1
348         ld b32 $r14 D[$r0 + #gpc_id]
349         shl b32 $r15 $r14
350         mov $r14 -0x6be8        // 0x409418 - HUB_BAR_SET
351         sethi $r14 0x400000
352         call #nv_wr32
353         ret
354
355 // Disables various things, waits a bit, and re-enables them..
356 //
357 // Not sure how exactly this helps, perhaps "ENABLE" is not such a
358 // good description for the bits we turn off?  Anyways, without this,
359 // funny things happen.
360 //
361 ctx_redswitch:
362         mov $r14 0x614
363         shl b32 $r14 6
364         mov $r15 0x020
365         iowr I[$r14] $r15       // GPC_RED_SWITCH = POWER
366         mov $r15 8
367         ctx_redswitch_delay:
368                 sub b32 $r15 1
369                 bra ne #ctx_redswitch_delay
370         mov $r15 0xa20
371         iowr I[$r14] $r15       // GPC_RED_SWITCH = UNK11, ENABLE, POWER
372         ret
373
374 // Transfer GPC context data between GPU and storage area
375 //
376 // In: $r15 context base address
377 //     $p1 clear on save, set on load
378 //     $p2 set if opposite direction done/will be done, so:
379 //              on save it means: "a load will follow this save"
380 //              on load it means: "a save preceeded this load"
381 //
382 ctx_xfer:
383         // set context base address
384         mov $r1 0xa04
385         shl b32 $r1 6
386         iowr I[$r1 + 0x000] $r15// MEM_BASE
387         bra not $p1 #ctx_xfer_not_load
388                 call #ctx_redswitch
389         ctx_xfer_not_load:
390
391         // strands
392         mov $r1 0x4afc
393         sethi $r1 0x20000
394         mov $r2 0xc
395         iowr I[$r1] $r2         // STRAND_CMD(0x3f) = 0x0c
396         call #strand_wait
397         mov $r2 0x47fc
398         sethi $r2 0x20000
399         iowr I[$r2] $r0         // STRAND_FIRST_GENE(0x3f) = 0x00
400         xbit $r2 $flags $p1
401         add b32 $r2 3
402         iowr I[$r1] $r2         // STRAND_CMD(0x3f) = 0x03/0x04 (SAVE/LOAD)
403
404         // mmio context
405         xbit $r10 $flags $p1    // direction
406         or $r10 2               // first
407         mov $r11 0x0000
408         sethi $r11 0x500000
409         ld b32 $r12 D[$r0 + #gpc_id]
410         shl b32 $r12 15
411         add b32 $r11 $r12       // base = NV_PGRAPH_GPCn
412         ld b32 $r12 D[$r0 + #gpc_mmio_list_head]
413         ld b32 $r13 D[$r0 + #gpc_mmio_list_tail]
414         mov $r14 0              // not multi
415         call #mmctx_xfer
416
417         // per-TPC mmio context
418         xbit $r10 $flags $p1    // direction
419         or $r10 4               // last
420         mov $r11 0x4000
421         sethi $r11 0x500000     // base = NV_PGRAPH_GPC0_TPC0
422         ld b32 $r12 D[$r0 + #gpc_id]
423         shl b32 $r12 15
424         add b32 $r11 $r12       // base = NV_PGRAPH_GPCn_TPC0
425         ld b32 $r12 D[$r0 + #tpc_mmio_list_head]
426         ld b32 $r13 D[$r0 + #tpc_mmio_list_tail]
427         ld b32 $r15 D[$r0 + #tpc_mask]
428         mov $r14 0x800          // stride = 0x800
429         call #mmctx_xfer
430
431         // wait for strands to finish
432         call #strand_wait
433
434         // if load, or a save without a load following, do some
435         // unknown stuff that's done after finishing a block of
436         // strand commands
437         bra $p1 #ctx_xfer_post
438         bra not $p2 #ctx_xfer_done
439         ctx_xfer_post:
440                 mov $r1 0x4afc
441                 sethi $r1 0x20000
442                 mov $r2 0xd
443                 iowr I[$r1] $r2         // STRAND_CMD(0x3f) = 0x0d
444                 call #strand_wait
445
446         // mark completion in HUB's barrier
447         ctx_xfer_done:
448         call #hub_barrier_done
449         ret
450
451 .align 256