xref: /rk3399_ARM-atf/lib/psci/aarch64/psci_helpers.S (revision cf0b1492ede6cbbf788144a56d276d8d7924500a)
1532ed618SSoby Mathew/*
2532ed618SSoby Mathew * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved.
3532ed618SSoby Mathew *
4532ed618SSoby Mathew * Redistribution and use in source and binary forms, with or without
5532ed618SSoby Mathew * modification, are permitted provided that the following conditions are met:
6532ed618SSoby Mathew *
7532ed618SSoby Mathew * Redistributions of source code must retain the above copyright notice, this
8532ed618SSoby Mathew * list of conditions and the following disclaimer.
9532ed618SSoby Mathew *
10532ed618SSoby Mathew * Redistributions in binary form must reproduce the above copyright notice,
11532ed618SSoby Mathew * this list of conditions and the following disclaimer in the documentation
12532ed618SSoby Mathew * and/or other materials provided with the distribution.
13532ed618SSoby Mathew *
14532ed618SSoby Mathew * Neither the name of ARM nor the names of its contributors may be used
15532ed618SSoby Mathew * to endorse or promote products derived from this software without specific
16532ed618SSoby Mathew * prior written permission.
17532ed618SSoby Mathew *
18532ed618SSoby Mathew * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19532ed618SSoby Mathew * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20532ed618SSoby Mathew * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21532ed618SSoby Mathew * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22532ed618SSoby Mathew * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23532ed618SSoby Mathew * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24532ed618SSoby Mathew * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25532ed618SSoby Mathew * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26532ed618SSoby Mathew * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27532ed618SSoby Mathew * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28532ed618SSoby Mathew * POSSIBILITY OF SUCH DAMAGE.
29532ed618SSoby Mathew */
30532ed618SSoby Mathew
31532ed618SSoby Mathew#include <asm_macros.S>
32532ed618SSoby Mathew#include <assert_macros.S>
33532ed618SSoby Mathew#include <platform_def.h>
34532ed618SSoby Mathew#include <psci.h>
35532ed618SSoby Mathew
36532ed618SSoby Mathew	.globl	psci_do_pwrdown_cache_maintenance
37532ed618SSoby Mathew	.globl	psci_do_pwrup_cache_maintenance
38*cf0b1492SSoby Mathew	.globl	psci_power_down_wfi
39*cf0b1492SSoby Mathew#if !ERROR_DEPRECATED
40*cf0b1492SSoby Mathew	.globl psci_entrypoint
41*cf0b1492SSoby Mathew#endif
42532ed618SSoby Mathew
43532ed618SSoby Mathew/* -----------------------------------------------------------------------
44532ed618SSoby Mathew * void psci_do_pwrdown_cache_maintenance(unsigned int power level);
45532ed618SSoby Mathew *
46532ed618SSoby Mathew * This function performs cache maintenance for the specified power
47532ed618SSoby Mathew * level. The levels of cache affected are determined by the power
48532ed618SSoby Mathew * level which is passed as the argument i.e. level 0 results
49532ed618SSoby Mathew * in a flush of the L1 cache. Both the L1 and L2 caches are flushed
50532ed618SSoby Mathew * for a higher power level.
51532ed618SSoby Mathew *
52532ed618SSoby Mathew * Additionally, this function also ensures that stack memory is correctly
53532ed618SSoby Mathew * flushed out to avoid coherency issues due to a change in its memory
54532ed618SSoby Mathew * attributes after the data cache is disabled.
55532ed618SSoby Mathew * -----------------------------------------------------------------------
56532ed618SSoby Mathew */
57532ed618SSoby Mathewfunc psci_do_pwrdown_cache_maintenance
58532ed618SSoby Mathew	stp     x29, x30, [sp,#-16]!
59532ed618SSoby Mathew	stp     x19, x20, [sp,#-16]!
60532ed618SSoby Mathew
61532ed618SSoby Mathew	/* ---------------------------------------------
62532ed618SSoby Mathew	 * Determine to how many levels of cache will be
63532ed618SSoby Mathew	 * subject to cache maintenance. Power level
64532ed618SSoby Mathew	 * 0 implies that only the cpu is being powered
65532ed618SSoby Mathew	 * down. Only the L1 data cache needs to be
66532ed618SSoby Mathew	 * flushed to the PoU in this case. For a higher
67532ed618SSoby Mathew	 * power level we are assuming that a flush
68532ed618SSoby Mathew	 * of L1 data and L2 unified cache is enough.
69532ed618SSoby Mathew	 * This information should be provided by the
70532ed618SSoby Mathew	 * platform.
71532ed618SSoby Mathew	 * ---------------------------------------------
72532ed618SSoby Mathew	 */
73532ed618SSoby Mathew	cmp	w0, #PSCI_CPU_PWR_LVL
74532ed618SSoby Mathew	b.eq	do_core_pwr_dwn
75532ed618SSoby Mathew	bl	prepare_cluster_pwr_dwn
76532ed618SSoby Mathew	b	do_stack_maintenance
77532ed618SSoby Mathew
78532ed618SSoby Mathewdo_core_pwr_dwn:
79532ed618SSoby Mathew	bl	prepare_core_pwr_dwn
80532ed618SSoby Mathew
81532ed618SSoby Mathew	/* ---------------------------------------------
82532ed618SSoby Mathew	 * Do stack maintenance by flushing the used
83532ed618SSoby Mathew	 * stack to the main memory and invalidating the
84532ed618SSoby Mathew	 * remainder.
85532ed618SSoby Mathew	 * ---------------------------------------------
86532ed618SSoby Mathew	 */
87532ed618SSoby Mathewdo_stack_maintenance:
88532ed618SSoby Mathew	bl	plat_get_my_stack
89532ed618SSoby Mathew
90532ed618SSoby Mathew	/* ---------------------------------------------
91532ed618SSoby Mathew	 * Calculate and store the size of the used
92532ed618SSoby Mathew	 * stack memory in x1.
93532ed618SSoby Mathew	 * ---------------------------------------------
94532ed618SSoby Mathew	 */
95532ed618SSoby Mathew	mov	x19, x0
96532ed618SSoby Mathew	mov	x1, sp
97532ed618SSoby Mathew	sub	x1, x0, x1
98532ed618SSoby Mathew	mov	x0, sp
99532ed618SSoby Mathew	bl	flush_dcache_range
100532ed618SSoby Mathew
101532ed618SSoby Mathew	/* ---------------------------------------------
102532ed618SSoby Mathew	 * Calculate and store the size of the unused
103532ed618SSoby Mathew	 * stack memory in x1. Calculate and store the
104532ed618SSoby Mathew	 * stack base address in x0.
105532ed618SSoby Mathew	 * ---------------------------------------------
106532ed618SSoby Mathew	 */
107532ed618SSoby Mathew	sub	x0, x19, #PLATFORM_STACK_SIZE
108532ed618SSoby Mathew	sub	x1, sp, x0
109532ed618SSoby Mathew	bl	inv_dcache_range
110532ed618SSoby Mathew
111532ed618SSoby Mathew	ldp	x19, x20, [sp], #16
112532ed618SSoby Mathew	ldp	x29, x30, [sp], #16
113532ed618SSoby Mathew	ret
114532ed618SSoby Mathewendfunc psci_do_pwrdown_cache_maintenance
115532ed618SSoby Mathew
116532ed618SSoby Mathew
117532ed618SSoby Mathew/* -----------------------------------------------------------------------
118532ed618SSoby Mathew * void psci_do_pwrup_cache_maintenance(void);
119532ed618SSoby Mathew *
120532ed618SSoby Mathew * This function performs cache maintenance after this cpu is powered up.
121532ed618SSoby Mathew * Currently, this involves managing the used stack memory before turning
122532ed618SSoby Mathew * on the data cache.
123532ed618SSoby Mathew * -----------------------------------------------------------------------
124532ed618SSoby Mathew */
125532ed618SSoby Mathewfunc psci_do_pwrup_cache_maintenance
126532ed618SSoby Mathew	stp	x29, x30, [sp,#-16]!
127532ed618SSoby Mathew
128532ed618SSoby Mathew	/* ---------------------------------------------
129532ed618SSoby Mathew	 * Ensure any inflight stack writes have made it
130532ed618SSoby Mathew	 * to main memory.
131532ed618SSoby Mathew	 * ---------------------------------------------
132532ed618SSoby Mathew	 */
133532ed618SSoby Mathew	dmb	st
134532ed618SSoby Mathew
135532ed618SSoby Mathew	/* ---------------------------------------------
136532ed618SSoby Mathew	 * Calculate and store the size of the used
137532ed618SSoby Mathew	 * stack memory in x1. Calculate and store the
138532ed618SSoby Mathew	 * stack base address in x0.
139532ed618SSoby Mathew	 * ---------------------------------------------
140532ed618SSoby Mathew	 */
141532ed618SSoby Mathew	bl	plat_get_my_stack
142532ed618SSoby Mathew	mov	x1, sp
143532ed618SSoby Mathew	sub	x1, x0, x1
144532ed618SSoby Mathew	mov	x0, sp
145532ed618SSoby Mathew	bl	inv_dcache_range
146532ed618SSoby Mathew
147532ed618SSoby Mathew	/* ---------------------------------------------
148532ed618SSoby Mathew	 * Enable the data cache.
149532ed618SSoby Mathew	 * ---------------------------------------------
150532ed618SSoby Mathew	 */
151532ed618SSoby Mathew	mrs	x0, sctlr_el3
152532ed618SSoby Mathew	orr	x0, x0, #SCTLR_C_BIT
153532ed618SSoby Mathew	msr	sctlr_el3, x0
154532ed618SSoby Mathew	isb
155532ed618SSoby Mathew
156532ed618SSoby Mathew	ldp	x29, x30, [sp], #16
157532ed618SSoby Mathew	ret
158532ed618SSoby Mathewendfunc psci_do_pwrup_cache_maintenance
159*cf0b1492SSoby Mathew
160*cf0b1492SSoby Mathew/* -----------------------------------------------------------------------
161*cf0b1492SSoby Mathew * void psci_power_down_wfi(void);
162*cf0b1492SSoby Mathew * This function is called to indicate to the power controller that it
163*cf0b1492SSoby Mathew * is safe to power down this cpu. It should not exit the wfi and will
164*cf0b1492SSoby Mathew * be released from reset upon power up.
165*cf0b1492SSoby Mathew * -----------------------------------------------------------------------
166*cf0b1492SSoby Mathew */
167*cf0b1492SSoby Mathewfunc psci_power_down_wfi
168*cf0b1492SSoby Mathew	dsb	sy		// ensure write buffer empty
169*cf0b1492SSoby Mathew	wfi
170*cf0b1492SSoby Mathew	bl	plat_panic_handler
171*cf0b1492SSoby Mathewendfunc psci_power_down_wfi
172*cf0b1492SSoby Mathew
173*cf0b1492SSoby Mathew/* -----------------------------------------------------------------------
174*cf0b1492SSoby Mathew * void psci_entrypoint(void);
175*cf0b1492SSoby Mathew * The deprecated entry point for PSCI on warm boot for AArch64.
176*cf0b1492SSoby Mathew * -----------------------------------------------------------------------
177*cf0b1492SSoby Mathew */
178*cf0b1492SSoby Mathewfunc_deprecated psci_entrypoint
179*cf0b1492SSoby Mathew	b	bl31_warm_entrypoint
180*cf0b1492SSoby Mathewendfunc_deprecated psci_entrypoint
181