platform/kernel/opensbi-spacemit.git
4 years agolib: sbi: Fix coding style issues
Bin Meng [Mon, 9 Mar 2020 03:52:41 +0000 (20:52 -0700)]
lib: sbi: Fix coding style issues

This fixes various coding style issues found in the SBI codes.
No functional changes.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: ae350: Sort build objects in alphabetical order
Bin Meng [Mon, 9 Mar 2020 02:17:58 +0000 (19:17 -0700)]
platform: ae350: Sort build objects in alphabetical order

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Sort build objects in alphabetical order
Bin Meng [Mon, 9 Mar 2020 02:17:57 +0000 (19:17 -0700)]
lib: Sort build objects in alphabetical order

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoinclude: sbi_scratch: Set per-HART scratch size to 4KB
Anup Patel [Wed, 4 Mar 2020 08:46:42 +0000 (14:16 +0530)]
include: sbi_scratch: Set per-HART scratch size to 4KB

Currently, the per-HART scratch size is 256 bytes on RV32 and
512 bytes on RV64. This patch set per-HART scratch size to 4KB
(4096 bytes) for both RV32 and RV64 so that we don't run-out
of scratch space anytime soon.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: kendryte/k210: Set per-HART stack size to 8KB
Anup Patel [Wed, 4 Mar 2020 08:40:03 +0000 (14:10 +0530)]
platform: kendryte/k210: Set per-HART stack size to 8KB

All platform except kendryte/k210 use 8KB of per-HART stack hence
this patch set per-HART stack size of kendryte/k210 to 8KB for
consistency.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi_bitops: More useful bit operations
Anup Patel [Wed, 4 Mar 2020 06:18:31 +0000 (11:48 +0530)]
include: sbi_bitops: More useful bit operations

This patch extends our bit operation library with mechanism to:
1. Iteratively traverse bits
2. Set bit
3. Clear bit
4. Change bit
5. ... other helpful functions ...

Most the above is adopted from Xvisor sources.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Move bits related defines and macros to sbi_bitops.h
Anup Patel [Wed, 4 Mar 2020 05:38:35 +0000 (11:08 +0530)]
include: Move bits related defines and macros to sbi_bitops.h

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 <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Fix return type of sbi_hsm_hart_started()
Anup Patel [Mon, 2 Mar 2020 07:45:17 +0000 (13:15 +0530)]
lib: Fix return type of sbi_hsm_hart_started()

The return type of sbi_hsm_hart_started() should be bool.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agoplatform: sifive: fu540: allow sv32 as an mmu-type
Sören Tempel [Sun, 8 Mar 2020 05:05:32 +0000 (10:35 +0530)]
platform: sifive: fu540: allow sv32 as an mmu-type

There has already been a commit to master which added 32-bit specific
fdt/payload addresses for the sifive/fu540 platform [0]. This commit
introduces another change for using sifive/fu540 as a 32-bit platform.
On 32-bit platforms, cores with the SV32 MMU type should not be
disabled. For this reason, this commit also allows using this MMU type
on the sifive/fu540 platform.

Alternatively it would also be possible to only allow SV39 and SV48 if
`__riscv_xlen == 64` and SV32 if `__riscv_xlen == 32`. Removing the
check entirely would also be an option.

[0]: 66fb729a1e46a9a46e809f3b7867fef91477e494

Signed-off-by: Sören Tempel <tempel@uni-bremen.de>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agomakefile: Do setup of the install target more flexible
Nikita Ermakov [Sat, 7 Mar 2020 22:31:02 +0000 (01:31 +0300)]
makefile: Do setup of the install target more flexible

- Add possibility to setup include, libs, firmware and docs paths.

- Change the default installation paths for include, libs, firmware
  and docs to meet FHS [1].

[1] https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html

Signed-off-by: Nikita Ermakov <coffe92@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Check MSIP bit after returning from WFI
Atish Patra [Fri, 6 Mar 2020 19:44:44 +0000 (11:44 -0800)]
lib: Check MSIP bit after returning from WFI

As per the RISC-V privilege specification, WFI can be implemented as
a NOP. Software should ensure that relevant interrupt pending bits
are set. Otherwise, loop back to WFI.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: Implement Hart State Management (HSM) SBI extension
Atish Patra [Wed, 12 Feb 2020 01:32:39 +0000 (17:32 -0800)]
lib: Implement Hart State Management (HSM) SBI extension

This patch adds support HSM extension. The specification is available
at https://github.com/riscv/riscv-sbi-doc.

