summaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)AuthorFilesLines
2021-03-22include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__Marouene Boubakri6-10/+10
GCC has already a predefined macro __ASSEMBLER__ therefore, it can be used without the need to define a new flag with -D__ASSEMBLY__. This is useful when adding the library to projects having a build system such one can build without the need to make changes. THe build system does not use the Makefile in the sources tree. Signed-off-by: Marouene Boubakri <marouene.boubakri@nxp.com> Signed-off-by: Anup Patel <anup.patel@wdc.com>
2021-03-19firmware: Support position independent executionVincent Chen1-0/+14
Enable OpenSBI to support position independent execution. Because the position independent code will cause an additional GOT reference when accessing the global variables, it will reduce performance a bit. Therefore, the position independent execution is disabled by default. Users can through specifying "FW_PIC=y" on the make command to enable this feature. In theory, after enabling position-independent execution, the OpenSBI can run at arbitrary address with appropriate alignment. Therefore, the original relocation mechanism will be skipped. In other words, OpenSBI will directly run at the load address without any code movement. Signed-off-by: Vincent Chen <vincent.chen@sifive.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-03-12include: sbi: SBI function IDs for RFENCE extensionHeinrich Schuchardt1-4/+4
The SBI function IDs for RFENCE extension must match the SBI specification. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03include: sbi: Upgrade SBI implementation version to v0.3Anup Patel1-1/+1
The OpenSBI SBI implementation is now compliant with latest draft SBI v0.3 specification so let's upgrade SBI implementation version. This will also help HSM suspend function detection in S-mode because HSM suspend function is only present when HSM extension is present and SBI implementation version is 0.3 (or higher). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03lib: sbi: Implement SBI HSM suspend functionAnup Patel1-0/+4
This patch implements the SBI HSM suspend function. Using this new SBI call, the S-mode software can put calling HART in platform specific suspend (i.e. low-power) state. For a successful retentive suspend, the SBI call will return without errors upon resuming whereas for a successful non-retentive suspend, the SBI call will resume from a user provided resume address. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03include: sbi: Add hart_suspend() platform callbackAnup Patel1-0/+30
We add hart_suspend() callback in platform operations which will be used by HSM implementation to enter retentive or non-retentive suspend state. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03lib: sbi: Add sbi_hart_reinit() functionAnup Patel1-0/+1
We add sbi_hart_reinit() function which will re-initialize HART CSRs assuming HART features are already detected. This new function will be useful in re-initializing HART after it resumes from HSM SUSPENDED state. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03include: sbi: Add HSM suspend related definesAnup Patel1-0/+17
This patch adds SBI HSM suspend related defines to ecall interface header. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03lib: sbi: Rename sbi_hsm_hart_started_mask() functionAnup Patel1-2/+2
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 <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03lib: sbi: Use SBI_HSM_STATE_xyz defines instead of SBI_STATE_xyz definesAnup Patel1-8/+0
We replace the use of SBI_STATE_xyz defines with SBI_HSM_STATE_xyz defines because the HSM state defines are complete enough to implement HSM state machine in OpenSBI. As a result of this, we can now remove sbi_hsm_hart_state_to_status() function because it is now redundant and sbi_hsm_hart_get_state() can directly return HSM state or error. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03include: sbi: Simplify HSM state define namesAnup Patel1-4/+4
We simplify HSM state define names so that these defines can directly replace SBI_HART_xyz defines used by SBI HSM implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-18include: Bump-up version to 0.9Anup Patel1-1/+1
This patch updates OpenSBI version to 0.9 as part of release preparation. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2021-01-15include: sbi: Don't pack struct sbi_platform and sbi_platform_operationsAnup Patel1-2/+2
We don't need to pack struct sbi_platform and sbi_platform_operations because GCC ensures member offsets match member data type irrespective to the target system (RV32 or RV64). This also allows GCC to generate more optimized instruction sequence when accessing members of struct sbi_platform and struct sbi_platform_operations. Reported-by: Paul Campbell <taniwha@gmail.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-15include: sbi: No need to pack struct sbi_scratchAnup Patel1-1/+1
All members in struct sbi_scrach are of machine word size so no need to pack this structure. This also allows GCC to generate more optimized instruction sequence when accessing members of struct sbi_scratch. Reported-by: Paul Campbell <taniwha@gmail.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-15include: sbi: No need to pack struct sbi_trap_regsAnup Patel1-1/+1
All members in struct sbi_trap_regs are of machine word size so no need to pack this structure. This also allows GCC to generate more optimized instruction sequence when accessing members of struct sbi_trap_regs. Reported-by: Paul Campbell <taniwha@gmail.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-12lib: sbi: Allow platforms to provide root domain memory regionsAnup Patel1-1/+19
Currently, the root domain memory regions are fixed in generic code but some of the platforms may want to explicitly define memory regions for the root domain. This patch adds optional domains_root_regions() platform callback which platforms can use to provide platform specific root domain memory regions. Due to this changes, the root domain should also undergo all sanity checks (just like regular domain) so we use sbi_domain_register() to register root domain. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-07lib: sbi: Allow custom local TLB flush functionAnup Patel1-13/+11
Currently, we have fixed TLB flush types supported by the remote TLB library. This approach is not flexible and does not allow custom local TLB flush function. For example, after updating PMP entries on a set of HARTs at runtime, we have to flush TLB on these HARTs as well. To support custom local TLB flush function, we replace the "type" field of "struct sbi_tlb_info" with a local TLB flush function pointer. We also provide definitions of standard TLB flush operations (such as fence_i, sfence.vma, hfence.vvma, hfence.gvma, etc). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-07lib: sbi: Introduce sbi_trap_exit() APIAnup Patel2-3/+9
We introduce sbi_trap_exit() API which can help non-firmware (i.e. generic or platform) code to force exit trap/interrupt handling and resume execution at context pointed by parameter "const struct sbi_trap_regs *regs". This new sbi_trap_exit() API will help Keystone Enclave project to resume execution of enclave from custom SBI call handler. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-01-07lib: sbi: Replace args with trap registers in ecall handlerAnup Patel2-5/+7
We had added args pointer in ecall handler to ensure that ecall handler only implements functionality and does not deal with SBI calling convention. This also helped us to keep SBI calling convention related code in one place at sbi_ecall_handler(). The Keystone Enclavce project needs access to the trap regsiters in their ecall handler so that they can context switch enclaves in custom SBI calls. To help the Keystone Enclave project, we replace the args pointer in ecall handler parameter with a const pointer to trap registers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: sbi: Remove domain_get() platform callback functionAnup Patel1-18/+0
The domain_get() platform callback function is now redundant because fdt_domain_populate() register new domain explicitly using the sbi_domain_register() function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: utils: Remove fdt_domain_get() functionAnup Patel1-11/+0
The fdt_domain_get() function is now redundant because the fdt_domains_populate() function can explicitly register new domains using the sbi_domain_register() function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: sbi: Add function to register new domainAnup Patel1-0/+10
We add sbi_domain_register() function to help platform code register a new domain explicitly instead of depending on domain_get() platform callback. This function will eventually help us completely remove the domain_get() platform callback. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-16lib: utils: Allow FDT domain iteration functions to failAnup Patel1-7/+11
We extend fdt_iterate_each_domain() and fdt_iterate_each_memregion() functions to allow underlying iteration function to fail. This will help us catch more domain misconfiguration issues at boot time. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: utils: Add helper routines to populate domains from FDTAnup Patel1-0/+80
We add various helper routines to populate domains, iterate domains, iterate domain memregions, and parse HART to domain assignment from the FDT. These helper routines can be used by platform support code and FDT fixup code. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04include: sbi: Add domains_init() platform operationAnup Patel1-0/+16
We introduce domains_init() platform operation which can be used by platform support to initialize/populate domains in the coldboot path. The domains_init() is called late in the coldboot sequence from the sbi_domain_finalize() so sbi_printf() can be used by platform support to print errors/warnings at time of populating domains. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04include: sbi: Use lower bits for domain memory region permissionsAnup Patel1-2/+4
We should use lower bits for domain memory region access permissions and higher bits for other domain memory region attributes. This helps us use same bit assignment for parsing domain memory region access permissions from device tree. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01lib: sbi: Implement System Reset (SRST) SBI extensionAnup Patel1-0/+1
The SBI SRST extension has been accepted and merged in the latest SBI v0.3-draft specification. (Refer, https://github.com/riscv/riscv-sbi-doc) It allows to S-mode software to request system shutdown, cold reboot, and warm reboot. This patch implements SBI SRST extension as a replacement of the legacy sbi_shutdown() call of SBI v0.1 specification. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01lib: sbi: Improve system reset platform operationsAnup Patel5-12/+42
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 <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01include: sbi: Remove opensbi specific reset type definesAnup Patel2-4/+2
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 <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01include: sbi: Add SBI SRST extension related definesAnup Patel1-0/+12
We extend the SBI ecall interface header for the SBI SRST extension recently accepted in SBI specification v0.3-draft. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-26lib: sbi: Detect PMP granularity and number of address bitsAtish Patra1-0/+2
As per RISC-V privilege specification, a platform may choose to implement a coarser granularity scheme for PMP addresses. In that case, we shouldn't allow any pmp region size smaller than the platform supports. A platform may not also implement all the bits for a PMP address specified in the priv specification. The pmp range granularity and address bits should be detected dynamically before detecing PMP regions. Any pmp modification request beyond these detected value must not succeed. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-10-21lib: sbi: Display domain details in boot printsAnup Patel2-2/+8
We extend boot prints to display details of each domain. In the process, we remove sbi_hart_pmp_dump() because it shows redundant information which domain details already show. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Remove redundant sbi_hart_pmp_xyz() functionsAnup Patel1-6/+0
The sbi_hart_pmp_get() and sbi_hart_pmp_check_addr() functions are not used anymore hence this patch removes these functions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Extend sbi_hsm_hart_start() for domainsAnup Patel1-2/+3
The sbi_hsm_hart_start() should consider the domain under which we are trying to start the HART. This will help ensure that HART A can start HART B only if both HARTs A and B belong to the same domain. We also have a special case when we bring-up boot HART of non-root domains in sbi_domain_finalize() where we should skip domain checks in sbi_hsm_hart_start(). To achieve this, sbi_hsm_hart_start() should do domain checks only when domain parameter is non-NULL. This patch extends sbi_hsm_hart_start() as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: sbi: Extend sbi_hsm_hart_started_mask() for domainsAnup Patel1-3/+4
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 <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20lib: sbi: Add initial domain supportAnup Patel2-0/+167
An OpenSBI domain is a logical entity representing a set of HARTs and a set of memory regions for these HARTs. The OpenSBI domains support will allow OpenSBI platforms and previous booting stage (i.e. U-Boot SPL, Coreboot, etc) to partition a system into multiple domains where each domain will run it's own software. For inter-domain isolation, OpenSBI will eventually use various HW features such as PMP, ePMP, IOPMP, SiFive shield, etc but initial implementation only use HW PMP support. This patch provides initial implementation of OpenSBI domains where we have a root/default domain and OpenSBI platforms can provide non-root/custom domains using domain_get() callback. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20include: sbi: Make hartmask pointer const in sbi_hartmask_test_hart()Anup Patel1-1/+1
The sbi_hartmask_test_hart() does not modify hartmask so the hartmask pointer parameter should be declared const. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20lib: sbi: Remove redundant hartid parameter from sbi_hart_init()Anup Patel1-1/+1
The hartid parameter of sbi_hart_init() is not used anywhere in sbi_hart_init() implementation so let's remove it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20lib: sbi: Configure PMP late in coldboot and warmboot pathAnup Patel1-0/+1
We factor-out PMP configuration from sbi_hart_init() as a separate sbi_hart_pmp_configure() function and do the PMP configuration very late in coldboot and warmboot path just before platform_final_init(). Eventually, this enable us to configure PMP totally based on OpenSBI domain where OpenSBI domains can be parsed from device-tree in any of the platform operations except platform_final_init(). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20include: sbi: Remove pmp_region callbacks from sbi_platform_operationsAnup Patel1-50/+0
The pmp_region_xyz() callbacks are not required in sbi_platform_operations because we will be using OpenSBI domain memory regions to program the PMP CSRs. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-20include: sbi: Remove redundant includes from sbi_platform.hAnup Patel1-2/+2
The sbi_ecall.h and sbi_trap.h are not required to be included in sbi_platform.h hence we remove it. This way sources requiring these headers will have to explicitly include it thereby reducing implicit includes. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-10-02lib: sbi_scratch: typo scatchHeinrich Schuchardt1-1/+1
%s/scatch/scratch Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-09-16lib: sbi: Allow specifying mode in sbi_hart_pmp_check_addr() APIAnup Patel2-2/+3
We extend sbi_hart_pmp_check_addr() API so that users can specify privilege mode of the address for checking PMP access permissions. To achieve this, we end-up converting "unsigned long *size" parameter to "unsigned long *log2len" for pmp_get() implementation so that we can deal with regions of "1UL << __riscv_xlen" size in a special case in sbi_hart_pmp_check_addr() implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-16lib: sbi: Allow specifying start mode to sbi_hsm_hart_start() APIAnup Patel1-1/+1
The sbi_scratch already has provision to specify the next stage mode so we can leverage this to specify start mode to sbi_hsm_hart_start(). In future, this will be useful in providing SBI calls to U-mode on embedded cores where we M-mode and U-mode but no S-mode. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-09include: Rename ECALL defines to match latest RISC-V specAnup Patel1-2/+2
We rename CAUSE_HYPERVISOR_ECALL to CAUSE_SUPERVISOR_ECALL and CAUSE_SUPERVISOR_ECALL to CAUSE_VIRTUAL_SUPERVISOR_ECALL so that it matches latest RISC-V privilege spec. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-01include: sbi: Few cosmetic changes in riscv_encoding.hAnup Patel1-87/+139
This patch does following cosmentic changes to riscv_encoding.h: 1. Re-organize CSR defines to match CSR listing in latest RISC-V privilege spec 2. Rename CSR_HCOUNTERNEN to CSR_HCOUNTEREN Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-01lib: sbi: Detect and print MHPM counters at boot-timeAnup Patel1-0/+1
A RISC-V platform can leave unimplemented MHPM counters hard-wired to zero. We extend hart_detect_features() to detect MHPM counters which are accessible and not hard-wired to zero. We also print number of available MHPM counters as part of boot prints. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-01lib: sbi: Improve PMP CSR detection and progammingAnup Patel1-1/+66
As-per latest RISC-V privilege spec up to 64 PMP entries are supported. Implementations may implement zero, 16, or 64 PMP CSRs. All PMP CSR fields are WARL and may be hardwired to zero. This patch improves PMP CSR detection and progamming considering above facts. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-01lib: sbi: Remove redundant SBI_HART_HAS_PMP featureAnup Patel1-5/+3
The SBI_HART_HAS_PMP feature is redundant because we already have number of PMP regions returned by sbi_hart_pmp_count(). Checking whether PMP is supported for a HART can be simply done by checking non-zero value returned by sbi_hart_pmp_count(). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-07-29lib: Add sbi_strncmp implementationAbner Chang1-0/+7
This commit add an implementation of sbi_strncmp. Signed-off-by: Abner Chang <abner.chang@hpe.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>