diff options
38 files changed, 288 insertions, 165 deletions
diff --git a/.github/workflows/repo-lockdown.yml b/.github/workflows/repo-lockdown.yml new file mode 100644 index 0000000..d74a759 --- /dev/null +++ b/.github/workflows/repo-lockdown.yml @@ -0,0 +1,26 @@ +name: 'Repo Lockdown' + +on: + pull_request_target: + types: opened + +permissions: + pull-requests: write + +jobs: + action: + runs-on: ubuntu-latest + steps: + - uses: dessant/repo-lockdown@v4 + with: + pr-comment: | + We have mailing list based patch review so it would be great if you can send these patchs to OpenSBI mailing list. + + You need to join OpenSBI mailing list using following link + http://lists.infradead.org/mailman/listinfo/opensbi + + Make sure you use "git send-email" to send the patches. + + Thanks for your contribution to OpenSBI project. + lock-pr: true + close-pr: true @@ -4,6 +4,7 @@ # exceptions we need even begin with dot !.clang-format !.gitignore +!.github # Object files *.o @@ -489,7 +489,7 @@ compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ $(src_dir)/scripts/d2c.sh -i $(6) -a $(D2C_ALIGN_BYTES) -p $(D2C_NAME_PREFIX) -t $(D2C_PADDING_BYTES) > $(1) compile_carray = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CARRAY $(subst $(build_dir)/,,$(1))"; \ - $(eval CARRAY_VAR_LIST := $(carray-$(subst .c,,$(shell basename $(1)))-y)) \ + $(eval CARRAY_VAR_LIST := $(carray-$(subst .carray.c,,$(shell basename $(1)))-y)) \ $(src_dir)/scripts/carray.sh -i $(2) -l "$(CARRAY_VAR_LIST)" > $(1) compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \ @@ -519,7 +519,7 @@ $(build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(build_dir)/%.c: $(src_dir)/%.carray +$(build_dir)/%.carray.c: $(src_dir)/%.carray $(call compile_carray,$@,$<) $(build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER) @@ -547,7 +547,7 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.c: $(platform_src_dir)/%.carray +$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(platform_src_dir)/%.c $(KCONFIG_AUTOHEADER) @@ -590,7 +590,7 @@ $(platform_build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.c: $(src_dir)/%.carray +$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER) @@ -687,6 +687,8 @@ clean: $(CMD_PREFIX)mkdir -p $(build_dir) $(if $(V), @echo " RM $(build_dir)/*.o") $(CMD_PREFIX)find $(build_dir) -type f -name "*.o" -exec rm -rf {} + + $(if $(V), @echo " RM $(build_dir)/*.carray.c") + $(CMD_PREFIX)find $(build_dir) -type f -name "*.carray.c" -exec rm -rf {} + $(if $(V), @echo " RM $(build_dir)/*.a") $(CMD_PREFIX)find $(build_dir) -type f -name "*.a" -exec rm -rf {} + $(if $(V), @echo " RM $(build_dir)/*.elf") diff --git a/docs/writing_tests.md b/docs/writing_tests.md index 0fd15d6..cee4c4d 100644 --- a/docs/writing_tests.md +++ b/docs/writing_tests.md @@ -57,9 +57,7 @@ carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += string_test_suite libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_string_test.o ``` -If you compiled OpenSBI with CONFIG_SBIUNIT enabled before, you may need to -manually remove the build folder in order to regenerate the carray files: -`rm -rf build/`. +Now, run `make clean` in order to regenerate the carray-related files. Recompile OpenSBI with the CONFIG_SBIUNIT option enabled and run it in QEMU. You will see something like this: diff --git a/include/sbi/riscv_encoding.h b/include/sbi/riscv_encoding.h index 477fa3a..050674a 100644 --- a/include/sbi/riscv_encoding.h +++ b/include/sbi/riscv_encoding.h @@ -207,7 +207,7 @@ #endif -#define MHPMEVENT_SSCOF_MASK _ULL(0xFFFF000000000000) +#define MHPMEVENT_SSCOF_MASK _ULL(0xFC00000000000000) #define ENVCFG_STCE (_ULL(1) << 63) #define ENVCFG_PBMTE (_ULL(1) << 62) diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index 0979765..3097db1 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -58,8 +58,6 @@ void sbi_console_set_device(const struct sbi_console_device *dev); struct sbi_scratch; -int sbi_console_init(struct sbi_scratch *scratch); - #define SBI_ASSERT(cond, args) do { \ if (unlikely(!(cond))) \ sbi_panic args; \ diff --git a/include/sbi/sbi_fifo.h b/include/sbi/sbi_fifo.h index 1a85f07..89a2ea2 100644 --- a/include/sbi/sbi_fifo.h +++ b/include/sbi/sbi_fifo.h @@ -23,6 +23,18 @@ struct sbi_fifo { u16 tail; }; +#define SBI_FIFO_INITIALIZER(__queue_mem, __entries, __entry_size) \ +{ .queue = __queue_mem, \ + .qlock = SPIN_LOCK_INITIALIZER, \ + .num_entries = __entries, \ + .entry_size = __entry_size, \ + .avail = 0, \ + .tail = 0, \ +} + +#define SBI_FIFO_DEFINE(__name, __queue_mem, __entries, __entry_size) \ +struct sbi_fifo __name = SBI_FIFO_INITIALIZER(__queue_mem, __entries, __entry_size) + enum sbi_fifo_inplace_update_types { SBI_FIFO_SKIP, SBI_FIFO_UPDATED, @@ -30,7 +42,7 @@ enum sbi_fifo_inplace_update_types { }; int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data); -int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data); +int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data, bool force); void sbi_fifo_init(struct sbi_fifo *fifo, void *queue_mem, u16 entries, u16 entry_size); int sbi_fifo_is_empty(struct sbi_fifo *fifo); diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index 581935a..7b3ac4b 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -111,9 +111,6 @@ struct sbi_platform_operations { /** Get platform specific mhpmevent value */ uint64_t (*pmu_xlate_to_mhpmevent)(uint32_t event_idx, uint64_t data); - /** Initialize the platform console */ - int (*console_init)(void); - /** Initialize the platform interrupt controller for current HART */ int (*irqchip_init)(bool cold_boot); /** Exit the platform interrupt controller for current HART */ @@ -550,20 +547,6 @@ static inline uint64_t sbi_platform_pmu_xlate_to_mhpmevent(const struct sbi_plat } /** - * Initialize the platform console - * - * @param plat pointer to struct sbi_platform - * - * @return 0 on success and negative error code on failure - */ -static inline int sbi_platform_console_init(const struct sbi_platform *plat) -{ - if (plat && sbi_platform_ops(plat)->console_init) - return sbi_platform_ops(plat)->console_init(); - return 0; -} - -/** * Initialize the platform interrupt controller for current HART * * @param plat pointer to struct sbi_platform diff --git a/include/sbi/sbi_version.h b/include/sbi/sbi_version.h index 8d9e395..d876aa5 100644 --- a/include/sbi/sbi_version.h +++ b/include/sbi/sbi_version.h @@ -11,7 +11,7 @@ #define __SBI_VERSION_H__ #define OPENSBI_VERSION_MAJOR 1 -#define OPENSBI_VERSION_MINOR 4 +#define OPENSBI_VERSION_MINOR 5 /** * OpenSBI 32-bit version with: diff --git a/lib/sbi/Kconfig b/lib/sbi/Kconfig index 6cf54ce..bd8ba2b 100644 --- a/lib/sbi/Kconfig +++ b/lib/sbi/Kconfig @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-2-Clause -menu "SBI Extension Support" +menu "Generic SBI Support" + +config CONSOLE_EARLY_BUFFER_SIZE + int "Early console buffer size (bytes)" + default 256 config SBI_ECALL_TIME bool "Timer extension" diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 211abad..535aa70 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -13,7 +13,7 @@ libsbi-objs-y += riscv_hardfp.o libsbi-objs-y += riscv_locks.o libsbi-objs-y += sbi_ecall.o -libsbi-objs-y += sbi_ecall_exts.o +libsbi-objs-y += sbi_ecall_exts.carray.o # The order of below extensions is performance optimized carray-sbi_ecall_exts-$(CONFIG_SBI_ECALL_TIME) += ecall_time diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index d3ec461..d760885 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -9,6 +9,7 @@ #include <sbi/riscv_locks.h> #include <sbi/sbi_console.h> +#include <sbi/sbi_fifo.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> #include <sbi/sbi_scratch.h> @@ -21,6 +22,15 @@ static char console_tbuf[CONSOLE_TBUF_MAX]; static u32 console_tbuf_len; static spinlock_t console_out_lock = SPIN_LOCK_INITIALIZER; +#ifdef CONFIG_CONSOLE_EARLY_BUFFER_SIZE +#define CONSOLE_EARLY_BUFFER_SIZE CONFIG_CONSOLE_EARLY_BUFFER_SIZE +#else +#define CONSOLE_EARLY_BUFFER_SIZE 256 +#endif +static char console_early_buffer[CONSOLE_EARLY_BUFFER_SIZE] = { 0 }; +static SBI_FIFO_DEFINE(console_early_fifo, console_early_buffer, \ + CONSOLE_EARLY_BUFFER_SIZE, sizeof(char)); + bool sbi_isprintable(char c) { if (((31 < c) && (c < 127)) || (c == '\f') || (c == '\r') || @@ -39,6 +49,7 @@ int sbi_getc(void) static unsigned long nputs(const char *str, unsigned long len) { + char ch; unsigned long i; if (console_dev) { @@ -51,6 +62,11 @@ static unsigned long nputs(const char *str, unsigned long len) console_dev->console_putc(str[i]); } } + } else { + for (i = 0; i < len; i++) { + ch = str[i]; + sbi_fifo_enqueue(&console_early_fifo, &ch, true); + } } return len; } @@ -472,19 +488,19 @@ const struct sbi_console_device *sbi_console_get_device(void) void sbi_console_set_device(const struct sbi_console_device *dev) { + char ch; + bool flush_early_fifo = false; + if (!dev) return; - console_dev = dev; -} - -int sbi_console_init(struct sbi_scratch *scratch) -{ - int rc = sbi_platform_console_init(sbi_platform_ptr(scratch)); + if (!console_dev) + flush_early_fifo = true; - /* console is not a necessary device */ - if (rc == SBI_ENODEV) - return 0; + console_dev = dev; - return rc; + if (flush_early_fifo) { + while (!sbi_fifo_dequeue(&console_early_fifo, &ch)) + sbi_putc(ch); + } } diff --git a/lib/sbi/sbi_emulate_csr.c b/lib/sbi/sbi_emulate_csr.c index 5f3b111..869c81f 100644 --- a/lib/sbi/sbi_emulate_csr.c +++ b/lib/sbi/sbi_emulate_csr.c @@ -10,7 +10,6 @@ #include <sbi/riscv_asm.h> #include <sbi/riscv_encoding.h> #include <sbi/sbi_bitops.h> -#include <sbi/sbi_console.h> #include <sbi/sbi_emulate_csr.h> #include <sbi/sbi_error.h> #include <sbi/sbi_hart.h> @@ -151,10 +150,6 @@ int sbi_emulate_csr_read(int csr_num, struct sbi_trap_regs *regs, break; } - if (ret) - sbi_dprintf("%s: hartid%d: invalid csr_num=0x%x\n", - __func__, current_hartid(), csr_num); - return ret; } @@ -189,9 +184,5 @@ int sbi_emulate_csr_write(int csr_num, struct sbi_trap_regs *regs, break; } - if (ret) - sbi_dprintf("%s: hartid%d: invalid csr_num=0x%x\n", - __func__, current_hartid(), csr_num); - return ret; } diff --git a/lib/sbi/sbi_fifo.c b/lib/sbi/sbi_fifo.c index 72c6d39..d07ebff 100644 --- a/lib/sbi/sbi_fifo.c +++ b/lib/sbi/sbi_fifo.c @@ -66,11 +66,63 @@ static inline void __sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) if (head >= fifo->num_entries) head = head - fifo->num_entries; - sbi_memcpy((char *)fifo->queue + head * fifo->entry_size, data, fifo->entry_size); + switch (fifo->entry_size) { + case 1: + *(char *)(fifo->queue + head * fifo->entry_size) = *(char *)data; + break; + case 2: + *(u16 *)(fifo->queue + head * fifo->entry_size) = *(u16 *)data; + break; + case 4: + *(u32 *)(fifo->queue + head * fifo->entry_size) = *(u32 *)data; + break; +#if __riscv_xlen > 32 + case 8: + *(u64 *)(fifo->queue + head * fifo->entry_size) = *(u64 *)data; + break; +#endif + default: + sbi_memcpy(fifo->queue + head * fifo->entry_size, + data, fifo->entry_size); + break; + } fifo->avail++; } +/* Note: must be called with fifo->qlock held */ +static inline void __sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data) +{ + if (!data) + goto skip_data_copy; + + switch (fifo->entry_size) { + case 1: + *(char *)data = *(char *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 2: + *(u16 *)data = *(u16 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; + case 4: + *(u32 *)data = *(u32 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#if __riscv_xlen > 32 + case 8: + *(u64 *)data = *(u64 *)(fifo->queue + (u32)fifo->tail * fifo->entry_size); + break; +#endif + default: + sbi_memcpy(data, fifo->queue + (u32)fifo->tail * fifo->entry_size, + fifo->entry_size); + break; + } + +skip_data_copy: + fifo->avail--; + fifo->tail++; + if (fifo->tail >= fifo->num_entries) + fifo->tail = 0; +} /* Note: must be called with fifo->qlock held */ static inline bool __sbi_fifo_is_empty(struct sbi_fifo *fifo) @@ -154,7 +206,7 @@ int sbi_fifo_inplace_update(struct sbi_fifo *fifo, void *in, return ret; } -int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) +int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data, bool force) { if (!fifo || !data) return SBI_EINVAL; @@ -162,9 +214,13 @@ int sbi_fifo_enqueue(struct sbi_fifo *fifo, void *data) spin_lock(&fifo->qlock); if (__sbi_fifo_is_full(fifo)) { - spin_unlock(&fifo->qlock); - return SBI_ENOSPC; + if (!force) { + spin_unlock(&fifo->qlock); + return SBI_ENOSPC; + } + __sbi_fifo_dequeue(fifo, NULL); } + __sbi_fifo_enqueue(fifo, data); spin_unlock(&fifo->qlock); @@ -184,13 +240,7 @@ int sbi_fifo_dequeue(struct sbi_fifo *fifo, void *data) return SBI_ENOENT; } - sbi_memcpy(data, (char *)fifo->queue + (u32)fifo->tail * fifo->entry_size, - fifo->entry_size); - - fifo->avail--; - fifo->tail++; - if (fifo->tail >= fifo->num_entries) - fifo->tail = 0; + __sbi_fifo_dequeue(fifo, data); spin_unlock(&fifo->qlock); diff --git a/lib/sbi/sbi_hsm.c b/lib/sbi/sbi_hsm.c index 7e32af3..3706acf 100644 --- a/lib/sbi/sbi_hsm.c +++ b/lib/sbi/sbi_hsm.c @@ -423,10 +423,12 @@ void __sbi_hsm_suspend_non_ret_save(struct sbi_scratch *scratch) hdata->saved_mie = csr_read(CSR_MIE); hdata->saved_mip = csr_read(CSR_MIP) & (MIP_SSIP | MIP_STIP); hdata->saved_medeleg = csr_read(CSR_MEDELEG); + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) { #if __riscv_xlen == 32 - hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH); + hdata->saved_menvcfgh = csr_read(CSR_MENVCFGH); #endif - hdata->saved_menvcfg = csr_read(CSR_MENVCFG); + hdata->saved_menvcfg = csr_read(CSR_MENVCFG); + } } static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch) @@ -434,10 +436,12 @@ static void __sbi_hsm_suspend_non_ret_restore(struct sbi_scratch *scratch) struct sbi_hsm_data *hdata = sbi_scratch_offset_ptr(scratch, hart_data_offset); - csr_write(CSR_MENVCFG, hdata->saved_menvcfg); + if (sbi_hart_priv_version(scratch) >= SBI_HART_PRIV_VER_1_12) { + csr_write(CSR_MENVCFG, hdata->saved_menvcfg); #if __riscv_xlen == 32 - csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh); + csr_write(CSR_MENVCFGH, hdata->saved_menvcfgh); #endif + } csr_write(CSR_MEDELEG, hdata->saved_medeleg); csr_write(CSR_MIE, hdata->saved_mie); csr_set(CSR_MIP, (hdata->saved_mip & (MIP_SSIP | MIP_STIP))); diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 0f9e14c..d80efe9 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -261,10 +261,6 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) if (rc) sbi_hart_hang(); - rc = sbi_console_init(scratch); - if (rc) - sbi_hart_hang(); - rc = sbi_sse_init(scratch, true); if (rc) { sbi_printf("%s: sse init failed (error %d)\n", __func__, rc); diff --git a/lib/sbi/sbi_sse.c b/lib/sbi/sbi_sse.c index e39963f..fe36a64 100644 --- a/lib/sbi/sbi_sse.c +++ b/lib/sbi/sbi_sse.c @@ -667,7 +667,7 @@ static int sse_ipi_inject_send(unsigned long hartid, uint32_t event_id) sse_inject_fifo_r = sbi_scratch_offset_ptr(remote_scratch, sse_inject_fifo_off); - ret = sbi_fifo_enqueue(sse_inject_fifo_r, &evt); + ret = sbi_fifo_enqueue(sse_inject_fifo_r, &evt, false); if (ret) return SBI_EFAIL; diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index cca319f..01b31f4 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -351,7 +351,8 @@ static int tlb_update(struct sbi_scratch *scratch, ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb); - if (ret == SBI_FIFO_UNCHANGED && sbi_fifo_enqueue(tlb_fifo_r, data) < 0) { + if (ret == SBI_FIFO_UNCHANGED && + sbi_fifo_enqueue(tlb_fifo_r, data, false) < 0) { /** * For now, Busy loop until there is space in the fifo. * There may be case where target hart is also diff --git a/lib/sbi/tests/objects.mk b/lib/sbi/tests/objects.mk index 8f27289..16608fa 100644 --- a/lib/sbi/tests/objects.mk +++ b/lib/sbi/tests/objects.mk @@ -1,5 +1,5 @@ libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_unit_test.o -libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_unit_tests.o +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_unit_tests.carray.o carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += bitmap_test_suite libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_bitmap_test.o @@ -12,3 +12,6 @@ libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_atomic_test.o carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += locks_test_suite libsbi-objs-$(CONFIG_SBIUNIT) += tests/riscv_locks_test.o + +carray-sbi_unit_tests-$(CONFIG_SBIUNIT) += math_test_suite +libsbi-objs-$(CONFIG_SBIUNIT) += tests/sbi_math_test.o
\ No newline at end of file diff --git a/lib/sbi/tests/sbi_math_test.c b/lib/sbi/tests/sbi_math_test.c new file mode 100644 index 0000000..81ed832 --- /dev/null +++ b/lib/sbi/tests/sbi_math_test.c @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright 2024 Beijing ESWIN Computing Technology Co., Ltd. + * + * Author: Dongdong Zhang <zhangdongdong@eswincomputing.com> + */ +#include <sbi/sbi_math.h> +#include <sbi/sbi_unit_test.h> + +static void log2roundup_test(struct sbiunit_test_case *test) +{ + struct { + unsigned long input; + unsigned long expected; + } cases[] = { + {1, 0}, + {2, 1}, + {3, 2}, + {4, 2}, + {5, 3}, + {8, 3}, + {9, 4}, + {15, 4}, + {16, 4}, + {17, 5}, + {31, 5}, + {32, 5}, + {33, 6}, + {63, 6}, + {64, 6}, + {65, 7}, + }; + + for (int i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) { + unsigned long result = log2roundup(cases[i].input); + SBIUNIT_EXPECT_EQ(test, result, cases[i].expected); + } +} + +static struct sbiunit_test_case math_test_cases[] = { + SBIUNIT_TEST_CASE(log2roundup_test), + SBIUNIT_END_CASE, +}; + +SBIUNIT_TEST_SUITE(math_test_suite, math_test_cases); diff --git a/lib/sbi/tests/sbi_unit_test.c b/lib/sbi/tests/sbi_unit_test.c index c2a0be6..cd09166 100644 --- a/lib/sbi/tests/sbi_unit_test.c +++ b/lib/sbi/tests/sbi_unit_test.c @@ -7,6 +7,10 @@ #include <sbi/sbi_types.h> #include <sbi/sbi_console.h> +#define ANSI_COLOR_GREEN "\x1b[32m" +#define ANSI_COLOR_RED "\x1b[31m" +#define ANSI_COLOR_RESET "\x1b[0m" + extern struct sbiunit_test_suite *sbi_unit_tests[]; extern unsigned long sbi_unit_tests_size; @@ -27,10 +31,13 @@ static void run_test_suite(struct sbiunit_test_suite *suite) count_fail++; else count_pass++; - sbi_printf("[%s] %s\n", s_case->failed ? "FAILED" : "PASSED", - s_case->name); + sbi_printf("%s[%s]%s %s\n", + s_case->failed ? ANSI_COLOR_RED : ANSI_COLOR_GREEN, + s_case->failed ? "FAILED" : "PASSED", + ANSI_COLOR_RESET, s_case->name); s_case++; } + sbi_printf("%u PASSED / %u FAILED / %u TOTAL\n", count_pass, count_fail, count_pass + count_fail); } diff --git a/lib/utils/fdt/fdt_helper.c b/lib/utils/fdt/fdt_helper.c index 9a945af..b7f7e07 100644 --- a/lib/utils/fdt/fdt_helper.c +++ b/lib/utils/fdt/fdt_helper.c @@ -411,6 +411,18 @@ static int fdt_parse_isa_one_hart(const char *isa, unsigned long *extensions) return 0; } +static void fdt_parse_isa_extensions_one_hart(const char *isa, + unsigned long *extensions, + int len) +{ + size_t i; + + for (i = 0; i < SBI_HART_EXT_MAX; i++) { + if (fdt_stringlist_contains(isa, len, sbi_hart_ext[i].name)) + __set_bit(sbi_hart_ext[i].id, extensions); + } +} + static int fdt_parse_isa_all_harts(void *fdt) { u32 hartid; @@ -434,10 +446,6 @@ static int fdt_parse_isa_all_harts(void *fdt) if (!fdt_node_is_enabled(fdt, cpu_offset)) continue; - val = fdt_getprop(fdt, cpu_offset, "riscv,isa", &len); - if (!val || len <= 0) - return SBI_ENOENT; - scratch = sbi_hartid_to_scratch(hartid); if (!scratch) return SBI_ENOENT; @@ -445,6 +453,17 @@ static int fdt_parse_isa_all_harts(void *fdt) hart_exts = sbi_scratch_offset_ptr(scratch, fdt_isa_bitmap_offset); + val = fdt_getprop(fdt, cpu_offset, "riscv,isa-extensions", &len); + if (val && len > 0) { + fdt_parse_isa_extensions_one_hart((const char *)val, + hart_exts, len); + continue; + } + + val = fdt_getprop(fdt, cpu_offset, "riscv,isa", &len); + if (!val || len <= 0) + return SBI_ENOENT; + err = fdt_parse_isa_one_hart((const char *)val, hart_exts); if (err) return err; diff --git a/lib/utils/gpio/objects.mk b/lib/utils/gpio/objects.mk index 76647a5..5210683 100644 --- a/lib/utils/gpio/objects.mk +++ b/lib/utils/gpio/objects.mk @@ -8,7 +8,7 @@ # libsbiutils-objs-$(CONFIG_FDT_GPIO) += gpio/fdt_gpio.o -libsbiutils-objs-$(CONFIG_FDT_GPIO) += gpio/fdt_gpio_drivers.o +libsbiutils-objs-$(CONFIG_FDT_GPIO) += gpio/fdt_gpio_drivers.carray.o carray-fdt_gpio_drivers-$(CONFIG_FDT_GPIO_DESIGNWARE) += fdt_gpio_designware libsbiutils-objs-$(CONFIG_FDT_GPIO_DESIGNWARE) += gpio/fdt_gpio_designware.o diff --git a/lib/utils/i2c/objects.mk b/lib/utils/i2c/objects.mk index 5f7a79f..d34d664 100644 --- a/lib/utils/i2c/objects.mk +++ b/lib/utils/i2c/objects.mk @@ -10,7 +10,7 @@ libsbiutils-objs-$(CONFIG_I2C) += i2c/i2c.o libsbiutils-objs-$(CONFIG_FDT_I2C) += i2c/fdt_i2c.o -libsbiutils-objs-$(CONFIG_FDT_I2C) += i2c/fdt_i2c_adapter_drivers.o +libsbiutils-objs-$(CONFIG_FDT_I2C) += i2c/fdt_i2c_adapter_drivers.carray.o carray-fdt_i2c_adapter_drivers-$(CONFIG_FDT_I2C_SIFIVE) += fdt_i2c_adapter_sifive libsbiutils-objs-$(CONFIG_FDT_I2C_SIFIVE) += i2c/fdt_i2c_sifive.o diff --git a/lib/utils/ipi/objects.mk b/lib/utils/ipi/objects.mk index 999e7bd..d1c94af 100644 --- a/lib/utils/ipi/objects.mk +++ b/lib/utils/ipi/objects.mk @@ -11,7 +11,7 @@ libsbiutils-objs-$(CONFIG_IPI_MSWI) += ipi/aclint_mswi.o libsbiutils-objs-$(CONFIG_IPI_PLICSW) += ipi/andes_plicsw.o libsbiutils-objs-$(CONFIG_FDT_IPI) += ipi/fdt_ipi.o -libsbiutils-objs-$(CONFIG_FDT_IPI) += ipi/fdt_ipi_drivers.o +libsbiutils-objs-$(CONFIG_FDT_IPI) += ipi/fdt_ipi_drivers.carray.o carray-fdt_ipi_drivers-$(CONFIG_FDT_IPI_MSWI) += fdt_ipi_mswi libsbiutils-objs-$(CONFIG_FDT_IPI_MSWI) += ipi/fdt_ipi_mswi.o diff --git a/lib/utils/irqchip/objects.mk b/lib/utils/irqchip/objects.mk index e458891..a13b384 100644 --- a/lib/utils/irqchip/objects.mk +++ b/lib/utils/irqchip/objects.mk @@ -8,7 +8,7 @@ # libsbiutils-objs-$(CONFIG_FDT_IRQCHIP) += irqchip/fdt_irqchip.o -libsbiutils-objs-$(CONFIG_FDT_IRQCHIP) += irqchip/fdt_irqchip_drivers.o +libsbiutils-objs-$(CONFIG_FDT_IRQCHIP) += irqchip/fdt_irqchip_drivers.carray.o carray-fdt_irqchip_drivers-$(CONFIG_FDT_IRQCHIP_APLIC) += fdt_irqchip_aplic libsbiutils-objs-$(CONFIG_FDT_IRQCHIP_APLIC) += irqchip/fdt_irqchip_aplic.o diff --git a/lib/utils/regmap/objects.mk b/lib/utils/regmap/objects.mk index 5bd139f..43487a5 100644 --- a/lib/utils/regmap/objects.mk +++ b/lib/utils/regmap/objects.mk @@ -8,7 +8,7 @@ # libsbiutils-objs-$(CONFIG_FDT_REGMAP) += regmap/fdt_regmap.o -libsbiutils-objs-$(CONFIG_FDT_REGMAP) += regmap/fdt_regmap_drivers.o +libsbiutils-objs-$(CONFIG_FDT_REGMAP) += regmap/fdt_regmap_drivers.carray.o carray-fdt_regmap_drivers-$(CONFIG_FDT_REGMAP_SYSCON) += fdt_regmap_syscon libsbiutils-objs-$(CONFIG_FDT_REGMAP_SYSCON) += regmap/fdt_regmap_syscon.o diff --git a/lib/utils/reset/objects.mk b/lib/utils/reset/objects.mk index 44944ca..a84336c 100644 --- a/lib/utils/reset/objects.mk +++ b/lib/utils/reset/objects.mk @@ -8,7 +8,7 @@ # libsbiutils-objs-$(CONFIG_FDT_RESET) += reset/fdt_reset.o -libsbiutils-objs-$(CONFIG_FDT_RESET) += reset/fdt_reset_drivers.o +libsbiutils-objs-$(CONFIG_FDT_RESET) += reset/fdt_reset_drivers.carray.o carray-fdt_reset_drivers-$(CONFIG_FDT_RESET_ATCWDT200) += fdt_reset_atcwdt200 libsbiutils-objs-$(CONFIG_FDT_RESET_ATCWDT200) += reset/fdt_reset_atcwdt200.o diff --git a/lib/utils/serial/objects.mk b/lib/utils/serial/objects.mk index 1e6bd2e..7c973c8 100644 --- a/lib/utils/serial/objects.mk +++ b/lib/utils/serial/objects.mk @@ -8,7 +8,7 @@ # libsbiutils-objs-$(CONFIG_FDT_SERIAL) += serial/fdt_serial.o -libsbiutils-objs-$(CONFIG_FDT_SERIAL) += serial/fdt_serial_drivers.o +libsbiutils-objs-$(CONFIG_FDT_SERIAL) += serial/fdt_serial_drivers.carray.o carray-fdt_serial_drivers-$(CONFIG_FDT_SERIAL_CADENCE) += fdt_serial_cadence libsbiutils-objs-$(CONFIG_FDT_SERIAL_CADENCE) += serial/fdt_serial_cadence.o diff --git a/lib/utils/timer/objects.mk b/lib/utils/timer/objects.mk index 9360a76..92e0927 100644 --- a/lib/utils/timer/objects.mk +++ b/lib/utils/timer/objects.mk @@ -11,7 +11,7 @@ libsbiutils-objs-$(CONFIG_TIMER_MTIMER) += timer/aclint_mtimer.o libsbiutils-objs-$(CONFIG_TIMER_PLMT) += timer/andes_plmt.o libsbiutils-objs-$(CONFIG_FDT_TIMER) += timer/fdt_timer.o -libsbiutils-objs-$(CONFIG_FDT_TIMER) += timer/fdt_timer_drivers.o +libsbiutils-objs-$(CONFIG_FDT_TIMER) += timer/fdt_timer_drivers.carray.o carray-fdt_timer_drivers-$(CONFIG_FDT_TIMER_MTIMER) += fdt_timer_mtimer libsbiutils-objs-$(CONFIG_FDT_TIMER_MTIMER) += timer/fdt_timer_mtimer.o diff --git a/platform/fpga/ariane/platform.c b/platform/fpga/ariane/platform.c index 8be5e6c..8d46d88 100644 --- a/platform/fpga/ariane/platform.c +++ b/platform/fpga/ariane/platform.c @@ -7,7 +7,6 @@ #include <sbi/riscv_asm.h> #include <sbi/riscv_encoding.h> #include <sbi/riscv_io.h> -#include <sbi/sbi_console.h> #include <sbi/sbi_const.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> @@ -67,8 +66,15 @@ static struct aclint_mtimer_data mtimer = { */ static int ariane_early_init(bool cold_boot) { - /* For now nothing to do. */ - return 0; + if (!cold_boot) + return 0; + + return uart8250_init(ARIANE_UART_ADDR, + ARIANE_UART_FREQ, + ARIANE_UART_BAUDRATE, + ARIANE_UART_REG_SHIFT, + ARIANE_UART_REG_WIDTH, + ARIANE_UART_REG_OFFSET); } /* @@ -87,19 +93,6 @@ static int ariane_final_init(bool cold_boot) return 0; } -/* - * Initialize the ariane console. - */ -static int ariane_console_init(void) -{ - return uart8250_init(ARIANE_UART_ADDR, - ARIANE_UART_FREQ, - ARIANE_UART_BAUDRATE, - ARIANE_UART_REG_SHIFT, - ARIANE_UART_REG_WIDTH, - ARIANE_UART_REG_OFFSET); -} - static int plic_ariane_warm_irqchip_init(int m_cntx_id, int s_cntx_id) { int ret; @@ -175,7 +168,6 @@ static int ariane_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = ariane_early_init, .final_init = ariane_final_init, - .console_init = ariane_console_init, .irqchip_init = ariane_irqchip_init, .ipi_init = ariane_ipi_init, .timer_init = ariane_timer_init, diff --git a/platform/fpga/openpiton/platform.c b/platform/fpga/openpiton/platform.c index 2317a89..dd74a0c 100644 --- a/platform/fpga/openpiton/platform.c +++ b/platform/fpga/openpiton/platform.c @@ -6,7 +6,6 @@ #include <sbi/riscv_asm.h> #include <sbi/riscv_encoding.h> #include <sbi/riscv_io.h> -#include <sbi/sbi_console.h> #include <sbi/sbi_const.h> #include <sbi/sbi_hart.h> #include <sbi/sbi_platform.h> @@ -103,7 +102,10 @@ static int openpiton_early_init(bool cold_boot) ACLINT_DEFAULT_MTIMECMP_OFFSET; } - return 0; + return uart8250_init(uart.addr, uart.freq, uart.baud, + OPENPITON_DEFAULT_UART_REG_SHIFT, + OPENPITON_DEFAULT_UART_REG_WIDTH, + OPENPITON_DEFAULT_UART_REG_OFFSET); } /* @@ -122,19 +124,6 @@ static int openpiton_final_init(bool cold_boot) return 0; } -/* - * Initialize the openpiton console. - */ -static int openpiton_console_init(void) -{ - return uart8250_init(uart.addr, - uart.freq, - uart.baud, - OPENPITON_DEFAULT_UART_REG_SHIFT, - OPENPITON_DEFAULT_UART_REG_WIDTH, - OPENPITON_DEFAULT_UART_REG_OFFSET); -} - static int plic_openpiton_warm_irqchip_init(int m_cntx_id, int s_cntx_id) { int ret; @@ -210,7 +199,6 @@ static int openpiton_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = openpiton_early_init, .final_init = openpiton_final_init, - .console_init = openpiton_console_init, .irqchip_init = openpiton_irqchip_init, .ipi_init = openpiton_ipi_init, .timer_init = openpiton_timer_init, diff --git a/platform/generic/objects.mk b/platform/generic/objects.mk index c215935..c4a8fee 100644 --- a/platform/generic/objects.mk +++ b/platform/generic/objects.mk @@ -19,7 +19,7 @@ platform-runcmd = qemu-system-riscv$(PLATFORM_RISCV_XLEN) -M virt -m 256M \ # Objects to build platform-objs-y += platform.o -platform-objs-y += platform_override_modules.o +platform-objs-y += platform_override_modules.carray.o # Blobs to build FW_DYNAMIC=y diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 1f46b76..3470474 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -221,9 +221,19 @@ static int generic_nascent_init(void) static int generic_early_init(bool cold_boot) { - if (cold_boot) + int rc; + + if (cold_boot) { fdt_reset_init(); + if (semihosting_enabled()) + rc = semihosting_init(); + else + rc = fdt_serial_init(); + if (rc) + return rc; + } + if (!generic_plat || !generic_plat->early_init) return 0; @@ -378,14 +388,6 @@ static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx, return evt_val; } -static int generic_console_init(void) -{ - if (semihosting_enabled()) - return semihosting_init(); - else - return fdt_serial_init(); -} - const struct sbi_platform_operations platform_ops = { .cold_boot_allowed = generic_cold_boot_allowed, .nascent_init = generic_nascent_init, @@ -395,7 +397,6 @@ const struct sbi_platform_operations platform_ops = { .final_exit = generic_final_exit, .extensions_init = generic_extensions_init, .domains_init = generic_domains_init, - .console_init = generic_console_init, .irqchip_init = fdt_irqchip_init, .irqchip_exit = fdt_irqchip_exit, .ipi_init = fdt_ipi_init, diff --git a/platform/kendryte/k210/platform.c b/platform/kendryte/k210/platform.c index 27b23f7..531adcd 100644 --- a/platform/kendryte/k210/platform.c +++ b/platform/kendryte/k210/platform.c @@ -9,7 +9,6 @@ #include <sbi/riscv_asm.h> #include <sbi/riscv_encoding.h> -#include <sbi/sbi_console.h> #include <sbi/sbi_const.h> #include <sbi/sbi_platform.h> #include <sbi/sbi_system.h> @@ -109,10 +108,13 @@ static struct sbi_system_reset_device k210_reset = { static int k210_early_init(bool cold_boot) { - if (cold_boot) - sbi_system_reset_add_device(&k210_reset); + if (!cold_boot) + return 0; - return 0; + sbi_system_reset_add_device(&k210_reset); + + return sifive_uart_init(K210_UART_BASE_ADDR, k210_get_clk_freq(), + K210_UART_BAUDRATE); } static int k210_final_init(bool cold_boot) @@ -130,12 +132,6 @@ static int k210_final_init(bool cold_boot) return 0; } -static int k210_console_init(void) -{ - return sifive_uart_init(K210_UART_BASE_ADDR, k210_get_clk_freq(), - K210_UART_BAUDRATE); -} - static int k210_irqchip_init(bool cold_boot) { int rc; @@ -181,8 +177,6 @@ const struct sbi_platform_operations platform_ops = { .final_init = k210_final_init, - .console_init = k210_console_init, - .irqchip_init = k210_irqchip_init, .ipi_init = k210_ipi_init, diff --git a/platform/nuclei/ux600/platform.c b/platform/nuclei/ux600/platform.c index f688b50..2289366 100644 --- a/platform/nuclei/ux600/platform.c +++ b/platform/nuclei/ux600/platform.c @@ -11,7 +11,6 @@ #include <sbi/riscv_asm.h> #include <sbi/riscv_io.h> #include <sbi/riscv_encoding.h> -#include <sbi/sbi_console.h> #include <sbi/sbi_const.h> #include <sbi/sbi_platform.h> #include <sbi/sbi_system.h> @@ -150,8 +149,10 @@ static int ux600_early_init(bool cold_boot) { u32 regval; - if (cold_boot) - sbi_system_reset_add_device(&ux600_reset); + if (!cold_boot) + return 0; + + sbi_system_reset_add_device(&ux600_reset); /* Measure CPU Frequency using Timer */ ux600_clk_freq = ux600_get_clk_freq(); @@ -163,7 +164,9 @@ static int ux600_early_init(bool cold_boot) regval = readl((void *)(UX600_GPIO_ADDR + UX600_GPIO_IOF_EN_OFS)) | UX600_GPIO_IOF_UART0_MASK; writel(regval, (void *)(UX600_GPIO_ADDR + UX600_GPIO_IOF_EN_OFS)); - return 0; + + return sifive_uart_init(UX600_DEBUG_UART, ux600_clk_freq, + UX600_UART_BAUDRATE); } static void ux600_modify_dt(void *fdt) @@ -184,12 +187,6 @@ static int ux600_final_init(bool cold_boot) return 0; } -static int ux600_console_init(void) -{ - return sifive_uart_init(UX600_DEBUG_UART, ux600_clk_freq, - UX600_UART_BAUDRATE); -} - static int ux600_irqchip_init(bool cold_boot) { int rc; @@ -234,7 +231,6 @@ static int ux600_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = ux600_early_init, .final_init = ux600_final_init, - .console_init = ux600_console_init, .irqchip_init = ux600_irqchip_init, .ipi_init = ux600_ipi_init, .timer_init = ux600_timer_init, diff --git a/platform/template/platform.c b/platform/template/platform.c index 4b3f2ac..b4d30a5 100644 --- a/platform/template/platform.c +++ b/platform/template/platform.c @@ -64,7 +64,12 @@ static struct aclint_mtimer_data mtimer = { */ static int platform_early_init(bool cold_boot) { - return 0; + if (!cold_boot) + return 0; + + /* Example if the generic UART8250 driver is used */ + return uart8250_init(PLATFORM_UART_ADDR, PLATFORM_UART_INPUT_FREQ, + PLATFORM_UART_BAUDRATE, 0, 1, 0); } /* @@ -76,16 +81,6 @@ static int platform_final_init(bool cold_boot) } /* - * Initialize the platform console. - */ -static int platform_console_init(void) -{ - /* Example if the generic UART8250 driver is used */ - return uart8250_init(PLATFORM_UART_ADDR, PLATFORM_UART_INPUT_FREQ, - PLATFORM_UART_BAUDRATE, 0, 1, 0); -} - -/* * Initialize the platform interrupt controller for current HART. */ static int platform_irqchip_init(bool cold_boot) @@ -143,7 +138,6 @@ static int platform_timer_init(bool cold_boot) const struct sbi_platform_operations platform_ops = { .early_init = platform_early_init, .final_init = platform_final_init, - .console_init = platform_console_init, .irqchip_init = platform_irqchip_init, .ipi_init = platform_ipi_init, .timer_init = platform_timer_init diff --git a/scripts/carray.sh b/scripts/carray.sh index 13f9d36..1fa2366 100755 --- a/scripts/carray.sh +++ b/scripts/carray.sh @@ -61,6 +61,7 @@ if [ -z "${ARRAY_NAME}" ]; then usage fi +printf "// Generated with $(basename $0) from $(basename ${CONFIG_FILE})\n" printf "#include <%s>\n\n" "${TYPE_HEADER}" for VAR in ${VAR_LIST}; do |