Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 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 |
| 44 | #define psci_lock_init(aff_map, idx) bakery_lock_init(&(aff_map)[(idx)].lock) |
| 45 | #define psci_lock_get(node) bakery_lock_get(&((node)->lock)) |
| 46 | #define psci_lock_release(node) bakery_lock_release(&((node)->lock)) |
| 47 | #else |
| 48 | #define psci_lock_init(aff_map, idx) ((aff_map)[(idx)].aff_map_index = (idx)) |
| 49 | #define psci_lock_get(node) bakery_lock_get((node)->aff_map_index, \ |
| 50 | CPU_DATA_PSCI_LOCK_OFFSET) |
| 51 | #define psci_lock_release(node) bakery_lock_release((node)->aff_map_index,\ |
| 52 | CPU_DATA_PSCI_LOCK_OFFSET) |
| 53 | #endif |
| 54 | |
| 55 | /* |
| 56 | * The PSCI capability which are provided by the generic code but does not |
| 57 | * depend on the platform or spd capabilities. |
| 58 | */ |
| 59 | #define PSCI_GENERIC_CAP \ |
| 60 | (define_psci_cap(PSCI_VERSION) | \ |
| 61 | define_psci_cap(PSCI_AFFINITY_INFO_AARCH64) | \ |
| 62 | define_psci_cap(PSCI_FEATURES)) |
| 63 | |
| 64 | /* |
| 65 | * The PSCI capabilities mask for 64 bit functions. |
| 66 | */ |
| 67 | #define PSCI_CAP_64BIT_MASK \ |
| 68 | (define_psci_cap(PSCI_CPU_SUSPEND_AARCH64) | \ |
| 69 | define_psci_cap(PSCI_CPU_ON_AARCH64) | \ |
| 70 | define_psci_cap(PSCI_AFFINITY_INFO_AARCH64) | \ |
| 71 | define_psci_cap(PSCI_MIG_AARCH64) | \ |
| 72 | define_psci_cap(PSCI_MIG_INFO_UP_CPU_AARCH64) | \ |
| 73 | define_psci_cap(PSCI_SYSTEM_SUSPEND_AARCH64)) |
| 74 | |
| 75 | |
| 76 | /******************************************************************************* |
| 77 | * The following two data structures hold the topology tree which in turn tracks |
| 78 | * the state of the all the affinity instances supported by the platform. |
| 79 | ******************************************************************************/ |
| 80 | typedef struct aff_map_node { |
| 81 | unsigned long mpidr; |
| 82 | unsigned char ref_count; |
| 83 | unsigned char state; |
| 84 | unsigned char level; |
| 85 | #if USE_COHERENT_MEM |
| 86 | bakery_lock_t lock; |
| 87 | #else |
| 88 | /* For indexing the bakery_info array in per CPU data */ |
| 89 | unsigned char aff_map_index; |
| 90 | #endif |
| 91 | } aff_map_node_t; |
| 92 | |
| 93 | typedef struct aff_limits_node { |
| 94 | int min; |
| 95 | int max; |
| 96 | } aff_limits_node_t; |
| 97 | |
| 98 | typedef aff_map_node_t (*mpidr_aff_map_nodes_t[MPIDR_MAX_AFFLVL + 1]); |
Soby Mathew | 6b8b302 | 2015-06-30 11:00:24 +0100 | [diff] [blame^] | 99 | typedef void (*afflvl_power_on_finisher_t)(aff_map_node_t *mpidr_nodes[], |
| 100 | int afflvl); |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 101 | |
| 102 | /******************************************************************************* |
| 103 | * Data prototypes |
| 104 | ******************************************************************************/ |
| 105 | extern const plat_pm_ops_t *psci_plat_pm_ops; |
| 106 | extern aff_map_node_t psci_aff_map[PSCI_NUM_AFFS]; |
| 107 | extern aff_limits_node_t psci_aff_limits[MPIDR_MAX_AFFLVL + 1]; |
| 108 | extern uint32_t psci_caps; |
| 109 | |
| 110 | /******************************************************************************* |
| 111 | * SPD's power management hooks registered with PSCI |
| 112 | ******************************************************************************/ |
| 113 | extern const spd_pm_ops_t *psci_spd_pm; |
| 114 | |
| 115 | /******************************************************************************* |
| 116 | * Function prototypes |
| 117 | ******************************************************************************/ |
| 118 | /* Private exported functions from psci_common.c */ |
| 119 | unsigned short psci_get_state(aff_map_node_t *node); |
| 120 | unsigned short psci_get_phys_state(aff_map_node_t *node); |
| 121 | void psci_set_state(aff_map_node_t *node, unsigned short state); |
| 122 | unsigned long mpidr_set_aff_inst(unsigned long, unsigned char, int); |
| 123 | int psci_validate_mpidr(unsigned long, int); |
| 124 | int get_power_on_target_afflvl(void); |
Soby Mathew | 6b8b302 | 2015-06-30 11:00:24 +0100 | [diff] [blame^] | 125 | void psci_afflvl_power_on_finish(int end_afflvl, |
| 126 | afflvl_power_on_finisher_t pon_handler); |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 127 | int psci_get_ns_ep_info(entry_point_info_t *ep, |
| 128 | uint64_t entrypoint, uint64_t context_id); |
| 129 | int psci_check_afflvl_range(int start_afflvl, int end_afflvl); |
| 130 | void psci_do_afflvl_state_mgmt(uint32_t start_afflvl, |
| 131 | uint32_t end_afflvl, |
| 132 | aff_map_node_t *mpidr_nodes[], |
| 133 | uint32_t state); |
| 134 | void psci_acquire_afflvl_locks(int start_afflvl, |
| 135 | int end_afflvl, |
| 136 | aff_map_node_t *mpidr_nodes[]); |
| 137 | void psci_release_afflvl_locks(int start_afflvl, |
| 138 | int end_afflvl, |
| 139 | mpidr_aff_map_nodes_t mpidr_nodes); |
| 140 | void psci_print_affinity_map(void); |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 141 | uint32_t psci_find_max_phys_off_afflvl(uint32_t start_afflvl, |
| 142 | uint32_t end_afflvl, |
| 143 | aff_map_node_t *mpidr_nodes[]); |
| 144 | unsigned int psci_is_last_on_cpu(void); |
| 145 | int psci_spd_migrate_info(uint64_t *mpidr); |
| 146 | |
| 147 | /* Private exported functions from psci_setup.c */ |
| 148 | int psci_get_aff_map_nodes(unsigned long mpidr, |
| 149 | int start_afflvl, |
| 150 | int end_afflvl, |
| 151 | aff_map_node_t *mpidr_nodes[]); |
| 152 | aff_map_node_t *psci_get_aff_map_node(unsigned long, int); |
| 153 | |
| 154 | /* Private exported functions from psci_affinity_on.c */ |
| 155 | int psci_afflvl_on(unsigned long target_cpu, |
| 156 | entry_point_info_t *ep, |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 157 | int end_afflvl); |
| 158 | |
Soby Mathew | 6b8b302 | 2015-06-30 11:00:24 +0100 | [diff] [blame^] | 159 | void psci_afflvl_on_finisher(aff_map_node_t *node[], int afflvl); |
| 160 | |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 161 | /* Private exported functions from psci_affinity_off.c */ |
Soby Mathew | 6b8b302 | 2015-06-30 11:00:24 +0100 | [diff] [blame^] | 162 | int psci_afflvl_off(int end_afflvl); |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 163 | |
| 164 | /* Private exported functions from psci_affinity_suspend.c */ |
| 165 | void psci_afflvl_suspend(entry_point_info_t *ep, |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 166 | int end_afflvl); |
| 167 | |
Soby Mathew | 6b8b302 | 2015-06-30 11:00:24 +0100 | [diff] [blame^] | 168 | void psci_afflvl_suspend_finisher(aff_map_node_t *node[], int afflvl); |
| 169 | |
Soby Mathew | 991d42c | 2015-06-29 16:30:12 +0100 | [diff] [blame] | 170 | void psci_set_suspend_power_state(unsigned int power_state); |
| 171 | |
| 172 | /* Private exported functions from psci_helpers.S */ |
| 173 | void psci_do_pwrdown_cache_maintenance(uint32_t affinity_level); |
| 174 | void psci_do_pwrup_cache_maintenance(void); |
| 175 | |
| 176 | /* Private exported functions from psci_system_off.c */ |
| 177 | void __dead2 psci_system_off(void); |
| 178 | void __dead2 psci_system_reset(void); |
| 179 | |
| 180 | #endif /* __PSCI_PRIVATE_H__ */ |