It allows to implement hart hotplug and fixed ordered hart booting in
supervisor.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add possible hart status values
Atish Patra [Wed, 12 Feb 2020 01:32:38 +0000 (17:32 -0800)]
lib: Add possible hart status values

SBI HSM extension defines possible hart status values in the
specification.

Define all possible status values. Add a helper function to
convert hart state to status because hart states are internal
to OpenSBI only and may not match the status values defined in
the specification.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Implement hart hotplug
Atish Patra [Wed, 12 Feb 2020 01:32:37 +0000 (17:32 -0800)]
lib: Implement hart hotplug

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 <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add a new platform feature to bringup secondary harts
Atish Patra [Wed, 12 Feb 2020 01:32:36 +0000 (17:32 -0800)]
lib: Add a new platform feature to bringup secondary harts

A platform may have a specific method to bring-up secondary harts for the
first time but may rely on generic WFI based approach for hart hotplug in
absence of a platform specific hart hotplug method.

Define a platform feature flag for such platforms. The platform needs to
implement platform specific bring-up method in hart_start and not define
hart_stop method in this case. They must only define
SBI_PLATFORM_HAS_HART_SECONDARY_BOOT.

SBI_PLATFORM_HAS_HART_HOTPLUG should only be defined when the platform
intend to support both hart_start and hart_stop and do not intend to rely
on generic WFI based approach.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoinclude: Bump-up version to 0.6
Anup Patel [Mon, 24 Feb 2020 05:57:57 +0000 (11:27 +0530)]
include: Bump-up version to 0.6

This patch updates OpenSBI version to 0.6 as part of
release preparation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Simplify the for-loop in sbi_ipi_send_many()
Anup Patel [Sat, 22 Feb 2020 06:20:55 +0000 (11:50 +0530)]
lib: Simplify the for-loop in sbi_ipi_send_many()

We don't need to separately call sbi_ipi_send() for current HART
in sbi_ipi_send_many(). Instead, we can simplify the for-loop in
sbi_ipi_send_many() and call sbi_ipi_send() for all HARTs in the
for-loop itself.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: Use available hart mask for correct hbase value
Atish Patra [Fri, 21 Feb 2020 23:47:54 +0000 (15:47 -0800)]
lib: Use available hart mask for correct hbase value

As per the latest SBI specification, all online harts should receive
IPI if hbase is set to -1.

Set the target mask to all available hart mask if hbase is -1.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Fix typo in atomic exchange functions
Atish Patra [Fri, 21 Feb 2020 23:47:53 +0000 (15:47 -0800)]
lib: Fix typo in atomic exchange functions

There is a typo in atomic operations code which prevents the
usage of riscv atomic instructions even if it is supported.

Fix the typo.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: qemu: virt: Correct the typo in config.mk
Bin Meng [Tue, 18 Feb 2020 10:18:33 +0000 (02:18 -0800)]
platform: qemu: virt: Correct the typo in config.mk

It should be "aligned".

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: sifive: fu540: Add 32-bit specific fdt/payload addresses
Bin Meng [Tue, 18 Feb 2020 10:15:59 +0000 (02:15 -0800)]
platform: sifive: fu540: Add 32-bit specific fdt/payload addresses

For testing 32-bit SiFive specific drivers with QEMU riscv32, add
32-bit specific FW_JUMP_FDT_ADDR and FW_PAYLOAD_OFFSET.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Print interrupt and exception delegation in boot prints
Anup Patel [Tue, 18 Feb 2020 06:23:52 +0000 (11:53 +0530)]
lib: Print interrupt and exception delegation in boot prints

We print MIDELEG and MEDELEG CSRs as part of boot prints so that
boot log shows the interrupts and exceptions delegated to S-mode.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Don't check MIDELEG and MEDELEG at end of delegate_traps()
Anup Patel [Tue, 18 Feb 2020 06:07:16 +0000 (11:37 +0530)]
lib: Don't check MIDELEG and MEDELEG at end of delegate_traps()

The MIDELEG and MEDELEG CSR checks at end of delegate_traps() were
added for initial bring-up on SiFive Unleashed and QEMU. These
checks are not required any more and in-future these checks can
cause failures because some of the MIDELEG/MEDELEG bits will be
hard-wired to 0 or 1.

For related discussion, refer github issue:
https://github.com/riscv/opensbi/issues/157

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: htif: Fix 32-bit build
Bin Meng [Tue, 18 Feb 2020 04:55:12 +0000 (20:55 -0800)]
lib: utils: htif: Fix 32-bit build

