From cf0fc9b5b25566da1689c24e07871bf91aa00a44 Mon Sep 17 00:00:00 2001 From: Chih-Min Chao Date: Mon, 27 Apr 2020 21:16:21 -0700 Subject: fdt: add pmp parsing helper Signed-off-by: Chih-Min Chao --- riscv/dts.cc | 16 ++++++++++++++++ riscv/dts.h | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/riscv/dts.cc b/riscv/dts.cc index c9daa96..3257976 100644 --- a/riscv/dts.cc +++ b/riscv/dts.cc @@ -44,6 +44,7 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz, " compatible = \"riscv\";\n" " riscv,isa = \"" << procs[i]->get_isa_string() << "\";\n" " mmu-type = \"riscv," << (procs[i]->get_max_xlen() <= 32 ? "sv32" : "sv48") << "\";\n" + " riscv,pmpregions = <16>;\n" " clock-frequency = <" << cpu_hz << ">;\n" " CPU" << i << "_intc: interrupt-controller {\n" " #interrupt-cells = <1>;\n" @@ -227,3 +228,18 @@ int fdt_parse_clint(void *fdt, unsigned long *clint_addr, return 0; } + +int fdt_parse_pmp(void *fdt, unsigned long *pmp_num, const char *compatible) +{ + int nodeoffset, rc; + + nodeoffset = fdt_node_offset_by_compatible(fdt, -1, compatible); + if (nodeoffset < 0) + return nodeoffset; + + rc = fdt_get_node_addr_size(fdt, nodeoffset, pmp_num, NULL, "riscv,pmpregions"); + if (rc < 0 || !pmp_num) + return -ENODEV; + + return 0; +} diff --git a/riscv/dts.h b/riscv/dts.h index cb3490d..ec27abc 100644 --- a/riscv/dts.h +++ b/riscv/dts.h @@ -15,5 +15,5 @@ std::string dts_compile(const std::string& dts); int fdt_parse_clint(void *fdt, unsigned long *clint_addr, const char *compatible); - +int fdt_parse_pmp(void *fdt, unsigned long *pmp_num, const char *compatible); #endif -- cgit v1.1