Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 2 | * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved. |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Soby Mathew | b234b2c | 2015-01-15 11:49:49 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Isla Mitchell | 2a4b4b7 | 2017-07-11 14:54:08 +0100 | [diff] [blame] | 8 | #include <stddef.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | |
| 10 | #include <arch_helpers.h> |
| 11 | #include <common/debug.h> |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 12 | #include <drivers/arm/gic.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | #include <drivers/console.h> |
| 14 | #include <plat/common/platform.h> |
| 15 | |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 16 | #include "psci_private.h" |
| 17 | |
Etienne Carriere | aa8d5f8 | 2017-06-07 16:42:42 +0200 | [diff] [blame] | 18 | void __dead2 psci_system_off(void) |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 19 | { |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 20 | psci_print_power_domain_map(); |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 21 | |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 22 | assert(psci_plat_pm_ops->system_off != NULL); |
Soby Mathew | b234b2c | 2015-01-15 11:49:49 +0000 | [diff] [blame] | 23 | |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 24 | /* Notify the Secure Payload Dispatcher */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 25 | if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_off != NULL)) { |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 26 | psci_spd_pm->svc_system_off(); |
| 27 | } |
| 28 | |
Jimmy Brisson | 831b0e9 | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 29 | console_flush(); |
Antonio Nino Diaz | 0b32628 | 2017-02-16 16:17:19 +0000 | [diff] [blame] | 30 | |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 31 | #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 Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 36 | /* Call the platform specific hook */ |
| 37 | psci_plat_pm_ops->system_off(); |
| 38 | |
Boyan Karatotev | 2b5e00d | 2024-12-19 16:07:29 +0000 | [diff] [blame] | 39 | psci_pwrdown_cpu_end_terminal(); |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Etienne Carriere | aa8d5f8 | 2017-06-07 16:42:42 +0200 | [diff] [blame] | 42 | void __dead2 psci_system_reset(void) |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 43 | { |
Soby Mathew | 6748784 | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 44 | psci_print_power_domain_map(); |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 45 | |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 46 | assert(psci_plat_pm_ops->system_reset != NULL); |
Soby Mathew | b234b2c | 2015-01-15 11:49:49 +0000 | [diff] [blame] | 47 | |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 48 | /* Notify the Secure Payload Dispatcher */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 49 | if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) { |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 50 | psci_spd_pm->svc_system_reset(); |
| 51 | } |
| 52 | |
Jimmy Brisson | 831b0e9 | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 53 | console_flush(); |
Antonio Nino Diaz | 0b32628 | 2017-02-16 16:17:19 +0000 | [diff] [blame] | 54 | |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 55 | #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 Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 60 | /* Call the platform specific hook */ |
| 61 | psci_plat_pm_ops->system_reset(); |
| 62 | |
Boyan Karatotev | 2b5e00d | 2024-12-19 16:07:29 +0000 | [diff] [blame] | 63 | psci_pwrdown_cpu_end_terminal(); |
Juan Castillo | d5f1309 | 2014-08-12 11:17:06 +0100 | [diff] [blame] | 64 | } |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 65 | |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 66 | u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie) |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 67 | { |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 68 | unsigned int is_vendor; |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 69 | |
| 70 | psci_print_power_domain_map(); |
| 71 | |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 72 | assert(psci_plat_pm_ops->system_reset2 != NULL); |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 73 | |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 74 | is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U; |
| 75 | if (is_vendor == 0U) { |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 76 | /* |
| 77 | * Only WARM_RESET is allowed for architectural type resets. |
| 78 | */ |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 79 | if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET) { |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 80 | return (u_register_t) PSCI_E_INVALID_PARAMS; |
Maheedhar Bollapalli | c7b0a28 | 2024-04-25 11:47:27 +0530 | [diff] [blame] | 81 | } |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 82 | 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 Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 85 | } |
| 86 | } |
| 87 | |
| 88 | /* Notify the Secure Payload Dispatcher */ |
Antonio Nino Diaz | 621d64f | 2018-07-16 23:19:25 +0100 | [diff] [blame] | 89 | if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) { |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 90 | psci_spd_pm->svc_system_reset(); |
| 91 | } |
Jimmy Brisson | 831b0e9 | 2020-08-05 13:44:05 -0500 | [diff] [blame] | 92 | console_flush(); |
Roberto Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 93 | |
Boyan Karatotev | 5d89341 | 2025-01-07 11:00:03 +0000 | [diff] [blame] | 94 | #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 Karatotev | 2b5e00d | 2024-12-19 16:07:29 +0000 | [diff] [blame] | 99 | 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 Vargas | 36a8f8f | 2017-07-26 09:23:09 +0100 | [diff] [blame] | 105 | } |