Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 24395f4 | 2024-09-26 17:09:53 +0100 | [diff] [blame] | 2 | * Copyright (c) 2014-2024, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 7 | #include <asm_macros.S> |
Achin Gupta | f6b9e99 | 2014-07-31 11:19:11 +0100 | [diff] [blame] | 8 | #include <assert_macros.S> |
Boyan Karatotev | 24395f4 | 2024-09-26 17:09:53 +0100 | [diff] [blame] | 9 | #include <cpu_macros.S> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | #include <lib/psci/psci.h> |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 11 | #include <platform_def.h> |
| 12 | |
| 13 | .globl psci_do_pwrdown_cache_maintenance |
| 14 | .globl psci_do_pwrup_cache_maintenance |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 15 | .globl psci_power_down_wfi |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 16 | |
| 17 | /* ----------------------------------------------------------------------- |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 18 | * void psci_do_pwrdown_cache_maintenance(unsigned int power level); |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 19 | * |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 20 | * This function performs cache maintenance for the specified power |
| 21 | * level. The levels of cache affected are determined by the power |
| 22 | * level which is passed as the argument i.e. level 0 results |
| 23 | * in a flush of the L1 cache. Both the L1 and L2 caches are flushed |
| 24 | * for a higher power level. |
Achin Gupta | f6b9e99 | 2014-07-31 11:19:11 +0100 | [diff] [blame] | 25 | * |
| 26 | * Additionally, this function also ensures that stack memory is correctly |
| 27 | * flushed out to avoid coherency issues due to a change in its memory |
| 28 | * attributes after the data cache is disabled. |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 29 | * ----------------------------------------------------------------------- |
| 30 | */ |
| 31 | func psci_do_pwrdown_cache_maintenance |
| 32 | stp x29, x30, [sp,#-16]! |
| 33 | stp x19, x20, [sp,#-16]! |
| 34 | |
| 35 | /* --------------------------------------------- |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 36 | * Invoke CPU-specific power down operations for |
| 37 | * the appropriate level |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 38 | * --------------------------------------------- |
| 39 | */ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 40 | bl prepare_cpu_pwr_dwn |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 41 | |
| 42 | /* --------------------------------------------- |
| 43 | * Do stack maintenance by flushing the used |
| 44 | * stack to the main memory and invalidating the |
| 45 | * remainder. |
| 46 | * --------------------------------------------- |
| 47 | */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 48 | bl plat_get_my_stack |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 49 | |
| 50 | /* --------------------------------------------- |
| 51 | * Calculate and store the size of the used |
| 52 | * stack memory in x1. |
| 53 | * --------------------------------------------- |
| 54 | */ |
| 55 | mov x19, x0 |
| 56 | mov x1, sp |
| 57 | sub x1, x0, x1 |
| 58 | mov x0, sp |
| 59 | bl flush_dcache_range |
| 60 | |
| 61 | /* --------------------------------------------- |
| 62 | * Calculate and store the size of the unused |
| 63 | * stack memory in x1. Calculate and store the |
| 64 | * stack base address in x0. |
| 65 | * --------------------------------------------- |
| 66 | */ |
| 67 | sub x0, x19, #PLATFORM_STACK_SIZE |
| 68 | sub x1, sp, x0 |
| 69 | bl inv_dcache_range |
| 70 | |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 71 | ldp x19, x20, [sp], #16 |
| 72 | ldp x29, x30, [sp], #16 |
| 73 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 74 | endfunc psci_do_pwrdown_cache_maintenance |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 75 | |
| 76 | |
| 77 | /* ----------------------------------------------------------------------- |
| 78 | * void psci_do_pwrup_cache_maintenance(void); |
| 79 | * |
| 80 | * This function performs cache maintenance after this cpu is powered up. |
| 81 | * Currently, this involves managing the used stack memory before turning |
| 82 | * on the data cache. |
| 83 | * ----------------------------------------------------------------------- |
| 84 | */ |
| 85 | func psci_do_pwrup_cache_maintenance |
| 86 | stp x29, x30, [sp,#-16]! |
| 87 | |
| 88 | /* --------------------------------------------- |
| 89 | * Ensure any inflight stack writes have made it |
| 90 | * to main memory. |
| 91 | * --------------------------------------------- |
| 92 | */ |
| 93 | dmb st |
| 94 | |
| 95 | /* --------------------------------------------- |
| 96 | * Calculate and store the size of the used |
| 97 | * stack memory in x1. Calculate and store the |
| 98 | * stack base address in x0. |
| 99 | * --------------------------------------------- |
| 100 | */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 101 | bl plat_get_my_stack |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 102 | mov x1, sp |
| 103 | sub x1, x0, x1 |
| 104 | mov x0, sp |
| 105 | bl inv_dcache_range |
| 106 | |
| 107 | /* --------------------------------------------- |
| 108 | * Enable the data cache. |
| 109 | * --------------------------------------------- |
| 110 | */ |
| 111 | mrs x0, sctlr_el3 |
| 112 | orr x0, x0, #SCTLR_C_BIT |
| 113 | msr sctlr_el3, x0 |
| 114 | isb |
| 115 | |
| 116 | ldp x29, x30, [sp], #16 |
| 117 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 118 | endfunc psci_do_pwrup_cache_maintenance |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 119 | |
| 120 | /* ----------------------------------------------------------------------- |
| 121 | * void psci_power_down_wfi(void); |
| 122 | * This function is called to indicate to the power controller that it |
| 123 | * is safe to power down this cpu. It should not exit the wfi and will |
| 124 | * be released from reset upon power up. |
| 125 | * ----------------------------------------------------------------------- |
| 126 | */ |
| 127 | func psci_power_down_wfi |
Boyan Karatotev | 24395f4 | 2024-09-26 17:09:53 +0100 | [diff] [blame] | 128 | apply_erratum cortex_a510, ERRATUM(2684597), ERRATA_A510_2684597 |
| 129 | |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 130 | dsb sy // ensure write buffer empty |
Harrison Mutai | 263c647 | 2023-01-11 17:01:04 +0000 | [diff] [blame] | 131 | 1: |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 132 | wfi |
Harrison Mutai | 263c647 | 2023-01-11 17:01:04 +0000 | [diff] [blame] | 133 | b 1b |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 134 | endfunc psci_power_down_wfi |