summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2024-05-13lib: sbi: fix hart_shmem_baseXiang W
When only phys_hi is equal to SBI_DBTR_SHMEM_INVALID_ADDR, it may be a legal address. The old code would modify the legal address. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Himanshu Chauhan <[email protected]>
2024-05-09platform: generic: thead: add Canaan Kendryte K230Yangyu Chen
Canaan Kendryte K230 SoC has T-Head C908 cores inside. The dt-binding has been merged into the linux kernel [1]. However, it has early version of C908 core which does not have Sscofpmf and need to use T-Head PMU extension. Thus, we add a K230 compatible string to thead_generic_match and set quirk for T-Head PMU. [1] https://lore.kernel.org/linux-riscv/[email protected]/ Signed-off-by: Yangyu Chen <[email protected]> Reviewed-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-09platform: generic: thead: separate T-Head PMU ErrataYangyu Chen
As Guo Ren said from the kernel mailing list [1], future T-Head CPUs, including the newer versions of T-Head C908, will feature standard Sscofpmf extension. For these CPUs, T-Head's implementation of PMU Overflow Interrupts may not needed anymore. In this case, we shouldn't apply T-Head PMU for all T-Head CPUs. Thus, this patch separated T-Head PMU errata. [1] https://lore.kernel.org/linux-riscv/[email protected]/ Signed-off-by: Yangyu Chen <[email protected]> Reviewed-by: Inochi Amaoto <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-09platform: andes: Change all occurrences of andes45 to andesBen Zong-You Xie
To make the framework suit all Andes CPUs, change all occurrences of andes45 to andes. In addition, we fix some coding style problems and remove an unused macro in andes.h. Signed-off-by: Ben Zong-You Xie <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-09platform: andes: Rename files with the prefix andes45Ben Zong-You Xie
Rename files with the prefix andes45 to andes. Signed-off-by: Ben Zong-You Xie <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07sbi: sbi_domain_context: Add spinlock for updating domain assigned_hartsAlvin Chang
Add spinlock protection to avoid race condition on assigned_harts during domain context switching. Also, rename/add variables for accessing the corresponding domain of target/current context. Signed-off-by: Alvin Chang <[email protected]> Reviewed-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: Refine the settings for switching to Virtual Supervisor Mode.Pope B.Lei
Although Mstatus.MPV is set, before executing mret, access to VS mode registers should use the actual register addresses, not the pseudonyms of S registers. Signed-off-by: Pope B.Lei <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: check handler entry to belong to supervisor modeClément Léger
When registering an SSE event, check for the handler_entry_pc to belong to supervisor mode domain using sbi_domain_check_addr_range(). Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: use PRV_S instead of hardcoded value for modeClément Léger
Rather then passing 1 to sbi_domain_check_addr_range() for supervisor mode, use PRV_S. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: call enable callback before sending IPIClément Léger
Move the enable callback call before sending the IPI. Even though the event is locked and no race condition can happen, this is more logical. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: remove superfluous sbi_list_empty() checkClément Léger
The list loop below that check is actually not looping if the list is empty so there was no need for this check. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: simplify 32bits overflow checkClément Léger
Rather than checking 32bits overflow with some absolute value, check the value to be different from the cast itself. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: rename sse_hart_unlock() to sse_enabled_event_unlock()Clément Léger
There was a naming incoherency between enabled events list lock/unlock. Rename sse_hart_unlock() to sse_enabled_event_unlock() to be coherent and reword comments above lock()/unlock() functions. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: sbi: sse: fix typos, comments and spacing errorsClément Léger
Fix some errors spotted by Samuel while reviewing the SSE implementation. Signed-off-by: Clément Léger <[email protected]> Reported-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: tests: Add test for spinlocksIvan Orlov
Implement the test which covers some of the functions from the `riscv_locks.h` file. This test consists of 3 test cases: 1) For lock/unlock functions 2) Unsuccessful trylock (the lock was previously taken) 3) Successful trylock (the lock is free and can be taken) Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: tests: Add test for atomic_tIvan Orlov
Implement the test which covers some of the functions from the `riscv_atomic.h` header file. The test contains 9 test cases: 1) atomic read/write test 2) add/return test 3) sub/return test 4) cmpxchg test 5) atomic_xchg test 6) atomic_raw_set_bit test 7) atomic_raw_clear_bit test 8) atomic_set_bit test 9) atomic_clear_bit test Some of the test cases operate on the `test_atomic` variable. It gets initialized in the suite init function. Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07lib: tests: Add test suite init functionIvan Orlov
Allow to define an init function for the test suite. It could help us to initialize global variable once, and use them in multiple test cases after the initialization. For instance, if multiple test cases use the same atomic_t var, it could be helpful to call ATOMIC_INIT once during the suite initialization. Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-10firmware: remove FW_TEXT_STARTXiang W
Now opensbi can run at any address via dynamic relocation. We can remove FW_TEXT_START. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2024-04-10lib: utils: check correct value in fdt_node_offset_by_compatibleHeinrich Schuchardt
After calling fdt_node_offset_by_compatible() we must check its return value and not an unrelated value. Addresses-Coverity-ID: 1584993 Logically dead code Fixes: 67ce5a763cfb ("platform: generic: Add support for specify coldboot harts in DT") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-10lib: sbi: sse_event_get() may return NULLHeinrich Schuchardt
sse_event_get() may return NULL. We should not dereference the return value in sbi_sse_exit() without checking. Fixes: c8cdf01d8f3a ("lib: sbi: Add support for Supervisor Software Events extension") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-10lib: sbi: Add missing sscrind and sscfg extensions in sbi_hart_ext[]Clément Léger
The sbi_hart_ext[] array is missing these two extensions ids. It is expected that this array contains all the extensions declaration at the same index of the SBI_HART_EXT_* define. Without this, when adding a new extension, there is a mismatch between ids and extension names and it can even display corrupted extension names. Addresses-Coverity-ID: 1584994 Out-of-bounds read Fixes: 6bb6b61c27eb ("lib: sbi: Add support for smcsrind and smcdeleg") Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-08Makefile: Remove unnecessary dependenciesSamuel Holland
The rule included from auto.conf.cmd adds a dependency on every Kconfig file, so these two Kconfig files do not need to be specified again here. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2024-04-07Makefile: Respect manual changes to .configSamuel Holland
The .config file may be manually edited or copied from another location. Since genconfig.py is responsible for generating auto.conf (the Makefile fragment) and autoconf.h (the C header) from .config, it must be run any time .config changes, not just when running menuconfig. Fixes: 662e631ccef2 ("Makefile: Add initial kconfig support for each platform") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2024-04-05sbi: sbi_domain_context: Check privilege spec version before accessing ↵Yu Chien Peter Lin
S-mode CSRs SCOUNTEREN and SENVCFG may not be supported on certain RISC-V core, so check the existence of these CSRs via privilege spec version to prevent illegal instructions. Signed-off-by: Yu Chien Peter Lin <[email protected]> Signed-off-by: Alvin Chang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05lib: sbi: Wakeup non-coldboot HARTs early in the coldboot pathAnup Patel
Currently, all non-coldboot HARTs busy spin in wait_for_coldboot() until the entire coldboot init sequence is completed. This means: 1) On QEMU, all non-coldboot HARTs will eat host CPU time and also slow down the coldboot HART until the entire coldboot init sequence is completed. 2) On real HW, all non-coldboot HARTs will consume more CPU power until the entire coldboot init sequence is completed. To address this, wake up all non-coldboot HARTs as early as possible in the coldboot init sequence. Signed-off-by: Anup Patel <[email protected]>
2024-04-05lib: sbi: Simplify wait_for_coldboot() implementationAnup Patel
On QEMU virt machine with large number of HARTs, some of the HARTs randomly fail to come out of wait_for_coldboot() due to one of the following race-conditions: 1) Failing HARTs are not able to acquire the coldboot_lock and update the coldboot_hartmask in wait_for_coldboot() before the coldboot HART acquires the coldboot_lock and sends IPI in wake_coldboot_harts() hence the failing HARTs never receive IPI from the coldboot HART. 2) Failing HARTs acquire the coldbood_lock and update the coldboot_hartmask before coldboot HART does sbi_scratch_init() so the sbi_hartmask_set_hartid() does not update the coldboot_hartmask on the failing HARTs hence they never receive IPI from the coldboot HART. To address this, use a simple busy-loop in wait_for_coldboot() for polling on coldboot_done flag. Signed-off-by: Anup Patel <[email protected]>
2024-04-05platform: generic: allwinner: Optimize current hart scratch accessSamuel Holland
The address of the local scratch area is stored in each hart's mscratch CSR. It is more efficient to read the CSR than to compute the address from the hart ID. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05lib: utils/timer: Optimize current hart scratch accessSamuel Holland
The address of the local scratch area is stored in each hart's mscratch CSR. It is more efficient to read the CSR than to compute the address from the hart ID. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05include: sbi: Support byteorder macros in assemblyVivian Wang
Avoid using C types and casts if sbi/sbi_byteorder.h is included in assembly code Signed-off-by: Vivian Wang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05lib: sbi: Add SSE support for PMU eventsClément Léger
Add SSE callbacks registration to PMU driver in order to disable interrupt delegation for PMU interrupts. When interrupts are undelegated send the PMU SSE event upon LCOFIP IRQ. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05lib: sbi: Implement SBI SSE extensionClément Léger
The SBI SSE extension defines a set of function that can be called to register and handle supervisor sofwtare events. This patch implements all of the functionality defined in the specification. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05lib: sbi: Add support for Supervisor Software Events extensionClément Léger
This extension [1] allows to deliver events from SBI to supervisor via a software mechanism. This extension defines events (either local or global) which are signaled by the SBI on specific signal sources (IRQ, exceptions, etc) and are injected to be executed in supervisor mode. [1] https://lists.riscv.org/g/tech-prs/message/798 Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-04-05firmware: remove copy-base relocationXiang W
Remove copy-base relocations that are no longer needed. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-20platform: generic: allwinner: sun20i-d1: Remove duplicated CSR definitionsChristoph Müllner
All T-Head CSRs are already defined in thead/c9xx_encoding.h. Let's reuse the values from there instead of redefining them with a slightly different name. Signed-off-by: Christoph Müllner <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-20docs: writing_tests: Make docs correspond the latest changesIvan Orlov
We should store test object files list in the `libsbi-objs-y` Makefile variable, not in `libsbitests-objs-y`. Update the documentation correspondingly. Since we don't use the `console_dev` static variable directly in the `sbi_console_test` unit test anymore, remove the paragraph which says that we do. Fixes: 86224ec36aed ("docs/writing_tests: Update tests paths") Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-19lib: sbi: Extend sbi_trap_error() to dump state in a nested trapAnup Patel
The sbi_trap_error() should dump state of all in-flight traps upon failure in a nested trap so extend it accordingly. Signed-off-by: Anup Patel <[email protected]> Tested-by: Samuel Holland <[email protected]>
2024-03-19lib: sbi: Pass trap context pointer to sbi_ecall_handler()Anup Patel
To be consistent with other trap handlers, pass trap context pointer to sbi_ecall_handler(). Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]> Reviewed-by: Clément Léger <[email protected]>
2024-03-19lib: sbi: Remove regs parameter from trap irq handling functionsAnup Patel
The trap irq handling functions no longer require regs parameter so remove it. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]>
2024-03-19lib: sbi: Remove regs paramter of sbi_irqchip_process()Anup Patel
The irqchip handlers will typically not need pointer to trap registers so remove regs parameter of sbi_irqchip_process(). Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]> Reviewed-by: Clément Léger <[email protected]>
2024-03-19lib: sbi: Simplify parameters of sbi_illegal_insn_handler()Anup Patel
The struct sbi_trap_context already has the information needed by sbi_illegal_insn_handler() so directly pass struct sbi_trap_context pointer to this function. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]>
2024-03-19lib: sbi: Simplify parameters of misaligned and access fault handlersAnup Patel
The struct sbi_trap_context already has the information needed by misaligned load/store and access fault load/store handlers so directly pass struct sbi_trap_context pointer to these functions. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]> Reviewed-by: Clément Léger <[email protected]>
2024-03-19lib: sbi: Introduce trap contextAnup Patel
Club the struct sbi_trap_regs and struct sbi_trap_info a new struct sbi_trap_context (aka trap context) which must be saved by low-level trap handler before calling sbi_trap_handler(). To track nested traps, the struct sbi_scratch points to the current trap context and the trap context has pointer to pervious context of previous trap. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]>
2024-03-19include: sbi: Add trap_context pointer in struct sbi_scratchAnup Patel
To track nested traps, the struct sbi_scratch needs a pointer the current trap context so add trap_context pointer in struct sbi_context. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]>
2024-03-19lib: sbi: Remove sbi_trap_exit() and related codeAnup Patel
Over the years, no uses of sbi_trap_exit() have been found so remove it and also remove related code from fw_base.S and sbi_scratch.h. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]>
2024-03-19lib: sbi: Remove epc from struct sbi_trap_infoSamuel Holland
In the only places this value is used, it duplicates mepc from struct sbi_trap_regs. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-19docs/writing_tests: Update tests pathsIvan Orlov
Since the tests should be moved to the lib/sbi/tests directory, the documentation should be updated correspondingly. So, update the paths where they have to be changed. Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-19lib: tests: Move tests to a separate directoryIvan Orlov
Move all of the SBIUnit-related code into the lib/sbi/tests directory. Update 'Makefile' to index objects from the tests subdirectory. I don't think creating the full separate list of Makefile variables (libsbitests-objs-path-y, libsbitests-object-mks, etc. as it is done for libsbiutils) is necessary for the tests because: 1) `lib/sbi/tests/objects.mk` is already indexed into 'libsbi-objects-mks' since the find expression for the libsbi-object-mks variable looks for objects.mk files in the nested directories as well). 2) Tests are tightly coupled with the `lib/sbi/` sources, therefore it may be reasonable to store the list of lib/sbi and lib/sbi/tests object files together in the libsbi-objs-path-y variable. Additionally, update relative paths in the tests where necessary. Signed-off-by: Ivan Orlov <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-11lib: sbi: call platform load/store emulatorsBo Gan
sbi_load/store_access_handler now tries to call platform emulators if defined. Otherwise, redirects the fault. If the platform code returns failure, this means the H/S/U has accessed the emulated devices in an unexpected manner, which is very likely caused by buggy code in H/S/U. We redirect the fault, so lower privileged level can get notified, and act accordingly. (E.g., oops in Linux) We let the handler truly fail if the trap was originated from M mode. In this case, something must be very wrong and we should just fail. Signed-off-by: Bo Gan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-11include: sbi: add emulate_load/store handler to platform opsBo Gan
This patch allows the platform to define load/store emulators. This enables a platform to trap-and-emulate special devices or filter access to existing physical devices. Signed-off-by: Bo Gan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-03-11lib: sbi: abstract out insn decoding to unify mem fault handlersBo Gan
This patch abstracts out the instruction decoding part of misaligned ld/st fault handlers, so it can be reused by ld/st access fault handlers. Also Added lb/lbu/sb decoding. (previously unreachable by misaligned fault) sbi_trap_emulate_load/store is now the common handler which takes a `emu` parameter that is responsible for emulating the misaligned or access fault. The `emu` callback is expected to fixup the fault, and based on the return code of `emu`, sbi_trap_emulate_load/store will: r/wlen => the fixup is successful and regs/mepc needs to be updated. 0 => the fixup is successful, but regs/mepc should be left untouched (this is usually used if `emu` does `sbi_trap_redirect`) -err => failed, sbi_trap_error will be called For now, load/store access faults are blindly redirected. It will be enhanced in the following patches. Signed-off-by: Bo Gan <[email protected]> Reviewed-by: Anup Patel <[email protected]>