xref: /netbsd-src/sys/arch/arm/arm/psci.h (revision 9e015301d478f2ba8de08d86ce37766bb4a4949b)
1 /* $NetBSD: psci.h,v 1.5 2024/12/30 19:09:49 jmcneill Exp $ */
2 
3 /*-
4  * Copyright (c) 2017 Jared McNeill <jmcneill@invisible.ca>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _ARM_PSCI_H
30 #define _ARM_PSCI_H
31 
32 /*
33  * List of supported PSCI functions.
34  */
35 enum psci_function {
36 	PSCI_FUNC_VERSION,
37 	PSCI_FUNC_CPU_SUSPEND,
38 	PSCI_FUNC_CPU_ON,
39 	PSCI_FUNC_SYSTEM_OFF,
40 	PSCI_FUNC_SYSTEM_RESET,
41 	PSCI_FUNC_FEATURES,
42 	PSCI_FUNC_MAX
43 };
44 
45 /*
46  * Possible PSCI conduits.
47  */
48 enum psci_conduit {
49 	PSCI_CONDUIT_NONE,
50 	PSCI_CONDUIT_SMC,
51 	PSCI_CONDUIT_HVC,
52 };
53 
54 /*
55  * PSCI error codes
56  */
57 #define	PSCI_SUCCESS		0
58 #define	PSCI_NOT_SUPPORTED	-1
59 #define	PSCI_INVALID_PARAMETERS	-2
60 #define	PSCI_DENIED		-3
61 #define	PSCI_ALREADY_ON		-4
62 #define	PSCI_ON_PENDING		-5
63 #define	PSCI_INTERNAL_FAILURE	-6
64 #define	PSCI_NOT_PRESENT	-7
65 #define	PSCI_DISABLED		-8
66 #define	PSCI_INVALID_ADDRESS	-9
67 
68 /*
69  * PSCI call method interface.
70  */
71 typedef int (*psci_fn)(register_t, register_t, register_t, register_t);
72 
73 /*
74  * Set the PSCI call method. Pass either psci_call_smc or psci_call_hvc.
75  */
76 void	psci_init(psci_fn);
77 
78 /*
79  * Return true if PSCI is available (psci_init has been called).
80  */
81 bool	psci_available(void);
82 
83 /*
84  * Return the PSCI conduit type.
85  */
86 enum psci_conduit psci_conduit(void);
87 
88 /*
89  * PSCI call methods, implemented in psci.S
90  */
91 int	psci_call_smc(register_t, register_t, register_t, register_t);
92 int	psci_call_hvc(register_t, register_t, register_t, register_t);
93 
94 /*
95  * Clear PSCI function table. The default table includes function IDs for
96  * PSCI 0.2+. A PSCI 0.1 implementation will use its own function ID mappings.
97  */
98 void	psci_clearfunc(void);
99 
100 /*
101  * Set PSCI function ID for a given PSCI function.
102  */
103 void	psci_setfunc(enum psci_function, uint32_t);
104 
105 /*
106  * Return the version of PSCI implemented.
107  */
108 uint32_t	psci_version(void);
109 #define	PSCI_VERSION_MAJOR	__BITS(31,16)
110 #define	PSCI_VERSION_MINOR	__BITS(15,0)
111 
112 /*
113  * Power up a core. Args: target_cpu, entry_point_address, context_id
114  */
115 int	psci_cpu_on(register_t, register_t, register_t);
116 
117 /*
118  * Suspend a core. Args: power_state
119  */
120 int	psci_cpu_suspend(uint32_t);
121 
122 /*
123  * Shut down the system.
124  */
125 void	psci_system_off(void);
126 
127 /*
128  * Reset the system.
129  */
130 void	psci_system_reset(void);
131 
132 /*
133  * Discover supported features.
134  */
135 int	psci_features(uint32_t);
136 
137 /*
138  * Generic PSCI call.
139  */
140 int	psci_call(register_t, register_t, register_t, register_t);
141 #endif /* _ARM_PSCI_H */
142