From 6b7d0ab627f642d55c83518c63a81ce656723d1b Mon Sep 17 00:00:00 2001 From: Travis Geiselbrecht Date: Wed, 5 Jul 2023 23:30:52 -0700 Subject: [lib][fdtwalk] add code to skip a cpu if disabled Some RISC-V cpus come up disabled, skip enumerating them. --- lib/fdtwalk/fdtwalk.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/fdtwalk/fdtwalk.c b/lib/fdtwalk/fdtwalk.c index 2ca506af..17f4f8fb 100644 --- a/lib/fdtwalk/fdtwalk.c +++ b/lib/fdtwalk/fdtwalk.c @@ -77,6 +77,21 @@ static status_t read_base_len_pair(const uint8_t *prop_ptr, size_t prop_len, return NO_ERROR; } +// returns true or false if a particular property is a particular value +static bool check_prop_is_val_string(const void *fdt, int offset, const char *prop, const char *val) { + int lenp; + const uint8_t *prop_ptr = fdt_getprop(fdt, offset, prop, &lenp); + if (!prop_ptr || lenp <= 0) { + return false; + } + + if (strncmp(val, (const char *)prop_ptr, strlen(val)) == 0) { + return true; + } + + return false; +} + status_t fdt_walk(const void *fdt, const struct fdt_walk_callbacks *cb) { int err = fdt_check_header(fdt); if (err != 0) { @@ -202,8 +217,13 @@ status_t fdt_walk(const void *fdt, const struct fdt_walk_callbacks *cb) { PANIC_UNIMPLEMENTED; } - LTRACEF("calling cpu callback with id %#x\n", id); - cb->cpu(id, cb->cpucookie); + // is it disabled? + if (check_prop_is_val_string(fdt, offset, "status", "disabled")) { + LTRACEF("cpu id %#x is disabled, skipping...\n", id); + } else { + LTRACEF("calling cpu callback with id %#x\n", id); + cb->cpu(id, cb->cpucookie); + } } } -- cgit v1.2.3