blob: 79909a862996a60230d9402f4dfff764d85b6311 [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_PRIVATE_H__
32#define __PSCI_PRIVATE_H__
33
34#include <arch.h>
35#include <bakery_lock.h>
36#include <bl_common.h>
37#include <psci.h>
38
39/*
40 * The following helper macros abstract the interface to the Bakery
41 * Lock API.
42 */
43#if USE_COHERENT_MEM
Soby Mathew4067dc32015-05-05 16:33:16 +010044#define psci_lock_init(pwr_map, idx) bakery_lock_init(&(pwr_map)[(idx)].lock)
Soby Mathewb48349e2015-06-29 16:30:12 +010045#define psci_lock_get(node) bakery_lock_get(&((node)->lock))
46#define psci_lock_release(node) bakery_lock_release(&((node)->lock))
47#else
Soby Mathew4067dc32015-05-05 16:33:16 +010048#define psci_lock_init(pwr_map, idx) \
49 ((pwr_map)[(idx)].pwr_domain_index = (idx))
50#define psci_lock_get(node) \
51 bakery_lock_get((node)->pwr_domain_index,\
Soby Mathewb48349e2015-06-29 16:30:12 +010052 CPU_DATA_PSCI_LOCK_OFFSET)
Soby Mathew4067dc32015-05-05 16:33:16 +010053#define psci_lock_release(node) \
54 bakery_lock_release((node)->pwr_domain_index,\
Soby Mathewb48349e2015-06-29 16:30:12 +010055 CPU_DATA_PSCI_LOCK_OFFSET)
56#endif
57
58/*
59 * The PSCI capability which are provided by the generic code but does not
60 * depend on the platform or spd capabilities.
61 */
62#define PSCI_GENERIC_CAP \
63 (define_psci_cap(PSCI_VERSION) | \
64 define_psci_cap(PSCI_AFFINITY_INFO_AARCH64) | \
65 define_psci_cap(PSCI_FEATURES))
66
67/*
68 * The PSCI capabilities mask for 64 bit functions.
69 */
70#define PSCI_CAP_64BIT_MASK \
71 (define_psci_cap(PSCI_CPU_SUSPEND_AARCH64) | \
72 define_psci_cap(PSCI_CPU_ON_AARCH64) | \
73 define_psci_cap(PSCI_AFFINITY_INFO_AARCH64) | \
74 define_psci_cap(PSCI_MIG_AARCH64) | \
75 define_psci_cap(PSCI_MIG_INFO_UP_CPU_AARCH64) | \
76 define_psci_cap(PSCI_SYSTEM_SUSPEND_AARCH64))
77
78
79/*******************************************************************************
80 * The following two data structures hold the topology tree which in turn tracks
Soby Mathew4067dc32015-05-05 16:33:16 +010081 * the state of the all the power domain instances supported by the platform.
Soby Mathewb48349e2015-06-29 16:30:12 +010082 ******************************************************************************/
Soby Mathew4067dc32015-05-05 16:33:16 +010083typedef struct pwr_map_node {
Soby Mathewb48349e2015-06-29 16:30:12 +010084 unsigned long mpidr;
85 unsigned char ref_count;
86 unsigned char state;
87 unsigned char level;
88#if USE_COHERENT_MEM
89 bakery_lock_t lock;
90#else
91 /* For indexing the bakery_info array in per CPU data */
Soby Mathew4067dc32015-05-05 16:33:16 +010092 unsigned char pwr_domain_index;
Soby Mathewb48349e2015-06-29 16:30:12 +010093#endif
Soby Mathew4067dc32015-05-05 16:33:16 +010094} pwr_map_node_t;
Soby Mathewb48349e2015-06-29 16:30:12 +010095
Soby Mathew4067dc32015-05-05 16:33:16 +010096typedef struct pwr_lvl_limits_node {
Soby Mathewb48349e2015-06-29 16:30:12 +010097 int min;
98 int max;
Soby Mathew4067dc32015-05-05 16:33:16 +010099} pwr_lvl_limits_node_t;
Soby Mathewb48349e2015-06-29 16:30:12 +0100100
Soby Mathew4067dc32015-05-05 16:33:16 +0100101typedef pwr_map_node_t (*mpidr_pwr_map_nodes_t[MPIDR_MAX_AFFLVL + 1]);
102typedef void (*pwrlvl_power_on_finisher_t)(pwr_map_node_t *mpidr_nodes[],
103 int pwrlvl);
Soby Mathewb48349e2015-06-29 16:30:12 +0100104
105/*******************************************************************************
106 * Data prototypes
107 ******************************************************************************/
108extern const plat_pm_ops_t *psci_plat_pm_ops;
Soby Mathew4067dc32015-05-05 16:33:16 +0100109extern pwr_map_node_t psci_pwr_domain_map[PSCI_NUM_PWR_DOMAINS];
110extern pwr_lvl_limits_node_t psci_pwr_domain_map[MPIDR_MAX_AFFLVL + 1];
Soby Mathewb48349e2015-06-29 16:30:12 +0100111extern uint32_t psci_caps;
112
113/*******************************************************************************
114 * SPD's power management hooks registered with PSCI
115 ******************************************************************************/
116extern const spd_pm_ops_t *psci_spd_pm;
117
118/*******************************************************************************
119 * Function prototypes
120 ******************************************************************************/
121/* Private exported functions from psci_common.c */
Soby Mathew4067dc32015-05-05 16:33:16 +0100122unsigned short psci_get_state(pwr_map_node_t *node);
123unsigned short psci_get_phys_state(pwr_map_node_t *node);
124void psci_set_state(pwr_map_node_t *node, unsigned short state);
125unsigned long mpidr_set_pwr_domain_inst(unsigned long, unsigned char, int);
Soby Mathew12d0d002015-04-09 13:40:55 +0100126int psci_validate_mpidr(unsigned long mpidr);
Soby Mathew4067dc32015-05-05 16:33:16 +0100127int get_power_on_target_pwrlvl(void);
128void psci_power_up_finish(int end_pwrlvl,
129 pwrlvl_power_on_finisher_t pon_handler);
Soby Mathewb48349e2015-06-29 16:30:12 +0100130int psci_get_ns_ep_info(entry_point_info_t *ep,
131 uint64_t entrypoint, uint64_t context_id);
Soby Mathew4067dc32015-05-05 16:33:16 +0100132int psci_check_pwrlvl_range(int start_pwrlvl, int end_pwrlvl);
133void psci_do_state_coordination(uint32_t start_pwrlvl,
134 uint32_t end_pwrlvl,
135 pwr_map_node_t *mpidr_nodes[],
Soby Mathewb48349e2015-06-29 16:30:12 +0100136 uint32_t state);
Soby Mathew4067dc32015-05-05 16:33:16 +0100137void psci_acquire_pwr_domain_locks(int start_pwrlvl,
138 int end_pwrlvl,
139 pwr_map_node_t *mpidr_nodes[]);
140void psci_release_pwr_domain_locks(int start_pwrlvl,
141 int end_pwrlvl,
142 mpidr_pwr_map_nodes_t mpidr_nodes);
143void psci_print_power_domain_map(void);
144uint32_t psci_find_max_phys_off_pwrlvl(uint32_t start_pwrlvl,
145 uint32_t end_pwrlvl,
146 pwr_map_node_t *mpidr_nodes[]);
Soby Mathewb48349e2015-06-29 16:30:12 +0100147unsigned int psci_is_last_on_cpu(void);
148int psci_spd_migrate_info(uint64_t *mpidr);
149
150/* Private exported functions from psci_setup.c */
Soby Mathew4067dc32015-05-05 16:33:16 +0100151int psci_get_pwr_map_nodes(unsigned long mpidr,
152 int start_pwrlvl,
153 int end_pwrlvl,
154 pwr_map_node_t *mpidr_nodes[]);
155pwr_map_node_t *psci_get_pwr_map_node(unsigned long, int);
Soby Mathewb48349e2015-06-29 16:30:12 +0100156
Soby Mathew4067dc32015-05-05 16:33:16 +0100157/* Private exported functions from psci_cpu_on.c */
158int psci_cpu_on_start(unsigned long target_cpu,
Soby Mathewb48349e2015-06-29 16:30:12 +0100159 entry_point_info_t *ep,
Soby Mathew4067dc32015-05-05 16:33:16 +0100160 int end_pwrlvl);
Soby Mathewb48349e2015-06-29 16:30:12 +0100161
Soby Mathew4067dc32015-05-05 16:33:16 +0100162void psci_cpu_on_finish(pwr_map_node_t *node[], int pwrlvl);
Soby Mathew6590ce22015-06-30 11:00:24 +0100163
Soby Mathew4067dc32015-05-05 16:33:16 +0100164/* Private exported functions from psci_cpu_off.c */
165int psci_do_cpu_off(int end_pwrlvl);
Soby Mathewb48349e2015-06-29 16:30:12 +0100166
Soby Mathew4067dc32015-05-05 16:33:16 +0100167/* Private exported functions from psci_cpu_suspend.c */
168void psci_cpu_suspend_start(entry_point_info_t *ep,
169 int end_pwrlvl);
Soby Mathewb48349e2015-06-29 16:30:12 +0100170
Soby Mathew4067dc32015-05-05 16:33:16 +0100171void psci_cpu_suspend_finish(pwr_map_node_t *node[], int pwrlvl);
Soby Mathew6590ce22015-06-30 11:00:24 +0100172
Soby Mathewb48349e2015-06-29 16:30:12 +0100173void psci_set_suspend_power_state(unsigned int power_state);
174
175/* Private exported functions from psci_helpers.S */
Soby Mathew4067dc32015-05-05 16:33:16 +0100176void psci_do_pwrdown_cache_maintenance(uint32_t pwr_level);
Soby Mathewb48349e2015-06-29 16:30:12 +0100177void psci_do_pwrup_cache_maintenance(void);
178
179/* Private exported functions from psci_system_off.c */
180void __dead2 psci_system_off(void);
181void __dead2 psci_system_reset(void);
182
183#endif /* __PSCI_PRIVATE_H__ */