xref: /rk3399_ARM-atf/lib/psci/psci_system_off.c (revision 36a8f8fd471ae7c6dc8a810aaa8ff8734706234e)
1532ed618SSoby Mathew /*
20b32628eSAntonio Nino Diaz  * Copyright (c) 2014-2017, ARM Limited and Contributors. All rights reserved.
3532ed618SSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5532ed618SSoby Mathew  */
6532ed618SSoby Mathew 
7532ed618SSoby Mathew #include <arch_helpers.h>
8532ed618SSoby Mathew #include <assert.h>
90b32628eSAntonio Nino Diaz #include <console.h>
10532ed618SSoby Mathew #include <debug.h>
11532ed618SSoby Mathew #include <platform.h>
122a4b4b71SIsla Mitchell #include <stddef.h>
13532ed618SSoby Mathew #include "psci_private.h"
14532ed618SSoby Mathew 
15aa8d5f88SEtienne Carriere void __dead2 psci_system_off(void)
16532ed618SSoby Mathew {
17532ed618SSoby Mathew 	psci_print_power_domain_map();
18532ed618SSoby Mathew 
19532ed618SSoby Mathew 	assert(psci_plat_pm_ops->system_off);
20532ed618SSoby Mathew 
21532ed618SSoby Mathew 	/* Notify the Secure Payload Dispatcher */
22532ed618SSoby Mathew 	if (psci_spd_pm && psci_spd_pm->svc_system_off) {
23532ed618SSoby Mathew 		psci_spd_pm->svc_system_off();
24532ed618SSoby Mathew 	}
25532ed618SSoby Mathew 
260b32628eSAntonio Nino Diaz 	console_flush();
270b32628eSAntonio Nino Diaz 
28532ed618SSoby Mathew 	/* Call the platform specific hook */
29532ed618SSoby Mathew 	psci_plat_pm_ops->system_off();
30532ed618SSoby Mathew 
31532ed618SSoby Mathew 	/* This function does not return. We should never get here */
32532ed618SSoby Mathew }
33532ed618SSoby Mathew 
34aa8d5f88SEtienne Carriere void __dead2 psci_system_reset(void)
35532ed618SSoby Mathew {
36532ed618SSoby Mathew 	psci_print_power_domain_map();
37532ed618SSoby Mathew 
38532ed618SSoby Mathew 	assert(psci_plat_pm_ops->system_reset);
39532ed618SSoby Mathew 
40532ed618SSoby Mathew 	/* Notify the Secure Payload Dispatcher */
41532ed618SSoby Mathew 	if (psci_spd_pm && psci_spd_pm->svc_system_reset) {
42532ed618SSoby Mathew 		psci_spd_pm->svc_system_reset();
43532ed618SSoby Mathew 	}
44532ed618SSoby Mathew 
450b32628eSAntonio Nino Diaz 	console_flush();
460b32628eSAntonio Nino Diaz 
47532ed618SSoby Mathew 	/* Call the platform specific hook */
48532ed618SSoby Mathew 	psci_plat_pm_ops->system_reset();
49532ed618SSoby Mathew 
50532ed618SSoby Mathew 	/* This function does not return. We should never get here */
51532ed618SSoby Mathew }
52*36a8f8fdSRoberto Vargas 
53*36a8f8fdSRoberto Vargas int psci_system_reset2(uint32_t reset_type, u_register_t cookie)
54*36a8f8fdSRoberto Vargas {
55*36a8f8fdSRoberto Vargas 	int is_vendor;
56*36a8f8fdSRoberto Vargas 
57*36a8f8fdSRoberto Vargas 	psci_print_power_domain_map();
58*36a8f8fdSRoberto Vargas 
59*36a8f8fdSRoberto Vargas 	assert(psci_plat_pm_ops->system_reset2);
60*36a8f8fdSRoberto Vargas 
61*36a8f8fdSRoberto Vargas 	is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1;
62*36a8f8fdSRoberto Vargas 	if (!is_vendor) {
63*36a8f8fdSRoberto Vargas 		/*
64*36a8f8fdSRoberto Vargas 		 * Only WARM_RESET is allowed for architectural type resets.
65*36a8f8fdSRoberto Vargas 		 */
66*36a8f8fdSRoberto Vargas 		if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET)
67*36a8f8fdSRoberto Vargas 			return PSCI_E_INVALID_PARAMS;
68*36a8f8fdSRoberto Vargas 		if (psci_plat_pm_ops->write_mem_protect &&
69*36a8f8fdSRoberto Vargas 		    psci_plat_pm_ops->write_mem_protect(0) < 0) {
70*36a8f8fdSRoberto Vargas 			return PSCI_E_NOT_SUPPORTED;
71*36a8f8fdSRoberto Vargas 		}
72*36a8f8fdSRoberto Vargas 	}
73*36a8f8fdSRoberto Vargas 
74*36a8f8fdSRoberto Vargas 	/* Notify the Secure Payload Dispatcher */
75*36a8f8fdSRoberto Vargas 	if (psci_spd_pm && psci_spd_pm->svc_system_reset) {
76*36a8f8fdSRoberto Vargas 		psci_spd_pm->svc_system_reset();
77*36a8f8fdSRoberto Vargas 	}
78*36a8f8fdSRoberto Vargas 	console_flush();
79*36a8f8fdSRoberto Vargas 
80*36a8f8fdSRoberto Vargas 	return psci_plat_pm_ops->system_reset2(is_vendor, reset_type, cookie);
81*36a8f8fdSRoberto Vargas }
82