diff options
-rw-r--r-- | riscv/dts.cc | 38 | ||||
-rw-r--r-- | riscv/dts.h | 5 |
2 files changed, 43 insertions, 0 deletions
diff --git a/riscv/dts.cc b/riscv/dts.cc index 56b76e6..9469e3f 100644 --- a/riscv/dts.cc +++ b/riscv/dts.cc @@ -225,6 +225,21 @@ static int fdt_get_node_addr_size(void *fdt, int node, reg_t *addr, return 0; } +int fdt_get_offset(void *fdt, const char *field) +{ + return fdt_path_offset(fdt, field); +} + +int fdt_get_first_subnode(void *fdt, int node) +{ + return fdt_first_subnode(fdt, node); +} + +int fdt_get_next_subnode(void *fdt, int node) +{ + return fdt_next_subnode(fdt, node); +} + int fdt_parse_clint(void *fdt, reg_t *clint_addr, const char *compatible) { @@ -273,3 +288,26 @@ int fdt_parse_pmp_alignment(void *fdt, reg_t *pmp_align, return 0; } + +int fdt_parse_mmu_type(void *fdt, int cpu_offset, char *mmu_type) +{ + int len; + const void *prop; + + if (!fdt || cpu_offset < 0) + return -EINVAL; + + prop = fdt_getprop(fdt, cpu_offset, "device_type", &len); + if (!prop || !len) + return -EINVAL; + if (strncmp ((char *)prop, "cpu", strlen ("cpu"))) + return -EINVAL; + + prop = fdt_getprop(fdt, cpu_offset, "mmu-type", &len); + if (!prop || !len) + return -EINVAL; + + strcpy(mmu_type, (char *)prop); + + return 0; +} diff --git a/riscv/dts.h b/riscv/dts.h index 1f01e0f..69dcb31 100644 --- a/riscv/dts.h +++ b/riscv/dts.h @@ -14,10 +14,15 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz, std::string dts_compile(const std::string& dts); +int fdt_get_offset(void *fdt, const char *field); +int fdt_get_first_subnode(void *fdt, int node); +int fdt_get_next_subnode(void *fdt, int node); + int fdt_parse_clint(void *fdt, reg_t *clint_addr, const char *compatible); int fdt_parse_pmp_num(void *fdt, reg_t *pmp_num, const char *compatible); int fdt_parse_pmp_alignment(void *fdt, reg_t *pmp_align, const char *compatible); +int fdt_parse_mmu_type(void *fdt, int cpu_offset, char *mmu_type); #endif |