When building 32-bit OpenSBI images, we get:

  lib/utils/sys/htif.c: In function '__check_fromhost':
  lib/utils/sys/htif.c:12:31: error: left shift count >= width of type
                                     [-Werror=shift-count-overflow]
   #define HTIF_DATA_MASK  ((1UL << HTIF_DATA_BITS) - 1)
                                 ^~

Fixes: c2f23cc6edd7 ("platform: Add Spike initial support")
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoRevert "lib: Use __builtin_ctzl() in pmp_get()"
Anup Patel [Tue, 18 Feb 2020 03:56:33 +0000 (09:26 +0530)]
Revert "lib: Use __builtin_ctzl() in pmp_get()"

This reverts commit 897b8fbdd92fcfad194417d348b8dad16ab0e17a.

We are seeing compile errors using newlib based GCC cross-toolchain
so we restore back old ctz() implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agodoc: thead-c910: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:39 +0000 (07:19 -0800)]
doc: thead-c910: Fix doc styles

- make title underline the same length as the title itself
- satisfy the 80 character per line rule as much as possible

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodoc: sifive_fu540: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:38 +0000 (07:19 -0800)]
doc: sifive_fu540: Fix doc styles

- make title underline the same length as the title itself
- put all URLs at the end of the doc

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodoc: qemu_virt: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:37 +0000 (07:19 -0800)]
doc: qemu_virt: Fix doc styles

Remove the unnecessary blank line at the end of the doc.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodoc: ariane-fpga: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:36 +0000 (07:19 -0800)]
doc: ariane-fpga: Fix doc styles

Various styles fixes including:

- satisfy the 80 character per line rule as much as possible
- make title underline the same length as the title itself
- remove the redundant FPGA (was FPGA FPGA SoC)

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodoc: andes-ae350: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:35 +0000 (07:19 -0800)]
doc: andes-ae350: Fix doc styles

Various styles fixes including:

- satisfy the 80 character per line rule as much as possible
- remove unnecessary spaces between words

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodoc: payload_linux: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:34 +0000 (07:19 -0800)]
doc: payload_linux: Fix doc styles

Remove the unnecessary blank line at the end of the doc.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodoc: coreboot: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:33 +0000 (07:19 -0800)]
doc: coreboot: Fix doc styles

- put all URLs at the end of the doc
- satisfy the 80 character per line rule as much as possible

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoThirdPartyNotices: Fix doc styles
Bin Meng [Sun, 16 Feb 2020 15:19:32 +0000 (07:19 -0800)]
ThirdPartyNotices: Fix doc styles

Remove the unnecessary blank line at the end of the doc.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodocs: platform: Add documentation for Spike platform
Anup Patel [Thu, 13 Feb 2020 12:10:17 +0000 (17:40 +0530)]
docs: platform: Add documentation for Spike platform

This patch adds documentation to build and run OpenSBI on
Spike simulator and QEMU Spike machine.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agoscripts: Add Spike to platform list of binary archive script
Anup Patel [Thu, 13 Feb 2020 11:35:15 +0000 (17:05 +0530)]
scripts: Add Spike to platform list of binary archive script

The Spike platform support works perfectly fine on QEMU RV64 Spike
machine and Spike emulator.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agoplatform: Remove stale options from config.mk files
Anup Patel [Thu, 13 Feb 2020 11:32:41 +0000 (17:02 +0530)]
platform: Remove stale options from config.mk files

This patch removes stale options from config.mk files of
Ariane FPGA and QEMU virt platform support.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: Add Spike initial support
James Clarke [Sat, 1 Feb 2020 01:07:51 +0000 (01:07 +0000)]
platform: Add Spike initial support

This patch adds initial platform support Spike emulator.

Signed-off-by: James Clarke <jrtc27@jrtc27.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: irqchip/plic: Disable all contexts and IRQs
Atish Patra [Wed, 12 Feb 2020 01:42:50 +0000 (17:42 -0800)]
lib: irqchip/plic: Disable all contexts and IRQs

To initialize PLIC in sane state, we should:
1. set maximum threshold value of M-mode PLIC contexts
2. set maximum threshold value of S-mode PLIC contexts
3. set irq priorities to miniumum

Fix the comment and initialize the threshold/priorities correctly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Initialize out value in SBI calls
Atish Patra [Wed, 12 Feb 2020 01:39:45 +0000 (17:39 -0800)]
lib: Initialize out value in SBI calls

As per the SBI specification, the return value in sbiret is undefined
if not explicitly described in the function. However, supervisor may
check this value by mistake and get a garbage value.

