xref: /rk3399_ARM-atf/lib/psci/psci_system_off.c (revision 6729b30a48ac4be8eb35db86b533c8a8e06fa8cc)
1 /*
2  * Copyright (c) 2014-2026, 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 
system_power_down(void)18 static void __dead2 system_power_down(void)
19 {
20 	/*
21 	 * Turn the GIC off after the platform has had powered other cores off
22 	 * but before caching has been disabled as part of powerdown prep.
23 	 */
24 #if USE_GIC_DRIVER
25 	unsigned int core_pos = plat_my_core_pos();
26 	gic_cpuif_disable(core_pos);
27 	gic_pcpu_off(core_pos);
28 #endif /* USE_GIC_DRIVER */
29 
30 	psci_pwrdown_cpu_start((unsigned int)PLAT_MAX_PWR_LVL);
31 	psci_pwrdown_cpu_end_terminal();
32 }
33 
psci_system_off(void)34 void __dead2 psci_system_off(void)
35 {
36 	psci_print_power_domain_map();
37 
38 	assert(psci_plat_pm_ops->system_off != NULL);
39 
40 	/* Notify the Secure Payload Dispatcher */
41 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_off != NULL)) {
42 		psci_spd_pm->svc_system_off();
43 	}
44 
45 	console_flush();
46 
47 	/* Call the platform specific hook */
48 	psci_plat_pm_ops->system_off();
49 
50 	system_power_down();
51 }
52 
psci_system_reset(void)53 void __dead2 psci_system_reset(void)
54 {
55 	psci_print_power_domain_map();
56 
57 	assert(psci_plat_pm_ops->system_reset != NULL);
58 
59 	/* Notify the Secure Payload Dispatcher */
60 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
61 		psci_spd_pm->svc_system_reset();
62 	}
63 
64 	console_flush();
65 
66 	/* Call the platform specific hook */
67 	psci_plat_pm_ops->system_reset();
68 
69 	system_power_down();
70 }
71 
psci_system_reset2(uint32_t reset_type,u_register_t cookie)72 u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie)
73 {
74 	unsigned int is_vendor;
75 	int ret;
76 
77 	psci_print_power_domain_map();
78 
79 	assert(psci_plat_pm_ops->system_reset2 != NULL);
80 
81 	is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U;
82 	if (is_vendor == 0U) {
83 		/*
84 		 * Only WARM_RESET is allowed for architectural type resets.
85 		 */
86 		if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET) {
87 			return (u_register_t) PSCI_E_INVALID_PARAMS;
88 		}
89 		if ((psci_plat_pm_ops->write_mem_protect != NULL) &&
90 		    (psci_plat_pm_ops->write_mem_protect(0) < 0)) {
91 			return (u_register_t) PSCI_E_NOT_SUPPORTED;
92 		}
93 	}
94 
95 	/* Notify the Secure Payload Dispatcher */
96 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
97 		psci_spd_pm->svc_system_reset();
98 	}
99 	console_flush();
100 
101 	ret = psci_plat_pm_ops->system_reset2((int) is_vendor, reset_type, cookie);
102 	if (ret != PSCI_E_SUCCESS) {
103 		return (u_register_t) ret;
104 	}
105 
106 	system_power_down();
107 }
108