2013-07-12 18:15:23 +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 < l i n u x / i r q c h i p / a r m - g i c - v3 . h >
2013-07-09 13:45:49 +04:00
# include < a s m / a s s e m b l e r . h >
# include < a s m / m e m o r y . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / k v m . h >
# include < a s m / k v m _ a s m . h >
# include < a s m / k v m _ a r m . h >
2013-07-12 18:15:23 +04:00
.text
.pushsection .hyp .text , " ax"
2013-07-09 13:45:49 +04:00
/ *
* We s t o r e L R s i n r e v e r s e o r d e r t o l e t t h e C P U d e a l w i t h s t r e a m i n g
* access. U s e t h i s m a c r o t o m a k e i t l o o k s a n e r . . .
* /
# define L R _ O F F S E T ( n ) ( V G I C _ V 3 _ C P U _ L R + ( 1 5 - n ) * 8 )
/ *
* Save t h e V G I C C P U s t a t e i n t o m e m o r y
* x0 : Register p o i n t i n g t o V C P U s t r u c t
* Do n o t c o r r u p t x1 ! ! !
* /
.macro save_vgic_v3_state
/ / Compute t h e a d d r e s s o f s t r u c t v g i c _ c p u
add x3 , x0 , #V C P U _ V G I C _ C P U
/ / Make s u r e s t o r e s t o t h e G I C v i a t h e m e m o r y m a p p e d i n t e r f a c e
/ / are n o w v i s i b l e t o t h e s y s t e m r e g i s t e r i n t e r f a c e
dsb s t
/ / Save a l l i n t e r e s t i n g r e g i s t e r s
2014-07-31 17:16:39 +04:00
mrs_ s x4 , I C H _ H C R _ E L 2
mrs_ s x5 , I C H _ V M C R _ E L 2
mrs_ s x6 , I C H _ M I S R _ E L 2
mrs_ s x7 , I C H _ E I S R _ E L 2
mrs_ s x8 , I C H _ E L S R _ E L 2
2013-07-09 13:45:49 +04:00
str w4 , [ x3 , #V G I C _ V 3 _ C P U _ H C R ]
str w5 , [ x3 , #V G I C _ V 3 _ C P U _ V M C R ]
str w6 , [ x3 , #V G I C _ V 3 _ C P U _ M I S R ]
str w7 , [ x3 , #V G I C _ V 3 _ C P U _ E I S R ]
str w8 , [ x3 , #V G I C _ V 3 _ C P U _ E L R S R ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ H C R _ E L 2 , x z r
2013-07-09 13:45:49 +04:00
2014-07-31 17:16:39 +04:00
mrs_ s x21 , I C H _ V T R _ E L 2
2013-07-09 13:45:49 +04:00
mvn w22 , w21
ubfiz w23 , w22 , 2 , 4 / / w23 = ( 1 5 - L i s t R e g s ) * 4
adr x24 , 1 f
add x24 , x24 , x23
br x24
1 :
2014-07-31 17:16:39 +04:00
mrs_ s x20 , I C H _ L R 1 5 _ E L 2
mrs_ s x19 , I C H _ L R 1 4 _ E L 2
mrs_ s x18 , I C H _ L R 1 3 _ E L 2
mrs_ s x17 , I C H _ L R 1 2 _ E L 2
mrs_ s x16 , I C H _ L R 1 1 _ E L 2
mrs_ s x15 , I C H _ L R 1 0 _ E L 2
mrs_ s x14 , I C H _ L R 9 _ E L 2
mrs_ s x13 , I C H _ L R 8 _ E L 2
mrs_ s x12 , I C H _ L R 7 _ E L 2
mrs_ s x11 , I C H _ L R 6 _ E L 2
mrs_ s x10 , I C H _ L R 5 _ E L 2
mrs_ s x9 , I C H _ L R 4 _ E L 2
mrs_ s x8 , I C H _ L R 3 _ E L 2
mrs_ s x7 , I C H _ L R 2 _ E L 2
mrs_ s x6 , I C H _ L R 1 _ E L 2
mrs_ s x5 , I C H _ L R 0 _ E L 2
2013-07-09 13:45:49 +04:00
adr x24 , 1 f
add x24 , x24 , x23
br x24
1 :
str x20 , [ x3 , #L R _ O F F S E T ( 15 ) ]
str x19 , [ x3 , #L R _ O F F S E T ( 14 ) ]
str x18 , [ x3 , #L R _ O F F S E T ( 13 ) ]
str x17 , [ x3 , #L R _ O F F S E T ( 12 ) ]
str x16 , [ x3 , #L R _ O F F S E T ( 11 ) ]
str x15 , [ x3 , #L R _ O F F S E T ( 10 ) ]
str x14 , [ x3 , #L R _ O F F S E T ( 9 ) ]
str x13 , [ x3 , #L R _ O F F S E T ( 8 ) ]
str x12 , [ x3 , #L R _ O F F S E T ( 7 ) ]
str x11 , [ x3 , #L R _ O F F S E T ( 6 ) ]
str x10 , [ x3 , #L R _ O F F S E T ( 5 ) ]
str x9 , [ x3 , #L R _ O F F S E T ( 4 ) ]
str x8 , [ x3 , #L R _ O F F S E T ( 3 ) ]
str x7 , [ x3 , #L R _ O F F S E T ( 2 ) ]
str x6 , [ x3 , #L R _ O F F S E T ( 1 ) ]
str x5 , [ x3 , #L R _ O F F S E T ( 0 ) ]
tbnz w21 , #29 , 6 f / / 6 b i t s
tbz w21 , #30 , 5 f / / 5 b i t s
/ / 7 bits
2014-07-31 17:16:39 +04:00
mrs_ s x20 , I C H _ A P 0 R 3 _ E L 2
2013-07-09 13:45:49 +04:00
str w20 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 0 R + 3 * 4 ) ]
2014-07-31 17:16:39 +04:00
mrs_ s x19 , I C H _ A P 0 R 2 _ E L 2
2013-07-09 13:45:49 +04:00
str w19 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 0 R + 2 * 4 ) ]
2014-07-31 17:16:39 +04:00
6 : mrs_ s x18 , I C H _ A P 0 R 1 _ E L 2
2013-07-09 13:45:49 +04:00
str w18 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 0 R + 1 * 4 ) ]
2014-07-31 17:16:39 +04:00
5 : mrs_ s x17 , I C H _ A P 0 R 0 _ E L 2
2013-07-09 13:45:49 +04:00
str w17 , [ x3 , #V G I C _ V 3 _ C P U _ A P 0 R ]
tbnz w21 , #29 , 6 f / / 6 b i t s
tbz w21 , #30 , 5 f / / 5 b i t s
/ / 7 bits
2014-07-31 17:16:39 +04:00
mrs_ s x20 , I C H _ A P 1 R 3 _ E L 2
2013-07-09 13:45:49 +04:00
str w20 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 1 R + 3 * 4 ) ]
2014-07-31 17:16:39 +04:00
mrs_ s x19 , I C H _ A P 1 R 2 _ E L 2
2013-07-09 13:45:49 +04:00
str w19 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 1 R + 2 * 4 ) ]
2014-07-31 17:16:39 +04:00
6 : mrs_ s x18 , I C H _ A P 1 R 1 _ E L 2
2013-07-09 13:45:49 +04:00
str w18 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 1 R + 1 * 4 ) ]
2014-07-31 17:16:39 +04:00
5 : mrs_ s x17 , I C H _ A P 1 R 0 _ E L 2
2013-07-09 13:45:49 +04:00
str w17 , [ x3 , #V G I C _ V 3 _ C P U _ A P 1 R ]
/ / Restore S R E _ E L 1 a c c e s s a n d r e - e n a b l e S R E a t E L 1 .
2014-07-31 17:16:39 +04:00
mrs_ s x5 , I C C _ S R E _ E L 2
2013-07-09 13:45:49 +04:00
orr x5 , x5 , #I C C _ S R E _ E L 2 _ E N A B L E
2014-07-31 17:16:39 +04:00
msr_ s I C C _ S R E _ E L 2 , x5
2013-07-09 13:45:49 +04:00
isb
mov x5 , #1
2014-07-31 17:16:39 +04:00
msr_ s I C C _ S R E _ E L 1 , x5
2013-07-09 13:45:49 +04:00
.endm
/ *
* Restore t h e V G I C C P U s t a t e f r o m m e m o r y
* x0 : Register p o i n t i n g t o V C P U s t r u c t
* /
.macro restore_vgic_v3_state
/ / Disable S R E _ E L 1 a c c e s s . N e c e s s a r y , o t h e r w i s e
/ / ICH_ V M C R _ E L 2 . V F I Q E n b e c o m e s o n e , a n d F I Q h a p p e n s . . .
2014-07-31 17:16:39 +04:00
msr_ s I C C _ S R E _ E L 1 , x z r
2013-07-09 13:45:49 +04:00
isb
/ / Compute t h e a d d r e s s o f s t r u c t v g i c _ c p u
add x3 , x0 , #V C P U _ V G I C _ C P U
/ / Restore a l l i n t e r e s t i n g r e g i s t e r s
ldr w4 , [ x3 , #V G I C _ V 3 _ C P U _ H C R ]
ldr w5 , [ x3 , #V G I C _ V 3 _ C P U _ V M C R ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ H C R _ E L 2 , x4
msr_ s I C H _ V M C R _ E L 2 , x5
2013-07-09 13:45:49 +04:00
2014-07-31 17:16:39 +04:00
mrs_ s x21 , I C H _ V T R _ E L 2
2013-07-09 13:45:49 +04:00
tbnz w21 , #29 , 6 f / / 6 b i t s
tbz w21 , #30 , 5 f / / 5 b i t s
/ / 7 bits
ldr w20 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 1 R + 3 * 4 ) ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 1 R 3 _ E L 2 , x20
2013-07-09 13:45:49 +04:00
ldr w19 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 1 R + 2 * 4 ) ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 1 R 2 _ E L 2 , x19
2013-07-09 13:45:49 +04:00
6 : ldr w18 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 1 R + 1 * 4 ) ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 1 R 1 _ E L 2 , x18
2013-07-09 13:45:49 +04:00
5 : ldr w17 , [ x3 , #V G I C _ V 3 _ C P U _ A P 1 R ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 1 R 0 _ E L 2 , x17
2013-07-09 13:45:49 +04:00
tbnz w21 , #29 , 6 f / / 6 b i t s
tbz w21 , #30 , 5 f / / 5 b i t s
/ / 7 bits
ldr w20 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 0 R + 3 * 4 ) ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 0 R 3 _ E L 2 , x20
2013-07-09 13:45:49 +04:00
ldr w19 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 0 R + 2 * 4 ) ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 0 R 2 _ E L 2 , x19
2013-07-09 13:45:49 +04:00
6 : ldr w18 , [ x3 , #( V G I C _ V 3 _ C P U _ A P 0 R + 1 * 4 ) ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 0 R 1 _ E L 2 , x18
2013-07-09 13:45:49 +04:00
5 : ldr w17 , [ x3 , #V G I C _ V 3 _ C P U _ A P 0 R ]
2014-07-31 17:16:39 +04:00
msr_ s I C H _ A P 0 R 0 _ E L 2 , x17
2013-07-09 13:45:49 +04:00
and w22 , w21 , #0xf
mvn w22 , w21
ubfiz w23 , w22 , 2 , 4 / / w23 = ( 1 5 - L i s t R e g s ) * 4
adr x24 , 1 f
add x24 , x24 , x23
br x24
1 :
ldr x20 , [ x3 , #L R _ O F F S E T ( 15 ) ]
ldr x19 , [ x3 , #L R _ O F F S E T ( 14 ) ]
ldr x18 , [ x3 , #L R _ O F F S E T ( 13 ) ]
ldr x17 , [ x3 , #L R _ O F F S E T ( 12 ) ]
ldr x16 , [ x3 , #L R _ O F F S E T ( 11 ) ]
ldr x15 , [ x3 , #L R _ O F F S E T ( 10 ) ]
ldr x14 , [ x3 , #L R _ O F F S E T ( 9 ) ]
ldr x13 , [ x3 , #L R _ O F F S E T ( 8 ) ]
ldr x12 , [ x3 , #L R _ O F F S E T ( 7 ) ]
ldr x11 , [ x3 , #L R _ O F F S E T ( 6 ) ]
ldr x10 , [ x3 , #L R _ O F F S E T ( 5 ) ]
ldr x9 , [ x3 , #L R _ O F F S E T ( 4 ) ]
ldr x8 , [ x3 , #L R _ O F F S E T ( 3 ) ]
ldr x7 , [ x3 , #L R _ O F F S E T ( 2 ) ]
ldr x6 , [ x3 , #L R _ O F F S E T ( 1 ) ]
ldr x5 , [ x3 , #L R _ O F F S E T ( 0 ) ]
adr x24 , 1 f
add x24 , x24 , x23
br x24
1 :
2014-07-31 17:16:39 +04:00
msr_ s I C H _ L R 1 5 _ E L 2 , x20
msr_ s I C H _ L R 1 4 _ E L 2 , x19
msr_ s I C H _ L R 1 3 _ E L 2 , x18
msr_ s I C H _ L R 1 2 _ E L 2 , x17
msr_ s I C H _ L R 1 1 _ E L 2 , x16
msr_ s I C H _ L R 1 0 _ E L 2 , x15
msr_ s I C H _ L R 9 _ E L 2 , x14
msr_ s I C H _ L R 8 _ E L 2 , x13
msr_ s I C H _ L R 7 _ E L 2 , x12
msr_ s I C H _ L R 6 _ E L 2 , x11
msr_ s I C H _ L R 5 _ E L 2 , x10
msr_ s I C H _ L R 4 _ E L 2 , x9
msr_ s I C H _ L R 3 _ E L 2 , x8
msr_ s I C H _ L R 2 _ E L 2 , x7
msr_ s I C H _ L R 1 _ E L 2 , x6
msr_ s I C H _ L R 0 _ E L 2 , x5
2013-07-09 13:45:49 +04:00
/ / Ensure t h a t t h e a b o v e w i l l h a v e r e a c h e d t h e
/ / ( re) d i s t r i b u t o r s . T h i s e n s u r e t h e g u e s t w i l l r e a d
/ / the c o r r e c t v a l u e s f r o m t h e m e m o r y - m a p p e d i n t e r f a c e .
isb
dsb s y
/ / Prevent t h e g u e s t f r o m t o u c h i n g t h e G I C s y s t e m r e g i s t e r s
2014-07-31 17:16:39 +04:00
mrs_ s x5 , I C C _ S R E _ E L 2
2013-07-09 13:45:49 +04:00
and x5 , x5 , #~ I C C _ S R E _ E L 2 _ E N A B L E
2014-07-31 17:16:39 +04:00
msr_ s I C C _ S R E _ E L 2 , x5
2013-07-09 13:45:49 +04:00
.endm
ENTRY( _ _ s a v e _ v g i c _ v3 _ s t a t e )
save_ v g i c _ v3 _ s t a t e
ret
ENDPROC( _ _ s a v e _ v g i c _ v3 _ s t a t e )
ENTRY( _ _ r e s t o r e _ v g i c _ v3 _ s t a t e )
restore_ v g i c _ v3 _ s t a t e
ret
ENDPROC( _ _ r e s t o r e _ v g i c _ v3 _ s t a t e )
2013-07-12 18:15:23 +04:00
ENTRY( _ _ v g i c _ v3 _ g e t _ i c h _ v t r _ e l 2 )
2014-07-31 17:16:39 +04:00
mrs_ s x0 , I C H _ V T R _ E L 2
2013-07-12 18:15:23 +04:00
ret
ENDPROC( _ _ v g i c _ v3 _ g e t _ i c h _ v t r _ e l 2 )
.popsection