2019-06-04 10:11:33 +02:00
/* SPDX-License-Identifier: GPL-2.0-only */
2016-06-23 17:54:48 +00:00
/ *
* kexec f o r a r m 6 4
*
* Copyright ( C ) L i n a r o .
* Copyright ( C ) H u a w e i F u t u r e w e i T e c h n o l o g i e s .
2021-09-30 14:31:10 +00:00
* Copyright ( C ) 2 0 2 1 , M i c r o s o f t C o r p o r a t i o n .
* Pasha T a t a s h i n < p a s h a . t a t a s h i n @soleen.com>
2016-06-23 17:54:48 +00:00
* /
# include < l i n u x / k e x e c . h >
# include < l i n u x / l i n k a g e . h >
# include < a s m / a s s e m b l e r . h >
# include < a s m / k e x e c . h >
# include < a s m / p a g e . h >
# include < a s m / s y s r e g . h >
2021-09-30 14:31:07 +00:00
# include < a s m / v i r t . h >
2016-06-23 17:54:48 +00:00
2021-09-30 14:31:10 +00:00
.macro turn_off_mmu tmp1 , t m p2
mov_ q \ t m p1 , I N I T _ S C T L R _ E L 1 _ M M U _ O F F
pre_ d i s a b l e _ m m u _ w o r k a r o u n d
msr s c t l r _ e l 1 , \ t m p1
isb
.endm
2021-09-30 14:31:08 +00:00
.section " .kexec_relocate .text " , " ax"
2016-06-23 17:54:48 +00:00
/ *
* arm6 4 _ r e l o c a t e _ n e w _ k e r n e l - P u t a 2 n d s t a g e i m a g e i n p l a c e a n d b o o t i t .
*
2021-01-25 14:19:16 -05:00
* The m e m o r y t h a t t h e o l d k e r n e l o c c u p i e s m a y b e o v e r w r i t t e n w h e n c o p y i n g t h e
2016-06-23 17:54:48 +00:00
* new i m a g e t o i t s f i n a l l o c a t i o n . T o a s s u r e t h a t t h e
* arm6 4 _ r e l o c a t e _ n e w _ k e r n e l r o u t i n e w h i c h d o e s t h a t c o p y i s n o t o v e r w r i t t e n ,
* all c o d e a n d d a t a n e e d e d b y a r m 6 4 _ r e l o c a t e _ n e w _ k e r n e l m u s t b e b e t w e e n t h e
* symbols a r m 6 4 _ r e l o c a t e _ n e w _ k e r n e l a n d a r m 6 4 _ r e l o c a t e _ n e w _ k e r n e l _ e n d . T h e
* machine_ k e x e c ( ) r o u t i n e w i l l c o p y a r m 6 4 _ r e l o c a t e _ n e w _ k e r n e l t o t h e k e x e c
2021-01-25 14:19:16 -05:00
* safe m e m o r y t h a t h a s b e e n s e t u p t o b e p r e s e r v e d d u r i n g t h e c o p y o p e r a t i o n .
2016-06-23 17:54:48 +00:00
* /
2020-05-01 12:54:29 +01:00
SYM_ C O D E _ S T A R T ( a r m 6 4 _ r e l o c a t e _ n e w _ k e r n e l )
2022-05-16 17:07:35 +01:00
/ *
* The k i m a g e s t r u c t u r e i s n ' t a l l o c a t e d s p e c i a l l y a n d m a y b e c l o b b e r e d
* during r e l o c a t i o n . W e m u s t l o a d a n y v a l u e s w e n e e d f r o m i t p r i o r t o
* any r e l o c a t i o n o c c u r r i n g .
* /
ldr x28 , [ x0 , #K I M A G E _ S T A R T ]
ldr x27 , [ x0 , #K I M A G E _ A R C H _ E L 2 _ V E C T O R S ]
ldr x26 , [ x0 , #K I M A G E _ A R C H _ D T B _ M E M ]
2016-06-23 17:54:48 +00:00
/* Setup the list loop variables. */
2021-09-30 14:31:09 +00:00
ldr x18 , [ x0 , #K I M A G E _ A R C H _ Z E R O _ P A G E ] / * x 18 = z e r o p a g e f o r B B M * /
ldr x17 , [ x0 , #K I M A G E _ A R C H _ T T B R 1 ] / * x17 = l i n e a r m a p c o p y * /
2021-09-30 14:31:05 +00:00
ldr x16 , [ x0 , #K I M A G E _ H E A D ] / * x 16 = k i m a g e _ h e a d * /
2021-09-30 14:31:10 +00:00
ldr x22 , [ x0 , #K I M A G E _ A R C H _ P H Y S _ O F F S E T ] / * x 22 p h y s _ o f f s e t * /
2021-01-25 14:19:17 -05:00
raw_ d c a c h e _ l i n e _ s i z e x15 , x1 / * x15 = d c a c h e l i n e s i z e * /
2021-09-30 14:31:09 +00:00
break_ b e f o r e _ m a k e _ t t b r _ s w i t c h x18 , x17 , x1 , x2 / * s e t l i n e a r m a p * /
2016-06-23 17:54:48 +00:00
.Lloop :
and x12 , x16 , P A G E _ M A S K / * x12 = a d d r * /
2021-09-30 14:31:10 +00:00
sub x12 , x12 , x22 / * C o n v e r t x12 t o v i r t * /
2016-06-23 17:54:48 +00:00
/* Test the entry flags. */
.Ltest_source :
tbz x16 , I N D _ S O U R C E _ B I T , . L t e s t _ i n d i r e c t i o n
/* Invalidate dest page to PoC. */
2021-09-30 14:31:10 +00:00
mov x19 , x13
2021-01-25 14:19:17 -05:00
copy_ p a g e x13 , x12 , x1 , x2 , x3 , x4 , x5 , x6 , x7 , x8
2021-09-30 14:31:10 +00:00
add x1 , x19 , #P A G E _ S I Z E
dcache_ b y _ m y l i n e _ o p c i v a c , s y , x19 , x1 , x15 , x20
2016-06-23 17:54:48 +00:00
b . L n e x t
.Ltest_indirection :
tbz x16 , I N D _ I N D I R E C T I O N _ B I T , . L t e s t _ d e s t i n a t i o n
2021-01-25 14:19:16 -05:00
mov x14 , x12 / * p t r = a d d r * /
2016-06-23 17:54:48 +00:00
b . L n e x t
.Ltest_destination :
tbz x16 , I N D _ D E S T I N A T I O N _ B I T , . L n e x t
2021-01-25 14:19:16 -05:00
mov x13 , x12 / * d e s t = a d d r * /
2016-06-23 17:54:48 +00:00
.Lnext :
2021-01-25 14:19:16 -05:00
ldr x16 , [ x14 ] , #8 / * e n t r y = * p t r + + * /
tbz x16 , I N D _ D O N E _ B I T , . L l o o p / * w h i l e ( ! ( e n t r y & D O N E ) ) * /
2016-06-23 17:54:48 +00:00
/* wait for writes from copy_page to finish */
dsb n s h
ic i a l l u
dsb n s h
isb
2021-09-30 14:31:10 +00:00
turn_ o f f _ m m u x12 , x13
2016-06-23 17:54:48 +00:00
/* Start new image. */
2022-05-16 17:07:35 +01:00
cbz x27 , . L e l 1
mov x1 , x28 / * k e r n e l e n t r y p o i n t * /
mov x2 , x26 / * d t b a d d r e s s * /
2021-09-30 14:31:07 +00:00
mov x3 , x z r
mov x4 , x z r
mov x0 , #H V C _ S O F T _ R E S T A R T
hvc #0 / * J u m p s f r o m e l 2 * /
.Lel1 :
2022-05-16 17:07:35 +01:00
mov x0 , x26 / * d t b a d d r e s s * /
mov x1 , x z r
2016-06-23 17:54:48 +00:00
mov x2 , x z r
mov x3 , x z r
2022-05-16 17:07:35 +01:00
br x28 / * J u m p s f r o m e l 1 * /
2020-05-01 12:54:29 +01:00
SYM_ C O D E _ E N D ( a r m 6 4 _ r e l o c a t e _ n e w _ k e r n e l )