1 /* fuc microcode for copy engine on nva3- chipsets
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.
26 /* To build for nva3:nvc0
27 * m4 -DNVA3 nva3_copy.fuc | envyas -a -w -m fuc -V nva3 -o nva3_copy.fuc.h
30 * m4 -DNVC0 nva3_copy.fuc | envyas -a -w -m fuc -V nva3 -o nvc0_copy.fuc.h
34 .section #nva3_pcopy_data
36 .section #nvc0_pcopy_data
47 ctx_query_address_high: .b32 0
48 ctx_query_address_low: .b32 0
49 ctx_query_counter: .b32 0
50 ctx_src_address_high: .b32 0
51 ctx_src_address_low: .b32 0
53 ctx_src_tile_mode: .b32 0
61 ctx_dst_address_high: .b32 0
62 ctx_dst_address_low: .b32 0
64 ctx_dst_tile_mode: .b32 0
73 ctx_swz_const0: .b32 0
74 ctx_swz_const1: .b32 0
82 .b32 #ctx_object ~0xffffffff
85 .b32 0x00010000 + #cmd_nop ~0xffffffff
86 // mthd 0x0140, PM_TRIGGER
88 .b32 0x00010000 + #cmd_pm_trigger ~0xffffffff
90 // mthd 0x0180-0x018c, DMA_
91 .b16 0x060 #ctx_dma_count
93 .b32 0x00010000 + #cmd_dma ~0xffffffff
94 .b32 0x00010000 + #cmd_dma ~0xffffffff
95 .b32 0x00010000 + #cmd_dma ~0xffffffff
97 // mthd 0x0200-0x0218, SRC_TILE
99 .b32 #ctx_src_tile_mode ~0x00000fff
100 .b32 #ctx_src_xsize ~0x0007ffff
101 .b32 #ctx_src_ysize ~0x00001fff
102 .b32 #ctx_src_zsize ~0x000007ff
103 .b32 #ctx_src_zoff ~0x00000fff
104 .b32 #ctx_src_xoff ~0x0007ffff
105 .b32 #ctx_src_yoff ~0x00001fff
106 // mthd 0x0220-0x0238, DST_TILE
108 .b32 #ctx_dst_tile_mode ~0x00000fff
109 .b32 #ctx_dst_xsize ~0x0007ffff
110 .b32 #ctx_dst_ysize ~0x00001fff
111 .b32 #ctx_dst_zsize ~0x000007ff
112 .b32 #ctx_dst_zoff ~0x00000fff
113 .b32 #ctx_dst_xoff ~0x0007ffff
114 .b32 #ctx_dst_yoff ~0x00001fff
115 // mthd 0x0300-0x0304, EXEC, WRCACHE_FLUSH
117 .b32 0x00010000 + #cmd_exec ~0xffffffff
118 .b32 0x00010000 + #cmd_wrcache_flush ~0xffffffff
119 // mthd 0x030c-0x0340, various stuff
121 .b32 #ctx_src_address_high ~0x000000ff
122 .b32 #ctx_src_address_low ~0xfffffff0
123 .b32 #ctx_dst_address_high ~0x000000ff
124 .b32 #ctx_dst_address_low ~0xfffffff0
125 .b32 #ctx_src_pitch ~0x0007ffff
126 .b32 #ctx_dst_pitch ~0x0007ffff
127 .b32 #ctx_xcnt ~0x0000ffff
128 .b32 #ctx_ycnt ~0x00001fff
129 .b32 #ctx_format ~0x0333ffff
130 .b32 #ctx_swz_const0 ~0xffffffff
131 .b32 #ctx_swz_const1 ~0xffffffff
132 .b32 #ctx_query_address_high ~0x000000ff
133 .b32 #ctx_query_address_low ~0xffffffff
134 .b32 #ctx_query_counter ~0xffffffff
138 .section #nva3_pcopy_code
140 .section #nvc0_pcopy_code
147 // setup i0 handler and route fifo and ctxswitch to it
153 iowr I[$r1 + 0x300] $r2
160 // enable fifo access and context switching
165 // sleep forever, waking for interrupts
173 iord $r1 I[$r0 + 0x200]
175 and $r2 $r1 0x00000008
179 and $r2 $r1 0x00000004
184 and $r1 $r1 0x0000000c
185 iowr I[$r0 + 0x100] $r1
188 // $p1 direction (0 = unload, 1 = load)
194 // target 7 hardcoded to ctx dma object
197 // read SCRATCH3 to decide if we are PCOPY0 or PCOPY1
204 // channel is in vram
210 // read 16-byte PCOPYn info, containing context pointer, from channel
215 // get a chunk of stack space, aligned to 256 byte boundary
225 // set context pointer, from within channel VM
228 ld b32 $r4 D[$r5 + 0]
230 ld b32 $r6 D[$r5 + 4]
235 // 256-byte context, at start of data segment
250 // read current channel
254 // if it's active, unload it and return
256 bra e #chsw_no_unload
262 iowr I[$r2 + 0x200] $r4
267 iord $r3 I[$r2 + 0x100]
269 // is there a channel waiting to be loaded?
271 bra e #chsw_finish_load
275 // load dma objects back into TARGET regs
277 mov $r6 #ctx_dma_count
279 ld b32 $r7 D[$r5 + $r6 * 4]
280 add b32 $r8 $r6 0x180
284 bra nc #chsw_load_ctx_dma
289 iowr I[$r2 + 0x200] $r3
293 // read incoming fifo command
295 iord $r2 I[$r3 + 0x100]
296 iord $r3 I[$r3 + 0x000]
298 // $r2 will be used to store exception data
301 // lookup method in the dispatch table, ILLEGAL_MTHD if not found
302 mov $r5 #dispatch_table
306 ld b16 $r6 D[$r5 + 0]
307 ld b16 $r7 D[$r5 + 2]
310 bra c #dispatch_illegal_mthd
313 bra c #dispatch_valid_mthd
319 // ensure no bits set in reserved fields, INVALID_BITFIELD
324 ld b32 $r5 D[$r4 + 4]
327 bra ne #dispatch_invalid_bitfield
329 // depending on dispatch flags: execute method, or save data as state
330 ld b16 $r5 D[$r4 + 0]
331 ld b16 $r6 D[$r4 + 2]
339 bra $p1 #dispatch_error
342 dispatch_invalid_bitfield:
344 dispatch_illegal_mthd:
347 // store exception data in SCRATCH0/SCRATCH1, signal hostirq
350 iowr I[$r4 + 0x000] $r2
351 iowr I[$r4 + 0x100] $r3
355 iord $r2 I[$r0 + 0x200]
370 // $r2: hostirq state
372 // $r4: dispatch table entry
376 // $r2: hostirq state
385 // $r2: hostirq state
387 // $r4: dispatch table entry
391 // $r2: hostirq state
401 // SET_DMA_* method handler
405 // $r2: hostirq state
407 // $r4: dispatch table entry
411 // $r2: hostirq state
414 sub b32 $r4 #dispatch_dma
417 st b32 D[$r4 + #ctx_dma] $r3
424 // Calculates the hw swizzle mask and adjusts the surface's xcnt to match
427 // zero out a chunk of the stack to store the swizzle into
429 st b32 D[$sp + 0x00] $r0
430 st b32 D[$sp + 0x04] $r0
431 st b32 D[$sp + 0x08] $r0
432 st b32 D[$sp + 0x0c] $r0
434 // extract cpp, src_ncomp and dst_ncomp from FORMAT
435 ld b32 $r4 D[$r0 + #ctx_format]
443 // convert FORMAT swizzle mask to hw swizzle mask
472 st b8 D[$sp + $r8] $r12
481 // SRC_XCNT = (xcnt * src_cpp), or 0 if no src ref in swz (hw will hang)
483 st b32 D[$r0 + #ctx_src_cpp] $r6
484 ld b32 $r8 D[$r0 + #ctx_xcnt]
491 st b32 D[$r0 + #ctx_dst_cpp] $r7
496 iowr I[$r5 + 0x000] $r6
497 iowr I[$r5 + 0x100] $r7
499 ld b32 $r6 D[$r0 + #ctx_dst_cpp]
502 ld b32 $r7 D[$r0 + #ctx_src_cpp]
505 iowr I[$r5 + 0x000] $r6
507 ld b32 $r6 D[$sp + 0x00]
508 iowr I[$r5 + 0x000] $r6
509 ld b32 $r6 D[$sp + 0x04]
510 iowr I[$r5 + 0x100] $r6
511 ld b32 $r6 D[$sp + 0x08]
512 iowr I[$r5 + 0x200] $r6
513 ld b32 $r6 D[$sp + 0x0c]
514 iowr I[$r5 + 0x300] $r6
516 ld b32 $r6 D[$r0 + #ctx_swz_const0]
517 iowr I[$r5 + 0x000] $r6
518 ld b32 $r6 D[$r0 + #ctx_swz_const1]
519 iowr I[$r5 + 0x100] $r6
523 // Setup to handle a tiled surface
525 // Calculates a number of parameters the hardware requires in order
526 // to correctly handle tiling.
528 // Offset calculation is performed as follows (Tp/Th/Td from TILE_MODE):
529 // nTx = round_up(w * cpp, 1 << Tp) >> Tp
530 // nTy = round_up(h, 1 << Th) >> Th
531 // Txo = (x * cpp) & ((1 << Tp) - 1)
532 // Tx = (x * cpp) >> Tp
533 // Tyo = y & ((1 << Th) - 1)
535 // Tzo = z & ((1 << Td) - 1)
538 // off = (Tzo << Tp << Th) + (Tyo << Tp) + Txo
539 // off += ((Tz * nTy * nTx)) + (Ty * nTx) + Tx) << Td << Th << Tp;
542 // $r4: hw command (0x104800)
543 // $r5: ctx offset adjustment for src/dst selection
544 // $p2: set if dst surface
546 cmd_exec_set_surface_tiled:
547 // translate TILE_MODE into Tp, Th, Td shift values
548 ld b32 $r7 D[$r5 + #ctx_src_tile_mode]
568 // Op = (x * cpp) & ((1 << Tp) - 1)
569 // Tx = (x * cpp) >> Tp
570 ld b32 $r10 D[$r5 + #ctx_src_xoff]
571 ld b32 $r11 D[$r5 + #ctx_src_cpp]
579 // Tyo = y & ((1 << Th) - 1)
581 ld b32 $r13 D[$r5 + #ctx_src_yoff]
588 // YTILE = ((1 << Th) << 12) | ((1 << Th) - Tyo)
596 iowr I[$r6 + 0x000] $r15
602 // nTx = ((w * cpp) + ((1 << Tp) - 1) >> Tp)
603 ld b32 $r15 D[$r5 + #ctx_src_xsize]
604 ld b32 $r11 D[$r5 + #ctx_src_cpp]
613 // nTy = (h + ((1 << Th) - 1)) >> Th
614 ld b32 $r15 D[$r5 + #ctx_src_ysize]
623 // CFG_YZ_TILE_SIZE = ((1 << Th) >> 2) << Td
630 // Tzo = z & ((1 << Td) - 1)
634 ld b32 $r8 D[$r5 + #ctx_src_zoff]
644 // Ot = ((Tz * nTy * nTx) + (Ty * nTx) + Tx) << Ts
654 // PITCH = (nTx - 1) << Ts
657 iowr I[$r6 + 0x200] $r9
659 // SRC_ADDRESS_LOW = (Ot + Op) & 0xffffffff
660 // CFG_ADDRESS_HIGH |= ((Ot + Op) >> 32) << 16
661 ld b32 $r7 D[$r5 + #ctx_src_address_low]
662 ld b32 $r8 D[$r5 + #ctx_src_address_high]
669 iowr I[$r6 + 0x000] $r7
671 iowr I[$r6 + 0x000] $r8
674 // Setup to handle a linear surface
676 // Nothing to see here.. Sets ADDRESS and PITCH, pretty non-exciting
678 cmd_exec_set_surface_linear:
682 ld b32 $r7 D[$r5 + #ctx_src_address_low]
683 iowr I[$r6 + 0x000] $r7
685 ld b32 $r7 D[$r5 + #ctx_src_address_high]
687 iowr I[$r6 + 0x000] $r7
689 ld b32 $r7 D[$r5 + #ctx_src_pitch]
690 iowr I[$r6 + 0x000] $r7
693 // wait for regs to be available for use
708 // if QUERY_SHORT not set, write out { -, 0, TIME_LO, TIME_HI }
710 bra ne #query_counter
714 ld b32 $r5 D[$r0 + #ctx_query_address_low]
716 iowr I[$r4 + 0x000] $r5
717 iowr I[$r4 + 0x100] $r0
719 iowr I[$r4 + 0x200] $r5
721 ld b32 $r5 D[$r0 + #ctx_query_address_high]
723 iowr I[$r4 + 0x000] $r5
727 iowr I[$r4 + 0x000] $r5
731 iowr I[$r4 + 0x100] $r5
734 iowr I[$r4 + 0x200] $r5
737 iowr I[$r4 + 0x300] $r5
742 iowr I[$r4 + 0x000] $r5
749 ld b32 $r5 D[$r0 + #ctx_query_address_low]
750 iowr I[$r4 + 0x000] $r5
751 iowr I[$r4 + 0x100] $r0
753 iowr I[$r4 + 0x200] $r5
755 ld b32 $r5 D[$r0 + #ctx_query_address_high]
757 iowr I[$r4 + 0x000] $r5
760 iowr I[$r4 + 0x000] $r5
763 iowr I[$r4 + 0x100] $r5
764 ld b32 $r5 D[$r0 + #ctx_query_counter]
766 iowr I[$r4 + 0x000] $r5
771 iowr I[$r4 + 0x000] $r5
774 // Execute a copy operation
778 // $r2: hostirq state
780 // 000002000 QUERY_SHORT
782 // 000000100 DST_LINEAR
783 // 000000010 SRC_LINEAR
785 // $r4: dispatch table entry
789 // $r2: hostirq state
794 // if format requested, call function to calculate it, otherwise
795 // fill in cpp/xcnt for both surfaces as if (cpp == 1)
797 bra e #cmd_exec_no_format
798 call #cmd_exec_set_format
800 bra #cmd_exec_init_src_surface
805 st b32 D[$r0 + #ctx_src_cpp] $r7
806 st b32 D[$r0 + #ctx_dst_cpp] $r7
807 ld b32 $r7 D[$r0 + #ctx_xcnt]
808 iowr I[$r6 + 0x000] $r7
809 iowr I[$r6 + 0x100] $r7
812 cmd_exec_init_src_surface:
817 call #cmd_exec_set_surface_linear
818 bra #cmd_exec_init_dst_surface
820 call #cmd_exec_set_surface_tiled
823 cmd_exec_init_dst_surface:
825 mov $r5 #ctx_dst_address_high - #ctx_src_address_high
828 call #cmd_exec_set_surface_linear
831 call #cmd_exec_set_surface_tiled
837 ld b32 $r6 D[$r0 + #ctx_ycnt]
838 iowr I[$r5 + 0x100] $r6
840 // SRC_TARGET = 1, DST_TARGET = 2
845 // if requested, queue up a QUERY write after the copy has completed
857 // $r2: hostirq state
859 // $r4: dispatch table entry
863 // $r2: hostirq state