Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 - Virtual Open Systems and Columbia University |
| 3 | * Author: Christoffer Dall <c.dall@virtualopensystems.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License, version 2, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | */ |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 18 | |
| 19 | #include <linux/linkage.h> |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 20 | #include <asm/assembler.h> |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 21 | #include <asm/unified.h> |
Christoffer Dall | 749cf76c | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 22 | #include <asm/asm-offsets.h> |
| 23 | #include <asm/kvm_asm.h> |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 24 | #include <asm/kvm_arm.h> |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 25 | #include <asm/kvm_mmu.h> |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 26 | |
| 27 | /******************************************************************** |
| 28 | * Hypervisor initialization |
| 29 | * - should be called with: |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 30 | * r0 = top of Hyp stack (kernel VA) |
| 31 | * r1 = pointer to hyp vectors |
| 32 | * r2,r3 = Hypervisor pgd pointer |
| 33 | * |
| 34 | * The init scenario is: |
Marc Zyngier | cd602a3 | 2016-06-30 18:40:47 +0100 | [diff] [blame^] | 35 | * - We jump in HYP with 3 parameters: runtime HYP pgd, runtime stack, |
| 36 | * runtime vectors |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 37 | * - Invalidate TLBs |
| 38 | * - Set stack and vectors |
Marc Zyngier | cd602a3 | 2016-06-30 18:40:47 +0100 | [diff] [blame^] | 39 | * - Setup the page tables |
| 40 | * - Enable the MMU |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 41 | * - Profit! (or eret, if you only care about the code). |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 42 | */ |
| 43 | |
| 44 | .text |
| 45 | .pushsection .hyp.idmap.text,"ax" |
| 46 | .align 5 |
| 47 | __kvm_hyp_init: |
| 48 | .globl __kvm_hyp_init |
| 49 | |
| 50 | @ Hyp-mode exception vector |
| 51 | W(b) . |
| 52 | W(b) . |
| 53 | W(b) . |
| 54 | W(b) . |
| 55 | W(b) . |
| 56 | W(b) __do_hyp_init |
| 57 | W(b) . |
| 58 | W(b) . |
| 59 | |
| 60 | __do_hyp_init: |
Marc Zyngier | cd602a3 | 2016-06-30 18:40:47 +0100 | [diff] [blame^] | 61 | @ Set stack pointer |
| 62 | mov sp, r0 |
| 63 | |
| 64 | @ Set HVBAR to point to the HYP vectors |
| 65 | mcr p15, 4, r1, c12, c0, 0 @ HVBAR |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 66 | |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 67 | @ Set the HTTBR to point to the hypervisor PGD pointer passed |
Victor Kamensky | 19b0e60 | 2014-06-12 09:30:02 -0700 | [diff] [blame] | 68 | mcrr p15, 4, rr_lo_hi(r2, r3), c2 |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 69 | |
| 70 | @ Set the HTCR and VTCR to the same shareability and cacheability |
| 71 | @ settings as the non-secure TTBCR and with T0SZ == 0. |
| 72 | mrc p15, 4, r0, c2, c0, 2 @ HTCR |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 73 | ldr r2, =HTCR_MASK |
| 74 | bic r0, r0, r2 |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 75 | mrc p15, 0, r1, c2, c0, 2 @ TTBCR |
| 76 | and r1, r1, #(HTCR_MASK & ~TTBCR_T0SZ) |
| 77 | orr r0, r0, r1 |
| 78 | mcr p15, 4, r0, c2, c0, 2 @ HTCR |
| 79 | |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 80 | @ Use the same memory attributes for hyp. accesses as the kernel |
| 81 | @ (copy MAIRx ro HMAIRx). |
| 82 | mrc p15, 0, r0, c10, c2, 0 |
| 83 | mcr p15, 4, r0, c10, c2, 0 |
| 84 | mrc p15, 0, r0, c10, c2, 1 |
| 85 | mcr p15, 4, r0, c10, c2, 1 |
| 86 | |
Pranavkumar Sawargaonkar | f6edbbf | 2014-07-31 12:23:23 +0530 | [diff] [blame] | 87 | @ Invalidate the stale TLBs from Bootloader |
| 88 | mcr p15, 4, r0, c8, c7, 0 @ TLBIALLH |
| 89 | dsb ish |
| 90 | |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 91 | @ Set the HSCTLR to: |
| 92 | @ - ARM/THUMB exceptions: Kernel config (Thumb-2 kernel) |
| 93 | @ - Endianness: Kernel config |
| 94 | @ - Fast Interrupt Features: Kernel config |
| 95 | @ - Write permission implies XN: disabled |
| 96 | @ - Instruction cache: enabled |
| 97 | @ - Data/Unified cache: enabled |
| 98 | @ - Memory alignment checks: enabled |
| 99 | @ - MMU: enabled (this code must be run from an identity mapping) |
| 100 | mrc p15, 4, r0, c1, c0, 0 @ HSCR |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 101 | ldr r2, =HSCTLR_MASK |
| 102 | bic r0, r0, r2 |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 103 | mrc p15, 0, r1, c1, c0, 0 @ SCTLR |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 104 | ldr r2, =(HSCTLR_EE | HSCTLR_FI | HSCTLR_I | HSCTLR_C) |
| 105 | and r1, r1, r2 |
| 106 | ARM( ldr r2, =(HSCTLR_M | HSCTLR_A) ) |
| 107 | THUMB( ldr r2, =(HSCTLR_M | HSCTLR_A | HSCTLR_TE) ) |
| 108 | orr r1, r1, r2 |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 109 | orr r0, r0, r1 |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 110 | mcr p15, 4, r0, c1, c0, 0 @ HSCR |
Marc Zyngier | 5a677ce | 2013-04-12 19:12:06 +0100 | [diff] [blame] | 111 | isb |
| 112 | |
Christoffer Dall | 342cd0a | 2013-01-20 18:28:06 -0500 | [diff] [blame] | 113 | eret |
| 114 | |
| 115 | .ltorg |
| 116 | |
| 117 | .globl __kvm_hyp_init_end |
| 118 | __kvm_hyp_init_end: |
| 119 | |
| 120 | .popsection |