summaryrefslogtreecommitdiff
path: root/lib/sbi/riscv_asm.c
AgeCommit message (Collapse)Author
2026-06-10lib: sbi: Move hart PMP functions to sbi_hart_pmp.cNicholas Piggin
The sbi_hart_pmp.c looks like a good place for the hart PMP CSR access functions. Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2026-06-10lib: sbi: Add hart_ prefix to PMP functionsNicholas Piggin
PMP functions that deal with hart PMP CSRs are given a sbi_hart_ prefix, to distinguish from RISC-V PMP encoding functions. The is_pmp_entry_mapped() function is changed a little more, to align with other PMP conventions, and made to return a bool to make it more obvious that it returns a bool and not an SBI_ return code. Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2026-06-10lib: sbi: Add sbi_pmp_is_enabled() helperNicholas Piggin
Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2026-06-10lib: sbi: Add PMP CSR read and write accessorsNicholas Piggin
PMPCFG CSR access is non-trivial as it requires shifting and masking, it makes PMP manipulation code simpler if this basic CSR read/write access is abstracted away. Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2026-06-10lib: sbi: Move RISC-V PMP encoding functions to sbi_pmp.cNicholas Piggin
Create a new file for handling the RISC-V PMP format and the new pmp_t type, as opposed to hart PMP CSR specific access. Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2026-06-10lib: sbi: split PMP encoding and CSR accessNicholas Piggin
Allow PMP encoding functions to be shared with non-hart PMP manipulation by splitting encoding / decoding and hart PMP CSR access into their own functions. Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2026-06-10lib: sbi: Introduce pmp_t typeNicholas Piggin
To help abstract details of PMP encoding and access, add a new pmp_t type which contains address and cfg in the format of the riscv CSRs. There is no functional change. Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-10-21lib: Allow custom CSRs in csr_read_num() and csr_write_num()Anup Patel
Some of the platforms use platform specific CSR access functions for configuring implementation specific CSRs (such as PMA registers). Extend the common csr_read_num() and csr_write_num() to allow custom CSRs so that platform specific CSR access functions are not needed. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2024-08-02lib: sbi: check result of pmp_get() in is_pmp_entry_mapped()Carlos López
pmp_get() may return an error if the given entry, given by the caller of is_pmp_entry_mapped(), is invalid. This results in the output parameters for pmp_get() being uninitialized. To avoid using garbage values, check the result and return early if necessary. This issue is not being hit because at the moment is_pmp_entry_mapped() is only being called from a single site with a valid hardcoded value. Signed-off-by: Carlos López <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-08-18lib: sbi: Add support for smcntrpmfKaiwen Xue
This adds the support for ISA extension smcntrpmf. When some inhibit flags are set by a lower privilege mode for new CSRs added by smcntrpmf, OpenSBI sets the appropriate values correspondingly. Signed-off-by: Kaiwen Xue <[email protected]> Signed-off-by: Kaiwen Xue <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2023-07-13lib: sbi: Add functions to manipulate PMP entriesHimanshu Chauhan
- Add a function to disable a given PMP entry. - Add a function to check if a given entry is disabled. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-11lib: sbi: Remove unnecessary semicolonXiang W
We have redundant semicolon at quite a few places so let's remove it. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2022-05-07lib: sbi: Remove 's' and 'u' from misa_string() outputAnup Patel
Both 's' and 'u' are not treated as ISA extensions since these are privilege modes so let's remove it from misa_string() output. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2022-05-07lib: sbi: Fix mhpmeventh access for rv32 in absence of sscofpmfAtish Patra
MHPMEVENT3H-31H are defined in sscofpmf extension. Thus, they should be accessed only if sscofpmf is present. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2022-03-27lib: pmp_set/pmp_get moved errors from runtime to compile timeXiang W
pmp_set/pmp_get calculates the location of the CSR register separately through conditional compilation. In the case of non-32-bit and 64-bit, we can report an error directly through #error without putting it at runtime Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-12-22lib: sbi: simplify pmp_set(), pmp_get()Heinrich Schuchardt
pmpcfg_csr and pmpcfg_shift are only negative for an unexpected value of __riscv_xlen. We can immediately return in this case. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Dong Du <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-12-02lib: sbi: Improve fatal error handlingJessica Clarke
BUG and BUG_ON are not informative and are rather lazy interfaces, only telling the user that something went wrong in a given function, but not what, requiring the user to find the sources corresponding to their firmware (which may not be available) and figure out how that BUG(_ON) was hit. Even SBI_ASSERT in its current form, which does include the condition that triggered it in the output, isn't necessarily very informative. In some cases, the error may be fixable by the user, but they need to know the problem in order to have any hope of fixing it. It's also a nuisance for developers, whose development trees may have changed significantly since the release in question being used, and so line numbers can make it harder for them to understand which error case a user has hit. This patch introduces a new sbi_panic function which is printf-like, allowing detailed error messages to be printed to the console. BUG and BUG_ON are removed, since the former is just a worse form of sbi_panic and the latter is a worse version of SBI_ASSERT. Finally, SBI_ASSERT is augmented to take a set of arguments to pass to sbi_panic on failure, used like so (sbi_boot_print_hart's current error case, which currently manually calls sbi_printf and sbi_hart_hang): SBI_ASSERT(xlen >= 1, ("Error %d getting MISA XLEN\n", xlen)); The existing users of BUG are replaced with calls to sbi_panic along with informative error messages. BUG_ON and SBI_ASSERT were unused (and, in the case of SBI_ASSERT, remain unused). Many existing users of sbi_hart_hang should be converted to use either sbi_panic or SBI_ASSERT after this commit. Signed-off-by: Jessica Clarke <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-11-12lib: sbi: clear pmpcfg.A before setting in pmp_set()Xiang W
We should clear A bits in prot variable before enabling A_NA4 or A_NAPOT. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-11-11lib: sbi: Update csr_read/write_num for PMUAtish Patra
The Sscofpmf extension introduces mhpmevent[h] csrs to handle filtering /overflow bits in RV32. There is no way to read/write mcountinhibit using mcountinhibit csr using a variable. Updated the support to read/write mhpmevent[h] and mcountinhibit csr. Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2021-09-22lib: sbi: Add BUG() macro for csr_read/write_num() and misa_string()Xiang W
We use BUG() macro in csr_read_num(), csr_write_num(), and misa_string() functions for unhandled cases. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-09-22lib: sbi: fix ctz bugXiang W
The original version of ctz will cause an endless loop, if the parameter passed in is 0. This commit fixes this bug. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-07-11lib: sbi: Use csr_read/write_num to read/update PMU countersAtish Patra
Currently, csr_read/write_num functions are used to read/write PMP related CSRs where CSR value is decided at runtime. Expand this function to include PMU related CSRs as well. Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2020-09-16lib: sbi: Allow specifying mode in sbi_hart_pmp_check_addr() APIAnup Patel
We extend sbi_hart_pmp_check_addr() API so that users can specify privilege mode of the address for checking PMP access permissions. To achieve this, we end-up converting "unsigned long *size" parameter to "unsigned long *log2len" for pmp_get() implementation so that we can deal with regions of "1UL << __riscv_xlen" size in a special case in sbi_hart_pmp_check_addr() implementation. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-09-01lib: sbi: Improve PMP CSR detection and progammingAnup Patel
As-per latest RISC-V privilege spec up to 64 PMP entries are supported. Implementations may implement zero, 16, or 64 PMP CSRs. All PMP CSR fields are WARL and may be hardwired to zero. This patch improves PMP CSR detection and progamming considering above facts. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-06-20lib: sbi: Fix 32/64 bits variable compatibilityLiush
On RV64,"unsigned long" is 64bit and "unsigned int" is 32bit. So in function "pmp_get" and "pmp_set", if "pmpcfg_shift >= 32", "0xff << pmpcfg_shift" will go beyond "unsigned int" width. This patch tries to fix this issue. In function 'pmp_get': cfgmask = (0xff << pmpcfg_shift); --> cfgmask = (0xffUL << pmpcfg_shift); In function 'pmp_set': cfgmask = ~(0xff << pmpcfg_shift); --> cfgmask = ~(0xffUL << pmpcfg_shift); Signed-off-by: Liush <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2020-05-07lib: sbi: Improve misa_string() implementationAnup Patel
The RISC-V ISA string does not follow alphabetical order. Instead, we have a RISC-V specific ordering of extensions in the RISC-V ISA string. This patch improves misa_string() implementation to return a valid RISC-V ISA string. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-03-18lib: sbi: Update pmp_get() to return decoded size directlyBin Meng
Currently pmp_get() returns the log2 length of the PMP memory region size. The caller has to calculate the size based on that and the same codes are duplicated. Update this function to return decoded size directly. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-03-10lib: sbi: Fix coding style issuesBin Meng
This fixes various coding style issues found in the SBI codes. No functional changes. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2020-02-18Revert "lib: Use __builtin_ctzl() in pmp_get()"Anup Patel
This reverts commit 897b8fbdd92fcfad194417d348b8dad16ab0e17a. We are seeing compile errors using newlib based GCC cross-toolchain so we restore back old ctz() implementation. Signed-off-by: Anup Patel <[email protected]>
2020-02-13lib: Use __builtin_ctzl() in pmp_get()Li Jinpei
We should should __builtin_ctzl() in pmp_get() instead of custom ctz() function. Signed-off-by: Li Jinpei <[email protected]> Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-11-27lib: Add error detection for misa_extensionXiang W
Add assertions for misa_extension to prevent incoming illegal characters. Signed-off-by: Xiang Wang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-11-26lib: Fix CPU capabilities detection functionXiang Wang
On some platforms, misa may not be implemented. On such a platform, reading misa will get 0. At this time, platform is required to implement a non-standard function to detect the CPU's capabilities. Therefore, this modification add interfaces for non-standard function. The MXL field of misa is always at the highest two bits, whether it is a 32-bit 64-bit or a 128-bit machine. Therefore, this modification fixes the use of a fixed offset to detect the machine length. Signed-off-by: Xiang Wang <[email protected]> Signed-off-by: Anup Patel <[email protected]>
2019-06-19lib: Move sbi core library to lib/sbiAtish Patra
Signed-off-by: Atish Patra <[email protected]> Acked-by: Anup Patel <[email protected]>