platform/kernel/opensbi.git
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>
4 years agofirmware: fw_base: Introduce optional fw_platform_init()
Anup Patel [Sun, 26 Apr 2020 09:01:28 +0000 (14:31 +0530)]
firmware: fw_base: Introduce optional fw_platform_init()

We add optional fw_platform_init() function which will allow
platform specific code to update "struct sbi_platform platform"
before it is used.

The fw_platform_init() can be a regular C function so before
callint it we:
1. zero-out BSS section
2. Setup temporary trap handler to catch bugs
3. Setup temporary stack pointer

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add simple FDT reset framework
Anup Patel [Fri, 24 Apr 2020 11:32:48 +0000 (17:02 +0530)]
lib: utils: Add simple FDT reset framework

We add simple reset framework which will select and use reset driver
based on details in FDT passed by previous booting stage.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add simple FDT serial framework
Anup Patel [Fri, 24 Apr 2020 11:30:37 +0000 (17:00 +0530)]
lib: utils: Add simple FDT serial framework

We add simple serial framework which will select and use serial driver
based on details in FDT passed by previous booting stage.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add simple FDT irqchip framework
Anup Patel [Fri, 24 Apr 2020 11:26:33 +0000 (16:56 +0530)]
lib: utils: Add simple FDT irqchip framework

We add simple irqchip framework which will select and use irqchip driver
based on details in FDT passed by previous booting stage.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add simple FDT ipi framework
Anup Patel [Fri, 24 Apr 2020 11:23:32 +0000 (16:53 +0530)]
lib: utils: Add simple FDT ipi framework

We add simple ipi framework which will select and use ipi driver
based on details in FDT passed by previous booting stage.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add simple FDT timer framework
Anup Patel [Fri, 24 Apr 2020 11:20:40 +0000 (16:50 +0530)]
lib: utils: Add simple FDT timer framework

We add simple timer framework which will select and use timer driver
based on details in FDT passed by previous booting stage.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Add array_size() macro
Anup Patel [Fri, 24 Apr 2020 13:07:10 +0000 (18:37 +0530)]
include: Add array_size() macro

Getting array size of a dynmaic array can be very handy hence
this patch.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agolib: utils: Add fdt_parse_plic_node() function
Anup Patel [Wed, 29 Apr 2020 08:51:52 +0000 (14:21 +0530)]
lib: utils: Add fdt_parse_plic_node() function

We add fdt_parse_plic_node() function which will allow us to parse
a particular DT node as PLIC node. This will be useful in parsing
the DT node which we have found by matching compatible string.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add fdt_parse_max_hart_id() API
Anup Patel [Fri, 24 Apr 2020 09:38:19 +0000 (15:08 +0530)]
lib: utils: Add fdt_parse_max_hart_id() API

We add fdt_parse_max_hart_id() API which return max HART id based
on CPU DT nodes. This will be used by generic FDT based drivers in
subsequent patches.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agolib: utils: Add fdt_parse_hart_id() function
Anup Patel [Sun, 26 Apr 2020 07:09:13 +0000 (12:39 +0530)]
lib: utils: Add fdt_parse_hart_id() function

Parsing HART id from a CPU DT node is a common requirement for
RISC-V systems. The newly added fdt_parse_hart_id() also helps
reduce duplicate code between fdt_cpu_fixup() function and
fdt_parse_hart_count() function.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agolib: utils: Add fdt_parse_sifive_uart_node() function
Anup Patel [Sat, 25 Apr 2020 13:20:37 +0000 (18:50 +0530)]
lib: utils: Add fdt_parse_sifive_uart_node() function

We add fdt_parse_sifive_uart_node() function which will allow
us to parse a particular DT node as SiFive UART node. This will
be useful in parsing the node pointed by stdout-path.

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: utils: Make fdt_get_node_addr_size() public function
Anup Patel [Fri, 24 Apr 2020 13:05:25 +0000 (18:35 +0530)]
lib: utils: Make fdt_get_node_addr_size() public function

The fdt_get_node_addr_size() will be useful in FDT based simple
driver frameworks so we make it a public function.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agolib: utils: Add FDT match table based node lookup
Anup Patel [Fri, 24 Apr 2020 13:02:10 +0000 (18:32 +0530)]
lib: utils: Add FDT match table based node lookup

