From ab0ef2922eefcf3744fcc57b8b73de8dd01b6f9b Mon Sep 17 00:00:00 2001 From: Hector Martin Date: Fri, 8 Sep 2023 00:02:55 +0900 Subject: [PATCH] kboot: Use adt_segment_ranges struct instead of open-coding Signed-off-by: Hector Martin --- src/adt.h | 9 +++++++++ src/kboot.c | 19 +++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/adt.h b/src/adt.h index 6373c868..5f717978 100644 --- a/src/adt.h +++ b/src/adt.h @@ -106,4 +106,13 @@ bool adt_is_compatible(const void *adt, int nodeoffset, const char *compat); for (const struct adt_property *prop = ADT_PROP(adt, _poff); _prop_count--; \ prop = ADT_PROP(adt, _poff = adt_next_property_offset(adt, _poff))) +/* Common ADT properties */ +struct adt_segment_ranges { + u64 phys; + u64 iova; + u64 remap; + u32 size; + u32 unk; +} PACKED; + #endif diff --git a/src/kboot.c b/src/kboot.c index 74524b08..5f055297 100644 --- a/src/kboot.c +++ b/src/kboot.c @@ -1541,33 +1541,32 @@ static int dt_reserve_asc_firmware(const char *adt_path, const char *fdt_path) bail("FDT: couldn't set '%s.phandle' property: %d\n", fdt_path, ret); } - const uint64_t *segments; + const struct adt_segment_ranges *seg; u32 segments_len; - segments = adt_getprop(adt, node, "segment-ranges", &segments_len); - unsigned int num_maps = segments_len / 32; + seg = adt_getprop(adt, node, "segment-ranges", &segments_len); + unsigned int num_maps = segments_len / sizeof(*seg); for (unsigned i = 0; i < num_maps; i++) { - u64 paddr = segments[0]; - u64 iova = segments[2]; - u32 size = segments[3]; - segments += 4; + u64 iova = seg->iova; char node_name[64]; - snprintf(node_name, sizeof(node_name), "asc-firmware@%lx", paddr); + snprintf(node_name, sizeof(node_name), "asc-firmware@%lx", seg->phys); - int mem_node = dt_get_or_add_reserved_mem(node_name, "apple,asc-mem", paddr, size); + int mem_node = dt_get_or_add_reserved_mem(node_name, "apple,asc-mem", seg->phys, seg->size); if (mem_node < 0) return ret; uint32_t mem_phandle = fdt_get_phandle(dt, mem_node); - ret = dt_device_set_reserved_mem(mem_node, node_name, dev_phandle, iova, size); + ret = dt_device_set_reserved_mem(mem_node, node_name, dev_phandle, iova, seg->size); if (ret < 0) return ret; ret = dt_device_add_mem_region(fdt_path, mem_phandle, NULL); if (ret < 0) return ret; + + seg++; } return 0;