blob: ce8adc2ed455309969903c35d64c88bdcd5a955b [file] [log] [blame]
Achin Guptab51da822014-06-26 09:58:52 +01001/*
Boyan Karatotevcc94e712024-09-26 17:00:09 +01002 * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved.
Achin Guptab51da822014-06-26 09:58:52 +01003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Achin Guptab51da822014-06-26 09:58:52 +01005 */
6
Achin Guptab51da822014-06-26 09:58:52 +01007#include <asm_macros.S>
Achin Gupta0a46e2c2014-07-31 11:19:11 +01008#include <assert_macros.S>
Boyan Karatotevdb9ee832024-09-26 17:09:53 +01009#include <cpu_macros.S>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000010#include <lib/psci/psci.h>
Achin Guptab51da822014-06-26 09:58:52 +010011#include <platform_def.h>
12
13 .globl psci_do_pwrdown_cache_maintenance
14 .globl psci_do_pwrup_cache_maintenance
15
16/* -----------------------------------------------------------------------
Boyan Karatotevaadb4b52025-03-12 10:36:46 +000017 * void psci_do_pwrdown_cache_maintenance(void);
Achin Guptab51da822014-06-26 09:58:52 +010018 *
Boyan Karatotevaadb4b52025-03-12 10:36:46 +000019 * This function turns off data caches and also ensures that stack memory
20 * is correctly flushed out to avoid coherency issues due to a change in
21 * its memory attributes.
Achin Guptab51da822014-06-26 09:58:52 +010022 * -----------------------------------------------------------------------
23 */
24func psci_do_pwrdown_cache_maintenance
25 stp x29, x30, [sp,#-16]!
26 stp x19, x20, [sp,#-16]!
27
Boyan Karatotevaadb4b52025-03-12 10:36:46 +000028 /* Disable L1 data cache and unified L2 cache */
29 mrs x1, sctlr_el3
30 bic x1, x1, #SCTLR_C_BIT
31 msr sctlr_el3, x1
32 isb
Achin Guptab51da822014-06-26 09:58:52 +010033
34 /* ---------------------------------------------
35 * Do stack maintenance by flushing the used
36 * stack to the main memory and invalidating the
37 * remainder.
38 * ---------------------------------------------
39 */
Soby Mathew67487842015-07-13 14:10:57 +010040 bl plat_get_my_stack
Achin Guptab51da822014-06-26 09:58:52 +010041
42 /* ---------------------------------------------
43 * Calculate and store the size of the used
44 * stack memory in x1.
45 * ---------------------------------------------
46 */
47 mov x19, x0
48 mov x1, sp
49 sub x1, x0, x1
50 mov x0, sp
51 bl flush_dcache_range
52
53 /* ---------------------------------------------
54 * Calculate and store the size of the unused
55 * stack memory in x1. Calculate and store the
56 * stack base address in x0.
57 * ---------------------------------------------
58 */
59 sub x0, x19, #PLATFORM_STACK_SIZE
60 sub x1, sp, x0
61 bl inv_dcache_range
62
Achin Guptab51da822014-06-26 09:58:52 +010063 ldp x19, x20, [sp], #16
64 ldp x29, x30, [sp], #16
65 ret
Kévin Petit8b779622015-03-24 14:03:57 +000066endfunc psci_do_pwrdown_cache_maintenance
Achin Guptab51da822014-06-26 09:58:52 +010067
68
69/* -----------------------------------------------------------------------
70 * void psci_do_pwrup_cache_maintenance(void);
71 *
72 * This function performs cache maintenance after this cpu is powered up.
73 * Currently, this involves managing the used stack memory before turning
74 * on the data cache.
75 * -----------------------------------------------------------------------
76 */
77func psci_do_pwrup_cache_maintenance
78 stp x29, x30, [sp,#-16]!
79
80 /* ---------------------------------------------
81 * Ensure any inflight stack writes have made it
82 * to main memory.
83 * ---------------------------------------------
84 */
85 dmb st
86
87 /* ---------------------------------------------
88 * Calculate and store the size of the used
89 * stack memory in x1. Calculate and store the
90 * stack base address in x0.
91 * ---------------------------------------------
92 */
Soby Mathew67487842015-07-13 14:10:57 +010093 bl plat_get_my_stack
Achin Guptab51da822014-06-26 09:58:52 +010094 mov x1, sp
95 sub x1, x0, x1
96 mov x0, sp
97 bl inv_dcache_range
98
99 /* ---------------------------------------------
100 * Enable the data cache.
101 * ---------------------------------------------
102 */
103 mrs x0, sctlr_el3
104 orr x0, x0, #SCTLR_C_BIT
105 msr sctlr_el3, x0
106 isb
107
108 ldp x29, x30, [sp], #16
109 ret
Kévin Petit8b779622015-03-24 14:03:57 +0000110endfunc psci_do_pwrup_cache_maintenance