Initialize it to zero to avoid nasty supervisor bugs.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Use __builtin_ctzl() in pmp_get()
Li Jinpei [Tue, 11 Feb 2020 10:07:24 +0000 (15:37 +0530)]
lib: Use __builtin_ctzl() in pmp_get()

We should should __builtin_ctzl() in pmp_get() instead of
custom ctz() function.

Signed-off-by: Li Jinpei <leekingp1994@163.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_scratch: use bitwise ops in sbi_scratch_alloc_offset()
Li Jinpei [Tue, 11 Feb 2020 09:57:49 +0000 (15:27 +0530)]
lib: sbi_scratch: use bitwise ops in sbi_scratch_alloc_offset()

Instead of using loop to make "size" machine word aligned, we should
use bitwise ops.

Signed-off-by: Li Jinpei <leekingp1994@163.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agodoc: sifive: fu540: Update QEMU instruction when using U-Boot as the payload
Bin Meng [Mon, 10 Feb 2020 15:42:03 +0000 (07:42 -0800)]
doc: sifive: fu540: Update QEMU instruction when using U-Boot as the payload

Document that when U-Boot v2020.01 (or higher) is used as the payload,
we need adjust the instructions a little bit when testing OpenSBI with
QEMU 'sifive_u' machine.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: sifive: fu540: Add platform specific 'make run' cmd
Bin Meng [Thu, 6 Feb 2020 12:15:21 +0000 (04:15 -0800)]
platform: sifive: fu540: Add platform specific 'make run' cmd

This adds sifive/fu540 specific QEMU run command.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Drop qemu/sifive_u support
Bin Meng [Thu, 6 Feb 2020 11:51:23 +0000 (03:51 -0800)]
platform: Drop qemu/sifive_u support

With QEMU v4.2 RISC-V changes to improve the emulation fidelity
of 'sifive_u' machine, OpenSBI v0.4 / U-Boot v2019.10 / Linux
kernel v5.3 images built for the SiFive HiFive Unleashed board
can be used out of the box without any special hack. Hence there
is no need for us to continue supporting such a special target in
OpenSBI. Going forward, sifive/fu540 platform can be used on both
real hardware and QEMU 'sifive_u' machine.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agomakefile: add support for building on macOS
Alex Richardson [Thu, 6 Feb 2020 04:27:34 +0000 (09:57 +0530)]
makefile: add support for building on macOS

On macOS the readlink command does not include a -f flag. Instead default
to using GNU readlink (which is often installed as greadlink).

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: sifive/fu540: Set tlb range flush limit to zero
Atish Patra [Tue, 4 Feb 2020 23:09:15 +0000 (15:09 -0800)]
platform: sifive/fu540: Set tlb range flush limit to zero

It was reported that tlb range flush is not working on fu540.
Only tlb full flush seems to work on fu540 probably due to some
hardware errata.

Set the tlb flush limit to zero so that all tlb flush requests
are converted to full flush.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Add an platform ops to return platform specific tlb flush limit
Atish Patra [Tue, 4 Feb 2020 23:09:14 +0000 (15:09 -0800)]
platform: Add an platform ops to return platform specific tlb flush limit

If a platform requires to perform a tlb full flush, they should set
the tlb_range_flush_limit value to zero. However, corresponding platform
API ignore the value and continue to return the default value.

Add a platform ops to retrieve platform specific tlb range flush limit.
The platform variable becomes redundant in presence of the platform ops.
Take this opportunity to remove the variable as well.

The default is still set to smallest page size in RISC-V (4KB), as there
is no way to figure out a best value for all platforms. Individual platform
should set it to the optimal value for their platform.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Update UART base addresses for qemu/sifve_u
Nikita Ermakov [Fri, 24 Jan 2020 13:47:32 +0000 (16:47 +0300)]
platform: Update UART base addresses for qemu/sifve_u

In the QEMU [1] there was a change of the UART base addresses for
sifive_u machine to match the hardware. Make corresponding changes in
the opensbi for qemu/sifive_u platform.

[1] https://git.qemu.org/?p=qemu.git;a=commitdiff;h=4b55bc2b5f7ff065da5d2b813ee5153c598d3764

Signed-off-by: Nikita Ermakov <coffe92@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: template: typo fix in system reboot/shutdown names
Jiuyang Liu (Sequencer) [Fri, 24 Jan 2020 02:04:10 +0000 (07:34 +0530)]
platform: template: typo fix in system reboot/shutdown names

This patch does minor typo fix in system reboot/shutdown names
in platform operations.

