blob: 19f24765d0ba59778ba16a5b45d3ee6ceb0ed245 [file] [log] [blame]
Juan Castillo4dc4a472014-08-12 11:17:06 +01001/*
Boyan Karatotev9bc65742025-01-07 11:00:03 +00002 * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved.
Juan Castillo4dc4a472014-08-12 11:17:06 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castillo4dc4a472014-08-12 11:17:06 +01005 */
6
Soby Mathew61e615b2015-01-15 11:49:49 +00007#include <assert.h>
Isla Mitchell99305012017-07-11 14:54:08 +01008#include <stddef.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00009
10#include <arch_helpers.h>
11#include <common/debug.h>
Boyan Karatotev9bc65742025-01-07 11:00:03 +000012#include <drivers/arm/gic.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <drivers/console.h>
14#include <plat/common/platform.h>
15
Juan Castillo4dc4a472014-08-12 11:17:06 +010016#include "psci_private.h"
17
Etienne Carriere3fdf5f32017-06-07 16:42:42 +020018void __dead2 psci_system_off(void)
Juan Castillo4dc4a472014-08-12 11:17:06 +010019{
Soby Mathew981487a2015-07-13 14:10:57 +010020 psci_print_power_domain_map();
Juan Castillo4dc4a472014-08-12 11:17:06 +010021
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010022 assert(psci_plat_pm_ops->system_off != NULL);
Soby Mathew61e615b2015-01-15 11:49:49 +000023
Juan Castillo4dc4a472014-08-12 11:17:06 +010024 /* Notify the Secure Payload Dispatcher */
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010025 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_off != NULL)) {
Juan Castillo4dc4a472014-08-12 11:17:06 +010026 psci_spd_pm->svc_system_off();
27 }
28
Jimmy Brisson39f9eee2020-08-05 13:44:05 -050029 console_flush();
Antonio Nino Diaze3962d02017-02-16 16:17:19 +000030
Boyan Karatotev9bc65742025-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 Castillo4dc4a472014-08-12 11:17:06 +010036 /* Call the platform specific hook */
37 psci_plat_pm_ops->system_off();
38
Boyan Karatotev7262eff2024-12-19 16:07:29 +000039 psci_pwrdown_cpu_end_terminal();
Juan Castillo4dc4a472014-08-12 11:17:06 +010040}
41
Etienne Carriere3fdf5f32017-06-07 16:42:42 +020042void __dead2 psci_system_reset(void)
Juan Castillo4dc4a472014-08-12 11:17:06 +010043{
Soby Mathew981487a2015-07-13 14:10:57 +010044 psci_print_power_domain_map();
Juan Castillo4dc4a472014-08-12 11:17:06 +010045
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010046 assert(psci_plat_pm_ops->system_reset != NULL);
Soby Mathew61e615b2015-01-15 11:49:49 +000047
Juan Castillo4dc4a472014-08-12 11:17:06 +010048 /* Notify the Secure Payload Dispatcher */
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010049 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
Juan Castillo4dc4a472014-08-12 11:17:06 +010050 psci_spd_pm->svc_system_reset();
51 }
52
Jimmy Brisson39f9eee2020-08-05 13:44:05 -050053 console_flush();
Antonio Nino Diaze3962d02017-02-16 16:17:19 +000054
Boyan Karatotev9bc65742025-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 Castillo4dc4a472014-08-12 11:17:06 +010060 /* Call the platform specific hook */
61 psci_plat_pm_ops->system_reset();
62
Boyan Karatotev7262eff2024-12-19 16:07:29 +000063 psci_pwrdown_cpu_end_terminal();
Juan Castillo4dc4a472014-08-12 11:17:06 +010064}
Roberto Vargasb820ad02017-07-26 09:23:09 +010065
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010066u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie)
Roberto Vargasb820ad02017-07-26 09:23:09 +010067{
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010068 unsigned int is_vendor;
Roberto Vargasb820ad02017-07-26 09:23:09 +010069
70 psci_print_power_domain_map();
71
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010072 assert(psci_plat_pm_ops->system_reset2 != NULL);
Roberto Vargasb820ad02017-07-26 09:23:09 +010073
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010074 is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U;
75 if (is_vendor == 0U) {
Roberto Vargasb820ad02017-07-26 09:23:09 +010076 /*
77 * Only WARM_RESET is allowed for architectural type resets.
78 */
Maheedhar Bollapallidfe13fb2024-04-25 11:47:27 +053079 if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET) {
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010080 return (u_register_t) PSCI_E_INVALID_PARAMS;
Maheedhar Bollapallidfe13fb2024-04-25 11:47:27 +053081 }
Antonio Nino Diaz56a0e8e2018-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 Vargasb820ad02017-07-26 09:23:09 +010085 }
86 }
87
88 /* Notify the Secure Payload Dispatcher */
Antonio Nino Diaz56a0e8e2018-07-16 23:19:25 +010089 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
Roberto Vargasb820ad02017-07-26 09:23:09 +010090 psci_spd_pm->svc_system_reset();
91 }
Jimmy Brisson39f9eee2020-08-05 13:44:05 -050092 console_flush();
Roberto Vargasb820ad02017-07-26 09:23:09 +010093
Boyan Karatotev9bc65742025-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 Karatotev7262eff2024-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 Vargasb820ad02017-07-26 09:23:09 +0100105}