summaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_ecall.c
AgeCommit message (Collapse)AuthorFilesLines
2024-12-22lib: sbi: Print list of available SBI extensions at boot-timeAnup Patel1-0/+24
Add boot-time prints for list of available standard and experimental SBI extensions. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-11-28treewide: Make carray arrays const and NULL-terminatedSamuel Holland1-3/+2
This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-03-19lib: sbi: Pass trap context pointer to sbi_ecall_handler()Anup Patel1-1/+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>
2023-12-19lib: sbi: Allow ecall handlers to directly update register stateAnup Patel1-9/+4
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-05-21lib: sbi: Introduce register_extensions extension callbackAndrew Jones1-1/+4
Rather than registering all extensions on their behalf in sbi_ecall_init(), introduce another extension callback and invoke that instead. For now, implement each callback by simply registering the extension, which means this patch has no intended functional change. In later patches, extension callbacks will be modified to choose when to register and to possibly narrow the extension ID range prior to registering. When an extension range needs to remove IDs, leaving gaps, then multiple invocations of sbi_ecall_register_extension() may be used. In summary, later patches for current extensions and the introductions of future extensions will use the new callback to ensure that only valid extension IDs from the initial range, which are also available, will be registered. Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-04-17lib: sbi: Don't check SBI error range for legacy console getcharAnup Patel1-1/+3
The legacy console getchar SBI call returns character value in the sbiret.error field so the "SBI_SUCCESS < ret" check in sbi_ecall_handler() results in unwanted error prints for the legacy console getchar SBI call. Let's suppress these unwanted error prints. Fixes: 67b2a408924b ("lib: sbi: sbi_ecall: Check the range of SBI error") Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-02-27lib: sbi: sbi_ecall: Check the range of SBI errorYu Chien Peter Lin1-1/+1
We should also check if the return error code is greater than 0 (SBI_SUCCESS), as this is an invalid error. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-01-06treewide: Replace TRUE/FALSE with true/falseBin Meng1-2/+2
C language standard uses true/false for the boolean type. Let's switch to that for better language compatibility. Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Samuel Holland <samuel@sholland.org> Tested-by: Samuel Holland <samuel@sholland.org>
2022-10-23lib: sbi_ecall: Generate extensions list with carrayVivian Wang1-28/+11
Instead of hard-coding the list of extensions in C code, use carray to generate the list of extensions. Using carray makes adding and removing extensions slightly cleaner. This also paves the way for using Kconfig to disable unneeded extensions. Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2021-07-11lib: sbi: Implement SBI PMU extensionAtish Patra1-0/+3
RISC-V SBI specfication 0.3 defines a PMU extension that allows supervisor mode to start/stop/configure pmu related events. This patch implements all of the functionality defined in the specification. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-01-07lib: sbi: Replace args with trap registers in ecall handlerAnup Patel1-9/+1
We had added args pointer in ecall handler to ensure that ecall handler only implements functionality and does not deal with SBI calling convention. This also helped us to keep SBI calling convention related code in one place at sbi_ecall_handler(). The Keystone Enclavce project needs access to the trap regsiters in their ecall handler so that they can context switch enclaves in custom SBI calls. To help the Keystone Enclave project, we replace the args pointer in ecall handler parameter with a const pointer to trap registers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01lib: sbi: Implement System Reset (SRST) SBI extensionAnup Patel1-0/+3
The SBI SRST extension has been accepted and merged in the latest SBI v0.3-draft specification. (Refer, https://github.com/riscv/riscv-sbi-doc) It allows to S-mode software to request system shutdown, cold reboot, and warm reboot. This patch implements SBI SRST extension as a replacement of the legacy sbi_shutdown() call of SBI v0.1 specification. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-06-20lib: Don't return any invalid error from SBI ecallAnup Patel1-0/+8
We should only return valid error codes from SBI ecalls as defined by the RISC-V SBI spec. To achieve this: 1. We use SBI_Exxxx defines for OpenSBI internal errors with error values starting from -1000 2. We use SBI_ERR_xxxx defines for errors defined by SBI spec 3. We map some of the SBI_Exxxx defines to SBI_ERR_xxxx defines which are semantically same 4. We throw a error print and force return error code to SBI_ERR_FAILED in sbi_ecall_handler() if we see an invalid error code being returned to S-mode Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-04-19lib: Allow overriding SBI implementation IDAnup Patel1-0/+12
Ideally, the SBI implementation ID for OpenSBI should always be 0x1 (as mentioned in SBI v0.2 spec) but external firmware (such as EDK2) which use OpenSBI as library might want to override the SBI implementation ID with their custom implementation ID. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: sbi_ecall: Remove mcause, scratch and hartid parametersAnup Patel1-3/+2
We remove mcause, scratch and hartid parameters from various functions for ecall handling because we can always get current HART id and current scratch pointer using just one CSR access. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: sbi_trap: Remove scratch parameter from sbi_trap_redirect()Anup Patel1-1/+1
The scratch parameter of sbi_trap_redirect() is not used hence we remove it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: Fix sbi_ecall_register_extension to prevent extension IDs overlapXiang Wang1-3/+11
The original code does not prevent the following scenarios: > sbi_ecall_register_extension(ext1); /* extension id (70-80) */ > sbi_ecall_register_extension(ext2); /* extension id (50-100) */ Signed-off-by: Xiang Wang <merle@hardenedlinux.org> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-10lib: sbi: Fix coding style issuesBin Meng1-1/+2
This fixes various coding style issues found in the SBI codes. No functional changes. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-02-24lib: Implement Hart State Management (HSM) SBI extensionAtish Patra1-0/+3
This patch adds support HSM extension. The specification is available at https://github.com/riscv/riscv-sbi-doc. It allows to implement hart hotplug and fixed ordered hart booting in supervisor. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-02-13lib: Initialize out value in SBI callsAtish Patra1-1/+1
As per the SBI specification, the return value in sbiret is undefined if not explicitly described in the function. However, supervisor may check this value by mistake and get a garbage value. Initialize it to zero to avoid nasty supervisor bugs. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-01-22lib: Factor-out SBI base extensionAnup Patel1-71/+0
This patch factor-out SBI base extension into its own source for better modularity of SBI implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Factor-out SBI vendor extensionAnup Patel1-27/+2
This patch factor-out SBI vendor extension into its own source for better modularity of SBI implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Factor-out SBI replacement extensionsAnup Patel1-133/+0
This patch factor-out SBI replacement extensions (such as RFENCE, IPI, and TIME) into its own source for better modularity of SBI implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Factor-out SBI legacy extensionAnup Patel1-102/+1
This patch factor-out SBI legacy extension into its own source for better modularity of SBI implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Add dynamic registration of SBI extensionsAnup Patel1-66/+174
This patch extends our SBI ecall implementation to allow dynamic registration of various SBI extensions. Using this dynamic registration we can break-up SBI ecall implementation into multiple files and even register experimental/custom SBI extensions from platform code. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Drop _fifo from the name of various sbi_tlb_fifo_xyz() functionsAnup Patel1-20/+10
This patch drops _fifo from the name of various sbi_tlb_fifo_xyz() functions because all these functions deal with remote TLB managment and FIFO is the per-HART data structure used internally by remote TLB implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Introduce sbi_tlb_fifo_request() APIAnup Patel1-33/+20
Instead of directly calling sbi_ipi_send_many(), we introduce sbi_tlb_fifo_request() for halting a set of HARTs. This way in future we can assign any IPI event number for remote FENCE within sbi_tlb.c only. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-01-22lib: Introduce sbi_ipi_send_smode() APIAnup Patel1-4/+2
Instead of directly calling sbi_ipi_send_many(), we introduce sbi_ipi_send_smode() for injecting S-mode software interrupts. This way in future we can assign any IPI event number for S-mode IPIs within sbi_ipi.c only. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-12-23lib: Implement RFENCE extensionAtish Patra1-1/+94
This patch adds RFENCE extension support in OpenSBI. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-12-23lib: Add IPI extension in SBIAtish Patra1-11/+59
This patch adds new IPI extension which replaces ipi related v0.1 extensions. This also adds a new API for ipi sending as trap handling is not necessary in v0.2 SBI IPI related extensions. It also modifies the IPI sending code which now accepts hart mask as a value instead of S-mode virtual address. Thus, the caller should set it to exact hart mask value everytime. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-12-23lib: Add TIME extension in SBIAtish Patra1-5/+25
This patch adds support for TIME extension which replaces v0.1 timer extension. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-12-23lib: Remove redundant IPI typesAtish Patra1-3/+3
We just need to distinguish only between FENCE and non FENCE related IPIs as all of the fence related requests are handled via fifo now. Remove the unnecessary IPI types related to individual fence types. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-11-26lib: Fix probe extensionAtish Patra1-0/+1
The break statement is missing in base extension function handling. Fix the typo. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Xiang Wang <merle@hardenedlinux.org> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-11-21lib: Simplify trap parameters in sbi_ecall functionsAnup Patel1-25/+18
The out_tcause and out_tval parameters are not sufficient for most sbi_ecall functions because this will grow in-future when we support RISC-V hypervisor v0.5 draft. We replace these parameters with out_trap which is a pointer to struct sbi_trap_info. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-11-21lib: Better naming of unpriv APIs for wider useAnup Patel1-8/+7
The unpriv APIs can be useful to external firmware and out-of-tree platform support code. This patch adds "sbi_" prefix to unpriv load/store APIs and rename struct riscv_unpriv to struct sbi_trap_info everywhere. We also place struct sbi_trap_info in sbi/sbi_trap.h so that we can use it for sbi_trap_redirect() as well. Overall, this patch will make naming of unpriv APIs consistent with other OpenSBI APIs. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-10-03lib: Provide a platform hook to implement vendor specific SBI extensions.Atish Patra1-3/+26
SBI v0.2 specification allows vendor extensions and it should be implemented in a independent of the core sbi library. Introduce a single platform callback that will let platforms handle all vendor extensions in platform specific code if they want. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-10-03lib: Implement SBI v0.2Atish Patra1-31/+125
SBI v0.2 introduces a base specification which is mandatory to implement for any SBI implementations that is not legacy. Add support for the base extension. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-10-03lib: Remove redundant variable assignmentAtish Patra1-10/+2
An ecall handler should only return error if valid SBI function fails. Otherwise, it should succeed with appropriate error in a0. Get rid of unnecessary setting of the temporary return variable to zero for the cases where errors are not expected. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-10-03lib: Rename existing SBI implementation as 0.1.Atish Patra1-18/+36
Current SBI implementation is now considered as version 0.1 and will be removed/replaced with newer extension/functions in future. Rename the existing implementations accordingly to be in sync with the specification. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Zong Li <zong.li@sifive.com>
2019-08-16lib: Fix race conditions in tlb fifo access.Atish Patra1-1/+9
Linux kernel expects tlb flush SBI call to be completely synchronous i.e. the SBI call should only return once corresponding *fence* instruction is executed. OpenSBI manages the outstanding TLB flush requests by keeping them in a per hart based fifo. However, there are few corner cases that may lead to race conditions while updating the fifo. Currently, the caller hart waits for IPI acknowledgement via clint address which is not a very good method as synchronization on MMIO may not be supported in every platform. Moreover, the waiter doesn't have any way of identifying if the IPI is received for specific tlb flush request or any other IPI. This may lead to unpredictable behavior in supervisor/user space. Fix this by waiting on individual fifo entries rather than MMIO address. Currently, a relaxed loop is being used because wfi again involves MMIO write which would be slower compared to relaxed loop. To avoid deadlock, fifo is processed every time a hart loops for fifo enqueue or fifo sync to consume the tlb flush requests sent by other harts. Signed-off-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-06-19lib: Move sbi core library to lib/sbiAtish Patra1-0/+107
Signed-off-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>