1 From 48342ae751c797ac73ac9c894b3f312df18ffd21 Mon Sep 17 00:00:00 2001
2 From: Geert Uytterhoeven <geert+renesas@glider.be>
3 Date: Wed, 15 Sep 2021 13:46:20 +0100
4 Subject: [PATCH] ARM: 9124/1: uncompress: Parse "linux,usable-memory-range" DT
7 Add support for parsing the "linux,usable-memory-range" DT property.
8 This property is used to describe the usable memory reserved for the
9 crash dump kernel, and thus makes the memory reservation explicit.
10 If present, Linux no longer needs to mask the program counter, and rely
11 on the "mem=" kernel parameter to obtain the start and size of usable
14 For backwards compatibility, the traditional method to derive the start
15 of memory is still used if "linux,usable-memory-range" is absent.
17 Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
18 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
19 Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com>
21 .../arm/boot/compressed/fdt_check_mem_start.c | 48 ++++++++++++++++---
22 1 file changed, 42 insertions(+), 6 deletions(-)
24 --- a/arch/arm/boot/compressed/fdt_check_mem_start.c
25 +++ b/arch/arm/boot/compressed/fdt_check_mem_start.c
26 @@ -55,16 +55,17 @@ static uint64_t get_val(const fdt32_t *c
27 * DTB, and, if out-of-range, replace it by the real start address.
28 * To preserve backwards compatibility (systems reserving a block of memory
29 * at the start of physical memory, kdump, ...), the traditional method is
30 - * always used if it yields a valid address.
31 + * used if it yields a valid address, unless the "linux,usable-memory-range"
32 + * property is present.
34 * Return value: start address of physical memory to use
36 uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
38 - uint32_t addr_cells, size_cells, base;
39 + uint32_t addr_cells, size_cells, usable_base, base;
40 uint32_t fdt_mem_start = 0xffffffff;
41 - const fdt32_t *reg, *endp;
43 + const fdt32_t *usable, *reg, *endp;
44 + uint64_t size, usable_end, end;
48 @@ -80,6 +81,27 @@ uint32_t fdt_check_mem_start(uint32_t me
49 if (addr_cells > 2 || size_cells > 2)
53 + * Usable memory in case of a crash dump kernel
54 + * This property describes a limitation: memory within this range is
55 + * only valid when also described through another mechanism
57 + usable = get_prop(fdt, "/chosen", "linux,usable-memory-range",
58 + (addr_cells + size_cells) * sizeof(fdt32_t));
60 + size = get_val(usable + addr_cells, size_cells);
64 + if (addr_cells > 1 && fdt32_ld(usable)) {
65 + /* Outside 32-bit address space */
69 + usable_base = fdt32_ld(usable + addr_cells - 1);
70 + usable_end = usable_base + size;
73 /* Walk all memory nodes and regions */
74 for (offset = fdt_next_node(fdt, -1, NULL); offset >= 0;
75 offset = fdt_next_node(fdt, offset, NULL)) {
76 @@ -107,7 +129,20 @@ uint32_t fdt_check_mem_start(uint32_t me
78 base = fdt32_ld(reg + addr_cells - 1);
80 - if (mem_start >= base && mem_start < end) {
83 + * Clip to usable range, which takes precedence
86 + if (base < usable_base)
89 + if (end > usable_end)
94 + } else if (mem_start >= base && mem_start < end) {
95 /* Calculated address is valid, use it */
98 @@ -123,7 +158,8 @@ uint32_t fdt_check_mem_start(uint32_t me
102 - * The calculated address is not usable.
103 + * The calculated address is not usable, or was overridden by the
104 + * "linux,usable-memory-range" property.
105 * Use the lowest usable physical memory address from the DTB instead,
106 * and make sure this is a multiple of 2 MiB for phys/virt patching.