blob: fe23711e136f07b4db1762767f6577b3770304b1 [file] [log] [blame]
Soby Mathewb48349e2015-06-29 16:30:12 +01001/*
Soby Mathew4067dc32015-05-05 16:33:16 +01002 * Copyright (c) 2013-2015, ARM Limited and Contributors. All rights reserved.
Soby Mathewb48349e2015-06-29 16:30:12 +01003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __PSCI_H__
32#define __PSCI_H__
33
34#include <bakery_lock.h>
Soby Mathew4067dc32015-05-05 16:33:16 +010035#include <platform_def.h> /* for PLAT_NUM_PWR_DOMAINS */
Soby Mathewb48349e2015-06-29 16:30:12 +010036
37/*******************************************************************************
Soby Mathew4067dc32015-05-05 16:33:16 +010038 * Number of power domains whose state this psci imp. can track
Soby Mathewb48349e2015-06-29 16:30:12 +010039 ******************************************************************************/
Soby Mathew4067dc32015-05-05 16:33:16 +010040#ifdef PLAT_NUM_PWR_DOMAINS
41#define PSCI_NUM_PWR_DOMAINS PLAT_NUM_PWR_DOMAINS
Soby Mathewb48349e2015-06-29 16:30:12 +010042#else
Soby Mathew4067dc32015-05-05 16:33:16 +010043#define PSCI_NUM_PWR_DOMAINS (2 * PLATFORM_CORE_COUNT)
Soby Mathewb48349e2015-06-29 16:30:12 +010044#endif
45
Soby Mathew82dcc032015-04-08 17:42:06 +010046#define PSCI_NUM_NON_CPU_PWR_DOMAINS (PSCI_NUM_PWR_DOMAINS - \
47 PLATFORM_CORE_COUNT)
48
49/* This is the power level corresponding to a CPU */
50#define PSCI_CPU_PWR_LVL 0
51
52/*
53 * The maximum power level supported by PSCI. Since PSCI CPU_SUSPEND
54 * uses the old power_state parameter format which has 2 bits to specify the
55 * power level, this constant is defined to be 3.
56 */
57#define PSCI_MAX_PWR_LVL 3
58
Soby Mathewb48349e2015-06-29 16:30:12 +010059/*******************************************************************************
60 * Defines for runtime services func ids
61 ******************************************************************************/
62#define PSCI_VERSION 0x84000000
63#define PSCI_CPU_SUSPEND_AARCH32 0x84000001
64#define PSCI_CPU_SUSPEND_AARCH64 0xc4000001
65#define PSCI_CPU_OFF 0x84000002
66#define PSCI_CPU_ON_AARCH32 0x84000003
67#define PSCI_CPU_ON_AARCH64 0xc4000003
68#define PSCI_AFFINITY_INFO_AARCH32 0x84000004
69#define PSCI_AFFINITY_INFO_AARCH64 0xc4000004
70#define PSCI_MIG_AARCH32 0x84000005
71#define PSCI_MIG_AARCH64 0xc4000005
72#define PSCI_MIG_INFO_TYPE 0x84000006
73#define PSCI_MIG_INFO_UP_CPU_AARCH32 0x84000007
74#define PSCI_MIG_INFO_UP_CPU_AARCH64 0xc4000007
75#define PSCI_SYSTEM_OFF 0x84000008
76#define PSCI_SYSTEM_RESET 0x84000009
77#define PSCI_FEATURES 0x8400000A
78#define PSCI_SYSTEM_SUSPEND_AARCH32 0x8400000E
79#define PSCI_SYSTEM_SUSPEND_AARCH64 0xc400000E
80
81/* Macro to help build the psci capabilities bitfield */
82#define define_psci_cap(x) (1 << (x & 0x1f))
83
84/*
85 * Number of PSCI calls (above) implemented
86 */
87#define PSCI_NUM_CALLS 18
88
89/*******************************************************************************
90 * PSCI Migrate and friends
91 ******************************************************************************/
92#define PSCI_TOS_UP_MIG_CAP 0
93#define PSCI_TOS_NOT_UP_MIG_CAP 1
94#define PSCI_TOS_NOT_PRESENT_MP 2
95
96/*******************************************************************************
97 * PSCI CPU_SUSPEND 'power_state' parameter specific defines
98 ******************************************************************************/
99#define PSTATE_ID_SHIFT 0
Soby Mathew8ee24982015-04-07 12:16:56 +0100100
101#if PSCI_EXTENDED_STATE_ID
102#define PSTATE_VALID_MASK 0xB0000000
103#define PSTATE_TYPE_SHIFT 30
104#define PSTATE_ID_MASK 0xfffffff
105#else
106#define PSTATE_VALID_MASK 0xFCFE0000
Soby Mathewb48349e2015-06-29 16:30:12 +0100107#define PSTATE_TYPE_SHIFT 16
Soby Mathew4067dc32015-05-05 16:33:16 +0100108#define PSTATE_PWR_LVL_SHIFT 24
Soby Mathewb48349e2015-06-29 16:30:12 +0100109#define PSTATE_ID_MASK 0xffff
Soby Mathew4067dc32015-05-05 16:33:16 +0100110#define PSTATE_PWR_LVL_MASK 0x3
Soby Mathewb48349e2015-06-29 16:30:12 +0100111
Soby Mathew8ee24982015-04-07 12:16:56 +0100112#define psci_get_pstate_pwrlvl(pstate) (((pstate) >> PSTATE_PWR_LVL_SHIFT) & \
Soby Mathew4067dc32015-05-05 16:33:16 +0100113 PSTATE_PWR_LVL_MASK)
114#define psci_make_powerstate(state_id, type, pwrlvl) \
Soby Mathewb48349e2015-06-29 16:30:12 +0100115 (((state_id) & PSTATE_ID_MASK) << PSTATE_ID_SHIFT) |\
116 (((type) & PSTATE_TYPE_MASK) << PSTATE_TYPE_SHIFT) |\
Soby Mathew4067dc32015-05-05 16:33:16 +0100117 (((pwrlvl) & PSTATE_PWR_LVL_MASK) << PSTATE_PWR_LVL_SHIFT)
Soby Mathew8ee24982015-04-07 12:16:56 +0100118#endif /* __PSCI_EXTENDED_STATE_ID__ */
119
120#define PSTATE_TYPE_STANDBY 0x0
121#define PSTATE_TYPE_POWERDOWN 0x1
122#define PSTATE_TYPE_MASK 0x1
123
124#define psci_get_pstate_id(pstate) (((pstate) >> PSTATE_ID_SHIFT) & \
125 PSTATE_ID_MASK)
126#define psci_get_pstate_type(pstate) (((pstate) >> PSTATE_TYPE_SHIFT) & \
127 PSTATE_TYPE_MASK)
128#define psci_check_power_state(pstate) ((pstate) & PSTATE_VALID_MASK)
Soby Mathewb48349e2015-06-29 16:30:12 +0100129
130/*******************************************************************************
131 * PSCI CPU_FEATURES feature flag specific defines
132 ******************************************************************************/
133/* Features flags for CPU SUSPEND power state parameter format. Bits [1:1] */
134#define FF_PSTATE_SHIFT 1
135#define FF_PSTATE_ORIG 0
136#define FF_PSTATE_EXTENDED 1
Soby Mathew8ee24982015-04-07 12:16:56 +0100137#if PSCI_EXTENDED_STATE_ID
138#define FF_PSTATE FF_PSTATE_EXTENDED
139#else
140#define FF_PSTATE FF_PSTATE_ORIG
141#endif
Soby Mathewb48349e2015-06-29 16:30:12 +0100142
143/* Features flags for CPU SUSPEND OS Initiated mode support. Bits [0:0] */
144#define FF_MODE_SUPPORT_SHIFT 0
145#define FF_SUPPORTS_OS_INIT_MODE 1
146
147/*******************************************************************************
148 * PSCI version
149 ******************************************************************************/
150#define PSCI_MAJOR_VER (1 << 16)
151#define PSCI_MINOR_VER 0x0
152
153/*******************************************************************************
154 * PSCI error codes
155 ******************************************************************************/
156#define PSCI_E_SUCCESS 0
157#define PSCI_E_NOT_SUPPORTED -1
158#define PSCI_E_INVALID_PARAMS -2
159#define PSCI_E_DENIED -3
160#define PSCI_E_ALREADY_ON -4
161#define PSCI_E_ON_PENDING -5
162#define PSCI_E_INTERN_FAIL -6
163#define PSCI_E_NOT_PRESENT -7
164#define PSCI_E_DISABLED -8
165
Soby Mathew82dcc032015-04-08 17:42:06 +0100166#define PSCI_INVALID_MPIDR ~(0ULL)
Soby Mathewb48349e2015-06-29 16:30:12 +0100167
Soby Mathewb48349e2015-06-29 16:30:12 +0100168#ifndef __ASSEMBLY__
169
170#include <stdint.h>
Soby Mathew8ee24982015-04-07 12:16:56 +0100171#include <types.h>
172
173/*
174 * These are the states reported by the PSCI_AFFINITY_INFO API for the specified
175 * CPU. The definitions of these states can be found in Section 5.7.1 in the
176 * PSCI specification (ARM DEN 0022C).
177 */
178typedef enum aff_info_state {
179 AFF_STATE_ON = 0,
180 AFF_STATE_OFF = 1,
181 AFF_STATE_ON_PENDING = 2
182} aff_info_state_t;
183
184/*
185 * Macro to represent invalid affinity level within PSCI.
186 */
187#define PSCI_INVALID_DATA -1
188
189/*
190 * Type for representing the local power state at a particular level.
191 */
192typedef uint8_t plat_local_state_t;
193
194/* The local state macro used to represent RUN state. */
195#define PSCI_LOCAL_STATE_RUN 0
196
197/*
198 * Macro to test whether the plat_local_state is RUN state
199 */
200#define is_local_state_run(plat_local_state) \
201 ((plat_local_state) == PSCI_LOCAL_STATE_RUN)
202
203/*
204 * Macro to test whether the plat_local_state is RETENTION state
205 */
206#define is_local_state_retn(plat_local_state) \
207 (((plat_local_state) > PSCI_LOCAL_STATE_RUN) && \
208 ((plat_local_state) <= PLAT_MAX_RET_STATE))
209
210/*
211 * Macro to test whether the plat_local_state is OFF state
212 */
213#define is_local_state_off(plat_local_state) \
214 (((plat_local_state) > PLAT_MAX_RET_STATE) && \
215 ((plat_local_state) <= PLAT_MAX_OFF_STATE))
216
217/*****************************************************************************
218 * This data structure defines the representation of the power state parameter
219 * for its exchange between the generic PSCI code and the platform port. For
220 * example, it is used by the platform port to specify the requested power
221 * states during a power management operation. It is used by the generic code
222 * to inform the platform about the target power states that each level
223 * should enter.
224 ****************************************************************************/
225typedef struct psci_power_state {
226 /*
227 * The pwr_domain_state[] stores the local power state at each level
228 * for the CPU.
229 */
230 plat_local_state_t pwr_domain_state[PLAT_MAX_PWR_LVL + 1];
231} psci_power_state_t;
Soby Mathewb48349e2015-06-29 16:30:12 +0100232
233/*******************************************************************************
234 * Structure used to store per-cpu information relevant to the PSCI service.
235 * It is populated in the per-cpu data array. In return we get a guarantee that
236 * this information will not reside on a cache line shared with another cpu.
237 ******************************************************************************/
238typedef struct psci_cpu_data {
Soby Mathew8ee24982015-04-07 12:16:56 +0100239 /* State as seen by PSCI Affinity Info API */
240 aff_info_state_t aff_info_state;
241 /*
242 * Highest power level which takes part in a power management
243 * operation.
244 */
245 int8_t target_pwrlvl;
246 /* The local power state of this CPU */
247 plat_local_state_t local_state;
Soby Mathewb48349e2015-06-29 16:30:12 +0100248#if !USE_COHERENT_MEM
Soby Mathew82dcc032015-04-08 17:42:06 +0100249 bakery_info_t pcpu_bakery_info[PSCI_NUM_NON_CPU_PWR_DOMAINS];
Soby Mathewb48349e2015-06-29 16:30:12 +0100250#endif
251} psci_cpu_data_t;
252
253/*******************************************************************************
254 * Structure populated by platform specific code to export routines which
255 * perform common low level pm functions
256 ******************************************************************************/
Soby Mathew8ee24982015-04-07 12:16:56 +0100257typedef struct plat_psci_ops {
258 void (*cpu_standby)(plat_local_state_t cpu_state);
Sandrine Bailleuxeb975f52015-06-11 10:46:48 +0100259 int (*pwr_domain_on)(u_register_t mpidr);
Soby Mathew8ee24982015-04-07 12:16:56 +0100260 void (*pwr_domain_off)(const psci_power_state_t *target_state);
Sandrine Bailleuxeb975f52015-06-11 10:46:48 +0100261 void (*pwr_domain_suspend)(const psci_power_state_t *target_state);
Soby Mathew8ee24982015-04-07 12:16:56 +0100262 void (*pwr_domain_on_finish)(const psci_power_state_t *target_state);
Sandrine Bailleuxeb975f52015-06-11 10:46:48 +0100263 void (*pwr_domain_suspend_finish)(
264 const psci_power_state_t *target_state);
Soby Mathewb48349e2015-06-29 16:30:12 +0100265 void (*system_off)(void) __dead2;
266 void (*system_reset)(void) __dead2;
Soby Mathew8ee24982015-04-07 12:16:56 +0100267 int (*validate_power_state)(unsigned int power_state,
268 psci_power_state_t *req_state);
Soby Mathewb48349e2015-06-29 16:30:12 +0100269 int (*validate_ns_entrypoint)(unsigned long ns_entrypoint);
Soby Mathew8ee24982015-04-07 12:16:56 +0100270 void (*get_sys_suspend_power_state)(
271 psci_power_state_t *req_state);
272} plat_psci_ops_t;
Soby Mathewb48349e2015-06-29 16:30:12 +0100273
274/*******************************************************************************
275 * Optional structure populated by the Secure Payload Dispatcher to be given a
276 * chance to perform any bookkeeping before PSCI executes a power mgmt.
277 * operation. It also allows PSCI to determine certain properties of the SP e.g.
278 * migrate capability etc.
279 ******************************************************************************/
280typedef struct spd_pm_ops {
281 void (*svc_on)(uint64_t target_cpu);
282 int32_t (*svc_off)(uint64_t __unused);
283 void (*svc_suspend)(uint64_t __unused);
284 void (*svc_on_finish)(uint64_t __unused);
285 void (*svc_suspend_finish)(uint64_t suspend_level);
286 int32_t (*svc_migrate)(uint64_t from_cpu, uint64_t to_cpu);
287 int32_t (*svc_migrate_info)(uint64_t *resident_cpu);
288 void (*svc_system_off)(void);
289 void (*svc_system_reset)(void);
290} spd_pm_ops_t;
291
292/*******************************************************************************
293 * Function & Data prototypes
294 ******************************************************************************/
295unsigned int psci_version(void);
296int psci_affinity_info(unsigned long, unsigned int);
297int psci_migrate(unsigned long);
298int psci_migrate_info_type(void);
299long psci_migrate_info_up_cpu(void);
300int psci_cpu_on(unsigned long,
301 unsigned long,
302 unsigned long);
303void __dead2 psci_power_down_wfi(void);
Sandrine Bailleuxeb975f52015-06-11 10:46:48 +0100304void psci_entrypoint(void);
Soby Mathewb48349e2015-06-29 16:30:12 +0100305void psci_register_spd_pm_hook(const spd_pm_ops_t *);
Soby Mathewb48349e2015-06-29 16:30:12 +0100306
307uint64_t psci_smc_handler(uint32_t smc_fid,
308 uint64_t x1,
309 uint64_t x2,
310 uint64_t x3,
311 uint64_t x4,
312 void *cookie,
313 void *handle,
314 uint64_t flags);
315
316/* PSCI setup function */
317int32_t psci_setup(void);
318
319
320#endif /*__ASSEMBLY__*/
321
322
323#endif /* __PSCI_H__ */