Skip to content

Commit 7a1be31

Browse files
ardbiesheuvelRussell King
authored andcommitted
ARM: 9012/1: move device tree mapping out of linear region
On ARM, setting up the linear region is tricky, given the constraints around placement and alignment of the memblocks, and how the kernel itself as well as the DT are placed in physical memory. Let's simplify matters a bit, by moving the device tree mapping to the top of the address space, right between the end of the vmalloc region and the start of the the fixmap region, and create a read-only mapping for it that is independent of the size of the linear region, and how it is organized. Since this region was formerly used as a guard region, which will now be populated fully on LPAE builds by this read-only mapping (which will still be able to function as a guard region for stray writes), bump the start of the [underutilized] fixmap region by 512 KB as well, to ensure that there is always a proper guard region here. Doing so still leaves ample room for the fixmap space, even with NR_CPUS set to its maximum value of 32. Tested-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent e9a2f8b commit 7a1be31

8 files changed

Lines changed: 38 additions & 17 deletions

File tree

‎Documentation/arm/memory.rst‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,14 @@ fffe8000 fffeffff DTCM mapping area for platforms with
4545
fffe0000 fffe7fff ITCM mapping area for platforms with
4646
ITCM mounted inside the CPU.
4747

48-
ffc00000 ffefffff Fixmap mapping region. Addresses provided
48+
ffc80000 ffefffff Fixmap mapping region. Addresses provided
4949
by fix_to_virt() will be located here.
5050

51+
ffc00000 ffc7ffff Guard region
52+
53+
ff800000 ffbfffff Permanent, fixed read-only mapping of the
54+
firmware provided DT blob
55+
5156
fee00000 feffffff Mapping of PCI I/O space. This is a static
5257
mapping within the vmalloc space.
5358

‎arch/arm/include/asm/fixmap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#ifndef _ASM_FIXMAP_H
33
#define _ASM_FIXMAP_H
44

5-
#define FIXADDR_START 0xffc00000UL
5+
#define FIXADDR_START 0xffc80000UL
66
#define FIXADDR_END 0xfff00000UL
77
#define FIXADDR_TOP (FIXADDR_END - PAGE_SIZE)
88

‎arch/arm/include/asm/memory.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
*/
6868
#define XIP_VIRT_ADDR(physaddr) (MODULES_VADDR + ((physaddr) & 0x000fffff))
6969

70+
#define FDT_FIXED_BASE UL(0xff800000)
71+
#define FDT_FIXED_SIZE (2 * PMD_SIZE)
72+
#define FDT_VIRT_ADDR(physaddr) ((void *)(FDT_FIXED_BASE | (physaddr) % PMD_SIZE))
73+
7074
#if !defined(CONFIG_SMP) && !defined(CONFIG_ARM_LPAE)
7175
/*
7276
* Allow 16MB-aligned ioremap pages
@@ -107,6 +111,7 @@ extern unsigned long vectors_base;
107111
#define MODULES_VADDR PAGE_OFFSET
108112

109113
#define XIP_VIRT_ADDR(physaddr) (physaddr)
114+
#define FDT_VIRT_ADDR(physaddr) ((void *)(physaddr))
110115

111116
#endif /* !CONFIG_MMU */
112117

‎arch/arm/kernel/head.S‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,8 @@ __create_page_tables:
275275
*/
276276
mov r0, r2, lsr #SECTION_SHIFT
277277
movs r0, r0, lsl #SECTION_SHIFT
278-
subne r3, r0, r8
279-
addne r3, r3, #PAGE_OFFSET
280-
addne r3, r4, r3, lsr #(SECTION_SHIFT - PMD_ORDER)
278+
ldrne r3, =FDT_FIXED_BASE >> (SECTION_SHIFT - PMD_ORDER)
279+
addne r3, r3, r4
281280
orrne r6, r7, r0
282281
strne r6, [r3], #1 << PMD_ORDER
283282
addne r6, r6, #1 << SECTION_SHIFT

‎arch/arm/kernel/setup.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/of_platform.h>
1919
#include <linux/init.h>
2020
#include <linux/kexec.h>
21+
#include <linux/libfdt.h>
2122
#include <linux/of_fdt.h>
2223
#include <linux/cpu.h>
2324
#include <linux/interrupt.h>
@@ -89,7 +90,6 @@ unsigned int cacheid __read_mostly;
8990
EXPORT_SYMBOL(cacheid);
9091

9192
unsigned int __atags_pointer __initdata;
92-
void *atags_vaddr __initdata;
9393

