2019-05-27 09:55:01 +03:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2005-10-10 16:36:14 +04: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 .
*
* /
# 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 / r e g . h >
# include < a s m / p a g e . h >
# include < a s m / c a c h 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 / t h r e a d _ i n f o . h >
# include < a s m / a s m - o f f s e t s . h >
[PATCH] powerpc: Merge kexec
This patch merges, to some extent, the PPC32 and PPC64 kexec implementations.
We adopt the PPC32 approach of having ppc_md callbacks for the kexec functions.
The current PPC64 implementation becomes the "default" implementation for PPC64
which platforms can select if they need no special treatment.
I've added these default callbacks to pseries/maple/cell/powermac, this means
iSeries no longer supports kexec - but it never worked anyway.
I've renamed PPC32's machine_kexec_simple to default_machine_kexec, inline with
PPC64. Judging by the comments it might be better named machine_kexec_non_of,
or something, but at the moment it's the only implementation for PPC32 so it's
the "default".
Kexec requires machine_shutdown(), which is in machine_kexec.c on PPC32, but we
already have in setup-common.c on powerpc. All this does is call
ppc_md.nvram_sync, which only powermac implements, so instead make
machine_shutdown a ppc_md member and have it call core99_nvram_sync directly
on powermac.
I've also stuck relocate_kernel.S into misc_32.S for powerpc.
Built for ARCH=ppc, and 32 & 64 bit ARCH=powerpc, with KEXEC=y/n. Booted on
P5 LPAR and successfully kexec'ed.
Should apply on top of 493f25ef4087395891c99fcfe2c72e62e293e89f.
Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2005-11-14 15:35:00 +03:00
# include < a s m / p r o c e s s o r . h >
2008-12-18 22:13:38 +03:00
# include < a s m / b u g . h >
2010-11-18 18:06:17 +03:00
# include < a s m / p t r a c e . h >
2016-01-14 07:33:46 +03:00
# include < a s m / e x p o r t . 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-10-10 16:36:14 +04:00
.text
2013-09-24 09:17:21 +04:00
/ *
* We s t o r e t h e s a v e d k s p _ l i m i t i n t h e u n u s e d p a r t
* of t h e S T A C K _ F R A M E _ O V E R H E A D
* /
2008-04-28 10:21:22 +04:00
_ GLOBAL( c a l l _ d o _ s o f t i r q )
mflr r0
stw r0 ,4 ( r1 )
2013-09-24 09:17:21 +04:00
lwz r10 ,T H R E A D + K S P _ L I M I T ( r2 )
2019-01-31 13:09:00 +03:00
stw r3 , T H R E A D + K S P _ L I M I T ( r2 )
2008-04-28 10:21:22 +04:00
stwu 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 )
mr r1 ,r3
2013-09-24 09:17:21 +04:00
stw r10 ,8 ( r1 )
2008-04-28 10:21:22 +04:00
bl _ _ d o _ s o f t i r q
2013-09-24 09:17:21 +04:00
lwz r10 ,8 ( r1 )
2008-04-28 10:21:22 +04:00
lwz r1 ,0 ( r1 )
lwz r0 ,4 ( r1 )
2013-09-24 09:17:21 +04:00
stw r10 ,T H R E A D + K S P _ L I M I T ( r2 )
2008-04-28 10:21:22 +04:00
mtlr r0
blr
2014-01-17 08:25:28 +04:00
/ *
2019-01-17 15:17:56 +03:00
* void c a l l _ d o _ i r q ( s t r u c t p t _ r e g s * r e g s , v o i d * s p ) ;
2014-01-17 08:25:28 +04:00
* /
2013-09-23 08:29:11 +04:00
_ GLOBAL( c a l l _ d o _ i r q )
2008-04-28 10:21:22 +04:00
mflr r0
stw r0 ,4 ( r1 )
2013-09-24 09:17:21 +04:00
lwz r10 ,T H R E A D + K S P _ L I M I T ( r2 )
2019-01-31 13:09:00 +03:00
stw r4 , T H R E A D + K S P _ L I M I T ( r2 )
2013-09-23 08:29:11 +04:00
stwu 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
2013-09-24 09:17:21 +04:00
stw r10 ,8 ( r1 )
2013-09-23 08:29:11 +04:00
bl _ _ d o _ i r q
2013-09-24 09:17:21 +04:00
lwz r10 ,8 ( r1 )
2008-04-28 10:21:22 +04:00
lwz r1 ,0 ( r1 )
lwz r0 ,4 ( r1 )
2013-09-24 09:17:21 +04:00
stw r10 ,T H R E A D + K S P _ L I M I T ( r2 )
2008-04-28 10:21:22 +04:00
mtlr r0
blr
2005-10-20 03:23:26 +04:00
/ *
* This r e t u r n s t h e h i g h 6 4 b i t s o f t h e p r o d u c t o f t w o 6 4 - b i t n u m b e r s .
* /
_ GLOBAL( m u l h d u )
cmpwi r6 ,0
cmpwi c r1 ,r3 ,0
mr r10 ,r4
mulhwu r4 ,r4 ,r5
beq 1 f
mulhwu r0 ,r10 ,r6
mullw r7 ,r10 ,r5
addc r7 ,r0 ,r7
addze r4 ,r4
1 : beqlr c r1 / * a l l d o n e i f h i g h p a r t o f A i s 0 * /
mullw r9 ,r3 ,r5
2016-02-09 19:08:33 +03:00
mulhwu r10 ,r3 ,r5
2005-10-20 03:23:26 +04:00
beq 2 f
2016-02-09 19:08:33 +03:00
mullw r0 ,r3 ,r6
mulhwu r8 ,r3 ,r6
2005-10-20 03:23:26 +04:00
addc r7 ,r0 ,r7
adde r4 ,r4 ,r8
2016-02-09 19:08:33 +03:00
addze r10 ,r10
2005-10-20 03:23:26 +04:00
2 : addc r4 ,r4 ,r9
2016-02-09 19:08:33 +03:00
addze r3 ,r10
2005-10-20 03:23:26 +04:00
blr
2005-10-10 16:36:14 +04:00
/ *
* reloc_ g o t 2 r u n s t h r o u g h t h e . g o t 2 s e c t i o n a d d i n g a n o f f s e t
* to e a c h e n t r y .
* /
_ GLOBAL( r e l o c _ g o t 2 )
mflr r11
lis r7 ,_ _ g o t 2 _ s t a r t @ha
addi r7 ,r7 ,_ _ g o t 2 _ s t a r t @l
lis r8 ,_ _ g o t 2 _ e n d @ha
addi r8 ,r8 ,_ _ g o t 2 _ e n d @l
subf r8 ,r7 ,r8
srwi. r8 ,r8 ,2
beqlr
mtctr r8
bl 1 f
1 : mflr r0
lis r4 ,1 b @ha
addi r4 ,r4 ,1 b @l
subf r0 ,r4 ,r0
add r7 ,r0 ,r7
2 : lwz r0 ,0 ( r7 )
add r0 ,r0 ,r3
stw r0 ,0 ( r7 )
addi r7 ,r7 ,4
bdnz 2 b
mtlr r11
blr
/ *
* call_ s e t u p _ c p u - c a l l t h e s e t u p _ c p u f u n c t i o n f o r t h i s c p u
* r3 = d a t a o f f s e t , r24 = c p u n u m b e r
*
* Setup f u n c t i o n i s c a l l e d w i t h :
* r3 = d a t a o f f s e t
* r4 = p t r t o C P U s p e c ( r e l o c a t e d )
* /
_ GLOBAL( c a l l _ s e t u p _ c p u )
addis r4 ,r3 ,c u r _ c p u _ s p e c @ha
addi r4 ,r4 ,c u r _ c p u _ s p e c @l
lwz r4 ,0 ( r4 )
add r4 ,r4 ,r3
lwz r5 ,C P U _ S P E C _ S E T U P ( r4 )
2006-05-19 08:24:18 +04:00
cmpwi 0 ,r5 ,0
2005-10-10 16:36:14 +04:00
add r5 ,r5 ,r3
beqlr
mtctr r5
bctr
2018-11-17 13:24:56 +03: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 ) & & d e f i n e d ( C O N F I G _ P P C _ B O O K 3 S _ 3 2 )
2005-10-10 16:36:14 +04:00
/ * This g e t s c a l l e d b y v i a - p m u . c t o s w i t c h t h e P L L s e l e c t i o n
* on 7 5 0 f x C P U . T h i s f u n c t i o n s h o u l d r e a l l y b e m o v e d t o s o m e
* other p l a c e ( a s m o s t o f t h e c p u f r e q c o d e i n v i a - p m u
* /
_ GLOBAL( l o w _ c h o o s e _ 7 5 0 f x _ p l l )
/* Clear MSR:EE */
mfmsr r7
rlwinm r0 ,r7 ,0 ,1 7 ,1 5
mtmsr r0
/* If switching to PLL1, disable HID0:BTIC */
cmplwi c r0 ,r3 ,0
beq 1 f
mfspr r5 ,S P R N _ H I D 0
rlwinm r5 ,r5 ,0 ,2 7 ,2 5
sync
mtspr S P R N _ H I D 0 ,r5
isync
sync
1 :
/* Calc new HID1 value */
mfspr r4 ,S P R N _ H I D 1 / * B u i l d a H I D 1 : P S b i t f r o m p a r a m e t e r * /
rlwinm r5 ,r3 ,1 6 ,1 5 ,1 5 / * C l e a r o u t H I D 1 : P S f r o m v a l u e r e a d * /
rlwinm r4 ,r4 ,0 ,1 6 ,1 4 / * C o u l d h a v e I u s e d r l w i m i h e r e ? * /
or r4 ,r4 ,r5
mtspr S P R N _ H I D 1 ,r4
2019-01-31 13:08:50 +03:00
# ifdef C O N F I G _ S M P
2005-10-10 16:36:14 +04:00
/* Store new HID1 image */
2019-01-31 13:09:04 +03:00
lwz r6 ,T A S K _ C P U ( r2 )
2005-10-10 16:36:14 +04:00
slwi r6 ,r6 ,2
2019-01-31 13:08:50 +03:00
# else
li r6 , 0
# endif
2005-10-10 16:36:14 +04:00
addis r6 ,r6 ,n a p _ s a v e _ h i d1 @ha
stw r4 ,n a p _ s a v e _ h i d1 @l(r6)
/* If switching to PLL0, enable HID0:BTIC */
cmplwi c r0 ,r3 ,0
bne 1 f
mfspr r5 ,S P R N _ H I D 0
ori r5 ,r5 ,H I D 0 _ B T I C
sync
mtspr S P R N _ H I D 0 ,r5
isync
sync
1 :
/* Return */
mtmsr r7
blr
_ GLOBAL( l o w _ c h o o s e _ 7 4 4 7 a _ d f s )
/* Clear MSR:EE */
mfmsr r7
rlwinm r0 ,r7 ,0 ,1 7 ,1 5
mtmsr r0
/* Calc new HID1 value */
mfspr r4 ,S P R N _ H I D 1
insrwi r4 ,r3 ,1 ,9 / * i n s e r t p a r a m e t e r i n t o b i t 9 * /
sync
mtspr S P R N _ H I D 1 ,r4
sync
isync
/* Return */
mtmsr r7
blr
2018-11-17 13:24:56 +03:00
# endif / * C O N F I G _ C P U _ F R E Q _ P M A C & & C O N F I G _ P P C _ B O O K 3 S _ 3 2 * /
2005-10-10 16:36:14 +04:00
2007-12-21 07:39:26 +03:00
# ifdef C O N F I G _ 4 0 x
/ *
* 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
2016-08-05 14:28:05 +03:00
rlwinm r0 ,r7 ,0 ,~ M S R _ D R
2007-12-21 07:39:26 +03:00
sync
mtmsr r0
sync
isync
lbz r3 ,0 ( r3 )
sync
mtmsr r7
sync
isync
blr
2020-03-31 19:03:44 +03:00
_ ASM_ N O K P R O B E _ S Y M B O L ( r e a l _ r e a d b )
2007-12-21 07:39:26 +03: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 _ w r i t e b )
mfmsr r7
2016-08-05 14:28:05 +03:00
rlwinm r0 ,r7 ,0 ,~ M S R _ D R
2007-12-21 07:39:26 +03:00
sync
mtmsr r0
sync
isync
stb r3 ,0 ( r4 )
sync
mtmsr r7
sync
isync
blr
2020-03-31 19:03:44 +03:00
_ ASM_ N O K P R O B E _ S Y M B O L ( r e a l _ w r i t e b )
2007-12-21 07:39:26 +03:00
# endif / * C O N F I G _ 4 0 x * /
2005-10-10 16:36:14 +04:00
/ *
* Copy a w h o l e p a g e . W e u s e t h e d c b z i n s t r u c t i o n o n t h e d e s t i n a t i o n
* to r e d u c e m e m o r y t r a f f i c ( i t e l i m i n a t e s t h e u n n e c e s s a r y r e a d s o f
* the d e s t i n a t i o n i n t o c a c h e ) . T h i s r e q u i r e s t h a t t h e d e s t i n a t i o n
* is c a c h e a b l e .
* /
# define C O P Y _ 1 6 _ B Y T E S \
lwz r6 ,4 ( r4 ) ; \
lwz r7 ,8 ( r4 ) ; \
lwz r8 ,1 2 ( r4 ) ; \
lwzu r9 ,1 6 ( r4 ) ; \
stw r6 ,4 ( r3 ) ; \
stw r7 ,8 ( r3 ) ; \
stw r8 ,1 2 ( r3 ) ; \
stwu r9 ,1 6 ( r3 )
_ GLOBAL( c o p y _ p a g e )
2019-08-16 10:52:20 +03:00
rlwinm r5 , r3 , 0 , L 1 _ C A C H E _ B Y T E S - 1
2005-10-10 16:36:14 +04:00
addi r3 ,r3 ,- 4
2019-08-16 10:52:20 +03:00
0 : twnei r5 , 0 / * W A R N i f r3 i s n o t c a c h e a l i g n e d * /
EMIT_ B U G _ E N T R Y 0 b ,_ _ F I L E _ _ ,_ _ L I N E _ _ , B U G F L A G _ W A R N I N G
2005-10-10 16:36:14 +04:00
addi r4 ,r4 ,- 4
li r5 ,4
# if M A X _ C O P Y _ P R E F E T C H > 1
li r0 ,M A X _ C O P Y _ P R E F E T C H
li r11 ,4
mtctr r0
11 : dcbt r11 ,r4
2005-10-17 05:50:32 +04:00
addi r11 ,r11 ,L 1 _ C A C H E _ B Y T E S
2005-10-10 16:36:14 +04:00
bdnz 1 1 b
# else / * M A X _ C O P Y _ P R E F E T C H = = 1 * /
dcbt r5 ,r4
2005-10-17 05:50:32 +04:00
li r11 ,L 1 _ C A C H E _ B Y T E S + 4
2005-10-10 16:36:14 +04:00
# endif / * M A X _ C O P Y _ P R E F E T C H * /
2008-12-11 04:55:41 +03:00
li r0 ,P A G E _ S I Z E / L 1 _ C A C H E _ B Y T E S - M A X _ C O P Y _ P R E F E T C H
2005-10-10 16:36:14 +04:00
crclr 4 * c r0 + e q
2 :
mtctr r0
1 :
dcbt r11 ,r4
dcbz r5 ,r3
COPY_ 1 6 _ B Y T E S
2005-10-17 05:50:32 +04:00
# if L 1 _ C A C H E _ B Y T E S > = 3 2
2005-10-10 16:36:14 +04:00
COPY_ 1 6 _ B Y T E S
2005-10-17 05:50:32 +04:00
# if L 1 _ C A C H E _ B Y T E S > = 6 4
2005-10-10 16:36:14 +04:00
COPY_ 1 6 _ B Y T E S
COPY_ 1 6 _ B Y T E S
2005-10-17 05:50:32 +04:00
# if L 1 _ C A C H E _ B Y T E S > = 1 2 8
2005-10-10 16:36:14 +04:00
COPY_ 1 6 _ B Y T E S
COPY_ 1 6 _ B Y T E S
COPY_ 1 6 _ B Y T E S
COPY_ 1 6 _ B Y T E S
# endif
# endif
# endif
bdnz 1 b
beqlr
crnot 4 * c r0 + e q ,4 * c r0 + e q
li r0 ,M A X _ C O P Y _ P R E F E T C H
li r11 ,4
b 2 b
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( c o p y _ p a g e )
2005-10-10 16:36:14 +04:00
/ *
* Extended p r e c i s i o n s h i f t s .
*
* Updated t o b e v a l i d f o r s h i f t c o u n t s f r o m 0 t o 6 3 i n c l u s i v e .
* - - Gabriel
*
* R3 / R 4 h a s 6 4 b i t v a l u e
* R5 h a s s h i f t c o u n t
* result i n R 3 / R 4
*
* ashrdi3 : arithmetic r i g h t s h i f t ( s i g n p r o p a g a t i o n )
* lshrdi3 : logical r i g h t s h i f t
* ashldi3 : left s h i f t
* /
_ GLOBAL( _ _ a s h r d i 3 )
subfic r6 ,r5 ,3 2
srw r4 ,r4 ,r5 # L S W = c o u n t > 31 ? 0 : L S W > > c o u n t
addi r7 ,r5 ,3 2 # c o u l d b e x o r i , o r a d d i w i t h - 32
slw r6 ,r3 ,r6 # t 1 = c o u n t > 3 1 ? 0 : M S W < < ( 3 2 - c o u n t )
rlwinm r8 ,r7 ,0 ,3 2 # t 3 = ( c o u n t < 3 2 ) ? 3 2 : 0
sraw r7 ,r3 ,r7 # t 2 = M S W > > ( c o u n t - 3 2 )
or r4 ,r4 ,r6 # L S W | = t 1
slw r7 ,r7 ,r8 # t 2 = ( c o u n t < 3 2 ) ? 0 : t 2
sraw r3 ,r3 ,r5 # M S W = M S W > > c o u n t
or r4 ,r4 ,r7 # L S W | = t 2
blr
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( _ _ a s h r d i 3 )
2005-10-10 16:36:14 +04:00
_ GLOBAL( _ _ a s h l d i 3 )
subfic r6 ,r5 ,3 2
slw r3 ,r3 ,r5 # M S W = c o u n t > 31 ? 0 : M S W < < c o u n t
addi r7 ,r5 ,3 2 # c o u l d b e x o r i , o r a d d i w i t h - 32
srw r6 ,r4 ,r6 # t 1 = c o u n t > 3 1 ? 0 : L S W > > ( 3 2 - c o u n t )
slw r7 ,r4 ,r7 # t 2 = c o u n t < 3 2 ? 0 : L S W < < ( c o u n t - 3 2 )
or r3 ,r3 ,r6 # M S W | = t 1
slw r4 ,r4 ,r5 # L S W = L S W < < c o u n t
or r3 ,r3 ,r7 # M S W | = t 2
blr
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( _ _ a s h l d i 3 )
2005-10-10 16:36:14 +04:00
_ GLOBAL( _ _ l s h r d i 3 )
subfic r6 ,r5 ,3 2
srw r4 ,r4 ,r5 # L S W = c o u n t > 31 ? 0 : L S W > > c o u n t
addi r7 ,r5 ,3 2 # c o u l d b e x o r i , o r a d d i w i t h - 32
slw r6 ,r3 ,r6 # t 1 = c o u n t > 3 1 ? 0 : M S W < < ( 3 2 - c o u n t )
srw r7 ,r3 ,r7 # t 2 = c o u n t < 3 2 ? 0 : M S W > > ( c o u n t - 3 2 )
or r4 ,r4 ,r6 # L S W | = t 1
srw r3 ,r3 ,r5 # M S W = M S W > > c o u n t
or r4 ,r4 ,r7 # L S W | = t 2
blr
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( _ _ l s h r d i 3 )
2005-10-10 16:36:14 +04:00
2013-10-09 09:11:17 +04:00
/ *
* 6 4 - bit c o m p a r i s o n : _ _ c m p d i 2 ( s64 a , s64 b )
* Returns 0 i f a < b , 1 i f a = = b , 2 i f a > b .
* /
_ GLOBAL( _ _ c m p d i 2 )
cmpw r3 ,r5
li r3 ,1
bne 1 f
cmplw r4 ,r6
beqlr
1 : li r3 ,0
bltlr
li r3 ,2
blr
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( _ _ c m p d i 2 )
2008-03-13 01:39:55 +03:00
/ *
* 6 4 - bit c o m p a r i s o n : _ _ u c m p d i 2 ( u 6 4 a , u 6 4 b )
* Returns 0 i f a < b , 1 i f a = = b , 2 i f a > b .
* /
_ GLOBAL( _ _ u c m p d i 2 )
cmplw r3 ,r5
li r3 ,1
bne 1 f
cmplw r4 ,r6
beqlr
1 : li r3 ,0
bltlr
li r3 ,2
blr
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( _ _ u c m p d i 2 )
2008-03-13 01:39:55 +03:00
2013-05-13 04:23:38 +04:00
_ GLOBAL( _ _ b s w a p d i 2 )
rotlwi r9 ,r4 ,8
rotlwi r10 ,r3 ,8
rlwimi r9 ,r4 ,2 4 ,0 ,7
rlwimi r10 ,r3 ,2 4 ,0 ,7
rlwimi r9 ,r4 ,2 4 ,1 6 ,2 3
rlwimi r10 ,r3 ,2 4 ,1 6 ,2 3
mr r3 ,r9
mr r4 ,r10
blr
2016-01-14 07:33:46 +03:00
EXPORT_ S Y M B O L ( _ _ b s w a p d i 2 )
2013-05-13 04:23:38 +04:00
2011-05-19 07:07:12 +04:00
# ifdef C O N F I G _ S M P
_ GLOBAL( s t a r t _ s e c o n d a r y _ r e s u m e )
/* Reset stack */
2019-01-17 15:23:57 +03:00
rlwinm r1 , r1 , 0 , 0 , 3 1 - T H R E A D _ S H I F T
2011-05-19 07:07:12 +04:00
addi r1 ,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
li r3 ,0
2011-05-21 00:22:25 +04:00
stw r3 ,0 ( r1 ) / * Z e r o t h e s t a c k f r a m e p o i n t e r * /
2011-05-19 07:07:12 +04:00
bl s t a r t _ s e c o n d a r y
b .
# endif / * C O N F I G _ S M P * /
2005-10-10 16:36:14 +04:00
/ *
* This r o u t i n e i s j u s t h e r e t o k e e p G C C h a p p y - s i g h . . .
* /
_ GLOBAL( _ _ m a i n )
blr