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 .
* /
# 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 >
/ *
* 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 )
2016-06-23 17:54:48 +00:00
/* Setup the list loop variables. */
2018-11-15 14:52:52 +09:00
mov x18 , x2 / * x18 = d t b a d d r e s s * /
2016-06-23 17:54:48 +00:00
mov x17 , x1 / * x17 = k i m a g e _ s t a r t * /
mov x16 , x0 / * x16 = k i m a g e _ h e a d * /
mov x14 , x z r / * x14 = e n t r y p t r * /
mov x13 , x z r / * x13 = c o p y d e s t * /
/* Check if the new image needs relocation. */
tbnz x16 , I N D _ D O N E _ B I T , . L d o n e
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 * /
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 * /
/* 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-01-25 14:19:17 -05:00
mov x2 , x13
add x20 , x2 , #P A G E _ S I Z E
2016-06-23 17:54:48 +00:00
sub x1 , x15 , #1
2021-01-25 14:19:17 -05:00
bic x2 , x2 , x1
2 : dc i v a c , x2
add x2 , x2 , x15
cmp x2 , x20
2016-06-23 17:54:48 +00:00
b. l o 2 b
dsb s y
2021-01-25 14:19:17 -05:00
copy_ p a g e x13 , x12 , x1 , x2 , x3 , x4 , x5 , x6 , x7 , x8
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
.Ldone :
/* wait for writes from copy_page to finish */
dsb n s h
ic i a l l u
dsb n s h
isb
/* Start new image. */
2018-11-15 14:52:52 +09:00
mov x0 , x18
2016-06-23 17:54:48 +00:00
mov x1 , x z r
mov x2 , x z r
mov x3 , x z r
br x17
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 )
2016-06-23 17:54:48 +00:00
.align 3 /* To keep the 64-bit values below naturally aligned. */
.Lcopy_end :
.org KEXEC_CONTROL_PAGE_SIZE
/ *
* arm6 4 _ r e l o c a t e _ n e w _ k e r n e l _ s i z e - N u m b e r o f b y t e s t o c o p y t o t h e
* control_ c o d e _ p a g e .
* /
.globl arm64_relocate_new_kernel_size
arm64_relocate_new_kernel_size :
.quad .Lcopy_end - arm6 4 _ r e l o c a t e _ n e w _ k e r n e l