platform/kernel/opensbi-spacemit.git
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
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>
4 years agoscripts: Extend create-binary-archive.sh for unified binary tar ball
Anup Patel [Tue, 24 Mar 2020 12:44:28 +0000 (18:14 +0530)]
scripts: Extend create-binary-archive.sh for unified binary tar ball

This patch extends/revamps create-binary-archive.sh to allow creating
unified binary tar ball containing both RV32 and RV64 images. Users
can also create "RV32 only" or "RV64 only" tar balls as well.

Few example commands are as follows:
./scripts/create-binary-archive.sh (Build both RV32 & RV64 images)
./scripts/create-binary-archive.sh -x 32 (Build RV32 only images)
./scripts/create-binary-archive.sh -x 64 (Build RV64 only images)

Signed-off-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: prevent coldboot_lottery from overflowing
Xiang Wang [Tue, 24 Mar 2020 10:11:48 +0000 (10:11 +0000)]
lib: prevent coldboot_lottery from overflowing

HSM_STOP will trigger multiple executions of sbi_init, atomic_add_return may
trigger coldboot_lottery overflow

Signed-off-by: Xiang Wang <merle@hardenedlinux.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: openpiton: Read the device configurations from device tree
Atish Patra [Mon, 23 Mar 2020 19:48:59 +0000 (12:48 -0700)]
platform: openpiton: Read the device configurations from device tree

OpenPiton is designed to run on different FPGAs with different
configurations. Use the fdt parser to retrieve the required values
from device tree instead of using fixed values.

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: Move fdt fixup helper routines to a different file
Atish Patra [Mon, 23 Mar 2020 19:48:58 +0000 (12:48 -0700)]
lib: utils: Move fdt fixup helper routines to a different file

FDT helper file contain both fdt fixup and parsing functions.

Split the fixup related functions to a separate file for a better code
organization.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: fpga/common: Add a fdt parsing helper functions
Atish Patra [Mon, 23 Mar 2020 19:48:57 +0000 (12:48 -0700)]
platform: fpga/common: Add a fdt parsing helper functions

Different DT based platforms from the sam family may reuse IP blocks with
different configurations. These different configurations can be obtained
by parsing the device tree.

Add a FDT parser framework that can parse various device configurations from
device tree. Currently, the parsing algorithms doesn't cover all the use cases
or possible combination of DT configurations. It will be improved over time.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Add OpenPiton platform support
Atish Patra [Mon, 23 Mar 2020 19:48:56 +0000 (12:48 -0700)]
platform: Add OpenPiton platform support

OpenPiton is a research platform from Princeton University [1].

"OpenPiton is the world's first open source, general purpose,
multithreaded manycore processor. It is a tiled manycore
framework scalable from one to 1/2 billion cores."

Add OpenSBI support for OpenPiton. As it is based on ariane core,
it reuses the platform code from arine project.

[1]. https://github.com/PrincetonUniversity/openpiton

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: fpga/ariane: Remove redundant plic address macros
Atish Patra [Mon, 23 Mar 2020 19:48:55 +0000 (12:48 -0700)]
platform: fpga/ariane: Remove redundant plic address macros

All the common PLIC specific macros are already defined in plic.c.

Remove it from platform code. While at it, Fix the other coding style
issues.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Move ariane standalone fpga project to its own project
Atish Patra [Mon, 23 Mar 2020 19:48:54 +0000 (12:48 -0700)]
platform: Move ariane standalone fpga project to its own project

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Check MSIP bit after returning from WFI
Atish Patra [Fri, 20 Mar 2020 22:10:36 +0000 (15:10 -0700)]
lib: Check MSIP bit after returning from WFI

Commit 71d2b837c46e (lib: Move all coldboot wait APIs to sbi_init.c)
caused a regression while moving the code from sbi_hart.c to sbi_init.c.

As per original commit text, WFI can be implemented as a NOP according
to the RISC-V privilege specification. Software should ensure that
relevant interrupt pending bits are set. Otherwise, loop back to WFI.
Fix the regression by applying the original patch to sbi_init.c.

