summaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)Author
2023-06-23include: Bump-up version to 1.3v1.3Anup Patel
This patch updates OpenSBI version to 1.3 as part of release preparation. Signed-off-by: Anup Patel <[email protected]>
2023-06-15platform/lib: Set no-map attribute on all PMP regionsAlexandre Ghiti
This reverts commit 6966ad0abe70 ("platform/lib: Allow the OS to map the regions that are protected by PMP"). It was thought at the time of this commit that allowing the kernel to map PMP protected regions was safe but it is actually not: for example, the hibernation process will try to access any linear mapping page and then will fault on such mapped PMP regions [1]. Another issue is that the device tree specification [2] states that a !no-map region must be declared as EfiBootServicesData/Code in the EFI memory map which would make the PMP protected regions reclaimable by the kernel. And to circumvent this, RISC-V edk2 diverges from the DT specification to declare those regions as EfiReserved. The no-map attribute was removed to allow the kernel to use hugepages larger than 2MB to map the linear mapping to improve the performance but actually a recent talk from Mike Rapoport [3] stated that the performance benefit was marginal. For all those reasons, let's mark all the PMP protected regions as "no-map". [1] https://lore.kernel.org/linux-riscv/CAAYs2=gQvkhTeioMmqRDVGjdtNF_vhB+vm_1dHJxPNi75YDQ_Q@mail.gmail.com/ [2] "3.5.4 /reserved-memory and UEFI" https://github.com/devicetree-org/devicetree-specification/releases/download/v0.4-rc1/devicetree-specification-v0.4-rc1.pdf [3] https://lwn.net/Articles/931406/ Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-06-05lib: sbi: Use scratch space to save per-HART domain pointerAnup Patel
Instead of using a global array indexed by hartid, we should use scratch space to save per-HART domain pointer. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-06-05lib: sbi: Print scratch size and usage at boot timeAnup Patel
The scratch space being a scarce resource so let us print it's size and usage at boot time. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-06-05lib: sbi: Introduce simple heap allocatorAnup Patel
We provide simple heap allocator to manage the heap space provided by OpenSBI firmware and platform. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[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-06-05include: sbi_scratch: Add helper macros to access data typeAnup Patel
Reading and writing a data type in scratch space is a very common use-case so let us add related helper macros in sbi_scratch.h. Signed-off-by: Anup Patel <[email protected]>
2023-06-04lib: sbi: Align system suspend errors with specAndrew Jones
The spec says sbi_system_suspend() will return SBI_ERR_INVALID_PARAM when "sleep_type is reserved or is platform-specific and unimplemented" and SBI_ERR_NOT_SUPPORTED when sleep_type "is not reserved and is implemented, but the platform does not support it due to one or more missing dependencies." Ensure SBI_ERR_INVALID_PARAM is returned for reserved sleep types and that the system suspend driver can choose which of the two error types to return itself by returning an error from its check function rather than a boolean. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: Document sbi_ecall_extension membersAndrew Jones
With the introduction of the register_extensions callback the range members (extid_start and extid_end) may now change and it has become a bit subtle as to when a probe function should be implemented. Document all the members and their relationship to the register_extensions callback. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-21lib: sbi: Introduce register_extensions extension callbackAndrew Jones
Rather than registering all extensions on their behalf in sbi_ecall_init(), introduce another extension callback and invoke that instead. For now, implement each callback by simply registering the extension, which means this patch has no intended functional change. In later patches, extension callbacks will be modified to choose when to register and to possibly narrow the extension ID range prior to registering. When an extension range needs to remove IDs, leaving gaps, then multiple invocations of sbi_ecall_register_extension() may be used. In summary, later patches for current extensions and the introductions of future extensions will use the new callback to ensure that only valid extension IDs from the initial range, which are also available, will be registered. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-05-11lib: sbi: Simplify BITS_PER_LONG definitionXiang W
No need to use #elif ladder when defining BITS_PER_LONG. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Andrew Jones <[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]>
2023-04-14lib: sbi: Optimize sbi_tlb queue waitingXiang W
When tlb_fifo is full, it will wait and affect the ipi update to other harts. This patch is optimized. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2023-04-07lib: sbi_pmu: Align the event type offset as per SBI specificationYu Chien Peter Lin
The bits encoded in event_idx[19:16] indicate the event type, with an offset of 16 instead of 20. Fixes: 13d40f21d588 ("lib: sbi: Add PMU support") Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-04-07lib: sbi: Implement SBI CPPC extensionSunil V L
Implement SBI CPPC extension. This extension is only available when OpenSBI platform provides a CPPC device to generic library. Signed-off-by: Sunil V L <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-04-07include: Add defines for SBI CPPC extensionSunil V L
Add SBI CPPC extension related defines to the SBI ecall interface header. Signed-off-by: Sunil V L <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-04-06lib: sbi: Introduce sbi_entry_count() functionAnup Patel
We introduce sbi_entry_count() function which counts the number of times a HART enters OpenSBI via cold-boot or warm-boot path. Signed-off-by: Anup Patel <[email protected]>
2023-04-06lib: sbi: Fix how to check whether the domain contains fw_regionXiang W
Because firmware is split into rw/rx segments, it cannot be recorded by a root_fw_region. This problem is solved by adding a flag fw_region_inited to sbi_domain. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi: Clear IPIs before init_warm_startup in non-boot hartsEvgenii Shatokhin
Since commit 50d4fde1c5a4 ("lib: Remove redundant sbi_platform_ipi_clear() calls"), the IPI sent from the boot hart in wake_coldboot_harts() is not cleared in the secondary harts until they reach sbi_ipi_init(). However, sbi_hsm_init() and sbi_hsm_hart_wait() are called earlier, so a secondary hart might enter sbi_hsm_hart_wait() with an already pending IPI. sbi_hsm_hart_wait() makes sure the hart leaves the loop only when it is actually ready, so a pending unrelated IPI should not cause safety issues. However, it might be inefficient on certain hardware, because it prevents "wfi" from stalling the hart even if the hardware supports this, making the hart needlessly spin in a "busy-wait" loop. This behaviour can be observed, for example, in a QEMU VM (QEMU 7.2.0) with "-machine virt" running a Linux guest. Inserting delays in sbi_hsm_hart_start() allows reproducing the issue more reliably. The comment in wait_for_coldboot() suggests that the initial IPI is needed in the warm resume path, so let us clear it before init_warm_startup() only. To do this, sbi_ipi_raw_clear() was created similar to sbi_ipi_raw_send(). Signed-off-by: Evgenii Shatokhin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi: Refactor the calls to sbi_hart_switch_mode()Evgenii Shatokhin
Move them into sbi_hsm_hart_start_finish() and sbi_hsm_hart_resume_finish() to make them easier to manage. This will be used by subsequent patches. Suggested-by: Anup Patel <[email protected]> Signed-off-by: Evgenii Shatokhin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi_pmu: Add hartid parameter PMU device opsMayuresh Chitale
Platform specific firmware event handler may leverage the hartid to program per hart specific registers for a given counter. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi_pmu: Introduce fw_counter_write_value APIMayuresh Chitale
Add fw_counter_write_value API for platform specific firmware events which separates setting the counter's initial value from starting the counter. This is required so that the fw_event_data array can be reused to save the event data received. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi_pmu: Update sbi_pmu dev opsMayuresh Chitale
Update fw_event_validate_code, fw_counter_match_code and fw_counter_start ops which used a 32 bit event code to use the 64 bit event data instead. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi_pmu: Reserve space for implementation specific firmware eventsMayuresh Chitale
We reserve space for SBI implementation specific custom firmware events which can be used by M-mode firmwares and HS-mode hypervisors for their own use. This reserved space is intentionally large to ensure that SBI implementation has enough space to accommodate platform specific firmware events as well. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi_pmu: Implement sbi_pmu_counter_fw_read_hiMayuresh Chitale
To support 64 bit firmware counters on RV32 systems, we implement sbi_pmu_counter_fw_read_hi() which returns the upper 32 bits of the firmware counter value. On RV64 (or higher) systems, this function will always return zero. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-10lib: sbi_pmu: add callback for counter widthMayuresh Chitale
This patch adds a callback to fetch the number of bits implemented for a custom firmware counter. If the callback fails or is not implemented then width defaults to 63. Signed-off-by: Mayuresh Chitale <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-03-09lib: utils/i2c: Add minimal StarFive jh7110 I2C driverMinda Chen
Starfive JH7110 I2C IP is synopsys designware. Minimum StarFIve I2C driver to read/send bytes over I2C bus. This allows querying information and perform operation of onboard PMIC, as well as power-off and reset. Signed-off-by: Minda Chen <[email protected]> Reviewed-by: Anup Patel <[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-27lib: sbi: Add system_suspend_allowed domain propertyAndrew Jones
Only privileged domains should be allowed to suspend the entire system. Give the root domain this property by default and allow other domains to be given the property by specifying it in the DT. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-02-27lib: sbi: Add system suspend skeletonAndrew Jones
Add the SUSP extension probe and ecall support, but for now the system suspend function is just a stub. Signed-off-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-02-27lib: sbi_hsm: Export some functionsAndrew Jones
A coming patch can make use of a few internal hsm functions if we export them. 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]>
2023-02-27lib: sbi_hart: Enable hcontext and scontextNylon Chen
According to the description in "riscv-state-enable[0]", to access h/scontext in S-Mode, we need to enable the 57th bit. If it is not enabled, an "illegal instruction" error will occur. Link: https://github.com/riscv/riscv-state-enable/blob/a28bfae443f350d5b4c42874f428367d5b322ffe/content.adoc [0] Signed-off-by: Nylon Chen <[email protected]> Reviewed-by: Zong Li <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-02-27include: fdt/fdt_helper: Change fdt_get_address() to return root.next_arg1Bin Meng
In sbi_domain_finalize(), when locating the coldboot hart's domain, the coldboot hart's scratch->arg1 will be overwritten by the domain configuration. However scratch->arg1 holds the FDT address of the coldboot hart, and is still being accessed by fdt_get_address() in later boot process. scratch->arg1 could then contain completely garbage and lead to a crash. To fix this, we change fdt_get_address() to return root domain's next_arg1 as the FDT pointer. Resolves: https://github.com/riscv-software-src/opensbi/issues/281 Fixes: b1678af210dc ("lib: sbi: Add initial domain support") Reported-by: Marouene Boubakri <[email protected]> Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-02-10lib: sbi: Add console_puts() callback in the console deviceAnup Patel
We add console_puts() callback in the console device which allows console drivers (such as semihosting) to implement a specialized way to output character string. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-02-10lib: sbi: Add sbi_domain_check_addr_range() functionAnup Patel
We add sbi_domain_check_addr_range() helper function to check whether a given address range is accessible under a particular domain. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-02-09lib: sbi: Add sbi_ngets() functionAnup Patel
We add new sbi_ngets() which help us read characters into a physical memory location. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Andrew Jones <[email protected]>
2023-02-09lib: sbi: Add sbi_nputs() functionAnup Patel
We add new sbi_nputs() which help us print a fixed number of characters from a physical memory location. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-02-09include: Add defines for SBI debug console extensionAnup Patel
We add SBI debug console extension related defines to the SBI ecall interface header. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2023-02-09include: sbi: Fix BSWAPx() macros for big-endian hostAnup Patel
The BSWAPx() macros won't do any swapping for big-endian host because the EXTRACT_BYTE() macro will pickup bytes in reverse order. Also, the EXTRACT_BYTE() will generate compile error for constants. To fix this, we get remove the EXTRACT_BYTE() macro and re-write BSWAPx() using simple mask and shift operations. Fixes: 09b34d8cca51 ("include: Add support for byteorder/endianness conversion") Reported-by: Samuel Holland <[email protected]> Signed-off-by: Anup Patel <[email protected]>
2023-02-08include: types: Add typedefs for endiannessRahul Pathak
If any variable/memory-location follows certain endianness then its important to annotate it properly so that proper conversion can be done before read/write from that variable/memory. Also, use these new typedefs in libfdt_env.h for deriving its own custom fdtX_t types Signed-off-by: Rahul Pathak <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-02-08include: Add support for byteorder/endianness conversionRahul Pathak
Define macros general byteorder conversion Define functions for endianness conversion from general byteorder conversion macros Signed-off-by: Rahul Pathak <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Sergey Matyukevich <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-01-24lib: utils: Add fdt_add_cpu_idle_states() helper functionSamuel Holland
Since the availability and latency properties of CPU idle states depend on the specific SBI HSM implementation, it is appropriate that the idle states are added to the devicetree at runtime by that implementation. This helper function adds a platform-provided array of idle states to the devicetree, following the SBI idle state binding. Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Samuel Holland <[email protected]>
2023-01-23firmware: Add RW section offset in scratchHimanshu Chauhan
Add the RW section offset, provided by _fw_rw_offset symbol, to the scratch structure. This will be used to program separate pmp entry for RW section. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-01-22lib: utils: atcsmu: Add Andes System Management Unit supportYu Chien Peter Lin
This patch adds atcsmu support for Andes AE350 platforms. The SMU provides system management capabilities, including clock, reset and power control based on power domain partitions. Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-01-22include: types: add always inline compiler attributeYu Chien Peter Lin
Provide __always_inline to sbi_types header. Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-01-22lib: sbi_hsm: handle failure when hart_stop returns SBI_ENOTSUPPYu Chien Peter Lin
Make use of generic warm-boot path when platform hart_stop callback returns SBI_ENOTSUPP, in case certain hart can not turn off its power domain, or it detects some error occured in power management unit, it can fall through warm-boot flow and wait for interrupt in sbi_hsm_hart_wait(). Also improves comment in sbi_hsm_hart_wait(). Signed-off-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-01-09lib: utils: Disallow non-root domains from adding M-mode regionsHimanshu Chauhan
The M-mode regions can only be added to the root domain. The non-root domains shouldn't be able to add them from FDT. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2023-01-09include: sbi: Fine grain the permissions for M and SU modesHimanshu Chauhan
Split the permissions for M-mode and SU-mode. This would help if different sections of OpenSBI need to be given different permissions and if M-mode has different permisssions than the SU-mode over a region. Signed-off-by: Himanshu Chauhan <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>