summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2024-12-19lib: utils: Improve rpmi_cppc_fc_db_trigger() for RV32Xiang W1-14/+7
Improve 64-bit operation under rv32 and remove db_val_u32_hi in rpmi_cppc_fc_db_trigger(). Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15lib: sbi_pmu: Verify the raw events first during event infoAtish Patra1-7/+6
The raw events have same event_idx. Thus, the event info sanity check only relies on the select mask. The raw event check should be done first so that regular hardware events can be verified using event idx range check. Fixes: e4345842168b ("lib: sbi_pmu: Implement SBI PMU event info function") Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15lib: sbi_pmu: Fix the sanity check condition for hw event mapAtish Patra1-2/+2
The hardware event map function invoked from platform code should exclude any raw events as there is a separate function for the raw events. Fixes: d8a483fc7fd0 ("lib: sbi_pmu: PMU raw event v2 support") Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15scripts/carray: change to using single awk invocation to generate .cBen Dooks1-33/+99
The shell script makes multiple call-outs to awk to get information from the configuration file. It would be easier to just write the whole thing in one .awk script and have the makefile altered to call that instead. There should be no functional difference other than the script type and has been tested with PLATFORM=generic build. This should be both quicker and easier to understand. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15script/carry.sh: send error to stderrBen Dooks1-6/+8
Send the errors to stderr, otherwise they end up being written to the file the script was redirecting to in the Makefile Also, use EOF block to make it easier to redirect Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15Makefile: remove carry output if scripts/carray.sh failsBen Dooks1-1/+1
If the script fails, we end up trying to build either an empty or damaged .c file. Just remove it and let gcc fail on non-existent file. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15top: add ~ files to .gitignoreBen Dooks1-0/+1
Ignore temporary files, and avoid accidentally adding them to a commit. Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15lib: sbi: sse: Fix a6 and a7 register content upon injectionClément Léger1-2/+2
The specification states that a6 contains the current hart id and a7 contains the entry argument. This was inverted in the current implementation. Reported-by: Andrew Jones <andrew.jones@linux.dev> Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15lib: sbi: fix GLOBAL_PLAT_DEFINEClément Léger1-2/+2
Fix GLOBAL_PLAT_0_START/END definitions. The specification states that the beginning of the range is 0xc000 and the end is 0xffff. Reported-by: Andrew Jones <andrew.jones@linux.dev> Signed-off-by: Clément Léger <cleger@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-15Makefile: Don't enable V-extension using -march optionAnup Patel2-6/+7
Enabling V-extension using -march option causes OpenSBI boot-time hang with LLVM compiler. As a work-around, don't enable V-extension using -march option and instead use a custom OpenSBI specific define inform availability of V-extension to lib/sbi/sbi_trap_v_ldst.c. Fixes: c2acc5e5b0d8 ("lib: sbi_misaligned_ldst: Add handling of vector load/store") Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2024-12-15lib: utils/fdt_cppc_rpmi: Fix compile error with LLVMAnup Patel1-2/+5
The following error is observed when compiling fdt_cppc_rpmi driver using LLVM: lib/utils/cppc/fdt_cppc_rpmi.c:87:3: error: label followed by a declaration is a C23 extension [-Werror,-Wc23-extensions] 87 | u64 db_val_u64 = 0; To fix the above issue, move the variable declaration at the start of function. Fixes: 591a98bdd549 ("lib: utils/cppc: Add RPMI CPPC driver") Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Samuel Holland <samuel.holland@sifive.com>
2024-12-06lib: sbi_misaligned_ldst: Add handling of vector load/storeNylon Chen6-12/+760
Add misaligned load/store handling for the vector extension to the sbi_misaligned_ldst library. This implementation is inspired from the misaligned_vec_ldst implementation in the riscv-pk project. Co-developed-by: Zong Li <zong.li@sifive.com> Signed-off-by: Zong Li <zong.li@sifive.com> Signed-off-by: Nylon Chen <nylon.chen@sifive.com> Reviewed-by: Andy Chiu <andy.chiu@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-06lib: utils/mpxy: Add RPMI client driver for MPXYRahul Pathak5-0/+548
Add a generic RPMI mailbox client driver which provides a MPXY channel. Initially, this driver only supports RPMI clock service group but can be extended to support multiple RPMI service groups. Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Co-developed-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils: Add simple FDT based MPXY driver frameworkAnup Patel8-0/+85
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: sbi: Implement SBI MPXY extensionAnup Patel4-0/+84
Implement the SBI MPXY extension which provides an SBI interface to the supervisor software for send messages via MPXY framework. Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Co-developed-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: sbi: Add SBI Message Proxy (MPXY) frameworkRahul Pathak7-7/+915
Introduce SBI Message Proxy (MPXY) framework which allows platform specific code or drivers to register message protocol specific channels. This framework enables the supervisor software to send messages belonging to different message protocols via OpenSBI firmware. Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Co-developed-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Co-developed-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils/cppc: Add RPMI CPPC driverSubrahmanya Lingappa5-0/+495
Add RPMI based driver for CPPC register read, write and probe. Signed-off-by: Subrahmanya Lingappa <slingappa@ventanamicro.com> Co-developed-by: Rahul Pathak <rpathak@ventanamicro.com> Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Co-developed-by: Sunil V L <sunilvl@ventanamicro.com> Signed-off-by: Sunil V L <sunilvl@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils: Add simple FDT based CPPC driver frameworkAnup Patel8-0/+77
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/hsm: Add RPMI HSM driverSubrahmanya Lingappa5-0/+467
The RPMI HSM service group provides set of routine to query and control power states of a Hart. Add RPMI based Hart State Management (HSM) driver. Signed-off-by: Subrahmanya Lingappa <slingappa@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils: Add simple FDT based HSM driver frameworkAnup Patel8-0/+77
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/fdt: Allow dynamic registration of FDT fixup callbacksAnup Patel2-0/+48
It should possible to fixup FDT from any part of OpenSBI so add fdt_register_general_fixup() which allows dynamic registration of FDT fixup callbacks. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: sbi: Add optional resume address to hart suspendSubrahmanya Lingappa3-5/+9
Add an optional resume address to the platform specific hart suspend call. Signed-off-by: Subrahmanya Lingappa <slingappa@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils/suspend: Add RPMI system suspend driverSubrahmanya Lingappa5-0/+186
Add RPMI based system suspend driver. To test this, execute the follwoing in Linux: $ echo mem > /sys/power/state To wake up, execute the following command on qemu monitor terminal: (qemu) system_wakeup Signed-off-by: Subrahmanya Lingappa <slingappa@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils: Add simple FDT based system suspend driver frameworkAnup Patel8-0/+77
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-06lib/utils: reset: Add RPMI System Reset driverRahul Pathak5-0/+177
Add RPMI based driver for system reset and enable it in the generic platform defconfig Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib/utils: Add RPMI messaging protocol and shared memory transport supportRahul Pathak7-0/+1173
The RISC-V Platform Management Interface (RPMI) defines a messaging protocol and shared memory based transport for bi-directional communication with an on-chip or external microcontroller. To support RPMI in OpenSBI, add: 1) The RPMI messaging protocol defines and helper macros 2) A FDT mailbox driver for the RPMI shared memory transport Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Co-developed-by: Subrahmanya Lingappa <slingappa@ventanamicro.com> Signed-off-by: Subrahmanya Lingappa <slingappa@ventanamicro.com> Co-developed-by: Anup Patel <apatel@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils/mailbox: Add simple FDT based mailbox frameworkAnup Patel5-0/+145
Add a simple FDT based mailbox framework which is built on top of the generic mailbox library. The phandle of FDT mailbox DT node is treated as the unique mailbox controller ID which is required by the generic mailbox library. The FDT based mailbox drivers will be probed on-demand from fdt_mailbox_request_chan() called by the mailbox client drivers. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: utils/mailbox: Add generic mailbox libraryAnup Patel5-0/+339
Add generic mailbox library which is independent of hardware description format. The OpenSBI platform support or mailbox drivers can register mailbox controller instances which can be discovered and used by different mailbox client drivers. Each mailbox controller instance has a unique ID which can be used by mailbox client drivers for find the mailbox controller instance. The mailbox client drivers will typically request a mailbox channel from the mailbox controller and use it to do data transfer with the remote end of mailbox channel. Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-06lib: Increase ROOT_REGION_MAX to accomodate more memregionsRahul Pathak1-1/+1
As more drivers adding memregions into root domain, the current static limit of ROOT_REGION_MAX is not sufficient. Increase the limit to accomodate more memregions. Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com>
2024-12-02lib: sbi_pmu: Implement SBI PMU event info functionAtish Patra3-0/+81
Allow the supervisor software to query about the event using the new function. This supports both firmware and hardware events. The hardware event presence is verified hw_event_map which is populated via PMU device tree node. The firmware event presence is checked through event validation function which should take care of both standard and platform firmware events. Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-02lib: sbi_pmu: Add SBI PMU event info function details.Atish Patra1-0/+9
The SBI v3.0 introduced a new function to query about the events without invoking CFG_MATCH. This allows supervisor software to identify which events are supported on the platform with single SBI call instead of a CFG_MATCH for each event. Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-02lib: sbi_pmu: Remove redundant check for fw eventsAtish Patra1-5/+0
The pmu_validate_event already has the same check for fw events. The validate function is called prior to the current function to find a counter for firmware. That's why, the redudant check can be removed from the find counter function. Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-12-02lib: sbi_pmu: PMU raw event v2 supportAtish Patra3-6/+12
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-12-01Makefile: Fix POSIX grep for multiple patternsIgor Melnikov1-2/+2
grep -e "-mstrict-align\|-mno-unaligned-access" makes use of GNU grep's backslash-escaped alternation operator \| which is available in basic regular expression syntax (BRE) mode. However, in POSIX grep's BRE mode | is an ordinary character which, when backslash-escaped, matches itself. Therefore, the search pattern becomes a plain string '-mstrict-align|-mno-unaligned-access' which obviously never matches the expected error and CC_SUPPORT_STRICT_ALIGN is always set to y. When cross-compiling with LLVM on amd64-unknown-openbsd7.6 host for riscv64-unknown-elf target this results in a compilation error: clang: error: unsupported option '-mno-unaligned-access' for target 'riscv64-unknown-elf' Using multiple -e options for this case maintains consistent behaviour across different grep implementations and fixes the issue. Signed-off-by: Igor Melnikov <imel@purelymail.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/timer: Use fdt_driver for initializationSamuel Holland5-45/+10
The timer driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_timer_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>
2024-11-28lib: utils/serial: Use fdt_driver for initializationSamuel Holland12-60/+18
The serial driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_serial_init() first attempts to match the chosen stdout device, and upon failure matches the first available serial device in the DT. It is a fatal error if no such device is found. This matches the behavior of fdt_driver_init_one(). Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/reset: Use fdt_driver for initializationSamuel Holland11-61/+26
The reset driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_reset_init() performs a best-effort initialization of all matching DT nodes. Platform-specific logic expects exactly one DT node to match a single driver. This is accomplished by using fdt_driver_init_one() with a local list containing that one driver. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/regmap: Use fdt_driver for initializationSamuel Holland4-34/+6
The regmap driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/ipi: Use fdt_driver for initializationSamuel Holland5-48/+10
The ipi driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. The generic fdt_ipi_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>
2024-11-28lib: utils/i2c: Use fdt_driver for initializationSamuel Holland5-37/+7
The i2c driver subsystem does not need any extra data, so it can use `struct fdt_driver` directly. It always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/gpio: Use fdt_driver for initializationSamuel Holland7-40/+28
FDT gpio drivers have an extra .xlate operation, so they need to embed the `struct fdt_driver` inside the subsystem-specific type. The gpio subsystem always initializes the driver for a specific DT node. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28scripts/carray.sh: Allow referencing a struct memberSamuel Holland1-2/+9
It can be useful to embed the objects referenced by a carray inside another struct. To avoid type punning, the generated carray code must use the correct type for the enclosing struct and member access to compute the desired object address. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28scripts/carray.sh: Avoid useless use of catSamuel Holland1-3/+3
awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1). Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: utils/fdt: Add helpers for generic driver initializationSamuel Holland3-0/+140
Currently, each driver subsystem contains its own code for matching drivers against the platform's devicetree blob. This bloats firmware size because the several FDT scanning loops are almost exact copies of each other, and is confusing because the loops do have some subtle differences. Furthermore, the existing match algorithm is inefficient: it scans the FDT structure separately for each driver in the list. A faster algorithm scans the FDT blob only once, matching all drivers in the list for each `compatible` property seen. Add new helpers implementing this faster algorithm. Since they must iterate through the list of drivers, the driver structure cannot be opaque. However, since the driver list is an array of pointers, the `struct fdt_driver` can be embedded in a subsystem-specific driver structure if needed. These three helpers cover all existing use cases for driver initialization within OpenSBI. An additional benefit of centralized driver initialization is the consistent use of fdt_node_is_enabled(). Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28treewide: Make carray arrays const and NULL-terminatedSamuel Holland12-38/+26
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-28sbi: fwft: clear the config lock when warm bootNick Hu1-0/+15
The hotplug cpu should clear the fwft config's SBI_FWFT_SET_FLAG_LOCK in the warm boot flow otherwise the cpu can't set the menvcfg.sse by SBI_EXT_FWFT_SET sbi call and cause the illegal instruction when accessing the CSR_SSP in kernel. Signed-off-by: Nick Hu <nick.hu@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: sbi_irqchip: Set the IRQ handler when registering a chipSamuel Holland3-19/+7
In addition to saving some code size, this moves the decision about setting the top-level external interrupt handler to the irqchip core, not the specific driver, which would be needed to support chained interrupt handlers. 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 Holland13-150/+26
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-28lib: sbi_irqchip: Call driver warm_init from SBI coreSamuel Holland14-20/+24
Currently, each platform keeps track of which irqchip driver is in use and calls its warm init function. Since the generic platform may use multiple irqchip drivers, it has logic to track an array of drivers. The code is simplified and made common across platforms by treating warm init and exit as properties of the driver, not the platform. Then the platform's only role is to select and prepare a driver during cold boot. For now, only add a .warm_init hook, since none of the existing drivers need an .exit hook. It could be added in the future if needed. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2024-11-28lib: sbi_irqchip: Register devices during cold initSamuel Holland5-0/+38
Have the SBI irqchip core keep track of registered irqchip devices. This is useful for any callbacks the irqchip driver may have, such as for warm initialization, the external interrupt handler function, and any future support for handling external interrupts (beyond IPIs) in M-mode. This improves on the tracking done in fdt_irqchip.c, as it tracks device instances, not just drivers, so callbacks can target a specific device. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>