Fixes: 71d2b837c46e ("lib: Move all coldboot wait APIs to sbi_init.c")

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: Fix sbi_ecall_register_extension to prevent extension IDs overlap
Xiang Wang [Thu, 19 Mar 2020 03:15:47 +0000 (03:15 +0000)]
lib: Fix sbi_ecall_register_extension to prevent extension IDs overlap

The original code does not prevent the following scenarios:
> sbi_ecall_register_extension(ext1); /* extension id (70-80) */
> sbi_ecall_register_extension(ext2); /* extension id (50-100) */

Signed-off-by: Xiang Wang <merle@hardenedlinux.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: sifive/fu540: Remove FU540_ENABLED_HART_MASK option
Anup Patel [Mon, 16 Mar 2020 04:59:34 +0000 (10:29 +0530)]
platform: sifive/fu540: Remove FU540_ENABLED_HART_MASK option

The FU540_ENABLED_HART_MASK compile time option was added for initial
bring-up on SiFive Unleashed. This option is redundant now because
disabled_hart_mask is already removed. Based on this rationale, we
remove FU540_ENABLED_HART_MASK compile time option.

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 agoinclude: sbi_platform: Introduce HART index to HART id table
Anup Patel [Sun, 15 Mar 2020 06:09:25 +0000 (11:39 +0530)]
include: sbi_platform: Introduce HART index to HART id table

A platform can have discontinuous and/or sparse HART ids so we
cannot always assume a set of HARTs with continuous HART ids.

This patch adds support for discontinuous and sparse HART ids by
introducing HART index to HART id table. This table has platform
hart_count entries and it maps HART index to HART id.

The HART index to HART id table has only two restrictions:
1. HART index < sbi_platform hart_count
2. HART id < SBI_HARTMASK_MAX_BITS

Example1:
Let's say we have a platform with 2 HART ids 11 and 22, for such a
a platform:
hart_count = 2
hart_index2id[0] = 11
hart_index2id[1] = 22

Example2:
Let's say we have a platform with 5 HARTs ids 0, 1, 2, 3, and 4
but out of these HART with id 0 is not usable so for such a platform:
hart_count = 5
hart_index2id[0] = -1U
hart_index2id[1] = 1
hart_index2id[2] = 2
hart_index2id[3] = 3
hart_index2id[4] = 4
OR
hart_count = 4
hart_index2id[0] = 1
hart_index2id[1] = 2
hart_index2id[2] = 3
hart_index2id[3] = 4

With HART index to HART id table in place, the hart_disabled()
callback is now redundant so we remove it as well.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Don't use sbi_platform_hart_count() API
Anup Patel [Sat, 14 Mar 2020 14:13:26 +0000 (19:43 +0530)]
lib: Don't use sbi_platform_hart_count() API

We don't need to use sbi_platform_hart_count() in sbi_init and
sbi_scratch because checking sbi_platform_hart_disabled() or
return value of sbi_hartid_to_scratch() is sufficient.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_hsm: Don't use sbi_platform_hart_disabled() API
Anup Patel [Sat, 14 Mar 2020 13:56:22 +0000 (19:26 +0530)]
lib: sbi_hsm: Don't use sbi_platform_hart_disabled() API

Checking return value of sbi_hartid_to_scratch() is sufficient
so no need to explicitly check for disabled HART using the
sbi_platform_hart_disabled() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_hsm: Remove scratch parameter from hart_started_mask() API
Anup Patel [Wed, 18 Mar 2020 09:50:12 +0000 (15:20 +0530)]
lib: sbi_hsm: Remove scratch parameter from hart_started_mask() API

The scratch parameter in sbi_hsm_hart_started_mask() API is now
redundant hence removing it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_hsm: Don't use sbi_platform_hart_count() API
Anup Patel [Wed, 18 Mar 2020 09:43:06 +0000 (15:13 +0530)]
lib: sbi_hsm: Don't use sbi_platform_hart_count() API