This patch adds FDT match table based node lookup funcitons.

These functions will be useful in implementing simple FDT
based driver frameworks.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Rename fdt_parse_clint() to fdt_parse_compat_addr()
Anup Patel [Fri, 24 Apr 2020 11:11:06 +0000 (16:41 +0530)]
lib: utils: Rename fdt_parse_clint() to fdt_parse_compat_addr()

The fdt_parse_clint() is quite generic and can be used for other
types of devices so we rename it to fdt_parse_compat_addr().

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: utils: Remove redundant clint_ipi_sync() declaration
Anup Patel [Fri, 24 Apr 2020 10:52:45 +0000 (16:22 +0530)]
lib: utils: Remove redundant clint_ipi_sync() declaration

The clint_ipi_sync() was removed long time back hence we remove
redundant declaration from clint.h

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: utils: Add fdt_parse_uart8250_node() function
Anup Patel [Sat, 25 Apr 2020 13:03:54 +0000 (18:33 +0530)]
lib: utils: Add fdt_parse_uart8250_node() function

We add fdt_parse_uart8250_node() function which will allow us
to parse a particular DT node as UART 8250 node. This will be
useful in parsing the node pointed by stdout-path.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Improve fdt_parse_uart8250() API
Anup Patel [Fri, 24 Apr 2020 09:51:34 +0000 (15:21 +0530)]
lib: utils: Improve fdt_parse_uart8250() API

The information parsed by fdt_parse_uart8250() API is not complete.
We need to parse reg-shift and reg-io-width for UART 8520 as well.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agolib: utils/serial: Skip baudrate config if input frequency is zero
Anup Patel [Sat, 25 Apr 2020 05:41:49 +0000 (11:11 +0530)]
lib: utils/serial: Skip baudrate config if input frequency is zero

We should skip baudrate config for UART8250 and SiFive UART when
input frequency is zero.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
4 years agofirmware: fw_base: Remove CSR_MTVEC update check
Charles Papon [Fri, 1 May 2020 03:58:38 +0000 (09:28 +0530)]
firmware: fw_base: Remove CSR_MTVEC update check

Remove unnecessary CSR_MTVEC read to reduce the openSBI CSR requirement.

Mux are costly in FPGA. Allowing CSR_MTVEC to be write only is usefull
for the FMax/Area of FPGA softcore.

https://github.com/SpinalHDL/opensbi.git branch mtvec

Signed-off-by: Charles Papon <charles.papon.90@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoscripts: adapt binary archive script for Nuclei UX600
Huaqi Fang [Wed, 29 Apr 2020 10:05:51 +0000 (18:05 +0800)]
scripts: adapt binary archive script for Nuclei UX600

Signed-off-by: Huaqi Fang <578567190@qq.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Add Nuclei UX600 platform
Huaqi Fang [Tue, 28 Apr 2020 14:43:40 +0000 (22:43 +0800)]
platform: Add Nuclei UX600 platform

* Nuclei UX600 is a 64-bit RISC-V core developed
  by Nuclei System Technology, see https://nucleisys.com/product.php

* The ISA is configurable in hardware on your demand

Signed-off-by: Huaqi Fang <578567190@qq.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: utils: Add SiFive test device
Anup Patel [Fri, 24 Apr 2020 06:56:23 +0000 (12:26 +0530)]
lib: utils: Add SiFive test device

This patch factor-out SiFive test device related stuff into
it's own source file from qemu/virt platform. In future, we
can find SiFive test device address from device tree as well.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi_platform: Combine reboot and shutdown into one callback
Anup Patel [Fri, 24 Apr 2020 06:56:22 +0000 (12:26 +0530)]
include: sbi_platform: Combine reboot and shutdown into one callback

We can achieve shutdown, cold reboot, and warm reboot using just
one sbi_platform callback so we combine system_reboot() and
system_shutdown() callbacks into one system_reset() callback.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: No need to provide default PMP region using platform callbacks
Anup Patel [Thu, 23 Apr 2020 06:22:30 +0000 (11:52 +0530)]
lib: No need to provide default PMP region using platform callbacks

The default (usually last) PMP region provides S-mode access to
complete memory range not covered by other PMP regions.

