diff options
author | Palmer Dabbelt <palmer@dabbelt.com> | 2017-11-02 15:44:15 -0700 |
---|---|---|
committer | Palmer Dabbelt <palmer@dabbelt.com> | 2017-11-02 15:45:26 -0700 |
commit | 9204785053e9a488b8990f9f98ff8f05c71fd0d5 (patch) | |
tree | d87d05b64a66af9a542a7d88e98f53d7ff17d33d /machine | |
parent | 220b1bee10d9399864131cd1dbe5037714237f03 (diff) | |
download | pk-9204785053e9a488b8990f9f98ff8f05c71fd0d5.zip pk-9204785053e9a488b8990f9f98ff8f05c71fd0d5.tar.gz pk-9204785053e9a488b8990f9f98ff8f05c71fd0d5.tar.bz2 |
Detect harts that can't boot Linux instead of hard-coding them
This checks to see if a hart can't boot Linux by looking for a
compatible "mmu-type" field. If the hart can't boot Linux, then bbl
masks it off.
Diffstat (limited to 'machine')
-rw-r--r-- | machine/disabled_hart_mask.h | 4 | ||||
-rw-r--r-- | machine/fdt.c | 28 | ||||
-rw-r--r-- | machine/fdt.h | 2 | ||||
-rw-r--r-- | machine/mentry.S | 4 | ||||
-rw-r--r-- | machine/minit.c | 3 | ||||
-rw-r--r-- | machine/mtrap.c | 3 |
6 files changed, 34 insertions, 10 deletions
diff --git a/machine/disabled_hart_mask.h b/machine/disabled_hart_mask.h new file mode 100644 index 0000000..2a3a73c --- /dev/null +++ b/machine/disabled_hart_mask.h @@ -0,0 +1,4 @@ +#ifndef DISABLED_HART_MASK_H +#define DISABLED_HART_MASK_H +extern long disabled_hart_mask; +#endif diff --git a/machine/fdt.c b/machine/fdt.c index 35681f8..061b19e 100644 --- a/machine/fdt.c +++ b/machine/fdt.c @@ -1,3 +1,4 @@ +#include <stdbool.h> #include <stdint.h> #include <string.h> #include "config.h" @@ -553,13 +554,15 @@ struct hart_filter { int compat; int hart; char *status; - unsigned long mask; + char *mmu_type; + long *disabled_hart_mask; }; static void hart_filter_open(const struct fdt_scan_node *node, void *extra) { struct hart_filter *filter = (struct hart_filter *)extra; - filter->status = 0; + filter->status = NULL; + filter->mmu_type = NULL; filter->compat = 0; filter->hart = -1; } @@ -575,9 +578,22 @@ static void hart_filter_prop(const struct fdt_scan_prop *prop, void *extra) filter->hart = reg; } else if (!strcmp(prop->name, "status")) { filter->status = (char*)prop->value; + } else if (!strcmp(prop->name, "mmu-type")) { + filter->mmu_type = (char*)prop->value; } } +static bool hart_filter_mask(const struct hart_filter *filter) +{ + if (filter->mmu_type == NULL) return true; + if (strcmp(filter->status, "okay")) return true; + if (!strcmp(filter->mmu_type, "riscv,sv39")) return false; + if (!strcmp(filter->mmu_type, "riscv,sv48")) return false; + printm("hart_filter_mask saw unknown hart type: status=\"%s\", mmu_type=\"%s\"\n", + filter->status, filter->mmu_type); + return true; +} + static void hart_filter_done(const struct fdt_scan_node *node, void *extra) { struct hart_filter *filter = (struct hart_filter *)extra; @@ -586,14 +602,15 @@ static void hart_filter_done(const struct fdt_scan_node *node, void *extra) assert (filter->status); assert (filter->hart >= 0); - if (((filter->mask >> filter->hart) & 1) && !strcmp(filter->status, "okay")) { + if (hart_filter_mask(filter)) { strcpy(filter->status, "masked"); uint32_t *len = (uint32_t*)filter->status; len[-2] = bswap(strlen("masked")+1); + *filter->disabled_hart_mask |= (1 << filter->hart); } } -void filter_harts(uintptr_t fdt, unsigned long hart_mask) +void filter_harts(uintptr_t fdt, long *disabled_hart_mask) { struct fdt_cb cb; struct hart_filter filter; @@ -604,7 +621,8 @@ void filter_harts(uintptr_t fdt, unsigned long hart_mask) cb.done = hart_filter_done; cb.extra = &filter; - filter.mask = hart_mask; + filter.disabled_hart_mask = disabled_hart_mask; + *disabled_hart_mask = 0; fdt_scan(fdt, &cb); } diff --git a/machine/fdt.h b/machine/fdt.h index 5932e17..d436778 100644 --- a/machine/fdt.h +++ b/machine/fdt.h @@ -61,7 +61,7 @@ void query_plic(uintptr_t fdt); void query_clint(uintptr_t fdt); // Remove information from FDT -void filter_harts(uintptr_t fdt, unsigned long hart_mask); +void filter_harts(uintptr_t fdt, long *disabled_hart_mask); void filter_plic(uintptr_t fdt); void filter_compat(uintptr_t fdt, const char *compat); diff --git a/machine/mentry.S b/machine/mentry.S index 33d7be4..11c053c 100644 --- a/machine/mentry.S +++ b/machine/mentry.S @@ -258,7 +258,7 @@ do_reset: add sp, sp, a2 # Boot on the first unmasked hart - la a4, platform__disabled_hart_mask + la a4, disabled_hart_mask LOAD a4, 0(a4) addi a5, a4, 1 not a4, a4 @@ -277,7 +277,7 @@ do_reset: wfi # masked harts never start - la a4, platform__disabled_hart_mask + la a4, disabled_hart_mask LOAD a4, 0(a4) srl a4, a4, a3 andi a4, a4, 1 diff --git a/machine/minit.c b/machine/minit.c index 187bef7..8ce96b1 100644 --- a/machine/minit.c +++ b/machine/minit.c @@ -6,6 +6,7 @@ #include "uart.h" #include "finisher.h" #include "platform_interface.h" +#include "disabled_hart_mask.h" #include <string.h> #include <limits.h> @@ -125,7 +126,7 @@ static void hart_plic_init() static void wake_harts() { for (int hart = 0; hart < MAX_HARTS; ++hart) - if ((((~platform__disabled_hart_mask & hart_mask) >> hart) & 1)) + if ((((~disabled_hart_mask & hart_mask) >> hart) & 1)) *OTHER_HLS(hart)->ipi = 1; // wakeup the hart } diff --git a/machine/mtrap.c b/machine/mtrap.c index e5faae3..dba3613 100644 --- a/machine/mtrap.c +++ b/machine/mtrap.c @@ -9,6 +9,7 @@ #include "fdt.h" #include "unprivileged_memory.h" #include "platform_interface.h" +#include "disabled_hart_mask.h" #include <errno.h> #include <stdarg.h> #include <stdio.h> @@ -63,7 +64,7 @@ void printm(const char* s, ...) static void send_ipi(uintptr_t recipient, int event) { - if (((platform__disabled_hart_mask >> recipient) & 1)) return; + if (((disabled_hart_mask >> recipient) & 1)) return; atomic_or(&OTHER_HLS(recipient)->mipi_pending, event); mb(); *OTHER_HLS(recipient)->ipi = 1; |