We remove usage of sbi_platform_hart_count() API from sbi_hsm
so that discontinuous and sparse HART ids can be supported.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: sbi_scratch: Don't set hartid_to_scratch table for disabled HART
Anup Patel [Sat, 14 Mar 2020 13:51:24 +0000 (19:21 +0530)]
lib: sbi_scratch: Don't set hartid_to_scratch table for disabled HART

As a step towards supporting discontinuous and sparse HART ids, we
don't set hartid_to_scratch table for disabled HARTs.

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 agoinclude: sbi_platform: Improve sbi_platform_hart_disabled() API
Anup Patel [Sat, 14 Mar 2020 14:09:15 +0000 (19:39 +0530)]
include: sbi_platform: Improve sbi_platform_hart_disabled() API

The sbi_platform_hart_disabled() should return TRUE for HART id
greater than platform hart count.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: Handle failure of sbi_hartid_to_scratch() API
Anup Patel [Sat, 14 Mar 2020 13:25:53 +0000 (18:55 +0530)]
lib: Handle failure of sbi_hartid_to_scratch() API

The sbi_hartid_to_scratch() API can fail for non-existent HARTs so
all uses of sbi_hartid_to_scratch() API should check return value.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_tlb: Simplify sbi_tlb_entry_process() function
Anup Patel [Sat, 14 Mar 2020 09:18:00 +0000 (14:48 +0530)]
lib: sbi_tlb: Simplify sbi_tlb_entry_process() function

We remove redundant scratch parameter from sbi_tlb_entry_process()
function.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_hsm: Simplify hart_get_state() and hart_started() APIs
Anup Patel [Sat, 14 Mar 2020 09:09:56 +0000 (14:39 +0530)]
lib: sbi_hsm: Simplify hart_get_state() and hart_started() APIs

We remove redundant scratch parameter from sbi_hsm_hart_get_state()
and sbi_hsm_hart_started() APIs.

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 agoinclude: Simplify HART id to scratch macro
Anup Patel [Sat, 14 Mar 2020 08:50:22 +0000 (14:20 +0530)]
include: Simplify HART id to scratch macro

This patch simplify HART id to scratch macro as follows:
1. Remove current "scratch" pointer argument because now we
   use HART id to scratch table
2. Rename sbi_hart_id_to_scratch() to sbi_hartid_to_scratch()
   to have macro name consistent with the name of callback
   in struct sbi_scratch

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_scratch: Introduce HART id to scratch table
Anup Patel [Sat, 14 Mar 2020 04:27:45 +0000 (09:57 +0530)]
lib: sbi_scratch: Introduce HART id to scratch table

Instead of calling hartid_to_scratch() callback every time when
we want sbi_scratch pointer from HART id, we create a table of
sbi_scratch pointers and use that to get sbi_scratch pointer.

As a result of HART id to scratch table, the conversion of
HART id to sbi_scratch pointer is just 2-3 instructions which
was 9 instructions previously.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: Update to call general DT fix-up helper
Bin Meng [Tue, 17 Mar 2020 14:59:51 +0000 (07:59 -0700)]
platform: Update to call general DT fix-up helper

Platform andes/ae350, ariane-fpga, qemu/virt and sifive/fu540 codes
have been updated to call this general DT fix-up helper.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: utils: Add a general device tree fix-up helper
Bin Meng [Tue, 17 Mar 2020 14:59:50 +0000 (07:59 -0700)]
lib: utils: Add a general device tree fix-up helper

This adds a general device tree fix-up helper to do all required
device tree fix-ups for a typical platform.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: sifive/fu540: Replace cpu0 node fix-up with the new helper
Bin Meng [Tue, 17 Mar 2020 14:59:49 +0000 (07:59 -0700)]
platform: sifive/fu540: Replace cpu0 node fix-up with the new helper

This replaces the FU540 specific cpu0 node "status" property fix-up
with the newly introduced generic fdt_cpu_fixup() helper.

