157356e90SAchin Gupta/* 2*1c3ea103SAntonio Nino Diaz * Copyright (c) 2013-2016, 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 7302446137SSoby Mathew /* ---------------------------------------------------- 7402446137SSoby Mathew * Common TSP interrupt handling routine 7502446137SSoby Mathew * ---------------------------------------------------- 7602446137SSoby Mathew */ 7702446137SSoby Mathew .macro handle_tsp_interrupt label 7802446137SSoby Mathew /* Enable the SError interrupt */ 7902446137SSoby Mathew msr daifclr, #DAIF_ABT_BIT 8002446137SSoby Mathew 8102446137SSoby Mathew save_caller_regs_and_lr 8202446137SSoby Mathew bl tsp_common_int_handler 8302446137SSoby Mathew cbz x0, interrupt_exit_\label 8402446137SSoby Mathew 8502446137SSoby Mathew /* 8602446137SSoby Mathew * This interrupt was not targetted to S-EL1 so send it to 8702446137SSoby Mathew * the monitor and wait for execution to resume. 8802446137SSoby Mathew */ 8902446137SSoby Mathew smc #0 9002446137SSoby Mathewinterrupt_exit_\label: 9102446137SSoby Mathew restore_caller_regs_and_lr 9202446137SSoby Mathew eret 9302446137SSoby Mathew .endm 9402446137SSoby 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: 111*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 11257356e90SAchin Gupta check_vector_size sync_exception_sp_el0 11357356e90SAchin Gupta 11457356e90SAchin Gupta .align 7 11557356e90SAchin Gupta 11657356e90SAchin Guptairq_sp_el0: 117*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 11857356e90SAchin Gupta check_vector_size irq_sp_el0 11957356e90SAchin Gupta 12057356e90SAchin Gupta .align 7 12157356e90SAchin Guptafiq_sp_el0: 122*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 12357356e90SAchin Gupta check_vector_size fiq_sp_el0 12457356e90SAchin Gupta 12557356e90SAchin Gupta .align 7 12657356e90SAchin Guptaserror_sp_el0: 127*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 12857356e90SAchin Gupta check_vector_size serror_sp_el0 12957356e90SAchin Gupta 13057356e90SAchin Gupta 13157356e90SAchin Gupta /* ----------------------------------------------------- 13257356e90SAchin Gupta * Current EL with SPx: 0x200 - 0x380. Only IRQs/FIQs 13357356e90SAchin Gupta * are expected and handled 13457356e90SAchin Gupta * ----------------------------------------------------- 13557356e90SAchin Gupta */ 13657356e90SAchin Gupta .align 7 13757356e90SAchin Guptasync_exception_sp_elx: 138*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 13957356e90SAchin Gupta check_vector_size sync_exception_sp_elx 14057356e90SAchin Gupta 14157356e90SAchin Gupta .align 7 14257356e90SAchin Guptairq_sp_elx: 14302446137SSoby Mathew handle_tsp_interrupt irq_sp_elx 14457356e90SAchin Gupta check_vector_size irq_sp_elx 14557356e90SAchin Gupta 14657356e90SAchin Gupta .align 7 14757356e90SAchin Guptafiq_sp_elx: 14802446137SSoby Mathew handle_tsp_interrupt fiq_sp_elx 14957356e90SAchin Gupta check_vector_size fiq_sp_elx 15057356e90SAchin Gupta 15157356e90SAchin Gupta .align 7 15257356e90SAchin Guptaserror_sp_elx: 153*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 15457356e90SAchin Gupta check_vector_size serror_sp_elx 15557356e90SAchin Gupta 15657356e90SAchin Gupta 15757356e90SAchin Gupta /* ----------------------------------------------------- 15857356e90SAchin Gupta * Lower EL using AArch64 : 0x400 - 0x580. No exceptions 15957356e90SAchin Gupta * are handled since TSP does not implement a lower EL 16057356e90SAchin Gupta * ----------------------------------------------------- 16157356e90SAchin Gupta */ 16257356e90SAchin Gupta .align 7 16357356e90SAchin Guptasync_exception_aarch64: 164*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 16557356e90SAchin Gupta check_vector_size sync_exception_aarch64 16657356e90SAchin Gupta 16757356e90SAchin Gupta .align 7 16857356e90SAchin Guptairq_aarch64: 169*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 17057356e90SAchin Gupta check_vector_size irq_aarch64 17157356e90SAchin Gupta 17257356e90SAchin Gupta .align 7 17357356e90SAchin Guptafiq_aarch64: 174*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 17557356e90SAchin Gupta check_vector_size fiq_aarch64 17657356e90SAchin Gupta 17757356e90SAchin Gupta .align 7 17857356e90SAchin Guptaserror_aarch64: 179*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 18057356e90SAchin Gupta check_vector_size serror_aarch64 18157356e90SAchin Gupta 18257356e90SAchin Gupta 18357356e90SAchin Gupta /* ----------------------------------------------------- 18457356e90SAchin Gupta * Lower EL using AArch32 : 0x600 - 0x780. No exceptions 18557356e90SAchin Gupta * handled since the TSP does not implement a lower EL. 18657356e90SAchin Gupta * ----------------------------------------------------- 18757356e90SAchin Gupta */ 18857356e90SAchin Gupta .align 7 18957356e90SAchin Guptasync_exception_aarch32: 190*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 19157356e90SAchin Gupta check_vector_size sync_exception_aarch32 19257356e90SAchin Gupta 19357356e90SAchin Gupta .align 7 19457356e90SAchin Guptairq_aarch32: 195*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 19657356e90SAchin Gupta check_vector_size irq_aarch32 19757356e90SAchin Gupta 19857356e90SAchin Gupta .align 7 19957356e90SAchin Guptafiq_aarch32: 200*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 20157356e90SAchin Gupta check_vector_size fiq_aarch32 20257356e90SAchin Gupta 20357356e90SAchin Gupta .align 7 20457356e90SAchin Guptaserror_aarch32: 205*1c3ea103SAntonio Nino Diaz bl plat_panic_handler 20657356e90SAchin Gupta check_vector_size serror_aarch32 20757356e90SAchin Gupta .align 7 208