1*2bf28e62SAndrew Thoelke/* 2*2bf28e62SAndrew Thoelke * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. 3*2bf28e62SAndrew Thoelke * 4*2bf28e62SAndrew Thoelke * Redistribution and use in source and binary forms, with or without 5*2bf28e62SAndrew Thoelke * modification, are permitted provided that the following conditions are met: 6*2bf28e62SAndrew Thoelke * 7*2bf28e62SAndrew Thoelke * Redistributions of source code must retain the above copyright notice, this 8*2bf28e62SAndrew Thoelke * list of conditions and the following disclaimer. 9*2bf28e62SAndrew Thoelke * 10*2bf28e62SAndrew Thoelke * Redistributions in binary form must reproduce the above copyright notice, 11*2bf28e62SAndrew Thoelke * this list of conditions and the following disclaimer in the documentation 12*2bf28e62SAndrew Thoelke * and/or other materials provided with the distribution. 13*2bf28e62SAndrew Thoelke * 14*2bf28e62SAndrew Thoelke * Neither the name of ARM nor the names of its contributors may be used 15*2bf28e62SAndrew Thoelke * to endorse or promote products derived from this software without specific 16*2bf28e62SAndrew Thoelke * prior written permission. 17*2bf28e62SAndrew Thoelke * 18*2bf28e62SAndrew Thoelke * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*2bf28e62SAndrew Thoelke * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*2bf28e62SAndrew Thoelke * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*2bf28e62SAndrew Thoelke * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*2bf28e62SAndrew Thoelke * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*2bf28e62SAndrew Thoelke * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*2bf28e62SAndrew Thoelke * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*2bf28e62SAndrew Thoelke * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*2bf28e62SAndrew Thoelke * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*2bf28e62SAndrew Thoelke * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*2bf28e62SAndrew Thoelke * POSSIBILITY OF SUCH DAMAGE. 29*2bf28e62SAndrew Thoelke */ 30*2bf28e62SAndrew Thoelke 31*2bf28e62SAndrew Thoelke#include <arch.h> 32*2bf28e62SAndrew Thoelke#include <platform.h> 33*2bf28e62SAndrew Thoelke#include <asm_macros.S> 34*2bf28e62SAndrew Thoelke 35*2bf28e62SAndrew Thoelke 36*2bf28e62SAndrew Thoelke .local pcpu_dv_mem_stack 37*2bf28e62SAndrew Thoelke .local platform_normal_stacks 38*2bf28e62SAndrew Thoelke .weak platform_set_stack 39*2bf28e62SAndrew Thoelke .weak platform_get_stack 40*2bf28e62SAndrew Thoelke .weak platform_set_coherent_stack 41*2bf28e62SAndrew Thoelke 42*2bf28e62SAndrew Thoelke 43*2bf28e62SAndrew Thoelke /* ----------------------------------------------------- 44*2bf28e62SAndrew Thoelke * void platform_set_coherent_stack (unsigned long mpidr) 45*2bf28e62SAndrew Thoelke * 46*2bf28e62SAndrew Thoelke * For a given CPU, this function sets the stack pointer 47*2bf28e62SAndrew Thoelke * to a stack allocated in device memory. This stack can 48*2bf28e62SAndrew Thoelke * be used by C code which enables/disables the SCTLR.M 49*2bf28e62SAndrew Thoelke * SCTLR.C bit e.g. while powering down a cpu 50*2bf28e62SAndrew Thoelke * ----------------------------------------------------- 51*2bf28e62SAndrew Thoelke */ 52*2bf28e62SAndrew Thoelkefunc platform_set_coherent_stack 53*2bf28e62SAndrew Thoelke mov x5, x30 // lr 54*2bf28e62SAndrew Thoelke get_mp_stack pcpu_dv_mem_stack, PCPU_DV_MEM_STACK_SIZE 55*2bf28e62SAndrew Thoelke mov sp, x0 56*2bf28e62SAndrew Thoelke ret x5 57*2bf28e62SAndrew Thoelke 58*2bf28e62SAndrew Thoelke /* ----------------------------------------------------- 59*2bf28e62SAndrew Thoelke * unsigned long platform_get_stack (unsigned long mpidr) 60*2bf28e62SAndrew Thoelke * 61*2bf28e62SAndrew Thoelke * For a given CPU, this function returns the stack 62*2bf28e62SAndrew Thoelke * pointer for a stack allocated in device memory. 63*2bf28e62SAndrew Thoelke * ----------------------------------------------------- 64*2bf28e62SAndrew Thoelke */ 65*2bf28e62SAndrew Thoelkefunc platform_get_stack 66*2bf28e62SAndrew Thoelke mov x10, x30 // lr 67*2bf28e62SAndrew Thoelke get_mp_stack platform_normal_stacks, PLATFORM_STACK_SIZE 68*2bf28e62SAndrew Thoelke ret x10 69*2bf28e62SAndrew Thoelke 70*2bf28e62SAndrew Thoelke /* ----------------------------------------------------- 71*2bf28e62SAndrew Thoelke * void platform_set_stack (unsigned long mpidr) 72*2bf28e62SAndrew Thoelke * 73*2bf28e62SAndrew Thoelke * For a given CPU, this function sets the stack pointer 74*2bf28e62SAndrew Thoelke * to a stack allocated in normal memory. 75*2bf28e62SAndrew Thoelke * ----------------------------------------------------- 76*2bf28e62SAndrew Thoelke */ 77*2bf28e62SAndrew Thoelkefunc platform_set_stack 78*2bf28e62SAndrew Thoelke mov x9, x30 // lr 79*2bf28e62SAndrew Thoelke bl platform_get_stack 80*2bf28e62SAndrew Thoelke mov sp, x0 81*2bf28e62SAndrew Thoelke ret x9 82*2bf28e62SAndrew Thoelke 83*2bf28e62SAndrew Thoelke /* ----------------------------------------------------- 84*2bf28e62SAndrew Thoelke * Per-cpu stacks in normal memory. 85*2bf28e62SAndrew Thoelke * Used for C code during runtime execution (when coherent 86*2bf28e62SAndrew Thoelke * stacks are not required). 87*2bf28e62SAndrew Thoelke * Each cpu gets a stack of PLATFORM_STACK_SIZE bytes. 88*2bf28e62SAndrew Thoelke * ----------------------------------------------------- 89*2bf28e62SAndrew Thoelke */ 90*2bf28e62SAndrew Thoelkedeclare_stack platform_normal_stacks, tzfw_normal_stacks, \ 91*2bf28e62SAndrew Thoelke PLATFORM_STACK_SIZE, PLATFORM_CORE_COUNT 92*2bf28e62SAndrew Thoelke 93*2bf28e62SAndrew Thoelke /* ----------------------------------------------------- 94*2bf28e62SAndrew Thoelke * Per-cpu stacks in device memory. 95*2bf28e62SAndrew Thoelke * Used for C code just before power down or right after 96*2bf28e62SAndrew Thoelke * power up when the MMU or caches need to be turned on 97*2bf28e62SAndrew Thoelke * or off. 98*2bf28e62SAndrew Thoelke * Each cpu gets a stack of PCPU_DV_MEM_STACK_SIZE bytes. 99*2bf28e62SAndrew Thoelke * ----------------------------------------------------- 100*2bf28e62SAndrew Thoelke */ 101*2bf28e62SAndrew Thoelkedeclare_stack pcpu_dv_mem_stack, tzfw_coherent_mem, \ 102*2bf28e62SAndrew Thoelke PCPU_DV_MEM_STACK_SIZE, PLATFORM_CORE_COUNT 103