Unlike previous logic, the helper routine does not test the "mmu-type"
property to determine which node we should fix up, instead it uses
sbi_platform_hart_disabled() API.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: utils: Add a fdt_cpu_fixup() helper
Bin Meng [Tue, 17 Mar 2020 14:59:48 +0000 (07:59 -0700)]
lib: utils: Add a fdt_cpu_fixup() helper

Add a helper routine to updates the "status" property of a CPU node
in the device tree to "disabled" if that hart is in disabled state.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: sifive/fu540: Remove "stdout-path" fix-up
Bin Meng [Tue, 17 Mar 2020 14:59:47 +0000 (07:59 -0700)]
platform: sifive/fu540: Remove "stdout-path" fix-up

As of today the upstream U-Boot & Linux kernel ships a device tree
that already has "stdout-path" properly set in the "/chosen" node.
This is the same with the QEMU 'sifive_u' machine. Hence the codes
to fix up the "stdout-path" in OpenSBI is not necessary.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: sifive/fu540: Fix up DT for reserved memory
Bin Meng [Tue, 17 Mar 2020 14:59:46 +0000 (07:59 -0700)]
platform: sifive/fu540: Fix up DT for reserved memory

This calls fdt_reserved_memory_fixup() helper in the platform's
final_init() routine.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: qemu/virt: Fix up DT for reserved memory
Bin Meng [Tue, 17 Mar 2020 14:59:45 +0000 (07:59 -0700)]
platform: qemu/virt: Fix up DT for reserved memory

This calls fdt_reserved_memory_fixup() helper in the platform's
final_init() routine.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: ariane-fpga: Fix up DT for reserved memory
Bin Meng [Tue, 17 Mar 2020 14:59:44 +0000 (07:59 -0700)]
platform: ariane-fpga: Fix up DT for reserved memory

This calls fdt_reserved_memory_fixup() helper in the platform's
final_init() routine.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: andes/ae350: Fix up DT for reserved memory
Bin Meng [Tue, 17 Mar 2020 14:59:43 +0000 (07:59 -0700)]
platform: andes/ae350: Fix up DT for reserved memory

This calls fdt_reserved_memory_fixup() helper in the platform's
final_init() routine.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Move PLIC DT fix up codes to fdt_helper.c
Bin Meng [Tue, 17 Mar 2020 14:59:42 +0000 (07:59 -0700)]
lib: utils: Move PLIC DT fix up codes to fdt_helper.c

Now that we have a dedicated fdt_helper.c file for DT releated
helper routines, move plic_fdt_fixup() codes from plic.c to
fdt_helper.c and rename it to fdt_plic_fixup() at the same time,
to keep name consistency in the same file.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoplatform: Clean up include header files
Bin Meng [Tue, 17 Mar 2020 14:59:41 +0000 (07:59 -0700)]
platform: Clean up include header files

Adjust the order of include header files in alphabetical order in
platform codes. Also remove unnecessary inclusions.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: utils: Add a fdt_reserved_memory_fixup() helper
Bin Meng [Tue, 17 Mar 2020 14:59:40 +0000 (07:59 -0700)]
lib: utils: Add a fdt_reserved_memory_fixup() helper

Add a helper routine to insert a child node of the reserved memory
node in the device tree that describes the protected memory region
done by OpenSBI via PMP.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolibfdt: Compile fdt_addresses.c
Bin Meng [Tue, 17 Mar 2020 14:59:39 +0000 (07:59 -0700)]
libfdt: Compile fdt_addresses.c

Pull fdt_addresses.o in for fdt_address_cells() & fdt_size_cells().

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi: Update pmp_get() to return decoded size directly
Bin Meng [Tue, 17 Mar 2020 14:59:38 +0000 (07:59 -0700)]
lib: sbi: Update pmp_get() to return decoded size directly

Currently pmp_get() returns the log2 length of the PMP memory
region size. The caller has to calculate the size based on that
and the same codes are duplicated.

