xref: /linux/drivers/gpu/drm/nouveau/nvkm/subdev/pmu/fuc/idle.fuc (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
1*ebb58dc2SBen Skeggs/*
2*ebb58dc2SBen Skeggs * Copyright 2013 Red Hat Inc.
3*ebb58dc2SBen Skeggs *
4*ebb58dc2SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5*ebb58dc2SBen Skeggs * copy of this software and associated documentation files (the "Software"),
6*ebb58dc2SBen Skeggs * to deal in the Software without restriction, including without limitation
7*ebb58dc2SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*ebb58dc2SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9*ebb58dc2SBen Skeggs * Software is furnished to do so, subject to the following conditions:
10*ebb58dc2SBen Skeggs *
11*ebb58dc2SBen Skeggs * The above copyright notice and this permission notice shall be included in
12*ebb58dc2SBen Skeggs * all copies or substantial portions of the Software.
13*ebb58dc2SBen Skeggs *
14*ebb58dc2SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*ebb58dc2SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*ebb58dc2SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*ebb58dc2SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*ebb58dc2SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*ebb58dc2SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*ebb58dc2SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21*ebb58dc2SBen Skeggs *
22*ebb58dc2SBen Skeggs * Authors: Ben Skeggs
23*ebb58dc2SBen Skeggs */
24*ebb58dc2SBen Skeggs
25*ebb58dc2SBen Skeggs#ifdef INCLUDE_PROC
26*ebb58dc2SBen Skeggsprocess(PROC_IDLE, #idle, #idle_recv)
27*ebb58dc2SBen Skeggs#endif
28*ebb58dc2SBen Skeggs
29*ebb58dc2SBen Skeggs/******************************************************************************
30*ebb58dc2SBen Skeggs * IDLE data segment
31*ebb58dc2SBen Skeggs *****************************************************************************/
32*ebb58dc2SBen Skeggs#ifdef INCLUDE_DATA
33*ebb58dc2SBen Skeggs#endif
34*ebb58dc2SBen Skeggs
35*ebb58dc2SBen Skeggs/******************************************************************************
36*ebb58dc2SBen Skeggs * IDLE code segment
37*ebb58dc2SBen Skeggs *****************************************************************************/
38*ebb58dc2SBen Skeggs#ifdef INCLUDE_CODE
39*ebb58dc2SBen Skeggs// description
40*ebb58dc2SBen Skeggs//
41*ebb58dc2SBen Skeggs// $r15 - current (idle)
42*ebb58dc2SBen Skeggs// $r14 - message
43*ebb58dc2SBen Skeggs// $r0  - zero
44*ebb58dc2SBen Skeggsidle_recv:
45*ebb58dc2SBen Skeggs	ret
46*ebb58dc2SBen Skeggs
47*ebb58dc2SBen Skeggs// description
48*ebb58dc2SBen Skeggs//
49*ebb58dc2SBen Skeggs// $r15 - current (idle)
50*ebb58dc2SBen Skeggs// $r0  - zero
51*ebb58dc2SBen Skeggsidle:
52*ebb58dc2SBen Skeggs	// set our "no interrupt has occurred during our execution" flag
53*ebb58dc2SBen Skeggs	bset $flags $p0
54*ebb58dc2SBen Skeggs
55*ebb58dc2SBen Skeggs	// count IDLE invocations for debugging purposes
56*ebb58dc2SBen Skeggs	nv_iord($r1, NV_PPWR_DSCRATCH(1))
57*ebb58dc2SBen Skeggs	add b32 $r1 1
58*ebb58dc2SBen Skeggs	nv_iowr(NV_PPWR_DSCRATCH(1), $r1)
59*ebb58dc2SBen Skeggs
60*ebb58dc2SBen Skeggs	// keep looping while there's pending messages for any process
61*ebb58dc2SBen Skeggs	idle_loop:
62*ebb58dc2SBen Skeggs	mov $r1 #proc_list_head
63*ebb58dc2SBen Skeggs	bclr $flags $p2
64*ebb58dc2SBen Skeggs	idle_proc:
65*ebb58dc2SBen Skeggs		// process the process' messages until there's none left
66*ebb58dc2SBen Skeggs		idle_proc_exec:
67*ebb58dc2SBen Skeggs			push $r1
68*ebb58dc2SBen Skeggs			mov b32 $r14 $r1
69*ebb58dc2SBen Skeggs			call(recv)
70*ebb58dc2SBen Skeggs			pop $r1
71*ebb58dc2SBen Skeggs			bra not $p1 #idle_proc_next
72*ebb58dc2SBen Skeggs			bset $flags $p2
73*ebb58dc2SBen Skeggs			bra #idle_proc_exec
74*ebb58dc2SBen Skeggs		// next process!
75*ebb58dc2SBen Skeggs		idle_proc_next:
76*ebb58dc2SBen Skeggs		add b32 $r1 #proc_size
77*ebb58dc2SBen Skeggs		cmp b32 $r1 $r15
78*ebb58dc2SBen Skeggs		bra ne #idle_proc
79*ebb58dc2SBen Skeggs	bra $p2 #idle_loop
80*ebb58dc2SBen Skeggs
81*ebb58dc2SBen Skeggs	// sleep if no interrupts have occurred
82*ebb58dc2SBen Skeggs	sleep $p0
83*ebb58dc2SBen Skeggs	bra #idle
84*ebb58dc2SBen Skeggs#endif
85