xref: /rk3399_ARM-atf/lib/psci/psci_system_off.c (revision f5cb144df1d96c9adf45fbf2376b4068d16d8701)
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 
18 void __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 
42 void __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 
66 u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie)
67 {
68 	unsigned int is_vendor;
69 	int ret;
70 
71 	psci_print_power_domain_map();
72 
73 	assert(psci_plat_pm_ops->system_reset2 != NULL);
74 
75 	is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U;
76 	if (is_vendor == 0U) {
77 		/*
78 		 * Only WARM_RESET is allowed for architectural type resets.
79 		 */
80 		if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET) {
81 			return (u_register_t) PSCI_E_INVALID_PARAMS;
82 		}
83 		if ((psci_plat_pm_ops->write_mem_protect != NULL) &&
84 		    (psci_plat_pm_ops->write_mem_protect(0) < 0)) {
85 			return (u_register_t) PSCI_E_NOT_SUPPORTED;
86 		}
87 	}
88 
89 	/* Notify the Secure Payload Dispatcher */
90 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
91 		psci_spd_pm->svc_system_reset();
92 	}
93 	console_flush();
94 
95 #if USE_GIC_DRIVER
96 	/* turn the GIC off before we hand off to the platform */
97 	gic_cpuif_disable(plat_my_core_pos());
98 #endif /* USE_GIC_DRIVER */
99 
100 	ret = psci_plat_pm_ops->system_reset2((int) is_vendor, reset_type, cookie);
101 	if (ret != PSCI_E_SUCCESS) {
102 		return (u_register_t) ret;
103 	}
104 
105 	psci_pwrdown_cpu_end_terminal();
106 }
107