Update this function to return decoded size directly.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoscripts: Cover sifive/fu540 in the 32-bit build
Bin Meng [Mon, 16 Mar 2020 09:43:46 +0000 (02:43 -0700)]
scripts: Cover sifive/fu540 in the 32-bit build

We now support building sifive/fu540 as a 32-bit platform. Add it
in the 32-bit platform list of binary archive script.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Use one unified per-HART stack size macro for all platforms
Bin Meng [Fri, 13 Mar 2020 05:39:54 +0000 (22:39 -0700)]
platform: Use one unified per-HART stack size macro for all platforms

As of today all platforms use 8KB of per-HART stack hence there is
no need for each platform to define its own macro or use the magic
number. Create one macro for all platforms. Platform still can use
its own version if needed.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: Set per-HART stack size to 8KB in the template platform codes
Bin Meng [Fri, 13 Mar 2020 05:39:53 +0000 (22:39 -0700)]
platform: Set per-HART stack size to 8KB in the template platform codes

The template platform codes should set per-HART stack size to 8KB
to avoid possible mistakes of future platform ports.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: ariane-fpga: Set per-HART stack size to 8KB
Bin Meng [Fri, 13 Mar 2020 05:39:52 +0000 (22:39 -0700)]
platform: ariane-fpga: Set per-HART stack size to 8KB

Recent commit

  4a603eb ("platform: kendryte/k210: Set per-HART stack size to 8KB")

forgot to update ariane-fpga codes, and the following commit

  678c3c3 ("include: sbi_scratch: Set per-HART scratch size to 4KB")

changed the per-HART scratch size to 4KB, which potentially breaks
ariane-fpga platform.

This patch set per-HART stack size of ariane-fpga to 8KB for consistency.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoMakefile: Fix distclean make target
Anup Patel [Wed, 11 Mar 2020 14:26:45 +0000 (19:56 +0530)]
Makefile: Fix distclean make target

The default install directory is not being removed correctly by
distclean make target due to recent changes. This patch fixes
distclean make target to fix default install directory removal.