Signed-off-by: Jiuyang Liu (Sequencer) <liujiuyang1994@gmail.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Factor-out SBI base extension
Anup Patel [Fri, 17 Jan 2020 13:55:24 +0000 (19:25 +0530)]
lib: Factor-out SBI base extension

This patch factor-out SBI base extension into its own source
for better modularity of SBI implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Factor-out SBI vendor extension
Anup Patel [Fri, 17 Jan 2020 13:42:52 +0000 (19:12 +0530)]
lib: Factor-out SBI vendor extension

This patch factor-out SBI vendor extension into its own source
for better modularity of SBI implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Factor-out SBI replacement extensions
Anup Patel [Fri, 17 Jan 2020 13:02:07 +0000 (18:32 +0530)]
lib: Factor-out SBI replacement extensions

This patch factor-out SBI replacement extensions (such as RFENCE,
IPI, and TIME) into its own source for better modularity of SBI
implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Factor-out SBI legacy extension
Anup Patel [Fri, 17 Jan 2020 12:39:49 +0000 (18:09 +0530)]
lib: Factor-out SBI legacy extension

This patch factor-out SBI legacy extension into its own source
for better modularity of SBI implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Add dynamic registration of SBI extensions
Anup Patel [Thu, 16 Jan 2020 06:08:49 +0000 (11:38 +0530)]
lib: Add dynamic registration of SBI extensions

This patch extends our SBI ecall implementation to allow
dynamic registration of various SBI extensions. Using this
dynamic registration we can break-up SBI ecall implementation
into multiple files and even register experimental/custom
SBI extensions from platform code.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Add generic and simple list handling APIs
Anup Patel [Fri, 17 Jan 2020 11:12:41 +0000 (16:42 +0530)]
include: Add generic and simple list handling APIs

This patch adds generic and simple list handling APIs adapted
from Xvisor sources.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Initialize TLB management directly from coldboot/warmboot path
Anup Patel [Wed, 15 Jan 2020 08:01:12 +0000 (13:31 +0530)]
lib: Initialize TLB management directly from coldboot/warmboot path

Currently, the remote TLB management is initialized via IPI init
which is counter intuitive. This patch initializes remote TLB
management directly from init_coldboot() and init_warmboot()
after IPI init is done.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Drop _fifo from the name of various sbi_tlb_fifo_xyz() functions
Anup Patel [Wed, 15 Jan 2020 07:51:47 +0000 (13:21 +0530)]
lib: Drop _fifo from the name of various sbi_tlb_fifo_xyz() functions

This patch drops _fifo from the name of various sbi_tlb_fifo_xyz()
functions because all these functions deal with remote TLB managment
and FIFO is the per-HART data structure used internally by remote
TLB implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Introduce sbi_ipi_event_create/destroy() APIs
Anup Patel [Wed, 15 Jan 2020 07:14:10 +0000 (12:44 +0530)]
lib: Introduce sbi_ipi_event_create/destroy() APIs

This patch introduces sbi_ipi_event_create/destroy() APIs and
struct sbi_ipi_event_ops for creating/destroying IPI events
at runtime based of event operations.

This new APIs will help platform code and utils code to create
custom IPI events which are not part of generic OpenSBI library.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Introduce sbi_tlb_fifo_request() API
Anup Patel [Wed, 15 Jan 2020 06:12:51 +0000 (11:42 +0530)]
lib: Introduce sbi_tlb_fifo_request() API

Instead of directly calling sbi_ipi_send_many(), we introduce
sbi_tlb_fifo_request() for halting a set of HARTs.

This way in future we can assign any IPI event number for remote
FENCE within sbi_tlb.c only.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Introduce sbi_ipi_send_halt() API
Anup Patel [Wed, 15 Jan 2020 05:46:54 +0000 (11:16 +0530)]
lib: Introduce sbi_ipi_send_halt() API

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 <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Introduce sbi_ipi_send_smode() API
Anup Patel [Wed, 15 Jan 2020 05:32:14 +0000 (11:02 +0530)]
lib: Introduce sbi_ipi_send_smode() API

Instead of directly calling sbi_ipi_send_many(), we introduce
sbi_ipi_send_smode() for injecting S-mode software interrupts.

This way in future we can assign any IPI event number for S-mode
IPIs within sbi_ipi.c only.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Move struct sbi_ipi_data definition to sbi_ipi.c
Anup Patel [Wed, 15 Jan 2020 05:18:56 +0000 (10:48 +0530)]
lib: Move struct sbi_ipi_data definition to sbi_ipi.c

