2012-03-05 15:49:27 +04:00
/ *
* Low- l e v e l C P U i n i t i a l i s a t i o n
* Based o n a r c h / a r m / k e r n e l / h e a d . S
*
* Copyright ( C ) 1 9 9 4 - 2 0 0 2 R u s s e l l K i n g
* Copyright ( C ) 2 0 0 3 - 2 0 1 2 A R M L t d .
* Authors : Catalin M a r i n a s < c a t a l i n . m a r i n a s @arm.com>
* Will D e a c o n < w i l l . d e a c o n @arm.com>
*
* 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
* it 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 v e r s i o n 2 a s
* published 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 .
*
* This p r o g r a m i s d i s t r i b u t e d i n t h e h o p e t h a t i t w i l l b e u s e f u l ,
* but W I T H O U T A N Y W A R R A N T Y ; without even the implied warranty of
* MERCHANTABILITY o r F I T N E S S F O R A P A R T I C U L A R P U R P O S E . S e e t h e
* GNU G e n e r a l P u b l i c L i c e n s e f o r m o r e d e t a i l s .
*
* You s h o u l d h a v e r e c e i v e d a c o p y 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
* along w i t h t h i s p r o g r a m . I f n o t , s e e < h t t p : / / w w w . g n u . o r g / l i c e n s e s / > .
* /
# include < l i n u x / l i n k a g e . h >
# include < l i n u x / i n i t . h >
2014-06-30 19:01:31 +04:00
# include < l i n u x / i r q c h i p / a r m - g i c - v3 . h >
2012-03-05 15:49:27 +04:00
# include < a s m / a s s e m b l e r . h >
# include < a s m / p t r a c e . h >
# include < a s m / a s m - o f f s e t s . h >
2014-03-26 22:25:55 +04:00
# include < a s m / c a c h e . h >
2012-08-29 21:32:18 +04:00
# include < a s m / c p u t y p e . h >
2012-03-05 15:49:27 +04:00
# include < a s m / m e m o r y . h >
# include < a s m / t h r e a d _ i n f o . h >
# include < a s m / p g t a b l e - h w d e f . h >
# include < a s m / p g t a b l e . h >
# include < a s m / p a g e . h >
2012-10-26 18:40:05 +04:00
# include < a s m / v i r t . h >
2012-03-05 15:49:27 +04:00
2015-03-17 11:14:29 +03:00
# define _ _ P H Y S _ O F F S E T ( K E R N E L _ S T A R T - T E X T _ O F F S E T )
2012-03-05 15:49:27 +04:00
2014-08-13 21:53:03 +04:00
# if ( T E X T _ O F F S E T & 0 x f f f ) ! = 0
# error T E X T _ O F F S E T m u s t b e a t l e a s t 4 K B a l i g n e d
# elif ( P A G E _ O F F S E T & 0 x1 f f f f f ) ! = 0
2014-06-24 19:51:37 +04:00
# error P A G E _ O F F S E T m u s t b e a t l e a s t 2 M B a l i g n e d
2014-08-13 21:53:03 +04:00
# elif T E X T _ O F F S E T > 0 x1 f f f f f
2014-06-24 19:51:37 +04:00
# error T E X T _ O F F S E T m u s t b e l e s s t h a n 2 M B
2012-03-05 15:49:27 +04:00
# endif
# ifdef C O N F I G _ A R M 6 4 _ 6 4 K _ P A G E S
# define B L O C K _ S H I F T P A G E _ S H I F T
# define B L O C K _ S I Z E P A G E _ S I Z E
2014-07-21 18:54:50 +04:00
# define T A B L E _ S H I F T P M D _ S H I F T
2012-03-05 15:49:27 +04:00
# else
# define B L O C K _ S H I F T S E C T I O N _ S H I F T
# define B L O C K _ S I Z E S E C T I O N _ S I Z E
2014-07-21 18:54:50 +04:00
# define T A B L E _ S H I F T P U D _ S H I F T
2012-03-05 15:49:27 +04:00
# endif
2015-03-17 11:14:29 +03:00
# define K E R N E L _ S T A R T _ t e x t
2012-03-05 15:49:27 +04:00
# define K E R N E L _ E N D _ e n d
/ *
* Initial m e m o r y m a p a t t r i b u t e s .
* /
# define P T E _ F L A G S P T E _ T Y P E _ P A G E | P T E _ A F | P T E _ S H A R E D
# define P M D _ F L A G S P M D _ T Y P E _ S E C T | P M D _ S E C T _ A F | P M D _ S E C T _ S
# ifdef C O N F I G _ A R M 6 4 _ 6 4 K _ P A G E S
# define M M _ M M U F L A G S P T E _ A T T R I N D X ( M T _ N O R M A L ) | P T E _ F L A G S
# else
# define M M _ M M U F L A G S P M D _ A T T R I N D X ( M T _ N O R M A L ) | P M D _ F L A G S
# endif
/ *
* Kernel s t a r t u p e n t r y p o i n t .
* - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* The r e q u i r e m e n t s a r e :
* MMU = o f f , D - c a c h e = o f f , I - c a c h e = o n o r o f f ,
* x0 = p h y s i c a l a d d r e s s t o t h e F D T b l o b .
*
* This c o d e i s m o s t l y p o s i t i o n i n d e p e n d e n t s o y o u c a l l t h i s a t
* _ _ pa( P A G E _ O F F S E T + T E X T _ O F F S E T ) .
*
* Note t h a t t h e c a l l e e - s a v e d r e g i s t e r s a r e u s e d f o r s t o r i n g v a r i a b l e s
* that a r e u s e f u l b e f o r e t h e M M U i s e n a b l e d . T h e a l l o c a t i o n s a r e d e s c r i b e d
* in t h e e n t r y r o u t i n e s .
* /
_ _ HEAD
/ *
* DO N O T M O D I F Y . I m a g e h e a d e r e x p e c t e d b y L i n u x b o o t - l o a d e r s .
* /
2014-04-16 06:47:52 +04:00
# ifdef C O N F I G _ E F I
efi_head :
/ *
* This a d d i n s t r u c t i o n h a s n o m e a n i n g f u l e f f e c t e x c e p t t h a t
* its o p c o d e f o r m s t h e m a g i c " M Z " s i g n a t u r e r e q u i r e d b y U E F I .
* /
add x13 , x18 , #0x16
b s t e x t
# else
2012-03-05 15:49:27 +04:00
b s t e x t / / b r a n c h t o k e r n e l s t a r t , m a g i c
.long 0 / / reserved
2014-04-16 06:47:52 +04:00
# endif
arm64: Update the Image header
Currently the kernel Image is stripped of everything past the initial
stack, and at runtime the memory is initialised and used by the kernel.
This makes the effective minimum memory footprint of the kernel larger
than the size of the loaded binary, though bootloaders have no mechanism
to identify how large this minimum memory footprint is. This makes it
difficult to choose safe locations to place both the kernel and other
binaries required at boot (DTB, initrd, etc), such that the kernel won't
clobber said binaries or other reserved memory during initialisation.
Additionally when big endian support was added the image load offset was
overlooked, and is currently of an arbitrary endianness, which makes it
difficult for bootloaders to make use of it. It seems that bootloaders
aren't respecting the image load offset at present anyway, and are
assuming that offset 0x80000 will always be correct.
This patch adds an effective image size to the kernel header which
describes the amount of memory from the start of the kernel Image binary
which the kernel expects to use before detecting memory and handling any
memory reservations. This can be used by bootloaders to choose suitable
locations to load the kernel and/or other binaries such that the kernel
will not clobber any memory unexpectedly. As before, memory reservations
are required to prevent the kernel from clobbering these locations
later.
Both the image load offset and the effective image size are forced to be
little-endian regardless of the native endianness of the kernel to
enable bootloaders to load a kernel of arbitrary endianness. Bootloaders
which wish to make use of the load offset can inspect the effective
image size field for a non-zero value to determine if the offset is of a
known endianness. To enable software to determine the endinanness of the
kernel as may be required for certain use-cases, a new flags field (also
little-endian) is added to the kernel header to export this information.
The documentation is updated to clarify these details. To discourage
future assumptions regarding the value of text_offset, the value at this
point in time is removed from the main flow of the documentation (though
kept as a compatibility note). Some minor formatting issues in the
documentation are also corrected.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Tom Rini <trini@ti.com>
Cc: Geoff Levand <geoff@infradead.org>
Cc: Kevin Hilman <kevin.hilman@linaro.org>
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2014-06-24 19:51:36 +04:00
.quad _kernel_offset_le / / Image l o a d o f f s e t f r o m s t a r t o f R A M , l i t t l e - e n d i a n
.quad _kernel_size_le / / Effective s i z e o f k e r n e l i m a g e , l i t t l e - e n d i a n
.quad _kernel_flags_le / / Informative f l a g s , l i t t l e - e n d i a n
2013-08-15 03:10:00 +04:00
.quad 0 / / reserved
.quad 0 / / reserved
.quad 0 / / reserved
.byte 0x41 / / Magic n u m b e r , " A R M \ x64 "
.byte 0x52
.byte 0x4d
.byte 0x64
2014-04-16 06:47:52 +04:00
# ifdef C O N F I G _ E F I
.long pe_header - efi_ h e a d / / O f f s e t t o t h e P E h e a d e r .
# else
2013-08-15 03:10:00 +04:00
.word 0 / / reserved
2014-04-16 06:47:52 +04:00
# endif
# ifdef C O N F I G _ E F I
arm64/efi: efistub: jump to 'stext' directly, not through the header
After the EFI stub has done its business, it jumps into the kernel by
branching to offset #0 of the loaded Image, which is where it expects
to find the header containing a 'branch to stext' instruction.
However, the UEFI spec 2.1.1 states the following regarding PE/COFF
image loading:
"A UEFI image is loaded into memory through the LoadImage() Boot
Service. This service loads an image with a PE32+ format into memory.
This PE32+ loader is required to load all sections of the PE32+ image
into memory."
In other words, it is /not/ required to load parts of the image that are
not covered by a PE/COFF section, so it may not have loaded the header
at the expected offset, as it is not covered by any PE/COFF section.
So instead, jump to 'stext' directly, which is at the base of the
PE/COFF .text section, by supplying a symbol 'stext_offset' to
efi-entry.o which contains the relative offset of stext into the Image.
Also replace other open coded calculations of the same value with a
reference to 'stext_offset'
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Roy Franz <roy.franz@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2014-10-08 18:11:27 +04:00
.globl stext_offset
.set stext_ o f f s e t , s t e x t - e f i _ h e a d
2014-04-16 06:47:52 +04:00
.align 3
pe_header :
.ascii " PE"
.short 0
coff_header :
.short 0xaa64 / / AArch6 4
.short 2 / / nr_ s e c t i o n s
.long 0 / / TimeDateStamp
.long 0 / / PointerToSymbolTable
.long 1 / / NumberOfSymbols
.short section_table - optional_ h e a d e r / / S i z e O f O p t i o n a l H e a d e r
.short 0x206 / / Characteristics.
/ / IMAGE_ F I L E _ D E B U G _ S T R I P P E D |
/ / IMAGE_ F I L E _ E X E C U T A B L E _ I M A G E |
/ / IMAGE_ F I L E _ L I N E _ N U M S _ S T R I P P E D
optional_header :
.short 0x20b / / PE3 2 + f o r m a t
.byte 0x02 / / MajorLinkerVersion
.byte 0x14 / / MinorLinkerVersion
2014-07-30 14:59:03 +04:00
.long _end - stext / / S i z e O f C o d e
2014-04-16 06:47:52 +04:00
.long 0 / / SizeOfInitializedData
.long 0 / / SizeOfUninitializedData
.long efi_stub_entry - efi_ h e a d / / A d d r e s s O f E n t r y P o i n t
arm64/efi: efistub: jump to 'stext' directly, not through the header
After the EFI stub has done its business, it jumps into the kernel by
branching to offset #0 of the loaded Image, which is where it expects
to find the header containing a 'branch to stext' instruction.
However, the UEFI spec 2.1.1 states the following regarding PE/COFF
image loading:
"A UEFI image is loaded into memory through the LoadImage() Boot
Service. This service loads an image with a PE32+ format into memory.
This PE32+ loader is required to load all sections of the PE32+ image
into memory."
In other words, it is /not/ required to load parts of the image that are
not covered by a PE/COFF section, so it may not have loaded the header
at the expected offset, as it is not covered by any PE/COFF section.
So instead, jump to 'stext' directly, which is at the base of the
PE/COFF .text section, by supplying a symbol 'stext_offset' to
efi-entry.o which contains the relative offset of stext into the Image.
Also replace other open coded calculations of the same value with a
reference to 'stext_offset'
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Roy Franz <roy.franz@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2014-10-08 18:11:27 +04:00
.long stext_offset / / BaseOfCode
2014-04-16 06:47:52 +04:00
extra_header_fields :
.quad 0 / / ImageBase
2014-10-10 13:25:24 +04:00
.long 0x1000 / / SectionAlignment
2014-10-10 20:42:55 +04:00
.long PECOFF_FILE_ALIGNMENT / / FileAlignment
2014-04-16 06:47:52 +04:00
.short 0 / / MajorOperatingSystemVersion
.short 0 / / MinorOperatingSystemVersion
.short 0 / / MajorImageVersion
.short 0 / / MinorImageVersion
.short 0 / / MajorSubsystemVersion
.short 0 / / MinorSubsystemVersion
.long 0 / / Win3 2 V e r s i o n V a l u e
2014-07-30 14:59:03 +04:00
.long _end - efi_ h e a d / / S i z e O f I m a g e
2014-04-16 06:47:52 +04:00
/ / Everything b e f o r e t h e k e r n e l i m a g e i s c o n s i d e r e d p a r t o f t h e h e a d e r
arm64/efi: efistub: jump to 'stext' directly, not through the header
After the EFI stub has done its business, it jumps into the kernel by
branching to offset #0 of the loaded Image, which is where it expects
to find the header containing a 'branch to stext' instruction.
However, the UEFI spec 2.1.1 states the following regarding PE/COFF
image loading:
"A UEFI image is loaded into memory through the LoadImage() Boot
Service. This service loads an image with a PE32+ format into memory.
This PE32+ loader is required to load all sections of the PE32+ image
into memory."
In other words, it is /not/ required to load parts of the image that are
not covered by a PE/COFF section, so it may not have loaded the header
at the expected offset, as it is not covered by any PE/COFF section.
So instead, jump to 'stext' directly, which is at the base of the
PE/COFF .text section, by supplying a symbol 'stext_offset' to
efi-entry.o which contains the relative offset of stext into the Image.
Also replace other open coded calculations of the same value with a
reference to 'stext_offset'
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Roy Franz <roy.franz@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2014-10-08 18:11:27 +04:00
.long stext_offset / / SizeOfHeaders
2014-04-16 06:47:52 +04:00
.long 0 / / CheckSum
.short 0xa / / Subsystem ( E F I a p p l i c a t i o n )
.short 0 / / DllCharacteristics
.quad 0 / / SizeOfStackReserve
.quad 0 / / SizeOfStackCommit
.quad 0 / / SizeOfHeapReserve
.quad 0 / / SizeOfHeapCommit
.long 0 / / LoaderFlags
.long 0x6 / / NumberOfRvaAndSizes
.quad 0 / / ExportTable
.quad 0 / / ImportTable
.quad 0 / / ResourceTable
.quad 0 / / ExceptionTable
.quad 0 / / CertificationTable
.quad 0 / / BaseRelocationTable
/ / Section t a b l e
section_table :
/ *
* The E F I a p p l i c a t i o n l o a d e r r e q u i r e s a r e l o c a t i o n s e c t i o n
* because E F I a p p l i c a t i o n s m u s t b e r e l o c a t a b l e . T h i s i s a
* dummy s e c t i o n a s f a r a s w e a r e c o n c e r n e d .
* /
.ascii " .reloc "
.byte 0
.byte 0 / / end o f 0 p a d d i n g o f s e c t i o n n a m e
.long 0
.long 0
.long 0 / / SizeOfRawData
.long 0 / / PointerToRawData
.long 0 / / PointerToRelocations
.long 0 / / PointerToLineNumbers
.short 0 / / NumberOfRelocations
.short 0 / / NumberOfLineNumbers
.long 0x42100040 / / Characteristics ( s e c t i o n f l a g s )
.ascii " .text "
.byte 0
.byte 0
.byte 0 / / end o f 0 p a d d i n g o f s e c t i o n n a m e
2014-07-30 14:59:03 +04:00
.long _end - stext / / V i r t u a l S i z e
arm64/efi: efistub: jump to 'stext' directly, not through the header
After the EFI stub has done its business, it jumps into the kernel by
branching to offset #0 of the loaded Image, which is where it expects
to find the header containing a 'branch to stext' instruction.
However, the UEFI spec 2.1.1 states the following regarding PE/COFF
image loading:
"A UEFI image is loaded into memory through the LoadImage() Boot
Service. This service loads an image with a PE32+ format into memory.
This PE32+ loader is required to load all sections of the PE32+ image
into memory."
In other words, it is /not/ required to load parts of the image that are
not covered by a PE/COFF section, so it may not have loaded the header
at the expected offset, as it is not covered by any PE/COFF section.
So instead, jump to 'stext' directly, which is at the base of the
PE/COFF .text section, by supplying a symbol 'stext_offset' to
efi-entry.o which contains the relative offset of stext into the Image.
Also replace other open coded calculations of the same value with a
reference to 'stext_offset'
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Roy Franz <roy.franz@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2014-10-08 18:11:27 +04:00
.long stext_offset / / VirtualAddress
2014-04-16 06:47:52 +04:00
.long _edata - stext / / S i z e O f R a w D a t a
arm64/efi: efistub: jump to 'stext' directly, not through the header
After the EFI stub has done its business, it jumps into the kernel by
branching to offset #0 of the loaded Image, which is where it expects
to find the header containing a 'branch to stext' instruction.
However, the UEFI spec 2.1.1 states the following regarding PE/COFF
image loading:
"A UEFI image is loaded into memory through the LoadImage() Boot
Service. This service loads an image with a PE32+ format into memory.
This PE32+ loader is required to load all sections of the PE32+ image
into memory."
In other words, it is /not/ required to load parts of the image that are
not covered by a PE/COFF section, so it may not have loaded the header
at the expected offset, as it is not covered by any PE/COFF section.
So instead, jump to 'stext' directly, which is at the base of the
PE/COFF .text section, by supplying a symbol 'stext_offset' to
efi-entry.o which contains the relative offset of stext into the Image.
Also replace other open coded calculations of the same value with a
reference to 'stext_offset'
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Roy Franz <roy.franz@linaro.org>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
2014-10-08 18:11:27 +04:00
.long stext_offset / / PointerToRawData
2014-04-16 06:47:52 +04:00
.long 0 / / PointerToRelocations ( 0 f o r e x e c u t a b l e s )
.long 0 / / PointerToLineNumbers ( 0 f o r e x e c u t a b l e s )
.short 0 / / NumberOfRelocations ( 0 f o r e x e c u t a b l e s )
.short 0 / / NumberOfLineNumbers ( 0 f o r e x e c u t a b l e s )
.long 0xe0500020 / / Characteristics ( s e c t i o n f l a g s )
2014-10-10 13:25:24 +04:00
/ *
* EFI w i l l l o a d s t e x t o n w a r d s a t t h e 4 k s e c t i o n a l i g n m e n t
* described i n t h e P E / C O F F h e a d e r . T o e n s u r e t h a t i n s t r u c t i o n
* sequences u s i n g a n a d r p a n d a : l o 1 2 : i m m e d i a t e w i l l f u n c t i o n
* correctly a t t h i s a l i g n m e n t , w e m u s t e n s u r e t h a t s t e x t i s
* placed a t a 4 k b o u n d a r y i n t h e I m a g e t o b e g i n w i t h .
* /
.align 12
2014-04-16 06:47:52 +04:00
# endif
2012-03-05 15:49:27 +04:00
ENTRY( s t e x t )
2015-03-17 12:55:12 +03:00
bl p r e s e r v e _ b o o t _ a r g s
2013-10-11 17:52:16 +04:00
bl e l 2 _ s e t u p / / D r o p t o E L 1 , w20 =cpu_boot_mode
2015-03-17 11:14:29 +03:00
adrp x24 , _ _ P H Y S _ O F F S E T
2013-10-11 17:52:16 +04:00
bl s e t _ c p u _ b o o t _ m o d e _ f l a g
2012-03-05 15:49:27 +04:00
bl _ _ c r e a t e _ p a g e _ t a b l e s / / x25 =TTBR0 , x26 =TTBR1
/ *
2015-03-18 17:55:20 +03:00
* The f o l l o w i n g c a l l s C P U s e t u p c o d e , s e e a r c h / a r m 6 4 / m m / p r o c . S f o r
* details.
2012-03-05 15:49:27 +04:00
* On r e t u r n , t h e C P U w i l l b e r e a d y f o r t h e M M U t o b e t u r n e d o n a n d
* the T C R w i l l h a v e b e e n s e t .
* /
2015-03-04 13:51:48 +03:00
ldr x27 , =__mmap_switched / / a d d r e s s t o j u m p t o a f t e r
2012-03-05 15:49:27 +04:00
/ / MMU h a s b e e n e n a b l e d
2015-03-17 10:59:53 +03:00
adr_ l l r , _ _ e n a b l e _ m m u / / r e t u r n ( P I C ) a d d r e s s
2015-03-18 17:55:20 +03:00
b _ _ c p u _ s e t u p / / i n i t i a l i s e p r o c e s s o r
2012-03-05 15:49:27 +04:00
ENDPROC( s t e x t )
2015-03-17 12:55:12 +03:00
/ *
* Preserve t h e a r g u m e n t s p a s s e d b y t h e b o o t l o a d e r i n x0 . . x3
* /
preserve_boot_args :
mov x21 , x0 / / x21 =FDT
adr_ l x0 , b o o t _ a r g s / / r e c o r d t h e c o n t e n t s o f
stp x21 , x1 , [ x0 ] / / x0 . . x3 a t k e r n e l e n t r y
stp x2 , x3 , [ x0 , #16 ]
dmb s y / / n e e d e d b e f o r e d c i v a c w i t h
/ / MMU o f f
add x1 , x0 , #0x20 / / 4 x 8 b y t e s
b _ _ i n v a l _ c a c h e _ r a n g e / / t a i l c a l l
ENDPROC( p r e s e r v e _ b o o t _ a r g s )
2014-11-22 00:50:41 +03:00
/ *
* Macro t o c r e a t e a t a b l e e n t r y t o t h e n e x t p a g e .
*
* tbl : page t a b l e a d d r e s s
* virt : virtual a d d r e s s
* shift : # imm p a g e t a b l e s h i f t
* ptrs : # imm p o i n t e r s p e r t a b l e p a g e
*
* Preserves : virt
* Corrupts : tmp1 , t m p2
* Returns : tbl - > n e x t l e v e l t a b l e p a g e a d d r e s s
* /
.macro create_ t a b l e _ e n t r y , t b l , v i r t , s h i f t , p t r s , t m p1 , t m p2
lsr \ t m p1 , \ v i r t , #\ s h i f t
and \ t m p1 , \ t m p1 , #\ p t r s - 1 / / t a b l e i n d e x
add \ t m p2 , \ t b l , #P A G E _ S I Z E
orr \ t m p2 , \ t m p2 , #P M D _ T Y P E _ T A B L E / / a d d r e s s o f n e x t t a b l e a n d e n t r y t y p e
str \ t m p2 , [ \ t b l , \ t m p1 , l s l #3 ]
add \ t b l , \ t b l , #P A G E _ S I Z E / / n e x t l e v e l t a b l e p a g e
.endm
/ *
* Macro t o p o p u l a t e t h e P G D ( a n d p o s s i b i l y P U D ) f o r t h e c o r r e s p o n d i n g
* block e n t r y i n t h e n e x t l e v e l ( t b l ) f o r t h e g i v e n v i r t u a l a d d r e s s .
*
* Preserves : tbl, n e x t , v i r t
* Corrupts : tmp1 , t m p2
* /
.macro create_ p g d _ e n t r y , t b l , v i r t , t m p1 , t m p2
create_ t a b l e _ e n t r y \ t b l , \ v i r t , P G D I R _ S H I F T , P T R S _ P E R _ P G D , \ t m p1 , \ t m p2
# if S W A P P E R _ P G T A B L E _ L E V E L S = = 3
create_ t a b l e _ e n t r y \ t b l , \ v i r t , T A B L E _ S H I F T , P T R S _ P E R _ P T E , \ t m p1 , \ t m p2
# endif
.endm
/ *
* Macro t o p o p u l a t e b l o c k e n t r i e s i n t h e p a g e t a b l e f o r t h e s t a r t . . e n d
* virtual r a n g e ( i n c l u s i v e ) .
*
* Preserves : tbl, f l a g s
* Corrupts : phys, s t a r t , e n d , p s t a t e
* /
.macro create_ b l o c k _ m a p , t b l , f l a g s , p h y s , s t a r t , e n d
lsr \ p h y s , \ p h y s , #B L O C K _ S H I F T
lsr \ s t a r t , \ s t a r t , #B L O C K _ S H I F T
and \ s t a r t , \ s t a r t , #P T R S _ P E R _ P T E - 1 / / t a b l e i n d e x
orr \ p h y s , \ f l a g s , \ p h y s , l s l #B L O C K _ S H I F T / / t a b l e e n t r y
lsr \ e n d , \ e n d , #B L O C K _ S H I F T
and \ e n d , \ e n d , #P T R S _ P E R _ P T E - 1 / / t a b l e e n d i n d e x
9999 : str \ p h y s , [ \ t b l , \ s t a r t , l s l #3 ] / / s t o r e t h e e n t r y
add \ s t a r t , \ s t a r t , #1 / / n e x t e n t r y
add \ p h y s , \ p h y s , #B L O C K _ S I Z E / / n e x t b l o c k
cmp \ s t a r t , \ e n d
b. l s 9 9 9 9 b
.endm
/ *
* Setup t h e i n i t i a l p a g e t a b l e s . W e o n l y s e t u p t h e b a r e s t a m o u n t w h i c h i s
* required t o g e t t h e k e r n e l r u n n i n g . T h e f o l l o w i n g s e c t i o n s a r e r e q u i r e d :
* - identity m a p p i n g t o e n a b l e t h e M M U ( l o w a d d r e s s , T T B R 0 )
* - first f e w M B o f t h e k e r n e l l i n e a r m a p p i n g t o j u m p t o o n c e t h e M M U h a s
2015-06-01 14:40:32 +03:00
* been e n a b l e d
2014-11-22 00:50:41 +03:00
* /
__create_page_tables :
2015-03-17 11:14:29 +03:00
adrp x25 , i d m a p _ p g _ d i r
adrp x26 , s w a p p e r _ p g _ d i r
2014-11-22 00:50:41 +03:00
mov x27 , l r
/ *
* Invalidate t h e i d m a p a n d s w a p p e r p a g e t a b l e s t o a v o i d p o t e n t i a l
* dirty c a c h e l i n e s b e i n g e v i c t e d .
* /
mov x0 , x25
add x1 , x26 , #S W A P P E R _ D I R _ S I Z E
bl _ _ i n v a l _ c a c h e _ r a n g e
/ *
* Clear t h e i d m a p a n d s w a p p e r p a g e t a b l e s .
* /
mov x0 , x25
add x6 , x26 , #S W A P P E R _ D I R _ S I Z E
1 : stp x z r , x z r , [ x0 ] , #16
stp x z r , x z r , [ x0 ] , #16
stp x z r , x z r , [ x0 ] , #16
stp x z r , x z r , [ x0 ] , #16
cmp x0 , x6
b. l o 1 b
ldr x7 , =MM_MMUFLAGS
/ *
* Create t h e i d e n t i t y m a p p i n g .
* /
mov x0 , x25 / / i d m a p _ p g _ d i r
2015-06-01 14:40:33 +03:00
adrp x3 , _ _ i d m a p _ t e x t _ s t a r t / / _ _ p a ( _ _ i d m a p _ t e x t _ s t a r t )
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
# ifndef C O N F I G _ A R M 6 4 _ V A _ B I T S _ 4 8
# define E X T R A _ S H I F T ( P G D I R _ S H I F T + P A G E _ S H I F T - 3 )
# define E X T R A _ P T R S ( 1 < < ( 4 8 - E X T R A _ S H I F T ) )
/ *
* If V A _ B I T S < 4 8 , i t m a y b e t o o s m a l l t o a l l o w f o r a n I D m a p p i n g t o b e
* created t h a t c o v e r s s y s t e m R A M i f t h a t i s l o c a t e d s u f f i c i e n t l y h i g h
* in t h e p h y s i c a l a d d r e s s s p a c e . S o f o r t h e I D m a p , u s e a n e x t e n d e d
* virtual r a n g e i n t h a t c a s e , b y c o n f i g u r i n g a n a d d i t i o n a l t r a n s l a t i o n
* level.
* First, w e h a v e t o v e r i f y o u r a s s u m p t i o n t h a t t h e c u r r e n t v a l u e o f
* VA_ B I T S w a s c h o s e n s u c h t h a t a l l t r a n s l a t i o n l e v e l s a r e f u l l y
* utilised, a n d t h a t l o w e r i n g T 0 S Z w i l l a l w a y s r e s u l t i n a n a d d i t i o n a l
* translation l e v e l t o b e c o n f i g u r e d .
* /
# if V A _ B I T S ! = E X T R A _ S H I F T
# error " M i s m a t c h b e t w e e n V A _ B I T S a n d p a g e s i z e / n u m b e r o f t r a n s l a t i o n l e v e l s "
# endif
/ *
* Calculate t h e m a x i m u m a l l o w e d v a l u e f o r T C R _ E L 1 . T 0 S Z s o t h a t t h e
2015-06-01 14:40:33 +03:00
* entire I D m a p r e g i o n c a n b e m a p p e d . A s T 0 S Z = = ( 6 4 - #b i t s u s e d ) ,
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
* this n u m b e r c o n v e n i e n t l y e q u a l s t h e n u m b e r o f l e a d i n g z e r o e s i n
2015-06-01 14:40:33 +03:00
* the p h y s i c a l a d d r e s s o f _ _ i d m a p _ t e x t _ e n d .
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
* /
2015-06-01 14:40:33 +03:00
adrp x5 , _ _ i d m a p _ t e x t _ e n d
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
clz x5 , x5
cmp x5 , T C R _ T 0 S Z ( V A _ B I T S ) / / d e f a u l t T 0 S Z s m a l l e n o u g h ?
b. g e 1 f / / . . t h e n s k i p a d d i t i o n a l l e v e l
2015-03-24 18:10:21 +03:00
adr_ l x6 , i d m a p _ t 0 s z
str x5 , [ x6 ]
dmb s y
dc i v a c , x6 / / I n v a l i d a t e p o t e n t i a l l y s t a l e c a c h e l i n e
arm64: mm: increase VA range of identity map
The page size and the number of translation levels, and hence the supported
virtual address range, are build-time configurables on arm64 whose optimal
values are use case dependent. However, in the current implementation, if
the system's RAM is located at a very high offset, the virtual address range
needs to reflect that merely because the identity mapping, which is only used
to enable or disable the MMU, requires the extended virtual range to map the
physical memory at an equal virtual offset.
This patch relaxes that requirement, by increasing the number of translation
levels for the identity mapping only, and only when actually needed, i.e.,
when system RAM's offset is found to be out of reach at runtime.
Tested-by: Laura Abbott <lauraa@codeaurora.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Tested-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2015-03-19 19:42:27 +03:00
create_ t a b l e _ e n t r y x0 , x3 , E X T R A _ S H I F T , E X T R A _ P T R S , x5 , x6
1 :
# endif
2014-11-22 00:50:41 +03:00
create_ p g d _ e n t r y x0 , x3 , x5 , x6
2015-06-01 14:40:33 +03:00
mov x5 , x3 / / _ _ p a ( _ _ i d m a p _ t e x t _ s t a r t )
adr_ l x6 , _ _ i d m a p _ t e x t _ e n d / / _ _ p a ( _ _ i d m a p _ t e x t _ e n d )
2014-11-22 00:50:41 +03:00
create_ b l o c k _ m a p x0 , x7 , x3 , x5 , x6
/ *
* Map t h e k e r n e l i m a g e ( s t a r t i n g w i t h P H Y S _ O F F S E T ) .
* /
mov x0 , x26 / / s w a p p e r _ p g _ d i r
mov x5 , #P A G E _ O F F S E T
create_ p g d _ e n t r y x0 , x5 , x3 , x6
2015-03-17 11:14:29 +03:00
ldr x6 , =KERNEL_END / / _ _ v a ( K E R N E L _ E N D )
2014-11-22 00:50:41 +03:00
mov x3 , x24 / / p h y s o f f s e t
create_ b l o c k _ m a p x0 , x7 , x3 , x5 , x6
/ *
* Since t h e p a g e t a b l e s h a v e b e e n p o p u l a t e d w i t h n o n - c a c h e a b l e
* accesses ( M M U d i s a b l e d ) , i n v a l i d a t e t h e i d m a p a n d s w a p p e r p a g e
* tables a g a i n t o r e m o v e a n y s p e c u l a t i v e l y l o a d e d c a c h e l i n e s .
* /
mov x0 , x25
add x1 , x26 , #S W A P P E R _ D I R _ S I Z E
2015-03-24 16:50:27 +03:00
dmb s y
2014-11-22 00:50:41 +03:00
bl _ _ i n v a l _ c a c h e _ r a n g e
mov l r , x27
ret
ENDPROC( _ _ c r e a t e _ p a g e _ t a b l e s )
.ltorg
/ *
2015-03-04 13:51:48 +03:00
* The f o l l o w i n g f r a g m e n t o f c o d e i s e x e c u t e d w i t h t h e M M U e n a b l e d .
2014-11-22 00:50:41 +03:00
* /
2015-03-04 13:51:48 +03:00
.set initial_ s p , i n i t _ t h r e a d _ u n i o n + T H R E A D _ S T A R T _ S P
2014-11-22 00:50:41 +03:00
__mmap_switched :
2015-03-04 13:51:48 +03:00
adr_ l x6 , _ _ b s s _ s t a r t
adr_ l x7 , _ _ b s s _ s t o p
2014-11-22 00:50:41 +03:00
1 : cmp x6 , x7
b. h s 2 f
str x z r , [ x6 ] , #8 / / C l e a r B S S
b 1 b
2 :
2015-03-04 13:51:48 +03:00
adr_ l s p , i n i t i a l _ s p , x4
str_ l x21 , _ _ f d t _ p o i n t e r , x5 / / S a v e F D T p o i n t e r
str_ l x24 , m e m s t a r t _ a d d r , x6 / / S a v e P H Y S _ O F F S E T
2014-11-22 00:50:41 +03:00
mov x29 , #0
b s t a r t _ k e r n e l
ENDPROC( _ _ m m a p _ s w i t c h e d )
/ *
* end e a r l y h e a d s e c t i o n , b e g i n h e a d c o d e t h a t i s a l s o u s e d f o r
* hotplug a n d n e e d s t o h a v e t h e s a m e p r o t e c t i o n s a s t h e t e x t r e g i o n
* /
.section " .text " , " ax"
2012-03-05 15:49:27 +04:00
/ *
* If w e ' r e f o r t u n a t e e n o u g h t o b o o t a t E L 2 , e n s u r e t h a t t h e w o r l d i s
* sane b e f o r e d r o p p i n g t o E L 1 .
2013-10-11 17:52:16 +04:00
*
* Returns e i t h e r B O O T _ C P U _ M O D E _ E L 1 o r B O O T _ C P U _ M O D E _ E L 2 i n x20 i f
* booted i n E L 1 o r E L 2 r e s p e c t i v e l y .
2012-03-05 15:49:27 +04:00
* /
ENTRY( e l 2 _ s e t u p )
mrs x0 , C u r r e n t E L
2014-06-06 17:16:21 +04:00
cmp x0 , #C u r r e n t E L _ E L 2
2013-10-11 17:52:17 +04:00
b. n e 1 f
mrs x0 , s c t l r _ e l 2
CPU_ B E ( o r r x0 , x0 , #( 1 < < 2 5 ) ) / / S e t t h e E E b i t f o r E L 2
CPU_ L E ( b i c x0 , x0 , #( 1 < < 2 5 ) ) / / C l e a r t h e E E b i t f o r E L 2
msr s c t l r _ e l 2 , x0
b 2 f
1 : mrs x0 , s c t l r _ e l 1
CPU_ B E ( o r r x0 , x0 , #( 3 < < 2 4 ) ) / / S e t t h e E E a n d E 0 E b i t s f o r E L 1
CPU_ L E ( b i c x0 , x0 , #( 3 < < 2 4 ) ) / / C l e a r t h e E E a n d E 0 E b i t s f o r E L 1
msr s c t l r _ e l 1 , x0
2013-10-11 17:52:16 +04:00
mov w20 , #B O O T _ C P U _ M O D E _ E L 1 / / T h i s c p u b o o t e d i n E L 1
2013-10-11 17:52:17 +04:00
isb
2012-03-05 15:49:27 +04:00
ret
/* Hyp configuration. */
2013-10-11 17:52:17 +04:00
2 : mov x0 , #( 1 < < 3 1 ) / / 6 4 - b i t E L 1
2012-03-05 15:49:27 +04:00
msr h c r _ e l 2 , x0
/* Generic timers. */
mrs x0 , c n t h c t l _ e l 2
orr x0 , x0 , #3 / / E n a b l e E L 1 p h y s i c a l t i m e r s
msr c n t h c t l _ e l 2 , x0
2012-11-30 02:48:31 +04:00
msr c n t v o f f _ e l 2 , x z r / / C l e a r v i r t u a l o f f s e t
2012-03-05 15:49:27 +04:00
2014-06-30 19:01:31 +04:00
# ifdef C O N F I G _ A R M _ G I C _ V 3
/* GICv3 system register access */
mrs x0 , i d _ a a64 p f r0 _ e l 1
ubfx x0 , x0 , #24 , #4
cmp x0 , #1
b. n e 3 f
2014-07-24 17:14:42 +04:00
mrs_ s x0 , I C C _ S R E _ E L 2
2014-06-30 19:01:31 +04:00
orr x0 , x0 , #I C C _ S R E _ E L 2 _ S R E / / S e t I C C _ S R E _ E L 2 . S R E = =1
orr x0 , x0 , #I C C _ S R E _ E L 2 _ E N A B L E / / S e t I C C _ S R E _ E L 2 . E n a b l e = =1
2014-07-24 17:14:42 +04:00
msr_ s I C C _ S R E _ E L 2 , x0
2014-06-30 19:01:31 +04:00
isb / / M a k e s u r e S R E i s n o w s e t
2014-07-24 17:14:42 +04:00
msr_ s I C H _ H C R _ E L 2 , x z r / / R e s e t I C C _ H C R _ E L 2 t o d e f a u l t s
2014-06-30 19:01:31 +04:00
3 :
# endif
2012-03-05 15:49:27 +04:00
/* Populate ID registers. */
mrs x0 , m i d r _ e l 1
mrs x1 , m p i d r _ e l 1
msr v p i d r _ e l 2 , x0
msr v m p i d r _ e l 2 , x1
/* sctlr_el1 */
mov x0 , #0x0800 / / S e t / c l e a r R E S { 1 ,0 } b i t s
2013-10-11 17:52:17 +04:00
CPU_ B E ( m o v k x0 , #0x33d0 , l s l #16 ) / / S e t E E a n d E 0 E o n B E s y s t e m s
CPU_ L E ( m o v k x0 , #0x30d0 , l s l #16 ) / / C l e a r E E a n d E 0 E o n L E s y s t e m s
2012-03-05 15:49:27 +04:00
msr s c t l r _ e l 1 , x0
/* Coprocessor traps. */
mov x0 , #0x33ff
msr c p t r _ e l 2 , x0 / / D i s a b l e c o p r o . t r a p s t o E L 2
# ifdef C O N F I G _ C O M P A T
msr h s t r _ e l 2 , x z r / / D i s a b l e C P 1 5 t r a p s t o E L 2
# endif
2012-11-06 23:27:59 +04:00
/* Stage-2 translation */
msr v t t b r _ e l 2 , x z r
2012-10-19 20:46:27 +04:00
/* Hypervisor stub */
2014-11-22 00:50:39 +03:00
adrp x0 , _ _ h y p _ s t u b _ v e c t o r s
add x0 , x0 , #: l o 12 : _ _ h y p _ s t u b _ v e c t o r s
2012-10-19 20:46:27 +04:00
msr v b a r _ e l 2 , x0
2012-03-05 15:49:27 +04:00
/* spsr */
mov x0 , #( P S R _ F _ B I T | P S R _ I _ B I T | P S R _ A _ B I T | P S R _ D _ B I T | \
PSR_ M O D E _ E L 1 h )
msr s p s r _ e l 2 , x0
msr e l r _ e l 2 , l r
2013-10-11 17:52:16 +04:00
mov w20 , #B O O T _ C P U _ M O D E _ E L 2 / / T h i s C P U b o o t e d i n E L 2
2012-03-05 15:49:27 +04:00
eret
ENDPROC( e l 2 _ s e t u p )
2013-10-11 17:52:16 +04:00
/ *
* Sets t h e _ _ b o o t _ c p u _ m o d e f l a g d e p e n d i n g o n t h e C P U b o o t m o d e p a s s e d
* in x20 . S e e a r c h / a r m 6 4 / i n c l u d e / a s m / v i r t . h f o r m o r e i n f o .
* /
ENTRY( s e t _ c p u _ b o o t _ m o d e _ f l a g )
2015-03-17 11:14:29 +03:00
adr_ l x1 , _ _ b o o t _ c p u _ m o d e
2013-10-11 17:52:16 +04:00
cmp w20 , #B O O T _ C P U _ M O D E _ E L 2
b. n e 1 f
add x1 , x1 , #4
2014-05-02 19:24:13 +04:00
1 : str w20 , [ x1 ] / / T h i s C P U h a s b o o t e d i n E L 1
dmb s y
dc i v a c , x1 / / I n v a l i d a t e p o t e n t i a l l y s t a l e c a c h e l i n e
2013-10-11 17:52:16 +04:00
ret
ENDPROC( s e t _ c p u _ b o o t _ m o d e _ f l a g )
2012-10-26 18:40:05 +04:00
/ *
* We n e e d t o f i n d o u t t h e C P U b o o t m o d e l o n g a f t e r b o o t , s o w e n e e d t o
* store i t i n a w r i t a b l e v a r i a b l e .
*
* This i s n o t i n . b s s , b e c a u s e w e s e t i t s u f f i c i e n t l y e a r l y t h a t t h e b o o t - t i m e
* zeroing o f . b s s w o u l d c l o b b e r i t .
* /
2014-03-26 22:25:55 +04:00
.pushsection .data . .cacheline_aligned
.align L1_CACHE_SHIFT
2015-03-13 18:21:18 +03:00
ENTRY( _ _ b o o t _ c p u _ m o d e )
2012-10-26 18:40:05 +04:00
.long BOOT_CPU_MODE_EL2
2015-03-13 19:14:36 +03:00
.long BOOT_CPU_MODE_EL1
2012-10-26 18:40:05 +04:00
.popsection
2012-03-05 15:49:27 +04:00
/ *
* This p r o v i d e s a " h o l d i n g p e n " f o r p l a t f o r m s t o h o l d a l l s e c o n d a r y
* cores a r e h e l d u n t i l w e ' r e r e a d y f o r t h e m t o i n i t i a l i s e .
* /
ENTRY( s e c o n d a r y _ h o l d i n g _ p e n )
2013-10-11 17:52:16 +04:00
bl e l 2 _ s e t u p / / D r o p t o E L 1 , w20 =cpu_boot_mode
bl s e t _ c p u _ b o o t _ m o d e _ f l a g
2012-03-05 15:49:27 +04:00
mrs x0 , m p i d r _ e l 1
2012-08-29 21:32:18 +04:00
ldr x1 , =MPIDR_HWID_BITMASK
and x0 , x0 , x1
2015-03-10 17:00:03 +03:00
adr_ l x3 , s e c o n d a r y _ h o l d i n g _ p e n _ r e l e a s e
2012-03-05 15:49:27 +04:00
pen : ldr x4 , [ x3 ]
cmp x4 , x0
b. e q s e c o n d a r y _ s t a r t u p
wfe
b p e n
ENDPROC( s e c o n d a r y _ h o l d i n g _ p e n )
arm64: factor out spin-table boot method
The arm64 kernel has an internal holding pen, which is necessary for
some systems where we can't bring CPUs online individually and must hold
multiple CPUs in a safe area until the kernel is able to handle them.
The current SMP infrastructure for arm64 is closely coupled to this
holding pen, and alternative boot methods must launch CPUs into the pen,
where they sit before they are launched into the kernel proper.
With PSCI (and possibly other future boot methods), we can bring CPUs
online individually, and need not perform the secondary_holding_pen
dance. Instead, this patch factors the holding pen management code out
to the spin-table boot method code, as it is the only boot method
requiring the pen.
A new entry point for secondaries, secondary_entry is added for other
boot methods to use, which bypasses the holding pen and its associated
overhead when bringing CPUs online. The smp.pen.text section is also
removed, as the pen can live in head.text without problem.
The cpu_operations structure is extended with two new functions,
cpu_boot and cpu_postboot, for bringing a cpu into the kernel and
performing any post-boot cleanup required by a bootmethod (e.g.
resetting the secondary_holding_pen_release to INVALID_HWID).
Documentation is added for cpu_operations.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2013-10-24 23:30:16 +04:00
/ *
* Secondary e n t r y p o i n t t h a t j u m p s s t r a i g h t i n t o t h e k e r n e l . O n l y t o
* be u s e d w h e r e C P U s a r e b r o u g h t o n l i n e d y n a m i c a l l y b y t h e k e r n e l .
* /
ENTRY( s e c o n d a r y _ e n t r y )
bl e l 2 _ s e t u p / / D r o p t o E L 1
2013-11-18 22:56:42 +04:00
bl s e t _ c p u _ b o o t _ m o d e _ f l a g
arm64: factor out spin-table boot method
The arm64 kernel has an internal holding pen, which is necessary for
some systems where we can't bring CPUs online individually and must hold
multiple CPUs in a safe area until the kernel is able to handle them.
The current SMP infrastructure for arm64 is closely coupled to this
holding pen, and alternative boot methods must launch CPUs into the pen,
where they sit before they are launched into the kernel proper.
With PSCI (and possibly other future boot methods), we can bring CPUs
online individually, and need not perform the secondary_holding_pen
dance. Instead, this patch factors the holding pen management code out
to the spin-table boot method code, as it is the only boot method
requiring the pen.
A new entry point for secondaries, secondary_entry is added for other
boot methods to use, which bypasses the holding pen and its associated
overhead when bringing CPUs online. The smp.pen.text section is also
removed, as the pen can live in head.text without problem.
The cpu_operations structure is extended with two new functions,
cpu_boot and cpu_postboot, for bringing a cpu into the kernel and
performing any post-boot cleanup required by a bootmethod (e.g.
resetting the secondary_holding_pen_release to INVALID_HWID).
Documentation is added for cpu_operations.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
2013-10-24 23:30:16 +04:00
b s e c o n d a r y _ s t a r t u p
ENDPROC( s e c o n d a r y _ e n t r y )
2012-03-05 15:49:27 +04:00
ENTRY( s e c o n d a r y _ s t a r t u p )
/ *
* Common e n t r y p o i n t f o r s e c o n d a r y C P U s .
* /
2015-03-17 11:14:29 +03:00
adrp x25 , i d m a p _ p g _ d i r
adrp x26 , s w a p p e r _ p g _ d i r
2015-03-18 17:55:20 +03:00
bl _ _ c p u _ s e t u p / / i n i t i a l i s e p r o c e s s o r
2012-03-05 15:49:27 +04:00
ldr x21 , =secondary_data
ldr x27 , =__secondary_switched / / a d d r e s s t o j u m p t o a f t e r e n a b l i n g t h e M M U
b _ _ e n a b l e _ m m u
ENDPROC( s e c o n d a r y _ s t a r t u p )
ENTRY( _ _ s e c o n d a r y _ s w i t c h e d )
ldr x0 , [ x21 ] / / g e t s e c o n d a r y _ d a t a . s t a c k
mov s p , x0
mov x29 , #0
b s e c o n d a r y _ s t a r t _ k e r n e l
ENDPROC( _ _ s e c o n d a r y _ s w i t c h e d )
/ *
2015-03-17 10:59:53 +03:00
* Enable t h e M M U .
2012-03-05 15:49:27 +04:00
*
2015-03-17 10:59:53 +03:00
* x0 = S C T L R _ E L 1 v a l u e f o r t u r n i n g o n t h e M M U .
* x2 7 = * v i r t u a l * a d d r e s s t o j u m p t o u p o n c o m p l e t i o n
*
* other r e g i s t e r s d e p e n d o n t h e f u n c t i o n c a l l e d u p o n c o m p l e t i o n
2012-03-05 15:49:27 +04:00
* /
2015-06-01 14:40:33 +03:00
.section " .idmap .text " , " ax"
2012-03-05 15:49:27 +04:00
__enable_mmu :
ldr x5 , =vectors
msr v b a r _ e l 1 , x5
msr t t b r0 _ e l 1 , x25 / / l o a d T T B R 0
msr t t b r1 _ e l 1 , x26 / / l o a d T T B R 1
isb
msr s c t l r _ e l 1 , x0
isb
2015-08-04 19:49:36 +03:00
/ *
* Invalidate t h e l o c a l I - c a c h e s o t h a t a n y i n s t r u c t i o n s f e t c h e d
* speculatively f r o m t h e P o C a r e d i s c a r d e d , s i n c e t h e y m a y h a v e
* been d y n a m i c a l l y p a t c h e d a t t h e P o U .
* /
ic i a l l u
dsb n s h
isb
2012-03-05 15:49:27 +04:00
br x27
2015-03-17 10:59:53 +03:00
ENDPROC( _ _ e n a b l e _ m m u )