blob: 19f24765d0ba59778ba16a5b45d3ee6ceb0ed245 [file] [log] [blame]
Juan Castillod5f13092014-08-12 11:17:06 +01001/*
Boyan Karatotev5d893412025-01-07 11:00:03 +00002 * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved.
Juan Castillod5f13092014-08-12 11:17:06 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillod5f13092014-08-12 11:17:06 +01005 */
6
Soby Mathewb234b2c2015-01-15 11:49:49 +00007#include <assert.h>
Isla Mitchell2a4b4b72017-07-11 14:54:08 +01008#include <stddef.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
11#include <common/debug.h>
Boyan Karatotev5d893412025-01-07 11:00:03 +000012#include <drivers/arm/gic.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000013#include <drivers/console.h>
14#include <plat/common/platform.h>
15
Juan Castillod5f13092014-08-12 11:17:06 +010016#include "psci_private.h"
17
Etienne Carriereaa8d5f82017-06-07 16:42:42 +020018void __dead2 psci_system_off(void)
Juan Castillod5f13092014-08-12 11:17:06 +010019{
Soby Mathew67487842015-07-13 14:10:57 +010020 psci_print_power_domain_map();
Juan Castillod5f13092014-08-12 11:17:06 +010021
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010022 assert(psci_plat_pm_ops->system_off != NULL);
Soby Mathewb234b2c2015-01-15 11:49:49 +000023
Juan Castillod5f13092014-08-12 11:17:06 +010024 /* Notify the Secure Payload Dispatcher */
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010025 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_off != NULL)) {
Juan Castillod5f13092014-08-12 11:17:06 +010026 psci_spd_pm->svc_system_off();
27 }
28
Jimmy Brisson831b0e92020-08-05 13:44:05 -050029 console_flush();
Antonio Nino Diaz0b326282017-02-16 16:17:19 +000030
Boyan Karatotev5d893412025-01-07 11:00:03 +000031#if USE_GIC_DRIVER
32 /* turn the GIC off before we hand off to the platform */
33 gic_cpuif_disable(plat_my_core_pos());
34#endif /* USE_GIC_DRIVER */
35
Juan Castillod5f13092014-08-12 11:17:06 +010036 /* Call the platform specific hook */
37 psci_plat_pm_ops->system_off();
38
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +000039 psci_pwrdown_cpu_end_terminal();
Juan Castillod5f13092014-08-12 11:17:06 +010040}
41
Etienne Carriereaa8d5f82017-06-07 16:42:42 +020042void __dead2 psci_system_reset(void)
Juan Castillod5f13092014-08-12 11:17:06 +010043{
Soby Mathew67487842015-07-13 14:10:57 +010044 psci_print_power_domain_map();
Juan Castillod5f13092014-08-12 11:17:06 +010045
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010046 assert(psci_plat_pm_ops->system_reset != NULL);
Soby Mathewb234b2c2015-01-15 11:49:49 +000047
Juan Castillod5f13092014-08-12 11:17:06 +010048 /* Notify the Secure Payload Dispatcher */
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010049 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
Juan Castillod5f13092014-08-12 11:17:06 +010050 psci_spd_pm->svc_system_reset();
51 }
52
Jimmy Brisson831b0e92020-08-05 13:44:05 -050053 console_flush();
Antonio Nino Diaz0b326282017-02-16 16:17:19 +000054
Boyan Karatotev5d893412025-01-07 11:00:03 +000055#if USE_GIC_DRIVER
56 /* turn the GIC off before we hand off to the platform */
57 gic_cpuif_disable(plat_my_core_pos());
58#endif /* USE_GIC_DRIVER */
59
Juan Castillod5f13092014-08-12 11:17:06 +010060 /* Call the platform specific hook */
61 psci_plat_pm_ops->system_reset();
62
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +000063 psci_pwrdown_cpu_end_terminal();
Juan Castillod5f13092014-08-12 11:17:06 +010064}
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010065
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010066u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie)
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010067{
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010068 unsigned int is_vendor;
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010069
70 psci_print_power_domain_map();
71
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010072 assert(psci_plat_pm_ops->system_reset2 != NULL);
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010073
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010074 is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U;
75 if (is_vendor == 0U) {
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010076 /*
77 * Only WARM_RESET is allowed for architectural type resets.
78 */
Maheedhar Bollapallic7b0a282024-04-25 11:47:27 +053079 if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET) {
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010080 return (u_register_t) PSCI_E_INVALID_PARAMS;
Maheedhar Bollapallic7b0a282024-04-25 11:47:27 +053081 }
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010082 if ((psci_plat_pm_ops->write_mem_protect != NULL) &&
83 (psci_plat_pm_ops->write_mem_protect(0) < 0)) {
84 return (u_register_t) PSCI_E_NOT_SUPPORTED;
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010085 }
86 }
87
88 /* Notify the Secure Payload Dispatcher */
Antonio Nino Diaz621d64f2018-07-16 23:19:25 +010089 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010090 psci_spd_pm->svc_system_reset();
91 }
Jimmy Brisson831b0e92020-08-05 13:44:05 -050092 console_flush();
Roberto Vargas36a8f8f2017-07-26 09:23:09 +010093
Boyan Karatotev5d893412025-01-07 11:00:03 +000094#if USE_GIC_DRIVER
95 /* turn the GIC off before we hand off to the platform */
96 gic_cpuif_disable(plat_my_core_pos());
97#endif /* USE_GIC_DRIVER */
98
Boyan Karatotev2b5e00d2024-12-19 16:07:29 +000099 u_register_t ret =
100 (u_register_t) psci_plat_pm_ops->system_reset2((int) is_vendor, reset_type, cookie);
101 if (ret != PSCI_E_SUCCESS)
102 return ret;
103
104 psci_pwrdown_cpu_end_terminal();
Roberto Vargas36a8f8f2017-07-26 09:23:09 +0100105}