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 38cf0b1492SSoby Mathew .globl psci_power_down_wfi 39cf0b1492SSoby Mathew#if !ERROR_DEPRECATED 40cf0b1492SSoby Mathew .globl psci_entrypoint 41cf0b1492SSoby 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 /* --------------------------------------------- 62*5dd9dbb5SJeenu Viswambharan * Invoke CPU-specific power down operations for 63*5dd9dbb5SJeenu Viswambharan * the appropriate level 64532ed618SSoby Mathew * --------------------------------------------- 65532ed618SSoby Mathew */ 66*5dd9dbb5SJeenu Viswambharan bl prepare_cpu_pwr_dwn 67532ed618SSoby Mathew 68532ed618SSoby Mathew /* --------------------------------------------- 69532ed618SSoby Mathew * Do stack maintenance by flushing the used 70532ed618SSoby Mathew * stack to the main memory and invalidating the 71532ed618SSoby Mathew * remainder. 72532ed618SSoby Mathew * --------------------------------------------- 73532ed618SSoby Mathew */ 74532ed618SSoby Mathew bl plat_get_my_stack 75532ed618SSoby Mathew 76532ed618SSoby Mathew /* --------------------------------------------- 77532ed618SSoby Mathew * Calculate and store the size of the used 78532ed618SSoby Mathew * stack memory in x1. 79532ed618SSoby Mathew * --------------------------------------------- 80532ed618SSoby Mathew */ 81532ed618SSoby Mathew mov x19, x0 82532ed618SSoby Mathew mov x1, sp 83532ed618SSoby Mathew sub x1, x0, x1 84532ed618SSoby Mathew mov x0, sp 85532ed618SSoby Mathew bl flush_dcache_range 86532ed618SSoby Mathew 87532ed618SSoby Mathew /* --------------------------------------------- 88532ed618SSoby Mathew * Calculate and store the size of the unused 89532ed618SSoby Mathew * stack memory in x1. Calculate and store the 90532ed618SSoby Mathew * stack base address in x0. 91532ed618SSoby Mathew * --------------------------------------------- 92532ed618SSoby Mathew */ 93532ed618SSoby Mathew sub x0, x19, #PLATFORM_STACK_SIZE 94532ed618SSoby Mathew sub x1, sp, x0 95532ed618SSoby Mathew bl inv_dcache_range 96532ed618SSoby Mathew 97532ed618SSoby Mathew ldp x19, x20, [sp], #16 98532ed618SSoby Mathew ldp x29, x30, [sp], #16 99532ed618SSoby Mathew ret 100532ed618SSoby Mathewendfunc psci_do_pwrdown_cache_maintenance 101532ed618SSoby Mathew 102532ed618SSoby Mathew 103532ed618SSoby Mathew/* ----------------------------------------------------------------------- 104532ed618SSoby Mathew * void psci_do_pwrup_cache_maintenance(void); 105532ed618SSoby Mathew * 106532ed618SSoby Mathew * This function performs cache maintenance after this cpu is powered up. 107532ed618SSoby Mathew * Currently, this involves managing the used stack memory before turning 108532ed618SSoby Mathew * on the data cache. 109532ed618SSoby Mathew * ----------------------------------------------------------------------- 110532ed618SSoby Mathew */ 111532ed618SSoby Mathewfunc psci_do_pwrup_cache_maintenance 112532ed618SSoby Mathew stp x29, x30, [sp,#-16]! 113532ed618SSoby Mathew 114532ed618SSoby Mathew /* --------------------------------------------- 115532ed618SSoby Mathew * Ensure any inflight stack writes have made it 116532ed618SSoby Mathew * to main memory. 117532ed618SSoby Mathew * --------------------------------------------- 118532ed618SSoby Mathew */ 119532ed618SSoby Mathew dmb st 120532ed618SSoby Mathew 121532ed618SSoby Mathew /* --------------------------------------------- 122532ed618SSoby Mathew * Calculate and store the size of the used 123532ed618SSoby Mathew * stack memory in x1. Calculate and store the 124532ed618SSoby Mathew * stack base address in x0. 125532ed618SSoby Mathew * --------------------------------------------- 126532ed618SSoby Mathew */ 127532ed618SSoby Mathew bl plat_get_my_stack 128532ed618SSoby Mathew mov x1, sp 129532ed618SSoby Mathew sub x1, x0, x1 130532ed618SSoby Mathew mov x0, sp 131532ed618SSoby Mathew bl inv_dcache_range 132532ed618SSoby Mathew 133532ed618SSoby Mathew /* --------------------------------------------- 134532ed618SSoby Mathew * Enable the data cache. 135532ed618SSoby Mathew * --------------------------------------------- 136532ed618SSoby Mathew */ 137532ed618SSoby Mathew mrs x0, sctlr_el3 138532ed618SSoby Mathew orr x0, x0, #SCTLR_C_BIT 139532ed618SSoby Mathew msr sctlr_el3, x0 140532ed618SSoby Mathew isb 141532ed618SSoby Mathew 142532ed618SSoby Mathew ldp x29, x30, [sp], #16 143532ed618SSoby Mathew ret 144532ed618SSoby Mathewendfunc psci_do_pwrup_cache_maintenance 145cf0b1492SSoby Mathew 146cf0b1492SSoby Mathew/* ----------------------------------------------------------------------- 147cf0b1492SSoby Mathew * void psci_power_down_wfi(void); 148cf0b1492SSoby Mathew * This function is called to indicate to the power controller that it 149cf0b1492SSoby Mathew * is safe to power down this cpu. It should not exit the wfi and will 150cf0b1492SSoby Mathew * be released from reset upon power up. 151cf0b1492SSoby Mathew * ----------------------------------------------------------------------- 152cf0b1492SSoby Mathew */ 153cf0b1492SSoby Mathewfunc psci_power_down_wfi 154cf0b1492SSoby Mathew dsb sy // ensure write buffer empty 155cf0b1492SSoby Mathew wfi 156a806dad5SJeenu Viswambharan no_ret plat_panic_handler 157cf0b1492SSoby Mathewendfunc psci_power_down_wfi 158cf0b1492SSoby Mathew 159cf0b1492SSoby Mathew/* ----------------------------------------------------------------------- 160cf0b1492SSoby Mathew * void psci_entrypoint(void); 161cf0b1492SSoby Mathew * The deprecated entry point for PSCI on warm boot for AArch64. 162cf0b1492SSoby Mathew * ----------------------------------------------------------------------- 163cf0b1492SSoby Mathew */ 164cf0b1492SSoby Mathewfunc_deprecated psci_entrypoint 165cf0b1492SSoby Mathew b bl31_warm_entrypoint 166cf0b1492SSoby Mathewendfunc_deprecated psci_entrypoint 167