blob: f4ea89c609cbea2964106c8b54b071ab062a0928 [file] [log] [blame]
Andrew Geissler9347dd42023-03-03 12:38:41 -06001From f4704146e1af9f6e0a2220db6b39a328c813fac1 Mon Sep 17 00:00:00 2001
Brad Bishopbec4ebc2022-08-03 09:55:16 -04002From: Jaxson Han <jaxson.han@arm.com>
3Date: Wed, 19 Jan 2022 16:19:02 +0800
4Subject: [PATCH] common: Add mem usage to /memreserve/
5
6Set /memreserve/ to prevent next boot stages from overrding PSCI
7services with libfdt.
8
9Issue-Id: SCM-3815
10Upstream-Status: Inappropriate [other]
11 Implementation pending further discussion
12Signed-off-by: Jaxson Han <jaxson.han@arm.com>
13Change-Id: I2ea80cdf736a910fa2c3deb622e21d50f04be960
14---
15 Makefile.am | 2 +-
16 common/boot.c | 1 +
17 common/device_tree.c | 34 ++++++++++++++++++++++++++++++++++
18 include/boot.h | 1 +
19 4 files changed, 37 insertions(+), 1 deletion(-)
20 create mode 100644 common/device_tree.c
21
22diff --git a/Makefile.am b/Makefile.am
Andrew Geissler9347dd42023-03-03 12:38:41 -060023index ab2c3a9..e905602 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040024--- a/Makefile.am
25+++ b/Makefile.am
26@@ -34,7 +34,7 @@ endif
27 PSCI_CPU_OFF := 0x84000002
28
29 COMMON_SRC := common/
30-COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o
31+COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o device_tree.o
32
33 LIBFDT_SRC := common/libfdt/
34 LIBFDT_OBJS := fdt.o fdt_ro.o fdt_rw.o
35diff --git a/common/boot.c b/common/boot.c
36index c74d34c..ee2bea0 100644
37--- a/common/boot.c
38+++ b/common/boot.c
39@@ -63,6 +63,7 @@ void __noreturn first_spin(unsigned int cpu, unsigned long *mbox,
40 {
41 if (cpu == 0) {
42 init_platform();
43+ dt_add_memreserve();
44
45 *mbox = (unsigned long)&entrypoint;
46 sevl();
47diff --git a/common/device_tree.c b/common/device_tree.c
48new file mode 100644
49index 0000000..4d0876c
50--- /dev/null
51+++ b/common/device_tree.c
52@@ -0,0 +1,34 @@
53+/*
54+ * device_tree.c - Basic device tree node handler
55+ *
56+ * Copyright (C) 2021 ARM Limited. All rights reserved.
57+ *
58+ * Use of this source code is governed by a BSD-style license that can be
59+ * found in the LICENSE.txt file.
60+ */
61+#include <libfdt.h>
62+
63+extern unsigned long dtb;
64+extern char firmware_start[], firmware_end[];
65+
66+extern void print_string(const char *str);
67+
68+static void *blob;
69+
70+
71+void dt_add_memreserve(void)
72+{
73+ int ret;
74+
75+ blob = (void*)&dtb;
76+ print_string("Add /memreserve/\n\r");
77+
78+ fdt_open_into(blob, blob, fdt_totalsize(blob) +
79+ sizeof(struct fdt_reserve_entry));
80+ ret = fdt_add_mem_rsv(blob, (uint64_t)firmware_start,
81+ (uint64_t)(firmware_end - firmware_start));
82+
83+ if(ret < 0) {
84+ print_string("reserve mem add err\n\r");
85+ }
86+}
87diff --git a/include/boot.h b/include/boot.h
88index d75e013..c3e2ec1 100644
89--- a/include/boot.h
90+++ b/include/boot.h
91@@ -16,4 +16,5 @@ void __noreturn spin(unsigned long *mbox, unsigned long invalid, int is_entry);
92 void __noreturn first_spin(unsigned int cpu, unsigned long *mbox,
93 unsigned long invalid_addr);
94
95+void dt_add_memreserve(void);
96 #endif