summaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_system.c
AgeCommit message (Collapse)Author
2025-10-28lib: sbi: Add system_resume callback for restoring the systemNick Hu
The last core who performs the system suspend is responsible for restoring the system after waking up. Add the system_resume callback for restoring the system from suspend. Suggested-by: Anup Patel <[email protected]> Signed-off-by: Nick Hu <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
2024-10-25lib: sbi: factorize previous mode computationClément Léger
Previous privilege mode retrieval from mstatus is done at different places, factorize it rather than copy/pasting it again. Signed-off-by: Clément Léger <[email protected]> Reviewed-by: Samuel Holland <[email protected]>
2024-09-26lib: sbi: Update __sbi_hsm_hart_get_state() to take a hart indexSamuel Holland
This removes some hartindex conversions in sbi_system_suspend(), but is mostly intended to support refactoring sbi_hsm_hart_interruptible_mask() to work exclusively with struct sbi_hartmask. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-09-26lib: sbi: Simplify halt broadcast logicSamuel Holland
Use the IPI .update callback to exclude the local hart. This allows reusing the normal logic for broadcasting an IPI to all active harts. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2024-05-07sbi: sbi_domain_context: Add spinlock for updating domain assigned_hartsAlvin Chang
Add spinlock protection to avoid race condition on assigned_harts during domain context switching. Also, rename/add variables for accessing the corresponding domain of target/current context. Signed-off-by: Alvin Chang <[email protected]> Reviewed-by: Yu Chien Peter Lin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-12-26lib: sbi: Fix shift bug in sbi_system_resetXiang W
There is a problem with judging whether the current hart belongs to hmask. If cur_hartid minus hbase is greater than BITS_PER_LONG, the previous hmask will also have a bit cleared incorrectly, which will cause some harts to lose ipi. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2023-09-24include: sbi: Remove sbi_hartmask_for_each_hart() macroAnup Patel
The sbi_hartmask_for_each_hart() macro is slow and has only one user so let us completely remove the sbi_hartmask_for_each_hart() macro. Signed-off-by: Anup Patel <[email protected]>
2023-09-24lib: sbi: Extend sbi_hartmask to support both hartid and hartindexXiang W
Currently, the sbi_hartmask is indexed by hartid which puts a limit on hartid to be less than SBI_HARTMASK_MAX_BITS. We extend the sbi_hartmask implementation to use hartindex and support updating sbi_hartmask using hartid. This removes the limit on hartid and existing code works largely unmodified. Signed-off-by: Xiang W <[email protected]> Signed-off-by: Anup Patel <[email protected]>
2023-07-31lib: sbi: Update system suspend to specAndrew Jones
commit 68e66106120f ("SUSP: Add SBI_ERR_DENIED") of the SBI spec adds a new error code, SBI_ERR_DENIED, which is returned when entry criteria has not be meant. Update the system suspend implementation to return this error when it has detected that not all harts are in the STOPPED state. Signed-off-by: Andrew Jones <[email protected]> Reviewed-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-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: Implement system suspendAndrew Jones
Fill the implementation of the system suspend ecall. A platform implementation of the suspend callbacks is still required for this to do anything. 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-01-06treewide: Replace TRUE/FALSE with true/falseBin Meng
C language standard uses true/false for the boolean type. Let's switch to that for better language compatibility. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Samuel Holland <[email protected]> Tested-by: Samuel Holland <[email protected]>
2021-10-11lib: sbi: add priority for reset handlerNikita Shubin
Let's make system_reset_check returning priority instead of only true/false. In that case 0 - means not supported, and anything above means priority that makes existing reset handlers being used in first place, unless it is decided to lower their priority. The handler with the most priority wins. Signed-off-by: Nikita Shubin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-10-11lib: sbi: convert reset to listNikita Shubin
To support different handlers for different types of resets, we are adding a sbi_list of restart handlers. Instead of sbi_system_reset_set_device we use sbi_system_reset_add_device to reflect the actual meaning. Signed-off-by: Nikita Shubin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-04-28lib: sbi: Simplify system reset platform operationsAnup Patel
Instead of having system_reset_check() and system_reset() callbacks in platform operations, it will be much simpler for reset driver to directly register these operations as a device to the sbi_system implementation. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Alistair Francis <[email protected]>
2021-03-03lib: sbi: Rename sbi_hsm_hart_started_mask() functionAnup Patel
A hart can take interrupt in the new HSM states introduced by the SBI HSM suspend function (such as SUSPENDED state) so we rename sbi_hsm_hart_started_mask() to something more generic such as sbi_hsm_hart_interruptible_mask(). Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-12-01lib: sbi: Improve system reset platform operationsAnup Patel
To implement the SBI SRST extension, we need two platform operations for system reset: 1) system_reset_check() - This operation will check whether given reset type and reason are supported by the platform 2) system_reset() - This operation will do the actual platform system reset and it will not return if reset type and reason are supported by the platform This patch updates system reset related code everywhere as-per above. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-12-01include: sbi: Remove opensbi specific reset type definesAnup Patel
We can now use the standard SBI SRST extension reset types instead of the opensbi specific (SBI_PLATFORM_RESET_xyz) reset types hence remove related opensbi specific defines. The "platform_" prefix of the reset type parameter of sbi_system_reset() function should also be removed. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Alistair Francis <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-10-20lib: sbi: Extend sbi_system_reset() for domainsAnup Patel
The sbi_system_reset() should issue platform system reset only if domain of current HART is allowed to do system reset. This patch extends sbi_system_reset() as-per above. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-10-20lib: sbi: Extend sbi_hsm_hart_started_mask() for domainsAnup Patel
The sbi_hsm_hart_started_mask() API should take one more parameter to allow caller specify domain under which started_mask is being generated. Further, the sbi_hsm_hart_started_mask() depends on sbi_hsm_hart_get_state() which also should return HART state under specified domain. This patch updates both sbi_hsm_hart_started_mask() and sbi_hsm_hart_get_state() as-per above. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Alistair Francis <[email protected]>
2020-04-27include: sbi_platform: Combine reboot and shutdown into one callbackAnup Patel
We can achieve shutdown, cold reboot, and warm reboot using just one sbi_platform callback so we combine system_reboot() and system_shutdown() callbacks into one system_reset() callback. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-03-28include: sbi_system: Remove scratch parameter and redundant functionsAnup Patel
This patch removes scratch parameter and redundant functions from sbi_system. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-03-28include: sbi_ipi: Remove scratch parameter from most functionsAnup Patel
This patch removes scratch parameter from most sbi_ipi functions. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-03-19lib: sbi_hsm: Remove scratch parameter from hart_started_mask() APIAnup Patel
The scratch parameter in sbi_hsm_hart_started_mask() API is now redundant hence removing it. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-03-13include: Make sbi_current_hartid() as macro in riscv_asm.hAnup Patel
The sbi_current_hartid() being a regular function is quite expensive because for callers it is a function call instead of a direct CSR read. This patch converts sbi_current_hartid() into a macro in riscv_asm.h. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-03-11lib: sbi_system: Use sbi_hsm_hart_started_mask() APIAnup Patel
This patch replaces use of sbi_hart_available_mask() API with sbi_hsm_hart_started_mask() API. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2020-03-08include: Move bits related defines and macros to sbi_bitops.hAnup Patel
The right location for all bits related defines and macros is sbi_bitops.h hence this patch. With this patch, the sbi_bits.h is redundant so we remove it. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-02-24lib: Implement hart hotplugAtish Patra
This patch adds support for hart hotplug in OpenSBI using a generic WFI based approach. Hart hotplug can be achieved via SBI HSM extension which allows supervisor mode software to start or stop any harts anytime. Any platform wishes to implement platform specific hart hotplug must implement both hart_start and hart_stop in addition to enable platform feature SBI_PLATFORM_HAS_HART_HOTPLUG. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2020-01-22lib: Introduce sbi_ipi_send_halt() APIAnup Patel
Instead of directly calling sbi_ipi_send_many(), we introduce sbi_ipi_send_halt() for halting a set of HARTs. This way in future we can assign any IPI event number for HART halting within sbi_ipi.c only. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-01-07lib: improve system reboot and shutdown implementationAnup Patel
We improve sbi_system_reboot() an sbi_system_shutdown() by: 1. Calling halt IPI to all harts (except current HART) before calling platform reboot/shutdown hook. 2. Calling sbi_exit() instead of sbi_hang() in-case platform reboot/shutdown hook failed. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2020-01-07lib: Add system early_exit and final_exit APIsAnup Patel
This patch adds system-level early_exit and final_exit APIs with corresponding platform hooks. These new APIs will be primarily used by sbi_exit() in OpenSBI exit path. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-12-23lib: Add IPI extension in SBIAtish Patra
This patch adds new IPI extension which replaces ipi related v0.1 extensions. This also adds a new API for ipi sending as trap handling is not necessary in v0.2 SBI IPI related extensions. It also modifies the IPI sending code which now accepts hart mask as a value instead of S-mode virtual address. Thus, the caller should set it to exact hart mask value everytime. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-06-19lib: Move sbi core library to lib/sbiAtish Patra
Signed-off-by: Atish Patra <[email protected]> Acked-by: Anup Patel <[email protected]>