summaryrefslogtreecommitdiff
path: root/platform/generic/platform.c
AgeCommit message (Collapse)AuthorFilesLines
2025-02-12lib: utils: Initialize miscellaneous drivers in one passSamuel Holland1-11/+5
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:Check that hartid is validRaj Vishwanathan1-2/+2
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>
2024-12-21platform: generic: Initialize console before other driversSamuel Holland1-5/+5
Initialize serial drivers first, so messages printed by other drivers do not need to use the early console buffer. Suggested-by: Anup Patel <anup@brainfault.org> Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-06lib: utils: Add simple FDT based MPXY driver frameworkAnup Patel1-0/+10
The generic platform can have multiple MPXY drivers so add a simple FDT based MPXY driver framework. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils: Add simple FDT based CPPC driver frameworkAnup Patel1-0/+2
The generic platform can have multiple CPPC drivers so add a simple FDT based CPPC driver framework. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils: Add simple FDT based HSM driver frameworkAnup Patel1-0/+2
The generic platform can have multiple HSM drivers so add a simple FDT based HSM driver framework. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils: Add simple FDT based system suspend driver frameworkAnup Patel1-0/+2
The generic platform can have multiple system suspend drivers so add a simple FDT based system suspend driver framework. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-02lib: sbi_pmu: PMU raw event v2 supportAtish Patra1-1/+2
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 <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
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-11-28platform: Drop irqchip warm init and exit hooksSamuel Holland1-1/+0
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 <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-11platform: Drop IPI warm init and exit hooksSamuel Holland1-1/+0
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 <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-11platform: introduce DT-based configurable heap sizeInochi Amaoto1-3/+25
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 <inochiama@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-05platform: Drop timer warm init and exit hooksSamuel Holland1-1/+0
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 <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-27platform: generic: Fix fw_platform_coldboot_harts_init() functionAnup Patel1-16/+16
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 <apatel@ventanamicro.com>
2024-08-24lib: utils/fdt: Add fdt_get_address_rw() helperSamuel Holland1-2/+2
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 <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24lib: utils/serial: Pass the FDT to fdt_serial_init()Samuel Holland1-1/+1
Indicate that this function does not modify the FDT blob, and deduplicate the call to fdt_get_address(). Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24lib: utils/reset: Pass the FDT to fdt_reset_init()Samuel Holland1-1/+1
Indicate that this function does not modify the FDT blob, and deduplicate the call to fdt_get_address(). Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24platform: generic: Pass FDT to early/final_init overridesSamuel Holland1-5/+4
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 <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-08-24platform: generic: Constify FDT pointers in fw_platform_init()Samuel Holland1-3/+3
Indicate that none of these functions modify the devicetree by constifying the parameter type. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-07-24platform: Setup serial console device in early_init()Anup Patel1-10/+11
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 <apatel@ventanamicro.com> Reviewed-By: Himanshu Chauhan <hchauhan@ventanamicro.com>
2024-02-20platform: generic: Parse system suspend test from config node.Cheng Yang1-1/+1
This patch update generic_domains_init() so that "system-suspend-test" is parsed from "/chosen/opensbi-config" DT node. Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-02-20platform: generic: Add support for specify coldboot harts in DTCheng Yang1-1/+64
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>
2023-12-19lib: sbi: Allow ecall handlers to directly update register stateAnup Patel1-5/+3
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-19platform: generic: Fine tune fw_platform_calculate_heap_size()Anup Patel1-1/+2
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 <apatel@ventanamicro.com>
2023-12-11platform: recalculate heap size to support new tlb entry numberInochi Amaoto1-1/+15
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-06platform: generic: Introduce pmu_init() platform overrideYu Chien Peter Lin1-0/+6
Add pmu_init() platform override, which will be used to register PMU device and populate event mappings. Signed-off-by: Yu Chien Peter Lin <peterlin@andestech.com> Reviewed-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-12-06sbi: sbi_pmu: Improve sbi_pmu_init() error handlingYu Chien Peter Lin1-1/+7
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 <peterlin@andestech.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2023-11-17lib: sbi: change sbi_hart_features.extensions as an arrayXiang W1-1/+1
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 <wxjstz@126.com> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-11-16platform: Uses hart count as the default size of tlb infoInochi Amaoto1-1/+1
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 <inochiama@outlook.com> Acked-by: Guo Ren <guoren@kernel.org> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-09-10platform: Allow platforms to specify the size of tlb fifoXiang W1-0/+8
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 <wxjstz@126.com> Signed-off-by: Xing Xiaoguang <xiaoguang.xing@sophgo.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-07-13lib: utils: Add detection of Smepmp from ISA string in FDTHimanshu Chauhan1-0/+9
- 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 <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-06-21lib: reset: Move fdt_reset_init into generic_early_initGuo Ren1-3/+3
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 <jrtc27@jrtc27.com> Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Signed-off-by: Guo Ren <guoren@kernel.org> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-06-05platform: Allow platforms to specify heap sizeAnup Patel1-1/+2
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 <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
2023-02-27platform: generic: Add system suspend testAndrew Jones1-1/+19
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 <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-02-27include: sbi: Remove extid parameter from vendor_ext_provider() callbackAnup Patel1-2/+2
The extid parameter of vendor_ext_provider() is redundant so let us remove it. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2023-02-27lib: sbi: Align SBI vendor extension id with mvendorid CSRAnup Patel1-13/+6
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 <apatel@ventanamicro.com>
2023-01-07platform: generic: Allow platform_override to perform firmware initWei Liang Lim1-0/+3
We add a generic platform override callback to allow platform specific firmware init. Signed-off-by: Wei Liang Lim <weiliang.lim@starfivetech.com> Reviewed-by: Chee Hong Ang <cheehong.ang@starfivetech.com> Reviewed-by: Jun Liang Tan <junliang.tan@starfivetech.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2023-01-07platform: generic: Allow platform_override to select cold boot HARTAnup Patel1-0/+9
We add a generic platform override callback to allow platform specific selection of cold boot HART. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2022-12-09platform: generic: Make use of fdt_match_node()Lad Prabhakar1-3/+3
It makes sense to use fdt_match_node() instead of fdt_find_match() in fw_platform_lookup_special() as we already have the start offset to search from. Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-10-13platform: generic: add extensions_init handler and platform-overrideHeiko Stuebner1-0/+10
Init of non-standard extensions is a platform-specific thing, so allow generic platforms to do this via a platform-override. Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Guo Ren <guoren@kernel.org> Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Heiko Stuebner <heiko@sntech.de>
2022-09-13lib: utils/serial: add semihosting supportKautuk Consul1-1/+10
We add RISC-V semihosting based serial console for JTAG based early debugging. The RISC-V semihosting specification is available at: https://github.com/riscv/riscv-semihosting-spec/blob/main/riscv-semihosting-spec.adoc Signed-off-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Kautuk Consul <kconsul@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-08platform: generic: Use kconfig to set platform version and default nameAnup Patel1-2/+4
The generic platform version and default name should be set based on kconfig options so that users can override it. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-06-13platform: generic: add overrides for vendor extensionsMayuresh Chitale1-0/+25
Allow the vendor_ext_check and vendor_ext_provider APIs of the generic platform to be overridden by other platforms Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-05-14platform: generic: check if CPU node is enabledJan Remes1-0/+3
Ignore CPU nodes in FDT which are not enabled. Signed-off-by: Jan Remes <jan.remes@codasip.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-05-13platform: generic: Generate platform override module list at compile-timeAnup Patel1-9/+5
Instead of having platform override module list hard-coded in the C source, we generate it using carray.sh at compile-time. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-02-15lib: utils/irqchip: Add FDT based driver for IMSICAnup Patel1-0/+12
We add simple FDT irqchip driver for IMSIC so that generic platform (and other FDT based platforms) can utilize common IMIC library. Signed-off-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2021-11-08platform: generic: move fdt_reset_init to final_initHeinrich Schuchardt1-10/+5
Move the fdt_reset_init() invocation from generic_early_init() to generic_final_init(). This allows to print error messages. Ignore the return value of fdt_reset_init() as we should not stop booting due to failure to initialize reset drivers. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com> Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-11-02include: sbi_utils: Introduce an helper to get fdt base addressAlexandre Ghiti1-3/+3
This simply adds an helper to get fdt address which is more explicit than sbi_scratch_thishart_arg1_ptr. Signed-off-by: Alexandre Ghiti <alexandre.ghiti@canonical.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-07-27generic: fu740: add workaround for CIP-1200 errataDavid Abdurachmanov1-0/+2
Instruction TLB can fail to respect a non-global SFENCE thus we need to flush the TLB using SFENCE.VMA x0, x0 See full description of CIP-1200 in Errata_FU740-C000_20210205 from https://www.sifive.com/boards/hifive-unmatched Signed-off-by: David Abdurachmanov <david.abdurachmanov@sifive.com> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2021-07-11platform: generic: Add PMU supportAtish Patra1-0/+30
Add PMU support for generic platform. Generic platform solely relies on the device tree to parse all pmu related information. If any event is not described in device tree, generic platform will not support it. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>