2019-05-20 10:19:02 +03:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2005-04-17 02:20:36 +04:00
/ *
L2 C R f u n c t i o n s
2007-10-20 01:21:04 +04:00
Copyright © 1 9 9 7 - 1 9 9 8 b y P o w e r L o g i x R & D , I n c .
2005-04-17 02:20:36 +04:00
* /
/ *
Thur, D e c . 1 2 , 1 9 9 8 .
- First p u b l i c r e l e a s e , c o n t r i b u t e d b y P o w e r L o g i x .
* * * * * * * * * * *
Sat, A u g . 7 , 1 9 9 9 .
- Terry : Made s u r e c o d e d i s a b l e d i n t e r r u p t s b e f o r e r u n n i n g . ( P r e v i o u s l y
it w a s a s s u m e d i n t e r r u p t s w e r e a l r e a d y d i s a b l e d ) .
- Terry : Updated f o r t e n t a t i v e G 4 s u p p o r t . 4 M B o f m e m o r y i s n o w f l u s h e d
instead o f 2 M B . ( P r o b . o n l y 3 i s n e c e s s a r y ) .
- Terry : Updated f o r w o r k a r o u n d t o H I D 0 [ D P M ] p r o c e s s o r b u g
during g l o b a l i n v a l i d a t e s .
* * * * * * * * * * *
Thu, J u l y 1 3 , 2 0 0 0 .
- Terry : Added i s y n c t o c o r r e c t f o r a n e r r a t a .
2 2 August 2 0 0 1 .
- DanM : Finally a d d e d t h e 7 4 5 0 p a t c h I ' v e h a d f o r t h e p a s t
several m o n t h s . T h e L 2 C R i s s i m i l a r , b u t I ' m g o i n g
to a s s u m e t h e u s e r o f t h i s f u n c t i o n s k n o w s w h a t t h e y
are d o i n g .
Author : Terry G r e e n i a u s ( t g r e e @phys.ualberta.ca)
Please e - m a i l u p d a t e s t o t h i s f i l e t o m e , t h a n k s !
* /
# 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 >
# include < a s m / c a c h e . h >
# include < a s m / p a g e . h >
2018-07-05 19:25:01 +03:00
# include < a s m / f e a t u r e - f i x u p s . h >
2005-04-17 02:20:36 +04:00
/ * Usage :
When s e t t i n g t h e L 2 C R r e g i s t e r , y o u m u s t d o a f e w s p e c i a l
things. I f y o u a r e e n a b l i n g t h e c a c h e , y o u m u s t p e r f o r m a
global i n v a l i d a t e . I f y o u a r e d i s a b l i n g t h e c a c h e , y o u m u s t
flush t h e c a c h e c o n t e n t s f i r s t . T h i s r o u t i n e t a k e s c a r e o f
doing t h e s e t h i n g s . W h e n f i r s t e n a b l i n g t h e c a c h e , m a k e s u r e
you p a s s i n t h e L 2 C R y o u w a n t , a s w e l l a s p a s s i n g i n t h e
global i n v a l i d a t e b i t s e t . A g l o b a l i n v a l i d a t e w i l l o n l y b e
performed i f t h e L 2 I b i t i s s e t i n a p p l y T h i s . W h e n e n a b l i n g
the c a c h e , y o u s h o u l d a l s o s e t t h e L 2 E b i t i n a p p l y T h i s . I f
you w a n t t o m o d i f y t h e L 2 C R c o n t e n t s a f t e r t h e c a c h e h a s b e e n
enabled, t h e r e c o m m e n d e d p r o c e d u r e i s t o f i r s t c a l l
_ _ setL2 C R ( 0 ) t o d i s a b l e t h e c a c h e a n d t h e n c a l l i t a g a i n w i t h
the n e w v a l u e s f o r L 2 C R . E x a m p l e s :
_ setL2 C R ( 0 ) - d i s a b l e s t h e c a c h e
_ setL2 C R ( 0 x B 3 A 0 4 0 0 0 ) - e n a b l e s m y G 3 u p g r a d e c a r d :
- L2 E s e t t o t u r n o n t h e c a c h e
- L2 S I Z s e t t o 1 M B
- L2 C L K s e t t o 1 : 1
- L2 R A M s e t t o p i p e l i n e d s y n c h r o n o u s l a t e - w r i t e
- L2 I s e t t o p e r f o r m a g l o b a l i n v a l i d a t i o n
- L2 O H s e t t o 0 . 5 n S
- L2 D F s e t b e c a u s e t h i s u p g r a d e c a r d
requires i t
A s i m i l a r c a l l s h o u l d w o r k f o r y o u r c a r d . Y o u n e e d t o k n o w
the c o r r e c t s e t t i n g f o r y o u r c a r d a n d t h e n p l a c e t h e m i n t h e
fields I h a v e o u t l i n e d a b o v e . O t h e r f i e l d s s u p p o r t o p t i o n a l
features, s u c h a s L 2 D O w h i c h c a c h e s o n l y d a t a , o r L 2 T S w h i c h
causes c a c h e p u s h e s f r o m t h e L 1 c a c h e t o g o t o t h e L 2 c a c h e
instead o f t o m a i n m e m o r y .
IMPORTANT :
Starting w i t h t h e 7 4 5 0 , t h e b i t s i n t h i s r e g i s t e r h a v e m o v e d
or b e h a v e d i f f e r e n t l y . T h e E n a b l e , P a r i t y E n a b l e , S i z e ,
and L 2 I n v a l i d a t e a r e t h e o n l y b i t s t h a t h a v e n o t m o v e d .
The s i z e i s r e a d - o n l y f o r t h e s e p r o c e s s o r s w i t h i n t e r n a l L 2
cache, a n d t h e i n v a l i d a t e i s a c o n t r o l a s w e l l a s s t a t u s .
- - Dan
* /
/ *
* Summary : this p r o c e d u r e i g n o r e s t h e L 2 I b i t i n t h e v a l u e p a s s e d i n ,
* flushes t h e c a c h e i f i t w a s a l r e a d y e n a b l e d , a l w a y s i n v a l i d a t e s t h e
* cache, t h e n e n a b l e s t h e c a c h e i f t h e L 2 E b i t i s s e t i n t h e v a l u e
* passed i n .
* - - paulus.
* /
_ GLOBAL( _ s e t _ L 2 C R )
/* Make sure this is a 750 or 7400 chip */
BEGIN_ F T R _ S E C T I O N
li r3 ,- 1
blr
END_ F T R _ S E C T I O N _ I F C L R ( C P U _ F T R _ L 2 C R )
mflr r9
/* Stop DST streams */
BEGIN_ F T R _ S E C T I O N
DSSALL
sync
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A L T I V E C )
/* Turn off interrupts and data relocation. */
mfmsr r7 / * S a v e M S R i n r7 * /
rlwinm r4 ,r7 ,0 ,1 7 ,1 5
rlwinm r4 ,r4 ,0 ,2 8 ,2 6 / * T u r n o f f D R b i t * /
sync
mtmsr r4
isync
/ * Before w e p e r f o r m t h e g l o b a l i n v a l i d a t i o n , w e m u s t d i s a b l e d y n a m i c
* power m a n a g e m e n t v i a H I D 0 [ D P M ] t o w o r k a r o u n d a p r o c e s s o r b u g w h e r e
* DPM c a n p o s s i b l y i n t e r f e r e w i t h t h e s t a t e m a c h i n e i n t h e p r o c e s s o r
* that i n v a l i d a t e s t h e L 2 c a c h e t a g s .
* /
mfspr r8 ,S P R N _ H I D 0 / * S a v e H I D 0 i n r8 * /
rlwinm r4 ,r8 ,0 ,1 2 ,1 0 / * T u r n o f f H I D 0 [ D P M ] * /
sync
mtspr S P R N _ H I D 0 ,r4 / * D i s a b l e D P M * /
sync
/* Get the current enable bit of the L2CR into r4 */
mfspr r4 ,S P R N _ L 2 C R
/* Tweak some bits */
rlwinm r5 ,r3 ,0 ,0 ,0 / * r5 c o n t a i n s t h e n e w e n a b l e b i t * /
rlwinm r3 ,r3 ,0 ,1 1 ,9 / * T u r n o f f t h e i n v a l i d a t e b i t * /
rlwinm r3 ,r3 ,0 ,1 ,3 1 / * T u r n o f f t h e e n a b l e b i t * /
/* Check to see if we need to flush */
rlwinm. r4 ,r4 ,0 ,0 ,0
beq 2 f
/ * Flush t h e c a c h e . F i r s t , r e a d t h e f i r s t 4 M B o f m e m o r y ( p h y s i c a l ) t o
* put n e w d a t a i n t h e c a c h e . ( A c t u a l l y w e o n l y n e e d
* the s i z e o f t h e L 2 c a c h e p l u s t h e s i z e o f t h e L 1 c a c h e , b u t 4 M B w i l l
* cover e v e r y t h i n g j u s t t o b e s a f e ) .
* /
/ * * * * Might b e a g o o d i d e a t o s e t L 2 D O h e r e - t o p r e v e n t i n s t r u c t i o n s
from g e t t i n g i n t o t h e c a c h e . B u t s i n c e w e i n v a l i d a t e
the n e x t t i m e w e e n a b l e t h e c a c h e i t d o e s n ' t r e a l l y m a t t e r .
2011-03-31 05:57:33 +04:00
Don' t d o t h i s u n l e s s y o u a c c o m m o d a t e a l l p r o c e s s o r v a r i a t i o n s .
2005-04-17 02:20:36 +04:00
The b i t m o v e d o n t h e 7 4 5 0 . . . . .
* * * * /
2005-08-31 08:54:47 +04:00
BEGIN_ F T R _ S E C T I O N
/ * Disable L 2 p r e f e t c h o n s o m e 7 4 5 x a n d t r y t o e n s u r e
* L2 p r e f e t c h e n g i n e s a r e i d l e . A s e x p l a i n e d b y e r r a t a
* text, w e c a n ' t b e s u r e t h e y a r e , w e j u s t h o p e v e r y h a r d
* that w e l l b e e n o u g h ( s i c ! ) . A t l e a s t I n o t i c e d A p p l e
* doesn' t e v e n b o t h e r d o i n g t h e d c b f ' s h e r e . . .
* /
mfspr r4 ,S P R N _ M S S C R 0
rlwinm r4 ,r4 ,0 ,0 ,2 9
sync
mtspr S P R N _ M S S C R 0 ,r4
sync
isync
lis r4 ,K E R N E L B A S E @h
dcbf 0 ,r4
dcbf 0 ,r4
dcbf 0 ,r4
dcbf 0 ,r4
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ S P E C 7 4 5 0 )
2005-04-17 02:20:36 +04:00
/* TODO: use HW flush assist when available */
lis r4 ,0 x00 0 2
mtctr r4
li r4 ,0
1 :
2017-08-14 21:42:43 +03:00
lwzx r0 ,0 ,r4
2005-04-17 02:20:36 +04:00
addi r4 ,r4 ,3 2 / * G o t o s t a r t o f n e x t c a c h e l i n e * /
bdnz 1 b
isync
/* Now, flush the first 4MB of memory */
lis r4 ,0 x00 0 2
mtctr r4
li r4 ,0
sync
1 :
dcbf 0 ,r4
addi r4 ,r4 ,3 2 / * G o t o s t a r t o f n e x t c a c h e l i n e * /
bdnz 1 b
2 :
/* Set up the L2CR configuration bits (and switch L2 off) */
/ * CPU e r r a t a : M a k e s u r e t h e m t s p r b e l o w i s a l r e a d y i n t h e
* L1 i c a c h e
* /
b 2 0 f
2005-10-17 05:50:32 +04:00
.balign L1_CACHE_BYTES
2005-04-17 02:20:36 +04:00
22 :
sync
mtspr S P R N _ L 2 C R ,r3
sync
b 2 3 f
20 :
b 2 1 f
21 : sync
isync
b 2 2 b
23 :
/* Perform a global invalidation */
oris r3 ,r3 ,0 x00 2 0
sync
mtspr S P R N _ L 2 C R ,r3
sync
isync / * F o r e r r a t a * /
BEGIN_ F T R _ S E C T I O N
/ * On t h e 7 4 5 0 , w e w a i t f o r t h e L 2 I b i t t o c l e a r . . . . . .
* /
10 : mfspr r3 ,S P R N _ L 2 C R
andis. r4 ,r3 ,0 x00 2 0
bne 1 0 b
b 1 1 f
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ S P E C 7 4 5 0 )
/* Wait for the invalidation to complete */
3 : mfspr r3 ,S P R N _ L 2 C R
rlwinm. r4 ,r3 ,0 ,3 1 ,3 1
bne 3 b
11 : rlwinm r3 ,r3 ,0 ,1 1 ,9 / * T u r n o f f t h e L 2 I b i t * /
sync
mtspr S P R N _ L 2 C R ,r3
sync
/* See if we need to enable the cache */
cmplwi r5 ,0
beq 4 f
/* Enable the cache */
oris r3 ,r3 ,0 x80 0 0
mtspr S P R N _ L 2 C R ,r3
sync
2005-08-31 08:54:47 +04:00
/* Enable L2 HW prefetch on 744x/745x */
BEGIN_ F T R _ S E C T I O N
mfspr r3 ,S P R N _ M S S C R 0
ori r3 ,r3 ,3
sync
mtspr S P R N _ M S S C R 0 ,r3
sync
isync
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ S P E C 7 4 5 0 )
2005-04-17 02:20:36 +04:00
4 :
/* Restore HID0[DPM] to whatever it was before */
sync
mtspr 1 0 0 8 ,r8
sync
/* Restore MSR (restores EE and DR bits to original state) */
SYNC
mtmsr r7
isync
mtlr r9
blr
_ GLOBAL( _ g e t _ L 2 C R )
/* Return the L2CR contents */
li r3 ,0
BEGIN_ F T R _ S E C T I O N
mfspr r3 ,S P R N _ L 2 C R
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ L 2 C R )
blr
/ *
* Here i s a s i m i l a r r o u t i n e f o r d e a l i n g w i t h t h e L 3 c a c h e
* on t h e 7 4 5 x f a m i l y o f c h i p s
* /
_ GLOBAL( _ s e t _ L 3 C R )
/* Make sure this is a 745x chip */
BEGIN_ F T R _ S E C T I O N
li r3 ,- 1
blr
END_ F T R _ S E C T I O N _ I F C L R ( C P U _ F T R _ L 3 C R )
/* Turn off interrupts and data relocation. */
mfmsr r7 / * S a v e M S R i n r7 * /
rlwinm r4 ,r7 ,0 ,1 7 ,1 5
rlwinm r4 ,r4 ,0 ,2 8 ,2 6 / * T u r n o f f D R b i t * /
sync
mtmsr r4
isync
/* Stop DST streams */
DSSALL
sync
/* Get the current enable bit of the L3CR into r4 */
mfspr r4 ,S P R N _ L 3 C R
/* Tweak some bits */
rlwinm r5 ,r3 ,0 ,0 ,0 / * r5 c o n t a i n s t h e n e w e n a b l e b i t * /
rlwinm r3 ,r3 ,0 ,2 2 ,2 0 / * T u r n o f f t h e i n v a l i d a t e b i t * /
rlwinm r3 ,r3 ,0 ,2 ,3 1 / * T u r n o f f t h e e n a b l e & P E b i t s * /
rlwinm r3 ,r3 ,0 ,5 ,3 / * T u r n o f f t h e c l k e n b i t * /
/* Check to see if we need to flush */
rlwinm. r4 ,r4 ,0 ,0 ,0
beq 2 f
/ * Flush t h e c a c h e .
* /
/* TODO: use HW flush assist */
lis r4 ,0 x00 0 8
mtctr r4
li r4 ,0
1 :
2017-08-14 21:42:43 +03:00
lwzx r0 ,0 ,r4
2005-04-17 02:20:36 +04:00
dcbf 0 ,r4
addi r4 ,r4 ,3 2 / * G o t o s t a r t o f n e x t c a c h e l i n e * /
bdnz 1 b
2 :
/* Set up the L3CR configuration bits (and switch L3 off) */
sync
mtspr S P R N _ L 3 C R ,r3
sync
oris r3 ,r3 ,L 3 C R _ L 3 R E S @h /* Set reserved bit 5 */
mtspr S P R N _ L 3 C R ,r3
sync
oris r3 ,r3 ,L 3 C R _ L 3 C L K E N @h /* Set clken */
mtspr S P R N _ L 3 C R ,r3
sync
/* Wait for stabilize */
li r0 ,2 5 6
mtctr r0
1 : bdnz 1 b
/* Perform a global invalidation */
ori r3 ,r3 ,0 x04 0 0
sync
mtspr S P R N _ L 3 C R ,r3
sync
isync
/* We wait for the L3I bit to clear...... */
10 : mfspr r3 ,S P R N _ L 3 C R
andi. r4 ,r3 ,0 x04 0 0
bne 1 0 b
/* Clear CLKEN */
rlwinm r3 ,r3 ,0 ,5 ,3 / * T u r n o f f t h e c l k e n b i t * /
mtspr S P R N _ L 3 C R ,r3
sync
/* Wait for stabilize */
li r0 ,2 5 6
mtctr r0
1 : bdnz 1 b
/* See if we need to enable the cache */
cmplwi r5 ,0
beq 4 f
/* Enable the cache */
oris r3 ,r3 ,( L 3 C R _ L 3 E | L 3 C R _ L 3 C L K E N ) @h
mtspr S P R N _ L 3 C R ,r3
sync
/* Wait for stabilize */
li r0 ,2 5 6
mtctr r0
1 : bdnz 1 b
/* Restore MSR (restores EE and DR bits to original state) */
4 : SYNC
mtmsr r7
isync
blr
_ GLOBAL( _ g e t _ L 3 C R )
/* Return the L3CR contents */
li r3 ,0
BEGIN_ F T R _ S E C T I O N
mfspr r3 ,S P R N _ L 3 C R
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ L 3 C R )
blr
/ * - - - End o f P o w e r L o g i x c o d e - - -
* /
/ * flush_ d i s a b l e _ L 1 ( ) - F l u s h a n d d i s a b l e L 1 c a c h e
*
* clobbers r0 , r3 , c t r , c r0
* Must b e c a l l e d w i t h i n t e r r u p t s d i s a b l e d a n d M M U e n a b l e d .
* /
_ GLOBAL( _ _ f l u s h _ d i s a b l e _ L 1 )
/* Stop pending alitvec streams and memory accesses */
BEGIN_ F T R _ S E C T I O N
DSSALL
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ A L T I V E C )
sync
/ * Load c o u n t e r t o 0 x40 0 0 c a c h e l i n e s ( 5 1 2 k ) a n d
* load c a c h e w i t h d a t a s
* /
li r3 ,0 x40 0 0 / * 5 1 2 k B / 3 2 B * /
mtctr r3
lis r3 ,K E R N E L B A S E @h
1 :
lwz r0 ,0 ( r3 )
addi r3 ,r3 ,0 x00 2 0 / * G o t o s t a r t o f n e x t c a c h e l i n e * /
bdnz 1 b
isync
sync
/* Now flush those cache lines */
li r3 ,0 x40 0 0 / * 5 1 2 k B / 3 2 B * /
mtctr r3
lis r3 ,K E R N E L B A S E @h
1 :
dcbf 0 ,r3
addi r3 ,r3 ,0 x00 2 0 / * G o t o s t a r t o f n e x t c a c h e l i n e * /
bdnz 1 b
sync
/* We can now disable the L1 cache (HID0:DCE, HID0:ICE) */
mfspr r3 ,S P R N _ H I D 0
rlwinm r3 ,r3 ,0 ,1 8 ,1 5
mtspr S P R N _ H I D 0 ,r3
sync
isync
blr
/ * inval_ e n a b l e _ L 1 - I n v a l i d a t e a n d e n a b l e L 1 c a c h e
*
* Assumes L 1 i s a l r e a d y d i s a b l e d a n d M S R : E E i s o f f
*
* clobbers r3
* /
_ GLOBAL( _ _ i n v a l _ e n a b l e _ L 1 )
/* Enable and then Flash inval the instruction & data cache */
mfspr r3 ,S P R N _ H I D 0
ori r3 ,r3 , H I D 0 _ I C E | H I D 0 _ I C F I | H I D 0 _ D C E | H I D 0 _ D C I
sync
isync
mtspr S P R N _ H I D 0 ,r3
xori r3 ,r3 , H I D 0 _ I C F I | H I D 0 _ D C I
mtspr S P R N _ H I D 0 ,r3
sync
blr