From 0f54569856de576eaf8daca98fdb5f620f344055 Mon Sep 17 00:00:00 2001 From: Chih-Min Chao Date: Mon, 27 Apr 2020 21:46:11 -0700 Subject: fdt: add pmp granularity function Signed-off-by: Chih-Min Chao --- riscv/dts.cc | 23 +++++++++++++++++++++-- riscv/dts.h | 5 ++++- 2 files changed, 25 insertions(+), 3 deletions(-) (limited to 'riscv') diff --git a/riscv/dts.cc b/riscv/dts.cc index 3257976..c12ff06 100644 --- a/riscv/dts.cc +++ b/riscv/dts.cc @@ -45,6 +45,7 @@ std::string make_dts(size_t insns_per_rtc_tick, size_t cpu_hz, " riscv,isa = \"" << procs[i]->get_isa_string() << "\";\n" " mmu-type = \"riscv," << (procs[i]->get_max_xlen() <= 32 ? "sv32" : "sv48") << "\";\n" " riscv,pmpregions = <16>;\n" + " riscv,pmpgranularity = <4>;\n" " clock-frequency = <" << cpu_hz << ">;\n" " CPU" << i << "_intc: interrupt-controller {\n" " #interrupt-cells = <1>;\n" @@ -229,7 +230,7 @@ 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 fdt_parse_pmp_num(void *fdt, unsigned long *pmp_num, const char *compatible) { int nodeoffset, rc; @@ -237,9 +238,27 @@ int fdt_parse_pmp(void *fdt, unsigned long *pmp_num, const char *compatible) if (nodeoffset < 0) return nodeoffset; - rc = fdt_get_node_addr_size(fdt, nodeoffset, pmp_num, NULL, "riscv,pmpregions"); + rc = fdt_get_node_addr_size(fdt, nodeoffset, pmp_num, NULL, + "riscv,pmpregions"); if (rc < 0 || !pmp_num) return -ENODEV; return 0; } + +int fdt_parse_pmp_alignment(void *fdt, unsigned long *pmp_align, + 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_align, NULL, + "riscv,pmpgranularity"); + if (rc < 0 || !pmp_align) + return -ENODEV; + + return 0; +} diff --git a/riscv/dts.h b/riscv/dts.h index ec27abc..08d8f9d 100644 --- a/riscv/dts.h +++ b/riscv/dts.h @@ -15,5 +15,8 @@ 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); +int fdt_parse_pmp_num(void *fdt, unsigned long *pmp_num, + const char *compatible); +int fdt_parse_pmp_alignment(void *fdt, unsigned long *pmp_align, + const char *compatible); #endif -- cgit v1.1