diff options
author | Alper Nebi Yasak <alpernebiyasak@gmail.com> | 2024-02-05 17:31:20 +0300 |
---|---|---|
committer | Lean Sheng Tan <sheng.tan@9elements.com> | 2024-06-03 15:38:55 +0000 |
commit | 377157c7fba0c68e2b5d273066713caa5af95f80 (patch) | |
tree | 16c13da3b0fc036ed27a027cf0c4a079ae7c3699 /src/include/device_tree.h | |
parent | eed791e8510662a87de756ff0fb68349b2822a96 (diff) |
device_tree: Add function to get top of memory from a FDT blob
coreboot needs to figure out top of memory to place CBMEM data. On some
non-x86 QEMU virtual machines, this is achieved by probing the RAM space
to find where the VM starts discarding data since it's not backed by
actual RAM. This behaviour seems to have changed on the QEMU side since
then, VMs using the "virt" model have started raising exceptions/errors
instead of silently discarding data (likely [1] for example) which has
previously broken coreboot on these emulation boards.
The qemu-aarch64 and qemu-riscv mainboards are intended for the "virt"
models and had this issue, which were mostly fixed by using exception
handlers in the RAM detection process [2][3]. But on 32-bit RISC-V we
fail to initialize CBMEM if we have 2048 MiB or more of RAM, and on
64-bit RISC-V we had to limit probing to 16383 MiB because it can run
into MMIO regions otherwise.
The qemu-armv7 mainboard code is intended for the "vexpress-a9" model VM
which doesn't appear to suffer from this issue. Still, the issue can be
observed on the ARMv7 "virt" model via a port based on qemu-aarch64.
QEMU docs for ARM and RISC-V "virt" models [4][5] recommend reading the
device tree blob it provides for device information (incl. RAM size).
Implement functions that parse the device tree blob to find described
memory regions and calculate the top of memory in order to use it in
mainboard code as an alternative to probing RAM space. ARM64 code
initializes CBMEM in romstage where malloc isn't available, so take care
to do parsing without unflattening the blob and make the code available
in romstage as well.
[1] https://lore.kernel.org/qemu-devel/1504626814-23124-1-git-send-email-peter.maydell@linaro.org/T/#u
[2] https://review.coreboot.org/c/coreboot/+/34774
[3] https://review.coreboot.org/c/coreboot/+/36486
[4] https://qemu-project.gitlab.io/qemu/system/arm/virt.html
[5] https://qemu-project.gitlab.io/qemu/system/riscv/virt.html
Change-Id: I8bef09bc1bc4e324ebeaa37f78d67d3aa315f52c
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/80322
Reviewed-by: Maximilian Brune <maximilian.brune@9elements.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/include/device_tree.h')
-rw-r--r-- | src/include/device_tree.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/include/device_tree.h b/src/include/device_tree.h index 6d2d65600f..bb522bf1da 100644 --- a/src/include/device_tree.h +++ b/src/include/device_tree.h @@ -129,6 +129,12 @@ u32 fdt_find_node_by_alias(const void *blob, const char *alias_name, */ int fdt_next_node_name(const void *blob, uint32_t node_offset, const char **name); + /* Read memory regions from a flat device-tree. */ +size_t fdt_read_memory_regions(const void *blob, struct device_tree_region regions[], + size_t regions_count); + /* Find top of memory from a flat device-tree. */ +uint64_t fdt_get_memory_top(const void *blob); + /* Read a flattened device tree into a hierarchical structure which refers to the contents of the flattened tree in place. Modifying the flat tree invalidates the unflattened one. */ |