Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 9f2f8ef | 2018-02-19 16:27:06 +0000 | [diff] [blame] | 2 | * Copyright (c) 2014-2018, 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> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 9 | #include <lib/psci/psci.h> |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 10 | #include <platform_def.h> |
| 11 | |
| 12 | .globl psci_do_pwrdown_cache_maintenance |
| 13 | .globl psci_do_pwrup_cache_maintenance |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 14 | .globl psci_power_down_wfi |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 15 | |
| 16 | /* ----------------------------------------------------------------------- |
Soby Mathew | 011ca18 | 2015-07-29 17:05:03 +0100 | [diff] [blame] | 17 | * void psci_do_pwrdown_cache_maintenance(unsigned int power level); |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 18 | * |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 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. |
Achin Gupta | f6b9e99 | 2014-07-31 11:19:11 +0100 | [diff] [blame] | 24 | * |
| 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. |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 28 | * ----------------------------------------------------------------------- |
| 29 | */ |
| 30 | func psci_do_pwrdown_cache_maintenance |
| 31 | stp x29, x30, [sp,#-16]! |
| 32 | stp x19, x20, [sp,#-16]! |
| 33 | |
| 34 | /* --------------------------------------------- |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 35 | * Invoke CPU-specific power down operations for |
| 36 | * the appropriate level |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 37 | * --------------------------------------------- |
| 38 | */ |
Jeenu Viswambharan | ee5eb80 | 2016-11-18 12:58:28 +0000 | [diff] [blame] | 39 | bl prepare_cpu_pwr_dwn |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 40 | |
| 41 | /* --------------------------------------------- |
| 42 | * Do stack maintenance by flushing the used |
| 43 | * stack to the main memory and invalidating the |
| 44 | * remainder. |
| 45 | * --------------------------------------------- |
| 46 | */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 47 | bl plat_get_my_stack |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 48 | |
| 49 | /* --------------------------------------------- |
| 50 | * Calculate and store the size of the used |
| 51 | * stack memory in x1. |
| 52 | * --------------------------------------------- |
| 53 | */ |
| 54 | mov x19, x0 |
| 55 | mov x1, sp |
| 56 | sub x1, x0, x1 |
| 57 | mov x0, sp |
| 58 | bl flush_dcache_range |
| 59 | |
| 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 | * --------------------------------------------- |
| 65 | */ |
| 66 | sub x0, x19, #PLATFORM_STACK_SIZE |
| 67 | sub x1, sp, x0 |
| 68 | bl inv_dcache_range |
| 69 | |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 70 | ldp x19, x20, [sp], #16 |
| 71 | ldp x29, x30, [sp], #16 |
| 72 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 73 | endfunc psci_do_pwrdown_cache_maintenance |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 74 | |
| 75 | |
| 76 | /* ----------------------------------------------------------------------- |
| 77 | * void psci_do_pwrup_cache_maintenance(void); |
| 78 | * |
| 79 | * This function performs cache maintenance after this cpu is powered up. |
| 80 | * Currently, this involves managing the used stack memory before turning |
| 81 | * on the data cache. |
| 82 | * ----------------------------------------------------------------------- |
| 83 | */ |
| 84 | func psci_do_pwrup_cache_maintenance |
| 85 | stp x29, x30, [sp,#-16]! |
| 86 | |
| 87 | /* --------------------------------------------- |
| 88 | * Ensure any inflight stack writes have made it |
| 89 | * to main memory. |
| 90 | * --------------------------------------------- |
| 91 | */ |
| 92 | dmb st |
| 93 | |
| 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 | * --------------------------------------------- |
| 99 | */ |
Soby Mathew | 981487a | 2015-07-13 14:10:57 +0100 | [diff] [blame] | 100 | bl plat_get_my_stack |
Achin Gupta | e1aa516 | 2014-06-26 09:58:52 +0100 | [diff] [blame] | 101 | mov x1, sp |
| 102 | sub x1, x0, x1 |
| 103 | mov x0, sp |
| 104 | bl inv_dcache_range |
| 105 | |
| 106 | /* --------------------------------------------- |
| 107 | * Enable the data cache. |
| 108 | * --------------------------------------------- |
| 109 | */ |
| 110 | mrs x0, sctlr_el3 |
| 111 | orr x0, x0, #SCTLR_C_BIT |
| 112 | msr sctlr_el3, x0 |
| 113 | isb |
| 114 | |
| 115 | ldp x29, x30, [sp], #16 |
| 116 | ret |
Kévin Petit | a877c25 | 2015-03-24 14:03:57 +0000 | [diff] [blame] | 117 | endfunc psci_do_pwrup_cache_maintenance |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 118 | |
| 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 | * ----------------------------------------------------------------------- |
| 125 | */ |
| 126 | func psci_power_down_wfi |
| 127 | dsb sy // ensure write buffer empty |
| 128 | wfi |
Jeenu Viswambharan | 68aef10 | 2016-11-30 15:21:11 +0000 | [diff] [blame] | 129 | no_ret plat_panic_handler |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 130 | endfunc psci_power_down_wfi |