Merge tag 'squashfs-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squas...
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / core / subdev / pwr / fuc / memx.fuc
1 /*
2  * Copyright 2013 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: Ben Skeggs
23  */
24
25 #ifdef INCLUDE_PROC
26 process(PROC_MEMX, #memx_init, #memx_recv)
27 #endif
28
29 /******************************************************************************
30  * MEMX data segment
31  *****************************************************************************/
32 #ifdef INCLUDE_DATA
33 .equ #memx_opcode 0
34 .equ #memx_header 2
35 .equ #memx_length 4
36 .equ #memx_func   8
37
38 #define handler(cmd,hdr,len,func) /*
39 */      .b16 MEMX_##cmd /*
40 */      .b16 hdr /*
41 */      .b16 len /*
42 */      .b16 0 /*
43 */      .b32 func
44
45 memx_func_head:
46 handler(ENTER , 0x0001, 0x0000, #memx_func_enter)
47 memx_func_next:
48 handler(LEAVE , 0x0000, 0x0000, #memx_func_leave)
49 handler(WR32  , 0x0000, 0x0002, #memx_func_wr32)
50 handler(WAIT  , 0x0004, 0x0000, #memx_func_wait)
51 handler(DELAY , 0x0001, 0x0000, #memx_func_delay)
52 memx_func_tail:
53
54 .equ #memx_func_size #memx_func_next - #memx_func_head
55 .equ #memx_func_num (#memx_func_tail - #memx_func_head) / #memx_func_size
56
57 memx_data_head:
58 .skip 0x0800
59 memx_data_tail:
60 #endif
61
62 /******************************************************************************
63  * MEMX code segment
64  *****************************************************************************/
65 #ifdef INCLUDE_CODE
66 // description
67 //
68 // $r15 - current (memx)
69 // $r4  - packet length
70 //      +00: bitmask of heads to wait for vblank on
71 // $r3  - opcode desciption
72 // $r0  - zero
73 memx_func_enter:
74         mov $r6 NV_PPWR_OUTPUT_SET_FB_PAUSE
75         nv_iowr(NV_PPWR_OUTPUT_SET, $r6)
76         memx_func_enter_wait:
77                 nv_iord($r6, NV_PPWR_OUTPUT)
78                 and $r6 NV_PPWR_OUTPUT_FB_PAUSE
79                 bra z #memx_func_enter_wait
80         //XXX: TODO
81         ld b32 $r6 D[$r1 + 0x00]
82         add b32 $r1 0x04
83         ret
84
85 // description
86 //
87 // $r15 - current (memx)
88 // $r4  - packet length
89 // $r3  - opcode desciption
90 // $r0  - zero
91 memx_func_leave:
92         mov $r6 NV_PPWR_OUTPUT_CLR_FB_PAUSE
93         nv_iowr(NV_PPWR_OUTPUT_CLR, $r6)
94         memx_func_leave_wait:
95                 nv_iord($r6, NV_PPWR_OUTPUT)
96                 and $r6 NV_PPWR_OUTPUT_FB_PAUSE
97                 bra nz #memx_func_leave_wait
98         ret
99
100 // description
101 //
102 // $r15 - current (memx)
103 // $r4  - packet length
104 //      +00*n: addr
105 //      +04*n: data
106 // $r3  - opcode desciption
107 // $r0  - zero
108 memx_func_wr32:
109         ld b32 $r6 D[$r1 + 0x00]
110         ld b32 $r5 D[$r1 + 0x04]
111         add b32 $r1 0x08
112         nv_wr32($r6, $r5)
113         sub b32 $r4 0x02
114         bra nz #memx_func_wr32
115         ret
116
117 // description
118 //
119 // $r15 - current (memx)
120 // $r4  - packet length
121 //      +00: addr
122 //      +04: mask
123 //      +08: data
124 //      +0c: timeout (ns)
125 // $r3  - opcode desciption
126 // $r0  - zero
127 memx_func_wait:
128         nv_iord($r8, NV_PPWR_TIMER_LOW)
129         ld b32 $r14 D[$r1 + 0x00]
130         ld b32 $r13 D[$r1 + 0x04]
131         ld b32 $r12 D[$r1 + 0x08]
132         ld b32 $r11 D[$r1 + 0x0c]
133         add b32 $r1 0x10
134         call(wait)
135         ret
136
137 // description
138 //
139 // $r15 - current (memx)
140 // $r4  - packet length
141 //      +00: time (ns)
142 // $r3  - opcode desciption
143 // $r0  - zero
144 memx_func_delay:
145         ld b32 $r14 D[$r1 + 0x00]
146         add b32 $r1 0x04
147         call(nsec)
148         ret
149
150 // description
151 //
152 // $r15 - current (memx)
153 // $r14 - sender process name
154 // $r13 - message (exec)
155 // $r12 - head of script
156 // $r11 - tail of script
157 // $r0  - zero
158 memx_exec:
159         push $r14
160         push $r13
161         mov b32 $r1 $r12
162         mov b32 $r2 $r11
163         memx_exec_next:
164                 // fetch the packet header, and locate opcode info
165                 ld b32 $r3 D[$r1]
166                 add b32 $r1 4
167                 shr b32 $r4 $r3 16
168                 mulu $r3 #memx_func_size
169
170                 // execute the opcode handler
171                 ld b32 $r5 D[$r3 + #memx_func_head + #memx_func]
172                 call $r5
173
174                 // keep going, if we haven't reached the end
175                 cmp b32 $r1 $r2
176                 bra l #memx_exec_next
177
178         // send completion reply
179         pop $r13
180         pop $r14
181         call(send)
182         ret
183
184 // description
185 //
186 // $r15 - current (memx)
187 // $r14 - sender process name
188 // $r13 - message
189 // $r12 - data0
190 // $r11 - data1
191 // $r0  - zero
192 memx_info:
193         mov $r12 #memx_data_head
194         mov $r11 #memx_data_tail - #memx_data_head
195         call(send)
196         ret
197
198 // description
199 //
200 // $r15 - current (memx)
201 // $r14 - sender process name
202 // $r13 - message
203 // $r12 - data0
204 // $r11 - data1
205 // $r0  - zero
206 memx_recv:
207         cmp b32 $r13 MEMX_MSG_EXEC
208         bra e #memx_exec
209         cmp b32 $r13 MEMX_MSG_INFO
210         bra e #memx_info
211         ret
212
213 // description
214 //
215 // $r15 - current (memx)
216 // $r0  - zero
217 memx_init:
218         ret
219 #endif