157356e90SAchin Gupta/* 257356e90SAchin Gupta * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved. 357356e90SAchin Gupta * 457356e90SAchin Gupta * Redistribution and use in source and binary forms, with or without 557356e90SAchin Gupta * modification, are permitted provided that the following conditions are met: 657356e90SAchin Gupta * 757356e90SAchin Gupta * Redistributions of source code must retain the above copyright notice, this 857356e90SAchin Gupta * list of conditions and the following disclaimer. 957356e90SAchin Gupta * 1057356e90SAchin Gupta * Redistributions in binary form must reproduce the above copyright notice, 1157356e90SAchin Gupta * this list of conditions and the following disclaimer in the documentation 1257356e90SAchin Gupta * and/or other materials provided with the distribution. 1357356e90SAchin Gupta * 1457356e90SAchin Gupta * Neither the name of ARM nor the names of its contributors may be used 1557356e90SAchin Gupta * to endorse or promote products derived from this software without specific 1657356e90SAchin Gupta * prior written permission. 1757356e90SAchin Gupta * 1857356e90SAchin Gupta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1957356e90SAchin Gupta * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2057356e90SAchin Gupta * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2157356e90SAchin Gupta * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2257356e90SAchin Gupta * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2357356e90SAchin Gupta * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2457356e90SAchin Gupta * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2557356e90SAchin Gupta * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2657356e90SAchin Gupta * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2757356e90SAchin Gupta * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2857356e90SAchin Gupta * POSSIBILITY OF SUCH DAMAGE. 2957356e90SAchin Gupta */ 3057356e90SAchin Gupta 3157356e90SAchin Gupta#include <bl_common.h> 3257356e90SAchin Gupta#include <arch.h> 3357356e90SAchin Gupta#include <tsp.h> 3457356e90SAchin Gupta#include <asm_macros.S> 3557356e90SAchin Gupta 3657356e90SAchin Gupta 3757356e90SAchin Gupta /* ---------------------------------------------------- 3857356e90SAchin Gupta * The caller-saved registers x0-x18 and LR are saved 3957356e90SAchin Gupta * here. 4057356e90SAchin Gupta * ---------------------------------------------------- 4157356e90SAchin Gupta */ 4257356e90SAchin Gupta 4357356e90SAchin Gupta#define SCRATCH_REG_SIZE #(20 * 8) 4457356e90SAchin Gupta 4557356e90SAchin Gupta .macro save_caller_regs_and_lr 4657356e90SAchin Gupta sub sp, sp, SCRATCH_REG_SIZE 4757356e90SAchin Gupta stp x0, x1, [sp] 4857356e90SAchin Gupta stp x2, x3, [sp, #0x10] 4957356e90SAchin Gupta stp x4, x5, [sp, #0x20] 5057356e90SAchin Gupta stp x6, x7, [sp, #0x30] 5157356e90SAchin Gupta stp x8, x9, [sp, #0x40] 5257356e90SAchin Gupta stp x10, x11, [sp, #0x50] 5357356e90SAchin Gupta stp x12, x13, [sp, #0x60] 5457356e90SAchin Gupta stp x14, x15, [sp, #0x70] 5557356e90SAchin Gupta stp x16, x17, [sp, #0x80] 5657356e90SAchin Gupta stp x18, x30, [sp, #0x90] 5757356e90SAchin Gupta .endm 5857356e90SAchin Gupta 5957356e90SAchin Gupta .macro restore_caller_regs_and_lr 6057356e90SAchin Gupta ldp x0, x1, [sp] 6157356e90SAchin Gupta ldp x2, x3, [sp, #0x10] 6257356e90SAchin Gupta ldp x4, x5, [sp, #0x20] 6357356e90SAchin Gupta ldp x6, x7, [sp, #0x30] 6457356e90SAchin Gupta ldp x8, x9, [sp, #0x40] 6557356e90SAchin Gupta ldp x10, x11, [sp, #0x50] 6657356e90SAchin Gupta ldp x12, x13, [sp, #0x60] 6757356e90SAchin Gupta ldp x14, x15, [sp, #0x70] 6857356e90SAchin Gupta ldp x16, x17, [sp, #0x80] 6957356e90SAchin Gupta ldp x18, x30, [sp, #0x90] 7057356e90SAchin Gupta add sp, sp, SCRATCH_REG_SIZE 7157356e90SAchin Gupta .endm 7257356e90SAchin Gupta 73*02446137SSoby Mathew /* ---------------------------------------------------- 74*02446137SSoby Mathew * Common TSP interrupt handling routine 75*02446137SSoby Mathew * ---------------------------------------------------- 76*02446137SSoby Mathew */ 77*02446137SSoby Mathew .macro handle_tsp_interrupt label 78*02446137SSoby Mathew /* Enable the SError interrupt */ 79*02446137SSoby Mathew msr daifclr, #DAIF_ABT_BIT 80*02446137SSoby Mathew 81*02446137SSoby Mathew save_caller_regs_and_lr 82*02446137SSoby Mathew bl tsp_common_int_handler 83*02446137SSoby Mathew cbz x0, interrupt_exit_\label 84*02446137SSoby Mathew 85*02446137SSoby Mathew /* 86*02446137SSoby Mathew * This interrupt was not targetted to S-EL1 so send it to 87*02446137SSoby Mathew * the monitor and wait for execution to resume. 88*02446137SSoby Mathew */ 89*02446137SSoby Mathew smc #0 90*02446137SSoby Mathewinterrupt_exit_\label: 91*02446137SSoby Mathew restore_caller_regs_and_lr 92*02446137SSoby Mathew eret 93*02446137SSoby Mathew .endm 94*02446137SSoby Mathew 9557356e90SAchin Gupta .globl tsp_exceptions 9657356e90SAchin Gupta 9757356e90SAchin Gupta /* ----------------------------------------------------- 9857356e90SAchin Gupta * TSP exception handlers. 9957356e90SAchin Gupta * ----------------------------------------------------- 10057356e90SAchin Gupta */ 10157356e90SAchin Gupta .section .vectors, "ax"; .align 11 10257356e90SAchin Gupta 10357356e90SAchin Gupta .align 7 10457356e90SAchin Guptatsp_exceptions: 10557356e90SAchin Gupta /* ----------------------------------------------------- 10657356e90SAchin Gupta * Current EL with _sp_el0 : 0x0 - 0x180. No exceptions 10757356e90SAchin Gupta * are expected and treated as irrecoverable errors. 10857356e90SAchin Gupta * ----------------------------------------------------- 10957356e90SAchin Gupta */ 11057356e90SAchin Guptasync_exception_sp_el0: 11157356e90SAchin Gupta wfi 11257356e90SAchin Gupta b sync_exception_sp_el0 11357356e90SAchin Gupta check_vector_size sync_exception_sp_el0 11457356e90SAchin Gupta 11557356e90SAchin Gupta .align 7 11657356e90SAchin Gupta 11757356e90SAchin Guptairq_sp_el0: 11857356e90SAchin Gupta b irq_sp_el0 11957356e90SAchin Gupta check_vector_size irq_sp_el0 12057356e90SAchin Gupta 12157356e90SAchin Gupta .align 7 12257356e90SAchin Guptafiq_sp_el0: 12357356e90SAchin Gupta b fiq_sp_el0 12457356e90SAchin Gupta check_vector_size fiq_sp_el0 12557356e90SAchin Gupta 12657356e90SAchin Gupta .align 7 12757356e90SAchin Guptaserror_sp_el0: 12857356e90SAchin Gupta b serror_sp_el0 12957356e90SAchin Gupta check_vector_size serror_sp_el0 13057356e90SAchin Gupta 13157356e90SAchin Gupta 13257356e90SAchin Gupta /* ----------------------------------------------------- 13357356e90SAchin Gupta * Current EL with SPx: 0x200 - 0x380. Only IRQs/FIQs 13457356e90SAchin Gupta * are expected and handled 13557356e90SAchin Gupta * ----------------------------------------------------- 13657356e90SAchin Gupta */ 13757356e90SAchin Gupta .align 7 13857356e90SAchin Guptasync_exception_sp_elx: 13957356e90SAchin Gupta wfi 14057356e90SAchin Gupta b sync_exception_sp_elx 14157356e90SAchin Gupta check_vector_size sync_exception_sp_elx 14257356e90SAchin Gupta 14357356e90SAchin Gupta .align 7 14457356e90SAchin Guptairq_sp_elx: 145*02446137SSoby Mathew handle_tsp_interrupt irq_sp_elx 14657356e90SAchin Gupta check_vector_size irq_sp_elx 14757356e90SAchin Gupta 14857356e90SAchin Gupta .align 7 14957356e90SAchin Guptafiq_sp_elx: 150*02446137SSoby Mathew handle_tsp_interrupt fiq_sp_elx 15157356e90SAchin Gupta check_vector_size fiq_sp_elx 15257356e90SAchin Gupta 15357356e90SAchin Gupta .align 7 15457356e90SAchin Guptaserror_sp_elx: 15557356e90SAchin Gupta b serror_sp_elx 15657356e90SAchin Gupta check_vector_size serror_sp_elx 15757356e90SAchin Gupta 15857356e90SAchin Gupta 15957356e90SAchin Gupta /* ----------------------------------------------------- 16057356e90SAchin Gupta * Lower EL using AArch64 : 0x400 - 0x580. No exceptions 16157356e90SAchin Gupta * are handled since TSP does not implement a lower EL 16257356e90SAchin Gupta * ----------------------------------------------------- 16357356e90SAchin Gupta */ 16457356e90SAchin Gupta .align 7 16557356e90SAchin Guptasync_exception_aarch64: 16657356e90SAchin Gupta wfi 16757356e90SAchin Gupta b sync_exception_aarch64 16857356e90SAchin Gupta check_vector_size sync_exception_aarch64 16957356e90SAchin Gupta 17057356e90SAchin Gupta .align 7 17157356e90SAchin Guptairq_aarch64: 17257356e90SAchin Gupta b irq_aarch64 17357356e90SAchin Gupta check_vector_size irq_aarch64 17457356e90SAchin Gupta 17557356e90SAchin Gupta .align 7 17657356e90SAchin Guptafiq_aarch64: 17757356e90SAchin Gupta b fiq_aarch64 17857356e90SAchin Gupta check_vector_size fiq_aarch64 17957356e90SAchin Gupta 18057356e90SAchin Gupta .align 7 18157356e90SAchin Guptaserror_aarch64: 18257356e90SAchin Gupta b serror_aarch64 18357356e90SAchin Gupta check_vector_size serror_aarch64 18457356e90SAchin Gupta 18557356e90SAchin Gupta 18657356e90SAchin Gupta /* ----------------------------------------------------- 18757356e90SAchin Gupta * Lower EL using AArch32 : 0x600 - 0x780. No exceptions 18857356e90SAchin Gupta * handled since the TSP does not implement a lower EL. 18957356e90SAchin Gupta * ----------------------------------------------------- 19057356e90SAchin Gupta */ 19157356e90SAchin Gupta .align 7 19257356e90SAchin Guptasync_exception_aarch32: 19357356e90SAchin Gupta wfi 19457356e90SAchin Gupta b sync_exception_aarch32 19557356e90SAchin Gupta check_vector_size sync_exception_aarch32 19657356e90SAchin Gupta 19757356e90SAchin Gupta .align 7 19857356e90SAchin Guptairq_aarch32: 19957356e90SAchin Gupta b irq_aarch32 20057356e90SAchin Gupta check_vector_size irq_aarch32 20157356e90SAchin Gupta 20257356e90SAchin Gupta .align 7 20357356e90SAchin Guptafiq_aarch32: 20457356e90SAchin Gupta b fiq_aarch32 20557356e90SAchin Gupta check_vector_size fiq_aarch32 20657356e90SAchin Gupta 20757356e90SAchin Gupta .align 7 20857356e90SAchin Guptaserror_aarch32: 20957356e90SAchin Gupta b serror_aarch32 21057356e90SAchin Gupta check_vector_size serror_aarch32 21157356e90SAchin Gupta .align 7 212