aboutsummaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)AuthorFilesLines
2024-05-07sbi: sbi_domain_context: Add spinlock for updating domain assigned_hartsAlvin Chang1-0/+3
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 <alvinga@andestech.com> Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-05-07lib: sbi: sse: fix typos, comments and spacing errorsClément Léger1-12/+12
Fix some errors spotted by Samuel while reviewing the SSE implementation. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reported-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-05-07lib: tests: Add test suite init functionIvan Orlov1-0/+2
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 <ivan.orlov0322@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-04-05lib: sbi: Simplify wait_for_coldboot() implementationAnup Patel1-1/+5
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 <apatel@ventanamicro.com>
2024-04-05include: sbi: Support byteorder macros in assemblyVivian Wang1-25/+30
Avoid using C types and casts if sbi/sbi_byteorder.h is included in assembly code Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-04-05lib: sbi: Add SSE support for PMU eventsClément Léger1-0/+3
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 <cleger@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-04-05lib: sbi: Add support for Supervisor Software Events extensionClément Léger3-1/+173
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 <cleger@rivosinc.com> Reviewed-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-19lib: sbi: Pass trap context pointer to sbi_ecall_handler()Anup Patel1-2/+2
To be consistent with other trap handlers, pass trap context pointer to sbi_ecall_handler(). Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Clément Léger <cleger@rivosinc.com>
2024-03-19lib: sbi: Remove regs parameter from trap irq handling functionsAnup Patel1-0/+2
The trap irq handling functions no longer require regs parameter so remove it. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
2024-03-19lib: sbi: Remove regs paramter of sbi_irqchip_process()Anup Patel1-3/+2
The irqchip handlers will typically not need pointer to trap registers so remove regs parameter of sbi_irqchip_process(). Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Clément Léger <cleger@rivosinc.com>
2024-03-19lib: sbi: Simplify parameters of sbi_illegal_insn_handler()Anup Patel1-2/+2
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 <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
2024-03-19lib: sbi: Simplify parameters of misaligned and access fault handlersAnup Patel1-8/+4
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 <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Clément Léger <cleger@rivosinc.com>
2024-03-19lib: sbi: Introduce trap contextAnup Patel1-1/+28
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 <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
2024-03-19include: sbi: Add trap_context pointer in struct sbi_scratchAnup Patel1-3/+12
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 <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
2024-03-19lib: sbi: Remove sbi_trap_exit() and related codeAnup Patel2-14/+3
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 <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Tested-by: Samuel Holland <samuel.holland@sifive.com>
2024-03-19lib: sbi: Remove epc from struct sbi_trap_infoSamuel Holland1-10/+6
In the only places this value is used, it duplicates mepc from struct sbi_trap_regs. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-11lib: sbi: call platform load/store emulatorsBo Gan1-0/+45
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 <ganboing@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-11include: sbi: add emulate_load/store handler to platform opsBo Gan1-0/+8
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 <ganboing@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-11lib: sbi: abstract out insn decoding to unify mem fault handlersBo Gan1-1/+12
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 <ganboing@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-11lib: sbi: change prototype of sbi_misaligned_load/store_handlerBo Gan1-4/+5
This simplifies both handlers such that when the handler needs to redirect the original trap, it's readily available. Signed-off-by: Bo Gan <ganboing@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-11lib: sbi: change prototype of sbi_trap_redirectBo Gan1-1/+1
sbi_trap_redirect now uses const pointer to `trap`. This ensures the caller that we never change `trap` in sbi_trap_redirect. Signed-off-by: Bo Gan <ganboing@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-11include: sbi: rename sbi_misaligned_ldst.h to sbi_trap_ldst.hBo Gan1-2/+2
Signed-off-by: Bo Gan <ganboing@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-10lib: sbi: Add initial domain context management supportQingyu Shang2-0/+83
The domain context management component in OpenSBI provides basic CPU context management routines for existing OpenSBI domain. As domain extension, it was initially designed to facilitate the suspension and resumption of domains, enabling secure domains to efficiently share CPU resources. The patch also provides an addition to the OpenSBI domain to provide updates on hart-domain assignment and declarations of contexts within the domain. Signed-off-by: Qingyu Shang <2931013282@sjtu.edu.cn> Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com> Tested-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-10lib: Add SBIUnit testing macros and functionsIvan Orlov1-0/+71
This patch introduces all of the SBIUnit macros and functions which can be used during the test development process. Also, it defines the 'run_all_tests' function, which is being called during the 'init_coldboot' right after printing the boot hart information. Also, add the CONFIG_SBIUNIT Kconfig entry in order to be able to turn the tests on and off. When the CONFIG_SBIUNIT is disabled, the tests and all related code is excluded completely on the compilation stage. Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2024-03-05lib: sbi_misaligned_ldst: Add handling of C.LHU/C.LH and C.SHNylon Chen1-0/+7
Added exception handling for compressed instructions C.LHU, C.LH, and C.SH from the zcb extension to the sbi_misaligned_ldst library. Signed-off-by: Nylon Chen <nylon.chen@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-04lib: sbi: Add support for smcsrind and smcdelegAtish Patra2-3/+30
Smcsrind allows generic indirect CSR access mechanism while Smcdeleg allows delegating hpmcounters in Supervisor mode. Enable both extensions and set the appropriate bits in mstateen and menvcfg. Co-developed-by: Kaiwen Xue <kaiwenxue1@gmail.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-02-20platform: generic: Add support for specify coldboot harts in DTCheng Yang1-0/+5
Added support for the generic platform to specify the set of coldboot hart in DT. If not specified in DT, all harts are allowed to coldboot as before. The functions related to sbi_hartmask are not available before coldboot, so I used bitmap, and added a new bitmap_test() function to test whether a certain bit of the bitmap is set. Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-01-10include: sbi: Add SBI debug trigger extension related definesHimanshu Chauhan1-0/+11
This patch adds defines for SBI debug trigger extension and function IDs to access the extension. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-01-10lib: sbi: Introduce the SBI debug triggers extension supportHimanshu Chauhan1-0/+125
RISC-V Debug specification includes Sdtrig ISA extension which describes Trigger Module. Triggers can cause a breakpoint exception or trace action without execution of a special instruction. They can be used to implement hardware breakpoints and watchpoints for native debugging. The SBI Debut Trigger extension (Draft v6) can be found at: https://lists.riscv.org/g/tech-debug/topic/99825362#1302 This patch is an initial implementation of SBI Debug Trigger Extension (Draft v6) in OpenSBI. The following features are supported: * mcontrol, mcontrol6 triggers * Breakpoint and trace actions NOTE: Chained triggers are not supported Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-01-10lib: sbi: Detect support of debug triggersHimanshu Chauhan1-0/+2
Detect if debug triggers, sdtrig extension, is supported by the CPU. The support is detected by access traps and ISA string parsing. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-01-10include: sbi: Introduce debug trigger register encodingsHimanshu Chauhan1-0/+249
This patch introduces Mcontrol and M6 control register encodings along with macros to manipulate them. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-01-10include: sbi: Add TINFO debug trigger CSRHimanshu Chauhan1-0/+1
Add the missing TINFO debug trigger CSR. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-01-10include: sbi: Introduce common endianess conversion macroHimanshu Chauhan1-0/+10
Introduce cpu_to_lle and lle_to_cpu macros which invoke correct word length cpu_to_le<64/32> conversion based on __riscv_xlen. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-27include: Bump-up version to 1.4v1.4Anup Patel1-1/+1
This patch updates OpenSBI version to 1.4 as part of release preparation. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Anup Patel <anup@brainfault.org>
2023-12-27lib: utils/timer: mtimer: only use regname for aclintInochi Amaoto1-1/+2
The parser will fail if the timer is clint timer and has regname property. As the regname is only meaningful for aclint, it is more robust to only check regname for aclint timer. Fixes: 6112d58 ("lib: utils/fdt: Allow to use reg-names when parsing ACLINT") Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-19lib: sbi: Remove the SBI_ETRAP error codeAnup Patel1-3/+2
The SBI_ETRAP error code was introduced only for doing trap redirection in generic sbi_ecall_handler(). Now the trap redirection is moved into sbi_ecall_legacy.c and SBI_ETRAP error code is only used in this source file so let us remove it. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-12-19lib: sbi: Allow ecall handlers to directly update register stateAnup Patel2-15/+16
Some of the upcoming SBI extensions (such as SSE) will directly update register state so improve the prototype of ecall handler to accommodate this. Further, this flexibility allows us to push the trap redirection from sbi_ecall_handler() to the sbi_ecall_legacy_handler(). Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-12-19lib: utils/irqchip: Add shared MMIO region for PLIC in root domainAnup Patel1-0/+1
On platforms with Smepmp, the MMIO regions accessed by M-mode need to be explicitly marked with M-mode only read/write or shared (both (M-mode and S-mode) read/write permission. If the above is not done then runtime PLIC access from M-mode on platforms with Smepmp will result in access fault when further results in CPU hotplug not working. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-12-19lib: sbi_tlb: Reduce size of struct sbi_tlb_infoAnup Patel1-13/+16
Let us reduce the size of struct sbi_tlb_info by doing the following: 1) Change the data type of asid and vmid fields to uint16_t 2) Replace local_fn() function pointer with an enum Based on the above, the size of struct sbi_tlb_info is reduced by 16 bytes on RV64 and 4 bytes on RV32. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-12-19lib: sbi: Detect extensions from the ISA string in DTYong-Xuan Wang1-0/+6
Enable access to some extensions through menvcfg and show them in "Boot HART ISA Extensions" if they are present in the device tree. Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-19lib: sbi: Using one array to define the name of extensionsYong-Xuan Wang1-0/+7
Define an array sbi_hart_ext to map extension ID and name , and use it for ISA parsing and printing out the supported extensions. Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-19lib: sbi: Refactor the code for enable extensions in menvfg CSRYong-Xuan Wang1-5/+0
Use 1 variable to store the value of menvcfg. Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-11lib: utils/fdt: Allow to use reg-names when parsing ACLINTInochi Amaoto1-0/+3
Currently, the fdt_parse_aclint_node() follows a fixed order to parse ACLINT timer. This may cause the undesirable result when the ACLINT device does not support mtime without adding an empty entry for it in the DT. To be robust, make fdt_parse_aclint_node() support "reg-names" property, so it can parse the DT in an order independent way. For compatibility, fdt_parse_aclint_node() only use "reg-names" when parsing ACLINT timer, and will fallback to the old way if "reg-names" property is not found. Link: https://lore.kernel.org/all/20231114-skedaddle-precinct-66c8897227bb@squawk/ Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup patel <anup@brainfault.org>
2023-12-11platform: recalculate heap size to support new tlb entry numberInochi Amaoto2-0/+4
Previous patch introduced a change that using hart count as the default number of tlb entries in the fifo. This makes the default tlb fifo size grow in square with the number of harts. So the default heap size is not enough to allocate tlb fifo when the hart count is big. Fixes: 52fd64b ("platform: Uses hart count as the default size of tlb info") Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-08lib: sbi_pmu: Fix the counter info functionAtish Patra1-0/+1
The counter info should only return valid hardware counters for the ones set in the counter mask. Otherwise, it will report incorrect number of hardware counters to the supervisor if the platform has discontiguous counters. Fixes: c744ed77b18c ("lib: sbi_pmu: Enable noncontigous hpm event and counters") Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-08lib: sbi_pmu: Add PMU snapshot definitionsAtish Patra2-1/+6
OpenSBI doesn't support SBI PMU snapshot yet as there is not much benefit unless the multiple counters overflow at the same time. Just add the definition and return not supported error at this moment. The default returned error is also not supported. Thus, no functional change intended. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Atish Patra <atishp@rivosinc.com>
2023-12-08lib: sbi_hart: Store PMP granularity as log base 2Samuel Holland1-2/+2
This minimizes the need to call log2roundup() to recover the log value. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-08lib: sbi: Fix __atomic_op_bit_ord and commentsXiang W1-4/+4
The original code returns the value of the word before modification. When modifying the upper 32 bits under RV64, the value returned via int return will have no meaning. Corrected to return the value of the bit. And modify the function description. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-06lib: utils: fdt_pmu: Make the fdt_pmu_evt_select table global variableYu Chien Peter Lin1-1/+23
To allow platform override pmu_init() filling the translation table fdt_pmu_evt_select[] when PMU node doesn't provide such information, we need to share the table and its entry counter with other .c file. We also define the structures of PMU property in fdt_helper.h, so we can initialize the mappings in arrays. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-06sbi: sbi_pmu: Add hw_counter_filter_mode() to pmu deviceYu Chien Peter Lin1-0/+6
Add support for custom PMU extensions to set inhibit bits on custom CSRs by introducing the PMU device callback hw_counter_filter_mode(). This allows the perf tool to restrict event counting under a specified privileged mode by appending a modifier, e.g. perf record -e event:k to count events only happening in kernel mode. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>