xref: /rk3399_ARM-atf/lib/psci/psci_system_off.c (revision 621d64f89b865aeb1cc3bb3b0f49bd2aec79efdb)
1 /*
2  * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch_helpers.h>
8 #include <assert.h>
9 #include <console.h>
10 #include <debug.h>
11 #include <platform.h>
12 #include <stddef.h>
13 #include "psci_private.h"
14 
15 void __dead2 psci_system_off(void)
16 {
17 	psci_print_power_domain_map();
18 
19 	assert(psci_plat_pm_ops->system_off != NULL);
20 
21 	/* Notify the Secure Payload Dispatcher */
22 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_off != NULL)) {
23 		psci_spd_pm->svc_system_off();
24 	}
25 
26 	(void) console_flush();
27 
28 	/* Call the platform specific hook */
29 	psci_plat_pm_ops->system_off();
30 
31 	/* This function does not return. We should never get here */
32 }
33 
34 void __dead2 psci_system_reset(void)
35 {
36 	psci_print_power_domain_map();
37 
38 	assert(psci_plat_pm_ops->system_reset != NULL);
39 
40 	/* Notify the Secure Payload Dispatcher */
41 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
42 		psci_spd_pm->svc_system_reset();
43 	}
44 
45 	(void) console_flush();
46 
47 	/* Call the platform specific hook */
48 	psci_plat_pm_ops->system_reset();
49 
50 	/* This function does not return. We should never get here */
51 }
52 
53 u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie)
54 {
55 	unsigned int is_vendor;
56 
57 	psci_print_power_domain_map();
58 
59 	assert(psci_plat_pm_ops->system_reset2 != NULL);
60 
61 	is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U;
62 	if (is_vendor == 0U) {
63 		/*
64 		 * Only WARM_RESET is allowed for architectural type resets.
65 		 */
66 		if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET)
67 			return (u_register_t) PSCI_E_INVALID_PARAMS;
68 		if ((psci_plat_pm_ops->write_mem_protect != NULL) &&
69 		    (psci_plat_pm_ops->write_mem_protect(0) < 0)) {
70 			return (u_register_t) PSCI_E_NOT_SUPPORTED;
71 		}
72 	}
73 
74 	/* Notify the Secure Payload Dispatcher */
75 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
76 		psci_spd_pm->svc_system_reset();
77 	}
78 	(void) console_flush();
79 
80 	return (u_register_t)
81 		psci_plat_pm_ops->system_reset2((int) is_vendor, reset_type,
82 						cookie);
83 }
84