aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2025-03-27lib: sbi: sse: Remove printf from sbi_sse_exit()Clément Léger1-4/+1
This printf is mainly useful for debugging, remove it. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2025-03-27lib: sbi: sse: Update SSE event idsClément Léger3-14/+42
The latest specification added new high priority RAS events and renamed the PMU to PMU_OVERFLOW. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2025-03-26lib: utils: Make sure that hartid and the scratch are alignedRaj Vishwanathan1-6/+3
Harts associated with an ACLINT_MSWI need not have sequential hartids. It is insufficient to use first_hartid and hart_count. To account for non-sequential hart ids, include the empty hart-ids' generate hart-count. Signed-off-by: Raj Vishwanathan <Raj.Vishwanathan@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-24lib: sbi: Use sbi_hart_count() and sbi_for_each_hartindex()Samuel Holland9-24/+11
Simplify the code and improve consistency by using the new macros where possible. sbi_hart_count() obsoletes sbi_scratch_last_hartindex(). Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-24lib: sbi_scratch: Add sbi_hart_count() and for_each_hartindex()Samuel Holland2-13/+16
There is currently no helper for iterating through the harts in a system, and code must choose between sbi_scratch_last_hartindex() and sbi_platform_hart_count() for the loop condition. sbi_scratch_last_hartindex() has unusual semantics, leading to the likelihood of off-by-one errors, and sbi_platform_hart_count() is provided by the platform and so may not be properly bounded. Add a new helper which definitively reports the number of harts managed by this OpenSBI instance, i.e. the number of valid hart indexes, and a convenient iterator macro. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-24lib: sbi_scratch: Optimize hartid and scratch lookupSamuel Holland2-5/+5
The compiler generates much better code for sbi_hartindex_to_hartid() and sbi_hartindex_to_scratch() when using a constant for the bounds check. This works out nicely because the underlying arrays are already a constant size, so the only change needed is to fill the remainder of each array with the appropriate default/out-of-bounds value. The ellipsis in the designated initializer is a GCC extension (also supported by Clang), but avoids runtime initialization of the array. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-24lib: sbi_scratch: Apply bounds check to platform hart_countSamuel Holland2-13/+12
The internal limit on the number of harts is SBI_HARTMASK_MAX_BITS, as this value determines the size of various bitmaps and arrays (including hartindex_to_hartid_table and hartindex_to_scratch_table). Clamp the value provided by the platform, and drop the extra array element. Update the documentation to indicate that hart_index2id must be sized based on hart_count, and that hart indexes must be contiguous. As of commit 5e90e54a1a53 ("lib: utils:Check that hartid is valid"), there is no restriction on the valid hart ID values. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-24lib: sbi: Avoid GOT indirection for global symbol referencesSamuel Holland3-1/+18
OpenSBI is compiled with -fPIE, which generally implies dynamic linking. This causes the compiler to generate GOT references for global symbols in order to support runtime symbol interposition. However, OpenSBI does not actually perform dynamic linking, so the GOT indirection just adds unnecessary overhead. The GOT references can be avoided by declaring global symbols with hidden visibility, thus making them local to this dynamic object and non-interposable. GCC/Clang's -fvisibility parameter is insufficient for this purpose when referencing objects from other translation units; either __attribute__((visibility(...)) or the pragma is required. Use the pragma since it is easier to apply to every symbol. Additionally clean up the one GOT reference from inline assembly. With this change, a firmware linked with LLD does not contain either a GOT or a PLT, and a firmware linked with BFD ld contains only a GOT with a single (unreferenced, legacy) _GLOBAL_OFFSET_TABLE_ entry. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-24Revert "lib: utils/irqchip: Match against more specific compatible strings ↵Samuel Holland1-7/+1
first" This reverts commit 6019259dfbdf9322858b4e7cfc3d1448376e2aa0. Now that fdt_driver_init_by_offset() respects the compatible string fallback priority order, this workaround is no longer necessary. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-24lib: utils/fdt: Respect compatible string fallback prioritySamuel Holland1-21/+25
When matching drivers to DT nodes, always match all drivers against the first compatible string before considering fallback compatible strings. This ensures the most specific match is always selected, regardless of the order of the drivers or match structures, as long as no compatible string appears in multiple match structures. Fixes: 1ccc52c427f3 ("lib: utils/fdt: Add helpers for generic driver initialization") Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-23lib: sbi: Return SBI_EALREADY error code if SSE event is presentHimanshu Chauhan1-1/+1
Return SBI_EALREADY error code instead of SBI_EINVAL, in case an event is already added to the supported list. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-23scripts: Fix firmware binaries compilation in create-binary-archive.shAnup Patel1-1/+4
Currently, the generic libsbi.a is compiled in create-binary-archive.sh before platform specific firmwares so a libsbi.a without any SBI extension gets linked to the platform specific firmwares. To address this, remove the temporary build directory in create-binary-archive.sh before using it. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-03-23lib: tests: add bitwise operations unit testsDongdong Zhang2-0/+138
Added unit tests for various bitwise operations using SBI unit test framework. Signed-off-by: Dongdong Zhang <zhangdongdong@eswincomputing.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-23lib: sbi: Fix potential garbage data in string copy functionsDongdong Zhang1-8/+8
In the original implementation of `sbi_strcpy` and `sbi_strncpy`, if the destination buffer (`dest`) was longer than the source string (`src`), the functions did not ensure that the remaining bytes in `dest` were properly null-terminated. This could result in garbage data being present in the destination buffer after the copy operation, as the functions only copied characters from `src` without explicitly terminating `dest`. Signed-off-by: Dongdong Zhang <zhangdongdong@eswincomputing.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-03-23lib: add tests for sbi_ecall functionalityAkshay Behl3-1/+56
This patch adds unit tests for verifying the sbi_ecall version, impid handling, and extension registration functions. The tests ensure that the extension registration and unregistration work as expected. Signed-off-by: Akshay Behl <akshaybehl231@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19lib: sbi: fwft: Return SBI_ERR_DENIED_LOCKED when setting a locked featureClément Léger1-1/+1
Latest modifications to the spec mandates that a set on a lock feature returns SBI_ERR_DENIED_LOCKED. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19include: sbi: Add SBI_ERR_DENIED_LOCKEDClément Léger2-1/+3
Add SBI_ERR_DENIED_LOCKED and set it as the SBI_LAST_ERR which was wrongly set to SBI_ERR_BAD_RANGE. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19lib: utils/irqchip: Match against more specific compatible strings firstAlex Studer1-1/+7
The T-HEAD C90x PLIC has some special quirks, such as the S-mode delegation bit. OpenSBI currently handles this by checking the compatible string in the device tree. However, this matching is done in the order of the fdt_match array. So if a device tree contains both strings, for example: compatible = "thead,c900-plic", "riscv,plic0"; Then OpenSBI will match against the generic "riscv,plic0" string, since that appears first in the fdt_match array. This means it will fail to set the S-mode delegation bit, and Linux will fail to boot. In some cases, it is not possible to change the compatible string to just the T-HEAD PLIC, as older versions of Linux only recognize the RISC-V compatible string. This patch fixes that by moving the RISC-V string to the end, ensuring that the more specific options get matched first. Signed-off-by: Alex Studer <alex@studer.dev> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19lib: utils/fdt: Allocate fdt_pmu_evt_select on the heapSamuel Holland2-11/+11
This reduces .bss size by 8 KiB, and should reduce overall memory usage since most platforms will have significantly fewer than 512 entries in this table. At the same time, it removes the fixed table size limit. Since the table is only used within fdt_pmu.c, instead of updating the extern declaration, make the table local to this file. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19lib: utils/fdt: Remove redundant PMU property length checksSamuel Holland1-3/+3
If a property value is too small, len will be zero after the division on the next line, so the property will be ignored. This is the same behavior as when the length check fails. Furthermore, the first two length checks were already ineffectual, because each item in those arrays is 12 bytes long, not 8. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19lib: utils: Constify FDT driver definitionsSamuel Holland4-4/+4
The carray referencing these definitions assumes they are const. Fixes: 6a26726e08e4 ("lib/utils: reset: Add RPMI System Reset driver") Fixes: 13f55f33a1d3 ("lib: utils/suspend: Add RPMI system suspend driver") Fixes: 33ee9b8240fe ("lib: utils/hsm: Add RPMI HSM driver") Fixes: 591a98bdd549 ("lib: utils/cppc: Add RPMI CPPC driver") Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19lib: sbi: sse: fix invalid errors returned for sse_hart_mask/unmask()Clément Léger1-2/+2
When called twice, sse_hart_mask()/sse_hart_unmask() should return SBI_EALREADY_STOPPED/SBI_EALREADY_STARTED. This was currently inverted. Fixes: b919daf49582 ("lib: sbi: Add support to mask/unmask SSE events") Reported-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-19lib: sbi: Fix non-root domain startupAnup Patel3-14/+43
Currently, the sbi_sse_init() in cold boot path is called after sbi_domain_finalize() so boot HART of non-root domains will start before SSE cold boot init which can cause warm boot of such HARTs to crash in sbi_sse_init(). To address the above issue, factor-out the non-root domain startup from sbi_domain_finalize() function as a separate sbi_domain_startup() function which can be called after sbi_sse_init() in cold boot path. Fixes: 93f7d819fdeb ("lib: sbi: sse: allow adding new events") Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-02-18README: Remove comment about boolin toolchains being 64-bit onlyJoel Stanley1-3/+0
As of January 2025 they have riscv32-ilp32d and riscv64-lp64d: https://toolchains.bootlin.com/releases_riscv32-ilp32d.html https://toolchains.bootlin.com/releases_riscv64-lp64d.html Signed-off-by: Joel Stanley <joel@jms.id.au> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-18README: Update toolchain section to mention PIE requirementJoel Stanley1-7/+6
Since commit 76d7e9b8ee72 ("firmware: remove copy-base relocation"), the Makefile enforces PIE support. Signed-off-by: Joel Stanley <joel@jms.id.au> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-18README: Any arch host can be used to cross compileJoel Stanley1-1/+1
Verified by cross compiling from an arm64 host. Signed-off-by: Joel Stanley <joel@jms.id.au> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-13lib: sbi: Update MPXY framework and SBI extension as per latest specAnup Patel4-41/+55
The latest SBI 3.0 spec defines a new sbi_mpxy_get_shmem_size() function and simplifies sbi_mpxy_set_shmem() function so update the MPXY framework and SBI extension accordingly. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-02-13lib: utils: Add MPXY RPMI mailbox driver for System MSI service groupAnup Patel5-0/+300
The supervisor software can directly receive most of the system MSIs except P2A doorbell and MSIs preferred to be handled in M-mode. Add MPXY RPMI mailbox client driver for the System MSI service group. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-02-13include: sbi_utils: Update RPMI service group IDs and BASE service groupAnup Patel2-13/+7
The service group ID assignment and some of the BASE services have changes in the latest RPMI specification so let's update the RPMI implementation accordingly. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2025-02-13lib: utils: Populate MPXY channel attributes from RPMI channel attributesAnup Patel2-39/+65
Use the RPMI mailbox channel attributes to populate MPXY channel attributes instead of hard coding them. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-02-13lib: utils: Implement get_attribute() for the RPMI shared memory mailboxAnup Patel2-1/+47
To allow clients query service group version of a RPMI mailbox channel, implement get_attribute() callback for the RPMI shared memory mailbox controller. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-02-13include: sbi_utils: Include mailbox.h in rpmi_mailbox.h headerAnup Patel1-0/+1
The rpmi_mailbox.h uses structures defined in mailbox.h so let's include mailbox.h in rpmi_mailbox.h header. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2025-02-13lib: utils: Improve variable declarations in MPXY RPMI mailbox clientAnup Patel1-16/+13
The local variable declarations should be at the start of function and preferrably organized like a inverted pyramid. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2025-02-13lib: utils: Drop notifications from MPXY RPMI mailbox clientAnup Patel3-14/+0
Currently, the common MPXY RPMI mailbox client does not support notifications so no need for dummy notifications support. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2025-02-13lib: sbi: Improve local variable declarations in MPXY frameworkAnup Patel1-40/+25
The local variable declarations should be at the start of function and preferrably organized like a inverted pyramid. Signed-off-by: Anup patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2025-02-13lib: sbi: Fix capability bit assignment in MPXY frameworkAnup Patel1-6/+6
The capability bit assignment in MPXY framework does not match the SBI MPXY extension in latest SBI specification so update it. Fixes: 7939bf1329eb ("lib: sbi: Add SBI Message Proxy (MPXY) framework") Signed-off-by: Anup patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2025-02-13lib: utils: Introduce optional MPXY RPMI service group operationsAnup Patel2-4/+32
Some of the RPMI service groups may need additional context and special handling when transferring messages via underlying mailbox channel so introduce optional MPXY RPMI service group operations for this purpose. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-02-13lib: utils: Constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mboxAnup Patel2-8/+9
The mpxy_rpmi_mbox_data is provided by RPMI service group specific MPXY driver to the common MPXY RPMI mailbox client implementation so let's constantify mpxy_rpmi_mbox_data in mpxy_rpmi_mbox so that it is not accidently modified. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2025-02-13lib: utils: Split the FDT MPXY RPMI mailbox client into two partsAnup Patel6-154/+191
Instead of having one common FDT MPXY RPMI mailbox client drivers for various RPMI service groups, split this driver into two parts: 1) Common MPXY RPMI mailbox client library 2) MPXY driver for RPMI clock service group The above split enables having a separate MPXY driver for each RPMI clock service group and #1 (above) will allow code sharing between various MPXY RPMI drivers. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2025-02-13lib: sbi: increase the size of the string used for extension displayClément Léger1-1/+1
With the "max" QEMU cpu, the displayed extension string is truncated due to the buffer being too small. Increase it to 256 to display the full set of extensions correctly. Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12lib: utils: Initialize miscellaneous drivers in one passSamuel Holland32-254/+39
For driver subsystems that are not tightly integrated into the OpenSBI init sequence, it is not important that the drivers are initialized in any particular order. By putting all of these drivers in one array, they can all be initialized with a single pass through the devicetree. This saves about 10 ms of boot time on HiFive Unmatched. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12lib: utils/fdt: Remove fdt_find_match()Samuel Holland2-27/+0
Now that all drivers are using the fdt_driver functions for initialization, this function is unused and can be removed. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12lib: utils/irqchip: Use fdt_driver for initializationSamuel Holland6-41/+10
The irqchip driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_irqchip_init() performs a best-effort initialization of all matching DT nodes. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12platform: generic: thead: add Sophgo SG2044Inochi Amaoto1-10/+7
The Sophgo SG2044 is a new version of C920, although it supports sscofpmf, it still needs this pmu quirks its cores. Signed-off-by: Inochi Amaoto <inochiama@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12firmware: fw_base.S: Fix comments for _wait_for_boot_hartXiang W1-1/+1
Due to some historical issues, the value of BOOT_STATUS_BOOT_HART_DONE has changed and the comment message needs to be corrected. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12lib: utils:Check that hartid is validRaj Vishwanathan3-6/+6
It is possible that hartid may not be sequential and it should not be validated against SBI_HARTMASK_MAX_BITS. Instead we should check the index of the hartid, hart index, against SBI_HARTMASK_MAX_BITS. Signed-off-by: Raj Vishwanathan <Raj.Vishwanathan@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-12include: sbi: Align SBI trap registers to a nice boundaryRaj Vishwanathan1-2/+5
Align SBI_TRAP_CONTEXT_SIZE to a multiple of 16 bytes. If it is not aligned to 16 bytes for RV64, it can create performance problems. Aligning it correctly can fix the performance issues. Signed-off-by: Raj Vishwanathan <Raj.Vishwanathan@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-11lib: utils: Make the enforce permission bit configurable from DTChao Du1-1/+3
The domain_support.md documentation states that the enforce permission bit (BIT[6]) could be set in the "regions" property of a domain instance DT node. However, this bit is masked in the current implementation. This patch unmasks the bit to make it configurable from DT. Signed-off-by: Chao Du <duchao@eswincomputing.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-02-11lib: utils/fdt: update fdt_parse_aplic_node()Huang Borong1-2/+1
1. Initialize struct imsic_data imsic to 0 at definition to prevent the use of uninitialized memory, ensuring the variable starts with known values. 2. Remove the redundant memset call on the "aplic" parameter since the memory for aplic is allocated using sbi_zalloc() by the caller irqchip_aplic_cold_init(), which guarantees it is already set to 0. Signed-off-by: Huang Borong <huangborong@bosc.ac.cn> Reviewed-by: Anup Patel <anup@brainfault.org>
2025-01-30include: utils/fdt_helper: fix typo har't'idLeo Yu-Chi Liang1-1/+1
s/hard_id/hartid/ Signed-off-by: Leo Yu-Chi Liang <ycliang@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org>