summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2019-01-22lib: Add atomic bit set/clear operations.Atish Patra1-0/+49
Add addtional functionlities for set/clear bits atomically. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-22lib: Move software interrupt enablement from firmware to libAtish Patra1-0/+4
The secondary hart waits for an IPI signal from the boot hart to executing boot code (hot boot). As a result, software generated interrupts have to be enabled for secondary harts before waiting for the boot hart boot completion IPI signal. Enabling software generated interrupts (IPI) can be done independently of the firmware code and moved to libsbi code so that the different firmware do not have to implement this. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-21lib: Use AMO instructions whenever __riscv_atomic is definedAnup Patel1-0/+24
We should use AMO instructions whenever __riscv_atomic is defined (i.e. atomics are supported). We use LR/SC only when __riscv_atomic is not defined. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-21lib: code cleanupDamien Le Moal1-0/+5
Use commonly accepted styles: newlines after declarations and before return to make the code more readable. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21lib: Fix bannerDamien Le Moal1-11/+11
Define the "OpenSBI" logo string as a macro renamed BANNER, since it is one rather than a logo. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-16include: Add documentation for sbi_trap_regs and friendsAnup Patel2-5/+32
This patch adds doxygen style documentation for struct sbi_trap_regs and related macros/defines/functions. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-16lib: Add documentation for sbi_init() APIAnup Patel1-5/+14
This patch adds doxygen style documentation for sbi_init() API. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-04lib: Handle misaligned load/store on FP regsAnup Patel1-2/+50
This patch extends misaligned load/store trap handling to handle FP regs as well. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-04include: Add hard FP access macros and definesAnup Patel3-7/+173
This patch adds hardware floating-point (hard FP) access macros and defines. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-02include: Remove redundant csr_read_n() and csr_write_n()Anup Patel1-40/+40
The patch removes redundant csr_read_n() and csr_write_n() because same thing can be achieved by using __ASM_STR() macro in csr_read() and csr_write() macros. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-31lib: Redirect illegal instruction trap to S-mode when not handledAnup Patel2-3/+46
Currently, we fail with error SBI_ENOTSUPP when we are not able to handle illegal instruction trap. Instead, we should just redirect illegal instruction trap to S-mode when not handled. This redirection of illegal instruction trap will help lazy save/restore of floating point registers to work correctly in Linux kernel. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27lib: Print mtval in sbi_trap_error()Anup Patel1-11/+11
The mtval CSR is very useful information when debugging hence print it upon trap error in sbi_trap_error(). Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27lib: Simplify sbi_platform timer_init() hooksAnup Patel2-13/+6
Instead of having separate timer_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one timer_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated timer_init() hook. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27lib: Simplify sbi_platform ipi_init() hooksAnup Patel2-13/+5
Instead of having separate ipi_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one ipi_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated ipi_init() hook. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27lib: Simplify sbi_platform irqchip_init() hooksAnup Patel1-6/+2
Instead of having separate irqchip_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one irqchip_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated irqchip_init() hook. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27lib: Simplify sbi_platform early_init() and final_init() hooksAnup Patel2-26/+12
Instead of having separate early_init() and final_init() hooks for cold and warm boot, this patch updates struct sbi_platform to have just one early_init() and one final_init() hook. The type of boot (cold or warm) is now a boolean flag parameter for the updated early_init() and final_init() hooks. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-27lib: Move ECALL defines to sbi_ecall_interface.hAnup Patel1-10/+1
This patch moves all ECALL defines to sbi_ecall_interface.h so that it can be shared with firmware payloads. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-26lib: Add misaligned load/store trap handlingAnup Patel3-1/+140
We generally don't get misaligned load/store traps from Linux/U-Boot compiled using GCC 8.2 or higher but this is not true with older GCC toolchains. To tackle this we add misaligned load/store trap handling adopted from BBL sources but much more simpler. (Note: BBL sources can be found at https://github.com/riscv/riscv-pk.git) Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-26lib: Move instruction encoding macros to riscv_encoding.hAnup Patel1-50/+0
This patch moves all instruction encoding macros to riscv_encoding.h. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-22Introduce hart disabled parameter in platform.Atish Patra3-7/+10
As of now, uboot doesn't have support for SMP. Moreover, unleashed board has a E51 hart which doesn't not support S mode. We should only boot only 1 non-zero hart. Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-21Introduce HAS_MFAULTS_DELEGATION featureDamien Le Moal1-5/+7
Conditionnally delegate page fault exceptions from M mode to S mode based on the platform features. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21lib: Remove prints from sbi_hart_switch_mode()Anup Patel1-8/+1
The sbi_hart_switch_mode() will be used by CPU hotplug. This means if we have prints in sbi_hart_switch_mode() then these prints will mix with Linux prints. Being a runtime firmware, we should be verbose only at coldboot time and error situations. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21lib: Fix delegate_traps() for Linux bootAnup Patel1-0/+3
commit d403c70fb11fb55042ca3cef0dbe399ed87cc79b breaks Linux booting because of fewer exceptions delegated to S-mode. This patch fixes Linux booting by having all required exceptions delegated to S-mode. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21console: protect output with a spinlockDamien Le Moal1-9/+11
Avoid getting messages from multiple harts mingled into garbage text with a spinlock serializing calls to sbi_puts() and sbi_printf(). Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21Introduce sbi_current_hartid()Damien Le Moal3-4/+13
Use this helper instead of hardcoding csr_read(mhartid). Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21Cleanup and rename sbi_hart_boot_next()Damien Le Moal2-14/+29
Cleanup sbi_hart_boot_nexti() code, adding messages for clarity and rename the function to sbi_hart_switch_mode() to reflect what the function actually does. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21Fix interrupt and exception delegationDamien Le Moal1-11/+13
When S mode is not supported, simply clear mideleg and medeleg. Otherwise, set delegation from M-mode to S-mode, removing the page fault exceptions as those would not happen in M-mode. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21Add a hang messageDamien Le Moal1-0/+2
Make it clear that the end of the FW execution was reached without the hand being passed to any payload. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21Add a bannerDamien Le Moal1-1/+14
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21Refine platform features controlDamien Le Moal2-11/+18
Allow a platform to report its supported features in more details. The new features defined are: * SBI_PLATFORM_HAS_PMP * SBI_PLATFORM_HAS_SCOUNTEREN * SBI_PLATFORM_HAS_MCOUNTEREN In addition, define the macro SBI_PLATFORM_DEFAULT_FEATURES as the set of features that are generally expected to be supported by a Linux capable platform. Operations touching the features controlled with these falgs are not executed if the platform does not set the corresponding feature flags. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21lib: Hang in sbi_hart_boot_next() if next mode is not supportedAtish Patra1-0/+4
We should not jump to next stage if next mode (S-mode or U-mode) is not supported by HART. Signed-off-by: Atish Patra <atish.patra@wdc.com> Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21lib: Introduce bitmap to track HARTs waiting for coldbootAnup Patel1-5/+16
On QEMU Virt, max supported HARTs are 8 but number of HARTs actually depend on "-smp" command-line parameter passed to QEMU. This creates problems in sbi_hart_wake_coldboot_harts() because when number of HARTs are less than 8. To tackle this, we introduce a bitmap to track HARTs waiting for coldboot to finish. We wake only those HARTs who have set their bit in coldboot bitmap. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21lib: sbi_hart: Remove unwanted sbi_printf()Anup Patel1-5/+3
This patch removes unwanted sbi_printf() from sbi_hart_wait_for_coldboot(). Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21Support unsigned long in sbi_printfAtish Patra1-1/+6
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-21Use wfi for coldboot finish call.Atish Patra2-16/+19
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-21Support /r/n as newline character.Atish Patra1-0/+2
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-16lib: Don't emulate CSR read for misa and mhartidAnup Patel1-15/+0
Emulation of CSR read for misa and mhartid was a workaround for bootloader accessing these CSRs in S-mode. This patch removes CSR read emulation for misa and mhartid. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-11Initial commit.Anup Patel14-0/+2081
Signed-off-by: Anup Patel <anup.patel@wdc.com>