2023-03-30 14:43:21 +08:00
/* SPDX-License-Identifier: GPL-2.0-only */
/ *
* Hibernation l o w l e v e l s u p p o r t f o r R I S C V .
*
* Copyright ( C ) 2 0 2 3 S t a r F i v e T e c h n o l o g y C o . , L t d .
*
* Author : Jee H e n g S i a < j e e h e n g . s i a @starfivetech.com>
* /
# include < a s m / a s m . h >
# include < a s m / a s m - o f f s e t s . h >
# include < a s m / a s s e m b l e r . h >
# include < a s m / c s r . h >
# include < l i n u x / l i n k a g e . h >
/ *
* int _ _ h i b e r n a t e _ c p u _ r e s u m e ( v o i d )
* Switch b a c k t o t h e h i b e r n a t e d i m a g e ' s p a g e t a b l e p r i o r t o r e s t o r i n g t h e C P U
* context.
*
* Always r e t u r n s 0
* /
ENTRY( _ _ h i b e r n a t e _ c p u _ r e s u m e )
/* switch to hibernated image's page table. */
csrw C S R _ S A T P , s0
sfence. v m a
REG_ L a0 , h i b e r n a t e _ c p u _ c o n t e x t
suspend_ r e s t o r e _ r e g s
/* Return zero value. */
mv a0 , z e r o
ret
END( _ _ h i b e r n a t e _ c p u _ r e s u m e )
/ *
* Prepare t o r e s t o r e t h e i m a g e .
* a0 : satp o f s a v e d p a g e t a b l e s .
* a1 : satp o f t e m p o r a r y p a g e t a b l e s .
* a2 : cpu_ r e s u m e .
* /
ENTRY( h i b e r n a t e _ r e s t o r e _ i m a g e )
mv s0 , a0
mv s1 , a1
mv s2 , a2
REG_ L s4 , r e s t o r e _ p b l i s t
REG_ L a1 , r e l o c a t e d _ r e s t o r e _ c o d e
2023-05-19 14:08:54 +08:00
jr a1
2023-03-30 14:43:21 +08:00
END( h i b e r n a t e _ r e s t o r e _ i m a g e )
/ *
* The b e l o w c o d e w i l l b e e x e c u t e d f r o m a ' s a f e ' p a g e .
* It f i r s t s w i t c h e s t o t h e t e m p o r a r y p a g e t a b l e , t h e n s t a r t s t o c o p y t h e p a g e s
* back t o t h e o r i g i n a l m e m o r y l o c a t i o n . F i n a l l y , i t j u m p s t o _ _ h i b e r n a t e _ c p u _ r e s u m e ( )
* to r e s t o r e t h e C P U c o n t e x t .
* /
ENTRY( h i b e r n a t e _ c o r e _ r e s t o r e _ c o d e )
/* switch to temp page table. */
csrw s a t p , s1
sfence. v m a
.Lcopy :
/* The below code will restore the hibernated image. */
REG_ L a1 , H I B E R N _ P B E _ A D D R ( s4 )
REG_ L a0 , H I B E R N _ P B E _ O R I G ( s4 )
copy_ p a g e a0 , a1
REG_ L s4 , H I B E R N _ P B E _ N E X T ( s4 )
bnez s4 , . L c o p y
2023-05-19 14:08:54 +08:00
jr s2
2023-03-30 14:43:21 +08:00
END( h i b e r n a t e _ c o r e _ r e s t o r e _ c o d e )