The struct sbi_ipi_data is only used in sbi_ipi.c so move it
to sbi_ipi.c from sbi_ipi.h.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Typo fix in comment for SBI_SCRATCH_SIZE define
Anup Patel [Wed, 15 Jan 2020 05:15:45 +0000 (10:45 +0530)]
include: Typo fix in comment for SBI_SCRATCH_SIZE define

This patch fixes a minor typo in comment for SBI_SCRATCH_SIZE define.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoscripts: Add C910 to platform list in the binary archive script
Liu Yibin [Sun, 19 Jan 2020 07:31:02 +0000 (15:31 +0800)]
scripts: Add C910 to platform list in the binary archive script

This patch adds T-HEAD C910 to RV64 platform list in the binary
archive script.

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: thead/c910: Don't set plic/clint address in warm boot
Liu Yibin [Mon, 13 Jan 2020 03:20:57 +0000 (11:20 +0800)]
platform: thead/c910: Don't set plic/clint address in warm boot

Since all harts share the same plic/clint address now, setting
them during cold boot is just fine.

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: thead/c910: Don't enable L2 cache in warm boot
Liu Yibin [Mon, 13 Jan 2020 03:20:56 +0000 (11:20 +0800)]
platform: thead/c910: Don't enable L2 cache in warm boot

Since all harts share the same L2 cache now, there's
no need to Enable L2 cache in warm boot.

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agofirmware: Fix placement of .align directives
Andreas Schwab [Thu, 9 Jan 2020 11:49:38 +0000 (12:49 +0100)]
firmware: Fix placement of .align directives

Move the .align directives after switching the section.  We want to align
the start of the current section, not the end of the previous section.
This also obsoletes the misguided workaround of disabling relaxation.

Signed-off-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodocs: platform: Update SiFive FU540 doc as-per U-Boot v2020.01
Anup Patel [Wed, 8 Jan 2020 04:06:09 +0000 (09:36 +0530)]
docs: platform: Update SiFive FU540 doc as-per U-Boot v2020.01

With U-Boot v2020.01, the SiFive FU540 DTB required by U-Boot is
embedded in U-Boot binary itself so we don't need to do anything
special for U-Boot v2020.01 as payload to OpenSBI firmware.

This patch updates SiFive FU540 documenation assuming we use
latest U-Boot v2020.01 release.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agoplatform: thead/c910: Remove SBI_PLATFORM_HAS_PMP
Liu Yibin [Wed, 8 Jan 2020 06:50:35 +0000 (14:50 +0800)]
platform: thead/c910: Remove SBI_PLATFORM_HAS_PMP

T-head c910 is a generic FPGA platform so we cannot
define PMP configuration for it in OpenSBI because
PMP configuration tend to be SOC specific.

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agodocs: Add description of using OPENSBI_EXTERNAL_SBI_TYPES
Abner Chang [Wed, 8 Jan 2020 04:54:34 +0000 (12:54 +0800)]
docs: Add description of using OPENSBI_EXTERNAL_SBI_TYPES

Add description of using OPENSBI_EXTERNAL_SBI_TYPES in external
firmware code base.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoinclude: Add OPENSBI_EXTERNAL_SBI_TYPES in sbi_types.h
Abner Chang [Tue, 7 Jan 2020 07:08:26 +0000 (15:08 +0800)]
include: Add OPENSBI_EXTERNAL_SBI_TYPES in sbi_types.h

Add OPENSBI_EXTERNAL_SBI_TYPES macro to allow external definitions of data
types and common macros. Also move some common definitions from sbi_bits.h to sbi_types.h.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agobuild: Use -ffreestanding
Khem Raj [Tue, 7 Jan 2020 02:41:06 +0000 (18:41 -0800)]
build: Use -ffreestanding

this is a stand-alone/baremetal application, therefore demanding
-ffreestanding would help it compile with hosted toolchains e.g. ( linux
toolchains ), it also ensures that it won't be using platform
optimizations like inlining mem* str* functions which gcc might decide
especially with wrapper string functions in opensbi code

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add sbi_init_count() API
Anup Patel [Fri, 3 Jan 2020 09:43:33 +0000 (15:13 +0530)]
lib: Add sbi_init_count() API

We add sbi_init_count() API which provides number of times a
given HART completed init sequence (warmboot/coldboot).

This will be very useful in debugging. With upcoming SBI HSM
extension, it will also help in implementing one-time init
code for each HART.

