blob: 62a0efc864e71cfd453eb3601b411326e07d3592 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +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
Achin Guptaa59caa42013-12-05 14:21:04 +000034#include <arch.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010035#include <bakery_lock.h>
Soby Mathew8595b872015-01-06 15:36:38 +000036#include <bl_common.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010037#include <psci.h>
Achin Gupta4f6ad662013-10-25 09:08:21 +010038
Soby Mathew523d6332015-01-08 18:02:19 +000039/*
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))
Andrew Thoelke56f44702014-06-20 00:36:14 +010047#else
Soby Mathew523d6332015-01-08 18:02:19 +000048#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)
Andrew Thoelke56f44702014-06-20 00:36:14 +010053#endif
54
Soby Mathew6cdddaf2015-01-07 11:10:22 +000055/*
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
74
Achin Gupta4f6ad662013-10-25 09:08:21 +010075/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +010076 * The following two data structures hold the topology tree which in turn tracks
77 * the state of the all the affinity instances supported by the platform.
78 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +010079typedef struct aff_map_node {
Achin Gupta4f6ad662013-10-25 09:08:21 +010080 unsigned long mpidr;
Soby Mathew523d6332015-01-08 18:02:19 +000081 unsigned char ref_count;
Achin Gupta4f6ad662013-10-25 09:08:21 +010082 unsigned char state;
Achin Gupta75f73672013-12-05 16:33:10 +000083 unsigned char level;
Soby Mathew523d6332015-01-08 18:02:19 +000084#if USE_COHERENT_MEM
Dan Handleye2712bc2014-04-10 15:37:22 +010085 bakery_lock_t lock;
Soby Mathew523d6332015-01-08 18:02:19 +000086#else
87 /* For indexing the bakery_info array in per CPU data */
88 unsigned char aff_map_index;
89#endif
Dan Handleye2712bc2014-04-10 15:37:22 +010090} aff_map_node_t;
Achin Gupta4f6ad662013-10-25 09:08:21 +010091
Dan Handleye2712bc2014-04-10 15:37:22 +010092typedef struct aff_limits_node {
Achin Gupta4f6ad662013-10-25 09:08:21 +010093 int min;
94 int max;
Dan Handleye2712bc2014-04-10 15:37:22 +010095} aff_limits_node_t;
Achin Gupta4f6ad662013-10-25 09:08:21 +010096
Soby Mathewe2b2d8f2014-12-04 14:14:12 +000097typedef aff_map_node_t (*mpidr_aff_map_nodes_t[MPIDR_MAX_AFFLVL + 1]);
Soby Mathew74e52a72014-10-02 16:56:51 +010098typedef void (*afflvl_power_on_finisher_t)(aff_map_node_t *);
Achin Gupta4f6ad662013-10-25 09:08:21 +010099
100/*******************************************************************************
101 * Data prototypes
102 ******************************************************************************/
Dan Handleya4cb68e2014-04-23 13:47:06 +0100103extern const plat_pm_ops_t *psci_plat_pm_ops;
Dan Handleye2712bc2014-04-10 15:37:22 +0100104extern aff_map_node_t psci_aff_map[PSCI_NUM_AFFS];
Soby Mathew6cdddaf2015-01-07 11:10:22 +0000105extern uint32_t psci_caps;
Achin Gupta4f6ad662013-10-25 09:08:21 +0100106
107/*******************************************************************************
Jeenu Viswambharan7f366602014-02-20 17:11:00 +0000108 * SPD's power management hooks registered with PSCI
Achin Gupta607084e2014-02-09 18:24:19 +0000109 ******************************************************************************/
Dan Handleye2712bc2014-04-10 15:37:22 +0100110extern const spd_pm_ops_t *psci_spd_pm;
Achin Gupta607084e2014-02-09 18:24:19 +0000111
112/*******************************************************************************
Achin Gupta4f6ad662013-10-25 09:08:21 +0100113 * Function prototypes
114 ******************************************************************************/
115/* Private exported functions from psci_common.c */
Dan Handleya17fefa2014-05-14 12:38:32 +0100116unsigned short psci_get_state(aff_map_node_t *node);
117unsigned short psci_get_phys_state(aff_map_node_t *node);
118void psci_set_state(aff_map_node_t *node, unsigned short state);
Dan Handleya17fefa2014-05-14 12:38:32 +0100119unsigned long mpidr_set_aff_inst(unsigned long, unsigned char, int);
120int psci_validate_mpidr(unsigned long, int);
Achin Guptaf3ccbab2014-07-25 14:52:47 +0100121int get_power_on_target_afflvl(void);
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100122void psci_afflvl_power_on_finish(int,
Dan Handleya17fefa2014-05-14 12:38:32 +0100123 int,
124 afflvl_power_on_finisher_t *);
Soby Mathew8595b872015-01-06 15:36:38 +0000125int psci_get_ns_ep_info(entry_point_info_t *ep,
126 uint64_t entrypoint, uint64_t context_id);
Dan Handleya17fefa2014-05-14 12:38:32 +0100127int psci_check_afflvl_range(int start_afflvl, int end_afflvl);
Achin Guptacab78e42014-07-28 00:09:01 +0100128void psci_do_afflvl_state_mgmt(uint32_t start_afflvl,
129 uint32_t end_afflvl,
Achin Gupta56bcdc22014-07-28 00:15:23 +0100130 aff_map_node_t *mpidr_nodes[],
Achin Guptacab78e42014-07-28 00:09:01 +0100131 uint32_t state);
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100132void psci_acquire_afflvl_locks(int start_afflvl,
Achin Gupta56bcdc22014-07-28 00:15:23 +0100133 int end_afflvl,
134 aff_map_node_t *mpidr_nodes[]);
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100135void psci_release_afflvl_locks(int start_afflvl,
Dan Handleya17fefa2014-05-14 12:38:32 +0100136 int end_afflvl,
137 mpidr_aff_map_nodes_t mpidr_nodes);
Juan Castillo4dc4a472014-08-12 11:17:06 +0100138void psci_print_affinity_map(void);
Achin Guptaf6b9e992014-07-31 11:19:11 +0100139void psci_set_max_phys_off_afflvl(uint32_t afflvl);
140uint32_t psci_find_max_phys_off_afflvl(uint32_t start_afflvl,
141 uint32_t end_afflvl,
Achin Gupta56bcdc22014-07-28 00:15:23 +0100142 aff_map_node_t *mpidr_nodes[]);
Soby Mathew110fe362014-10-23 10:35:34 +0100143int psci_spd_migrate_info(uint64_t *mpidr);
Achin Gupta0959db52013-12-02 17:33:04 +0000144
Achin Gupta4f6ad662013-10-25 09:08:21 +0100145/* Private exported functions from psci_setup.c */
Dan Handleya17fefa2014-05-14 12:38:32 +0100146int psci_get_aff_map_nodes(unsigned long mpidr,
147 int start_afflvl,
148 int end_afflvl,
Achin Gupta56bcdc22014-07-28 00:15:23 +0100149 aff_map_node_t *mpidr_nodes[]);
Dan Handleya17fefa2014-05-14 12:38:32 +0100150aff_map_node_t *psci_get_aff_map_node(unsigned long, int);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100151
152/* Private exported functions from psci_affinity_on.c */
Soby Mathew8595b872015-01-06 15:36:38 +0000153int psci_afflvl_on(unsigned long target_cpu,
154 entry_point_info_t *ep,
155 int start_afflvl,
156 int end_afflvl);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100157
158/* Private exported functions from psci_affinity_off.c */
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100159int psci_afflvl_off(int, int);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100160
161/* Private exported functions from psci_affinity_suspend.c */
Soby Mathew74e52a72014-10-02 16:56:51 +0100162void psci_afflvl_suspend(entry_point_info_t *ep,
Soby Mathew8595b872015-01-06 15:36:38 +0000163 int start_afflvl,
164 int end_afflvl);
165
Andrew Thoelke2bc07852014-06-09 12:44:21 +0100166unsigned int psci_afflvl_suspend_finish(int, int);
Achin Guptaf3ccbab2014-07-25 14:52:47 +0100167void psci_set_suspend_power_state(unsigned int power_state);
Jeenu Viswambharancaa84932014-02-06 10:36:15 +0000168
Achin Guptae1aa5162014-06-26 09:58:52 +0100169/* Private exported functions from psci_helpers.S */
170void psci_do_pwrdown_cache_maintenance(uint32_t affinity_level);
171void psci_do_pwrup_cache_maintenance(void);
Achin Gupta4f6ad662013-10-25 09:08:21 +0100172
Juan Castillo4dc4a472014-08-12 11:17:06 +0100173/* Private exported functions from psci_system_off.c */
174void __dead2 psci_system_off(void);
175void __dead2 psci_system_reset(void);
176
Achin Gupta4f6ad662013-10-25 09:08:21 +0100177#endif /* __PSCI_PRIVATE_H__ */