1/* 2 * Hypervisor stub 3 * 4 * Copyright (C) 2012 ARM Ltd. 5 * Author: Marc Zyngier <marc.zyngier@arm.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20#include <linux/init.h> 21#include <linux/linkage.h> 22#include <linux/irqchip/arm-gic-v3.h> 23 24#include <asm/assembler.h> 25#include <asm/ptrace.h> 26#include <asm/virt.h> 27 28 .text 29 .pushsection .hyp.text, "ax" 30 31 .align 11 32 33ENTRY(__hyp_stub_vectors) 34 ventry el2_sync_invalid // Synchronous EL2t 35 ventry el2_irq_invalid // IRQ EL2t 36 ventry el2_fiq_invalid // FIQ EL2t 37 ventry el2_error_invalid // Error EL2t 38 39 ventry el2_sync_invalid // Synchronous EL2h 40 ventry el2_irq_invalid // IRQ EL2h 41 ventry el2_fiq_invalid // FIQ EL2h 42 ventry el2_error_invalid // Error EL2h 43 44 ventry el1_sync // Synchronous 64-bit EL1 45 ventry el1_irq_invalid // IRQ 64-bit EL1 46 ventry el1_fiq_invalid // FIQ 64-bit EL1 47 ventry el1_error_invalid // Error 64-bit EL1 48 49 ventry el1_sync_invalid // Synchronous 32-bit EL1 50 ventry el1_irq_invalid // IRQ 32-bit EL1 51 ventry el1_fiq_invalid // FIQ 32-bit EL1 52 ventry el1_error_invalid // Error 32-bit EL1 53ENDPROC(__hyp_stub_vectors) 54 55 .align 11 56 57el1_sync: 58 mrs x1, esr_el2 59 lsr x1, x1, #26 60 cmp x1, #0x16 61 b.ne 2f // Not an HVC trap 62 cbz x0, 1f 63 msr vbar_el2, x0 // Set vbar_el2 64 b 2f 651: mrs x0, vbar_el2 // Return vbar_el2 662: eret 67ENDPROC(el1_sync) 68 69.macro invalid_vector label 70\label: 71 b \label 72ENDPROC(\label) 73.endm 74 75 invalid_vector el2_sync_invalid 76 invalid_vector el2_irq_invalid 77 invalid_vector el2_fiq_invalid 78 invalid_vector el2_error_invalid 79 invalid_vector el1_sync_invalid 80 invalid_vector el1_irq_invalid 81 invalid_vector el1_fiq_invalid 82 invalid_vector el1_error_invalid 83 84/* 85 * __hyp_set_vectors: Call this after boot to set the initial hypervisor 86 * vectors as part of hypervisor installation. On an SMP system, this should 87 * be called on each CPU. 88 * 89 * x0 must be the physical address of the new vector table, and must be 90 * 2KB aligned. 91 * 92 * Before calling this, you must check that the stub hypervisor is installed 93 * everywhere, by waiting for any secondary CPUs to be brought up and then 94 * checking that is_hyp_mode_available() is true. 95 * 96 * If not, there is a pre-existing hypervisor, some CPUs failed to boot, or 97 * something else went wrong... in such cases, trying to install a new 98 * hypervisor is unlikely to work as desired. 99 * 100 * When you call into your shiny new hypervisor, sp_el2 will contain junk, 101 * so you will need to set that to something sensible at the new hypervisor's 102 * initialisation entry point. 103 */ 104 105ENTRY(__hyp_get_vectors) 106 mov x0, xzr 107 // fall through 108ENTRY(__hyp_set_vectors) 109 hvc #0 110 ret 111ENDPROC(__hyp_get_vectors) 112ENDPROC(__hyp_set_vectors) 113