airoha: copy 5.15 files to 6.1
[openwrt/staging/stintel.git] / target / linux / airoha / patches-6.1 / 0004-ARM-9124-1-uncompress-Parse-linux-usable-memory-rang.patch
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
5 property
6
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
12 memory.
13
14 For backwards compatibility, the traditional method to derive the start
15 of memory is still used if "linux,usable-memory-range" is absent.
16
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>
20 ---
21 .../arm/boot/compressed/fdt_check_mem_start.c | 48 ++++++++++++++++---
22 1 file changed, 42 insertions(+), 6 deletions(-)
23
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.
33 *
34 * Return value: start address of physical memory to use
35 */
36 uint32_t fdt_check_mem_start(uint32_t mem_start, const void *fdt)
37 {
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;
42 - uint64_t size, end;
43 + const fdt32_t *usable, *reg, *endp;
44 + uint64_t size, usable_end, end;
45 const char *type;
46 int offset, len;
47
48 @@ -80,6 +81,27 @@ uint32_t fdt_check_mem_start(uint32_t me
49 if (addr_cells > 2 || size_cells > 2)
50 return mem_start;
51
52 + /*
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
56 + */
57 + usable = get_prop(fdt, "/chosen", "linux,usable-memory-range",
58 + (addr_cells + size_cells) * sizeof(fdt32_t));
59 + if (usable) {
60 + size = get_val(usable + addr_cells, size_cells);
61 + if (!size)
62 + return mem_start;
63 +
64 + if (addr_cells > 1 && fdt32_ld(usable)) {
65 + /* Outside 32-bit address space */
66 + return mem_start;
67 + }
68 +
69 + usable_base = fdt32_ld(usable + addr_cells - 1);
70 + usable_end = usable_base + size;
71 + }
72 +
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
77
78 base = fdt32_ld(reg + addr_cells - 1);
79 end = base + size;
80 - if (mem_start >= base && mem_start < end) {
81 + if (usable) {
82 + /*
83 + * Clip to usable range, which takes precedence
84 + * over mem_start
85 + */
86 + if (base < usable_base)
87 + base = usable_base;
88 +
89 + if (end > usable_end)
90 + end = usable_end;
91 +
92 + if (end <= base)
93 + continue;
94 + } else if (mem_start >= base && mem_start < end) {
95 /* Calculated address is valid, use it */
96 return mem_start;
97 }
98 @@ -123,7 +158,8 @@ uint32_t fdt_check_mem_start(uint32_t me
99 }
100
101 /*
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.
107 */