aboutsummaryrefslogtreecommitdiff
path: root/riscv/dts.cc
diff options
context:
space:
mode:
authorChih-Min Chao <chihmin.chao@sifive.com>2020-11-15 22:10:18 -0800
committerChih-Min Chao <chihmin.chao@sifive.com>2020-11-15 22:10:19 -0800
commit0ca970dce354cff6ad68edbf27f0559d02be5915 (patch)
treec9fef609e62fb159e4e32f66e6ba057c1eb6d8d5 /riscv/dts.cc
parent70fdec9e6320f070f79fcbedec3a8c6e76618b85 (diff)
downloadspike-0ca970dce354cff6ad68edbf27f0559d02be5915.zip
spike-0ca970dce354cff6ad68edbf27f0559d02be5915.tar.gz
spike-0ca970dce354cff6ad68edbf27f0559d02be5915.tar.bz2
dts: extract cpu node checking as helper function
all atrribute in cpu could leverage it Signed-off-by: Chih-Min Chao <chihmin.chao@sifive.com>
Diffstat (limited to 'riscv/dts.cc')
-rw-r--r--riscv/dts.cc30
1 files changed, 21 insertions, 9 deletions
diff --git a/riscv/dts.cc b/riscv/dts.cc
index 9469e3f..883ceb1 100644
--- a/riscv/dts.cc
+++ b/riscv/dts.cc
@@ -225,6 +225,24 @@ static int fdt_get_node_addr_size(void *fdt, int node, reg_t *addr,
return 0;
}
+static int check_cpu_node(void *fdt, int cpu_offset)
+{
+ 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;
+
+ return 0;
+}
+
+
int fdt_get_offset(void *fdt, const char *field)
{
return fdt_path_offset(fdt, field);
@@ -291,17 +309,11 @@ int fdt_parse_pmp_alignment(void *fdt, reg_t *pmp_align,
int fdt_parse_mmu_type(void *fdt, int cpu_offset, char *mmu_type)
{
- int len;
+ int len, rc;
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;
+ if ((rc = check_cpu_node(fdt, cpu_offset)) < 0)
+ return rc;
prop = fdt_getprop(fdt, cpu_offset, "mmu-type", &len);
if (!prop || !len)