1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
* This file is part of the coreboot project.
*
* Copyright 2014 Google Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*/
#ifndef __ARCH_PSCI_H__
#define __ARCH_PSCI_H__
#include <stdint.h>
#include <arch/cpu.h>
#include <arch/smc.h>
/* Return Values */
enum {
PSCI_RET_SUCCESS = 0,
PSCI_RET_NOT_SUPPORTED = -1,
PSCI_RET_INVALID_PARAMETERS = -2,
PSCI_RET_DENIED = -3,
PSCI_RET_ALREADY_ON = -4,
PSCI_RET_ON_PENDING = -5,
PSCI_RET_INTERNAL_FAILURE = -6,
PSCI_RET_NOT_PRESENT = -7,
PSCI_RET_DISABLED = -8,
};
/* Generic PSCI state. */
enum {
PSCI_STATE_OFF = 0,
PSCI_STATE_ON_PENDING,
PSCI_STATE_ON,
};
/* Affinity level support. */
enum {
PSCI_AFFINITY_LEVEL_0,
PSCI_AFFINITY_LEVEL_1,
PSCI_AFFINITY_LEVEL_2,
PSCI_AFFINITY_LEVEL_3,
PSCI_AFFINITY_ROOT,
PSCI_AFFINITY_LEVEL_HIGHEST = PSCI_AFFINITY_ROOT,
};
static inline int psci_level_below(int level)
{
return level - 1;
}
struct psci_node;
struct psci_cpu_state {
struct cpu_info *ci;
struct cpu_action startup;
/* Ancestor of target to update state in CPU_ON case. */
struct psci_node *ancestor;
};
struct psci_node_group {
size_t num;
struct psci_node *nodes;
};
struct psci_node {
uint64_t mpidr;
/* Affinity level of node. */
int level;
/* Generic power state of this entity. */
int state;
/* The SoC can stash its own state accounting in here. */
int soc_state;
/* Parent of curernt entity. */
struct psci_node *parent;
/*
* CPUs are leaves in the tree. They don't have children. The
* CPU-specific bits of storage can be shared with the children
* storage.
*/
union {
struct psci_node_group children;
struct psci_cpu_state cpu_state;
};
};
static inline struct psci_node *psci_node_parent(const struct psci_node *n)
{
return n->parent;
}
static inline int psci_root_node(const struct psci_node *n)
{
return psci_node_parent(n) == NULL;
}
enum {
PSCI_CMD_ON,
PSCI_CMD_OFF,
PSCI_CMD_STANDBY,
};
/*
* PSCI actions are serialized into a command for the SoC to process. There are
* 2 phases of a command being processed: prepare and commit. The prepare() is
* called with the PSCI locks held for the state of the PSCI nodes. If
* successful, the appropriate locks will be dropped and commit() will be
* called with the same structure. It is permissible for the SoC support code
* to modify the struture passed in (e.g. to update the requested state_id to
* reflect dynamic constraints on how deep of a state to enter).
*/
struct psci_cmd {
/* Command type. */
int type;
/*
* PSCI state id for PSCI_CMD_OFF and PSCI_CMD_STANDBY commands.
* A value of -1 indicates a CPU_OFF request.
*/
int state_id;
/*
* target is the command's target, but it can affect up to the
* ancestor entity. If target == ancestor then it only affects
* target, otherwise all entites up the hierarchy including ancestor.
*/
struct psci_node *target;
struct psci_node *ancestor;
};
struct psci_soc_ops {
/*
* Return number of entities one level below given parent affinitly
* level and mpidr.
*/
size_t (*children_at_level)(int parent_level, uint64_t mpidr);
int (*cmd_prepare)(struct psci_cmd *cmd);
int (*cmd_commit)(struct psci_cmd *cmd);
};
/* Each SoC needs to provide the functions in the psci_soc_ops structure. */
extern struct psci_soc_ops soc_psci_ops;
/* PSCI Functions. */
enum {
/* 32-bit System level functions. */
PSCI_VERSION = SMC_FUNC_FAST32(0x4, 0x0),
PSCI_SYSTEM_OFF = SMC_FUNC_FAST32(0x4, 0x8),
PSCI_SYSTEM_RESET = SMC_FUNC_FAST32(0x4, 0x9),
/* 32-bit CPU support functions. */
PSCI_CPU_SUSPEND32 = SMC_FUNC_FAST32(0x4, 0x1),
PSCI_CPU_OFF32 = SMC_FUNC_FAST32(0x4, 0x2),
PSCI_CPU_ON32 = SMC_FUNC_FAST32(0x4, 0x3),
/* 64-bit CPU support functions. */
PSCI_CPU_SUSPEND64 = SMC_FUNC_FAST64(0x4, 0x1),
PSCI_CPU_ON64 = SMC_FUNC_FAST64(0x4, 0x3),
};
/* Parameter arguments. */
enum {
PSCI_PARAM_0 = 1,
PSCI_PARAM_1,
PSCI_PARAM_2,
PSCI_PARAM_3,
PSCI_RETURN_0 = 1,
PSCI_RETURN_1,
PSCI_RETURN_2,
PSCI_RETURN_3,
};
struct psci_func {
uint32_t id;
struct smc_call *smc;
};
static inline void psci_func_init(struct psci_func *pf, struct smc_call *smc)
{
pf->id = smc_function_id(smc);
pf->smc = smc;
}
static inline uint64_t psci64_arg(struct psci_func *pf, unsigned i)
{
return smc64_arg(pf->smc, i);
}
static inline uint32_t psci32_arg(struct psci_func *pf, unsigned i)
{
return psci64_arg(pf, i);
}
static inline void psci64_result(struct psci_func *pf, unsigned i, uint64_t v)
{
smc64_result(pf->smc, i, v);
}
static inline void psci32_result(struct psci_func *pf, unsigned i, uint32_t v)
{
uint64_t v64 = v;
psci64_result(pf, i, v64);
}
static inline void psci32_return(struct psci_func *pf, int32_t val)
{
psci32_result(pf, 0, val);
}
static inline void psci64_return(struct psci_func *pf, int64_t val)
{
psci64_result(pf, 0, val);
}
void psci_init(uintptr_t cpu_on_entry);
void psci_soc_init(uintptr_t cpu_on_entry);
/* Turn on the current CPU within the PSCI subsystem. */
void psci_turn_on_self(const struct cpu_action *action);
int psci_turn_off_self(void);
/* Entry point for CPUs just turning on or waking up. */
void psci_cpu_entry(void);
#endif /* __ARCH_PSCI_H__ */
|