2005-10-10 22:36:14 +10:00
/ *
* This f i l e c o n t a i n s m i s c e l l a n e o u s l o w - l e v e l f u n c t i o n 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)
*
* Largely 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)
* and P a u l M a c k e r r a s .
* Adapted f o r i S e r i e s b y M i k e C o r r i g a n ( m i k e j c @us.ibm.com)
2006-06-28 11:55:49 +10:00
* PPC6 4 u p d a t e s b y D a v e E n g e b r e t s e n ( e n g e b r e t @us.ibm.com)
*
2005-10-10 22:36:14 +10:00
* 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 < l i n u x / s y s . h >
# include < a s m / u n i s t d . h >
# include < a s m / e r r n o . h >
# include < a s m / p r o c e s s o r . h >
# include < a s m / p a g e . h >
# include < a s m / c a c h e . 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 / c p u t a b l e . h >
[PATCH] powerpc: Merge thread_info.h
Merge ppc32 and ppc64 versions of thread_info.h. They were pretty
similar already, the chief changes are:
- Instead of inline asm to implement current_thread_info(),
which needs to be different for ppc32 and ppc64, we use C with an
asm("r1") register variable. gcc turns it into the same asm as we
used to have for both platforms.
- We replace ppc32's 'local_flags' with the ppc64
'syscall_noerror' field. The noerror flag was in fact the only thing
in the local_flags field anyway, so the ppc64 approach is simpler, and
means we only need a load-immediate/store instead of load/mask/store
when clearing the flag.
- In readiness for 64k pages, when THREAD_SIZE will be less
than a page, ppc64 used kmalloc() rather than get_free_pages() to
allocate the kernel stack. With this patch we do the same for ppc32,
since there's no strong reason not to.
- For ppc64, we no longer export THREAD_SHIFT and THREAD_SIZE
via asm-offsets, thread_info.h can now be safely included in asm, as
on ppc32.
Built and booted on G4 Powerbook (ARCH=ppc and ARCH=powerpc) and
Power5 (ARCH=ppc64 and ARCH=powerpc).
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-10-21 15:45:50 +10:00
# include < a s m / t h r e a d _ i n f o . h >
2010-05-13 19:40:11 +00:00
# include < a s m / k e x e c . h >
2010-11-18 15:06:17 +00:00
# include < a s m / p t r a c e . h >
2015-10-06 22:48:18 -05:00
# include < a s m / m m u . h >
2016-01-13 23:33:46 -05:00
# include < a s m / e x p o r t . h >
2005-10-10 22:36:14 +10:00
.text
_ GLOBAL( c a l l _ d o _ s o f t i r q )
mflr r0
std r0 ,1 6 ( r1 )
2008-04-24 13:20:16 +10:00
stdu r1 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ O V E R H E A D ( r3 )
2005-10-10 22:36:14 +10:00
mr r1 ,r3
2014-02-04 16:04:35 +11:00
bl _ _ d o _ s o f t i r q
2005-10-10 22:36:14 +10:00
ld r1 ,0 ( r1 )
ld r0 ,1 6 ( r1 )
mtlr r0
blr
2013-09-23 14:29:11 +10:00
_ GLOBAL( c a l l _ d o _ i r q )
2005-10-10 22:36:14 +10:00
mflr r0
std r0 ,1 6 ( r1 )
2013-09-23 14:29:11 +10:00
stdu r1 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ O V E R H E A D ( r4 )
mr r1 ,r4
2014-02-04 16:04:35 +11:00
bl _ _ d o _ i r q
2005-10-10 22:36:14 +10:00
ld r1 ,0 ( r1 )
ld r0 ,1 6 ( r1 )
mtlr r0
blr
.section " .toc " , " aw"
PPC64_CACHES :
.tc ppc6 4 _ c a c h e s [ T C ] ,p p c64 _ c a c h e s
.section " .text "
/ *
* Write a n y m o d i f i e d d a t a c a c h e b l o c k s o u t t o m e m o r y
* and i n v a l i d a t e t h e c o r r e s p o n d i n g i n s t r u c t i o n c a c h e b l o c k s .
*
* flush_ i c a c h e _ r a n g e ( u n s i g n e d l o n g s t a r t , u n s i g n e d l o n g s t o p )
*
* flush a l l b y t e s f r o m s t a r t t h r o u g h s t o p - 1 i n c l u s i v e
* /
2017-04-03 13:25:12 +10:00
_ GLOBAL_ T O C ( f l u s h _ i c a c h e _ r a n g e )
2013-08-06 18:23:30 +08:00
BEGIN_ F T R _ S E C T I O N
2013-08-22 09:30:35 +08:00
PURGE_ P R E F E T C H E D _ I N S
2013-08-06 18:23:30 +08:00
blr
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ C O H E R E N T _ I C A C H E )
2005-10-10 22:36:14 +10:00
/ *
* Flush t h e d a t a c a c h e t o m e m o r y
*
* Different s y s t e m s h a v e d i f f e r e n t c a c h e l i n e s i z e s
* and i n s o m e c a s e s i - c a c h e a n d d - c a c h e l i n e s i z e s d i f f e r f r o m
* each o t h e r .
* /
ld r10 ,P P C 6 4 _ C A C H E S @toc(r2)
2017-01-08 17:31:45 -06:00
lwz r7 ,D C A C H E L 1 B L O C K S I Z E ( r10 ) / * G e t c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
addi r5 ,r7 ,- 1
andc r6 ,r3 ,r5 / * r o u n d l o w t o l i n e b d y * /
subf r8 ,r6 ,r4 / * c o m p u t e l e n g t h * /
add r8 ,r8 ,r5 / * e n s u r e w e g e t e n o u g h * /
2017-01-08 17:31:45 -06:00
lwz r9 ,D C A C H E L 1 L O G B L O C K S I Z E ( r10 ) / * G e t l o g - 2 o f c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
srw. r8 ,r8 ,r9 / * c o m p u t e l i n e c o u n t * /
beqlr / * n o t h i n g t o d o ? * /
mtctr r8
1 : dcbst 0 ,r6
add r6 ,r6 ,r7
bdnz 1 b
sync
/* Now invalidate the instruction cache */
2017-01-08 17:31:45 -06:00
lwz r7 ,I C A C H E L 1 B L O C K S I Z E ( r10 ) / * G e t I c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
addi r5 ,r7 ,- 1
andc r6 ,r3 ,r5 / * r o u n d l o w t o l i n e b d y * /
subf r8 ,r6 ,r4 / * c o m p u t e l e n g t h * /
add r8 ,r8 ,r5
2017-01-08 17:31:45 -06:00
lwz r9 ,I C A C H E L 1 L O G B L O C K S I Z E ( r10 ) / * G e t l o g - 2 o f I c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
srw. r8 ,r8 ,r9 / * c o m p u t e l i n e c o u n t * /
beqlr / * n o t h i n g t o d o ? * /
mtctr r8
2 : icbi 0 ,r6
add r6 ,r6 ,r7
bdnz 2 b
isync
blr
2016-09-16 20:48:17 +10:00
_ ASM_ N O K P R O B E _ S Y M B O L ( f l u s h _ i c a c h e _ r a n g e )
2016-01-13 23:33:46 -05:00
EXPORT_ S Y M B O L ( f l u s h _ i c a c h e _ r a n g e )
2016-09-16 20:48:17 +10:00
2005-10-10 22:36:14 +10:00
/ *
* Like a b o v e , b u t o n l y d o t h e D - c a c h e .
*
* flush_ d c a c h e _ r a n g e ( u n s i g n e d l o n g s t a r t , u n s i g n e d l o n g s t o p )
*
* flush a l l b y t e s f r o m s t a r t t o s t o p - 1 i n c l u s i v e
* /
2017-04-03 13:25:12 +10:00
_ GLOBAL_ T O C ( f l u s h _ d c a c h e _ r a n g e )
2005-10-10 22:36:14 +10:00
/ *
* Flush t h e d a t a c a c h e t o m e m o r y
*
* Different s y s t e m s h a v e d i f f e r e n t c a c h e l i n e s i z e s
* /
ld r10 ,P P C 6 4 _ C A C H E S @toc(r2)
2017-01-08 17:31:45 -06:00
lwz r7 ,D C A C H E L 1 B L O C K S I Z E ( r10 ) / * G e t d c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
addi r5 ,r7 ,- 1
andc r6 ,r3 ,r5 / * r o u n d l o w t o l i n e b d y * /
subf r8 ,r6 ,r4 / * c o m p u t e l e n g t h * /
add r8 ,r8 ,r5 / * e n s u r e w e g e t e n o u g h * /
2017-01-08 17:31:45 -06:00
lwz r9 ,D C A C H E L 1 L O G B L O C K S I Z E ( r10 ) / * G e t l o g - 2 o f d c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
srw. r8 ,r8 ,r9 / * c o m p u t e l i n e c o u n t * /
beqlr / * n o t h i n g t o d o ? * /
mtctr r8
0 : dcbst 0 ,r6
add r6 ,r6 ,r7
bdnz 0 b
sync
blr
2016-01-13 23:33:46 -05:00
EXPORT_ S Y M B O L ( f l u s h _ d c a c h e _ r a n g e )
2005-10-10 22:36:14 +10:00
/ *
* Like a b o v e , b u t w o r k s o n n o n - m a p p e d p h y s i c a l a d d r e s s e s .
* Use o n l y f o r n o n - L P A R s e t u p s ! I t a l s o a s s u m e s r e a l m o d e
* is c a c h e a b l e . U s e d f o r f l u s h i n g o u t t h e D A R T b e f o r e u s i n g
* it a s u n c a c h e a b l e m e m o r y
*
* flush_ d c a c h e _ p h y s _ r a n g e ( u n s i g n e d l o n g s t a r t , u n s i g n e d l o n g s t o p )
*
* flush a l l b y t e s f r o m s t a r t t o s t o p - 1 i n c l u s i v e
* /
_ GLOBAL( f l u s h _ d c a c h e _ p h y s _ r a n g e )
ld r10 ,P P C 6 4 _ C A C H E S @toc(r2)
2017-01-08 17:31:45 -06:00
lwz r7 ,D C A C H E L 1 B L O C K S I Z E ( r10 ) / * G e t d c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
addi r5 ,r7 ,- 1
andc r6 ,r3 ,r5 / * r o u n d l o w t o l i n e b d y * /
subf r8 ,r6 ,r4 / * c o m p u t e l e n g t h * /
add r8 ,r8 ,r5 / * e n s u r e w e g e t e n o u g h * /
2017-01-08 17:31:45 -06:00
lwz r9 ,D C A C H E L 1 L O G B L O C K S I Z E ( r10 ) / * G e t l o g - 2 o f d c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
srw. r8 ,r8 ,r9 / * c o m p u t e l i n e c o u n t * /
beqlr / * n o t h i n g t o d o ? * /
mfmsr r5 / * D i s a b l e M M U D a t a R e l o c a t i o n * /
ori r0 ,r5 ,M S R _ D R
xori r0 ,r0 ,M S R _ D R
sync
mtmsr r0
sync
isync
mtctr r8
0 : dcbst 0 ,r6
add r6 ,r6 ,r7
bdnz 0 b
sync
isync
mtmsr r5 / * R e - e n a b l e M M U D a t a R e l o c a t i o n * /
sync
isync
blr
_ GLOBAL( f l u s h _ i n v a l _ d c a c h e _ r a n g e )
ld r10 ,P P C 6 4 _ C A C H E S @toc(r2)
2017-01-08 17:31:45 -06:00
lwz r7 ,D C A C H E L 1 B L O C K S I Z E ( r10 ) / * G e t d c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
addi r5 ,r7 ,- 1
andc r6 ,r3 ,r5 / * r o u n d l o w t o l i n e b d y * /
subf r8 ,r6 ,r4 / * c o m p u t e l e n g t h * /
add r8 ,r8 ,r5 / * e n s u r e w e g e t e n o u g h * /
2017-01-08 17:31:45 -06:00
lwz r9 ,D C A C H E L 1 L O G B L O C K S I Z E ( r10 ) / * G e t l o g - 2 o f d c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
srw. r8 ,r8 ,r9 / * c o m p u t e l i n e c o u n t * /
beqlr / * n o t h i n g t o d o ? * /
sync
isync
mtctr r8
0 : dcbf 0 ,r6
add r6 ,r6 ,r7
bdnz 0 b
sync
isync
blr
/ *
* Flush a p a r t i c u l a r p a g e f r o m t h e d a t a c a c h e t o R A M .
* Note : this i s n e c e s s a r y b e c a u s e t h e i n s t r u c t i o n c a c h e d o e s * n o t *
* snoop f r o m t h e d a t a c a c h e .
*
* void _ _ f l u s h _ d c a c h e _ i c a c h e ( v o i d * p a g e )
* /
_ GLOBAL( _ _ f l u s h _ d c a c h e _ i c a c h e )
/ *
* Flush t h e d a t a c a c h e t o m e m o r y
*
* Different s y s t e m s h a v e d i f f e r e n t c a c h e l i n e s i z e s
* /
2013-08-22 09:30:35 +08:00
BEGIN_ F T R _ S E C T I O N
PURGE_ P R E F E T C H E D _ I N S
blr
END_ F T R _ S E C T I O N _ I F S E T ( C P U _ F T R _ C O H E R E N T _ I C A C H E )
2005-10-10 22:36:14 +10:00
/* Flush the dcache */
ld r7 ,P P C 6 4 _ C A C H E S @toc(r2)
clrrdi r3 ,r3 ,P A G E _ S H I F T / * P a g e a l i g n * /
2017-01-08 17:31:45 -06:00
lwz r4 ,D C A C H E L 1 B L O C K S P E R P A G E ( r7 ) / * G e t # d c a c h e b l o c k s p e r p a g e * /
lwz r5 ,D C A C H E L 1 B L O C K S I Z E ( r7 ) / * G e t d c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
mr r6 ,r3
mtctr r4
0 : dcbst 0 ,r6
add r6 ,r6 ,r5
bdnz 0 b
sync
/* Now invalidate the icache */
2017-01-08 17:31:45 -06:00
lwz r4 ,I C A C H E L 1 B L O C K S P E R P A G E ( r7 ) / * G e t # i c a c h e b l o c k s p e r p a g e * /
lwz r5 ,I C A C H E L 1 B L O C K S I Z E ( r7 ) / * G e t i c a c h e b l o c k s i z e * /
2005-10-10 22:36:14 +10:00
mtctr r4
1 : icbi 0 ,r3
add r3 ,r3 ,r5
bdnz 1 b
isync
blr
2013-05-13 00:23:38 +00:00
_ GLOBAL( _ _ b s w a p d i 2 )
2016-01-13 23:33:46 -05:00
EXPORT_ S Y M B O L ( _ _ b s w a p d i 2 )
2013-05-13 00:23:38 +00:00
srdi r8 ,r3 ,3 2
rlwinm r7 ,r3 ,8 ,0 x f f f f f f f f
rlwimi r7 ,r3 ,2 4 ,0 ,7
rlwinm r9 ,r8 ,8 ,0 x f f f f f f f f
rlwimi r7 ,r3 ,2 4 ,1 6 ,2 3
rlwimi r9 ,r8 ,2 4 ,0 ,7
rlwimi r9 ,r8 ,2 4 ,1 6 ,2 3
sldi r7 ,r7 ,3 2
or r3 ,r7 ,r9
blr
2006-09-25 18:19:00 +10:00
2013-07-25 12:12:32 +10:00
2013-11-29 14:55:22 +11:00
# ifdef C O N F I G _ P P C _ E A R L Y _ D E B U G _ B O O T X
2013-07-25 12:12:32 +10:00
_ GLOBAL( r m c i _ o n )
sync
isync
li r3 ,0 x10 0
rldicl r3 ,r3 ,3 2 ,0
mfspr r5 ,S P R N _ H I D 4
or r5 ,r5 ,r3
sync
mtspr S P R N _ H I D 4 ,r5
isync
slbia
isync
sync
blr
_ GLOBAL( r m c i _ o f f )
sync
isync
li r3 ,0 x10 0
rldicl r3 ,r3 ,3 2 ,0
mfspr r5 ,S P R N _ H I D 4
andc r5 ,r5 ,r3
sync
mtspr S P R N _ H I D 4 ,r5
isync
slbia
isync
sync
blr
2013-11-29 14:55:22 +11:00
# endif / * C O N F I G _ P P C _ E A R L Y _ D E B U G _ B O O T X * /
# if d e f i n e d ( C O N F I G _ P P C _ P M A C ) | | d e f i n e d ( C O N F I G _ P P C _ M A P L E )
2013-07-25 12:12:32 +10:00
2005-10-10 22:36:14 +10:00
/ *
* Do a n I O a c c e s s i n r e a l m o d e
* /
_ GLOBAL( r e a l _ r e a d b )
mfmsr r7
ori r0 ,r7 ,M S R _ D R
xori r0 ,r0 ,M S R _ D R
sync
mtmsrd r0
sync
isync
mfspr r6 ,S P R N _ H I D 4
rldicl r5 ,r6 ,3 2 ,0
ori r5 ,r5 ,0 x10 0
rldicl r5 ,r5 ,3 2 ,0
sync
mtspr S P R N _ H I D 4 ,r5
isync
slbia
isync
lbz r3 ,0 ( r3 )
sync
mtspr S P R N _ H I D 4 ,r6
isync
slbia
isync
mtmsrd r7
sync
isync
blr
/ *
* Do a n I O a c c e s s i n r e a l m o d e
* /
_ GLOBAL( r e a l _ w r i t e b )
mfmsr r7
ori r0 ,r7 ,M S R _ D R
xori r0 ,r0 ,M S R _ D R
sync
mtmsrd r0
sync
isync
mfspr r6 ,S P R N _ H I D 4
rldicl r5 ,r6 ,3 2 ,0
ori r5 ,r5 ,0 x10 0
rldicl r5 ,r5 ,3 2 ,0
sync
mtspr S P R N _ H I D 4 ,r5
isync
slbia
isync
stb r3 ,0 ( r4 )
sync
mtspr S P R N _ H I D 4 ,r6
isync
slbia
isync
mtmsrd r7
sync
isync
blr
# endif / * d e f i n e d ( C O N F I G _ P P C _ P M A C ) | | d e f i n e d ( C O N F I G _ P P C _ M A P L E ) * /
2007-02-04 16:36:49 -06:00
# ifdef C O N F I G _ P P C _ P A S E M I
_ GLOBAL( r e a l _ 2 0 5 _ r e a d b )
mfmsr r7
ori r0 ,r7 ,M S R _ D R
xori r0 ,r0 ,M S R _ D R
sync
mtmsrd r0
sync
isync
2012-06-25 13:33:18 +00:00
LBZCIX( R 3 ,R 0 ,R 3 )
2007-02-04 16:36:49 -06:00
isync
mtmsrd r7
sync
isync
blr
_ GLOBAL( r e a l _ 2 0 5 _ w r i t e b )
mfmsr r7
ori r0 ,r7 ,M S R _ D R
xori r0 ,r0 ,M S R _ D R
sync
mtmsrd r0
sync
isync
2012-06-25 13:33:18 +00:00
STBCIX( R 3 ,R 0 ,R 4 )
2007-02-04 16:36:49 -06:00
isync
mtmsrd r7
sync
isync
blr
# endif / * C O N F I G _ P P C _ P A S E M I * /
2011-06-17 03:10:06 +00:00
# if d e f i n e d ( C O N F I G _ C P U _ F R E Q _ P M A C 6 4 ) | | d e f i n e d ( C O N F I G _ C P U _ F R E Q _ M A P L E )
2005-11-07 14:27:33 +11:00
/ *
* SCOM a c c e s s f u n c t i o n s f o r 9 7 0 ( F X o n l y f o r n o w )
*
* unsigned l o n g s c o m 9 7 0 _ r e a d ( u n s i g n e d i n t a d d r e s s ) ;
* void s c o m 9 7 0 _ w r i t e ( u n s i g n e d i n t a d d r e s s , u n s i g n e d l o n g v a l u e ) ;
*
* The a d d r e s s p a s s e d i n i s t h e 2 4 b i t s r e g i s t e r a d d r e s s . T h i s c o d e
* is 9 7 0 s p e c i f i c a n d w i l l n o t c h e c k t h e s t a t u s b i t s , s o y o u s h o u l d
* know w h a t y o u a r e d o i n g .
* /
_ GLOBAL( s c o m 9 7 0 _ r e a d )
/* interrupts off */
mfmsr r4
ori r0 ,r4 ,M S R _ E E
xori r0 ,r0 ,M S R _ E E
mtmsrd r0 ,1
/ * rotate 2 4 b i t s S C O M a d d r e s s 8 b i t s l e f t a n d m a s k o u t i t ' s l o w 8 b i t s
* ( including p a r i t y ) . O n c u r r e n t C P U s t h e y m u s t b e 0 ' d ,
* and f i n a l l y o r i n R W b i t
* /
rlwinm r3 ,r3 ,8 ,0 ,1 5
ori r3 ,r3 ,0 x80 0 0
/* do the actual scom read */
sync
mtspr S P R N _ S C O M C ,r3
isync
mfspr r3 ,S P R N _ S C O M D
isync
mfspr r0 ,S P R N _ S C O M C
isync
/ * XXX : fixup r e s u l t o n s o m e b u g g y 9 7 0 ' s ( o u c h ! w e l o s t a b i t , b a h
* that' s t h e b e s t w e c a n d o ) . N o t i m p l e m e n t e d y e t a s w e d o n ' t u s e
* the s c o m o n a n y o f t h e b o g u s C P U s y e t , b u t m a y h a v e t o b e d o n e
* ultimately
* /
/* restore interrupts */
mtmsrd r4 ,1
blr
_ GLOBAL( s c o m 9 7 0 _ w r i t e )
/* interrupts off */
mfmsr r5
ori r0 ,r5 ,M S R _ E E
xori r0 ,r0 ,M S R _ E E
mtmsrd r0 ,1
/ * rotate 2 4 b i t s S C O M a d d r e s s 8 b i t s l e f t a n d m a s k o u t i t ' s l o w 8 b i t s
* ( including p a r i t y ) . O n c u r r e n t C P U s t h e y m u s t b e 0 ' d .
* /
rlwinm r3 ,r3 ,8 ,0 ,1 5
sync
mtspr S P R N _ S C O M D ,r4 / * w r i t e d a t a * /
isync
mtspr S P R N _ S C O M C ,r3 / * w r i t e c o m m a n d * /
isync
mfspr 3 ,S P R N _ S C O M C
isync
/* restore interrupts */
mtmsrd r5 ,1
blr
2011-06-17 03:10:06 +00:00
# endif / * C O N F I G _ C P U _ F R E Q _ P M A C 6 4 | | C O N F I G _ C P U _ F R E Q _ M A P L E * /
2005-11-07 14:27:33 +11:00
2005-10-10 22:36:14 +10:00
/ * kexec_ w a i t ( p h y s _ c p u )
*
* wait f o r t h e f l a g t o c h a n g e , i n d i c a t i n g t h i s k e r n e l i s g o i n g a w a y b u t
* the s l a v e c o d e f o r t h e n e x t o n e i s a t a d d r e s s e s 0 t o 1 0 0 .
*
2011-05-10 19:28:33 +00:00
* This i s u s e d b y a l l s l a v e s , e v e n t h o s e t h a t d i d n o t f i n d a m a t c h i n g
* paca i n t h e s e c o n d a r y s t a r t u p c o d e .
2005-10-10 22:36:14 +10:00
*
* Physical ( h a r d w a r e ) c p u i d s h o u l d b e i n r3 .
* /
_ GLOBAL( k e x e c _ w a i t )
bl 1 f
1 : mflr r5
addi r5 ,r5 ,k e x e c _ f l a g - 1 b
99 : HMT_ L O W
2016-11-29 23:45:50 +11:00
# ifdef C O N F I G _ K E X E C _ C O R E / * u s e n o m e m o r y w i t h o u t k e x e c * /
2005-10-10 22:36:14 +10:00
lwz r4 ,0 ( r5 )
cmpwi 0 ,r4 ,0
2015-07-22 15:50:50 +10:00
beq 9 9 b
# ifdef C O N F I G _ P P C _ B O O K 3 S _ 6 4
li r10 ,0 x60
mfmsr r11
clrrdi r11 ,r11 ,1 / * C l e a r M S R _ L E * /
mtsrr0 r10
mtsrr1 r11
rfid
# else
2015-10-06 22:48:21 -05:00
/* Create TLB entry in book3e_secondary_core_init */
li r4 ,0
2015-07-22 15:50:50 +10:00
ba 0 x60
# endif
2005-10-10 22:36:14 +10:00
# endif
/ * this c a n b e i n t e x t b e c a u s e w e w o n ' t c h a n g e i t u n t i l w e a r e
* running i n r e a l a n y w a y s
* /
kexec_flag :
.long 0
2016-11-29 23:45:50 +11:00
# ifdef C O N F I G _ K E X E C _ C O R E
2015-10-06 22:48:18 -05:00
# ifdef C O N F I G _ P P C _ B O O K 3 E
/ *
* BOOK3 E h a s n o r e a l M M U m o d e , s o w e h a v e t o s e t u p t h e i n i t i a l T L B
* for a c o r e t o i d e n t i t y m a p v : 0 t o p : 0 . T h i s c u r r e n t i m p l e m e n t a t i o n
* assumes t h a t 1 G i s e n o u g h f o r k e x e c .
* /
kexec_create_tlb :
/ *
* Invalidate a l l n o n - I P R O T T L B e n t r i e s t o a v o i d a n y T L B c o n f l i c t .
* IPROT T L B e n t r i e s s h o u l d b e > = P A G E _ O F F S E T a n d t h u s n o t c o n f l i c t .
* /
PPC_ T L B I L X _ A L L ( 0 ,R 0 )
sync
isync
mfspr r10 ,S P R N _ T L B 1 C F G
andi. r10 ,r10 ,T L B n C F G _ N _ E N T R Y / * E x t r a c t # e n t r i e s * /
subi r10 ,r10 ,1 / * L a s t e n t r y : n o c o n f l i c t w i t h k e r n e l t e x t * /
lis r9 ,M A S 0 _ T L B S E L ( 1 ) @h
rlwimi r9 ,r10 ,1 6 ,4 ,1 5 / * S e t u p M A S 0 = T L B S E L | E S E L ( r9 ) * /
/* Set up a temp identity mapping v:0 to p:0 and return to it. */
# if d e f i n e d ( C O N F I G _ S M P ) | | d e f i n e d ( C O N F I G _ P P C _ E 5 0 0 M C )
# define M _ I F _ N E E D E D M A S 2 _ M
# else
# define M _ I F _ N E E D E D 0
# endif
mtspr S P R N _ M A S 0 ,r9
lis r9 ,( M A S 1 _ V A L I D | M A S 1 _ I P R O T ) @h
ori r9 ,r9 ,( M A S 1 _ T S I Z E ( B O O K 3 E _ P A G E S Z _ 1 G B ) ) @l
mtspr S P R N _ M A S 1 ,r9
LOAD_ R E G _ I M M E D I A T E ( r9 , 0 x0 | M _ I F _ N E E D E D )
mtspr S P R N _ M A S 2 ,r9
LOAD_ R E G _ I M M E D I A T E ( r9 , 0 x0 | M A S 3 _ S R | M A S 3 _ S W | M A S 3 _ S X )
mtspr S P R N _ M A S 3 ,r9
li r9 ,0
mtspr S P R N _ M A S 7 ,r9
tlbwe
isync
blr
# endif
2005-10-10 22:36:14 +10:00
/ * kexec_ s m p _ w a i t ( v o i d )
*
* call w i t h i n t e r r u p t s o f f
* note : this i s a t e r m i n a l r o u t i n e , i t d o e s n o t s a v e l r
*
* get p h y s i d f r o m p a c a
* switch t o r e a l m o d e
2011-05-10 19:28:33 +00:00
* mark t h e p a c a a s n o l o n g e r u s e d
2005-10-10 22:36:14 +10:00
* join o t h e r c p u s i n k e x e c _ w a i t ( p h y s _ i d )
* /
_ GLOBAL( k e x e c _ s m p _ w a i t )
lhz r3 ,P A C A H W C P U I D ( r13 )
bl r e a l _ m o d e
2011-05-10 19:28:33 +00:00
li r4 ,K E X E C _ S T A T E _ R E A L _ M O D E
stb r4 ,P A C A K E X E C S T A T E ( r13 )
SYNC
2014-02-04 16:04:35 +11:00
b k e x e c _ w a i t
2005-10-10 22:36:14 +10:00
/ *
* switch t o r e a l m o d e ( t u r n m m u o f f )
* we u s e t h e e a r l y k e r n e l t r i c k t h a t t h e h a r d w a r e i g n o r e s b i t s
* 0 and 1 ( b i g e n d i a n ) o f t h e e f f e c t i v e a d d r e s s i n r e a l m o d e
*
* don' t o v e r w r i t e r3 h e r e , i t i s l i v e f o r k e x e c _ w a i t a b o v e .
* /
real_mode : /* assume normal blr return */
2015-10-06 22:48:18 -05:00
# ifdef C O N F I G _ P P C _ B O O K 3 E
/* Create an identity mapping. */
b k e x e c _ c r e a t e _ t l b
# else
2005-10-10 22:36:14 +10:00
1 : li r9 ,M S R _ R I
li r10 ,M S R _ D R | M S R _ I R
mflr r11 / * r e t u r n a d d r e s s t o S R R 0 * /
mfmsr r12
andc r9 ,r12 ,r9
andc r10 ,r12 ,r10
mtmsrd r9 ,1
mtspr S P R N _ S R R 1 ,r10
mtspr S P R N _ S R R 0 ,r11
rfid
2015-10-06 22:48:18 -05:00
# endif
2005-10-10 22:36:14 +10:00
/ *
2016-08-19 14:22:38 +05:30
* kexec_ s e q u e n c e ( n e w s t a c k , s t a r t , i m a g e , c o n t r o l , c l e a r _ a l l ( ) ,
copy_ w i t h _ m m u _ o f f )
2005-10-10 22:36:14 +10:00
*
* does t h e g r u n g y w o r k w i t h s t a c k s w i t c h i n g a n d r e a l m o d e s w i t c h e s
* also d o e s s i m p l e c a l l s t o o t h e r c o d e
* /
_ GLOBAL( k e x e c _ s e q u e n c e )
mflr r0
std r0 ,1 6 ( r1 )
/* switch stacks to newstack -- &kexec_stack.stack */
2008-04-24 13:20:16 +10:00
stdu r1 ,T H R E A D _ S I Z E - S T A C K _ F R A M E _ O V E R H E A D ( r3 )
2005-10-10 22:36:14 +10:00
mr r1 ,r3
li r0 ,0
std r0 ,1 6 ( r1 )
/ * save r e g s f o r l o c a l v a r s o n n e w s t a c k .
* yes, w e w o n ' t g o b a c k , b u t . . .
* /
std r31 ,- 8 ( r1 )
std r30 ,- 1 6 ( r1 )
std r29 ,- 2 4 ( r1 )
std r28 ,- 3 2 ( r1 )
std r27 ,- 4 0 ( r1 )
std r26 ,- 4 8 ( r1 )
std r25 ,- 5 6 ( r1 )
2008-04-24 13:20:16 +10:00
stdu r1 ,- S T A C K _ F R A M E _ O V E R H E A D - 6 4 ( r1 )
2005-10-10 22:36:14 +10:00
/* save args into preserved regs */
mr r31 ,r3 / * n e w s t a c k ( b o t h ) * /
mr r30 ,r4 / * s t a r t ( r e a l ) * /
mr r29 ,r5 / * i m a g e ( v i r t ) * /
mr r28 ,r6 / * c o n t r o l , u n u s e d * /
mr r27 ,r7 / * c l e a r _ a l l ( ) f n d e s c * /
2016-08-19 14:22:38 +05:30
mr r26 ,r8 / * c o p y _ w i t h _ m m u _ o f f * /
2005-10-10 22:36:14 +10:00
lhz r25 ,P A C A H W C P U I D ( r13 ) / * g e t o u r p h y s c p u f r o m p a c a * /
/* disable interrupts, we are overwriting kernel data next */
2015-10-06 22:48:22 -05:00
# ifdef C O N F I G _ P P C _ B O O K 3 E
wrteei 0
# else
2005-10-10 22:36:14 +10:00
mfmsr r3
rlwinm r3 ,r3 ,0 ,1 7 ,1 5
mtmsrd r3 ,1
2015-10-06 22:48:22 -05:00
# endif
2005-10-10 22:36:14 +10:00
2016-08-19 14:22:38 +05:30
/ * We n e e d t o t u r n t h e M M U o f f u n l e s s w e a r e i n h a s h m o d e
* under a h y p e r v i s o r
* /
cmpdi r26 ,0
beq 1 f
bl r e a l _ m o d e
1 :
2005-10-10 22:36:14 +10:00
/* copy dest pages, flush whole dest image */
mr r3 ,r29
2014-02-04 16:04:35 +11:00
bl k e x e c _ c o p y _ f l u s h / * ( i m a g e ) * /
2005-10-10 22:36:14 +10:00
2016-08-19 14:22:38 +05:30
/* turn off mmu now if not done earlier */
cmpdi r26 ,0
bne 1 f
2005-10-10 22:36:14 +10:00
bl r e a l _ m o d e
2007-04-11 18:32:17 +10:00
/* copy 0x100 bytes starting at start to 0 */
2016-08-19 14:22:38 +05:30
1 : li r3 ,0
2007-04-11 18:32:17 +10:00
mr r4 ,r30 / * s t a r t , a k a p h y s m e m o f f s e t * /
li r5 ,0 x10 0
li r6 ,0
2014-02-04 16:04:35 +11:00
bl c o p y _ a n d _ f l u s h / * ( d e s t , s r c , c o p y l i m i t , s t a r t o f f s e t ) * /
2007-04-11 18:32:17 +10:00
1 : /* assume normal blr return */
/* release other cpus to the new kernel secondary start at 0x60 */
mflr r5
li r6 ,1
stw r6 ,k e x e c _ f l a g - 1 b ( 5 )
2016-08-19 14:22:35 +05:30
cmpdi r27 ,0
beq 1 f
2005-10-10 22:36:14 +10:00
/* clear out hardware hash page table and tlb */
2016-06-06 22:26:10 +05:30
# ifdef P P C 6 4 _ E L F _ A B I _ v1
2014-02-04 16:07:47 +11:00
ld r12 ,0 ( r27 ) / * d e r e f f u n c t i o n d e s c r i p t o r * /
# else
mr r12 ,r27
# endif
mtctr r12
2016-07-05 15:03:58 +10:00
bctrl / * m m u _ h a s h _ o p s . h p t e _ c l e a r _ a l l ( v o i d ) ; */
2005-10-10 22:36:14 +10:00
/ *
* kexec i m a g e c a l l i n g i s :
* the f i r s t 0 x10 0 b y t e s o f t h e e n t r y p o i n t a r e c o p i e d t o 0
*
* all s l a v e s b r a n c h t o s l a v e = 0 x60 ( a b s o l u t e )
* slave( p h y s _ c p u _ i d ) ;
*
* master g o e s t o s t a r t = e n t r y p o i n t
* start( p h y s _ c p u _ i d , s t a r t , 0 ) ;
*
*
* a w r a p p e r i s n e e d e d t o c a l l e x i s t i n g k e r n e l s , h e r e i s a n a p p r o x i m a t e
* description o f o n e m e t h o d :
*
* v2 : ( 2 .6 .10 )
* start w i l l b e n e a r t h e b o o t _ b l o c k ( m a y b e 0 x10 0 b y t e s b e f o r e i t ? )
* it w i l l h a v e a 0 x60 , w h i c h w i l l b t o b o o t _ b l o c k , w h e r e i t w i l l w a i t
* and 0 w i l l s t o r e p h y s i n t o s t r u c t b o o t - b l o c k a n d l o a d r3 f r o m t h e r e ,
* copy k e r n e l 0 - 0 x10 0 a n d t e l l s l a v e s t o b a c k d o w n t o 0 x60 a g a i n
*
* v1 : ( 2 .6 .9 )
* boot b l o c k w i l l h a v e a l l c p u s s c a n n i n g d e v i c e t r e e t o s e e i f t h e y
* are t h e b o o t c p u ? ? ? ? ?
* other d e v i c e t r e e d i f f e r e n c e s ( p r o p s i z e s , v a v s p a , e t c ) . . .
* /
2016-08-19 14:22:35 +05:30
1 : mr r3 ,r25 # m y p h y s c p u
2005-10-10 22:36:14 +10:00
mr r4 ,r30 # s t a r t , a k a p h y s m e m o f f s e t
mtlr 4
li r5 ,0
2008-10-22 10:39:18 +00:00
blr / * i m a g e - > s t a r t ( p h y s i d , i m a g e - > s t a r t , 0 ) ; */
2016-11-29 23:45:50 +11:00
# endif / * C O N F I G _ K E X E C _ C O R E * /