2020-05-04 14:42:36 +01:00
/* SPDX-License-Identifier: GPL-2.0-only */
/ *
* Copyright ( C ) 2 0 2 0 A R M L t d .
* /
# include < l i n u x / l i n k a g e . h >
2020-10-26 13:31:47 +00:00
# include < a s m / a s m - u a c c e s s . h >
2020-05-04 14:42:36 +01:00
# include < a s m / a s s e m b l e r . h >
2020-03-30 10:29:38 +01:00
# include < a s m / m t e . h >
2019-08-06 11:37:53 +01:00
# include < a s m / p a g e . h >
2020-05-04 14:42:36 +01:00
# include < a s m / s y s r e g . h >
.arch armv8 . 5 - a + m e m t a g
/ *
* multitag_ t r a n s f e r _ s i z e - s e t \ r e g t o t h e b l o c k s i z e t h a t i s a c c e s s e d b y t h e
* LDGM/ S T G M i n s t r u c t i o n s .
* /
.macro multitag_ t r a n s f e r _ s i z e , r e g , t m p
mrs_ s \ r e g , S Y S _ G M I D _ E L 1
ubfx \ r e g , \ r e g , #S Y S _ G M I D _ E L 1 _ B S _ S H I F T , #S Y S _ G M I D _ E L 1 _ B S _ S I Z E
mov \ t m p , #4
lsl \ r e g , \ t m p , \ r e g
.endm
/ *
* Clear t h e t a g s i n a p a g e
* x0 - a d d r e s s o f t h e p a g e t o b e c l e a r e d
* /
SYM_ F U N C _ S T A R T ( m t e _ c l e a r _ p a g e _ t a g s )
multitag_ t r a n s f e r _ s i z e x1 , x2
1 : stgm x z r , [ x0 ]
add x0 , x0 , x1
tst x0 , #( P A G E _ S I Z E - 1 )
b. n e 1 b
ret
SYM_ F U N C _ E N D ( m t e _ c l e a r _ p a g e _ t a g s )
2019-08-06 11:37:53 +01:00
/ *
* Copy t h e t a g s f r o m t h e s o u r c e p a g e t o t h e d e s t i n a t i o n o n e
* x0 - a d d r e s s o f t h e d e s t i n a t i o n p a g e
* x1 - a d d r e s s o f t h e s o u r c e p a g e
* /
SYM_ F U N C _ S T A R T ( m t e _ c o p y _ p a g e _ t a g s )
mov x2 , x0
mov x3 , x1
multitag_ t r a n s f e r _ s i z e x5 , x6
1 : ldgm x4 , [ x3 ]
stgm x4 , [ x2 ]
add x2 , x2 , x5
add x3 , x3 , x5
tst x2 , #( P A G E _ S I Z E - 1 )
b. n e 1 b
ret
SYM_ F U N C _ E N D ( m t e _ c o p y _ p a g e _ t a g s )
2020-03-30 10:29:38 +01:00
/ *
* Read t a g s f r o m a u s e r b u f f e r ( o n e t a g p e r b y t e ) a n d s e t t h e c o r r e s p o n d i n g
* tags a t t h e g i v e n k e r n e l a d d r e s s . U s e d b y P T R A C E _ P O K E M T E T A G S .
* x0 - k e r n e l a d d r e s s ( t o )
* x1 - u s e r b u f f e r ( f r o m )
* x2 - n u m b e r o f t a g s / b y t e s ( n )
* Returns :
* x0 - n u m b e r o f t a g s r e a d / s e t
* /
SYM_ F U N C _ S T A R T ( m t e _ c o p y _ t a g s _ f r o m _ u s e r )
mov x3 , x1
cbz x2 , 2 f
1 :
2020-12-02 13:15:54 +00:00
user_ l d s t 2 f , l d t r b , w4 , x1 , 0
2020-03-30 10:29:38 +01:00
lsl x4 , x4 , #M T E _ T A G _ S H I F T
stg x4 , [ x0 ] , #M T E _ G R A N U L E _ S I Z E
add x1 , x1 , #1
subs x2 , x2 , #1
b. n e 1 b
/ / exception h a n d l i n g a n d f u n c t i o n r e t u r n
2 : sub x0 , x1 , x3 / / u p d a t e t h e n u m b e r o f t a g s s e t
ret
SYM_ F U N C _ E N D ( m t e _ c o p y _ t a g s _ f r o m _ u s e r )
/ *
* Get t h e t a g s f r o m a k e r n e l a d d r e s s r a n g e a n d w r i t e t h e t a g v a l u e s t o t h e
* given u s e r b u f f e r ( o n e t a g p e r b y t e ) . U s e d b y P T R A C E _ P E E K M T E T A G S .
* x0 - u s e r b u f f e r ( t o )
* x1 - k e r n e l a d d r e s s ( f r o m )
* x2 - n u m b e r o f t a g s / b y t e s ( n )
* Returns :
* x0 - n u m b e r o f t a g s r e a d / s e t
* /
SYM_ F U N C _ S T A R T ( m t e _ c o p y _ t a g s _ t o _ u s e r )
mov x3 , x0
cbz x2 , 2 f
1 :
ldg x4 , [ x1 ]
ubfx x4 , x4 , #M T E _ T A G _ S H I F T , # M T E _ T A G _ S I Z E
2020-12-02 13:15:54 +00:00
user_ l d s t 2 f , s t t r b , w4 , x0 , 0
2020-03-30 10:29:38 +01:00
add x0 , x0 , #1
add x1 , x1 , #M T E _ G R A N U L E _ S I Z E
subs x2 , x2 , #1
b. n e 1 b
/ / exception h a n d l i n g a n d f u n c t i o n r e t u r n
2 : sub x0 , x0 , x3 / / u p d a t e t h e n u m b e r o f t a g s c o p i e d
ret
SYM_ F U N C _ E N D ( m t e _ c o p y _ t a g s _ t o _ u s e r )
2020-05-13 16:37:50 +01:00
/ *
* Save t h e t a g s i n a p a g e
* x0 - p a g e a d d r e s s
* x1 - t a g s t o r a g e
* /
SYM_ F U N C _ S T A R T ( m t e _ s a v e _ p a g e _ t a g s )
multitag_ t r a n s f e r _ s i z e x7 , x5
1 :
mov x2 , #0
2 :
ldgm x5 , [ x0 ]
orr x2 , x2 , x5
add x0 , x0 , x7
tst x0 , #0xFF / / 1 6 t a g v a l u e s f i t i n a r e g i s t e r ,
b. n e 2 b / / w h i c h i s 1 6 * 1 6 =256 b y t e s
str x2 , [ x1 ] , #8
tst x0 , #( P A G E _ S I Z E - 1 )
b. n e 1 b
ret
SYM_ F U N C _ E N D ( m t e _ s a v e _ p a g e _ t a g s )
/ *
* Restore t h e t a g s i n a p a g e
* x0 - p a g e a d d r e s s
* x1 - t a g s t o r a g e
* /
SYM_ F U N C _ S T A R T ( m t e _ r e s t o r e _ p a g e _ t a g s )
multitag_ t r a n s f e r _ s i z e x7 , x5
1 :
ldr x2 , [ x1 ] , #8
2 :
stgm x2 , [ x0 ]
add x0 , x0 , x7
tst x0 , #0xFF
b. n e 2 b
tst x0 , #( P A G E _ S I Z E - 1 )
b. n e 1 b
ret
SYM_ F U N C _ E N D ( m t e _ r e s t o r e _ p a g e _ t a g s )