Use L2 blocks when in the identity map

This reduces the memory mapped to be closer to the minimal memory
needed to enable the MMU.

Reviewed by:	mmel
Sponsored by:	Innovate UK
Differential Revision:://reviews.freebsd.org/D27765
This commit is contained in:
Andrew Turner 2020-12-24 11:02:34 +00:00
parent c8db60c067
commit 48ba9b2669
3 changed files with 49 additions and 61 deletions

View File

@ -466,35 +466,58 @@ common:
add x27, x24, #PAGE_SIZE
mov x6, x27 /* The initial page table */
#if defined(SOCDEV_PA) && defined(SOCDEV_VA)
/* Create the VA = PA map */
mov x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK))
adrp x16, _start
and x16, x16, #(~L2_OFFSET)
mov x9, x16 /* PA start */
mov x8, x16 /* VA start (== PA start) */
mov x10, #1
bl build_l2_block_pagetable
#if defined(SOCDEV_PA)
/* Create a table for the UART */
mov x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_DEVICE))
mov x8, #(SOCDEV_VA) /* VA start */
mov x9, #(SOCDEV_PA) /* PA start */
add x16, x16, #(L2_SIZE) /* VA start */
mov x8, x16
/* Store the socdev virtual address */
add x17, x8, #(SOCDEV_PA & L2_OFFSET)
adrp x9, socdev_va
str x17, [x9, :lo12:socdev_va]
mov x9, #(SOCDEV_PA & ~L2_OFFSET) /* PA start */
mov x10, #1
bl build_l1_block_pagetable
bl build_l2_block_pagetable
#endif
#if defined(LINUX_BOOT_ABI)
/* Map FDT data ? */
cbz x19, 1f
/* Create the identity mapping for FDT data (2 MiB max) */
/* Create the mapping for FDT data (2 MiB max) */
mov x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK))
mov x9, x0
mov x8, x0 /* VA start (== PA start) */
add x16, x16, #(L2_SIZE) /* VA start */
mov x8, x16
mov x9, x0 /* PA start */
/* Update the module pointer to point at the allocated memory */
and x0, x0, #(L2_OFFSET) /* Keep the lower bits */
add x0, x0, x8 /* Add the aligned virtual address */
mov x10, #1
bl build_l1_block_pagetable
bl build_l2_block_pagetable
1:
#endif
/* Create the VA = PA map */
mov x7, #(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK))
mov x9, x28
mov x8, x9 /* VA start (== PA start) */
mov x10, #1
bl build_l1_block_pagetable
/* Move to the l1 table */
add x27, x27, #PAGE_SIZE
/* Link the l1 -> l2 table */
mov x9, x6
mov x6, x27
bl link_l1_pagetable
/* Move to the l0 table */
add x27, x27, #PAGE_SIZE
@ -513,13 +536,10 @@ LEND(create_pagetables)
/*
* Builds an L0 -> L1 table descriptor
*
* This is a link for a 512GiB block of memory with up to 1GiB regions mapped
* within it by build_l1_block_pagetable.
*
* x6 = L0 table
* x8 = Virtual Address
* x9 = L1 PA (trashed)
* x10 = Entry count
* x10 = Entry count (trashed)
* x11, x12 and x13 are trashed
*/
LENTRY(link_l0_pagetable)
@ -551,9 +571,6 @@ LEND(link_l0_pagetable)
/*
* Builds an L1 -> L2 table descriptor
*
* This is a link for a 1GiB block of memory with up to 2MiB regions mapped
* within it by build_l2_block_pagetable.
*
* x6 = L1 table
* x8 = Virtual Address
* x9 = L2 PA (trashed)
@ -580,51 +597,13 @@ LENTRY(link_l1_pagetable)
ret
LEND(link_l1_pagetable)
/*
* Builds count 1 GiB page table entry
* x6 = L1 table
* x7 = Variable lower block attributes
* x8 = VA start
* x9 = PA start (trashed)
* x10 = Entry count
* x11, x12 and x13 are trashed
*/
LENTRY(build_l1_block_pagetable)
/*
* Build the L1 table entry.
*/
/* Find the table index */
lsr x11, x8, #L1_SHIFT
and x11, x11, #Ln_ADDR_MASK
/* Build the L1 block entry */
orr x12, x7, #L1_BLOCK
orr x12, x12, #(ATTR_DEFAULT)
/* Only use the output address bits */
lsr x9, x9, #L1_SHIFT
/* Set the physical address for this virtual address */
1: orr x13, x12, x9, lsl #L1_SHIFT
/* Store the entry */
str x13, [x6, x11, lsl #3]
sub x10, x10, #1
add x11, x11, #1
add x9, x9, #1
cbnz x10, 1b
ret
LEND(build_l1_block_pagetable)
/*
* Builds count 2 MiB page table entry
* x6 = L2 table
* x7 = Type (0 = Device, 1 = Normal)
* x8 = VA start
* x9 = PA start (trashed)
* x10 = Entry count
* x10 = Entry count (trashed)
* x11, x12 and x13 are trashed
*/
LENTRY(build_l2_block_pagetable)
@ -778,6 +757,8 @@ pagetable_l1_ttbr1:
.space PAGE_SIZE
pagetable_l0_ttbr1:
.space PAGE_SIZE
pagetable_l2_ttbr0_bootstrap:
.space PAGE_SIZE
pagetable_l1_ttbr0_bootstrap:
.space PAGE_SIZE
pagetable_l0_ttbr0_boostrap:

View File

@ -60,6 +60,14 @@ void parse_fdt_bootargs(void);
int memory_mapping_mode(vm_paddr_t pa);
extern void (*pagezero)(void *);
#ifdef SOCDEV_PA
/*
* The virtual address SOCDEV_PA is mapped at.
* Only valid while the early pagetables are valid.
*/
extern uintptr_t socdev_va;
#endif
#endif /* _KERNEL */
#endif /* _MACHINE_MACHDEP_H_ */

View File

@ -3,7 +3,6 @@
ARM64 opt_global.h
INTRNG opt_global.h
SOCDEV_PA opt_global.h
SOCDEV_VA opt_global.h
THUNDERX_PASS_1_1_ERRATA opt_global.h
VFP opt_global.h
LINUX_BOOT_ABI opt_global.h