Commit graph

930 commits

Author SHA1 Message Date
Anup Patel
4d1eccc41d include: Add hard FP access macros and defines
This patch adds hardware floating-point (hard FP) access
macros and defines.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-03 14:21:08 -08:00
Anup Patel
81e8950abe include: Remove redundant csr_read_n() and csr_write_n()
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>
2019-01-02 09:57:12 +05:30
Anup Patel
5959312a5c lib: Redirect illegal instruction trap to S-mode when not handled
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-31 09:28:26 +05:30
Anup Patel
f2d4c5f291 lib: Print mtval in sbi_trap_error()
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-27 10:06:38 +05:30
Anup Patel
52ed1d1709 lib: Simplify sbi_platform timer_init() hooks
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-27 09:35:09 +05:30
Anup Patel
c1b6200653 lib: Simplify sbi_platform ipi_init() hooks
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-27 09:35:09 +05:30
Anup Patel
e34aa8a671 lib: Simplify sbi_platform irqchip_init() hooks
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-27 09:35:09 +05:30
Anup Patel
7b59571758 lib: Simplify sbi_platform early_init() and final_init() hooks
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-27 09:35:09 +05:30
Anup Patel
b46970b47e lib: Move ECALL defines to sbi_ecall_interface.h
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-27 09:29:29 +05:30
Anup Patel
b5ae8e8a65 lib: Add misaligned load/store trap handling
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-26 11:14:22 +05:30
Anup Patel
96f66f79ca lib: Move instruction encoding macros to riscv_encoding.h
This patch moves all instruction encoding macros to
riscv_encoding.h.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-26 11:14:22 +05:30
Atish Patra
88b173b33b Introduce hart disabled parameter in platform.
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-21 22:11:21 -08:00
Damien Le Moal
27332e63fa Introduce HAS_MFAULTS_DELEGATION feature
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-21 16:32:30 +05:30
Anup Patel
a18913200a lib: Remove prints from sbi_hart_switch_mode()
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-21 14:54:06 +05:30
Anup Patel
1bfa244505 lib: Fix delegate_traps() for Linux boot
commit d403c70fb1 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-21 14:54:06 +05:30
Damien Le Moal
e1e8f18130 console: protect output with a spinlock
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-21 18:12:58 +09:00
Damien Le Moal
5563a03354 Introduce sbi_current_hartid()
Use this helper instead of hardcoding csr_read(mhartid).

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21 17:06:59 +09:00
Damien Le Moal
426adf9f60 Cleanup and rename sbi_hart_boot_next()
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-21 16:44:53 +09:00
Damien Le Moal
d403c70fb1 Fix interrupt and exception delegation
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-21 15:12:22 +09:00
Damien Le Moal
9c183df632 Add a hang message
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-21 15:12:22 +09:00
Damien Le Moal
84df181c84 Add a banner
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2018-12-21 15:09:13 +09:00
Damien Le Moal
aa68f0252f Refine platform features control
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-21 15:09:13 +09:00
Atish Patra
f003787455 lib: Hang in sbi_hart_boot_next() if next mode is not supported
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-21 11:09:47 +05:30
Anup Patel
6f02b6938f lib: Introduce bitmap to track HARTs waiting for coldboot
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-21 10:09:33 +05:30
Anup Patel
ab5b228ff5 lib: sbi_hart: Remove unwanted sbi_printf()
This patch removes unwanted sbi_printf() from
sbi_hart_wait_for_coldboot().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-21 07:51:59 +05:30
Atish Patra
1d4e36edf8 Support unsigned long in sbi_printf
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-20 15:55:32 -08:00
Atish Patra
84971c0bc0 Use wfi for coldboot finish call.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-20 15:55:27 -08:00
Atish Patra
3250fe7299 Support /r/n as newline character.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2018-12-20 15:38:43 -08:00
Anup Patel
292e6344fa lib: Don't emulate CSR read for misa and mhartid
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-16 10:15:55 +05:30
Anup Patel
9e8ff05cb6 Initial commit.
Signed-off-by: Anup Patel <anup.patel@wdc.com>
2018-12-11 19:24:06 +05:30