From: Inochi Amaoto <inochiama@gmail.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 2/2] platform: introduce DT-based configurable heap size
Date: Mon, 16 Sep 2024 15:25:15 +0800 [thread overview]
Message-ID: <20240916072516.628461-2-inochiama@gmail.com> (raw)
In-Reply-To: <20240916072405.628158-1-inochiama@gmail.com>
The default heap size will work for most platforms, but for some
special platforms, the heap is too small to hold all the information
or is too big so that it take too much ram. Introduce configurable
heap should solve this problem and make all generic platforms happy.
Add DT-based heap-size for the generic platform.
Signed-off-by: Inochi Amaoto <inochiama@gmail.com>
---
docs/opensbi_config.md | 4 ++++
platform/generic/platform.c | 28 +++++++++++++++++++++++++---
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/docs/opensbi_config.md b/docs/opensbi_config.md
index 1b710f1..c620379 100644
--- a/docs/opensbi_config.md
+++ b/docs/opensbi_config.md
@@ -23,6 +23,9 @@ The DT properties of a domain configuration DT node are as follows:
set of harts is permitted to perform a cold boot. Otherwise, all
harts are allowed to cold boot.
+* **heap-size** (Optional) - When present, the SBI will initialize
+ the heap with the set value (This value is in byte).
+
* **system-suspend-test** (Optional) - When present, enable a system
suspend test implementation which simply waits five seconds and issues a WFI.
@@ -36,6 +39,7 @@ The OpenSBI Configuration Node will be deleted at the end of cold boot
opensbi-config {
compatible = "opensbi,config";
cold-boot-harts = <&cpu1 &cpu2 &cpu3 &cpu4>;
+ heap-size = <0x400000>;
system-suspend-test;
};
};
diff --git a/platform/generic/platform.c b/platform/generic/platform.c
index 49d877d..c8e988e 100644
--- a/platform/generic/platform.c
+++ b/platform/generic/platform.c
@@ -69,6 +69,28 @@ static u32 fw_platform_calculate_heap_size(u32 hart_count)
return BIT_ALIGN(heap_size, HEAP_BASE_ALIGN);
}
+static u32 fw_platform_get_heap_size(const void *fdt, u32 hart_count)
+{
+ int chosen_offset, config_offset, len;
+ const fdt32_t *val;
+
+ /* Get the heap size from device tree */
+ chosen_offset = fdt_path_offset(fdt, "/chosen");
+ if (chosen_offset < 0)
+ goto default_config;
+
+ config_offset = fdt_node_offset_by_compatible(fdt, chosen_offset, "opensbi,config");
+ if (config_offset < 0)
+ goto default_config;
+
+ val = (fdt32_t *)fdt_getprop(fdt, config_offset, "heap-size", &len);
+ if (len > 0 && val)
+ return fdt32_to_cpu(*val);
+
+default_config:
+ return fw_platform_calculate_heap_size(hart_count);
+}
+
extern struct sbi_platform platform;
static bool platform_has_mlevel_imsic = false;
static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 };
@@ -76,9 +98,9 @@ static u32 generic_hart_index2id[SBI_HARTMASK_MAX_BITS] = { 0 };
static DECLARE_BITMAP(generic_coldboot_harts, SBI_HARTMASK_MAX_BITS);
/*
- * The fw_platform_coldboot_harts_init() function is called by fw_platform_init()
+ * The fw_platform_coldboot_harts_init() function is called by fw_platform_init()
* function to initialize the cold boot harts allowed by the generic platform
- * according to the DT property "cold-boot-harts" in "/chosen/opensbi-config"
+ * according to the DT property "cold-boot-harts" in "/chosen/opensbi-config"
* DT node. If there is no "cold-boot-harts" in DT, all harts will be allowed.
*/
static void fw_platform_coldboot_harts_init(const void *fdt)
@@ -185,7 +207,7 @@ unsigned long fw_platform_init(unsigned long arg0, unsigned long arg1,
}
platform.hart_count = hart_count;
- platform.heap_size = fw_platform_calculate_heap_size(hart_count);
+ platform.heap_size = fw_platform_get_heap_size(fdt, hart_count);
platform_has_mlevel_imsic = fdt_check_imsic_mlevel(fdt);
fw_platform_coldboot_harts_init(fdt);
--
2.46.1
next prev parent reply other threads:[~2024-09-16 7:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-16 7:24 [PATCH 0/2] platform: improve heap size handle Inochi Amaoto
2024-09-16 7:25 ` [PATCH 1/2] platform: ensure enough heap size with debug triggers extension Inochi Amaoto
2024-09-20 5:33 ` Xiang W
2024-09-16 7:25 ` Inochi Amaoto [this message]
2024-09-20 5:33 ` [PATCH 2/2] platform: introduce DT-based configurable heap size Xiang W
2024-09-20 7:40 ` Inochi Amaoto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240916072516.628461-2-inochiama@gmail.com \
--to=inochiama@gmail.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox