2005-04-16 15:20:36 -07:00
/ * sleep. S : p o w e r s a v i n g m o d e e n t r y
*
* Copyright ( C ) 2 0 0 4 R e d H a t , I n c . A l l R i g h t s R e s e r v e d .
2008-06-05 22:46:18 -07:00
* Written b y D a v i d W o o d h o u s e ( d w m w2 @infradead.org)
2005-04-16 15:20:36 -07: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 < l i n u x / l i n k a g e . h >
# include < a s m / s e t u p . h >
# include < a s m / s e g m e n t . h >
# include < a s m / p a g e . h >
# include < a s m / p t r a c e . h >
# include < a s m / e r r n o . h >
# include < a s m / c a c h e . h >
# include < a s m / s p r - r e g s . h >
# define _ _ a d d r _ M A S K 0 x f e f f98 2 0 / * i n t e r r u p t c o n t r o l l e r m a s k * /
# define _ _ a d d r _ F R 5 5 X _ D R C N 0 x f e f f02 1 8 / * A d d r e s s o f D R C N r e g i s t e r * /
# define F R 5 5 X _ D S T S _ O F F S E T - 4 / * O f f s e t f r o m D R C N t o D S T S * /
# define F R 5 5 X _ S D R A M C _ D S T S _ S S I 0 x00 0 0 0 0 0 2 / * i n d i c a t e s t h a t t h e S D R A M i s i n s e l f - r e f r e s h m o d e * /
# define _ _ a d d r _ F R 4 X X _ D R C N 0 x f e 0 0 0 4 3 0 / * A d d r e s s o f D R C N r e g i s t e r * /
# define F R 4 X X _ D S T S _ O F F S E T - 8 / * O f f s e t f r o m D R C N t o D S T S * /
# define F R 4 X X _ S D R A M C _ D S T S _ S S I 0 x00 0 0 0 0 0 1 / * i n d i c a t e s t h a t t h e S D R A M i s i n s e l f - r e f r e s h m o d e * /
# define S D R A M C _ D R C N _ S R 0 x00 0 0 0 0 0 1 / * t r a n s i t i o n S D R A M i n t o s e l f - r e f r e s h m o d e * /
.section .bss
.balign 8
.globl __sleep_save_area
__sleep_save_area :
.space 16
.text
.balign 4
.macro li v r
sethi. p % h i ( \ v ) ,\ r
setlo % l o ( \ v ) ,\ r
.endm
# ifdef C O N F I G _ P M
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# CPU s u s p e n s i o n r o u t i n e
# - void f r v _ c p u _ s u s p e n d ( u n s i g n e d l o n g p d m _ m o d e )
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
.globl frv_cpu_suspend
.type frv_ c p u _ s u s p e n d ,@function
frv_cpu_suspend :
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# save h s r0 , p s r , i s r , a n d l r f o r r e s u m e c o d e
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
li _ _ s l e e p _ s a v e _ a r e a ,g r11
movsg h s r0 ,g r4
movsg p s r ,g r5
movsg i s r ,g r6
movsg l r ,g r7
stdi g r4 ,@(gr11,#0)
stdi g r6 ,@(gr11,#8)
# store t h e r e t u r n a d d r e s s f r o m s l e e p i n G R 1 4 , a n d i t s c o m p l e m e n t i n G R 1 3 a s a c h e c k
li _ _ r a m b o o t _ r e s u m e ,g r14
# ifdef C O N F I G _ M M U
# Resume v i a R A M B O O T # w i l l t u r n M M U o f f , s o b o o t l o a d e r n e e d s a p h y s i c a l a d d r e s s .
sethi. p % h i ( _ _ p a g e _ o f f s e t ) ,g r13
setlo % l o ( _ _ p a g e _ o f f s e t ) ,g r13
sub g r14 ,g r13 ,g r14
# endif
not g r14 ,g r13
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# preload a n d l o c k i n t o i c a c h e t h a t c o d e w h i c h m a y h a v e t o r u n
# when d r a m i s i n s e l f - r e f r e s h s t a t e .
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
movsg h s r0 , g r3
li H S R 0 _ I C E ,g r4
or g r3 ,g r4 ,g r3
movgs g r3 ,h s r0
or g r3 ,g r8 ,g r7 / / a d d t h e s l e e p b i t s f o r l a t e r
li #_ _ i c a c h e _ l o c k _ s t a r t , g r 3
li #_ _ i c a c h e _ l o c k _ e n d , g r 4
1 : icpl g r3 ,g r0 ,#1
addi g r3 ,#L 1 _ C A C H E _ B Y T E S ,g r3
cmp g r4 ,g r3 ,i c c0
bhi i c c0 ,#0 ,1 b
# disable e x c e p t i o n s
movsg p s r ,g r8
andi. p g r8 ,#~ P S R _ P I L , g r 8
andi g r8 ,~ P S R _ E T ,g r8
movgs g r8 ,p s r
ori g r8 ,#P S R _ E T , g r 8
srli g r8 ,#28 ,g r4
subicc g r4 ,#3 ,g r0 ,i c c0
beq i c c0 ,#0 ,1 f
# FR4 x x
li _ _ a d d r _ F R 4 X X _ D R C N ,g r4
li F R 4 X X _ S D R A M C _ D S T S _ S S I ,g r5
li F R 4 X X _ D S T S _ O F F S E T ,g r6
bra _ _ i c a c h e _ l o c k _ s t a r t
1 :
# FR5 x x
li _ _ a d d r _ F R 5 5 X _ D R C N ,g r4
li F R 5 5 X _ S D R A M C _ D S T S _ S S I ,g r5
li F R 5 5 X _ D S T S _ O F F S E T ,g r6
bra _ _ i c a c h e _ l o c k _ s t a r t
.size frv_ c p u _ s u s p e n d , . - f r v _ c p u _ s u s p e n d
#
# the f i n a l p a r t o f t h e s l e e p s e q u e n c e . . .
# - we w a n t i t t o b e b e c a c h e l i n e a l i g n e d s o w e c a n l o c k i t i n t o t h e i c a c h e e a s i l y
# On e n t r y : g r7 h o l d s d e s i r e d h s r0 s l e e p v a l u e
# gr8 h o l d s d e s i r e d p s r s l e e p v a l u e
#
.balign L1_CACHE_BYTES
.type _ _ icache_ l o c k _ s t a r t ,@function
__icache_lock_start :
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# put S D R A M i n s e l f - r e f r e s h m o d e
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Flush a l l d a t a i n t h e c a c h e u s i n g t h e D C E F i n s t r u c t i o n .
dcef @(gr0,gr0),#1
# Stop D M A C t r a n s f e r
# Execute d u m m y l o a d f r o m S D R A M
ldi @(gr11,#0),gr11
# put t h e S D R A M i n t o s e l f - r e f r e s h m o d e
ld @(gr4,gr0),gr11
ori g r11 ,#S D R A M C _ D R C N _ S R , g r 11
st g r11 ,@(gr4,gr0)
membar
# wait f o r S D R A M t o r e a c h s e l f - r e f r e s h m o d e
1 : ld @(gr4,gr6),gr11
andcc g r11 ,g r5 ,g r11 ,i c c0
beq i c c0 ,#0 ,1 b
# Set t h e G P I O r e g i s t e r s o t h a t t h e I R Q [ 3 : 0 ] p i n s b e c o m e v a l i d , a s r e q u i r e d .
# Set t h e c l o c k m o d e ( C L K C r e g i s t e r ) a s r e q u i r e d .
# - At t h i s t i m e , a l s o s e t t h e C L K C r e g i s t e r P 0 b i t .
# Set t h e H S R 0 r e g i s t e r P D M f i e l d .
movgs g r7 ,h s r0
# Execute N O P 3 2 t i m e s .
.rept 32
nop
.endr
# if 0 / / F u j i t s u r e c o m m e n d t o s k i p t h i s a n d w i l l u p d a t e d o c s .
# Release t h e i n t e r r u p t m a s k s e t t i n g o f t h e M A S K r e g i s t e r o f t h e
# interrupt c o n t r o l l e r i f n e c e s s a r y .
sti g r10 ,@(gr9,#0)
membar
# endif
# Set t h e P S R r e g i s t e r E T b i t t o 1 t o e n a b l e i n t e r r u p t s .
movgs g r8 ,p s r
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# this i s o n l y r e a c h e d i f w a k i n g u p v i a i n t e r r u p t
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Execute N O P 3 2 t i m e s .
.rept 32
nop
.endr
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# wake S D R A M f r o m s e l f - r e f r e s h m o d e
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ld @(gr4,gr0),gr11
andi g r11 ,#~ S D R A M C _ D R C N _ S R , g r 11
st g r11 ,@(gr4,gr0)
membar
2 :
ld @(gr4,gr6),gr11 // Wait for it to come back...
andcc g r11 ,g r5 ,g r0 ,i c c0
bne i c c0 ,0 ,2 b
# wait f o r t h e S D R A M t o s t a b i l i s e
li 0 x01 0 0 0 0 0 ,g r3
3 : subicc g r3 ,#1 ,g r3 ,i c c0
bne i c c0 ,#0 ,3 b
# now t h a t D R A M i s b a c k , t h i s i s t h e e n d o f t h e c o d e w h i c h g e t s
# locked i n i c a c h e .
__icache_lock_end :
.size _ _ icache_ l o c k _ s t a r t , . - _ _ i c a c h e _ l o c k _ s t a r t
# Fall- t h r o u g h t o t h e R A M B O O T # w a k e u p p a t h
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# resume f r o m s u s p e n d r e - e n t r y p o i n t r e a c h e d v i a R A M B O O T # a n d b o o t l o a d e r
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
__ramboot_resume :
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# restore h s r0 , p s r , i s r , a n d l e a v e s a v e d l r i n g r7
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
li _ _ s l e e p _ s a v e _ a r e a ,g r11
# ifdef C O N F I G _ M M U
movsg h s r0 ,g r4
sethi. p % h i ( H S R 0 _ E X M M U ) ,g r3
setlo % l o ( H S R 0 _ E X M M U ) ,g r3
andcc g r3 ,g r4 ,g r0 ,i c c0
bne i c c0 ,#0 ,2 f
# need t o u s e p h y s i c a l a d d r e s s
sethi. p % h i ( _ _ p a g e _ o f f s e t ) ,g r3
setlo % l o ( _ _ p a g e _ o f f s e t ) ,g r3
sub g r11 ,g r3 ,g r11
# flush a l l t l b e n t r i e s
setlos #64 ,g r4
setlos. p #P A G E _ S I Z E , g r 5
setlos #0 ,g r6
1 :
tlbpr g r6 ,g r0 ,#6 ,#0
subicc. p g r4 ,#1 ,g r4 ,i c c0
add g r6 ,g r5 ,g r6
bne i c c0 ,#2 ,1 b
# need a t e m p o r a r y m a p p i n g f o r t h e c u r r e n t p h y s i c a l a d d r e s s w e a r e
# using b e t w e e n t i m e M M U i s e n a b l e d a n d j u m p t o v i r t u a l a d d r e s s i s
# made.
sethi. p % h i ( 0 x00 0 0 0 0 0 0 ) ,g r4
setlo % l o ( 0 x00 0 0 0 0 0 0 ) ,g r4 ; physical address
setlos #x A M P R x _ L | x A M P R x _ M | x A M P R x _ S S _ 256 M b | x A M P R x _ S _ K E R N E L | x A M P R x _ V ,g r5
or g r4 ,g r5 ,g r5
movsg c x n r ,g r13
or g r4 ,g r13 ,g r4
movgs g r4 ,i a m l r1 ; mapped from real address 0
movgs g r5 ,i a m p r1 ; cached kernel memory at 0x00000000
2 :
# endif
lddi @(gr11,#0),gr4 ; hsr0, psr
lddi @(gr11,#8),gr6 ; isr, lr
movgs g r4 ,h s r0
bar
# ifdef C O N F I G _ M M U
sethi. p % h i ( 1 f ) ,g r11
setlo % l o ( 1 f ) ,g r11
jmpl @(gr11,gr0)
1 :
movgs g r0 ,i a m p r1 ; get rid of temporary mapping
# endif
movgs g r5 ,p s r
movgs g r6 ,i s r
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# unlock t h e i c a c h e w h i c h w a s l o c k e d b e f o r e g o i n g t o s l e e p
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
li _ _ i c a c h e _ l o c k _ s t a r t ,g r3
li _ _ i c a c h e _ l o c k _ e n d ,g r4
1 : icul g r3
addi g r3 ,#L 1 _ C A C H E _ B Y T E S ,g r3
cmp g r4 ,g r3 ,i c c0
bhi i c c0 ,#0 ,1 b
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# back t o b u s i n e s s a s u s u a l
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
jmpl @(gr7,gr0) ;
# endif / * C O N F I G _ P M * /
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# CPU c o r e s l e e p m o d e r o u t i n e
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
.globl frv_cpu_core_sleep
.type frv_ c p u _ c o r e _ s l e e p ,@function
frv_cpu_core_sleep :
# Preload i n t o i c a c h e .
li #_ _ c o r e _ s l e e p _ i c a c h e _ l o c k _ s t a r t , g r 3
li #_ _ c o r e _ s l e e p _ i c a c h e _ l o c k _ e n d , g r 4
1 : icpl g r3 ,g r0 ,#1
addi g r3 ,#L 1 _ C A C H E _ B Y T E S ,g r3
cmp g r4 ,g r3 ,i c c0
bhi i c c0 ,#0 ,1 b
bra _ _ c o r e _ s l e e p _ i c a c h e _ l o c k _ s t a r t
.balign L1_CACHE_BYTES
__core_sleep_icache_lock_start :
# ( 1 ) Set t h e P S R r e g i s t e r E T b i t t o 0 t o d i s a b l e i n t e r r u p t s .
movsg p s r ,g r8
andi. p g r8 ,#~ ( P S R _ P I L ) , g r 8
andi g r8 ,#~ ( P S R _ E T ) , g r 4
movgs g r4 ,p s r
# if 0 / / F u j i t s u r e c o m m e n d t o s k i p t h i s a n d w i l l u p d a t e d o c s .
# ( 2 ) Set ' 1 ' t o a l l b i t s i n t h e M A S K r e g i s t e r o f t h e i n t e r r u p t
# controller a n d m a s k i n t e r r u p t s .
sethi. p % h i ( _ _ a d d r _ M A S K ) ,g r9
setlo % l o ( _ _ a d d r _ M A S K ) ,g r9
sethi. p % h i ( 0 x f f f f00 0 0 ) ,g r4
setlo % l o ( 0 x f f f f00 0 0 ) ,g r4
ldi @(gr9,#0),gr10
sti g r4 ,@(gr9,#0)
# endif
# ( 3 ) Flush a l l d a t a i n t h e c a c h e u s i n g t h e D C E F i n s t r u c t i o n .
dcef @(gr0,gr0),#1
# ( 4 ) Execute t h e m e m o r y b a r r i e r i n s t r u c t i o n
membar
# ( 5 ) Set t h e G P I O r e g i s t e r s o t h a t t h e I R Q [ 3 : 0 ] p i n s b e c o m e v a l i d , a s r e q u i r e d .
# ( 6 ) Set t h e c l o c k m o d e ( C L K C r e g i s t e r ) a s r e q u i r e d .
# - At t h i s t i m e , a l s o s e t t h e C L K C r e g i s t e r P 0 b i t .
# ( 7 ) Set t h e H S R 0 r e g i s t e r P D M f i e l d t o 0 0 1 .
movsg h s r0 ,g r4
ori g r4 ,H S R 0 _ P D M _ C O R E _ S L E E P ,g r4
movgs g r4 ,h s r0
# ( 8 ) Execute N O P 3 2 t i m e s .
.rept 32
nop
.endr
# if 0 / / F u j i t s u r e c o m m e n d t o s k i p t h i s a n d w i l l u p d a t e d o c s .
# ( 9 ) Release t h e i n t e r r u p t m a s k s e t t i n g o f t h e M A S K r e g i s t e r o f t h e
# interrupt c o n t r o l l e r i f n e c e s s a r y .
sti g r10 ,@(gr9,#0)
membar
# endif
# ( 1 0 ) Set t h e P S R r e g i s t e r E T b i t t o 1 t o e n a b l e i n t e r r u p t s .
movgs g r8 ,p s r
__core_sleep_icache_lock_end :
# Unlock f r o m i c a c h e
li _ _ c o r e _ s l e e p _ i c a c h e _ l o c k _ s t a r t ,g r3
li _ _ c o r e _ s l e e p _ i c a c h e _ l o c k _ e n d ,g r4
1 : icul g r3
addi g r3 ,#L 1 _ C A C H E _ B Y T E S ,g r3
cmp g r4 ,g r3 ,i c c0
bhi i c c0 ,#0 ,1 b
bralr
.size frv_ c p u _ c o r e _ s l e e p , . - f r v _ c p u _ c o r e _ s l e e p