2 * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
7 #include <asm_macros.S>
8 #include <assert_macros.S>
9 #include <platform_def.h>
12 .globl psci_do_pwrdown_cache_maintenance
13 .globl psci_do_pwrup_cache_maintenance
14 .globl psci_power_down_wfi
16 /* -----------------------------------------------------------------------
17 * void psci_do_pwrdown_cache_maintenance(unsigned int power level);
19 * This function performs cache maintenance for the specified power
20 * level. The levels of cache affected are determined by the power
21 * level which is passed as the argument i.e. level 0 results
22 * in a flush of the L1 cache. Both the L1 and L2 caches are flushed
23 * for a higher power level.
25 * Additionally, this function also ensures that stack memory is correctly
26 * flushed out to avoid coherency issues due to a change in its memory
27 * attributes after the data cache is disabled.
28 * -----------------------------------------------------------------------
30 func psci_do_pwrdown_cache_maintenance
31 stp x29, x30, [sp,#-16]!
32 stp x19, x20, [sp,#-16]!
34 /* ---------------------------------------------
35 * Invoke CPU-specific power down operations for
36 * the appropriate level
37 * ---------------------------------------------
39 bl prepare_cpu_pwr_dwn
41 /* ---------------------------------------------
42 * Do stack maintenance by flushing the used
43 * stack to the main memory and invalidating the
45 * ---------------------------------------------
49 /* ---------------------------------------------
50 * Calculate and store the size of the used
52 * ---------------------------------------------
60 /* ---------------------------------------------
61 * Calculate and store the size of the unused
62 * stack memory in x1. Calculate and store the
63 * stack base address in x0.
64 * ---------------------------------------------
66 sub x0, x19, #PLATFORM_STACK_SIZE
70 ldp x19, x20, [sp], #16
71 ldp x29, x30, [sp], #16
73 endfunc psci_do_pwrdown_cache_maintenance
76 /* -----------------------------------------------------------------------
77 * void psci_do_pwrup_cache_maintenance(void);
79 * This function performs cache maintenance after this cpu is powered up.
80 * Currently, this involves managing the used stack memory before turning
82 * -----------------------------------------------------------------------
84 func psci_do_pwrup_cache_maintenance
85 stp x29, x30, [sp,#-16]!
87 /* ---------------------------------------------
88 * Ensure any inflight stack writes have made it
90 * ---------------------------------------------
94 /* ---------------------------------------------
95 * Calculate and store the size of the used
96 * stack memory in x1. Calculate and store the
97 * stack base address in x0.
98 * ---------------------------------------------
106 /* ---------------------------------------------
107 * Enable the data cache.
108 * ---------------------------------------------
111 orr x0, x0, #SCTLR_C_BIT
115 ldp x29, x30, [sp], #16
117 endfunc psci_do_pwrup_cache_maintenance
119 /* -----------------------------------------------------------------------
120 * void psci_power_down_wfi(void);
121 * This function is called to indicate to the power controller that it
122 * is safe to power down this cpu. It should not exit the wfi and will
123 * be released from reset upon power up.
124 * -----------------------------------------------------------------------
126 func psci_power_down_wfi
127 dsb sy // ensure write buffer empty
129 no_ret plat_panic_handler
130 endfunc psci_power_down_wfi