platform/kernel/opensbi-spacemit.git
4 years agoMakefile: Allow padding zeros when converting DTB to C source
Heinrich Schuchardt [Wed, 14 Oct 2020 16:35:31 +0000 (22:05 +0530)]
Makefile: Allow padding zeros when converting DTB to C source

We extend d2c.sh to allow padding zeros in output C source when
converting DTB to C source. Using this feature, platforms can
create extra room for in-place FDT fixups on built-in DTBs.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: Remove FW_PAYLOAD_FDT_PATH compile-time option
Anup Patel [Wed, 14 Oct 2020 11:13:34 +0000 (16:43 +0530)]
firmware: Remove FW_PAYLOAD_FDT_PATH compile-time option

The FW_PAYLOAD_FDT_PATH compile-time option is replaced by
FW_FDT_PATH compile-time option which is more flexible and
common across all OpenSBI firmwares.

This patch removes FW_PAYLOAD_FDT_PATH and updates related
documentation to use FW_FDT_PATH.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: Add common FW_FDT_PATH compile-time option
Anup Patel [Wed, 14 Oct 2020 10:33:35 +0000 (16:03 +0530)]
firmware: Add common FW_FDT_PATH compile-time option

Currently, only FW_PAYLOAD has mechanism to embed external
FDT using FW_PAYLOAD_FDT_PATH compile-time option.

This patch adds a common FW_FDT_PATH compile-time option to
embed external FDT for all OpenSBI firmwares (i.e FW_JUMP,
FW_PAYLOAD, and FW_DYNAMIC).

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoMakefile: Build ELF, BIN and LD script in platform build directory
Anup Patel [Wed, 14 Oct 2020 08:14:18 +0000 (13:44 +0530)]
Makefile: Build ELF, BIN and LD script in platform build directory

Currently, the make rules for ELF, BIN and LD script are little
generic to allowing ELF, BIN and LD script to be anywhere in the
build directory. For OpenSBI firmwares, the ELF, BIN, and LD script
are always platform specific so we update make rules accordingly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agomakefile: fix clean directive
Damien Le Moal [Mon, 5 Oct 2020 14:55:53 +0000 (23:55 +0900)]
makefile: fix clean directive

Add cleaning of compiled device tree files (.dtb files).

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: sbi_scratch: typo scatch
Heinrich Schuchardt [Thu, 1 Oct 2020 10:27:47 +0000 (12:27 +0200)]
lib: sbi_scratch: typo scatch

%s/scatch/scratch

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: sbi: Fix PMP CSR detection
Pragnesh Patel [Wed, 23 Sep 2020 07:14:17 +0000 (12:44 +0530)]
lib: sbi: Fix PMP CSR detection

HiFive unleashed currently implements fewer than 56 bits of physical
address so existing PMP CSR detection is broken.

PMP address register encodes bits 55-2 of a 56-bit physical address,
Not all physical address bits may be implemented, So just check
minimum 1 bit.

