git: 02ecd34fde77 - main - sys: Use fdt_foreach on arm, arm64, and riscv
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 08 Apr 2025 10:49:11 UTC
The branch main has been updated by andrew:
URL: https://cgit.FreeBSD.org/src/commit/?id=02ecd34fde778dd5d73bd3ba3de24aa853734ac9
commit 02ecd34fde778dd5d73bd3ba3de24aa853734ac9
Author: Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2025-04-08 10:30:33 +0000
Commit: Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2025-04-08 10:48:28 +0000
sys: Use fdt_foreach on arm, arm64, and riscv
This means we can remove the fixed mem_regions array.
Reviewed by: imp
Sponsored by: Arm Ltd
Differential Revision: https://reviews.freebsd.org/D49700
---
sys/arm/arm/machdep.c | 26 +++++++++++++------
sys/arm64/arm64/machdep.c | 24 ++++++++++++------
sys/riscv/riscv/machdep.c | 63 ++++++++++++++++++++++++++++++-----------------
3 files changed, 76 insertions(+), 37 deletions(-)
diff --git a/sys/arm/arm/machdep.c b/sys/arm/arm/machdep.c
index 31f888313d59..7db5a6f9bcdd 100644
--- a/sys/arm/arm/machdep.c
+++ b/sys/arm/arm/machdep.c
@@ -415,14 +415,26 @@ arm_kdb_init(void)
}
#ifdef FDT
+static void
+fdt_physmem_hardware_region_cb(const struct mem_region *mr, void *arg __unused)
+{
+ physmem_hardware_region(mr->mr_start, mr->mr_size);
+}
+
+static void
+fdt_physmem_exclude_region_cb(const struct mem_region *mr, void *arg __unused)
+{
+ physmem_exclude_region(mr->mr_start, mr->mr_size,
+ EXFLAG_NODUMP | EXFLAG_NOALLOC);
+}
+
void *
initarm(struct arm_boot_params *abp)
{
- struct mem_region mem_regions[FDT_MEM_REGIONS];
vm_paddr_t lastaddr;
vm_offset_t dtbp, kernelstack, dpcpu;
char *env;
- int err_devmap, mem_regions_sz;
+ int err_devmap;
phandle_t root;
char dts_version[255];
#ifdef EFI
@@ -469,15 +481,13 @@ initarm(struct arm_boot_params *abp)
#endif
{
/* Grab physical memory regions information from device tree. */
- if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,NULL) != 0)
+ if (fdt_foreach_mem_region(fdt_physmem_hardware_region_cb,
+ NULL) != 0)
panic("Cannot get physical memory regions");
- physmem_hardware_regions(mem_regions, mem_regions_sz);
-
/* Grab reserved memory regions information from device tree. */
- if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
- physmem_exclude_regions(mem_regions, mem_regions_sz,
- EXFLAG_NODUMP | EXFLAG_NOALLOC);
+ fdt_foreach_reserved_region(fdt_physmem_exclude_region_cb,
+ NULL);
}
/*
diff --git a/sys/arm64/arm64/machdep.c b/sys/arm64/arm64/machdep.c
index 93343a1972af..6184ce937b8a 100644
--- a/sys/arm64/arm64/machdep.c
+++ b/sys/arm64/arm64/machdep.c
@@ -722,6 +722,21 @@ memory_mapping_mode(vm_paddr_t pa)
return (VM_MEMATTR_DEVICE);
}
+#ifdef FDT
+static void
+fdt_physmem_hardware_region_cb(const struct mem_region *mr, void *arg __unused)
+{
+ physmem_hardware_region(mr->mr_start, mr->mr_size);
+}
+
+static void
+fdt_physmem_exclude_region_cb(const struct mem_region *mr, void *arg __unused)
+{
+ physmem_exclude_region(mr->mr_start, mr->mr_size,
+ EXFLAG_NODUMP | EXFLAG_NOALLOC);
+}
+#endif
+
void
initarm(struct arm64_bootparams *abp)
{
@@ -729,8 +744,6 @@ initarm(struct arm64_bootparams *abp)
struct pcpu *pcpup;
char *env;
#ifdef FDT
- struct mem_region mem_regions[FDT_MEM_REGIONS];
- int mem_regions_sz;
phandle_t root;
char dts_version[255];
#endif
@@ -781,14 +794,11 @@ initarm(struct arm64_bootparams *abp)
#ifdef FDT
else {
/* Grab physical memory regions information from device tree. */
- if (fdt_get_mem_regions(mem_regions, &mem_regions_sz,
+ if (fdt_foreach_mem_region(fdt_physmem_hardware_region_cb,
NULL) != 0)
panic("Cannot get physical memory regions");
- physmem_hardware_regions(mem_regions, mem_regions_sz);
}
- if (fdt_get_reserved_mem(mem_regions, &mem_regions_sz) == 0)
- physmem_exclude_regions(mem_regions, mem_regions_sz,
- EXFLAG_NODUMP | EXFLAG_NOALLOC);
+ fdt_foreach_reserved_mem(fdt_physmem_exclude_region_cb, NULL);
#endif
/* Exclude the EFI framebuffer from our view of physical memory. */
diff --git a/sys/riscv/riscv/machdep.c b/sys/riscv/riscv/machdep.c
index fea4ca9a7b92..516dbde5ffaa 100644
--- a/sys/riscv/riscv/machdep.c
+++ b/sys/riscv/riscv/machdep.c
@@ -506,13 +506,46 @@ parse_metadata(void)
return (lastaddr);
}
+#ifdef FDT
+static void
+fdt_physmem_hardware_region_cb(const struct mem_region *mr, void *arg)
+{
+ bool *first = arg;
+
+ physmem_hardware_region(mr->mr_start, mr->mr_size);
+
+ if (*first) {
+ /*
+ * XXX: Unconditionally exclude the lowest 2MB of physical
+ * memory, as this area is assumed to contain the SBI firmware,
+ * and this is not properly reserved in all cases (e.g. in
+ * older firmware like BBL).
+ *
+ * This is a little fragile, but it is consistent with the
+ * platforms we support so far.
+ *
+ * TODO: remove this when the all regular booting methods
+ * properly report their reserved memory in the device tree.
+ */
+ physmem_exclude_region(mr->mr_start, L2_SIZE,
+ EXFLAG_NODUMP | EXFLAG_NOALLOC);
+ *first = false;
+ }
+}
+
+static void
+fdt_physmem_exclude_region_cb(const struct mem_region *mr, void *arg __unused)
+{
+ physmem_exclude_region(mr->mr_start, mr->mr_size,
+ EXFLAG_NODUMP | EXFLAG_NOALLOC);
+}
+#endif
+
void
initriscv(struct riscv_bootparams *rvbp)
{
- struct mem_region mem_regions[FDT_MEM_REGIONS];
struct efi_map_header *efihdr;
struct pcpu *pcpup;
- int mem_regions_sz;
vm_offset_t lastaddr;
vm_size_t kernlen;
char *env;
@@ -547,31 +580,17 @@ initriscv(struct riscv_bootparams *rvbp)
}
#ifdef FDT
else {
+ bool first;
+
/* Exclude reserved memory specified by the device tree. */
- if (fdt_get_reserved_mem(mem_regions, &mem_regions_sz) == 0) {
- physmem_exclude_regions(mem_regions, mem_regions_sz,
- EXFLAG_NODUMP | EXFLAG_NOALLOC);
- }
+ fdt_foreach_reserved_mem(fdt_physmem_exclude_region_cb, NULL);
/* Grab physical memory regions information from device tree. */
- if (fdt_get_mem_regions(mem_regions, &mem_regions_sz, NULL) != 0)
+ first = true;
+ if (fdt_foreach_mem_region(fdt_physmem_hardware_region_cb,
+ &first) != 0)
panic("Cannot get physical memory regions");
- physmem_hardware_regions(mem_regions, mem_regions_sz);
- /*
- * XXX: Unconditionally exclude the lowest 2MB of physical
- * memory, as this area is assumed to contain the SBI firmware,
- * and this is not properly reserved in all cases (e.g. in
- * older firmware like BBL).
- *
- * This is a little fragile, but it is consistent with the
- * platforms we support so far.
- *
- * TODO: remove this when the all regular booting methods
- * properly report their reserved memory in the device tree.
- */
- physmem_exclude_region(mem_regions[0].mr_start, L2_SIZE,
- EXFLAG_NODUMP | EXFLAG_NOALLOC);
}
#endif