Signed-off-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: zero-out memory allocated using sbi_scratch_alloc_offset()
Anup Patel [Fri, 3 Jan 2020 09:25:04 +0000 (14:55 +0530)]
lib: zero-out memory allocated using sbi_scratch_alloc_offset()

We should zero-out memory allocated from extra scratch space using
sbi_scratch_alloc_offset() API hence this patch. This will not
impact performance because we mostly allocate from extra scratch
space only at cold boot time.

Signed-off-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: improve system reboot and shutdown implementation
Anup Patel [Fri, 3 Jan 2020 05:47:44 +0000 (11:17 +0530)]
lib: improve system reboot and shutdown implementation

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 <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: do sbi_exit() upon halt IPI
Anup Patel [Fri, 3 Jan 2020 05:44:21 +0000 (11:14 +0530)]
lib: do sbi_exit() upon halt IPI

Instead of doing sbi_hang() we should do sbi_exit() upon
halt IPI.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: save/restore MIE CSR in sbi_hart_wait_for_coldboot()
Anup Patel [Fri, 3 Jan 2020 04:50:12 +0000 (10:20 +0530)]
lib: save/restore MIE CSR in sbi_hart_wait_for_coldboot()

Currently, sbi_hart_wait_for_coldboot() leaves MIE.MSIP bit
set when it returns which is not correct because MIE.MSIP
should be left enabled only by sbi_ipi_init().

This patch does save/restore of MIE CSR to ensure that MIE
CSR is in original state after sbi_hart_wait_for_coldboot()
returns.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Add irqchip exit API
Anup Patel [Fri, 3 Jan 2020 04:21:58 +0000 (09:51 +0530)]
lib: Add irqchip exit API

We add an optional platform irqchip exit hook for exit path handling
in sbi_exit() implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Add ipi exit API
Anup Patel [Fri, 3 Jan 2020 04:09:10 +0000 (09:39 +0530)]
lib: Add ipi exit API

We add sbi_ipi_exit() API for exit path handling in sbi_exit()
implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Add timer exit API
Anup Patel [Fri, 3 Jan 2020 03:48:42 +0000 (09:18 +0530)]
lib: Add timer exit API

We add sbi_timer_exit() API for OpenSBI exit path handling in
sbi_exit() implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Add system early_exit and final_exit APIs
Anup Patel [Fri, 3 Jan 2020 03:40:41 +0000 (09:10 +0530)]
lib: Add system early_exit and final_exit APIs

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 <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Add initial sbi_exit() API
Anup Patel [Fri, 3 Jan 2020 03:19:23 +0000 (08:49 +0530)]
lib: Add initial sbi_exit() API

This patch adds initial implementation of sbi_exit() API which
can be used to perform OpenSBI exit sequence for current HART.

The sbi_exit() implementation will be further extended by
subsequent patches.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Remove unnecessary checks from init_coldboot() and init_warmboot()
Anup Patel [Fri, 3 Jan 2020 03:04:51 +0000 (08:34 +0530)]
lib: Remove unnecessary checks from init_coldboot() and init_warmboot()

We remove unnecessary checks related to hart hotplug and disabled
hart in coldboot and warmboot init path.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: Add T-head C910 initial support
Liu Yibin [Thu, 2 Jan 2020 04:21:36 +0000 (12:21 +0800)]
platform: Add T-head C910 initial support

This commit provides basic support for the Thead/C910 platform.

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: utils: Support CLINT with 32bit MMIO access on RV64 system
Anup Patel [Mon, 30 Dec 2019 06:01:59 +0000 (11:31 +0530)]
lib: utils: Support CLINT with 32bit MMIO access on RV64 system

It is possible to have a CLINT implementation which supports
only 32bit MMIO accesses on RV64 system so this patch extends
our CLINT driver such that platform code can specify whether
CLINT supports 64bit MMIO access.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra<atish.patra@wdc.com>
Reviewed-by: Zong Li <zong.li@sifive.com>
4 years agodocs: Improve docs for FDT address passing
Liu Yibin [Sun, 29 Dec 2019 07:47:51 +0000 (15:47 +0800)]
docs: Improve docs for FDT address passing

This patch updates FW_JUMP and FW_PAYLOAD documentation for the
case where FW_xyz_FDT_ADDR is not specified.

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agofirmware: Improve comments for fw_prev_arg1() and fw_next_arg1()
Anup Patel [Fri, 27 Dec 2019 03:24:24 +0000 (08:54 +0530)]
firmware: Improve comments for fw_prev_arg1() and fw_next_arg1()

