2 * Copyright 2013 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 /******************************************************************************
27 *****************************************************************************/
30 process(PROC_KERN, 0, 0)
40 /******************************************************************************
42 *****************************************************************************/
50 // $r13 - data (return)
53 nv_iowr(NV_PPWR_MMIO_ADDR, $r14)
54 imm32($r13, NV_PPWR_MMIO_CTRL_OP_RD | NV_PPWR_MMIO_CTRL_TRIGGER)
55 nv_iowr(NV_PPWR_MMIO_CTRL, $r13)
57 nv_iord($r13, NV_PPWR_MMIO_CTRL)
58 and $r13 NV_PPWR_MMIO_CTRL_STATUS
60 nv_iord($r13, NV_PPWR_MMIO_DATA)
70 nv_iowr(NV_PPWR_MMIO_ADDR, $r14)
71 nv_iowr(NV_PPWR_MMIO_DATA, $r13)
72 imm32($r13, NV_PPWR_MMIO_CTRL_OP_WR | NV_PPWR_MMIO_CTRL_MASK_B32_0 | NV_PPWR_MMIO_CTRL_TRIGGER)
74 #ifdef NVKM_FALCON_MMIO_TRAP
76 mov $r13 NV_PPWR_INTR_TRIGGER_USER1
77 nv_iowr(NV_PPWR_INTR_TRIGGER, $r13)
79 nv_iord($r13, NV_PPWR_INTR)
80 and $r13 NV_PPWR_INTR_USER1
85 nv_iowr(NV_PPWR_MMIO_CTRL, $r13)
87 nv_iord($r13, NV_PPWR_MMIO_CTRL)
88 and $r13 NV_PPWR_MMIO_CTRL_STATUS
92 // busy-wait for a period of time
100 nv_iord($r8, NV_PPWR_TIMER_LOW)
102 nv_iord($r9, NV_PPWR_TIMER_LOW)
110 // busy-wait for a period of time
116 // $r11 - timeout (ns)
121 nv_iord($r8, NV_PPWR_TIMER_LOW)
127 nv_iord($r9, NV_PPWR_TIMER_LOW)
136 // $r15 - current (kern)
138 // $r8 - NV_PPWR_INTR
140 // read process' timer status, skip if not enabled
141 ld b32 $r9 D[$r14 + #proc_time]
143 bra z #intr_watchdog_next_proc
145 // subtract last timer's value from process' timer,
146 // if it's <= 0 then the timer has expired
147 ld b32 $r10 D[$r0 + #time_prev]
149 bra g #intr_watchdog_next_time
153 bra #intr_watchdog_next_proc
155 // otherwise, update the next timer's value if this
156 // process' timer is the soonest
157 intr_watchdog_next_time:
158 // ... or if there's no next timer yet
159 ld b32 $r10 D[$r0 + #time_next]
161 bra z #intr_watchdog_next_time_set
164 bra g #intr_watchdog_next_proc
165 intr_watchdog_next_time_set:
166 st b32 D[$r0 + #time_next] $r9
168 // update process' timer status, and advance
169 intr_watchdog_next_proc:
170 st b32 D[$r14 + #proc_time] $r9
171 add b32 $r14 #proc_size
172 cmp b32 $r14 #proc_list_tail
173 bra ne #intr_watchdog
191 nv_iord($r8, NV_PPWR_DSCRATCH(0))
193 nv_iowr(NV_PPWR_DSCRATCH(0), $r8)
195 nv_iord($r8, NV_PPWR_INTR)
196 and $r9 $r8 NV_PPWR_INTR_WATCHDOG
197 bra z #intr_skip_watchdog
198 st b32 D[$r0 + #time_next] $r0
199 mov $r14 #proc_list_head
201 ld b32 $r9 D[$r0 + #time_next]
203 bra z #intr_skip_watchdog
204 nv_iowr(NV_PPWR_WATCHDOG_TIME, $r9)
205 st b32 D[$r0 + #time_prev] $r9
208 and $r9 $r8 NV_PPWR_INTR_SUBINTR
209 bra z #intr_skip_subintr
210 nv_iord($r9, NV_PPWR_SUBINTR)
211 and $r10 $r9 NV_PPWR_SUBINTR_FIFO
212 bra z #intr_subintr_skip_fifo
213 nv_iord($r12, NV_PPWR_FIFO_INTR)
215 imm32($r14, PROC_HOST)
219 nv_iowr(NV_PPWR_FIFO_INTR, $r12)
220 intr_subintr_skip_fifo:
221 nv_iowr(NV_PPWR_SUBINTR, $r9)
224 mov $r9 (NV_PPWR_INTR_USER0 | NV_PPWR_INTR_USER1 | NV_PPWR_INTR_PAUSE)
227 nv_iowr(NV_PPWR_INTR_ACK, $r8)
243 // calculate the number of ticks in the specified nanoseconds delay
247 // $r14 - ticks (return)
253 /* try not losing precision (multiply then divide) */
254 imm32($r13, HW_TICKS_PER_US)
257 /* use an immeditate, it's ok because HW_TICKS_PER_US < 16 bits */
260 /* check if there wasn't any overflow */
262 bra e #ticks_from_ns_quit
264 /* let's divide then multiply, too bad for the precision! */
266 imm32($r13, HW_TICKS_PER_US)
269 /* this cannot overflow as long as HW_TICKS_PER_US < 1000 */
277 // calculate the number of ticks in the specified microsecond delay
281 // $r14 - ticks (return)
287 /* simply multiply $us by HW_TICKS_PER_US */
288 imm32($r13, HW_TICKS_PER_US)
292 /* check if there wasn't any overflow */
294 bra e #ticks_from_us_quit
304 // calculate the number of ticks in the specified microsecond delay
308 // $r14 - us (return)
311 /* simply divide $ticks by HW_TICKS_PER_US */
312 imm32($r13, HW_TICKS_PER_US)
317 // request the current process be sent a message after a timeout expires
320 // $r14 - ticks (make sure it is < 2^31 to avoid any possible overflow)
326 // interrupts off to prevent racing with timer isr
329 // if current process already has a timer set, bail
330 ld b32 $r8 D[$r15 + #proc_time]
334 // halt watchdog timer temporarily
336 nv_iowr(NV_PPWR_WATCHDOG_ENABLE, $r8)
338 // find out how much time elapsed since the last update
339 // of the watchdog and add this time to the wanted ticks
340 nv_iord($r8, NV_PPWR_WATCHDOG_TIME)
341 ld b32 $r9 D[$r0 + #time_prev]
344 st b32 D[$r15 + #proc_time] $r14
346 // check for a pending interrupt. if there's one already
347 // pending, we can just bail since the timer isr will
348 // queue the next soonest right after it's done
349 nv_iord($r8, NV_PPWR_INTR)
350 and $r8 NV_PPWR_INTR_WATCHDOG
353 // update the watchdog if this timer should expire first,
354 // or if there's no timeout already set
355 nv_iord($r8, NV_PPWR_WATCHDOG_TIME)
361 nv_iowr(NV_PPWR_WATCHDOG_TIME, $r14)
362 st b32 D[$r0 + #time_prev] $r14
364 // re-enable the watchdog timer
367 nv_iowr(NV_PPWR_WATCHDOG_ENABLE, $r8)
369 // interrupts back on
377 // send message to another process
382 // $r12 - message data 0
383 // $r11 - message data 1
388 // check for space in queue
389 ld b32 $r8 D[$r14 + #proc_qget]
390 ld b32 $r9 D[$r14 + #proc_qput]
396 and $r8 $r9 #proc_qmaskp
397 shl b32 $r8 $r8 #proc_qlen
398 add b32 $r8 #proc_queue
401 ld b32 $r10 D[$r15 + #proc_id]
402 st b32 D[$r8 + #msg_process] $r10
403 st b32 D[$r8 + #msg_message] $r13
404 st b32 D[$r8 + #msg_data0] $r12
405 st b32 D[$r8 + #msg_data1] $r11
410 st b32 D[$r14 + #proc_qput] $r9
417 // lookup process structure by its name
420 // $r14 - process name
427 mov $r8 #proc_list_head
430 ld b32 $r10 D[$r8 + #proc_id]
433 add b32 $r8 #proc_size
434 cmp b32 $r8 #proc_list_tail
442 // send message to another process
447 // $r12 - message data 0
448 // $r11 - message data 1
455 // process single message for a given process
464 ld b32 $r8 D[$r14 + #proc_qget]
465 ld b32 $r9 D[$r14 + #proc_qput]
470 and $r9 $r8 #proc_qmaskp
473 st b32 D[$r14 + #proc_qget] $r8
474 ld b32 $r10 D[$r14 + #proc_recv]
481 shl b32 $r9 $r9 #proc_qlen
483 add b32 $r14 #proc_queue
484 ld b32 $r11 D[$r14 + #msg_data1]
485 ld b32 $r12 D[$r14 + #msg_data0]
486 ld b32 $r13 D[$r14 + #msg_message]
487 ld b32 $r14 D[$r14 + #msg_process]
502 nv_iord($r1, NV_PPWR_CAPS)
507 #ifdef NVKM_FALCON_MMIO_UAS
508 // somehow allows the magic "access mmio via D[]" stuff that's
509 // used by the nv_rd32/nv_wr32 macros to work
510 imm32($r1, 0x10 | NV_PPWR_UAS_CONFIG_ENABLE)
511 nv_iowrs(NV_PPWR_UAS_CONFIG, $r1)
514 // route all interrupts except user0/1 and pause to fuc
516 nv_iowr(NV_PPWR_INTR_ROUTE, $r1)
518 // enable watchdog and subintr intrs
519 mov $r1 NV_PPWR_INTR_EN_CLR_MASK
520 nv_iowr(NV_PPWR_INTR_EN_CLR, $r1)
521 mov $r1 NV_PPWR_INTR_EN_SET_WATCHDOG
522 or $r1 NV_PPWR_INTR_EN_SET_SUBINTR
523 nv_iowr(NV_PPWR_INTR_EN_SET, $r1)
525 // enable interrupts globally
531 // enable watchdog timer
533 nv_iowr(NV_PPWR_WATCHDOG_ENABLE, $r1)
535 // bootstrap processes, idle process will be last, and not return
536 mov $r15 #proc_list_head
538 ld b32 $r1 D[$r15 + #proc_init]
542 add b32 $r15 #proc_size