Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
[pandora-kernel.git] / arch / arm / kvm / init.S
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  */
18
19 #include <linux/linkage.h>
20 #include <asm/unified.h>
21 #include <asm/asm-offsets.h>
22 #include <asm/kvm_asm.h>
23 #include <asm/kvm_arm.h>
24
25 /********************************************************************
26  * Hypervisor initialization
27  *   - should be called with:
28  *       r0,r1 = Hypervisor pgd pointer
29  *       r2 = top of Hyp stack (kernel VA)
30  *       r3 = pointer to hyp vectors
31  */
32
33         .text
34         .pushsection    .hyp.idmap.text,"ax"
35         .align 5
36 __kvm_hyp_init:
37         .globl __kvm_hyp_init
38
39         @ Hyp-mode exception vector
40         W(b)    .
41         W(b)    .
42         W(b)    .
43         W(b)    .
44         W(b)    .
45         W(b)    __do_hyp_init
46         W(b)    .
47         W(b)    .
48
49 __do_hyp_init:
50         @ Set the HTTBR to point to the hypervisor PGD pointer passed
51         mcrr    p15, 4, r0, r1, c2
52
53         @ Set the HTCR and VTCR to the same shareability and cacheability
54         @ settings as the non-secure TTBCR and with T0SZ == 0.
55         mrc     p15, 4, r0, c2, c0, 2   @ HTCR
56         ldr     r12, =HTCR_MASK
57         bic     r0, r0, r12
58         mrc     p15, 0, r1, c2, c0, 2   @ TTBCR
59         and     r1, r1, #(HTCR_MASK & ~TTBCR_T0SZ)
60         orr     r0, r0, r1
61         mcr     p15, 4, r0, c2, c0, 2   @ HTCR
62
63         mrc     p15, 4, r1, c2, c1, 2   @ VTCR
64         ldr     r12, =VTCR_MASK
65         bic     r1, r1, r12
66         bic     r0, r0, #(~VTCR_HTCR_SH)        @ clear non-reusable HTCR bits
67         orr     r1, r0, r1
68         orr     r1, r1, #(KVM_VTCR_SL0 | KVM_VTCR_T0SZ | KVM_VTCR_S)
69         mcr     p15, 4, r1, c2, c1, 2   @ VTCR
70
71         @ Use the same memory attributes for hyp. accesses as the kernel
72         @ (copy MAIRx ro HMAIRx).
73         mrc     p15, 0, r0, c10, c2, 0
74         mcr     p15, 4, r0, c10, c2, 0
75         mrc     p15, 0, r0, c10, c2, 1
76         mcr     p15, 4, r0, c10, c2, 1
77
78         @ Set the HSCTLR to:
79         @  - ARM/THUMB exceptions: Kernel config (Thumb-2 kernel)
80         @  - Endianness: Kernel config
81         @  - Fast Interrupt Features: Kernel config
82         @  - Write permission implies XN: disabled
83         @  - Instruction cache: enabled
84         @  - Data/Unified cache: enabled
85         @  - Memory alignment checks: enabled
86         @  - MMU: enabled (this code must be run from an identity mapping)
87         mrc     p15, 4, r0, c1, c0, 0   @ HSCR
88         ldr     r12, =HSCTLR_MASK
89         bic     r0, r0, r12
90         mrc     p15, 0, r1, c1, c0, 0   @ SCTLR
91         ldr     r12, =(HSCTLR_EE | HSCTLR_FI | HSCTLR_I | HSCTLR_C)
92         and     r1, r1, r12
93  ARM(   ldr     r12, =(HSCTLR_M | HSCTLR_A)                     )
94  THUMB( ldr     r12, =(HSCTLR_M | HSCTLR_A | HSCTLR_TE)         )
95         orr     r1, r1, r12
96         orr     r0, r0, r1
97         isb
98         mcr     p15, 4, r0, c1, c0, 0   @ HSCR
99         isb
100
101         @ Set stack pointer and return to the kernel
102         mov     sp, r2
103
104         @ Set HVBAR to point to the HYP vectors
105         mcr     p15, 4, r3, c12, c0, 0  @ HVBAR
106
107         eret
108
109         .ltorg
110
111         .globl __kvm_hyp_init_end
112 __kvm_hyp_init_end:
113
114         .popsection