2019-06-03 08:44:50 +03:00
/* SPDX-License-Identifier: GPL-2.0-only */
2012-03-05 15:49:28 +04:00
/ *
* Cache m a i n t e n a n c e
*
* Copyright ( C ) 2 0 0 1 D e e p B l u e S o l u t i o n s L t d .
* Copyright ( C ) 2 0 1 2 A R M L t d .
* /
2014-12-01 13:53:08 +03:00
# include < l i n u x / e r r n o . h >
2012-03-05 15:49:28 +04:00
# include < l i n u x / l i n k a g e . h >
# include < l i n u x / i n i t . h >
# include < a s m / a s s e m b l e r . h >
2014-11-14 18:54:10 +03:00
# include < a s m / c p u f e a t u r e . h >
2015-06-01 12:47:41 +03:00
# include < a s m / a l t e r n a t i v e . h >
2016-12-26 12:10:19 +03:00
# include < a s m / a s m - u a c c e s s . h >
2012-03-05 15:49:28 +04:00
/ *
* flush_ i c a c h e _ r a n g e ( s t a r t ,e n d )
*
* Ensure t h a t t h e I a n d D c a c h e s a r e c o h e r e n t w i t h i n s p e c i f i e d r e g i o n .
* This i s t y p i c a l l y u s e d w h e n c o d e h a s b e e n w r i t t e n t o a m e m o r y r e g i o n ,
* and w i l l b e e x e c u t e d .
*
* - start - v i r t u a l s t a r t a d d r e s s o f r e g i o n
* - end - v i r t u a l e n d a d d r e s s o f r e g i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T ( _ _ f l u s h _ i c a c h e _ r a n g e )
2012-03-05 15:49:28 +04:00
/* FALLTHROUGH */
/ *
* _ _ flush_ c a c h e _ u s e r _ r a n g e ( s t a r t ,e n d )
*
* Ensure t h a t t h e I a n d D c a c h e s a r e c o h e r e n t w i t h i n s p e c i f i e d r e g i o n .
* This i s t y p i c a l l y u s e d w h e n c o d e h a s b e e n w r i t t e n t o a m e m o r y r e g i o n ,
* and w i l l b e e x e c u t e d .
*
* - start - v i r t u a l s t a r t a d d r e s s o f r e g i o n
* - end - v i r t u a l e n d a d d r e s s o f r e g i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T ( _ _ f l u s h _ c a c h e _ u s e r _ r a n g e )
2018-01-09 13:51:58 +03:00
uaccess_ t t b r0 _ e n a b l e x2 , x3 , x4
2018-03-07 18:00:08 +03:00
alternative_ i f A R M 6 4 _ H A S _ C A C H E _ I D C
dsb i s h s t
b 7 f
alternative_ e l s e _ n o p _ e n d i f
2012-03-05 15:49:28 +04:00
dcache_ l i n e _ s i z e x2 , x3
sub x3 , x2 , #1
bic x4 , x0 , x3
1 :
2016-06-28 20:07:28 +03:00
user_ a l t 9 f , " d c c v a u , x4 " , " d c c i v a c , x4 " , A R M 6 4 _ W O R K A R O U N D _ C L E A N _ C A C H E
2012-03-05 15:49:28 +04:00
add x4 , x4 , x2
cmp x4 , x1
b. l o 1 b
2014-05-02 19:24:15 +04:00
dsb i s h
2012-03-05 15:49:28 +04:00
2018-03-07 18:00:08 +03:00
7 :
alternative_ i f A R M 6 4 _ H A S _ C A C H E _ D I C
isb
b 8 f
alternative_ e l s e _ n o p _ e n d i f
2017-10-23 19:11:16 +03:00
invalidate_ i c a c h e _ b y _ l i n e x0 , x1 , x2 , x3 , 9 f
2018-03-07 18:00:08 +03:00
8 : mov x0 , #0
2016-09-02 16:54:03 +03:00
1 :
2018-01-17 14:35:27 +03:00
uaccess_ t t b r0 _ d i s a b l e x1 , x2
2014-12-01 13:53:08 +03:00
ret
9 :
mov x0 , #- E F A U L T
2016-09-02 16:54:03 +03:00
b 1 b
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D ( _ _ f l u s h _ i c a c h e _ r a n g e )
SYM_ F U N C _ E N D ( _ _ f l u s h _ c a c h e _ u s e r _ r a n g e )
2012-03-05 15:49:28 +04:00
2017-10-23 19:11:16 +03:00
/ *
* invalidate_ i c a c h e _ r a n g e ( s t a r t ,e n d )
*
* Ensure t h a t t h e I c a c h e i s i n v a l i d w i t h i n s p e c i f i e d r e g i o n .
*
* - start - v i r t u a l s t a r t a d d r e s s o f r e g i o n
* - end - v i r t u a l e n d a d d r e s s o f r e g i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T ( i n v a l i d a t e _ i c a c h e _ r a n g e )
2018-03-07 18:00:08 +03:00
alternative_ i f A R M 6 4 _ H A S _ C A C H E _ D I C
mov x0 , x z r
isb
ret
alternative_ e l s e _ n o p _ e n d i f
2018-01-09 13:51:58 +03:00
uaccess_ t t b r0 _ e n a b l e x2 , x3 , x4
2017-10-23 19:11:16 +03:00
invalidate_ i c a c h e _ b y _ l i n e x0 , x1 , x2 , x3 , 2 f
mov x0 , x z r
1 :
2018-01-17 14:35:27 +03:00
uaccess_ t t b r0 _ d i s a b l e x1 , x2
2017-10-23 19:11:16 +03:00
ret
2 :
mov x0 , #- E F A U L T
b 1 b
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D ( i n v a l i d a t e _ i c a c h e _ r a n g e )
2017-10-23 19:11:16 +03:00
2012-03-05 15:49:28 +04:00
/ *
2014-01-21 05:17:47 +04:00
* _ _ flush_ d c a c h e _ a r e a ( k a d d r , s i z e )
2012-03-05 15:49:28 +04:00
*
2015-12-17 12:38:32 +03:00
* Ensure t h a t a n y D - c a c h e l i n e s f o r t h e i n t e r v a l [ k a d d r , k a d d r + s i z e )
* are c l e a n e d a n d i n v a l i d a t e d t o t h e P o C .
2012-03-05 15:49:28 +04:00
*
* - kaddr - k e r n e l a d d r e s s
* - size - s i z e i n q u e s t i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T _ P I ( _ _ f l u s h _ d c a c h e _ a r e a )
2015-12-17 12:38:32 +03:00
dcache_ b y _ l i n e _ o p c i v a c , s y , x0 , x1 , x2 , x3
2012-03-05 15:49:28 +04:00
ret
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D _ P I ( _ _ f l u s h _ d c a c h e _ a r e a )
2013-05-21 20:35:19 +04:00
2015-12-17 12:38:32 +03:00
/ *
* _ _ clean_ d c a c h e _ a r e a _ p o u ( k a d d r , s i z e )
*
* Ensure t h a t a n y D - c a c h e l i n e s f o r t h e i n t e r v a l [ k a d d r , k a d d r + s i z e )
* are c l e a n e d t o t h e P o U .
*
* - kaddr - k e r n e l a d d r e s s
* - size - s i z e i n q u e s t i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T ( _ _ c l e a n _ d c a c h e _ a r e a _ p o u )
2018-03-07 18:00:08 +03:00
alternative_ i f A R M 6 4 _ H A S _ C A C H E _ I D C
dsb i s h s t
ret
alternative_ e l s e _ n o p _ e n d i f
2015-12-17 12:38:32 +03:00
dcache_ b y _ l i n e _ o p c v a u , i s h , x0 , x1 , x2 , x3
ret
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D ( _ _ c l e a n _ d c a c h e _ a r e a _ p o u )
2015-12-17 12:38:32 +03:00
2014-03-26 22:25:55 +04:00
/ *
2017-07-25 13:55:39 +03:00
* _ _ inval_ d c a c h e _ a r e a ( k a d d r , s i z e )
*
* Ensure t h a t a n y D - c a c h e l i n e s f o r t h e i n t e r v a l [ k a d d r , k a d d r + s i z e )
* are i n v a l i d a t e d . A n y p a r t i a l l i n e s a t t h e e n d s o f t h e i n t e r v a l a r e
* also c l e a n e d t o P o C t o p r e v e n t d a t a l o s s .
*
* - kaddr - k e r n e l a d d r e s s
2016-08-02 03:50:50 +03:00
* - size - s i z e i n q u e s t i o n
2014-03-26 22:25:55 +04:00
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T _ L O C A L ( _ _ d m a _ i n v _ a r e a )
SYM_ F U N C _ S T A R T _ P I ( _ _ i n v a l _ d c a c h e _ a r e a )
2014-03-26 22:25:55 +04:00
/* FALLTHROUGH */
2013-05-21 20:35:19 +04:00
/ *
2017-07-25 13:55:39 +03:00
* _ _ dma_ i n v _ a r e a ( s t a r t , s i z e )
* - start - v i r t u a l s t a r t a d d r e s s o f r e g i o n
* - size - s i z e i n q u e s t i o n
2013-05-21 20:35:19 +04:00
* /
2017-07-25 13:55:39 +03:00
add x1 , x1 , x0
2013-05-21 20:35:19 +04:00
dcache_ l i n e _ s i z e x2 , x3
sub x3 , x2 , #1
2014-04-01 21:32:55 +04:00
tst x1 , x3 / / e n d c a c h e l i n e a l i g n e d ?
2013-05-21 20:35:19 +04:00
bic x1 , x1 , x3
2014-04-01 21:32:55 +04:00
b. e q 1 f
dc c i v a c , x1 / / c l e a n & i n v a l i d a t e D / U l i n e
1 : tst x0 , x3 / / s t a r t c a c h e l i n e a l i g n e d ?
bic x0 , x0 , x3
b. e q 2 f
dc c i v a c , x0 / / c l e a n & i n v a l i d a t e D / U l i n e
b 3 f
2 : dc i v a c , x0 / / i n v a l i d a t e D / U l i n e
3 : add x0 , x0 , x2
2013-05-21 20:35:19 +04:00
cmp x0 , x1
2014-04-01 21:32:55 +04:00
b. l o 2 b
2013-05-21 20:35:19 +04:00
dsb s y
ret
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D _ P I ( _ _ i n v a l _ d c a c h e _ a r e a )
SYM_ F U N C _ E N D ( _ _ d m a _ i n v _ a r e a )
2016-08-02 03:50:50 +03:00
/ *
* _ _ clean_ d c a c h e _ a r e a _ p o c ( k a d d r , s i z e )
*
* Ensure t h a t a n y D - c a c h e l i n e s f o r t h e i n t e r v a l [ k a d d r , k a d d r + s i z e )
* are c l e a n e d t o t h e P o C .
*
* - kaddr - k e r n e l a d d r e s s
* - size - s i z e i n q u e s t i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T _ L O C A L ( _ _ d m a _ c l e a n _ a r e a )
SYM_ F U N C _ S T A R T _ P I ( _ _ c l e a n _ d c a c h e _ a r e a _ p o c )
2016-08-02 03:50:50 +03:00
/* FALLTHROUGH */
2013-05-21 20:35:19 +04:00
/ *
2016-08-02 03:50:50 +03:00
* _ _ dma_ c l e a n _ a r e a ( s t a r t , s i z e )
2013-05-21 20:35:19 +04:00
* - start - v i r t u a l s t a r t a d d r e s s o f r e g i o n
2016-08-02 03:50:50 +03:00
* - size - s i z e i n q u e s t i o n
2013-05-21 20:35:19 +04:00
* /
2016-08-02 03:50:50 +03:00
dcache_ b y _ l i n e _ o p c v a c , s y , x0 , x1 , x2 , x3
2013-05-21 20:35:19 +04:00
ret
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D _ P I ( _ _ c l e a n _ d c a c h e _ a r e a _ p o c )
SYM_ F U N C _ E N D ( _ _ d m a _ c l e a n _ a r e a )
2013-05-21 20:35:19 +04:00
2017-07-25 13:55:42 +03:00
/ *
* _ _ clean_ d c a c h e _ a r e a _ p o p ( k a d d r , s i z e )
*
* Ensure t h a t a n y D - c a c h e l i n e s f o r t h e i n t e r v a l [ k a d d r , k a d d r + s i z e )
* are c l e a n e d t o t h e P o P .
*
* - kaddr - k e r n e l a d d r e s s
* - size - s i z e i n q u e s t i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T _ P I ( _ _ c l e a n _ d c a c h e _ a r e a _ p o p )
2018-12-10 16:39:48 +03:00
alternative_ i f _ n o t A R M 6 4 _ H A S _ D C P O P
b _ _ c l e a n _ d c a c h e _ a r e a _ p o c
alternative_ e l s e _ n o p _ e n d i f
2017-07-25 13:55:42 +03:00
dcache_ b y _ l i n e _ o p c v a p , s y , x0 , x1 , x2 , x3
ret
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D _ P I ( _ _ c l e a n _ d c a c h e _ a r e a _ p o p )
2017-07-25 13:55:42 +03:00
2013-05-21 20:35:19 +04:00
/ *
2016-08-02 03:50:50 +03:00
* _ _ dma_ f l u s h _ a r e a ( s t a r t , s i z e )
*
* clean & i n v a l i d a t e D / U l i n e
*
2013-05-21 20:35:19 +04:00
* - start - v i r t u a l s t a r t a d d r e s s o f r e g i o n
2016-08-02 03:50:50 +03:00
* - size - s i z e i n q u e s t i o n
2013-05-21 20:35:19 +04:00
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T _ P I ( _ _ d m a _ f l u s h _ a r e a )
2016-08-02 03:50:50 +03:00
dcache_ b y _ l i n e _ o p c i v a c , s y , x0 , x1 , x2 , x3
2013-05-21 20:35:19 +04:00
ret
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D _ P I ( _ _ d m a _ f l u s h _ a r e a )
2013-05-21 20:35:19 +04:00
/ *
* _ _ dma_ m a p _ a r e a ( s t a r t , s i z e , d i r )
* - start - k e r n e l v i r t u a l s t a r t a d d r e s s
* - size - s i z e o f r e g i o n
* - dir - D M A d i r e c t i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T _ P I ( _ _ d m a _ m a p _ a r e a )
2013-05-21 20:35:19 +04:00
cmp w2 , #D M A _ F R O M _ D E V I C E
2016-08-02 03:50:50 +03:00
b. e q _ _ d m a _ i n v _ a r e a
b _ _ d m a _ c l e a n _ a r e a
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D _ P I ( _ _ d m a _ m a p _ a r e a )
2013-05-21 20:35:19 +04:00
/ *
* _ _ dma_ u n m a p _ a r e a ( s t a r t , s i z e , d i r )
* - start - k e r n e l v i r t u a l s t a r t a d d r e s s
* - size - s i z e o f r e g i o n
* - dir - D M A d i r e c t i o n
* /
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ S T A R T _ P I ( _ _ d m a _ u n m a p _ a r e a )
2013-05-21 20:35:19 +04:00
cmp w2 , #D M A _ T O _ D E V I C E
2016-08-02 03:50:50 +03:00
b. n e _ _ d m a _ i n v _ a r e a
2013-05-21 20:35:19 +04:00
ret
2020-01-06 22:58:18 +03:00
SYM_ F U N C _ E N D _ P I ( _ _ d m a _ u n m a p _ a r e a )