2012-12-17 21:07:52 +04:00
/ *
* Copyright ( C ) 2 0 1 2 ,2 0 1 3 - A R M L t d
* Author : Marc Z y n g i e r < m a r c . z y n g i e r @arm.com>
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify
* it u n d e r t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e , v e r s i o n 2 , a s
* published b y t h e F r e e S o f t w a r e F o u n d a t i o n .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y o f t h e G N U G e n e r a l P u b l i c L i c e n s e
* along w i t h t h i s p r o g r a m . I f n o t , s e e < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > .
* /
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
# include < a s m / k v m _ a r m . h >
# include < a s m / k v m _ m m u . h >
.text
.pushsection .hyp .idmap .text , " ax"
.align 11
ENTRY( _ _ k v m _ h y p _ i n i t )
ventry _ _ i n v a l i d / / S y n c h r o n o u s E L 2 t
ventry _ _ i n v a l i d / / I R Q E L 2 t
ventry _ _ i n v a l i d / / F I Q E L 2 t
ventry _ _ i n v a l i d / / E r r o r E L 2 t
ventry _ _ i n v a l i d / / S y n c h r o n o u s E L 2 h
ventry _ _ i n v a l i d / / I R Q E L 2 h
ventry _ _ i n v a l i d / / F I Q E L 2 h
ventry _ _ i n v a l i d / / E r r o r E L 2 h
ventry _ _ d o _ h y p _ i n i t / / S y n c h r o n o u s 6 4 - b i t E L 1
ventry _ _ i n v a l i d / / I R Q 6 4 - b i t E L 1
ventry _ _ i n v a l i d / / F I Q 6 4 - b i t E L 1
ventry _ _ i n v a l i d / / E r r o r 6 4 - b i t E L 1
ventry _ _ i n v a l i d / / S y n c h r o n o u s 3 2 - b i t E L 1
ventry _ _ i n v a l i d / / I R Q 3 2 - b i t E L 1
ventry _ _ i n v a l i d / / F I Q 3 2 - b i t E L 1
ventry _ _ i n v a l i d / / E r r o r 3 2 - b i t E L 1
__invalid :
b .
/ *
* x0 : HYP b o o t p g d
* x1 : HYP p g d
* x2 : HYP s t a c k
* x3 : HYP v e c t o r s
* /
__do_hyp_init :
msr t t b r0 _ e l 2 , x0
mrs x4 , t c r _ e l 1
ldr x5 , =TCR_EL2_MASK
and x4 , x4 , x5
ldr x5 , =TCR_EL2_FLAGS
orr x4 , x4 , x5
msr t c r _ e l 2 , x4
ldr x4 , =VTCR_EL2_FLAGS
2014-03-07 12:49:25 +04:00
/ *
* Read t h e P A R a n g e b i t s f r o m I D _ A A 6 4 M M F R 0 _ E L 1 a n d s e t t h e P S b i t s i n
* VTCR_ E L 2 .
* /
mrs x5 , I D _ A A 6 4 M M F R 0 _ E L 1
bfi x4 , x5 , #16 , #3
2012-12-17 21:07:52 +04:00
msr v t c r _ e l 2 , x4
mrs x4 , m a i r _ e l 1
msr m a i r _ e l 2 , x4
isb
2014-07-31 10:53:23 +04:00
/* Invalidate the stale TLBs from Bootloader */
tlbi a l l e 2
dsb s y
2013-11-05 22:29:45 +04:00
mrs x4 , s c t l r _ e l 2
and x4 , x4 , #S C T L R _ E L 2 _ E E / / p r e s e r v e e n d i a n n e s s o f E L 2
ldr x5 , =SCTLR_EL2_FLAGS
orr x4 , x4 , x5
2012-12-17 21:07:52 +04:00
msr s c t l r _ e l 2 , x4
isb
/* MMU is now enabled. Get ready for the trampoline dance */
ldr x4 , =TRAMPOLINE_VA
adr x5 , t a r g e t
bfi x4 , x5 , #0 , #P A G E _ S H I F T
br x4
target : /* We're now in the trampoline code, switch page tables */
msr t t b r0 _ e l 2 , x1
isb
/* Invalidate the old TLBs */
tlbi a l l e 2
dsb s y
/* Set the stack and new vectors */
kern_ h y p _ v a x2
mov s p , x2
kern_ h y p _ v a x3
msr v b a r _ e l 2 , x3
/* Hello, World! */
eret
ENDPROC( _ _ k v m _ h y p _ i n i t )
.ltorg
.popsection