The state of a0, a1, and a2 registers in fw_prev_arg1() and
fw_next_arg1() is same as passed by previous booting stage
so we add this info in comments for both these functions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agofirmware: Return real DTB address when FW_xyz_FDT_ADDR is not defined
Liu Yibin [Thu, 26 Dec 2019 09:38:55 +0000 (17:38 +0800)]
firmware: Return real DTB address when FW_xyz_FDT_ADDR is not defined

Function fw_next_arg1 in firmware/fw_jump.S:59 and
firmware/fw_payload.S:63 should return real dtb
address(if specified in a1) in a0, in case we don't
want to specify FW_xyz_FDT_ADDR when compiling.

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Implement RFENCE extension
Atish Patra [Mon, 25 Nov 2019 07:33:50 +0000 (23:33 -0800)]
lib: Implement RFENCE extension

This patch adds RFENCE extension support in OpenSBI.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Support stage1 and stage2 tlb flushing
Atish Patra [Mon, 25 Nov 2019 07:33:49 +0000 (23:33 -0800)]
lib: Support stage1 and stage2 tlb flushing

The hypervisor specification support hfence calls which can be used
issue tlb flush requests at both level of address translation. Currently,
these requests are issued only via SBI which are defined in v0.2.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add hfence instruction encoding
Atish Patra [Mon, 25 Nov 2019 07:33:48 +0000 (23:33 -0800)]
lib: Add hfence instruction encoding

Currently, the toolchains do not have support for hfence instruction.
Hence, the instruction are hardcode until we have toolchain support.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add IPI extension in SBI
Atish Patra [Mon, 25 Nov 2019 07:33:47 +0000 (23:33 -0800)]
lib: Add IPI extension in SBI

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 <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add TIME extension in SBI
Atish Patra [Mon, 25 Nov 2019 07:33:46 +0000 (23:33 -0800)]
lib: Add TIME extension in SBI

This patch adds support for TIME extension which replaces v0.1
timer extension.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Remove redundant IPI types
Atish Patra [Mon, 25 Nov 2019 07:33:45 +0000 (23:33 -0800)]
lib: Remove redundant IPI types

We just need to distinguish only between FENCE and non FENCE related
IPIs as all of the fence related requests are handled via fifo now.

Remove the unnecessary IPI types related to individual fence types.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add replacement extension and function ids
Atish Patra [Mon, 25 Nov 2019 07:33:44 +0000 (23:33 -0800)]
lib: Add replacement extension and function ids

Take this opportunity to move the enums to macros as enums make
sbi_ecall_interface.h unusable in assembly files.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Use MTINST CSR in misaligned load/store emulation
Anup Patel [Thu, 12 Dec 2019 17:21:42 +0000 (22:51 +0530)]
lib: Use MTINST CSR in misaligned load/store emulation

We should use MTINST CSR in misaligned load/store emulation whenever
possible to avoid unpriv read in getting trapped instruction. This will
improve preformance on HW having proper implementation of MTINST CSR.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agolib: Extend trap redirection for hypervisor v0.5 spec
Anup Patel [Thu, 12 Dec 2019 16:53:30 +0000 (22:23 +0530)]
lib: Extend trap redirection for hypervisor v0.5 spec

The hypervisor v0.5 spec introduces two new CSRs for both M-mode
and HS-mode which need to be considered when redirecting traps
hence this patch.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Fix sbi_get_insn() for load guest page fault
Anup Patel [Thu, 12 Dec 2019 02:01:38 +0000 (07:31 +0530)]
lib: Fix sbi_get_insn() for load guest page fault

We should treat load guest page fault in sbi_get_insn() as
fetch guest patch fault.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agoinclude: Extend struct sbi_trap_info for mtval2 and mtinst
Anup Patel [Thu, 12 Dec 2019 01:52:03 +0000 (07:22 +0530)]
include: Extend struct sbi_trap_info for mtval2 and mtinst

We have two new trap CSRs namely mtval2 and mtinst when
RISC-V hypervisor extension is available hence we extend
struct sbi_trap_info accordingly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agolib: Delegate guest page faults to HS-mode
Anup Patel [Thu, 12 Dec 2019 01:30:59 +0000 (07:00 +0530)]
lib: Delegate guest page faults to HS-mode

As-per RISC-V hypervisor v0.5 spec, we have new guest page faults
which need to be delegated to HS-mode.

Also, we can have bits in in MIDELEG and MEDELEG hardwired to 1
which means we need to fix the sainty check on these CSRs at the
end of delegate_traps() function.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>