summaryrefslogtreecommitdiff
path: root/platform/generic/platform.c
AgeCommit message (Collapse)Author
2026-06-12platform: generic: Optimize extensions_init() to parse ISA extensions onceAnup Patel
Instead of parsing ISA extensions separately for each hart in the generic_extensions_init() function, it is better to parse ISA extensions for all available harts in the cold boot path. Also, this allows us to remove fdt_isa_bitmap from scratch space and directly initialize "extensions" in struct sbi_hart_features for each hart. Signed-off-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-12-16platform: generic: Keep some empty space in FDT passed to next stageAnup Patel
Leaving no empty space in the FDT passed to the next booting stage causes the following U-Boot crash on Ventana internal platforms: Unhandled exception: Load access fault EPC: 00000000fffa6372 RA: 00000000fffa7418 TVAL: 0001746174730068 EPC: 0000000080245372 RA: 0000000080246418 reloc adjusted SP: 00000000fef38440 GP: 00000000fef40e60 TP: 0000000000000000 T0: 00000000fef40a70 T1: 000000000000ff00 T2: 0000000000000000 S0: 00000000fffc17a8 S1: 00000000fef38d40 A0: 7375746174730068 A1: 00000000fffc17a8 A2: 0000000000000010 A3: 0000000000000010 A4: 0000000000000000 A5: 00000000fffc17b8 A6: 0000000000ff0000 A7: 000000000000b100 S2: 0000000000000000 S3: 0000000000000001 S4: 00000000fef38d40 S5: 7375746174730068 S6: 0000000000000000 S7: 00000000fef4eef0 S8: 00000000fef4ef90 S9: 0000000000000000 S10: 0000000000000000 S11: 00000000fef4efc0 T3: 00000000fef40ea8 T4: 0000000000ff0000 T5: 00000000fef40a60 T6: 00000000fef40a6c To address the above issue, keep some minimal empty space in the FDT instead of no empty space. Fixes: bbe9a23060e9 ("platform: generic: Pack the FDT after applying fixups") Signed-off-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-10-28lib: utils/cache: Add fdt cmo helpersNick Hu
Add the helpers to build up the cache hierarchy via FDT and provide some cmo functions for the user who want to flush the entire cache. Signed-off-by: Nick Hu <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-09-16lib: utils/ipi: Convert IPI drivers as early driversAnup Patel
The fdt_ipi_init() is already called from generic_early_init() so let's convert IPI drivers as early drivers. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Nick Hu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-09-16include: sbi: Remove platform specific IPI initAnup Patel
The platform specfic IPI init is not need anymore because using IPI device rating multiple IPI devices can be registered in any order as part of the platform specific early init. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Nick Hu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-08-28platform: generic: Pack the FDT after applying fixupsSamuel Holland
This minimizes the size that will be reserved by the OS for the FDT, and it prevents the FDT buffer from containing uninitialized memory, which can be important for some simulation platforms and for attestation. Closes: https://github.com/riscv-software-src/opensbi/issues/388 Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-05-20lib: utils: Fix fdt_mpxy_init() not returning error codeAlvin Chang
It seems that current implementation doesn't fail on fdt_mpxy_init(), because platforms might not have any MPXY devices. In fact, if there are no MPXY devices, fdt_driver_init_all() will return SBI_OK. More importantly, if there is any MPXY device which fails the initialization, OpenSBI must check the error code and stop the booting. Thus, this commit adds the return value for fdt_mpxy_init(). Signed-off-by: Alvin Chang <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-04-24lib: sbi: Set the scratch allocation to alignment to cacheline sizeRaj Vishwanathan
Set the scratch allocation alignment to cacheline size specified by riscv,cbom-block-size in the DTS file to avoid two atomic variables from the same cache line causing livelock on some platforms. If the cacheline is not specified, we set it a default value. Signed-off-by: Raj Vishwanathan <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-04-23lib: sbi_platform: Remove the vendor_ext_check hookSamuel Holland
Now that the generic platform only sets .vendor_ext_provider if the function is really implemented, there is no need for a separate hook to check if a vendor extension is implemented. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-04-23platform: generic: Initialize overrides with fdt_driverSamuel Holland
In addition to deduplicating the code, this also improves the match selection logic to respect the priority order of the compatible strings, as implemented in commit 0ffe265fd969 ("lib: utils/fdt: Respect compatible string fallback priority"). Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-04-23platform: generic: Remove platform override hooksSamuel Holland
Now that all of the overrides are modifying generic_platform_ops directly, remove the unused hooks and forwarding functions. The remaining members of struct platform_override match struct fdt_driver, so use that type instead. This allows a future commit to reuse the fdt_driver-based init function. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-04-23platform: generic: Allow replacing platform operationsSamuel Holland
Currently the generic platform follows the middleware pattern: it implements the sbi_platform hooks, while providing its own set of hooks for further customization. This has a few disadvantages: each location where customization is needed requires a separate platform_override hook, including places where the generic function does nothing except forward to a platform_override hook, and the extra layer of function pointers adds runtime overhead. Let's restructure the generic platform to follow the helper pattern. Allow platform overrides to treat the generic platform as a template, adding or replacing the sbi_platform_operations as needed. Export the generic implementations, so they can be called as helpers from inside the override functions. With this pattern, the platform_override function pointers are replaced by direct calls, and the forwarding functions can be removed. The forwarding functions are not exported, since there is no reason for an override to call them. generic_vendor_ext_check() must be rewritten, since now there is a new way to override vendor_ext_provider. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-04-23platform: generic: Add an init hook matching fdt_driverSamuel Holland
In preparation for reusing the fdt_driver code to match platform overrides, add a new .init hook matching the type signature from fdt_driver. This hook replaces the existing .fw_init hook, since it is called at roughly the same place in the init process. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2025-03-24lib: sbi: Use sbi_hart_count() and sbi_for_each_hartindex()Samuel Holland
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2025-02-12lib: utils: Initialize miscellaneous drivers in one passSamuel Holland
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2025-02-12lib: utils:Check that hartid is validRaj Vishwanathan
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-12-21platform: generic: Initialize console before other driversSamuel Holland
Initialize serial drivers first, so messages printed by other drivers do not need to use the early console buffer. Suggested-by: Anup Patel <[email protected]> Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-12-06lib: utils: Add simple FDT based MPXY driver frameworkAnup Patel
The generic platform can have multiple MPXY drivers so add a simple FDT based MPXY driver framework. Signed-off-by: Anup Patel <[email protected]>
2024-12-06lib: utils: Add simple FDT based CPPC driver frameworkAnup Patel
The generic platform can have multiple CPPC drivers so add a simple FDT based CPPC driver framework. Signed-off-by: Anup Patel <[email protected]>
2024-12-06lib: utils: Add simple FDT based HSM driver frameworkAnup Patel
The generic platform can have multiple HSM drivers so add a simple FDT based HSM driver framework. Signed-off-by: Anup Patel <[email protected]>
2024-12-06lib: utils: Add simple FDT based system suspend driver frameworkAnup Patel
The generic platform can have multiple system suspend drivers so add a simple FDT based system suspend driver framework. Signed-off-by: Anup Patel <[email protected]>
2024-12-02lib: sbi_pmu: PMU raw event v2 supportAtish Patra
As per the updated ISA specification and SBI PMU v3.0, lower 56 bits are available for the platform to implement mhpmeventX encoding. Implement the PMU raw event V2 support defined in SBI v3.0 which allows more bits for platforms to encode the raw events. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-11-28treewide: Make carray arrays const and NULL-terminatedSamuel Holland
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-11-28platform: Drop irqchip warm init and exit hooksSamuel Holland
Now that driver lifecycle is managed from within the SBI irqchip core, platforms need only to initialize the driver once during cold init. Remove the remaining platform hooks that are no longer used. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-11-11platform: Drop IPI warm init and exit hooksSamuel Holland
Now that the SBI IPI core clears IPIs at warm boot in a generic way, none of the drivers or platforms use these hooks, and we can remove them. Platforms need only to initialize the driver once during cold init. If other hooks are needed in the future, they can be added to struct sbi_ipi_device. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-11-11platform: introduce DT-based configurable heap sizeInochi Amaoto
The default heap size will work for most platforms, but for some special platforms, the heap is too small to hold all the information or is too big so that it take too much ram. Introduce configurable heap should solve this problem and make all generic platforms happy. Add DT-based heap-size for the generic platform. Signed-off-by: Inochi Amaoto <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-11-05platform: Drop timer warm init and exit hooksSamuel Holland
Now that driver lifecycle is managed from within the SBI timer core, platforms need only to initialize the driver once during cold init. Remove the remaining platform hooks that are no longer used. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-27platform: generic: Fix fw_platform_coldboot_harts_init() functionAnup Patel
It is possible that the OpenSBI config DT node is present but the "cold-boot-harts" DT property is not present. In this case, the fw_platform_coldboot_harts_init() will do nothing which in-turn causes OpenSBI firmware hang at boot time. To address the above issue, fallback to the default approach when the "cold-boot-harts" DT property is not present. Fixes: 67ce5a763cfb ("platform: generic: Add support for specify coldboot harts in DT") Signed-off-by: Anup Patel <[email protected]>
2024-08-24lib: utils/fdt: Add fdt_get_address_rw() helperSamuel Holland
Help tracking the lifecycle of the FDT blob by indicating which parts of the firmware modify it, and thus invalidate any previously-obtained offsets or pointers to data inside the blob. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/serial: Pass the FDT to fdt_serial_init()Samuel Holland
Indicate that this function does not modify the FDT blob, and deduplicate the call to fdt_get_address(). Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24lib: utils/reset: Pass the FDT to fdt_reset_init()Samuel Holland
Indicate that this function does not modify the FDT blob, and deduplicate the call to fdt_get_address(). Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24platform: generic: Pass FDT to early/final_init overridesSamuel Holland
Several of these override functions access the FDT blob. Explicitly indicate which callbacks are allowed to modify the FDT blob by passing the parameter as a possibly-const pointer. This also reduces code size by deduplicating the call to fdt_get_address(). Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-08-24platform: generic: Constify FDT pointers in fw_platform_init()Samuel Holland
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-07-24platform: Setup serial console device in early_init()Anup Patel
The sbi_console_init() does not do any special initialization so setup serial console device in early_init() so that console prints work as early as possible. Signed-off-by: Anup Patel <[email protected]> Reviewed-By: Himanshu Chauhan <[email protected]>
2024-02-20platform: generic: Parse system suspend test from config node.Cheng Yang
This patch update generic_domains_init() so that "system-suspend-test" is parsed from "/chosen/opensbi-config" DT node. Signed-off-by: Cheng Yang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-02-20platform: generic: Add support for specify coldboot harts in DTCheng Yang
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-12-19lib: sbi: Allow ecall handlers to directly update register stateAnup Patel
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 <[email protected]>
2023-12-19platform: generic: Fine tune fw_platform_calculate_heap_size()Anup Patel
Let's use SBI_TLB_INFO_SIZE instead of hard-coded 0x40 in fw_platform_calculate_heap_size() to fine tune the heap size required for per-hart TLB fifos. Signed-off-by: Anup Patel <[email protected]>
2023-12-11platform: recalculate heap size to support new tlb entry numberInochi Amaoto
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-12-06platform: generic: Introduce pmu_init() platform overrideYu Chien Peter Lin
Add pmu_init() platform override, which will be used to register PMU device and populate event mappings. Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Lad Prabhakar <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-12-06sbi: sbi_pmu: Improve sbi_pmu_init() error handlingYu Chien Peter Lin
This patch makes the following changes: - As sbi_platform_pmu_init() returns a negative error code on failure, let sbi_pmu_init() print out the error code with sbi_dprintf(). - In order to distinguish the SBI_EFAIL error returned by sbi_pmu_add_*_counter_map(), return SBI_ENOENT to indicate that fdt_pmu_setup() failed to locate "riscv,pmu" node, and generic_pmu_init() ignores such case. Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Lad Prabhakar <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2023-11-17lib: sbi: change sbi_hart_features.extensions as an arrayXiang W
In the future there may be a lot of ISA extensions, a 'long' may not be able to accommodate, changed to an array for the future. Addresses-Coverity-ID: 1568357 Out-of-bounds access Fixes: 6259b2ec2d09 ("lib: utils/fdt: Fix fdt_parse_isa_extensions() implementation") Signed-off-by: Xiang W <[email protected]> Reviewed-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-11-16platform: Uses hart count as the default size of tlb infoInochi Amaoto
For platform with high number of harts, it is better to auto detect a suitable number of entries in tlb fifo. Since allocating tlb entry for all online harts can reduce the wait time significantly, using the number of the online harts can make most platforms happy. This auto detection can avoid most duplicate code for setting tlb fifo size. Signed-off-by: Inochi Amaoto <[email protected]> Acked-by: Guo Ren <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-10platform: Allow platforms to specify the size of tlb fifoXiang W
For some platforms with a particularly high number of harts, if the tlb fifo is too small, it case harts to wait. Platforms should be allowed to specify the size of the tlb fifo. Signed-off-by: Xiang W <[email protected]> Signed-off-by: Xing Xiaoguang <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-07-13lib: utils: Add detection of Smepmp from ISA string in FDTHimanshu Chauhan
- Add function to parse ISA string in FDT. - Set Smepmp feature bit in extensions if "smepmp" string is found in ISA string. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-06-21lib: reset: Move fdt_reset_init into generic_early_initGuo Ren
The fdt_reset_thead driver needs to modify the __reset_thead_csr_stub text region for the secondary harts booting. After that, the sbi_hart_pmp_configure may lock down the text region with M_READABLE & M_EXECUTABLE attributes in the future. Currently, the M_READABLE & M_EXECUtABLE have no effect on m-mode, the L-bit in pmpcfg csr is useless for the current opensbi scenario. See: Priv-isa-spec 3.7.1.2. Locking and Privilege Mode When the L bit is clear, any M-mode access matching the PMP entry will succeed; the R/W/X permissions apply only to S and U modes. That's why current fdt_reset_thead could still work well after commit: 230278dcf127 ("lib: sbi: Add separate entries for firmware RX and RW regions"). So this patch fixes up a fake bug for the M-mode permission setting of the future. Fixes: 230278dcf127 ("lib: sbi: Add separate entries for firmware RX and RW regions") Link: http://lists.infradead.org/pipermail/opensbi/2023-June/005176.html Reported-by: Jessica Clarke <[email protected]> Signed-off-by: Guo Ren <[email protected]> Signed-off-by: Guo Ren <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-06-05platform: Allow platforms to specify heap sizeAnup Patel
We extend struct sbi_platform and struct sbi_scratch to allow platforms specify the heap size to the OpenSBI firmwares. The OpenSBI firmwares will use this information to determine the location of heap and provide heap base address in per-HART scratch space. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-02-27platform: generic: Add system suspend testAndrew Jones
When the system-suspend-test property is present in the domain config node as shown below, implement system suspend with a simple 5 second delay followed by a WFI. This allows testing system suspend when the low-level firmware doesn't support it. / { chosen { opensbi-domains { compatible = "opensbi,domain,config"; system-suspend-test; }; Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-02-27include: sbi: Remove extid parameter from vendor_ext_provider() callbackAnup Patel
The extid parameter of vendor_ext_provider() is redundant so let us remove it. Signed-off-by: Anup Patel <[email protected]>
2023-02-27lib: sbi: Align SBI vendor extension id with mvendorid CSRAnup Patel
As-per the SBI specification, the lower 24bits of the SBI vendor extension id is same as lower 24bits of the mvendorid CSR. We update the SBI vendor extension id checking based on above. Signed-off-by: Anup Patel <[email protected]>