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