2019-05-27 09:55:01 +03:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2009-01-08 17:31:20 +03:00
/ *
* This f i l e c o n t a i n s l o w l e v e l C P U s e t u p f u n c t i o n s .
* Kumar G a l a < g a l a k @kernel.crashing.org>
* Copyright 2 0 0 9 F r e e s c a l e S e m i c o n d u c t o r , I n c .
*
* Based o n c p u _ s e t u p _ 6 x x c o d e b y
* Benjamin H e r r e n s c h m i d t < b e n h @kernel.crashing.org>
* /
2015-11-20 12:13:58 +03:00
# include < a s m / p a g e . h >
2009-01-08 17:31:20 +03:00
# include < a s m / p r o c e s s o r . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / p p c _ a s m . h >
2018-11-29 17:06:55 +03:00
# include < a s m / n o h a s h / m m u - b o o k 3 e . h >
2012-07-09 16:55:31 +04:00
# include < a s m / a s m - o f f s e t s . h >
2015-11-20 12:13:58 +03:00
# include < a s m / m p c85 x x . h >
2009-01-08 17:31:20 +03:00
2009-06-11 00:37:28 +04:00
_ GLOBAL( _ _ e 5 0 0 _ i c a c h e _ s e t u p )
mfspr r0 , S P R N _ L 1 C S R 1
andi. r3 , r0 , L 1 C S R 1 _ I C E
bnelr / * A l r e a d y e n a b l e d * /
oris r0 , r0 , L 1 C S R 1 _ C P E @h
ori r0 , r0 , ( L 1 C S R 1 _ I C F I | L 1 C S R 1 _ I C L F R | L 1 C S R 1 _ I C E )
mtspr S P R N _ L 1 C S R 1 , r0 / * E n a b l e I - C a c h e * /
isync
blr
_ GLOBAL( _ _ e 5 0 0 _ d c a c h e _ s e t u p )
mfspr r0 , S P R N _ L 1 C S R 0
andi. r3 , r0 , L 1 C S R 0 _ D C E
bnelr / * A l r e a d y e n a b l e d * /
msync
isync
li r0 , 0
mtspr S P R N _ L 1 C S R 0 , r0 / * D i s a b l e * /
msync
isync
li r0 , ( L 1 C S R 0 _ D C F I | L 1 C S R 0 _ C L F C )
mtspr S P R N _ L 1 C S R 0 , r0 / * I n v a l i d a t e * /
isync
1 : mfspr r0 , S P R N _ L 1 C S R 0
andi. r3 , r0 , L 1 C S R 0 _ C L F C
bne+ 1 b / * W a i t f o r l o c k b i t s r e s e t * /
oris r0 , r0 , L 1 C S R 0 _ C P E @h
ori r0 , r0 , L 1 C S R 0 _ D C E
msync
isync
mtspr S P R N _ L 1 C S R 0 , r0 / * E n a b l e * /
isync
blr
2013-12-17 12:17:01 +04:00
/ *
* FIXME - w e h a v e n ' t y e t d o n e t e s t i n g t o d e t e r m i n e a r e a s o n a b l e d e f a u l t
* value f o r P W 2 0 _ W A I T _ I D L E _ B I T .
* /
# define P W 2 0 _ W A I T _ I D L E _ B I T 5 0 / * 1 m s , T B f r e q u e n c y i s 4 1 . 6 6 M H Z * /
_ GLOBAL( s e t u p _ p w20 _ i d l e )
mfspr r3 , S P R N _ P W R M G T C R 0
/* Set PW20_WAIT bit, enable pw20 state*/
ori r3 , r3 , P W R M G T C R 0 _ P W 2 0 _ W A I T
li r11 , P W 2 0 _ W A I T _ I D L E _ B I T
/* Set Automatic PW20 Core Idle Count */
rlwimi r3 , r11 , P W R M G T C R 0 _ P W 2 0 _ E N T _ S H I F T , P W R M G T C R 0 _ P W 2 0 _ E N T
mtspr S P R N _ P W R M G T C R 0 , r3
blr
2013-12-17 12:17:00 +04:00
/ *
* FIXME - w e h a v e n ' t y e t d o n e t e s t i n g t o d e t e r m i n e a r e a s o n a b l e d e f a u l t
* value f o r A V _ W A I T _ I D L E _ B I T .
* /
# define A V _ W A I T _ I D L E _ B I T 5 0 / * 1 m s , T B f r e q u e n c y i s 4 1 . 6 6 M H Z * /
_ GLOBAL( s e t u p _ a l t i v e c _ i d l e )
mfspr r3 , S P R N _ P W R M G T C R 0
/* Enable Altivec Idle */
oris r3 , r3 , P W R M G T C R 0 _ A V _ I D L E _ P D _ E N @h
li r11 , A V _ W A I T _ I D L E _ B I T
/* Set Automatic AltiVec Idle Count */
rlwimi r3 , r11 , P W R M G T C R 0 _ A V _ I D L E _ C N T _ S H I F T , P W R M G T C R 0 _ A V _ I D L E _ C N T
mtspr S P R N _ P W R M G T C R 0 , r3
blr
2014-08-20 17:09:03 +04:00
# ifdef C O N F I G _ P P C _ E 5 0 0 M C
2012-09-08 00:57:17 +04:00
_ GLOBAL( _ _ s e t u p _ c p u _ e 6 5 0 0 )
mflr r6
# ifdef C O N F I G _ P P C 6 4
2014-02-04 09:04:35 +04:00
bl s e t u p _ a l t i v e c _ i v o r s
2013-08-08 16:56:09 +04:00
/* Touch IVOR42 only if the CPU supports E.HV category */
mfspr r10 ,S P R N _ M M U C F G
rlwinm. r10 ,r10 ,0 ,M M U C F G _ L P I D S I Z E
beq 1 f
2014-02-04 09:04:35 +04:00
bl s e t u p _ l r a t _ i v o r
2013-08-08 16:56:09 +04:00
1 :
2012-09-08 00:57:17 +04:00
# endif
2013-12-17 12:17:01 +04:00
bl s e t u p _ p w20 _ i d l e
2013-12-17 12:17:00 +04:00
bl s e t u p _ a l t i v e c _ i d l e
2012-09-08 00:57:17 +04:00
bl _ _ s e t u p _ c p u _ e 5 5 0 0
mtlr r6
blr
2014-08-20 17:09:03 +04:00
# endif / * C O N F I G _ P P C _ E 5 0 0 M C * /
2012-09-08 00:57:17 +04:00
2010-10-08 17:32:11 +04:00
# ifdef C O N F I G _ P P C 3 2
2014-08-20 17:09:03 +04:00
# ifdef C O N F I G _ E 2 0 0
2009-01-08 17:31:20 +03:00
_ GLOBAL( _ _ s e t u p _ c p u _ e 2 0 0 )
/* enable dedicated debug exception handling resources (Debug APU) */
mfspr r3 ,S P R N _ H I D 0
ori r3 ,r3 ,H I D 0 _ D A P U E N @l
mtspr S P R N _ H I D 0 ,r3
b _ _ s e t u p _ e 2 0 0 _ i v o r s
2014-08-20 17:09:03 +04:00
# endif / * C O N F I G _ E 2 0 0 * /
# ifdef C O N F I G _ E 5 0 0
# ifndef C O N F I G _ P P C _ E 5 0 0 M C
2009-01-08 17:31:20 +03:00
_ GLOBAL( _ _ s e t u p _ c p u _ e 5 0 0 v1 )
_ GLOBAL( _ _ s e t u p _ c p u _ e 5 0 0 v2 )
2009-06-11 00:37:28 +04:00
mflr r4
bl _ _ e 5 0 0 _ i c a c h e _ s e t u p
bl _ _ e 5 0 0 _ d c a c h e _ s e t u p
bl _ _ s e t u p _ e 5 0 0 _ i v o r s
2013-04-28 09:20:08 +04:00
# if d e f i n e d ( C O N F I G _ F S L _ R I O ) | | d e f i n e d ( C O N F I G _ F S L _ P C I )
2010-11-03 12:36:37 +03:00
/* Ensure that RFXE is set */
mfspr r3 ,S P R N _ H I D 1
oris r3 ,r3 ,H I D 1 _ R F X E @h
mtspr S P R N _ H I D 1 ,r3
# endif
2009-06-11 00:37:28 +04:00
mtlr r4
blr
2014-08-20 17:09:03 +04:00
# else / * C O N F I G _ P P C _ E 5 0 0 M C * /
2009-01-08 17:31:20 +03:00
_ GLOBAL( _ _ s e t u p _ c p u _ e 5 0 0 m c )
2012-07-09 16:58:21 +04:00
_ GLOBAL( _ _ s e t u p _ c p u _ e 5 5 0 0 )
2012-07-09 16:55:31 +04:00
mflr r5
2009-06-11 00:37:28 +04:00
bl _ _ e 5 0 0 _ i c a c h e _ s e t u p
bl _ _ e 5 0 0 _ d c a c h e _ s e t u p
bl _ _ s e t u p _ e 5 0 0 m c _ i v o r s
2012-07-09 16:55:31 +04:00
/ *
* We o n l y w a n t t o t o u c h I V O R 3 8 - 4 1 i f w e ' r e r u n n i n g o n h a r d w a r e
* that s u p p o r t s c a t e g o r y E . H V . T h e a r c h i t e c t u r a l w a y t o d e t e r m i n e
* this i s M M U C F G [ L P I D S I Z E ] .
* /
mfspr r3 , S P R N _ M M U C F G
rlwinm. r3 , r3 , 0 , M M U C F G _ L P I D S I Z E
beq 1 f
bl _ _ s e t u p _ e h v _ i v o r s
b 2 f
1 :
lwz r3 , C P U _ S P E C _ F E A T U R E S ( r4 )
/ * We n e e d t h i s c h e c k a s c p u _ s e t u p i s a l s o c a l l e d f o r
* the s e c o n d a r y c o r e s . S o , i f w e h a v e a l r e a d y c l e a r e d
* the f e a t u r e o n t h e p r i m a r y c o r e , a v o i d d o i n g i t o n t h e
* secondary c o r e .
* /
2018-03-20 00:46:13 +03:00
andi. r6 , r3 , C P U _ F T R _ E M B _ H V
2012-07-09 16:55:31 +04:00
beq 2 f
rlwinm r3 , r3 , 0 , ~ C P U _ F T R _ E M B _ H V
stw r3 , C P U _ S P E C _ F E A T U R E S ( r4 )
2 :
mtlr r5
2009-06-11 00:37:28 +04:00
blr
2014-08-20 17:09:03 +04:00
# endif / * C O N F I G _ P P C _ E 5 0 0 M C * /
# endif / * C O N F I G _ E 5 0 0 * /
# endif / * C O N F I G _ P P C 3 2 * /
2012-07-09 17:01:51 +04:00
2012-07-09 16:58:21 +04:00
# ifdef C O N F I G _ P P C _ B O O K 3 E _ 6 4
2012-09-08 00:57:17 +04:00
_ GLOBAL( _ _ r e s t o r e _ c p u _ e 6 5 0 0 )
mflr r5
2014-02-04 09:04:35 +04:00
bl s e t u p _ a l t i v e c _ i v o r s
2013-08-08 16:56:09 +04:00
/* Touch IVOR42 only if the CPU supports E.HV category */
mfspr r10 ,S P R N _ M M U C F G
rlwinm. r10 ,r10 ,0 ,M M U C F G _ L P I D S I Z E
beq 1 f
2014-02-04 09:04:35 +04:00
bl s e t u p _ l r a t _ i v o r
2013-08-08 16:56:09 +04:00
1 :
2014-02-04 09:04:35 +04:00
bl s e t u p _ p w20 _ i d l e
bl s e t u p _ a l t i v e c _ i d l e
2012-09-08 00:57:17 +04:00
bl _ _ r e s t o r e _ c p u _ e 5 5 0 0
mtlr r5
blr
2010-10-08 17:32:11 +04:00
_ GLOBAL( _ _ r e s t o r e _ c p u _ e 5 5 0 0 )
mflr r4
bl _ _ e 5 0 0 _ i c a c h e _ s e t u p
bl _ _ e 5 0 0 _ d c a c h e _ s e t u p
2014-02-04 09:04:35 +04:00
bl _ _ s e t u p _ b a s e _ i v o r s
bl s e t u p _ p e r f m o n _ i v o r
bl s e t u p _ d o o r b e l l _ i v o r s
2012-07-09 17:01:51 +04:00
/ *
* We o n l y w a n t t o t o u c h I V O R 3 8 - 4 1 i f w e ' r e r u n n i n g o n h a r d w a r e
* that s u p p o r t s c a t e g o r y E . H V . T h e a r c h i t e c t u r a l w a y t o d e t e r m i n e
* this i s M M U C F G [ L P I D S I Z E ] .
* /
mfspr r10 ,S P R N _ M M U C F G
rlwinm. r10 ,r10 ,0 ,M M U C F G _ L P I D S I Z E
beq 1 f
2014-02-04 09:04:35 +04:00
bl s e t u p _ e h v _ i v o r s
2012-07-09 17:01:51 +04:00
1 :
2010-10-08 17:32:11 +04:00
mtlr r4
blr
2012-07-09 17:01:51 +04:00
_ GLOBAL( _ _ s e t u p _ c p u _ e 5 5 0 0 )
mflr r5
bl _ _ e 5 0 0 _ i c a c h e _ s e t u p
bl _ _ e 5 0 0 _ d c a c h e _ s e t u p
2014-02-04 09:04:35 +04:00
bl _ _ s e t u p _ b a s e _ i v o r s
bl s e t u p _ p e r f m o n _ i v o r
bl s e t u p _ d o o r b e l l _ i v o r s
2012-07-09 17:01:51 +04:00
/ *
* We o n l y w a n t t o t o u c h I V O R 3 8 - 4 1 i f w e ' r e r u n n i n g o n h a r d w a r e
* that s u p p o r t s c a t e g o r y E . H V . T h e a r c h i t e c t u r a l w a y t o d e t e r m i n e
* this i s M M U C F G [ L P I D S I Z E ] .
* /
mfspr r10 ,S P R N _ M M U C F G
rlwinm. r10 ,r10 ,0 ,M M U C F G _ L P I D S I Z E
beq 1 f
2014-02-04 09:04:35 +04:00
bl s e t u p _ e h v _ i v o r s
2012-07-09 17:04:01 +04:00
b 2 f
2012-07-09 17:01:51 +04:00
1 :
2012-07-09 17:04:01 +04:00
ld r10 ,C P U _ S P E C _ F E A T U R E S ( r4 )
LOAD_ R E G _ I M M E D I A T E ( r9 ,C P U _ F T R _ E M B _ H V )
andc r10 ,r10 ,r9
std r10 ,C P U _ S P E C _ F E A T U R E S ( r4 )
2 :
2012-07-09 17:01:51 +04:00
mtlr r5
blr
2012-07-09 16:58:21 +04:00
# endif
2015-11-20 12:13:58 +03:00
2019-10-25 12:29:01 +03:00
/* flush L1 data cache, it can apply to e500v2, e500mc and e5500 */
2015-11-20 12:13:58 +03:00
_ GLOBAL( f l u s h _ d c a c h e _ L 1 )
mfmsr r10
wrteei 0
mfspr r3 ,S P R N _ L 1 C F G 0
rlwinm r5 ,r3 ,9 ,3 / * E x t r a c t c a c h e b l o c k s i z e * /
twlgti r5 ,1 / * O n l y 3 2 a n d 6 4 b y t e c a c h e b l o c k s
* are c u r r e n t l y d e f i n e d .
* /
li r4 ,3 2
subfic r6 ,r5 ,2 / * r6 = l o g 2 ( 1 K i B / c a c h e b l o c k s i z e ) -
* log2 ( n u m b e r o f w a y s )
* /
slw r5 ,r4 ,r5 / * r5 = c a c h e b l o c k s i z e * /
rlwinm r7 ,r3 ,0 ,0 x f f / * E x t r a c t n u m b e r o f K i B i n t h e c a c h e * /
mulli r7 ,r7 ,1 3 / * A n 8 - w a y c a c h e w i l l r e q u i r e 1 3
* loads p e r s e t .
* /
slw r7 ,r7 ,r6
/* save off HID0 and set DCFA */
mfspr r8 ,S P R N _ H I D 0
ori r9 ,r8 ,H I D 0 _ D C F A @l
mtspr S P R N _ H I D 0 ,r9
isync
LOAD_ R E G _ I M M E D I A T E ( r6 , K E R N E L B A S E )
mr r4 , r6
mtctr r7
1 : lwz r3 ,0 ( r4 ) / * L o a d . . . * /
add r4 ,r4 ,r5
bdnz 1 b
msync
mr r4 , r6
mtctr r7
1 : dcbf 0 ,r4 / * . . . a n d f l u s h . * /
add r4 ,r4 ,r5
bdnz 1 b
/* restore HID0 */
mtspr S P R N _ H I D 0 ,r8
isync
wrtee r10
blr
has_L2_cache :
/* skip L2 cache on P2040/P2040E as they have no L2 cache */
mfspr r3 , S P R N _ S V R
/* shift right by 8 bits and clear E bit of SVR */
rlwinm r4 , r3 , 2 4 , ~ 0 x80 0
lis r3 , S V R _ P 2 0 4 0 @h
ori r3 , r3 , S V R _ P 2 0 4 0 @l
cmpw r4 , r3
beq 1 f
li r3 , 1
blr
1 :
li r3 , 0
blr
/* flush backside L2 cache */
flush_backside_L2_cache :
mflr r10
bl h a s _ L 2 _ c a c h e
mtlr r10
cmpwi r3 , 0
beq 2 f
/* Flush the L2 cache */
mfspr r3 , S P R N _ L 2 C S R 0
ori r3 , r3 , L 2 C S R 0 _ L 2 F L @l
msync
isync
mtspr S P R N _ L 2 C S R 0 ,r3
isync
/* check if it is complete */
1 : mfspr r3 ,S P R N _ L 2 C S R 0
andi. r3 , r3 , L 2 C S R 0 _ L 2 F L @l
bne 1 b
2 :
blr
_ GLOBAL( c p u _ d o w n _ f l u s h _ e 5 0 0 v2 )
mflr r0
bl f l u s h _ d c a c h e _ L 1
mtlr r0
blr
_ GLOBAL( c p u _ d o w n _ f l u s h _ e 5 0 0 m c )
_ GLOBAL( c p u _ d o w n _ f l u s h _ e 5 5 0 0 )
mflr r0
bl f l u s h _ d c a c h e _ L 1
bl f l u s h _ b a c k s i d e _ L 2 _ c a c h e
mtlr r0
blr
/* L1 Data Cache of e6500 contains no modified data, no flush is required */
_ GLOBAL( c p u _ d o w n _ f l u s h _ e 6 5 0 0 )
blr