Currently, the default PMP region is described as platform specific
PMP region which is not appropriate because all platforms need it
and default PMP region should be part of generic library.

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 agoinclude: Bump-up version to 0.7 v0.7
Anup Patel [Mon, 20 Apr 2020 10:58:42 +0000 (16:28 +0530)]
include: Bump-up version to 0.7

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

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Allow overriding SBI implementation ID
Anup Patel [Fri, 17 Apr 2020 09:40:10 +0000 (15:10 +0530)]
lib: Allow overriding SBI implementation ID

Ideally, the SBI implementation ID for OpenSBI should always be
0x1 (as mentioned in SBI v0.2 spec) but external firmware (such
as EDK2) which use OpenSBI as library might want to override the
SBI implementation ID with their custom implementation ID.

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 agodocs: Update README about supported SBI versions
Atish Patra [Fri, 17 Apr 2020 01:56:31 +0000 (18:56 -0700)]
docs: Update README about supported SBI versions

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Support vector extension
Atish Patra [Fri, 17 Apr 2020 01:56:30 +0000 (18:56 -0700)]
lib: Support vector extension

Enable vector context in mstatus by updating the corresponding bits
in mstatus if vector extension is supported by the hart.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: irqchip/plic: Fix maximum priority threshold value
Atish Patra [Fri, 3 Apr 2020 18:13:08 +0000 (11:13 -0700)]
lib: irqchip/plic: Fix maximum priority threshold value

As per the PLIC specification, maximum priority threshold value is 0x7.
Even though, writing a higher value doesn't cause any error in qemu
hifive unleashed, there may be some implementation which checks the upper
and may result in an illegal access.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: thead/c910: Use HSM extension to boot secondary cores
Liu Yibin [Fri, 27 Mar 2020 03:31:48 +0000 (11:31 +0800)]
platform: thead/c910: Use HSM extension to boot secondary cores

Remove custom vendor extension and use HSM extension
to boot secondary cores

Signed-off-by: Liu Yibin <yibin_liu@c-sky.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agoinclude: sbi_console: Remove scratch parameter from sbi_dprintf()
Anup Patel [Fri, 27 Mar 2020 06:46:16 +0000 (12:16 +0530)]
include: sbi_console: Remove scratch parameter from sbi_dprintf()

This patch removes scratch parameter from sbi_dprintf() function
because sbi_dprintf() can use sbi_scratch_thishart_ptr() to get
current HART scratch space.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi_timer: Remove scratch parameter from most funcitons
Anup Patel [Fri, 27 Mar 2020 06:38:34 +0000 (12:08 +0530)]
include: sbi_timer: Remove scratch parameter from most funcitons

This patch removes scratch parameter from most sbi_timer functions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi_system: Remove scratch parameter and redundant functions
Anup Patel [Fri, 27 Mar 2020 06:13:37 +0000 (11:43 +0530)]
include: sbi_system: Remove scratch parameter and redundant functions

This patch removes scratch parameter and redundant functions from
sbi_system.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi_ipi: Remove scratch parameter from most functions
Anup Patel [Fri, 27 Mar 2020 05:56:11 +0000 (11:26 +0530)]
include: sbi_ipi: Remove scratch parameter from most functions

This patch removes scratch parameter from most sbi_ipi functions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi_tlb: Remove scratch parameter from sbi_tlb_request()
Anup Patel [Fri, 27 Mar 2020 05:28:47 +0000 (10:58 +0530)]
include: sbi_tlb: Remove scratch parameter from sbi_tlb_request()

The sbi_ipi_send_many() should get current HART scratch pointer
on it's own using eventually hence removing scratch parameter from
sbi_tlb_request().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: sbi_scratch: Introduce sbi_scratch_last_hartid() API
Anup Patel [Thu, 26 Mar 2020 13:05:38 +0000 (18:35 +0530)]
lib: sbi_scratch: Introduce sbi_scratch_last_hartid() API

The patch adds sbi_scratch_last_hartid() API which returns
last HART id having a scratch space. We can use this new API
to optimize places where we iterate over HART id from 0 to
SBI_HARTMASK_MAX_BITS.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Use more consistent name for atomic xchg() and cmpxchg()
Anup Patel [Thu, 26 Mar 2020 12:40:02 +0000 (18:10 +0530)]
include: Use more consistent name for atomic xchg() and cmpxchg()