9494
unsigned int system_rev;
9595
EXPORT_SYMBOL(system_rev);
@@ -1083,13 +1083,18 @@ void __init hyp_mode_check(void)
10831083
void __init setup_arch(char **cmdline_p)
10841084
{
10851085
const struct machine_desc *mdesc = NULL;
1086+
void *atags_vaddr = NULL;
10861087

10871088
if (__atags_pointer)
1088-
atags_vaddr = phys_to_virt(__atags_pointer);
1089+
atags_vaddr = FDT_VIRT_ADDR(__atags_pointer);
10891090

10901091
setup_processor();
1091-
if (atags_vaddr)
1092+
if (atags_vaddr) {
10921093
mdesc = setup_machine_fdt(atags_vaddr);
1094+
if (mdesc)
1095+
memblock_reserve(__atags_pointer,
1096+
fdt_totalsize(atags_vaddr));
1097+
}
10931098
if (!mdesc)
10941099
mdesc = setup_machine_tags(atags_vaddr, __machine_arch_type);
10951100
if (!mdesc) {

‎arch/arm/mm/init.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ void __init arm_memblock_init(const struct machine_desc *mdesc)
223223
if (mdesc->reserve)
224224
mdesc->reserve();
225225

226-
early_init_fdt_reserve_self();
227226
early_init_fdt_scan_reserved_mem();
228227

229228
/* reserve memory for DMA contiguous allocations */

‎arch/arm/mm/mmu.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "mm.h"
4040
#include "tcm.h"
4141

42+
extern unsigned long __atags_pointer;
43+
4244
/*
4345
* empty_zero_page is a special page that is used for
4446
* zero-initialized data and COW.
@@ -946,7 +948,7 @@ static void __init create_mapping(struct map_desc *md)
946948
return;
947949
}
948950

949-
if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
951+
if (md->type == MT_DEVICE &&
950952
md->virtual >= PAGE_OFFSET && md->virtual < FIXADDR_START &&
951953
(md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
952954
pr_warn("BUG: mapping for 0x%08llx at 0x%08lx out of vmalloc space\n",
@@ -1333,6 +1335,15 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
13331335
for (addr = VMALLOC_START; addr < (FIXADDR_TOP & PMD_MASK); addr += PMD_SIZE)
13341336
pmd_clear(pmd_off_k(addr));
13351337

1338+
if (__atags_pointer) {
1339+
/* create a read-only mapping of the device tree */
1340+
map.pfn = __phys_to_pfn(__atags_pointer & SECTION_MASK);
1341+
map.virtual = FDT_FIXED_BASE;
1342+
map.length = FDT_FIXED_SIZE;
1343+
map.type = MT_ROM;
1344+
create_mapping(&map);
1345+
}
1346+
13361347
/*
13371348
* Map the kernel if it is XIP.
13381349
* It is always first in the modulearea.
@@ -1489,8 +1500,7 @@ static void __init map_lowmem(void)
14891500
}
14901501

14911502
#ifdef CONFIG_ARM_PV_FIXUP
1492-
extern void *atags_vaddr;
1493-
typedef void pgtables_remap(long long offset, unsigned long pgd, void *bdata);
1503+
typedef void pgtables_remap(long long offset, unsigned long pgd);
14941504
pgtables_remap lpae_pgtables_remap_asm;
14951505

14961506
/*
@@ -1503,7 +1513,6 @@ static void __init early_paging_init(const struct machine_desc *mdesc)
15031513
unsigned long pa_pgd;
15041514
unsigned int cr, ttbcr;
15051515
long long offset;
1506-
void *boot_data;
15071516

15081517
if (!mdesc->pv_fixup)
15091518
return;
@@ -1520,7 +1529,6 @@ static void __init early_paging_init(const struct machine_desc *mdesc)
15201529
*/
15211530
lpae_pgtables_remap = (pgtables_remap *)(unsigned long)__pa(lpae_pgtables_remap_asm);
15221531
pa_pgd = __pa(swapper_pg_dir);
1523-
boot_data = atags_vaddr;
15241532
barrier();
15251533

15261534
pr_info("Switching physical address space to 0x%08llx\n",
@@ -1556,7 +1564,7 @@ static void __init early_paging_init(const struct machine_desc *mdesc)
15561564
* needs to be assembly. It's fairly simple, as we're using the
15571565
* temporary tables setup by the initial assembly code.
15581566
*/
1559-
lpae_pgtables_remap(offset, pa_pgd, boot_data);
1567+
lpae_pgtables_remap(offset, pa_pgd);
15601568

15611569
/* Re-enable the caches and cacheable TLB walks */
15621570
asm volatile("mcr p15, 0, %0, c2, c0, 2" : : "r" (ttbcr));

‎arch/arm/mm/pv-fixup-asm.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ ENTRY(lpae_pgtables_remap_asm)
3939

4040
/* Update level 2 entries for the boot data */
4141
add r7, r2, #0x1000
42-
add r7, r7, r3, lsr #SECTION_SHIFT - L2_ORDER
43-
bic r7, r7, #(1 << L2_ORDER) - 1
42+
movw r3, #FDT_FIXED_BASE >> (SECTION_SHIFT - L2_ORDER)
43+
add r7, r7, r3
4444
ldrd r4, r5, [r7]
4545
adds r4, r4, r0
4646
adc r5, r5, r1

0 commit comments

Comments
 (0)