From: dlg Date: Wed, 21 Feb 2024 01:45:14 +0000 (+0000) Subject: handle /reserved-memory nodes from device trees on arm64. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=aa73d72211f4de3e5cdb187d5df3bc58db0783b0;p=openbsd handle /reserved-memory nodes from device trees on arm64. u-boot is supposed to take these entries and put them in the efi memory map, but i keep hitting machines where an otherwise functional u-boot does not do this, resulting in weird errors. i have an espressobin with a vendor u-boot that has a reserved-memory region for psci. without this diff the machine faults when the kernel tries to reboot using a psci handler. a macchiatobin with an otherwise working u-boot throws SErrors or panics on weird memory corruption problems without this. i thought it was bad RAM, but the problems persisted with completely different ram, and very underclocked and well cooled ram. riscv64 already has code to handle reserved-memory regions. the riscv64 change is to add handling for the "no-map" property. ok kettenis@ --- diff --git a/sys/arch/arm64/arm64/machdep.c b/sys/arch/arm64/arm64/machdep.c index 69dc76ae9d2..fc1df710f67 100644 --- a/sys/arch/arm64/arm64/machdep.c +++ b/sys/arch/arm64/arm64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.85 2023/12/04 15:00:09 claudio Exp $ */ +/* $OpenBSD: machdep.c,v 1.86 2024/02/21 01:45:14 dlg Exp $ */ /* * Copyright (c) 2014 Patrick Wildt * Copyright (c) 2021 Mark Kettenis @@ -1053,6 +1053,22 @@ initarm(struct arm64_bootparams *abp) } } + /* Remove reserved memory. */ + node = fdt_find_node("/reserved-memory"); + if (node) { + for (node = fdt_child_node(node); node; + node = fdt_next_node(node)) { + char *no_map; + if (fdt_node_property(node, "no-map", &no_map) < 0) + continue; + if (fdt_get_reg(node, 0, ®)) + continue; + if (reg.size == 0) + continue; + memreg_remove(®); + } + } + /* Remove the initial 64MB block. */ reg.addr = memstart; reg.size = memend - memstart; diff --git a/sys/arch/riscv64/riscv64/machdep.c b/sys/arch/riscv64/riscv64/machdep.c index 7658ba0df54..1141cd27786 100644 --- a/sys/arch/riscv64/riscv64/machdep.c +++ b/sys/arch/riscv64/riscv64/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.34 2024/01/23 19:51:10 kettenis Exp $ */ +/* $OpenBSD: machdep.c,v 1.35 2024/02/21 01:45:14 dlg Exp $ */ /* * Copyright (c) 2014 Patrick Wildt @@ -792,6 +792,9 @@ initriscv(struct riscv_bootparams *rbp) if (node) { for (node = fdt_child_node(node); node; node = fdt_next_node(node)) { + char *no_map; + if (fdt_node_property(node, "no-map", &no_map) < 0) + continue; if (fdt_get_reg(node, 0, ®)) continue; if (reg.size == 0)