1 /* 2 * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <assert.h> 8 #include <stddef.h> 9 10 #include <arch_helpers.h> 11 #include <common/debug.h> 12 #include <drivers/arm/gic.h> 13 #include <drivers/console.h> 14 #include <plat/common/platform.h> 15 16 #include "psci_private.h" 17 psci_system_off(void)18void __dead2 psci_system_off(void) 19 { 20 psci_print_power_domain_map(); 21 22 assert(psci_plat_pm_ops->system_off != NULL); 23 24 /* Notify the Secure Payload Dispatcher */ 25 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_off != NULL)) { 26 psci_spd_pm->svc_system_off(); 27 } 28 29 console_flush(); 30 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 36 /* Call the platform specific hook */ 37 psci_plat_pm_ops->system_off(); 38 39 psci_pwrdown_cpu_end_terminal(); 40 } 41 psci_system_reset(void)42void __dead2 psci_system_reset(void) 43 { 44 psci_print_power_domain_map(); 45 46 assert(psci_plat_pm_ops->system_reset != NULL); 47 48 /* Notify the Secure Payload Dispatcher */ 49 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) { 50 psci_spd_pm->svc_system_reset(); 51 } 52 53 console_flush(); 54 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 60 /* Call the platform specific hook */ 61 psci_plat_pm_ops->system_reset(); 62 63 psci_pwrdown_cpu_end_terminal(); 64 } 65 psci_system_reset2(uint32_t reset_type,u_register_t cookie)66u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie) 67 { 68 unsigned int is_vendor; 69 70 psci_print_power_domain_map(); 71 72 assert(psci_plat_pm_ops->system_reset2 != NULL); 73 74 is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U; 75 if (is_vendor == 0U) { 76 /* 77 * Only WARM_RESET is allowed for architectural type resets. 78 */ 79 if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET) { 80 return (u_register_t) PSCI_E_INVALID_PARAMS; 81 } 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; 85 } 86 } 87 88 /* Notify the Secure Payload Dispatcher */ 89 if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) { 90 psci_spd_pm->svc_system_reset(); 91 } 92 console_flush(); 93 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 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(); 105 } 106