2012-10-19 17:46:27 +01:00
/ *
* Hypervisor s t u b
*
* Copyright ( C ) 2 0 1 2 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 / i n i t . h >
# include < l i n u x / l i n k a g e . h >
2014-06-30 16:01:31 +01:00
# include < l i n u x / i r q c h i p / a r m - g i c - v3 . h >
2012-10-19 17:46:27 +01:00
# include < a s m / a s s e m b l e r . h >
2016-04-27 17:47:03 +01:00
# include < a s m / k v m _ a r m . h >
2016-04-27 17:47:04 +01:00
# include < a s m / k v m _ a s m . h >
2012-10-19 17:46:27 +01:00
# include < a s m / p t r a c e . h >
# include < a s m / v i r t . h >
.text
.align 11
ENTRY( _ _ h y p _ s t u b _ v e c t o r s )
ventry e l 2 _ s y n c _ i n v a l i d / / S y n c h r o n o u s E L 2 t
ventry e l 2 _ i r q _ i n v a l i d / / I R Q E L 2 t
ventry e l 2 _ f i q _ i n v a l i d / / F I Q E L 2 t
ventry e l 2 _ e r r o r _ i n v a l i d / / E r r o r E L 2 t
ventry e l 2 _ s y n c _ i n v a l i d / / S y n c h r o n o u s E L 2 h
ventry e l 2 _ i r q _ i n v a l i d / / I R Q E L 2 h
ventry e l 2 _ f i q _ i n v a l i d / / F I Q E L 2 h
ventry e l 2 _ e r r o r _ i n v a l i d / / E r r o r E L 2 h
ventry e l 1 _ s y n c / / S y n c h r o n o u s 6 4 - b i t E L 1
ventry e l 1 _ i r q _ i n v a l i d / / I R Q 6 4 - b i t E L 1
ventry e l 1 _ f i q _ i n v a l i d / / F I Q 6 4 - b i t E L 1
ventry e l 1 _ e r r o r _ i n v a l i d / / E r r o r 6 4 - b i t E L 1
ventry e l 1 _ s y n c _ 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 e l 1 _ i r q _ i n v a l i d / / I R Q 3 2 - b i t E L 1
ventry e l 1 _ f i q _ i n v a l i d / / F I Q 3 2 - b i t E L 1
ventry e l 1 _ e r r o r _ i n v a l i d / / E r r o r 3 2 - b i t E L 1
ENDPROC( _ _ h y p _ s t u b _ v e c t o r s )
.align 11
el1_sync :
2016-04-27 17:47:03 +01:00
mrs x30 , e s r _ e l 2
lsr x30 , x30 , #E S R _ E L x _ E C _ S H I F T
cmp x30 , #E S R _ E L x _ E C _ H V C 64
b. n e 9 f / / N o t a n H V C t r a p
cmp x0 , #H V C _ G E T _ V E C T O R S
b. n e 1 f
mrs x0 , v b a r _ e l 2
b 9 f
1 : cmp x0 , #H V C _ S E T _ V E C T O R S
b. n e 2 f
msr v b a r _ e l 2 , x1
b 9 f
2016-06-23 17:54:48 +00:00
2 : cmp x0 , #H V C _ S O F T _ R E S T A R T
b. n e 3 f
mov x0 , x2
mov x2 , x4
mov x4 , x1
mov x1 , x3
br x4 / / n o r e t u r n
2016-04-27 17:47:04 +01:00
/* Someone called kvm_call_hyp() against the hyp-stub... */
2016-06-23 17:54:48 +00:00
3 : mov x0 , #A R M _ E X C E P T I O N _ H Y P _ G O N E
2016-04-27 17:47:03 +01:00
9 : eret
2012-10-19 17:46:27 +01:00
ENDPROC( e l 1 _ s y n c )
.macro invalid_vector label
\ label :
b \ l a b e l
ENDPROC( \ l a b e l )
.endm
invalid_ v e c t o r e l 2 _ s y n c _ i n v a l i d
invalid_ v e c t o r e l 2 _ i r q _ i n v a l i d
invalid_ v e c t o r e l 2 _ f i q _ i n v a l i d
invalid_ v e c t o r e l 2 _ e r r o r _ i n v a l i d
invalid_ v e c t o r e l 1 _ s y n c _ i n v a l i d
invalid_ v e c t o r e l 1 _ i r q _ i n v a l i d
invalid_ v e c t o r e l 1 _ f i q _ i n v a l i d
invalid_ v e c t o r e l 1 _ e r r o r _ i n v a l i d
/ *
* __hyp_set_vectors : Call t h i s a f t e r b o o t t o s e t t h e i n i t i a l h y p e r v i s o r
* vectors a s p a r t o f h y p e r v i s o r i n s t a l l a t i o n . O n a n S M P s y s t e m , t h i s s h o u l d
* be c a l l e d o n e a c h C P U .
*
* x0 m u s t b e t h e p h y s i c a l a d d r e s s o f t h e n e w v e c t o r t a b l e , a n d m u s t b e
* 2 KB a l i g n e d .
*
* Before c a l l i n g t h i s , y o u m u s t c h e c k t h a t t h e s t u b h y p e r v i s o r i s i n s t a l l e d
* everywhere, b y w a i t i n g f o r a n y s e c o n d a r y C P U s t o b e b r o u g h t u p a n d t h e n
* checking t h a t i s _ h y p _ m o d e _ a v a i l a b l e ( ) i s t r u e .
*
* If n o t , t h e r e i s a p r e - e x i s t i n g h y p e r v i s o r , s o m e C P U s f a i l e d t o b o o t , o r
* something e l s e w e n t w r o n g . . . i n s u c h c a s e s , t r y i n g t o i n s t a l l a n e w
* hypervisor i s u n l i k e l y t o w o r k a s d e s i r e d .
*
* When y o u c a l l i n t o y o u r s h i n y n e w h y p e r v i s o r , s p _ e l 2 w i l l c o n t a i n j u n k ,
* so y o u w i l l n e e d t o s e t t h a t t o s o m e t h i n g s e n s i b l e a t t h e n e w h y p e r v i s o r ' s
* initialisation e n t r y p o i n t .
* /
ENTRY( _ _ h y p _ g e t _ v e c t o r s )
2016-04-27 17:47:02 +01:00
str l r , [ s p , #- 16 ] !
2016-04-27 17:47:03 +01:00
mov x0 , #H V C _ G E T _ V E C T O R S
2012-10-19 17:46:27 +01:00
hvc #0
2016-04-27 17:47:02 +01:00
ldr l r , [ s p ] , #16
2012-10-19 17:46:27 +01:00
ret
ENDPROC( _ _ h y p _ g e t _ v e c t o r s )
2016-04-27 17:47:02 +01:00
ENTRY( _ _ h y p _ s e t _ v e c t o r s )
str l r , [ s p , #- 16 ] !
2016-04-27 17:47:03 +01:00
mov x1 , x0
mov x0 , #H V C _ S E T _ V E C T O R S
2016-04-27 17:47:02 +01:00
hvc #0
ldr l r , [ s p ] , #16
ret
2012-10-19 17:46:27 +01:00
ENDPROC( _ _ h y p _ s e t _ v e c t o r s )