Fixes: 74d1db706293 ("lib: sbi: Improve PMP CSR detection and
progamming")

Signed-off-by: Pragnesh Patel <pragnesh.patel@sifive.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: generic: Don't mark non-MMU HARTs as invalid
Anup Patel [Wed, 9 Sep 2020 08:24:03 +0000 (13:54 +0530)]
platform: generic: Don't mark non-MMU HARTs as invalid

Currently, the generic platform fw_platform_init() marks non-MMU
HARTs (e.g. E-core on SiFive Unleashed) as invalid. This means
such non-MMU HARTs won't be allowed to go ahead by sbi_init().

The sbi_init() now has a check for next stage privilege mode when
selecting coldboot HART. This check will force non-MMU HARTS (i.e.
HARTs without S-mode) to proceed in warmboot path and wait in the
HSM STOPPED state. This means we don't need to mark non-MMU HARTs
as invalid in generic platform fw_platform_init().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Ensure coldboot HART supports next privilege mode
Anup Patel [Wed, 9 Sep 2020 03:49:09 +0000 (09:19 +0530)]
lib: sbi: Ensure coldboot HART supports next privilege mode

The coldboot HART jumps to the next booting stage at the end of
init_coldboot() so it is absolutely necessary for coldboot HART
to support the privilege mode expected by the next booting stage.

We extend the coldboot HART selection in sbi_init() to ensure that
the selected coldboot HART always supports privilege mode specified
in scratch space (i.e. scratch->next_mode). This will further help
us allow E-core (without MMU) on SiFive Unleashed and PolarFire
ICICLE boards to proceed further and wait in HSM STOPPED state.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Improve fdt_cpu_fixup() implementation
Anup Patel [Mon, 7 Sep 2020 13:46:27 +0000 (19:16 +0530)]
lib: utils: Improve fdt_cpu_fixup() implementation

The fdt_cpu_fixup() should work fine even if HARTs without MMU
are not marked invalid by platform support code.

In future, we plan to treat HARTs without MMU as valid in the
generic platform support so that we can hold these HARTs in
HSM STOPPED state.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Allow specifying mode in sbi_hart_pmp_check_addr() API
Anup Patel [Mon, 7 Sep 2020 10:20:33 +0000 (15:50 +0530)]
lib: sbi: Allow specifying mode in sbi_hart_pmp_check_addr() API

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>
4 years agolib: sbi: Allow specifying start mode to sbi_hsm_hart_start() API
Anup Patel [Mon, 7 Sep 2020 05:41:29 +0000 (11:11 +0530)]
lib: sbi: Allow specifying start mode to sbi_hsm_hart_start() API

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>
4 years agolib: sbi_trap: Allow M-mode to M-mode ECALLs
Anup Patel [Fri, 4 Sep 2020 11:09:49 +0000 (16:39 +0530)]
lib: sbi_trap: Allow M-mode to M-mode ECALLs

We should allow M-mode to M-mode ECALLs because:
1. No other mode can handle M-mode ECALLs
2. In future, we can allow M-mode baremetal application (not
   linked to OpenSBI) running independently and cooperatively
   without corrupting OpenSBI M-mode state (CSRs and memory).

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Rename ECALL defines to match latest RISC-V spec
Anup Patel [Tue, 1 Sep 2020 12:24:29 +0000 (17:54 +0530)]
include: Rename ECALL defines to match latest RISC-V spec

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>
4 years agolib: sbi: Don't handle VS-mode ecall in sbi_trap_handler()
Anup Patel [Tue, 1 Sep 2020 12:20:14 +0000 (17:50 +0530)]
lib: sbi: Don't handle VS-mode ecall in sbi_trap_handler()

The VS-mode ecall is supposed to be handled by HS-mode so
sbi_trap_handler() should fallback to default case for
VS-mode ecall trap.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Improve HPM CSR read/write emulation
Anup Patel [Fri, 21 Aug 2020 12:54:14 +0000 (18:24 +0530)]
lib: sbi: Improve HPM CSR read/write emulation

We improve HPM CSR read/write emulation as follows:
1. Fail for unimplemented counters so that trap is redirected
   to S-mode which can further help debugging S-mode software.
2. Check permissions in both MCOUNTEREN and SCOUNTEREN for
   HS-mode and U-mode.
3. Don't check permissions for TIME CSR because we emulate
   TIME CSR for both Host (HS/U-mode) and Guest (VS/VU-mode).
   Also, faster TIME CSR read is very helpful for good
   performance of S-mode software.
4. Don't emulate S-mode CSR read/write to M-mode HPM CSRs
   because these should not be accessible to S-mode software.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi: Few cosmetic changes in riscv_encoding.h
Anup Patel [Fri, 21 Aug 2020 12:49:32 +0000 (18:19 +0530)]
include: sbi: Few cosmetic changes in riscv_encoding.h

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>
4 years agolib: sbi: Detect and print MHPM counters at boot-time
Anup Patel [Wed, 19 Aug 2020 12:01:37 +0000 (17:31 +0530)]
lib: sbi: Detect and print MHPM counters at boot-time

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>
4 years agolib: sbi: Improve PMP CSR detection and progamming
Anup Patel [Tue, 18 Aug 2020 07:58:08 +0000 (13:28 +0530)]
lib: sbi: Improve PMP CSR detection and progamming

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>
4 years agolib: sbi: Remove redundant SBI_HART_HAS_PMP feature
Anup Patel [Tue, 18 Aug 2020 06:21:16 +0000 (11:51 +0530)]
lib: sbi: Remove redundant SBI_HART_HAS_PMP feature

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>
4 years agolib: sbi: Handle the case where MTVAL has illegal instruction address
Anup Patel [Sat, 15 Aug 2020 16:47:58 +0000 (22:17 +0530)]
lib: sbi: Handle the case where MTVAL has illegal instruction address

The Kendryte K210 follows RISC-V v1.9 spec so MTVAL has instruction
address (instead of instruction encoding) on illegal instruction trap.

To handle above case, we fix sbi_illegal_insn_handler() without any
impact on RISC-V v1.10 (or higher) systems. This achieved by exploiting
the fact that program counter (and instruction address) is always 2-byte
aligned in RISC-V world.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_init: Avoid thundering hurd problem with coldboot_lock
Anup Patel [Sat, 15 Aug 2020 14:11:11 +0000 (19:41 +0530)]
lib: sbi_init: Avoid thundering hurd problem with coldboot_lock

We can have thundering hurd problem with coldboot_lock where the
boot HART can potentially starve trying to acquire coldboot_lock
because some of the non-boot HARTs are continuously acquiring and
releasing coldboot_lock. This can happen if MIP.MSIP bit is already
set for some of the non-boot HARTs.

To avoid thundering hurd problem for coldboot_lock, we use the
__smp_load_acquire() and __smp_store_release() for coldboot_done
flag and use coldboot_lock only for coldboot_wait_hmask.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
4 years agoplatform: kendryte/k210: fixup FDT
Heinrich Schuchardt [Tue, 18 Aug 2020 15:48:37 +0000 (17:48 +0200)]
platform: kendryte/k210: fixup FDT

When passing the device tree to the next stage we should apply necessary
device tree fix-ups first. These include:

* fix up the CPU node in the device tree
* fix up the PLIC node in the device tree
* fix up the reserved memory node in the device tree

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_trap: Fix hstatus.SPVP update in sbi_trap_redirect()
Georg Kotheimer [Fri, 14 Aug 2020 21:01:29 +0000 (23:01 +0200)]
lib: sbi_trap: Fix hstatus.SPVP update in sbi_trap_redirect()

When redirecting from VS/VU-mode to HS-mode, hstatus.SPVP was set
to the value of mstatus.SPP, as according to the specification both
flags should be set to the same value.
However, the assignment of SPVP takes place before SPP itself is
updated, which results in SPVP having an outdated value.

Signed-off-by: Georg Kotheimer <georg.kotheimer@tu-dresden.de>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agofirmware: fw_base: Improve exception stack setup in trap handler
Anup Patel [Mon, 10 Aug 2020 13:07:46 +0000 (18:37 +0530)]
firmware: fw_base: Improve exception stack setup in trap handler

Currently, the low-level trap handler (i.e. _trap_handler()) uses
branch instructions to conditionally setup exception stack based
on which mode trap occured.

This patch implements exception stack setup using xor instructions
which is faster with same number of instructions due to lack of
branch instructions.

The new exception stack setup approach can be best described by the
following pseudocode:

 Came_From_M_Mode = ((MSTATUS.MPP < PRV_M) ? 1 : 0) - 1;
 Exception_Stack = TP ^ (Came_From_M_Mode & (SP ^ TP))

 Came_From_M_Mode = 0    ==>    Exception_Stack = TP
 Came_From_M_Mode = -1   ==>    Exception_Stack = SP

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_misaligned_ldst: Determine transformed instruction length correctly
Anup Patel [Wed, 29 Jul 2020 11:40:16 +0000 (17:10 +0530)]
lib: sbi_misaligned_ldst: Determine transformed instruction length correctly

If MTINST[0:0] bit is 1 then we have transformed instruction encoding
in MTINST CSR. For transformed instructions, if the MTINST[1:1] bit
is Zero then original trapped instruction was a 16bit instruction
which was converted to 32bit instruction at time of taking trap.

We should use MTINST[1:1] bit to determine correct instruction length
of transformed instruction.

This patch updates misaligned load/store emulation as-per above.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Use strncmp in fdt_parse_hart_id()
Abner Chang [Sat, 25 Jul 2020 09:30:41 +0000 (17:30 +0800)]
lib: utils: Use strncmp in fdt_parse_hart_id()

Use strncmp instead of using sbi_strcmp directly in fdt_parse_hart_id()
to allow compiling fdt_helper.c by external firmware.

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>
4 years agolib: utils: Add a macro in libfdt_env.h for strncmp
Abner Chang [Sat, 25 Jul 2020 09:30:40 +0000 (17:30 +0800)]
lib: utils: Add a macro in libfdt_env.h for strncmp

This commit add a macro to replace strncmp with 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>
4 years agolib: Add sbi_strncmp implementation
Abner Chang [Sat, 25 Jul 2020 09:30:39 +0000 (17:30 +0800)]
lib: Add sbi_strncmp implementation

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>
4 years agoinclude: sbi_bitops: Remove dead shift assignment in ffs/fls
Tobias Klauser [Tue, 7 Jul 2020 09:56:55 +0000 (11:56 +0200)]
include: sbi_bitops: Remove dead shift assignment in ffs/fls

The value assigned to x by the shift assignment in the last if block of
ffs/fls is never read. Remove it.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib/utils: fdt: Update FDT expand size to 1024 for reserved memory node
Bin Meng [Thu, 25 Jun 2020 09:36:39 +0000 (02:36 -0700)]
lib/utils: fdt: Update FDT expand size to 1024 for reserved memory node

Currently 256 bytes is used for the FDT expand size when fixing up
reserved memory node. Increase it to 1024 bytes with an estimated
size of 64 bytes per PMP memory region by 16 regions in total.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoREADME.md: fix markdown link formatting
Tobias Klauser [Wed, 1 Jul 2020 13:07:08 +0000 (15:07 +0200)]
README.md: fix markdown link formatting

Consistently use reference-style markdown links in the README. This
won't show the URL next to the linked text for the [Github] and [U-Boot]
links and link the text "Bootlin toolchain repository" instead of
showing it verbatim with the URL next to it.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodocs/platform: sifive_fu540: Update U-Boot instructions
Bin Meng [Fri, 26 Jun 2020 01:26:04 +0000 (18:26 -0700)]
docs/platform: sifive_fu540: Update U-Boot instructions

U-Boot v2020.07 release adds SPL support to SiFive HiFive Unleashed.
Update the doc to mention that detailed build instructions are in the
U-Boot doc.

This also adds detailed command line description to show how to boot
U-Boot v2020.07 S-mode payload in the QEMU chapter.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoconfig.mk: Update QEMU run command for generic and sifive fu540 platforms
Bin Meng [Fri, 26 Jun 2020 01:26:03 +0000 (18:26 -0700)]
config.mk: Update QEMU run command for generic and sifive fu540 platforms

Since QEMU v5.1, if there is no "-bios" option provided, the default
OpenSBI firmware will be loaded by QEMU as the BIOS automatically,
hence to load fw_payload type image, we should explicitly pass the
"-bios" option to QEMU.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agodocs/platform: Update QEMU parameter for fw_payload
Bin Meng [Fri, 26 Jun 2020 01:26:02 +0000 (18:26 -0700)]
docs/platform: Update QEMU parameter for fw_payload

Since QEMU v5.1, if there is no "-bios" option provided, the default
OpenSBI firmware will be loaded by QEMU as the BIOS automatically,
hence to load fw_payload type image, we should explicitly pass the
"-bios" option to QEMU.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Bump-up version to 0.8
Anup Patel [Sat, 20 Jun 2020 06:27:24 +0000 (11:57 +0530)]
include: Bump-up version to 0.8

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

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Don't return any invalid error from SBI ecall
Anup Patel [Wed, 10 Jun 2020 13:09:53 +0000 (18:39 +0530)]
lib: Don't return any invalid error from SBI ecall

We should only return valid error codes from SBI ecalls as
defined by the RISC-V SBI spec.

To achieve this:
1. We use SBI_Exxxx defines for OpenSBI internal errors with
   error values starting from -1000
2. We use SBI_ERR_xxxx defines for errors defined by SBI spec
3. We map some of the SBI_Exxxx defines to SBI_ERR_xxxx defines
   which are semantically same
4. We throw a error print and force return error code to
   SBI_ERR_FAILED in sbi_ecall_handler() if we see an invalid
   error code being returned to S-mode

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Fix 32/64 bits variable compatibility
Liush [Fri, 19 Jun 2020 03:55:19 +0000 (11:55 +0800)]
lib: sbi: Fix 32/64 bits variable compatibility

On RV64,"unsigned long" is 64bit and "unsigned int" is 32bit. So in
function "pmp_get" and "pmp_set", if "pmpcfg_shift >= 32", "0xff << pmpcfg_shift"
will go beyond "unsigned int" width. This patch tries to fix this issue.

In function 'pmp_get':
cfgmask = (0xff << pmpcfg_shift);
-->
cfgmask = (0xffUL << pmpcfg_shift);
In function 'pmp_set':
cfgmask = ~(0xff << pmpcfg_shift);
-->
cfgmask = ~(0xffUL << pmpcfg_shift);

Signed-off-by: Liush <liush.damon@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Add support for Shakti C-class SoC from IIT-M
Vijai Kumar K [Wed, 17 Jun 2020 13:55:16 +0000 (19:25 +0530)]
platform: Add support for Shakti C-class SoC from IIT-M

C-Class is a member of the SHAKTI family of processors from Indian
Institute of Technology - Madras(IIT-M).
It is an extremely configurable and commercial-grade 5-stage in-order
core supporting the standard RV64GCSUN ISA extensions.

https://gitlab.com/shaktiproject/cores/c-class/blob/master/README.md

We add OpenSBI support for Shakti C-class SoC.

Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Fix the SBI_HART_HAS_MCOUNTEREN feature check
Alistair Francis [Wed, 17 Jun 2020 00:07:33 +0000 (17:07 -0700)]
lib: Fix the SBI_HART_HAS_MCOUNTEREN feature check

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Don't print delegation CSRs if there is no S-Mode
Alistair Francis [Wed, 17 Jun 2020 00:06:15 +0000 (17:06 -0700)]
lib: Don't print delegation CSRs if there is no S-Mode

If the platform doesn't support S-Mode don't print the delegation
registers.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Update Nuclei ux600 platform support
Huaqi Fang [Fri, 12 Jun 2020 09:01:49 +0000 (17:01 +0800)]
platform: Update Nuclei ux600 platform support

Changes are made to support our FPGA evaluation board,
it has DDR memory(0xA0000000-0xB0000000).

* Adapt the config.mk to match FPGA evaluation board DDR memory address
* Since the RISC-V CPU core frequency of FPGA might change, so we use the
  fixed TIMER frequency to measure the real CPU core frequency.
* And the UART baudrate has to set to 57600bps for Nuclei FPGA evaluation
  board when CPU core frequency is about 8MHz, otherwise the UART input
  will not work correctly.

Signed-off-by: Huaqi Fang <578567190@qq.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform/lib: Allow the OS to map the regions that are protected by PMP
Alexandre Ghiti [Sat, 13 Jun 2020 06:59:13 +0000 (02:59 -0400)]
platform/lib: Allow the OS to map the regions that are protected by PMP

This is achieved by removing the 'no-map' property from the
'reserved-memory' node when PMP is present, otherwise we keep it as it
offers a small protection if the OS does not map this region at all.
A new callback in platform_override is introduced and allows to fixup the
device-tree. It is used here to override this new default behaviour on
SiFive Fu540 platforms that has an erratum that prevents S-mode software
to access a PMP protected region using 1GB page table mapping.

If PMP is present, telling the OS not to map the reserved regions does not
add much protection since it only avoids access to regions that are already
protected by PMP. But by not allowing the OS to map those regions, it
creates holes in the OS system memory map and prevents the use of
hugepages which would generate, among other benefits, less TLB miss.

Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Fix __sbi_hfence_gvma_vmid_gpa() and __sbi_hfence_vvma_asid_va()
Anup Patel [Sat, 6 Jun 2020 12:03:48 +0000 (17:33 +0530)]
lib: Fix __sbi_hfence_gvma_vmid_gpa() and __sbi_hfence_vvma_asid_va()

The arguments/parameters of __sbi_hfence_gvma_vmid_gpa() and
__sbi_hfence_vvma_asid_va() functions are swapped so we fix it.

Currently, we did not face any issues because QEMU does a full
TLB flush for all HFENCE instructions.

We also improve documentation of HFENCE.GVMA and HFENCE.VVMA
instruction encoding.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: Add AE350 cache control SBIs
Nylon Chen [Tue, 9 Jun 2020 05:56:58 +0000 (13:56 +0800)]
platform: Add AE350 cache control SBIs

This patch contains the following AE350 specific SBIs:

- get mcache_ctl status
- get mmisc_ctl status
- set mcache_ctl status
- set mmisc_ctl status
- I-cache operation
- D-cache operation
- enable/disable L1-I-cache prefetch
- enable/disable L1-D-cache prefetch
- enable/disable non-blocking load store
- enable/disable write-around

Signed-off-by: Nylon Chen <nylon7@andestech.com>
Reviewed-by: Anup Patel <Anup.Patel@wdc.com>
Reviewed-by: Atish Patra <Atish.Patra@wdc.com>
4 years agoplatform: Add AE350 platform specific SBI handler
Nylon Chen [Tue, 9 Jun 2020 05:56:57 +0000 (13:56 +0800)]
platform: Add AE350 platform specific SBI handler

We add AE350 platform specific SBI handler to implement
AE350 specific SBI calls.

Signed-off-by: Nylon Chen <nylon7@andestech.com>
Reviewed-by: Anup Patel <Anup.Patel@wdc.com>
Reviewed-by: Atish Patra <Atish.Patra@wdc.com>
4 years agodocs: Remove redundant documentation about combined payload use case
Atish Patra [Fri, 5 Jun 2020 06:31:49 +0000 (23:31 -0700)]
docs: Remove redundant documentation about combined payload use case

U-Boot now supports loading Linux kernel image via network and storage
media. Thus, we don't need to use a combined payload containing both
U-Boot & Linux kernel image to boot Linux from U-Boot prompt.

Remove the old documentation.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodocs: Use doxygen config to mark the main page
Atish Patra [Fri, 5 Jun 2020 06:31:48 +0000 (23:31 -0700)]
docs: Use doxygen config to mark the main page

The doxygen config option "USE_MDFILE_AS_MAINPAGE" can be used to set
the main page in doxygen generated pdf. This allows us to remove the
"#mainpage" from the README file which markdown doesn't parse.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add RISC-V hypervisor v0.6.1 support
Anup Patel [Thu, 28 May 2020 03:07:42 +0000 (08:37 +0530)]
lib: Add RISC-V hypervisor v0.6.1 support

To support RISC-V hypervisor v0.6.1, we:
1. Don't need to explicitly forward WFI traps from VS/VU-mode
2. Have to delegate virtual instruction trap to HS-mode
3. Have to update trap redirection for changes in HSTATUS CSR

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: Remove FW_PAYLOAD_FDT and related documentation
Anup Patel [Mon, 25 May 2020 09:43:31 +0000 (15:13 +0530)]
firmware: Remove FW_PAYLOAD_FDT and related documentation

Now that no platform is using FW_PAYLOAD_FDT mechanism, we
remove related code from Makefile and related documentation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: kendryte/k210: Use new mechanism of builtin DTB
Anup Patel [Tue, 2 Jun 2020 05:07:15 +0000 (10:37 +0530)]
platform: kendryte/k210: Use new mechanism of builtin DTB

We update kendryte/k210 to use new mechanism of having builtin DTB
where we convert k210.dts to C source and further compile-n-link it
with libplatsbi.a.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoMakefile: Add mechanism for platforms to have multiple builtin DTBs
Anup Patel [Mon, 25 May 2020 09:12:35 +0000 (14:42 +0530)]
Makefile: Add mechanism for platforms to have multiple builtin DTBs

Currently, we can only include one DTB as builtin for a platform
using FDT_PAYLOAD_DTB make variable in platform config.mk.

This patch adds new mechanism using which we can convert any DTS
file to C source and futher compile-n-link it with libplatsbi.a.

The generated C source will have the DTB contents as an array
"const char <varprefix>_start[]" where <varprefix> is specified
in platform objects.mk makefile.

Example1
--------
If we have built-in k210.dts and desired <varprefix> is
"dt_k210" then specify following in platform objects.mk:
platform-objs-y += k210.o
platform-varprefix-k210.o = dt_k210

Example2
--------
If we have built-in abc/k210.dts and desired <varprefix> is
"dt_abc_k210" then specify following in platform objects.mk:
platform-objs-y += abc/k210.o
platform-varprefix-abc-k210.o = dt_abc_k210

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoMakefile: Preprocess builtin DTS
Anup Patel [Sun, 24 May 2020 07:41:00 +0000 (13:11 +0530)]
Makefile: Preprocess builtin DTS

In order to use GCC style defines and macros in DTS, we should
preporcess builtin DTS before converting it to DTB.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: Allow fw_platform_init() to return updated FDT location
Anup Patel [Sun, 24 May 2020 04:33:13 +0000 (10:03 +0530)]
firmware: Allow fw_platform_init() to return updated FDT location

Currently, the fw_platform_init() does not return anything but we can
further improve by allowing fw_platform_init() to return updated FDT
location.

It is certainly not mandatory for fw_platform_init() to return a new
location of FDT (or modify FDT). In fact, the fw_platform_init() can
always return the original FDT location (i.e. 'arg1') unmodified.

This new capability of fw_platform_init() will allow platforms to:
1. Have multiple built-in FDTs and select one
2. Modify FDT before using based on platform specific straps or OTP

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: fw_base: Don't OR forced FW_OPTIONS
Anup Patel [Sat, 23 May 2020 06:39:57 +0000 (12:09 +0530)]
firmware: fw_base: Don't OR forced FW_OPTIONS

Currently, we are ORing FW_OPTIONS with the options passed by
previous booting stage to fw_dynamic. This causes confusion
because compiling fw_dynamic with FW_OPTIONS=0x2 does not force
enable boot prints as the U-Boot SPL passes options=0x1 in
fw_dyanmic_info.

The best thing to do is always prefer FW_OPTIONS when available.
This is intuitive for OpenSBI users and easy in debugging.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: fw_base: Make builtin DTB available to fw_platform_init()
Anup Patel [Sat, 23 May 2020 06:07:15 +0000 (11:37 +0530)]
firmware: fw_base: Make builtin DTB available to fw_platform_init()

Currently, fw_prev_arg1() is called after fw_platform_init() which
caused builtin DTB to be not available to fw_platform_init().

To allow builtin DTB available to fw_platform_init(), we should
call fw_save_info() and fw_prev_arg1() before fw_platform_init().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoMakefile: Fix builtin DTB compilation for out-of-tree platforms
Anup Patel [Sat, 23 May 2020 06:01:18 +0000 (11:31 +0530)]
Makefile: Fix builtin DTB compilation for out-of-tree platforms

The make rule for builtin DTB compilation does not consider
out-of-tree platforms so this patch fixes it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils/timer: Initialize all matching timer DT nodes
Anup Patel [Wed, 13 May 2020 07:41:44 +0000 (13:11 +0530)]
lib: utils/timer: Initialize all matching timer DT nodes

We can have multiple matching DT nodes of the same FDT timer driver
so in this case we should call cold_init() for all matching DT nodes
instead of just first matching DT node.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils/ipi: Initialize all matching ipi DT nodes
Anup Patel [Wed, 13 May 2020 07:44:33 +0000 (13:14 +0530)]
lib: utils/ipi: Initialize all matching ipi DT nodes

We can have multiple matching DT nodes of the same FDT ipi driver
so in this case we should call cold_init() for all matching DT nodes
instead of just first matching DT node.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add fdt_parse_clint_node() function
Anup Patel [Wed, 13 May 2020 04:25:28 +0000 (09:55 +0530)]
lib: utils: Add fdt_parse_clint_node() function

We add fdt_parse_clint_node() function which will be used by
fdt_ipi_clint and fdt_timer_clint drivers to parse CLINT details
from DT node.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Allow CLINT functions to be used for multiple CLINTs
Anup Patel [Tue, 12 May 2020 13:08:31 +0000 (18:38 +0530)]
lib: utils: Allow CLINT functions to be used for multiple CLINTs

We extend CLINT cold init function to have a "struct clint_data *"
parameter pointing to CLINT details. This allows platforms to use
CLINT functions for multiple CLINT instances.

When multiple CLINTs are present, the platform can also provide
one of the CLINT as reference CLINT for other CLINTs. This will
help CLINTs to sync their time value with reference CLINT using
a time_delta computed in warm init function.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils/irqchip: Initialize all matching irqchip DT nodes
Anup Patel [Tue, 12 May 2020 09:29:59 +0000 (14:59 +0530)]
lib: utils/irqchip: Initialize all matching irqchip DT nodes

We can have multiple matching DT nodes of the same FDT irqchip
driver so in this case we should call cold_init() for all matching
DT nodes instead of just first matching DT node.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Extend fdt_find_match() Implementation
Anup Patel [Tue, 12 May 2020 08:29:52 +0000 (13:59 +0530)]
lib: utils: Extend fdt_find_match() Implementation

We extend fdt_find_match() implementation by adding node offset
parameter which represents the first node to match from.

The improved fdt_find_match() can be used to find multiple
match nodes.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Allow PLIC functions to be used for multiple PLICs
Anup Patel [Tue, 12 May 2020 07:27:52 +0000 (12:57 +0530)]
lib: utils: Allow PLIC functions to be used for multiple PLICs

We extend all PLIC functions to have a "struct plic_data *"
parameter pointing to PLIC details. This allows platforms to
use these functions for multiple PLIC instances.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Remove redundant parameters from PLIC init functions
Anup Patel [Tue, 12 May 2020 04:44:43 +0000 (10:14 +0530)]
lib: utils: Remove redundant parameters from PLIC init functions

The "target_hart" and "hart_count" parameters of PLIC cold and
warm init functions are only used for sanity checks and not
required in PLIC initialization.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi: Add firmware extension constants
Daniel Schaefer [Fri, 15 May 2020 09:34:55 +0000 (11:34 +0200)]
include: sbi: Add firmware extension constants

Cc: Abner Chang <abner.chang@hpe.com>
Signed-off-by: Daniel Schaefer <git@danielschaefer.me>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: sbi_hart: Detect number of supported PMP regions
Anup Patel [Mon, 18 May 2020 06:34:18 +0000 (12:04 +0530)]
lib: sbi_hart: Detect number of supported PMP regions

It is not mandatory for a RISC-V systems to implement all PMP
regions so we have to check all PMPADDRx CSRs to determine excat
number of supported PMP regions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: sbi: Few cosmetic improvements to HART feature detection
Anup Patel [Mon, 11 May 2020 06:12:54 +0000 (11:42 +0530)]
lib: sbi: Few cosmetic improvements to HART feature detection

This patch does few cosmetic improvements to HART feature detection:
1. Remove sbi_ perfix from HART feature detection functions
   because all local/static functions in sbi_hart.c don't have
   sbi_ prefix
2. Remove sbi_hart_set_feature() because it's quite small and
   local/static in sbi_hart.c

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi: Use scratch pointer as parmeter in HART feature APIs
Anup Patel [Mon, 11 May 2020 06:00:15 +0000 (11:30 +0530)]
include: sbi: Use scratch pointer as parmeter in HART feature APIs

It makes more sense to have scratch pointer as parameter in
HART feature APIs because:
1. We already have scratch pointer at places where these APIs
   are used.
2. This is consistent with lot of other APIs in sbi_hart.h

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Print platform HART count just before boot HART id
Anup Patel [Sun, 10 May 2020 06:19:59 +0000 (11:49 +0530)]
lib: sbi: Print platform HART count just before boot HART id

On platforms with continuous HART ids starting from zero:
0 <= boot HART id < platform HART count

The above co-relation of boot HART id and platform HART count
is true for most RISC-V platfors so it's better to print platform
HART count just before boot HART id.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Remove extra spaces from boot time prints
Anup Patel [Sun, 10 May 2020 06:16:55 +0000 (11:46 +0530)]
lib: sbi: Remove extra spaces from boot time prints

We remove extra spaces from boot time prints.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Improve get_feature_str() implementation and usage
Anup Patel [Sun, 10 May 2020 06:06:14 +0000 (11:36 +0530)]
lib: sbi: Improve get_feature_str() implementation and usage

We do following improvements for get_feature_str():
1. We should return "none" from get_feature_str() no features
   available instead of sbi_boot_prints() explicitly handling
   failure.
2. We don't need to return failure (just like misa_xlen())
   because we are returning "none" for no features and we are
   truncating output when space is not available.
3. Based on 1 and 2, the sbi_boot_prints() can be further
   simplified.
4. No need for two char[] in sbi_boot_prints()

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: detect features before everything else in sbi_hart_init()
Anup Patel [Sun, 10 May 2020 05:43:00 +0000 (11:13 +0530)]
lib: sbi: detect features before everything else in sbi_hart_init()

We should detect HART features in sbi_hart_init() before
mstatus_init(), delegate_traps() and pmp_init().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: Correct spelling mistakes
Daniel Schaefer [Fri, 15 May 2020 09:38:12 +0000 (11:38 +0200)]
firmware: Correct spelling mistakes

Signed-off-by: Daniel Schaefer <git@danielschaefer.me>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Optimize inline assembly for unprivilege access functions
Atish Patra [Fri, 15 May 2020 22:30:33 +0000 (15:30 -0700)]
lib: Optimize inline assembly for unprivilege access functions

Currently, unprivileged access functions uses few additional instructions
which are redundant. It also uses specific registers which are not necessary.

Remove those additional instructions and let the compiler choose the
registers.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add hart features in boot time print
Atish Patra [Sat, 9 May 2020 23:47:32 +0000 (16:47 -0700)]
lib: Add hart features in boot time print

We have now clear distinction between platform and hart features.
Modify the boot print messages to print hart specific features in
a string format.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add platform features in boot time print
Atish Patra [Sat, 9 May 2020 23:47:31 +0000 (16:47 -0700)]
lib: Add platform features in boot time print

We have now clear distinction between platform and hart features.
Modify the boot print messages to print platform features in a string
format. In the process, this patch moved relatively larger functions
to its own file from platform.h header file.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: timer: Provide a hart based timer feature
Atish Patra [Sat, 9 May 2020 23:47:30 +0000 (16:47 -0700)]
lib: timer: Provide a hart based timer feature

As per the RISC-V specification, time value can be obtained from a time
CSR implemented in hardware or a MMIO based IP block. Qemu virt machine
already supports timer csr while CLINT provides the timer for other
platforms.

Implement a hart specific timer feature that can be detected at runtime.
As CSR based timer implementation are faster than MMIO address based, it
is always preferred over MMIO based one.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: fpga: Remove redundant platform specific features
Atish Patra [Sat, 9 May 2020 23:47:29 +0000 (16:47 -0700)]
platform: fpga: Remove redundant platform specific features

Any platform feature that belongs to a hart, have already been moved to
hart features and are detected at run time. The remaining platform features
are identical to platform default features.

Use the platform default features instead of defining a separate copy of it.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Move platform features to hart
Atish Patra [Sat, 9 May 2020 23:47:28 +0000 (16:47 -0700)]
platform: Move platform features to hart

PMP & performance counters belong to a hart rather than a platform.
In addition to that, these features enable reading/writing from a
particular csr. Thus, they can be detected and set at runtime rather
than compile time.

Move PMP/MCOUNTEREN/SCOUNTEREN features to hart and detect them at runtime.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add support for hart specific features
Atish Patra [Sat, 9 May 2020 23:47:27 +0000 (16:47 -0700)]
lib: Add support for hart specific features

There may be some features which are hart specific rather than a platform
specific feature. Add a framework to support that.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: utils: Update reserved memory fdt node even if PMP is not present
Atish Patra [Sat, 9 May 2020 23:47:26 +0000 (16:47 -0700)]
lib: utils: Update reserved memory fdt node even if PMP is not present

As per RISC-V ISA, pmp is not mandatory. Currently, we only add reserved
memory node in DT only if PMP is present. That allows supervisor to access
the memory where OpenSBI continue to exist without realizing it for non-pmp
based platforms. It may result in corrupting OpenSBI. That's why OpenSBI
should at least let the supervisor know where it continue to exist.
This a best effort service provided by OpenSBI expecting that supervisor
software is not buggy and properly sets up its memory after parsing the
reserved-memory device tree node.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Create a separate math helper function file
Atish Patra [Sat, 9 May 2020 23:47:25 +0000 (16:47 -0700)]
lib: Create a separate math helper function file

There may be few common mathematics helper functions which can be used
anywhere in OpenSBI project.

Add a separate math helper function file to add these functions.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Add csr detect support
Atish Patra [Sat, 9 May 2020 23:47:24 +0000 (16:47 -0700)]
lib: Add csr detect support

As RISC-V ISA allows many CSRs such as pmp, s/mcounteren to be optional
in hardware, OpenSBI should provide an option to dynamically detect
these csr access capability at run time.

Implement a csr read/write access check helper macros.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Rename unprivileged trap handler
Atish Patra [Sat, 9 May 2020 23:47:23 +0000 (16:47 -0700)]
lib: Rename unprivileged trap handler

Unprivileged trap handler can be reused for any cases where the executing
code expects a trap.

Rename it to "expected" trap handler as it will be used in other cases in
future.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodocs: Don't use italic text in page title
Anup Patel [Wed, 6 May 2020 06:57:38 +0000 (12:27 +0530)]
docs: Don't use italic text in page title

Doxygen does not support italic text in page title so fix
some of the markdown files accordingly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agodocs: Fix ordering of pages in table of contents
Anup Patel [Wed, 6 May 2020 06:46:48 +0000 (12:16 +0530)]
docs: Fix ordering of pages in table of contents

Currently, all markdown pages are randomly arranged in table of
contents so to fix this we treat top-level README.md as mainpage
and enable Doxygen TREEVIEW.

Also, there should not be any text before title of a markdown
page so we move project copyright as separate section in top-level
README.md.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agodocs: Add platform requirements document
Anup Patel [Tue, 5 May 2020 04:16:46 +0000 (09:46 +0530)]
docs: Add platform requirements document

We add platform requirements document to clarify OpenSBI
expectations from a RISC-V platform.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
4 years agodocs: platform/generic: Add details about IPI and timer expectations
Anup Patel [Wed, 6 May 2020 04:42:11 +0000 (10:12 +0530)]
docs: platform/generic: Add details about IPI and timer expectations

The generic platform provides IPI and timer functionality based on
DT node provided in the FDT passed by previous booting stage. This
patch updates generic platform documentation about IPI and timer
expectations.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agodocs: platform/generic: Add details about stdout-path DT property
Anup Patel [Tue, 5 May 2020 04:23:40 +0000 (09:53 +0530)]
docs: platform/generic: Add details about stdout-path DT property

The generic platform will try to select serial console based on the
stdout-path DT property in /chosen DT node hence we document this.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Improve misa_string() implementation
Anup Patel [Tue, 5 May 2020 06:16:25 +0000 (11:46 +0530)]
lib: sbi: Improve misa_string() implementation

The RISC-V ISA string does not follow alphabetical order. Instead,
we have a RISC-V specific ordering of extensions in the RISC-V ISA
string. This patch improves misa_string() implementation to return
a valid RISC-V ISA string.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_tlb: Fix remote TLB HFENCE VVMA implementation
Anup Patel [Mon, 4 May 2020 05:28:07 +0000 (10:58 +0530)]
lib: sbi_tlb: Fix remote TLB HFENCE VVMA implementation

The HFENCE VVMA instructions flushes TLB based on the VMID
present in HGATP CSR. To handle this, we get the current
VMID for SBI HFENCE VVMA call and we use this current VMID
to do remote TLB HFENCE VVMA on desired set of HARTs.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi: Remove redundant page table related defines
Anup Patel [Wed, 6 May 2020 08:05:00 +0000 (13:35 +0530)]
include: sbi: Remove redundant page table related defines

We don't have page table programming in OpenSBI so let's remove
redundant page table related defines from riscv_encoding.h.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agodocs: Add missing links in platform.md
Anup Patel [Fri, 1 May 2020 09:50:47 +0000 (15:20 +0530)]
docs: Add missing links in platform.md

The links to some of the platforms were missing in platform.md
file hence this patch.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agoplatform: Remove spike directory
Anup Patel [Fri, 1 May 2020 06:45:50 +0000 (12:15 +0530)]
platform: Remove spike directory

The OpenSBI generic platform works perfectly fine on the QEMU spike
machine and Spike emulator so let's remove dedicated Spike platform
from OpenSBI.

All Spike platform related documentation in OpenSBI will now suggest
using OpenSBI generic platform.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agoplatform: Remove qemu/virt directory
Anup Patel [Fri, 1 May 2020 06:36:56 +0000 (12:06 +0530)]
platform: Remove qemu/virt directory

The OpenSBI generic platform works perfectly fine on the QEMU virt
machine so let's remove dedicated QEMU virt machine platform from
OpenSBI.

All QEMU virt machine related documentation in OpenSBI will now
suggest using OpenSBI generic platform.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bin.meng@windriver.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agoplatform: generic: Add Sifive FU540 TLB flush range limit override
Anup Patel [Tue, 28 Apr 2020 04:05:32 +0000 (09:35 +0530)]
platform: generic: Add Sifive FU540 TLB flush range limit override

We need to override the remote TLB flush range limit for SiFive FU540
so we add platform override to achieve this.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoscripts: Add generic platform to create-binary-archive.sh
Anup Patel [Mon, 27 Apr 2020 13:02:19 +0000 (18:32 +0530)]
scripts: Add generic platform to create-binary-archive.sh

This patch adds generic platform to create-binary-archive.sh
script.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Print platform hart count at boot time
Anup Patel [Sun, 26 Apr 2020 10:22:26 +0000 (15:52 +0530)]
lib: sbi: Print platform hart count at boot time

Now that we have generic platform which detects hart count from
DTB, we should print platform hart count at boot time.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: Add generic FDT based platform support
Anup Patel [Tue, 28 Apr 2020 03:53:30 +0000 (09:23 +0530)]
platform: Add generic FDT based platform support

We add generic FDT based platform support which provides platform
specific functionality based on the FDT passed by previous booting
stage.

By default, the generic FDT platform makes following assumptions:
1. platform FW_TEXT_START is 0x80000000
2. platform features are default
3. platform stack size is default
4. platform has no quirks or work-arounds

The above assumptions (except 1) can be overridden by adding special
platform callbacks which will be called based on the FDT root node
compatible string.

By default, we compile OpenSBI generic platform as follows:
$ make PLATFORM=generic

For a non-standard FW_TEXT_START, we can compile OpenSBI generic
platform as follows:
$ make PLATFORM=generic FW_TEXT_START=<non_standard_text_start>

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>