We should remove the "arch_" prefix from atomic xchg() and cmpxchg()
function names to have consistent naming of all atomic functions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: sbi_platform: Remove priv parameter from hart_start() callback
Anup Patel [Fri, 20 Mar 2020 11:14:38 +0000 (16:44 +0530)]
include: sbi_platform: Remove priv parameter from hart_start() callback

The priv parameter in hart_start() platform callback is redundant hence
we remove it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_trap: Simplify sbi_trap_handler() API
Anup Patel [Fri, 20 Mar 2020 03:23:35 +0000 (08:53 +0530)]
lib: sbi_trap: Simplify sbi_trap_handler() API

This patch simplify sbi_trap_handler() API as follows:
1. Remove current hartid local variable because sbi_trap_handler()
   itself does not need it.
2. Remove scratch parameter because none of the functions directly
   called by sbi_trap_handler() require it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_ecall: Remove mcause, scratch and hartid parameters
Anup Patel [Thu, 19 Mar 2020 16:25:12 +0000 (21:55 +0530)]
lib: sbi_ecall: Remove mcause, scratch and hartid parameters

We remove mcause, scratch and hartid parameters from various
functions for ecall handling because we can always get current
HART id and current scratch pointer using just one CSR access.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_misaligned_ldst: Remove mcause, scratch and hartid parameters
Anup Patel [Thu, 19 Mar 2020 16:00:02 +0000 (21:30 +0530)]
lib: sbi_misaligned_ldst: Remove mcause, scratch and hartid parameters

We remove mcause, scratch and hartid parameters from various functions
for misaligned load/store handling because we can always get current
HART id and current scratch pointer using just one CSR access.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_illegal_insn: Remove mcause, scratch and hartid parameters
Anup Patel [Thu, 19 Mar 2020 14:24:32 +0000 (19:54 +0530)]
lib: sbi_illegal_insn: Remove mcause, scratch and hartid parameters

We remove mcause, scratch and hartid parameters from various
functions for illegal instruction handling because we can always
get current HART id and current scratch pointer using just one
CSR access.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_emulate_csr: Remove scratch and hartid parameter
Anup Patel [Thu, 19 Mar 2020 14:16:00 +0000 (19:46 +0530)]
lib: sbi_emulate_csr: Remove scratch and hartid parameter

We remove scratch and hartid parameter from various functions
for CSR emulation because we can always get current HART id
and current scratch pointer using just one CSR access.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_trap: Remove scratch parameter from sbi_trap_redirect()
Anup Patel [Thu, 19 Mar 2020 14:03:25 +0000 (19:33 +0530)]
lib: sbi_trap: Remove scratch parameter from sbi_trap_redirect()

The scratch parameter of sbi_trap_redirect() is not used hence we
remove it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Remove scratch parameter from unpriv load/store functions
Anup Patel [Thu, 19 Mar 2020 12:07:54 +0000 (17:37 +0530)]
lib: Remove scratch parameter from unpriv load/store functions

The scratch parameter of unpriv load/store functions is now redundant
hence we remove it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Optimize unpriv load/store implementation
Anup Patel [Thu, 19 Mar 2020 11:43:16 +0000 (17:13 +0530)]
lib: Optimize unpriv load/store implementation

This patch optimize unpriv load/store implementation by having
dedicated unpriv trap handler (just like KVM RISC-V).

As a result of this optimization:
1. We have reduced roughly 13+ instruction in all unpriv load/store
   functions. The reduced instruction also include two function calls.
2. Per-HART trap info pointer in scratch space is now redundant
   hence removed.
3. The sbi_trap_handler() is now much cleaner because we don't have
   to handle unpriv load/store traps.

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 [Thu, 19 Mar 2020 05:53:41 +0000 (11:23 +0530)]
lib: utils: Improve fdt_cpu_fixup() implementation

Currently, the fdt_cpu_fixup() implementation assumes:
1. We have one CPU DT for each HART under /cpus DT node
2. The CPU DT nodes are named sequentially (i.e cpu@0,
   cpu@1, ...) which is not true for discontinuous and
   sparse HART ids (i.e. cpu@0, cpu@4, cpu@5). Generally,
   CPU DT node are named based on HART id and not HART
   index

If any of the above assumptions are violated then the
fdt_cpu_fixup() will not work.

This improves fdt_cpu_fixup() implementation and makes
it independent of above assumptions.

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>