Index: fdt_memory.c =================================================================== RCS file: /cvsroot/src/sys/dev/fdt/fdt_memory.c,v retrieving revision 1.8 diff -p -u -r1.8 fdt_memory.c --- fdt_memory.c 4 Nov 2022 10:51:16 -0000 1.8 +++ fdt_memory.c 31 Dec 2023 13:03:36 -0000 @@ -77,26 +77,43 @@ fdt_memory_range_free(struct fdt_memory_ void fdt_memory_get(uint64_t *pstart, uint64_t *pend) { - const int memory = OF_finddevice("/memory"); + const void *fdt_data = fdtbus_get_data(); uint64_t cur_addr, cur_size; - int index, nadd; + int index, nadd = 0, off, memory; - for (index = 0, nadd = 0; - fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0; - index++) { - if (cur_size == 0) - continue; - fdt_memory_add_range(cur_addr, cur_size); + off = fdt_node_offset_by_prop_value(fdt_data, -1, + "device_type", "memory", sizeof("memory")); - if (nadd++ == 0) { - *pstart = cur_addr; - *pend = cur_addr + cur_size; - continue; + /* + * Device Tree Specification 3.2 says that memory + * nodes are named "memory" and have device_type + * "memory", but if the device_type is missing, try + * to find the (then single) node by name. + */ + if (off == -FDT_ERR_NOTFOUND) + off = fdt_path_offset(fdt_data, "/memory"); + + while (off != -FDT_ERR_NOTFOUND) { + memory = fdtbus_offset2phandle(off); + for (index = 0; + fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0; + index++) { + if (cur_size == 0) + continue; + fdt_memory_add_range(cur_addr, cur_size); + + if (nadd++ == 0) { + *pstart = cur_addr; + *pend = cur_addr + cur_size; + continue; + } + if (cur_addr < *pstart) + *pstart = cur_addr; + if (cur_addr + cur_size > *pend) + *pend = cur_addr + cur_size; } - if (cur_addr < *pstart) - *pstart = cur_addr; - if (cur_addr + cur_size > *pend) - *pend = cur_addr + cur_size; + off = fdt_node_offset_by_prop_value(fdt_data, off, + "device_type", "memory", sizeof("memory")); } if (nadd == 0) panic("Cannot determine memory size");