summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2021-04-28firmware/fw_payload: reduce the size by getting rid of paddingdebugTekkaman Ninja5-1/+81
Signed-off-by: Tekkaman Ninja <tekkamanninja@163.com>
2021-04-28add starfive_vic7100 support in genericTekkaman Ninja3-0/+41
2021-04-28Add "snps,dw-apb-uart" in uart8250 driver.Tekkaman Ninja1-0/+1
This patch add "snps,dw-apb-uart".compatible ID in uart8250 driver for StarFive VIC-7100. Signed-off-by: Tekkaman Ninja <tekkamanninja@163.com>
2021-04-28Add StarFive VIC-7100 supportTekkaman Ninja3-0/+310
This patch add StarFive VIC-7100 support. Signed-off-by: Tekkaman Ninja <tekkamanninja@163.com>
2021-03-22include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__Marouene Boubakri8-12/+12
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-22lib: sbi: illegal CSR 0x306 access in hpm_allowed()Heinrich Schuchardt1-5/+14
The trap handler sbi_emulate_csr_read() invokes hpm_allowed() which reads CSR 0x306 (mcounteren). The K210 does not support CSR 0x306. While trying to handle a trap occurring in S-mode code this creates an additional trap in M-mode. This results in failure to redirect to S-mode and the system hanging in sbi_hart_hang(). In hart_detect_features() we have already determined if CSR 0x306 is available and stored that information in the scratch area. We can use this information to decide if CSR 0x306 shall be accessed in hpm_allowed() and thus avoid the M-mode trap. Likewise if CSR scounteren is not available we have to avoid reading CSR 0x106. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-03-19firmware: Support position independent executionVincent Chen5-2/+96
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-19firmware: Use lla to access all global symbolsVincent Chen5-64/+64
When OpenSBI is compiled as fPIE mode, the assembler will translate "la" to GOT reference pattern. It will cause to cost an additional load instruction when obtaining the symbol address. However, if the symbol locates within the positive or negative 2GB region, we can use "lla" instead of "la" to avoid unneeded GOT references. This patch assumes that the OpenSBI image excluding the payload does not exceed 2GB. Based on this assumption, all "la" instructions are replaced by "lla" to avoid performance degradation when compiling as fPIE mode. 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-03lib: Remove redundant sbi_platform_ipi_clear() callsAnup Patel3-7/+16
The sbi_platform_ipi_clear() called from wait_for_coldboot() and sbi_hsm_hart_wait() is redundant because IPI will be automatically cleared by sbi_platform_ipi_init() called from sbi_ipi_init(). Further, wait_for_coldboot() is common for warm startup and warm resume path so the sbi_platform_ipi_clear() called in warm resume path cause resuming HART to miss an IPI injected other HART to wakeup the HART. Signed-off-by: Anup Patel <anup.patel@wdc.com> 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 Patel4-9/+235
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 Patel2-12/+18
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: Fix error codes returned by HSM start() and stop() functionsAnup Patel1-2/+2
The sbi_hsm_hart_start() and sbi_hsm_hart_stop() functions should only return error codes as defined by the SBI specification. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03lib: sbi: Remove redundant sbi_hsm_hart_started() functionAnup Patel1-11/+3
The sbi_hsm_hart_started() function is only used by sbi_hsm_hart_stop() for checking state of calling HART and current domain assignment. The atomic_cmpxchg() called by sbi_hsm_hart_stop() will check state of calling hart anyway and domain assignment can be checked by other domain function such as sbi_domain_is_assigned_hart(). This means sbi_hsm_hart_started() is redundant and can be removed. 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 Patel5-9/+9
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 Patel3-55/+24
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 Patel2-8/+8
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-03-03platform: implement K210 system resetHeinrich Schuchardt2-0/+28
Implement rebooting the K210 via the system reset extension. All reset types are treated in the same way. A request for shutdown results in a reboot. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com> Reviewed-by: Anup Patel <anup.patel@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-18platform: template: Fix compile errorAnup Patel1-2/+2
This clint driver init functions were incorrectly used in template platform which resulted in compile error. This patch fixes clint driver function usage in template platform. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@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 Patel2-9/+27
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: utils: Fix shakti uart implementationVijai Kumar K1-2/+6
Fix uart_putc implementation. Due to a bug in the IP, this went unnoticed. Use macros instead of magic numbers to make the code more readable. Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-01-07lib: sbi: Allow custom local TLB flush functionAnup Patel4-64/+44
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 Patel4-3/+72
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 Patel9-69/+76
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-24lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()Anup Patel1-1/+1
The misaligned load emulation does not sign-extend values correctly due to missing sign typecast in value passed to the SET_RD() macro. A very easy way to reproduce this issue is to load 16-bit value 0xff1e from a byte aligned address using LH instruction on hardware lacking misaligned load/store. This patch fixes sbi_misaligned_load_handler() for above issue. 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 Patel2-93/+3
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 Patel3-59/+36
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 Patel2-0/+81
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 Patel2-54/+79
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-13lib: utils/libfdt: Upgrade to v1.6.0 releaseDimitri John Ledkov11-154/+356
Sync with libfdt v1.6.0 release source codes. Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-12-04platform: generic: Populate domains from FDTAnup Patel1-0/+9
The generic platform should populate domains from FDT using the domain FDT helper routines. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-04lib: utils: Add helper routines to populate domains from FDTAnup Patel3-0/+526
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-04docs: Add domain device tree binding documentationAnup Patel1-0/+208
This patch adds domain device tree binding documentation in the OpenSBI domain support documentation. 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 Patel2-0/+24
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-04lib: sbi: Add error prints in sbi_domain_finalize()Anup Patel1-11/+52
We add error prints in sbi_domain_finalize() and sanitize_domain() to help debug domain configuration issues. 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: sbi: Override domain boot HART when coldboot HART assigned to itAnup Patel1-0/+11
If coldboot HART is assigned to a domain then we should use coldboot HART as the boot HART of the domain. This allows coldboot HART to continue boot sequence even when it is assigned to some non-root domain. 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-04lib: sbi: Auto start domain only if boot HART within limitsAnup Patel1-0/+4
The sbi_domain_finalize() should auto start a domain only if the boot HART is withing limits (i.e. less than SBI_HARTMASK_MAX_BITS). 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: sbi: Fix domain_count check in sbi_domain_finalize()Anup Patel1-1/+1
The domain_count check in sbi_domain_finalize() for newly discovered domain is incorrect and should be reversed. 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: sbi: Fix typo in sbi_domain_finalize()Anup Patel1-2/+2
There has been typo in automatic domain boot hart startup for non-root domains so this patch fixes it. 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: sbi: Fix sbi_hart_switch_mode() for u-modeAnup Patel1-3/+5
We should check and access N-extension CSRs in sbi_hart_switch_mode() when next_mode is u-mode because N-extension is optional. 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-01firmware: fw_base: Optimize trap handler for RV32 systemsAnup Patel1-19/+68
On RV32 systems, we have two CSRs for M-mode status (MSTATUS and MSTATUSH) when H-extension is implemented. This means we have to save/restore MSTATUSH for RV32 systems only when H-extension is implemented. The current _trap_handler() has extra instructions (roughly 10) for conditional save/restore of MSTATUSH CSR. These extra instructions in RV32 _trap_handler() can be avoided if we create separate low-level trap handler for RV32 systems having H-extension. This patch optimizes low-level trap handler for RV32 systems accordingly. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-12-01lib: sbi: Implement System Reset (SRST) SBI extensionAnup Patel3-0/+64
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>