Fixes: 82ae8e8fe2a3 ("makefile: Do setup of the install target
more flexible")
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agoinclude: Make sbi_current_hartid() as macro in riscv_asm.h
Anup Patel [Thu, 12 Mar 2020 04:51:25 +0000 (10:21 +0530)]
include: Make sbi_current_hartid() as macro in riscv_asm.h

The sbi_current_hartid() being a regular function is quite
expensive because for callers it is a function call instead
of a direct CSR read. This patch converts sbi_current_hartid()
into a macro in riscv_asm.h.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_hsm: Optimize sbi_hsm_hart_get_state() implementation
Anup Patel [Wed, 11 Mar 2020 14:04:39 +0000 (19:34 +0530)]
lib: sbi_hsm: Optimize sbi_hsm_hart_get_state() implementation

Now that sbi_hart_id_to_scratch() is optimized, we don't need
the "if ()" statement. Also, the hstate local variable is
redundant so we remove that as well.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agofirmware: fw_base: Optimize _hartid_to_scratch() implementation
Anup Patel [Wed, 11 Mar 2020 13:55:24 +0000 (19:25 +0530)]
firmware: fw_base: Optimize _hartid_to_scratch() implementation

This patch optimizes _hartid_to_scratch() in following ways:
1. Use caller saved registers instead of callee saved registers
   so that we don't need to save/restore registers on stack
2. Remove second redundant mul instruction by re-arranging
   instructions

Overall, we reduce 9 instructions in _hartid_to_scratch()
implementation.

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: Make sbi_hart_id_to_scratch() as macro
Anup Patel [Wed, 11 Mar 2020 13:38:08 +0000 (19:08 +0530)]
include: Make sbi_hart_id_to_scratch() as macro

The sbi_hart_id_to_scratch() just forwards call to firmware specific
hartid_to_scratch() callback so we make sbi_hart_id_to_scratch() as
macro in sbi_scratch.h instead of regular function in sbi_hart.c.

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 agolibfdt: Upgrade to v1.5.1 release
Bin Meng [Thu, 12 Mar 2020 05:46:28 +0000 (22:46 -0700)]
libfdt: Upgrade to v1.5.1 release

Sync with latest libfdt v1.5.1 release source codes.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolibfdt: Add INT32_MAX and UINT32_MAX in libfdt_env.h
Bin Meng [Thu, 12 Mar 2020 05:46:27 +0000 (22:46 -0700)]
libfdt: Add INT32_MAX and UINT32_MAX in libfdt_env.h

Add two macros in preparation to sync libfdt codes to latest v1.5.1
release from upstream.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agosbi: Add definitions for true/false
Bin Meng [Thu, 12 Mar 2020 05:46:26 +0000 (22:46 -0700)]
sbi: Add definitions for true/false

We currently have TRUE/FALSE, but it could be convenient to have
true/false as well.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agoplatform: ariane-fpga: Change license for ariane-fpga from GPL-2.0 to BSD-2
Panagiotis Peristerakis [Thu, 12 Mar 2020 13:56:24 +0000 (15:56 +0200)]
platform: ariane-fpga: Change license for ariane-fpga from GPL-2.0 to BSD-2

Signed-off-by: Panagiotis Peristerakis <perister@ics.forth.gr>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: sbi: Fix misaligned trap handling
Damien Le Moal [Thu, 12 Mar 2020 05:20:37 +0000 (14:20 +0900)]
lib: sbi: Fix misaligned trap handling

Compile time checks of __riscv_compressed can only check if OpenSBI is
being compiled using compressed instructions or not. Checking this macro
does not indicate if an instruction that generated a misaligned trap is
a compressed instruction or not.

Since the misaligned trap handling code inspects instructions _C_ bits
to detect compressed instructions, we can remove all static checks on
__riscv_compressed and dissociate hanlding of misaligned traps and
OpenSBI compilation.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agodocs: Remove out-of-date documentation
Atish Patra [Tue, 10 Mar 2020 23:46:53 +0000 (16:46 -0700)]
docs: Remove out-of-date documentation

Upstream U-Boot now have SMP support and doesn't require any additional
patches for HiFive Unleashed.

Update the documentation.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: sbi_hart: Remove HART available mask and related APIs
Anup Patel [Mon, 2 Mar 2020 11:03:07 +0000 (16:33 +0530)]
lib: sbi_hart: Remove HART available mask and related APIs

The HART available mask and related APIs are now totally redundant
because of more extensive HART state machine implemented by sbi_hsm.

Due to above, we remove HART available mask and related APIs.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: sbi_ipi: Use sbi_hsm_hart_started_mask() API
Anup Patel [Mon, 2 Mar 2020 10:51:38 +0000 (16:21 +0530)]
lib: sbi_ipi: Use sbi_hsm_hart_started_mask() API

This patch replaces use of sbi_hart_available_mask() API with
sbi_hsm_hart_started_mask() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: sbi_system: Use sbi_hsm_hart_started_mask() API
Anup Patel [Mon, 2 Mar 2020 10:49:49 +0000 (16:19 +0530)]
lib: sbi_system: Use sbi_hsm_hart_started_mask() API

This patch replaces use of sbi_hart_available_mask() API with
sbi_hsm_hart_started_mask() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: sbi_ecall_legacy: Use sbi_hsm_hart_started_mask() API
Anup Patel [Mon, 2 Mar 2020 10:47:49 +0000 (16:17 +0530)]
lib: sbi_ecall_legacy: Use sbi_hsm_hart_started_mask() API

This patch replaces use of sbi_hart_available_mask() API with
sbi_hsm_hart_started_mask API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: Introduce sbi_hsm_hart_started_mask() API
Anup Patel [Mon, 2 Mar 2020 10:43:50 +0000 (16:13 +0530)]
lib: Introduce sbi_hsm_hart_started_mask() API

This patch introduce sbi_hsm_hart_started_mask() API as
a replacement of sbi_hart_available_mask() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agoinclude: Remove disabled_hart_mask from sbi_platform
Anup Patel [Mon, 2 Mar 2020 12:19:17 +0000 (17:49 +0530)]
include: Remove disabled_hart_mask from sbi_platform

The disabled_hard_mask in sbi_platform is only 64bits wide so we
cannot disable a HART with HARTID > 63. To tackle this, we remove
disabled_hart_mask and replace it with hart_disabled() platform
callback.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_init: Use hartmask for coldboot wait
Anup Patel [Wed, 4 Mar 2020 12:00:21 +0000 (17:30 +0530)]
lib: sbi_init: Use hartmask for coldboot wait

The coldboot_wait_bitmap is of fixed size and has __riscv_xlen
bits. This limits us to scale beyond __riscv_xlen HARTs hence
we replace coldboot_wait_bitmap with coldboot_wait_hmask which
is of type struct sbi_hartmask.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Move all coldboot wait APIs to sbi_init.c
Anup Patel [Mon, 2 Mar 2020 11:20:01 +0000 (16:50 +0530)]
lib: Move all coldboot wait APIs to sbi_init.c

The coldboot wait APIs are only used by sbi_init.c so no point in
having coldboot related code in sbi_hart.c.

As per-above rationale, we move all coldboot wait related APIs to
sbi_init.c as static/local functions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
4 years agolib: sbi_tlb: Use sbi_hartmask in sbi_tlb_info
Anup Patel [Wed, 4 Mar 2020 08:51:42 +0000 (14:21 +0530)]
lib: sbi_tlb: Use sbi_hartmask in sbi_tlb_info

Instead of using single ulong as source mask for sbi_tlb_info,
we use sbi_hartmask. This way sbi_tlb_info can easily scale
for large number of HARTs.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Introduce SBI_TLB_INFO_INIT() helper macro
Anup Patel [Tue, 3 Mar 2020 14:11:09 +0000 (19:41 +0530)]
lib: Introduce SBI_TLB_INFO_INIT() helper macro

We introduce SBI_TLB_INFO_INIT() helper macro to help easy
initialization of struct sbi_tlb_info which is passed to the
sbi_tlb_request() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: sbi_init: Don't allow HARTID greater than SBI_HARTMASK_MAX_BITS
Anup Patel [Wed, 4 Mar 2020 09:00:49 +0000 (14:30 +0530)]
lib: sbi_init: Don't allow HARTID greater than SBI_HARTMASK_MAX_BITS

We only allow HARTs with HARTID less than SBI_HARTMASK_MAX_BITS in
sbi_init() function so that sbi_hartmask can safely used across
OpenSBI sources.

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 agoinclude: Simple hartmask library
Anup Patel [Wed, 4 Mar 2020 08:28:22 +0000 (13:58 +0530)]
include: Simple hartmask library

We add a simple hartmask library to create and maintain HART mask
in different parts of OpenSBI sources. This new library is build
as wrapper library on-top-of bitmap library.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: Simple bitmap library
Anup Patel [Wed, 4 Mar 2020 06:59:15 +0000 (12:29 +0530)]
lib: Simple bitmap library

We add simple bitmap library which will help us create and maintain
bitmaps. It will also help us create a simple HART mask library.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
4 years agolib: serial: Fix coding style issues
Bin Meng [Mon, 9 Mar 2020 03:52:42 +0000 (20:52 -0700)]
lib: serial: Fix coding style issues

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

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
4 years agolib: sbi: Fix coding style issues
Bin Meng [Mon, 9 Mar 2020 03:52:41 +0000 (20:52 -0700)]
lib: sbi: Fix coding style issues

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

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

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

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

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

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

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

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

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

Most the above is adopted from Xvisor sources.

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

The right location for all bits related defines and macros is
sbi_bitops.h hence this patch. With this patch, the sbi_bits.h
is redundant so we remove it.

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

The return type of sbi_hsm_hart_started() should be bool.

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