2005-09-26 10:04:21 +04:00
/ *
* This f i l e c o n t a i n s s l e e p l o w - l e v e l f u n c t i o n s f o r P o w e r B o o k G 3 .
* Copyright ( C ) 1 9 9 9 B e n j a m i n H e r r e n s c h m i d t ( b e n h @kernel.crashing.org)
* and P a u l M a c k e r r a s ( p a u l u s @samba.org).
*
* 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 / p r o c e s s o r . h >
# include < a s m / p a g e . h >
# include < a s m / p p c _ a s m . h >
# include < a s m / c p u t a b l e . h >
# include < a s m / c a c h e . 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 >
2008-12-18 22:13:32 +03:00
# include < a s m / m m u . h >
2005-09-26 10:04:21 +04:00
# define M A G I C 0 x4 c61 7 2 7 3 / * ' L a r s ' * /
/ *
* Structure f o r s t o r i n g C P U r e g i s t e r s o n t h e s t a c k .
* /
# define S L _ S P 0
# define S L _ P C 4
# define S L _ M S R 8
# define S L _ S D R 1 0 x c
# define S L _ S P R G 0 0 x10 / * 4 s p r g ' s * /
# define S L _ D B A T 0 0 x20
# define S L _ I B A T 0 0 x28
# define S L _ D B A T 1 0 x30
# define S L _ I B A T 1 0 x38
# define S L _ D B A T 2 0 x40
# define S L _ I B A T 2 0 x48
# define S L _ D B A T 3 0 x50
# define S L _ I B A T 3 0 x58
# define S L _ T B 0 x60
# define S L _ R 2 0 x68
# define S L _ C R 0 x6 c
# define S L _ R 1 2 0 x70 / * r12 t o r31 * /
# define S L _ S I Z E ( S L _ R 1 2 + 8 0 )
.section .text
.align 5
2006-10-18 16:04:49 +04:00
# if d e f i n e d ( C O N F I G _ P M ) | | d e f i n e d ( C O N F I G _ C P U _ F R E Q _ P M A C ) | | \
( defined( C O N F I G _ H O T P L U G _ C P U ) & & d e f i n e d ( C O N F I G _ P P C 3 2 ) )
2005-09-26 10:04:21 +04:00
/ * This g e t s c a l l e d b y v i a - p m u . c l a t e d u r i n g t h e s l e e p p r o c e s s .
* The P M U w a s a l r e a d y s e n d t h e s l e e p c o m m a n d a n d w i l l s h u t u s d o w n
* soon. W e n e e d t o s a v e a l l t h a t i s n e e d e d a n d s e t u p t h e w a k e u p
* vector t h a t w i l l b e c a l l e d b y t h e R O M o n w a k e u p
* /
_ GLOBAL( l o w _ s l e e p _ h a n d l e r )
# ifndef C O N F I G _ 6 x x
blr
# else
mflr r0
stw r0 ,4 ( r1 )
stwu r1 ,- S L _ S I Z E ( r1 )
mfcr r0
stw r0 ,S L _ C R ( r1 )
stw r2 ,S L _ R 2 ( r1 )
stmw r12 ,S L _ R 1 2 ( r1 )
/* Save MSR & SDR1 */
mfmsr r4
stw r4 ,S L _ M S R ( r1 )
mfsdr1 r4
stw r4 ,S L _ S D R 1 ( r1 )
/* Get a stable timebase and save it */
1 : mftbu r4
stw r4 ,S L _ T B ( r1 )
mftb r5
stw r5 ,S L _ T B + 4 ( r1 )
mftbu r3
cmpw r3 ,r4
bne 1 b
/* Save SPRGs */
mfsprg r4 ,0
stw r4 ,S L _ S P R G 0 ( r1 )
mfsprg r4 ,1
stw r4 ,S L _ S P R G 0 + 4 ( r1 )
mfsprg r4 ,2
stw r4 ,S L _ S P R G 0 + 8 ( r1 )
mfsprg r4 ,3
stw r4 ,S L _ S P R G 0 + 1 2 ( r1 )
/* Save BATs */
mfdbatu r4 ,0
stw r4 ,S L _ D B A T 0 ( r1 )
mfdbatl r4 ,0
stw r4 ,S L _ D B A T 0 + 4 ( r1 )
mfdbatu r4 ,1
stw r4 ,S L _ D B A T 1 ( r1 )
mfdbatl r4 ,1
stw r4 ,S L _ D B A T 1 + 4 ( r1 )
mfdbatu r4 ,2
stw r4 ,S L _ D B A T 2 ( r1 )
mfdbatl r4 ,2
stw r4 ,S L _ D B A T 2 + 4 ( r1 )
mfdbatu r4 ,3
stw r4 ,S L _ D B A T 3 ( r1 )
mfdbatl r4 ,3
stw r4 ,S L _ D B A T 3 + 4 ( r1 )
mfibatu r4 ,0
stw r4 ,S L _ I B A T 0 ( r1 )
mfibatl r4 ,0
stw r4 ,S L _ I B A T 0 + 4 ( r1 )
mfibatu r4 ,1
stw r4 ,S L _ I B A T 1 ( r1 )
mfibatl r4 ,1
stw r4 ,S L _ I B A T 1 + 4 ( r1 )
mfibatu r4 ,2
stw r4 ,S L _ I B A T 2 ( r1 )
mfibatl r4 ,2
stw r4 ,S L _ I B A T 2 + 4 ( r1 )
mfibatu r4 ,3
stw r4 ,S L _ I B A T 3 ( r1 )
mfibatl r4 ,3
stw r4 ,S L _ I B A T 3 + 4 ( r1 )
/* Backup various CPU config stuffs */
bl _ _ s a v e _ c p u _ s e t u p
/ * The R O M c a n w a k e u s u p v i a 2 d i f f e r e n t v e c t o r s :
* - On w a l l s t r e e t & l o m b a r d , w e m u s t w r i t e a m a g i c
* value ' L a r s ' a t a d d r e s s 4 a n d a p o i n t e r t o a
* memory l o c a t i o n c o n t a i n i n g t h e P C t o r e s u m e f r o m
* at a d d r e s s 0 .
* - On C o r e 9 9 , w e m u s t s t o r e t h e w a k e u p v e c t o r a t
* address 0 x80 a n d e v e n t u a l l y i t ' s p a r a m e t e r s
* at a d d r e s s 0 x84 . I ' v e h a v e s o m e t r o u b l e w i t h t h o s e
* parameters h o w e v e r a n d I n o l o n g e r u s e t h e m .
* /
lis r5 ,g r a c k l e _ w a k e _ u p @ha
addi r5 ,r5 ,g r a c k l e _ w a k e _ u p @l
tophys( r5 ,r5 )
stw r5 ,S L _ P C ( r1 )
lis r4 ,K E R N E L B A S E @h
tophys( r5 ,r1 )
addi r5 ,r5 ,S L _ P C
lis r6 ,M A G I C @ha
addi r6 ,r6 ,M A G I C @l
stw r5 ,0 ( r4 )
stw r6 ,4 ( r4 )
/* Setup stuffs at 0x80-0x84 for Core99 */
lis r3 ,c o r e 9 9 _ w a k e _ u p @ha
addi r3 ,r3 ,c o r e 9 9 _ w a k e _ u p @l
tophys( r3 ,r3 )
stw r3 ,0 x80 ( r4 )
stw r5 ,0 x84 ( r4 )
/ * Store a p o i n t e r t o o u r b a c k u p s t o r a g e i n t o
* a k e r n e l g l o b a l
* /
lis r3 ,s l e e p _ s t o r a g e @ha
addi r3 ,r3 ,s l e e p _ s t o r a g e @l
stw r5 ,0 ( r3 )
.globl low_cpu_die
low_cpu_die :
/* Flush & disable all caches */
bl f l u s h _ d i s a b l e _ c a c h e s
/* Turn off data relocation. */
mfmsr r3 / * S a v e M S R i n r7 * /
rlwinm r3 ,r3 ,0 ,2 8 ,2 6 / * T u r n o f f D R b i t * /
sync
mtmsr r3
isync
BEGIN_ F T R _ S E C T I O N
/* Flush any pending L2 data prefetches to work around HW bug */
sync
lis r3 ,0 x f f f0
lwz r0 ,0 ( r3 ) / * p e r f o r m c a c h e - i n h i b i t e d l o a d t o R O M * /
sync / * ( c a c h e s a r e d i s a b l e d a t t h i s p o i n t ) * /
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 )
/ *
* Set t h e H I D 0 a n d M S R f o r s l e e p .
* /
mfspr r2 ,S P R N _ H I D 0
rlwinm r2 ,r2 ,0 ,1 0 ,7 / * c l e a r d o z e , n a p * /
oris r2 ,r2 ,H I D 0 _ S L E E P @h
sync
isync
mtspr S P R N _ H I D 0 ,r2
sync
/ * This l o o p p u t s u s b a c k t o s l e e p i n c a s e w e h a v e a s p u r r i o u s
* wakeup s o t h a t t h e h o s t b r i d g e p r o p e r l y s t a y s a s l e e p . T h e
* CPU w i l l b e t u r n e d o f f , e i t h e r a f t e r a k n o w n t i m e ( a b o u t 1
* second) o n w a l l s t r e e t & l o m b a r d , o r a s s o o n a s t h e C P U e n t e r s
* SLEEP m o d e o n c o r e 9 9
* /
mfmsr r2
oris r2 ,r2 ,M S R _ P O W @h
1 : sync
mtmsr r2
isync
b 1 b
/ *
* Here i s t h e r e s u m e c o d e .
* /
/ *
* Core9 9 m a c h i n e s r e s u m e h e r e
* r4 h a s t h e p h y s i c a l a d d r e s s o f S L _ P C ( s p ) ( u n u s e d )
* /
_ GLOBAL( c o r e 9 9 _ w a k e _ u p )
/ * Make s u r e H I D 0 n o l o n g e r c o n t a i n s a n y s l e e p b i t a n d t h a t d a t a c a c h e
* is d i s a b l e d
* /
mfspr r3 ,S P R N _ H I D 0
rlwinm r3 ,r3 ,0 ,1 1 ,7 / * c l e a r S L E E P , N A P , D O Z E b i t s * /
rlwinm 3 ,r3 ,0 ,1 8 ,1 5 / * c l e a r D C E , I C E * /
mtspr S P R N _ H I D 0 ,r3
sync
isync
/* sanitize MSR */
mfmsr r3
ori r3 ,r3 ,M S R _ E E | M S R _ I P
xori r3 ,r3 ,M S R _ E E | M S R _ I P
sync
isync
mtmsr r3
sync
isync
/* Recover sleep storage */
lis r3 ,s l e e p _ s t o r a g e @ha
addi r3 ,r3 ,s l e e p _ s t o r a g e @l
tophys( r3 ,r3 )
lwz r1 ,0 ( r3 )
/* Pass thru to older resume code ... */
/ *
* Here i s t h e r e s u m e c o d e f o r o l d e r m a c h i n e s .
* r1 h a s t h e p h y s i c a l a d d r e s s o f S L _ P C ( s p ) .
* /
grackle_wake_up :
/ * Restore t h e k e r n e l ' s s e g m e n t r e g i s t e r s b e f o r e
* we d o a n y r1 m e m o r y a c c e s s a s w e a r e n o t s u r e t h e y
* are i n a s a n e s t a t e a b o v e t h e f i r s t 2 5 6 M b r e g i o n
* /
li r0 ,1 6 / * l o a d u p s e g m e n t r e g i s t e r v a l u e s * /
mtctr r0 / * f o r c o n t e x t 0 * /
lis r3 ,0 x20 0 0 / * K u = 1 , V S I D = 0 * /
li r4 ,0
3 : mtsrin r3 ,r4
addi r3 ,r3 ,0 x11 1 / * i n c r e m e n t V S I D * /
addis r4 ,r4 ,0 x10 0 0 / * a d d r e s s o f n e x t s e g m e n t * /
bdnz 3 b
sync
isync
subi r1 ,r1 ,S L _ P C
/* Restore various CPU config stuffs */
bl _ _ r e s t o r e _ c p u _ s e t u p
/* Make sure all FPRs have been initialized */
bl r e l o c _ o f f s e t
bl _ _ i n i t _ f p u _ r e g i s t e r s
/ * Invalidate & e n a b l e L 1 c a c h e , w e d o n ' t c a r e a b o u t
* whatever t h e R O M m a y h a v e t r i e d t o w r i t e t o m e m o r y
* /
bl _ _ i n v a l _ e n a b l e _ L 1
/* Restore the BATs, and SDR1. Then we can turn on the MMU. */
lwz r4 ,S L _ S D R 1 ( r1 )
mtsdr1 r4
lwz r4 ,S L _ S P R G 0 ( r1 )
mtsprg 0 ,r4
lwz r4 ,S L _ S P R G 0 + 4 ( r1 )
mtsprg 1 ,r4
lwz r4 ,S L _ S P R G 0 + 8 ( r1 )
mtsprg 2 ,r4
lwz r4 ,S L _ S P R G 0 + 1 2 ( r1 )
mtsprg 3 ,r4
lwz r4 ,S L _ D B A T 0 ( r1 )
mtdbatu 0 ,r4
lwz r4 ,S L _ D B A T 0 + 4 ( r1 )
mtdbatl 0 ,r4
lwz r4 ,S L _ D B A T 1 ( r1 )
mtdbatu 1 ,r4
lwz r4 ,S L _ D B A T 1 + 4 ( r1 )
mtdbatl 1 ,r4
lwz r4 ,S L _ D B A T 2 ( r1 )
mtdbatu 2 ,r4
lwz r4 ,S L _ D B A T 2 + 4 ( r1 )
mtdbatl 2 ,r4
lwz r4 ,S L _ D B A T 3 ( r1 )
mtdbatu 3 ,r4
lwz r4 ,S L _ D B A T 3 + 4 ( r1 )
mtdbatl 3 ,r4
lwz r4 ,S L _ I B A T 0 ( r1 )
mtibatu 0 ,r4
lwz r4 ,S L _ I B A T 0 + 4 ( r1 )
mtibatl 0 ,r4
lwz r4 ,S L _ I B A T 1 ( r1 )
mtibatu 1 ,r4
lwz r4 ,S L _ I B A T 1 + 4 ( r1 )
mtibatl 1 ,r4
lwz r4 ,S L _ I B A T 2 ( r1 )
mtibatu 2 ,r4
lwz r4 ,S L _ I B A T 2 + 4 ( r1 )
mtibatl 2 ,r4
lwz r4 ,S L _ I B A T 3 ( r1 )
mtibatu 3 ,r4
lwz r4 ,S L _ I B A T 3 + 4 ( r1 )
mtibatl 3 ,r4
2008-12-18 22:13:32 +03:00
BEGIN_ M M U _ F T R _ S E C T I O N
2005-09-26 10:04:21 +04:00
li r4 ,0
mtspr S P R N _ D B A T 4 U ,r4
mtspr S P R N _ D B A T 4 L ,r4
mtspr S P R N _ D B A T 5 U ,r4
mtspr S P R N _ D B A T 5 L ,r4
mtspr S P R N _ D B A T 6 U ,r4
mtspr S P R N _ D B A T 6 L ,r4
mtspr S P R N _ D B A T 7 U ,r4
mtspr S P R N _ D B A T 7 L ,r4
mtspr S P R N _ I B A T 4 U ,r4
mtspr S P R N _ I B A T 4 L ,r4
mtspr S P R N _ I B A T 5 U ,r4
mtspr S P R N _ I B A T 5 L ,r4
mtspr S P R N _ I B A T 6 U ,r4
mtspr S P R N _ I B A T 6 L ,r4
mtspr S P R N _ I B A T 7 U ,r4
mtspr S P R N _ I B A T 7 L ,r4
2008-12-18 22:13:32 +03:00
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 _ U S E _ H I G H _ B A T S )
2005-09-26 10:04:21 +04:00
/* Flush all TLBs */
lis r4 ,0 x10 0 0
1 : addic. r4 ,r4 ,- 0 x10 0 0
tlbie r4
blt 1 b
sync
/* restore the MSR and turn on the MMU */
lwz r3 ,S L _ M S R ( r1 )
bl t u r n _ o n _ m m u
/* get back the stack pointer */
tovirt( r1 ,r1 )
/* Restore TB */
li r3 ,0
mttbl r3
lwz r3 ,S L _ T B ( r1 )
lwz r4 ,S L _ T B + 4 ( r1 )
mttbu r3
mttbl r4
/* Restore the callee-saved registers and return */
lwz r0 ,S L _ C R ( r1 )
mtcr r0
lwz r2 ,S L _ R 2 ( r1 )
lmw r12 ,S L _ R 1 2 ( r1 )
addi r1 ,r1 ,S L _ S I Z E
lwz r0 ,4 ( r1 )
mtlr r0
blr
turn_on_mmu :
mflr r4
tovirt( r4 ,r4 )
mtsrr0 r4
mtsrr1 r3
sync
isync
rfi
# endif / * d e f i n e d ( C O N F I G _ P M ) | | d e f i n e d ( C O N F I G _ C P U _ F R E Q ) * /
.section .data
2005-10-17 05:50:32 +04:00
.balign L1_CACHE_BYTES
2005-09-26 10:04:21 +04:00
sleep_storage :
.long 0
2005-10-17 05:50:32 +04:00
.balign L1 _ C A C H E _ B Y T E S , 0
2005-09-26 10:04:21 +04:00
# endif / * C O N F I G _ 6 x x * /
.section .text