2012-12-17 17:07:52 +00: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 >
2015-03-19 16:42:28 +00:00
# include < a s m / p g t a b l e - h w d e f . h >
2012-12-17 17:07:52 +00:00
.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
2015-03-19 16:42:28 +00:00
# ifndef C O N F I G _ A R M 6 4 _ V A _ B I T S _ 4 8
/ *
* If w e a r e r u n n i n g w i t h V A _ B I T S < 4 8 , w e m a y b e r u n n i n g w i t h a n e x t r a
* level o f t r a n s l a t i o n i n t h e I D m a p . T h i s i s o n l y t h e c a s e i f s y s t e m
* RAM i s o u t o f r a n g e f o r t h e c u r r e n t l y c o n f i g u r e d p a g e s i z e a n d n u m b e r
* of t r a n s l a t i o n l e v e l s , i n w h i c h c a s e w e w i l l a l s o n e e d t h e e x t r a
* level f o r t h e H Y P I D m a p , o r w e w o n ' t b e a b l e t o e n a b l e t h e E L 2 M M U .
*
* However, a t E L 2 , t h e r e i s o n l y o n e T T B R r e g i s t e r , a n d w e c a n ' t s w i t c h
* between t r a n s l a t i o n t a b l e s * a n d * u p d a t e T C R _ E L 2 . T 0 S Z a t t h e s a m e
* time. B o t t o m l i n e : w e n e e d t h e e x t r a l e v e l i n * b o t h * o u r t r a n s l a t i o n
* tables.
*
* So u s e t h e s a m e T 0 S Z v a l u e w e u s e f o r t h e I D m a p .
* /
ldr_ l x5 , i d m a p _ t 0 s z
bfi x4 , x5 , T C R _ T 0 S Z _ O F F S E T , T C R _ T x S Z _ W I D T H
# endif
2012-12-17 17:07:52 +00:00
msr t c r _ e l 2 , x4
ldr x4 , =VTCR_EL2_FLAGS
2014-03-07 08:49:25 +00: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 17:07:52 +00: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 12:23:23 +05:30
/* Invalidate the stale TLBs from Bootloader */
tlbi a l l e 2
dsb s y
2013-11-05 18:29:45 +00: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 17:07:52 +00:00
msr s c t l r _ e l 2 , x4
isb
2015-03-19 16:42:28 +00:00
/* Skip the trampoline dance if we merged the boot and runtime PGDs */
cmp x0 , x1
b. e q m e r g e d
2012-12-17 17:07:52 +00:00
/* 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
2015-03-19 16:42:28 +00:00
merged :
2012-12-17 17:07:52 +00:00
/* 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