xref: /rk3399_ARM-atf/lib/psci/psci_system_off.c (revision 09d40e0e08283a249e7dce0e106c07c5141f9b7e)
1532ed618SSoby Mathew /*
2621d64f8SAntonio Nino Diaz  * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
3532ed618SSoby Mathew  *
482cb2c1aSdp-arm  * SPDX-License-Identifier: BSD-3-Clause
5532ed618SSoby Mathew  */
6532ed618SSoby Mathew 
7532ed618SSoby Mathew #include <assert.h>
82a4b4b71SIsla Mitchell #include <stddef.h>
9*09d40e0eSAntonio Nino Diaz 
10*09d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
11*09d40e0eSAntonio Nino Diaz #include <common/debug.h>
12*09d40e0eSAntonio Nino Diaz #include <drivers/console.h>
13*09d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
14*09d40e0eSAntonio Nino Diaz 
15532ed618SSoby Mathew #include "psci_private.h"
16532ed618SSoby Mathew 
17aa8d5f88SEtienne Carriere void __dead2 psci_system_off(void)
18532ed618SSoby Mathew {
19532ed618SSoby Mathew 	psci_print_power_domain_map();
20532ed618SSoby Mathew 
21621d64f8SAntonio Nino Diaz 	assert(psci_plat_pm_ops->system_off != NULL);
22532ed618SSoby Mathew 
23532ed618SSoby Mathew 	/* Notify the Secure Payload Dispatcher */
24621d64f8SAntonio Nino Diaz 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_off != NULL)) {
25532ed618SSoby Mathew 		psci_spd_pm->svc_system_off();
26532ed618SSoby Mathew 	}
27532ed618SSoby Mathew 
28621d64f8SAntonio Nino Diaz 	(void) console_flush();
290b32628eSAntonio Nino Diaz 
30532ed618SSoby Mathew 	/* Call the platform specific hook */
31532ed618SSoby Mathew 	psci_plat_pm_ops->system_off();
32532ed618SSoby Mathew 
33532ed618SSoby Mathew 	/* This function does not return. We should never get here */
34532ed618SSoby Mathew }
35532ed618SSoby Mathew 
36aa8d5f88SEtienne Carriere void __dead2 psci_system_reset(void)
37532ed618SSoby Mathew {
38532ed618SSoby Mathew 	psci_print_power_domain_map();
39532ed618SSoby Mathew 
40621d64f8SAntonio Nino Diaz 	assert(psci_plat_pm_ops->system_reset != NULL);
41532ed618SSoby Mathew 
42532ed618SSoby Mathew 	/* Notify the Secure Payload Dispatcher */
43621d64f8SAntonio Nino Diaz 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
44532ed618SSoby Mathew 		psci_spd_pm->svc_system_reset();
45532ed618SSoby Mathew 	}
46532ed618SSoby Mathew 
47621d64f8SAntonio Nino Diaz 	(void) console_flush();
480b32628eSAntonio Nino Diaz 
49532ed618SSoby Mathew 	/* Call the platform specific hook */
50532ed618SSoby Mathew 	psci_plat_pm_ops->system_reset();
51532ed618SSoby Mathew 
52532ed618SSoby Mathew 	/* This function does not return. We should never get here */
53532ed618SSoby Mathew }
5436a8f8fdSRoberto Vargas 
55621d64f8SAntonio Nino Diaz u_register_t psci_system_reset2(uint32_t reset_type, u_register_t cookie)
5636a8f8fdSRoberto Vargas {
57621d64f8SAntonio Nino Diaz 	unsigned int is_vendor;
5836a8f8fdSRoberto Vargas 
5936a8f8fdSRoberto Vargas 	psci_print_power_domain_map();
6036a8f8fdSRoberto Vargas 
61621d64f8SAntonio Nino Diaz 	assert(psci_plat_pm_ops->system_reset2 != NULL);
6236a8f8fdSRoberto Vargas 
63621d64f8SAntonio Nino Diaz 	is_vendor = (reset_type >> PSCI_RESET2_TYPE_VENDOR_SHIFT) & 1U;
64621d64f8SAntonio Nino Diaz 	if (is_vendor == 0U) {
6536a8f8fdSRoberto Vargas 		/*
6636a8f8fdSRoberto Vargas 		 * Only WARM_RESET is allowed for architectural type resets.
6736a8f8fdSRoberto Vargas 		 */
6836a8f8fdSRoberto Vargas 		if (reset_type != PSCI_RESET2_SYSTEM_WARM_RESET)
69621d64f8SAntonio Nino Diaz 			return (u_register_t) PSCI_E_INVALID_PARAMS;
70621d64f8SAntonio Nino Diaz 		if ((psci_plat_pm_ops->write_mem_protect != NULL) &&
71621d64f8SAntonio Nino Diaz 		    (psci_plat_pm_ops->write_mem_protect(0) < 0)) {
72621d64f8SAntonio Nino Diaz 			return (u_register_t) PSCI_E_NOT_SUPPORTED;
7336a8f8fdSRoberto Vargas 		}
7436a8f8fdSRoberto Vargas 	}
7536a8f8fdSRoberto Vargas 
7636a8f8fdSRoberto Vargas 	/* Notify the Secure Payload Dispatcher */
77621d64f8SAntonio Nino Diaz 	if ((psci_spd_pm != NULL) && (psci_spd_pm->svc_system_reset != NULL)) {
7836a8f8fdSRoberto Vargas 		psci_spd_pm->svc_system_reset();
7936a8f8fdSRoberto Vargas 	}
80621d64f8SAntonio Nino Diaz 	(void) console_flush();
8136a8f8fdSRoberto Vargas 
82621d64f8SAntonio Nino Diaz 	return (u_register_t)
83621d64f8SAntonio Nino Diaz 		psci_plat_pm_ops->system_reset2((int) is_vendor, reset_type,
84621d64f8SAntonio Nino Diaz 						cookie);
8536a8f8fdSRoberto Vargas }
86