2008-12-18 22:13:42 +03:00
/ *
* This f i l e c o n t a i n s l o w - l e v e l f u n c t i o n s f o r p e r f o r m i n g v a r i o u s
* types o f T L B i n v a l i d a t i o n s o n v a r i o u s p r o c e s s o r s w i t h n o h a s h
* table.
*
* This f i l e i m p l e m e n t s t h e f o l l o w i n g f u n c t i o n s f o r a l l n o - h a s h
* processors. S o m e a r e n ' t i m p l e m e n t e d f o r s o m e v a r i a n t s . S o m e
* are i n l i n e i n t l b f l u s h . h
*
* - tlbil_ v a
* - tlbil_ p i d
* - tlbil_ a l l
2010-03-05 13:43:12 +03:00
* - tlbivax_ b c a s t
2008-12-18 22:13:42 +03:00
*
* Code m o s t l y m o v e d o v e r f r o m m i s c _ 3 2 . S
*
* Copyright ( C ) 1 9 9 5 - 1 9 9 6 G a r y T h o m a s ( g d t @linuxppc.org)
*
* Partially r e w r i t t e n b y C o r t D o u g a n ( c o r t @cs.nmt.edu)
* Paul M a c k e r r a s , K u m a r G a l a a n d B e n j a m i n H e r r e n s c h m i d t .
*
* 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 i t 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
* as p u b l i s h e d 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 ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
*
* /
# include < a s m / r e g . h >
# include < a s m / p a g e . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / m m u . h >
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / p r o c e s s o r . h >
2010-03-05 13:43:12 +03:00
# include < a s m / b u g . h >
2008-12-18 22:13:42 +03:00
# if d e f i n e d ( C O N F I G _ 4 0 x )
/ *
* 4 0 x i m p l e m e n t a t i o n n e e d s o n l y t l b i l _ v a
* /
2009-07-24 03:15:24 +04:00
_ GLOBAL( _ _ t l b i l _ v a )
2008-12-18 22:13:42 +03:00
/ * We r u n t h e s e a r c h w i t h i n t e r r u p t s d i s a b l e d b e c a u s e w e h a v e t o c h a n g e
* the P I D a n d I d o n ' t w a n t t o p r e e m p t w h e n t h a t h a p p e n s .
* /
mfmsr r5
mfspr r6 ,S P R N _ P I D
wrteei 0
mtspr S P R N _ P I D ,r4
tlbsx. r3 , 0 , r3
mtspr S P R N _ P I D ,r6
wrtee r5
bne 1 f
sync
/ * There a r e o n l y 6 4 T L B e n t r i e s , s o r3 < 6 4 , w h i c h m e a n s b i t 2 5 i s
* clear. S i n c e 2 5 i s t h e V b i t i n t h e T L B _ T A G , l o a d i n g t h i s v a l u e
* will i n v a l i d a t e t h e T L B e n t r y . * /
tlbwe r3 , r3 , T L B _ T A G
isync
1 : blr
# elif d e f i n e d ( C O N F I G _ 8 x x )
/ *
* Nothing t o d o f o r 8 x x , e v e r y t h i n g i s i n l i n e
* /
2010-03-05 13:43:12 +03:00
# elif d e f i n e d ( C O N F I G _ 4 4 x ) / * I n c l u d e s 4 7 x * /
2008-12-18 22:13:42 +03:00
/ *
* 4 4 0 implementation u s e s t l b s x / w e f o r t l b i l _ v a a n d a f u l l s w e e p
* of t h e T L B f o r e v e r y t h i n g e l s e .
* /
2009-07-24 03:15:24 +04:00
_ GLOBAL( _ _ t l b i l _ v a )
2008-12-18 22:13:42 +03:00
mfspr r5 ,S P R N _ M M U C R
2010-03-05 13:43:12 +03:00
mfmsr r10
/ *
* We w r i t e 1 6 b i t s o f S T I D s i n c e 4 7 x s u p p o r t s t h a t m u c h , w e
* will n e v e r b e p a s s e d o u t o f b o u n d s v a l u e s o n 4 4 0 ( h o p e f u l l y )
* /
rlwimi r5 ,r4 ,0 ,1 6 ,3 1
2008-12-18 22:13:42 +03:00
2008-12-18 22:13:46 +03:00
/ * We h a v e t o r u n t h e s e a r c h w i t h i n t e r r u p t s d i s a b l e d , o t h e r w i s e
* an i n t e r r u p t w h i c h c a u s e s a T L B m i s s c a n c l o b b e r t h e M M U C R
* between t h e m t s p r a n d t h e t l b s x .
*
* Critical a n d M a c h i n e C h e c k i n t e r r u p t s t a k e c a r e o f s a v i n g
* and r e s t o r i n g M M U C R , s o o n l y n o r m a l i n t e r r u p t s h a v e t o b e
* taken c a r e o f .
* /
wrteei 0
2008-12-18 22:13:42 +03:00
mtspr S P R N _ M M U C R ,r5
2010-03-05 13:43:12 +03:00
tlbsx. r6 ,0 ,r3
bne 1 0 f
2008-12-18 22:13:42 +03:00
sync
2010-03-05 13:43:12 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
b 2 f
END_ M M U _ F T R _ S E C T I O N _ I F S E T ( M M U _ F T R _ T Y P E _ 4 7 x )
/ * On 4 4 0 T h e r e a r e o n l y 6 4 T L B e n t r i e s , s o r3 < 6 4 , w h i c h m e a n s b i t
* 2 2 , is c l e a r . S i n c e 2 2 i s t h e V b i t i n t h e T L B _ P A G E I D , l o a d i n g t h i s
2008-12-18 22:13:42 +03:00
* value w i l l i n v a l i d a t e t h e T L B e n t r y .
* /
2010-03-05 13:43:12 +03:00
tlbwe r6 ,r6 ,P P C 4 4 x _ T L B _ P A G E I D
2008-12-18 22:13:42 +03:00
isync
2010-03-05 13:43:12 +03:00
10 : wrtee r10
blr
2 :
# ifdef C O N F I G _ P P C _ 4 7 x
oris r7 ,r6 ,0 x80 0 0 / * s p e c i f y w a y e x p l i c i t e l y * /
clrrwi r4 ,r3 ,1 2 / * g e t a n E P N f o r t h e h a s h i n g w i t h V = 0 * /
ori r4 ,r4 ,P P C 4 7 x _ T L B E _ S I Z E
tlbwe r4 ,r7 ,0 / * w r i t e i t * /
isync
wrtee r10
blr
# else / * C O N F I G _ P P C _ 4 7 x * /
1 : trap
EMIT_ B U G _ E N T R Y 1 b ,_ _ F I L E _ _ ,_ _ L I N E _ _ ,0 ;
# endif / * ! C O N F I G _ P P C _ 4 7 x * /
2008-12-18 22:13:42 +03:00
_ GLOBAL( _ t l b i l _ a l l )
_ GLOBAL( _ t l b i l _ p i d )
2010-03-05 13:43:12 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
b 2 f
END_ M M U _ F T R _ S E C T I O N _ I F S E T ( M M U _ F T R _ T Y P E _ 4 7 x )
2008-12-18 22:13:42 +03:00
li r3 ,0
sync
/* Load high watermark */
lis r4 ,t l b _ 4 4 x _ h w a t e r @ha
lwz r5 ,t l b _ 4 4 x _ h w a t e r @l(r4)
1 : tlbwe r3 ,r3 ,P P C 4 4 x _ T L B _ P A G E I D
addi r3 ,r3 ,1
cmpw 0 ,r3 ,r5
ble 1 b
isync
blr
2010-03-05 13:43:12 +03:00
2 :
# ifdef C O N F I G _ P P C _ 4 7 x
/ * 4 7 6 variant. T h e r e ' s n o t s i m p l e w a y t o d o t h i s , h o p e f u l l y w e ' l l
* try t o l i m i t t h e a m o u n t o f s u c h f u l l i n v a l i d a t e s
* /
mfmsr r11 / * I n t e r r u p t s o f f * /
wrteei 0
li r3 ,- 1 / * C u r r e n t s e t * /
lis r10 ,t l b _ 4 7 x _ b o l t m a p @h
ori r10 ,r10 ,t l b _ 4 7 x _ b o l t m a p @l
lis r7 ,0 x80 0 0 / * S p e c i f y w a y e x p l i c i t e l y * /
b 9 f / * F o r e a c h s e t * /
1 : li r9 ,4 / * N u m b e r o f w a y s * /
li r4 ,0 / * C u r r e n t w a y * /
li r6 ,0 / * D e f a u l t e n t r y v a l u e 0 * /
andi. r0 ,r8 ,1 / * C h e c k i f w a y 0 i s b o l t e d * /
mtctr r9 / * L o a d w a y c o u n t e r * /
bne- 3 f / * B o l t e d , s k i p l o a d i n g i t * /
2 : /* For each way */
or r5 ,r3 ,r4 / * M a k e w a y | i n d e x f o r t l b r e * /
rlwimi r5 ,r5 ,1 6 ,8 ,1 5 / * C o p y i n d e x i n t o p o s i t i o n * /
tlbre r6 ,r5 ,0 / * R e a d e n t r y * /
3 : addis r4 ,r4 ,0 x20 0 0 / * N e x t w a y * /
andi. r0 ,r6 ,P P C 4 7 x _ T L B 0 _ V A L I D / * V a l i d e n t r y ? * /
beq 4 f / * N o p e , s k i p i t * /
rlwimi r7 ,r5 ,0 ,1 ,2 / * I n s e r t w a y n u m b e r * /
rlwinm r6 ,r6 ,0 ,2 1 ,1 9 / * C l e a r V * /
tlbwe r6 ,r7 ,0 / * W r i t e i t * /
4 : bdnz 2 b / * L o o p f o r e a c h w a y * /
srwi r8 ,r8 ,1 / * N e x t b o l t m a p b i t * /
9 : cmpwi c r1 ,r3 ,2 5 5 / * L a s t s e t d o n e ? * /
addi r3 ,r3 ,1 / * N e x t s e t * /
beq c r1 ,1 f / * E n d o f l o o p * /
andi. r0 ,r3 ,0 x1 f / * N e e d t o l o a d a n e w b o l t m a p w o r d ? * /
bne 1 b / * N o , l o o p * /
lwz r8 ,0 ( r10 ) / * L o a d b o l t m a p e n t r y * /
addi r10 ,r10 ,4 / * N e x t w o r d * /
b 1 b / * T h e n l o o p * /
1 : isync / * S y n c s h a d o w s * /
wrtee r11
# else / * C O N F I G _ P P C _ 4 7 x * /
1 : trap
EMIT_ B U G _ E N T R Y 1 b ,_ _ F I L E _ _ ,_ _ L I N E _ _ ,0 ;
# endif / * ! C O N F I G _ P P C _ 4 7 x * /
blr
# ifdef C O N F I G _ P P C _ 4 7 x
2011-01-26 09:17:59 +03:00
/ *
* 4 7 x v a r i a n t o f i c b t
* /
# define I C B T ( C T ,R A ,R B ) \
.long 0x7c00002c | ( ( CT) < < 2 1 ) | ( ( R A ) < < 1 6 ) | ( ( R B ) < < 1 1 )
2010-03-05 13:43:12 +03:00
/ *
* _ tlbivax_ b c a s t i s o n l y o n 4 7 x . W e d o n ' t b o t h e r d o i n g a r u n t i m e
* check t h o u g h , i t w i l l b l o w u p s o o n e n o u g h i f w e m i s t a k e n l y t r y
* to u s e i t o n a 4 4 0 .
* /
_ GLOBAL( _ t l b i v a x _ b c a s t )
mfspr r5 ,S P R N _ M M U C R
mfmsr r10
rlwimi r5 ,r4 ,0 ,1 6 ,3 1
wrteei 0
mtspr S P R N _ M M U C R ,r5
2010-08-18 10:44:26 +04:00
isync
2010-03-05 13:43:12 +03:00
/* tlbivax 0,r3 - use .long to avoid binutils deps */
.long 0x7c000624 | ( r3 < < 1 1 )
isync
eieio
tlbsync
2011-01-26 09:17:59 +03:00
BEGIN_ F T R _ S E C T I O N
b 1 f
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ 4 7 6 _ D D 2 )
sync
wrtee r10
blr
/ *
* DD2 H W c o u l d h a n g i f i n i n s t r u c t i o n f e t c h h a p p e n s b e f o r e m s y n c c o m p l e t e s .
* Touch e n o u g h i n s t r u c t i o n c a c h e l i n e s t o e n s u r e c a c h e h i t s
* /
1 : mflr r9
bl 2 f
2 : mflr r6
li r7 ,3 2
ICBT( 0 ,r6 ,r7 ) / * t o u c h n e x t c a c h e l i n e * /
add r6 ,r6 ,r7
ICBT( 0 ,r6 ,r7 ) / * t o u c h n e x t c a c h e l i n e * /
add r6 ,r6 ,r7
ICBT( 0 ,r6 ,r7 ) / * t o u c h n e x t c a c h e l i n e * /
2010-03-05 13:43:12 +03:00
sync
2011-01-26 09:17:59 +03:00
nop
nop
nop
nop
nop
nop
nop
nop
mtlr r9
2010-03-05 13:43:12 +03:00
wrtee r10
blr
# endif / * C O N F I G _ P P C _ 4 7 x * /
2008-12-18 22:13:42 +03:00
# elif d e f i n e d ( C O N F I G _ F S L _ B O O K E )
/ *
2009-02-11 07:26:06 +03:00
* FSL B o o k E i m p l e m e n t a t i o n s .
*
* Since f e a t u r e s e c t i o n s a r e u s i n g _ S E C T I O N _ E L S E w e n e e d
* to h a v e t h e l a r g e r c o d e p a t h b e f o r e t h e _ S E C T I O N _ E L S E
2008-12-18 22:13:42 +03:00
* /
/ *
* Flush M M U T L B o n t h e l o c a l p r o c e s s o r
* /
_ GLOBAL( _ t l b i l _ a l l )
2009-02-11 07:26:06 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
li r3 ,( M M U C S R 0 _ T L B F I ) @l
mtspr S P R N _ M M U C S R 0 , r3
1 :
mfspr r3 ,S P R N _ M M U C S R 0
andi. r3 ,r3 ,M M U C S R 0 _ T L B F I @l
bne 1 b
MMU_ F T R _ S E C T I O N _ E L S E
2009-04-23 17:51:22 +04:00
PPC_ T L B I L X _ A L L ( 0 ,0 )
2009-02-11 07:26:06 +03:00
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F C L R ( M M U _ F T R _ U S E _ T L B I L X )
msync
isync
blr
_ GLOBAL( _ t l b i l _ p i d )
BEGIN_ M M U _ F T R _ S E C T I O N
slwi r3 ,r3 ,1 6
mfmsr r10
wrteei 0
mfspr r4 ,S P R N _ M A S 6 / * s a v e M A S 6 * /
mtspr S P R N _ M A S 6 ,r3
PPC_ T L B I L X _ P I D ( 0 ,0 )
mtspr S P R N _ M A S 6 ,r4 / * r e s t o r e M A S 6 * /
wrtee r10
MMU_ F T R _ S E C T I O N _ E L S E
2008-12-18 22:13:42 +03:00
li r3 ,( M M U C S R 0 _ T L B F I ) @l
mtspr S P R N _ M M U C S R 0 , r3
1 :
mfspr r3 ,S P R N _ M M U C S R 0
andi. r3 ,r3 ,M M U C S R 0 _ T L B F I @l
bne 1 b
2009-02-11 07:26:06 +03:00
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F S E T ( M M U _ F T R _ U S E _ T L B I L X )
2008-12-18 22:13:42 +03:00
msync
isync
blr
/ *
* Flush M M U T L B f o r a p a r t i c u l a r a d d r e s s , b u t o n l y o n t h e l o c a l p r o c e s s o r
* ( no b r o a d c a s t )
* /
2009-07-24 03:15:24 +04:00
_ GLOBAL( _ _ t l b i l _ v a )
2008-12-18 22:13:42 +03:00
mfmsr r10
wrteei 0
slwi r4 ,r4 ,1 6
2009-02-11 07:26:06 +03:00
ori r4 ,r4 ,( M A S 6 _ I S I Z E ( B O O K 3 E _ P A G E S Z _ 4 K ) ) @l
2008-12-18 22:13:42 +03:00
mtspr S P R N _ M A S 6 ,r4 / * a s s u m e A S =0 f o r n o w * /
2009-02-11 07:26:06 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
2008-12-18 22:13:42 +03:00
tlbsx 0 ,r3
mfspr r4 ,S P R N _ M A S 1 / * c h e c k v a l i d * /
andis. r3 ,r4 ,M A S 1 _ V A L I D @h
beq 1 f
rlwinm r4 ,r4 ,0 ,1 ,3 1
mtspr S P R N _ M A S 1 ,r4
tlbwe
2009-02-11 07:26:06 +03:00
MMU_ F T R _ S E C T I O N _ E L S E
PPC_ T L B I L X _ V A ( 0 ,r3 )
ALT_ M M U _ F T R _ S E C T I O N _ E N D _ I F C L R ( M M U _ F T R _ U S E _ T L B I L X )
2008-12-18 22:13:42 +03:00
msync
isync
1 : wrtee r10
blr
2009-07-24 03:15:47 +04:00
# elif d e f i n e d ( C O N F I G _ P P C _ B O O K 3 E )
/ *
* New B o o k 3 E ( > = 2 . 0 6 ) i m p l e m e n t a t i o n
*
* Note : We m a y b e a b l e t o g e t a w a y w i t h o u t t h e i n t e r r u p t m a s k i n g s t u f f
* if w e s a v e / r e s t o r e M A S 6 o n e x c e p t i o n s t h a t m i g h t m o d i f y i t
* /
_ GLOBAL( _ t l b i l _ p i d )
slwi r4 ,r3 ,M A S 6 _ S P I D _ S H I F T
mfmsr r10
wrteei 0
mtspr S P R N _ M A S 6 ,r4
PPC_ T L B I L X _ P I D ( 0 ,0 )
wrtee r10
msync
isync
blr
_ GLOBAL( _ t l b i l _ p i d _ n o i n d )
slwi r4 ,r3 ,M A S 6 _ S P I D _ S H I F T
mfmsr r10
ori r4 ,r4 ,M A S 6 _ S I N D
wrteei 0
mtspr S P R N _ M A S 6 ,r4
PPC_ T L B I L X _ P I D ( 0 ,0 )
wrtee r10
msync
isync
blr
_ GLOBAL( _ t l b i l _ a l l )
PPC_ T L B I L X _ A L L ( 0 ,0 )
msync
isync
blr
_ GLOBAL( _ t l b i l _ v a )
mfmsr r10
wrteei 0
cmpwi c r0 ,r6 ,0
slwi r4 ,r4 ,M A S 6 _ S P I D _ S H I F T
rlwimi r4 ,r5 ,M A S 6 _ I S I Z E _ S H I F T ,M A S 6 _ I S I Z E _ M A S K
beq 1 f
rlwimi r4 ,r6 ,M A S 6 _ S I N D _ S H I F T ,M A S 6 _ S I N D
1 : mtspr S P R N _ M A S 6 ,r4 / * a s s u m e A S =0 f o r n o w * /
PPC_ T L B I L X _ V A ( 0 ,r3 )
msync
isync
wrtee r10
blr
_ GLOBAL( _ t l b i v a x _ b c a s t )
mfmsr r10
wrteei 0
cmpwi c r0 ,r6 ,0
slwi r4 ,r4 ,M A S 6 _ S P I D _ S H I F T
rlwimi r4 ,r5 ,M A S 6 _ I S I Z E _ S H I F T ,M A S 6 _ I S I Z E _ M A S K
beq 1 f
rlwimi r4 ,r6 ,M A S 6 _ S I N D _ S H I F T ,M A S 6 _ S I N D
1 : mtspr S P R N _ M A S 6 ,r4 / * a s s u m e A S =0 f o r n o w * /
PPC_ T L B I V A X ( 0 ,r3 )
eieio
tlbsync
sync
wrtee r10
blr
_ GLOBAL( s e t _ c o n t e x t )
# ifdef C O N F I G _ B D I _ S W I T C H
/ * Context s w i t c h t h e P T E p o i n t e r f o r t h e A b a t r o n B D I 2 0 0 0 .
* The P G D I R i s t h e s e c o n d p a r a m e t e r .
* /
lis r5 , a b a t r o n _ p t e p t r s @h
ori r5 , r5 , a b a t r o n _ p t e p t r s @l
stw r4 , 0 x4 ( r5 )
# endif
mtspr S P R N _ P I D ,r3
isync / * F o r c e c o n t e x t c h a n g e * /
blr
2009-04-23 16:56:11 +04:00
# else
2008-12-18 22:13:42 +03:00
# error U n s u p p o r t e d p r o c e s s o r t y p e !
# endif
2010-05-13 23:38:21 +04:00
2009-10-17 03:48:40 +04:00
# if d e f i n e d ( C O N F I G _ P P C _ F S L _ B O O K 3 E )
2010-05-13 23:38:21 +04:00
/ *
* extern v o i d l o a d c a m _ e n t r y ( u n s i g n e d i n t i n d e x )
*
* Load T L B C A M [ i n d e x ] e n t r y i n t o t h e L 2 C A M M M U
* /
_ GLOBAL( l o a d c a m _ e n t r y )
LOAD_ R E G _ A D D R ( r4 , T L B C A M )
mulli r5 ,r3 ,T L B C A M _ S I Z E
add r3 ,r5 ,r4
lwz r4 ,T L B C A M _ M A S 0 ( r3 )
mtspr S P R N _ M A S 0 ,r4
lwz r4 ,T L B C A M _ M A S 1 ( r3 )
mtspr S P R N _ M A S 1 ,r4
PPC_ L L r4 ,T L B C A M _ M A S 2 ( r3 )
mtspr S P R N _ M A S 2 ,r4
lwz r4 ,T L B C A M _ M A S 3 ( r3 )
mtspr S P R N _ M A S 3 ,r4
BEGIN_ M M U _ F T R _ S E C T I O N
lwz r4 ,T L B C A M _ M A S 7 ( r3 )
mtspr S P R N _ M A S 7 ,r4
END_ M M U _ F T R _ S E C T I O N _ I F S E T ( M M U _ F T R _ B I G _ P H Y S )
isync
tlbwe
isync
blr
# endif