git: 8d5b63efd19c - main - dev/fdt: Add fdt_foreach_reserved_mem
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 08 Apr 2025 10:49:09 UTC
The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=8d5b63efd19c9395eb9519145be4ba02406dc9b3 commit 8d5b63efd19c9395eb9519145be4ba02406dc9b3 Author: Andrew Turner <andrew@FreeBSD.org> AuthorDate: 2025-04-08 10:30:17 +0000 Commit: Andrew Turner <andrew@FreeBSD.org> CommitDate: 2025-04-08 10:48:28 +0000 dev/fdt: Add fdt_foreach_reserved_mem As with fdt_foreach_mem_region add a function that calls a callback for each reserved memory region. This allows us to exclude this memory from the physical map in a way that is safe from overflowing a fixed array on the stack. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D49698 --- sys/dev/fdt/fdt_common.c | 38 ++++++++++++++++++++++++++++++++++++++ sys/dev/fdt/fdt_common.h | 1 + 2 files changed, 39 insertions(+) diff --git a/sys/dev/fdt/fdt_common.c b/sys/dev/fdt/fdt_common.c index 6c505ac2cd7c..e23878750bea 100644 --- a/sys/dev/fdt/fdt_common.c +++ b/sys/dev/fdt/fdt_common.c @@ -499,6 +499,44 @@ out: return (rv); } +int +fdt_foreach_reserved_mem(fdt_mem_region_cb cb, void *arg) +{ + struct mem_region mr; + pcell_t reg[FDT_REG_CELLS]; + phandle_t child, root; + int addr_cells, size_cells; + int rv; + + root = OF_finddevice("/reserved-memory"); + if (root == -1) + return (ENXIO); + + if ((rv = fdt_addrsize_cells(root, &addr_cells, &size_cells)) != 0) + return (rv); + + if (addr_cells + size_cells > FDT_REG_CELLS) + panic("Too many address and size cells %d %d", addr_cells, + size_cells); + + for (child = OF_child(root); child != 0; child = OF_peer(child)) { + if (!OF_hasprop(child, "no-map")) + continue; + + rv = OF_getprop(child, "reg", reg, sizeof(reg)); + if (rv <= 0) + /* XXX: Does a no-map of a dynamic range make sense? */ + continue; + + fdt_data_to_res(reg, addr_cells, size_cells, + (u_long *)&mr.mr_start, (u_long *)&mr.mr_size); + + cb(&mr, arg); + } + + return (0); +} + int fdt_get_reserved_mem(struct mem_region *reserved, int *mreserved) { diff --git a/sys/dev/fdt/fdt_common.h b/sys/dev/fdt/fdt_common.h index f450d976dfe0..d1db7c0620fd 100644 --- a/sys/dev/fdt/fdt_common.h +++ b/sys/dev/fdt/fdt_common.h @@ -85,6 +85,7 @@ phandle_t fdt_find_compatible(phandle_t, const char *, int); phandle_t fdt_depth_search_compatible(phandle_t, const char *, int); int fdt_foreach_mem_region(fdt_mem_region_cb, void *); int fdt_get_mem_regions(struct mem_region *, int *, uint64_t *); +int fdt_foreach_reserved_mem(fdt_mem_region_cb, void *); int fdt_get_reserved_mem(struct mem_region *, int *); int fdt_get_reserved_regions(struct mem_region *, int *); int fdt_get_phyaddr(phandle_t, device_t, int *, void **);