blob: 9fe8b3759d3dc8695f0882c03162cd9bcfed7cdf [file] [log] [blame]
Soby Mathewea26bad2016-11-14 12:25:45 +00001/*
Pranav Madhu0c02e812021-12-11 22:23:25 +05302 * Copyright (c) 2017-2022, Arm Limited and Contributors. All rights reserved.
Soby Mathewea26bad2016-11-14 12:25:45 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Soby Mathewea26bad2016-11-14 12:25:45 +00007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <string.h>
9
10#include <arch_helpers.h>
11#include <common/debug.h>
Antonio Nino Diaz326f56b2019-01-23 18:55:03 +000012#include <drivers/arm/css/css_scp.h>
Antonio Nino Diazc30db5b2019-01-23 20:37:32 +000013#include <drivers/arm/css/scmi.h>
Pranav Madhu0c02e812021-12-11 22:23:25 +053014#include <lib/mmio.h>
Antonio Nino Diazbd7b7402019-01-25 14:30:04 +000015#include <plat/arm/common/plat_arm.h>
16#include <plat/arm/css/common/css_pm.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <plat/common/platform.h>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000018#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000019
Soby Mathewea26bad2016-11-14 12:25:45 +000020/*
21 * This file implements the SCP helper functions using SCMI protocol.
22 */
23
24/*
25 * SCMI power state parameter bit field encoding for ARM CSS platforms.
26 *
27 * 31 20 19 16 15 12 11 8 7 4 3 0
28 * +-------------------------------------------------------------+
29 * | SBZ | Max level | Level 3 | Level 2 | Level 1 | Level 0 |
30 * | | | state | state | state | state |
31 * +-------------------------------------------------------------+
32 *
33 * `Max level` encodes the highest level that has a valid power state
34 * encoded in the power state.
35 */
36#define SCMI_PWR_STATE_MAX_PWR_LVL_SHIFT 16
37#define SCMI_PWR_STATE_MAX_PWR_LVL_WIDTH 4
38#define SCMI_PWR_STATE_MAX_PWR_LVL_MASK \
39 ((1 << SCMI_PWR_STATE_MAX_PWR_LVL_WIDTH) - 1)
Daniel Boulbyddf6d402018-05-09 12:21:46 +010040#define SCMI_SET_PWR_STATE_MAX_PWR_LVL(_power_state, _max_level) \
41 (_power_state) |= ((_max_level) & SCMI_PWR_STATE_MAX_PWR_LVL_MASK)\
Soby Mathewea26bad2016-11-14 12:25:45 +000042 << SCMI_PWR_STATE_MAX_PWR_LVL_SHIFT
Daniel Boulbyddf6d402018-05-09 12:21:46 +010043#define SCMI_GET_PWR_STATE_MAX_PWR_LVL(_power_state) \
44 (((_power_state) >> SCMI_PWR_STATE_MAX_PWR_LVL_SHIFT) \
Soby Mathewea26bad2016-11-14 12:25:45 +000045 & SCMI_PWR_STATE_MAX_PWR_LVL_MASK)
46
47#define SCMI_PWR_STATE_LVL_WIDTH 4
48#define SCMI_PWR_STATE_LVL_MASK \
49 ((1 << SCMI_PWR_STATE_LVL_WIDTH) - 1)
Daniel Boulbyddf6d402018-05-09 12:21:46 +010050#define SCMI_SET_PWR_STATE_LVL(_power_state, _level, _level_state) \
51 (_power_state) |= ((_level_state) & SCMI_PWR_STATE_LVL_MASK) \
52 << (SCMI_PWR_STATE_LVL_WIDTH * (_level))
53#define SCMI_GET_PWR_STATE_LVL(_power_state, _level) \
54 (((_power_state) >> (SCMI_PWR_STATE_LVL_WIDTH * (_level))) & \
Soby Mathewea26bad2016-11-14 12:25:45 +000055 SCMI_PWR_STATE_LVL_MASK)
56
57/*
58 * The SCMI power state enumeration for a power domain level
59 */
60typedef enum {
61 scmi_power_state_off = 0,
62 scmi_power_state_on = 1,
63 scmi_power_state_sleep = 2,
64} scmi_power_state_t;
65
66/*
Aditya Angadi7f8837b2019-12-31 14:23:53 +053067 * The global handles for invoking the SCMI driver APIs after the driver
Soby Mathewea26bad2016-11-14 12:25:45 +000068 * has been initialized.
69 */
Aditya Angadi7f8837b2019-12-31 14:23:53 +053070static void *scmi_handles[PLAT_ARM_SCMI_CHANNEL_COUNT];
Soby Mathewea26bad2016-11-14 12:25:45 +000071
Aditya Angadi7f8837b2019-12-31 14:23:53 +053072/* The global SCMI channels array */
73static scmi_channel_t scmi_channels[PLAT_ARM_SCMI_CHANNEL_COUNT];
Soby Mathewea26bad2016-11-14 12:25:45 +000074
Aditya Angadi7f8837b2019-12-31 14:23:53 +053075/*
76 * Channel ID for the default SCMI channel.
77 * The default channel is used to issue SYSTEM level SCMI requests and is
78 * initialized to the channel which has the boot cpu as its resource.
79 */
80static uint32_t default_scmi_channel_id;
81
82/*
83 * TODO: Allow use of channel specific lock instead of using a single lock for
84 * all the channels.
85 */
Roberto Vargas00996942017-11-13 13:41:58 +000086ARM_SCMI_INSTANTIATE_LOCK;
Soby Mathewea26bad2016-11-14 12:25:45 +000087
88/*
Aditya Angadi7f8837b2019-12-31 14:23:53 +053089 * Function to obtain the SCMI Domain ID and SCMI Channel number from the linear
90 * core position. The SCMI Channel number is encoded in the upper 16 bits and
91 * the Domain ID is encoded in the lower 16 bits in each entry of the mapping
92 * array exported by the platform.
93 */
94static void css_scp_core_pos_to_scmi_channel(unsigned int core_pos,
95 unsigned int *scmi_domain_id, unsigned int *scmi_channel_id)
96{
97 unsigned int composite_id;
98
99 composite_id = plat_css_core_pos_to_scmi_dmn_id_map[core_pos];
100
101 *scmi_channel_id = GET_SCMI_CHANNEL_ID(composite_id);
102 *scmi_domain_id = GET_SCMI_DOMAIN_ID(composite_id);
103}
104
105/*
Soby Mathewea26bad2016-11-14 12:25:45 +0000106 * Helper function to suspend a CPU power domain and its parent power domains
107 * if applicable.
108 */
Roberto Vargas5f5a5e62018-02-12 12:36:17 +0000109void css_scp_suspend(const struct psci_power_state *target_state)
Soby Mathewea26bad2016-11-14 12:25:45 +0000110{
Deepak Pandey207c5222017-10-10 21:34:32 +0530111 int ret;
Soby Mathewea26bad2016-11-14 12:25:45 +0000112
113 /* At least power domain level 0 should be specified to be suspended */
114 assert(target_state->pwr_domain_state[ARM_PWR_LVL0] ==
115 ARM_LOCAL_STATE_OFF);
116
117 /* Check if power down at system power domain level is requested */
Nariman Poushincd956262018-05-01 09:28:40 +0100118 if (css_system_pwr_state(target_state) == ARM_LOCAL_STATE_OFF) {
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530119 /* Issue SCMI command for SYSTEM_SUSPEND on all SCMI channels */
120 ret = scmi_sys_pwr_state_set(
121 scmi_handles[default_scmi_channel_id],
122 SCMI_SYS_PWR_FORCEFUL_REQ, SCMI_SYS_PWR_SUSPEND);
Soby Mathewea26bad2016-11-14 12:25:45 +0000123 if (ret != SCMI_E_SUCCESS) {
124 ERROR("SCMI system power domain suspend return 0x%x unexpected\n",
125 ret);
126 panic();
127 }
128 return;
129 }
Deepak Pandey207c5222017-10-10 21:34:32 +0530130#if !HW_ASSISTED_COHERENCY
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530131 unsigned int lvl, channel_id, domain_id;
Deepak Pandey207c5222017-10-10 21:34:32 +0530132 uint32_t scmi_pwr_state = 0;
Soby Mathewea26bad2016-11-14 12:25:45 +0000133 /*
134 * If we reach here, then assert that power down at system power domain
135 * level is running.
136 */
Soby Mathewfd2e5e42018-09-10 11:32:49 +0100137 assert(css_system_pwr_state(target_state) == ARM_LOCAL_STATE_RUN);
Soby Mathewea26bad2016-11-14 12:25:45 +0000138
139 /* For level 0, specify `scmi_power_state_sleep` as the power state */
140 SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, ARM_PWR_LVL0,
141 scmi_power_state_sleep);
142
143 for (lvl = ARM_PWR_LVL1; lvl <= PLAT_MAX_PWR_LVL; lvl++) {
144 if (target_state->pwr_domain_state[lvl] == ARM_LOCAL_STATE_RUN)
145 break;
146
147 assert(target_state->pwr_domain_state[lvl] ==
148 ARM_LOCAL_STATE_OFF);
149 /*
150 * Specify `scmi_power_state_off` as power state for higher
151 * levels.
152 */
153 SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, lvl,
154 scmi_power_state_off);
155 }
156
157 SCMI_SET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state, lvl - 1);
158
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530159 css_scp_core_pos_to_scmi_channel(plat_my_core_pos(),
160 &domain_id, &channel_id);
161 ret = scmi_pwr_state_set(scmi_handles[channel_id],
162 domain_id, scmi_pwr_state);
Soby Mathewea26bad2016-11-14 12:25:45 +0000163
164 if (ret != SCMI_E_SUCCESS) {
165 ERROR("SCMI set power state command return 0x%x unexpected\n",
166 ret);
167 panic();
168 }
Deepak Pandey207c5222017-10-10 21:34:32 +0530169#endif
Soby Mathewea26bad2016-11-14 12:25:45 +0000170}
171
172/*
173 * Helper function to turn off a CPU power domain and its parent power domains
174 * if applicable.
175 */
Roberto Vargas85664f52018-02-12 12:36:17 +0000176void css_scp_off(const struct psci_power_state *target_state)
Soby Mathewea26bad2016-11-14 12:25:45 +0000177{
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530178 unsigned int lvl = 0, channel_id, domain_id;
Ambroise Vincenta88a35d2019-02-14 09:48:21 +0000179 int ret;
Soby Mathewea26bad2016-11-14 12:25:45 +0000180 uint32_t scmi_pwr_state = 0;
181
182 /* At-least the CPU level should be specified to be OFF */
183 assert(target_state->pwr_domain_state[ARM_PWR_LVL0] ==
184 ARM_LOCAL_STATE_OFF);
185
186 /* PSCI CPU OFF cannot be used to turn OFF system power domain */
Soby Mathewfd2e5e42018-09-10 11:32:49 +0100187 assert(css_system_pwr_state(target_state) == ARM_LOCAL_STATE_RUN);
Soby Mathewea26bad2016-11-14 12:25:45 +0000188
189 for (; lvl <= PLAT_MAX_PWR_LVL; lvl++) {
190 if (target_state->pwr_domain_state[lvl] == ARM_LOCAL_STATE_RUN)
191 break;
192
193 assert(target_state->pwr_domain_state[lvl] ==
194 ARM_LOCAL_STATE_OFF);
195 SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, lvl,
196 scmi_power_state_off);
197 }
198
199 SCMI_SET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state, lvl - 1);
200
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530201 css_scp_core_pos_to_scmi_channel(plat_my_core_pos(),
202 &domain_id, &channel_id);
203 ret = scmi_pwr_state_set(scmi_handles[channel_id],
204 domain_id, scmi_pwr_state);
Soby Mathewea26bad2016-11-14 12:25:45 +0000205 if (ret != SCMI_E_QUEUED && ret != SCMI_E_SUCCESS) {
206 ERROR("SCMI set power state command return 0x%x unexpected\n",
207 ret);
208 panic();
209 }
210}
211
212/*
213 * Helper function to turn ON a CPU power domain and its parent power domains
214 * if applicable.
215 */
216void css_scp_on(u_register_t mpidr)
217{
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530218 unsigned int lvl = 0, channel_id, core_pos, domain_id;
219 int ret;
Soby Mathewea26bad2016-11-14 12:25:45 +0000220 uint32_t scmi_pwr_state = 0;
221
222 for (; lvl <= PLAT_MAX_PWR_LVL; lvl++)
223 SCMI_SET_PWR_STATE_LVL(scmi_pwr_state, lvl,
224 scmi_power_state_on);
225
226 SCMI_SET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state, lvl - 1);
227
Manish Pandeybb667592020-03-03 17:12:10 +0000228 core_pos = (unsigned int)plat_core_pos_by_mpidr(mpidr);
229 assert(core_pos < PLATFORM_CORE_COUNT);
Soby Mathewe089e3f2017-06-09 15:04:43 +0100230
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530231 css_scp_core_pos_to_scmi_channel(core_pos, &domain_id,
232 &channel_id);
233 ret = scmi_pwr_state_set(scmi_handles[channel_id],
234 domain_id, scmi_pwr_state);
Soby Mathewea26bad2016-11-14 12:25:45 +0000235 if (ret != SCMI_E_QUEUED && ret != SCMI_E_SUCCESS) {
236 ERROR("SCMI set power state command return 0x%x unexpected\n",
237 ret);
238 panic();
239 }
240}
241
242/*
243 * Helper function to get the power state of a power domain node as reported
244 * by the SCP.
245 */
246int css_scp_get_power_state(u_register_t mpidr, unsigned int power_level)
247{
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530248 int ret;
Soby Mathewea26bad2016-11-14 12:25:45 +0000249 uint32_t scmi_pwr_state = 0, lvl_state;
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530250 unsigned int channel_id, cpu_idx, domain_id;
Soby Mathewea26bad2016-11-14 12:25:45 +0000251
252 /* We don't support get power state at the system power domain level */
253 if ((power_level > PLAT_MAX_PWR_LVL) ||
254 (power_level == CSS_SYSTEM_PWR_DMN_LVL)) {
255 WARN("Invalid power level %u specified for SCMI get power state\n",
256 power_level);
257 return PSCI_E_INVALID_PARAMS;
258 }
259
Manish Pandeybb667592020-03-03 17:12:10 +0000260 cpu_idx = (unsigned int)plat_core_pos_by_mpidr(mpidr);
261 assert(cpu_idx < PLATFORM_CORE_COUNT);
Soby Mathewea26bad2016-11-14 12:25:45 +0000262
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530263 css_scp_core_pos_to_scmi_channel(cpu_idx, &domain_id, &channel_id);
264 ret = scmi_pwr_state_get(scmi_handles[channel_id],
265 domain_id, &scmi_pwr_state);
Soby Mathewea26bad2016-11-14 12:25:45 +0000266
267 if (ret != SCMI_E_SUCCESS) {
268 WARN("SCMI get power state command return 0x%x unexpected\n",
269 ret);
270 return PSCI_E_INVALID_PARAMS;
271 }
272
273 /*
274 * Find the maximum power level described in the get power state
275 * command. If it is less than the requested power level, then assume
276 * the requested power level is ON.
277 */
278 if (SCMI_GET_PWR_STATE_MAX_PWR_LVL(scmi_pwr_state) < power_level)
279 return HW_ON;
280
281 lvl_state = SCMI_GET_PWR_STATE_LVL(scmi_pwr_state, power_level);
282 if (lvl_state == scmi_power_state_on)
283 return HW_ON;
284
285 assert((lvl_state == scmi_power_state_off) ||
286 (lvl_state == scmi_power_state_sleep));
287 return HW_OFF;
288}
289
Pranav Madhub785b842022-07-22 23:46:11 +0530290/*
291 * Callback function to raise a SGI designated to trigger the CPU power down
292 * sequence on all the online secondary cores.
293 */
294static void css_raise_pwr_down_interrupt(u_register_t mpidr)
295{
296#if CSS_SYSTEM_GRACEFUL_RESET
297 plat_ic_raise_el3_sgi(CSS_CPU_PWR_DOWN_REQ_INTR, mpidr);
298#endif
299}
300
Roberto Vargasfc2b4eb2017-07-31 09:45:10 +0100301void __dead2 css_scp_system_off(int state)
Soby Mathewea26bad2016-11-14 12:25:45 +0000302{
303 int ret;
304
305 /*
Pranav Madhu0c02e812021-12-11 22:23:25 +0530306 * Before issuing the system power down command, set the trusted mailbox
307 * to 0. This will ensure that in the case of a warm/cold reset, the
308 * primary CPU executes from the cold boot sequence.
309 */
310 mmio_write_64(PLAT_ARM_TRUSTED_MAILBOX_BASE, 0U);
311
312 /*
Pranav Madhub785b842022-07-22 23:46:11 +0530313 * Send powerdown request to online secondary core(s)
314 */
315 ret = psci_stop_other_cores(0, css_raise_pwr_down_interrupt);
316 if (ret != PSCI_E_SUCCESS) {
317 ERROR("Failed to powerdown secondary core(s)\n");
318 }
319
320 /*
Soby Mathewea26bad2016-11-14 12:25:45 +0000321 * Disable GIC CPU interface to prevent pending interrupt from waking
322 * up the AP from WFI.
323 */
324 plat_arm_gic_cpuif_disable();
Pranav Madhub785b842022-07-22 23:46:11 +0530325 plat_arm_gic_redistif_off();
Soby Mathewea26bad2016-11-14 12:25:45 +0000326
327 /*
Roberto Vargasfc2b4eb2017-07-31 09:45:10 +0100328 * Issue SCMI command. First issue a graceful
Soby Mathewea26bad2016-11-14 12:25:45 +0000329 * request and if that fails force the request.
330 */
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530331 ret = scmi_sys_pwr_state_set(scmi_handles[default_scmi_channel_id],
Soby Mathewea26bad2016-11-14 12:25:45 +0000332 SCMI_SYS_PWR_FORCEFUL_REQ,
Roberto Vargasfc2b4eb2017-07-31 09:45:10 +0100333 state);
334
Soby Mathewea26bad2016-11-14 12:25:45 +0000335 if (ret != SCMI_E_SUCCESS) {
Roberto Vargasfc2b4eb2017-07-31 09:45:10 +0100336 ERROR("SCMI system power state set 0x%x returns unexpected 0x%x\n",
337 state, ret);
Soby Mathewea26bad2016-11-14 12:25:45 +0000338 panic();
339 }
Pranav Madhub785b842022-07-22 23:46:11 +0530340
341 /* Powerdown of primary core */
342 psci_pwrdown_cpu(PLAT_MAX_PWR_LVL);
Soby Mathewea26bad2016-11-14 12:25:45 +0000343 wfi();
Roberto Vargasfc2b4eb2017-07-31 09:45:10 +0100344 ERROR("CSS set power state: operation not handled.\n");
Soby Mathewea26bad2016-11-14 12:25:45 +0000345 panic();
346}
347
348/*
Roberto Vargasfc2b4eb2017-07-31 09:45:10 +0100349 * Helper function to shutdown the system via SCMI.
350 */
351void __dead2 css_scp_sys_shutdown(void)
352{
353 css_scp_system_off(SCMI_SYS_PWR_SHUTDOWN);
354}
355
356/*
Soby Mathewea26bad2016-11-14 12:25:45 +0000357 * Helper function to reset the system via SCMI.
358 */
359void __dead2 css_scp_sys_reboot(void)
360{
Roberto Vargasfc2b4eb2017-07-31 09:45:10 +0100361 css_scp_system_off(SCMI_SYS_PWR_COLD_RESET);
Soby Mathewea26bad2016-11-14 12:25:45 +0000362}
363
Dimitris Papastamosd7a36512018-06-18 13:01:06 +0100364static int scmi_ap_core_init(scmi_channel_t *ch)
365{
366#if PROGRAMMABLE_RESET_ADDRESS
367 uint32_t version;
368 int ret;
369
370 ret = scmi_proto_version(ch, SCMI_AP_CORE_PROTO_ID, &version);
371 if (ret != SCMI_E_SUCCESS) {
372 WARN("SCMI AP core protocol version message failed\n");
373 return -1;
374 }
375
376 if (!is_scmi_version_compatible(SCMI_AP_CORE_PROTO_VER, version)) {
377 WARN("SCMI AP core protocol version 0x%x incompatible with driver version 0x%x\n",
378 version, SCMI_AP_CORE_PROTO_VER);
379 return -1;
380 }
381 INFO("SCMI AP core protocol version 0x%x detected\n", version);
382#endif
383 return 0;
384}
385
Daniel Boulbyf45a4bb2018-09-18 13:26:03 +0100386void __init plat_arm_pwrc_setup(void)
Soby Mathewea26bad2016-11-14 12:25:45 +0000387{
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530388 unsigned int composite_id, idx;
389
390 for (idx = 0; idx < PLAT_ARM_SCMI_CHANNEL_COUNT; idx++) {
Andre Przywara42c5cd22021-10-14 10:36:46 +0100391 INFO("Initializing SCMI driver on channel %d\n", idx);
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530392
393 scmi_channels[idx].info = plat_css_get_scmi_info(idx);
394 scmi_channels[idx].lock = ARM_SCMI_LOCK_GET_INSTANCE;
395 scmi_handles[idx] = scmi_init(&scmi_channels[idx]);
396
397 if (scmi_handles[idx] == NULL) {
398 ERROR("SCMI Initialization failed on channel %d\n", idx);
399 panic();
400 }
401
402 if (scmi_ap_core_init(&scmi_channels[idx]) < 0) {
403 ERROR("SCMI AP core protocol initialization failed\n");
404 panic();
405 }
Dimitris Papastamosd7a36512018-06-18 13:01:06 +0100406 }
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530407
408 composite_id = plat_css_core_pos_to_scmi_dmn_id_map[plat_my_core_pos()];
409 default_scmi_channel_id = GET_SCMI_CHANNEL_ID(composite_id);
Soby Mathewea26bad2016-11-14 12:25:45 +0000410}
411
412/******************************************************************************
413 * This function overrides the default definition for ARM platforms. Initialize
414 * the SCMI driver, query capability via SCMI and modify the PSCI capability
415 * based on that.
416 *****************************************************************************/
Chandni Cherukurie4bf6a02018-11-14 13:43:59 +0530417const plat_psci_ops_t *css_scmi_override_pm_ops(plat_psci_ops_t *ops)
Soby Mathewea26bad2016-11-14 12:25:45 +0000418{
419 uint32_t msg_attr;
420 int ret;
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530421 void *scmi_handle = scmi_handles[default_scmi_channel_id];
Soby Mathewea26bad2016-11-14 12:25:45 +0000422
423 assert(scmi_handle);
424
425 /* Check that power domain POWER_STATE_SET message is supported */
426 ret = scmi_proto_msg_attr(scmi_handle, SCMI_PWR_DMN_PROTO_ID,
427 SCMI_PWR_STATE_SET_MSG, &msg_attr);
428 if (ret != SCMI_E_SUCCESS) {
429 ERROR("Set power state command is not supported by SCMI\n");
430 panic();
431 }
432
433 /*
434 * Don't support PSCI NODE_HW_STATE call if SCMI doesn't support
435 * POWER_STATE_GET message.
436 */
437 ret = scmi_proto_msg_attr(scmi_handle, SCMI_PWR_DMN_PROTO_ID,
438 SCMI_PWR_STATE_GET_MSG, &msg_attr);
439 if (ret != SCMI_E_SUCCESS)
440 ops->get_node_hw_state = NULL;
441
442 /* Check if the SCMI SYSTEM_POWER_STATE_SET message is supported */
443 ret = scmi_proto_msg_attr(scmi_handle, SCMI_SYS_PWR_PROTO_ID,
444 SCMI_SYS_PWR_STATE_SET_MSG, &msg_attr);
445 if (ret != SCMI_E_SUCCESS) {
446 /* System power management operations are not supported */
447 ops->system_off = NULL;
448 ops->system_reset = NULL;
449 ops->get_sys_suspend_power_state = NULL;
Roberto Vargas3caafd72017-08-16 08:57:45 +0100450 } else {
451 if (!(msg_attr & SCMI_SYS_PWR_SUSPEND_SUPPORTED)) {
452 /*
453 * System power management protocol is available, but
454 * it does not support SYSTEM SUSPEND.
455 */
456 ops->get_sys_suspend_power_state = NULL;
457 }
458 if (!(msg_attr & SCMI_SYS_PWR_WARM_RESET_SUPPORTED)) {
459 /*
460 * WARM reset is not available.
461 */
462 ops->system_reset2 = NULL;
463 }
Soby Mathewea26bad2016-11-14 12:25:45 +0000464 }
465
466 return ops;
467}
Roberto Vargas3caafd72017-08-16 08:57:45 +0100468
469int css_system_reset2(int is_vendor, int reset_type, u_register_t cookie)
470{
471 if (is_vendor || (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET))
472 return PSCI_E_INVALID_PARAMS;
473
474 css_scp_system_off(SCMI_SYS_PWR_WARM_RESET);
475 /*
476 * css_scp_system_off cannot return (it is a __dead function),
477 * but css_system_reset2 has to return some value, even in
478 * this case.
479 */
480 return 0;
481}
Dimitris Papastamosd7a36512018-06-18 13:01:06 +0100482
483#if PROGRAMMABLE_RESET_ADDRESS
484void plat_arm_program_trusted_mailbox(uintptr_t address)
485{
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530486 int ret, i;
Dimitris Papastamosd7a36512018-06-18 13:01:06 +0100487
Aditya Angadi7f8837b2019-12-31 14:23:53 +0530488 for (i = 0; i < PLAT_ARM_SCMI_CHANNEL_COUNT; i++) {
489 assert(scmi_handles[i]);
490
491 ret = scmi_ap_core_set_reset_addr(scmi_handles[i], address,
492 SCMI_AP_CORE_LOCK_ATTR);
493 if (ret != SCMI_E_SUCCESS) {
494 ERROR("CSS: Failed to program reset address: %d\n", ret);
495 panic();
496 }
Dimitris Papastamosd7a36512018-06-18 13:01:06 +0100497 }
498}
499#endif