From c884d3112276503d0f37134fba286544e9da69b2 Mon Sep 17 00:00:00 2001 From: Nathan Whitehorn Date: Fri, 16 Jan 2015 18:47:20 +0000 Subject: [PATCH] Add two fake properties ("fdtbootcpu" and "fdtmemreserv") to the device tree's /chosen node to provide out-of-band header fields of the FDT. This emulation is not perfect without corresponding changes to ofw_fdt_nextprop(), but is enough to enable lookup by memory-map-parsing code. MFC after: 1 week --- sys/dev/ofw/ofw_fdt.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sys/dev/ofw/ofw_fdt.c b/sys/dev/ofw/ofw_fdt.c index f4072a322ea2..01f82c46fb96 100644 --- a/sys/dev/ofw/ofw_fdt.c +++ b/sys/dev/ofw/ofw_fdt.c @@ -231,6 +231,13 @@ ofw_fdt_getproplen(ofw_t ofw, phandle_t package, const char *propname) return (len + 1); } + if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) { + if (strcmp(propname, "fdtbootcpu") == 0) + return (sizeof(cell_t)); + if (strcmp(propname, "fdtmemreserv") == 0) + return (sizeof(uint64_t)*2*fdt_num_mem_rsv(fdtp)); + } + return (len); } @@ -242,6 +249,7 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf, const void *prop; const char *name; int len, offset; + uint32_t cpuid; offset = fdt_phandle_offset(package); if (offset < 0) @@ -258,6 +266,18 @@ ofw_fdt_getprop(ofw_t ofw, phandle_t package, const char *propname, void *buf, return (len + 1); } + if (prop == NULL && offset == fdt_path_offset(fdtp, "/chosen")) { + if (strcmp(propname, "fdtbootcpu") == 0) { + cpuid = cpu_to_fdt32(fdt_boot_cpuid_phys(fdtp)); + len = sizeof(cpuid); + prop = &cpuid; + } + if (strcmp(propname, "fdtmemreserv") == 0) { + prop = (char *)fdtp + fdt_off_mem_rsvmap(fdtp); + len = sizeof(uint64_t)*2*fdt_num_mem_rsv(fdtp); + } + } + if (prop == NULL) return (-1);