platform/kernel/opensbi-spacemit.git
3 years agolib: sign conflict in wake_coldboot_harts()
Heinrich Schuchardt [Mon, 21 Jun 2021 19:37:54 +0000 (21:37 +0200)]
lib: sign conflict in wake_coldboot_harts()

Compiling wake_coldboot_harts() with GCC 11 and -Wextra yields:

lib/sbi/sbi_init.c:208:27:
error: comparison of integer expressions of different signedness:
‘int’ and ‘u32’ {aka ‘unsigned int’} [-Werror=sign-compare]
  208 |         for (int i = 0; i <= sbi_scratch_last_hartid(); i++) {
      |                           ^~

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sign conflict in sbi_tlb_entry_process()
Heinrich Schuchardt [Mon, 21 Jun 2021 19:50:10 +0000 (21:50 +0200)]
lib: sign conflict in sbi_tlb_entry_process()

Compiling sbi_tlb_entry_process() with GCC 11 and -Wextra yields:

lib/sbi/sbi_tlb.c: In function ‘sbi_tlb_process_count’:
lib/sbi/sbi_tlb.c:206:31:
error: comparison of integer expressions of different signedness:
‘u32’ {aka ‘unsigned int’} and ‘int’ [-Werror=sign-compare]
  206 |                 if (deq_count > count)

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils/libfdt: Upgrade to v1.6.1 release
Bin Meng [Fri, 11 Jun 2021 07:27:27 +0000 (15:27 +0800)]
lib: utils/libfdt: Upgrade to v1.6.1 release

Sync with libfdt v1.6.1 release source codes.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Fix GET_F64_REG inline assembly
Charles Papon [Sat, 12 Jun 2021 04:23:33 +0000 (09:53 +0530)]
lib: sbi: Fix GET_F64_REG inline assembly

Current, GET_F64_REG() macro does not generate correct inline
assembly for the RV32 systems. This patch provides separate
definitions of GET_F64_REG() macro for RV32 and RV64 systems.

Signed-off-by: Charles Papon <charles.papon.90@gmail.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils: missing initialization in thead_reset_init
Heinrich Schuchardt [Tue, 8 Jun 2021 20:05:46 +0000 (22:05 +0200)]
lib: utils: missing initialization in thead_reset_init

If property csr-copy does not exist, fdt_getprop() will return NULL and cnt
will have a random value from the stack.

Call clone_csrs() only if cnt is initialized to a non-zero value.

Fixes: 49e422c5ad7a ("lib: utils: reset: Add T-HEAD sample platform reset driver")
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi_scratch: zero out scratch memory on all harts
Heinrich Schuchardt [Sat, 5 Jun 2021 12:22:43 +0000 (14:22 +0200)]
lib: sbi_scratch: zero out scratch memory on all harts

In sbi_scratch_init() we determine the last hart. The index of the last
hart cannot exceed SBI_HARTMASK_MAX_BITS - 1. We should not initialize
last_hartid_having_scratch to a higher number to avoid buffer overflows
when using this value before calling sbi_scratch_init().

When allocating scratch memory in sbi_scratch_alloc_offset() we zero out
the allocated memory for all harts except for the last one. We should not
skip the last hart.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: andes/ae350: Drop plicsw_ipi_sync()
Bin Meng [Fri, 4 Jun 2021 15:35:45 +0000 (23:35 +0800)]
platform: andes/ae350: Drop plicsw_ipi_sync()

plicsw_ipi_sync() is a forward declaration but without the actual
implementation. Drop it.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: andes/ae350: Drop plicsw_get_pending()
Bin Meng [Fri, 4 Jun 2021 15:35:44 +0000 (23:35 +0800)]
platform: andes/ae350: Drop plicsw_get_pending()

This is not used anywhere. Drop it.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs/platform: andes-ae350: Fix missing spaces
Bin Meng [Fri, 4 Jun 2021 15:35:43 +0000 (23:35 +0800)]
docs/platform: andes-ae350: Fix missing spaces

Fix several places in the docmentation that are missing spaces.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: andes/ae350: Cosmetic fixes in plicsw.c
Bin Meng [Fri, 4 Jun 2021 15:35:42 +0000 (23:35 +0800)]
platform: andes/ae350: Cosmetic fixes in plicsw.c

- %s/CLINT/PLICSW
- replace '.' with a space
- add a space around * in plicsw_cold_ipi_init()

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi_scratch: remove owner from sbi_scratch_alloc_offset
Heinrich Schuchardt [Sat, 29 May 2021 19:54:29 +0000 (21:54 +0200)]
lib: sbi_scratch: remove owner from sbi_scratch_alloc_offset

The parameter owner of function sbi_scratch_alloc_offset() is never used.
The scratch memory is small. We should not use it for debug information in
future. Hence eliminate the parameter.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils: consider ':' in stdout-path
Heinrich Schuchardt [Fri, 28 May 2021 17:06:32 +0000 (19:06 +0200)]
lib: utils: consider ':' in stdout-path

The value of the /chosen/stdout-path devicetree property is used to
determine the UART used by openSBI. According to the devicetree
specification the value may contain a hyphen, e.g.

chosen {
                stdout-path = "/serial@f00:115200";
        };

If the character ':' is present, it terminates the path of the device.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agodocs: debugging OpenSBI
Heinrich Schuchardt [Fri, 28 May 2021 16:22:14 +0000 (18:22 +0200)]
docs: debugging OpenSBI

Describe how to debug OpenSBI on QEMU with GDB.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils: Try other FDT drivers when we see SBI_ENODEV
Anup Patel [Thu, 20 May 2021 15:46:25 +0000 (21:16 +0530)]
lib: utils: Try other FDT drivers when we see SBI_ENODEV

We should try other FDT drivers when we see SBI_ENODEV returned
by cold_init() of FDT driver.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: Check region base for merging in sbi_domain_root_add_memregion()
Anup Patel [Thu, 20 May 2021 10:17:07 +0000 (15:47 +0530)]
lib: Check region base for merging in sbi_domain_root_add_memregion()

We can merge region B onto region A only if base of region A is
aligned to region A order + 1.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils/fdt: Replace strcmp with strncmp
Daniel Schaefer [Wed, 19 May 2021 07:54:10 +0000 (15:54 +0800)]
lib: utils/fdt: Replace strcmp with strncmp

Use strncmp() instead of strcmp() in __fixup_find_domain_offset()
so that it compiles fine when linking with external firmware (such
as EDK2).

Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Abner Chang <abner.chang@hpe.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils/fdt: Don't use sbi_string functions
Daniel Schaefer [Wed, 19 May 2021 07:54:09 +0000 (15:54 +0800)]
lib: utils/fdt: Don't use sbi_string functions

When SBI is built by external firmware, we need to use their functions,
defined in libfdt_env.h.

Just like 2cfd2fc9048806353298a1b967abf985901e36e8

Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
Reviewed-by: Abner Chang <abner.chang@hpe.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils: Add strncpy macro to libfdt_env.h
Daniel Schaefer [Wed, 19 May 2021 07:54:08 +0000 (15:54 +0800)]
lib: utils: Add strncpy macro to libfdt_env.h

we want to use sbi_strncpy as strncpy in the OpenSBI implementation for
libfdt.

Just like 2845d2d2cf4fb74a89452ba223995aa4a118c07e

Signed-off-by: Daniel Schaefer <daniel.schaefer@hpe.com>
Reviewed-by: Abner Chang <abner.chang@hpe.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoMakefile: unconditionally disable SSP
Fabrice Fontaine [Sat, 15 May 2021 08:16:38 +0000 (10:16 +0200)]
Makefile: unconditionally disable SSP

Though -nostdlib is passed in CFLAGS, -fno-stack-protector must also be
passed to avoid linking errors related to undefined references to
'__stack_chk_guard' and '__stack_chk_fail' if toolchain enforces
-fstack-protector.

Fixes:
 - https://gitlab.com/kubu93/buildroot/-/jobs/1247043359

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils/serial: Support Synopsys DesignWare APB UART
Bin Meng [Fri, 14 May 2021 01:16:13 +0000 (09:16 +0800)]
lib: utils/serial: Support Synopsys DesignWare APB UART

Synopsys DesignWare APB UART is seen on the StarFive JH7100 SoC.
Its programming interface is compatible with the existing 8250
UART driver. Simply add its compatible string to the driver makes
it work with the StarFive JH7100 SoC on a BeagleV board.

With this patch, the generic platform firmware can be used out of
the box on the BeagleV board.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Have spinlock checks return bool
Daniel Schaefer [Thu, 13 May 2021 04:52:35 +0000 (12:52 +0800)]
lib: sbi: Have spinlock checks return bool

spin_lock_check already returned bool in the source file but not in the
header. With some toolchains that causes an error, as it should.

Because it and related functions all essentially return a bool, we can
use this opportunity to change them.

Signed-off-by: Daniel Schaefer <git@danielschaefer.me>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: Remove sifive/fu540 platform
Bin Meng [Thu, 29 Apr 2021 10:16:09 +0000 (18:16 +0800)]
platform: Remove sifive/fu540 platform

Now that SiFive HiFive Unleashed board is using the generic platform
support in OpenSBI, let's remove the old non-generic one.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs: platform: Describe sifive_fu540 as supported generic platform
Bin Meng [Thu, 29 Apr 2021 10:16:08 +0000 (18:16 +0800)]
docs: platform: Describe sifive_fu540 as supported generic platform

The upstream U-Boot/QEMU have been using generic platform for SiFive
HiFive Unleashed board for some time. Let's document sifive_fu540 as
one of the supported targets for "generic" platform.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs: platform: Sort platform names
Bin Meng [Thu, 29 Apr 2021 10:16:07 +0000 (18:16 +0800)]
docs: platform: Sort platform names

Let's sort the platform names in alphabetical order.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils/serial: Add support for Gaisler APBUART
Daniel Cederman [Fri, 30 Apr 2021 06:35:56 +0000 (08:35 +0200)]
lib: utils/serial: Add support for Gaisler APBUART

This patch adds support for the UART used by the NOEL-V processor.

Cobham Gaisler's NOEL-V RISC-V processor IP is available under GPL
and commercial license and is described in more detail at
https://www.gaisler.com/noelv.

Signed-off-by: Daniel Cederman <cederman@gaisler.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
3 years agodocs/platform: sifive_fu540: Update U-Boot defconfig name
Bin Meng [Wed, 21 Apr 2021 04:20:04 +0000 (12:20 +0800)]
docs/platform: sifive_fu540: Update U-Boot defconfig name

With latest U-Boot upstream (v2021.07 in development), the defconfig
name has been changed to sifive_unleashed_defconfig. Update the doc.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Show devices provided by platform in boot prints
Anup Patel [Thu, 22 Apr 2021 09:19:44 +0000 (14:49 +0530)]
lib: sbi: Show devices provided by platform in boot prints

We extend the boot-time prints to show various devices provided
(or registered) by the platform support. This will help users
verify hardware devices available for OpenSBI firmwares.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Simplify HSM platform operations
Anup Patel [Thu, 22 Apr 2021 08:44:02 +0000 (14:14 +0530)]
lib: sbi: Simplify HSM platform operations

Instead of having hsm_start(), hsm_stop() and hsm_suspend()
callbacks in platform operations, it will be much simpler for
HSM driver to directly register these operations as a device
to the sbi_hsm implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Simplify system reset platform operations
Anup Patel [Thu, 22 Apr 2021 06:23:32 +0000 (11:53 +0530)]
lib: sbi: Simplify system reset platform operations

Instead of having system_reset_check() and system_reset() callbacks
in platform operations, it will be much simpler for reset driver to
directly register these operations as a device to the sbi_system
implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Simplify ipi platform operations
Anup Patel [Thu, 22 Apr 2021 04:57:15 +0000 (10:27 +0530)]
lib: sbi: Simplify ipi platform operations

Instead of having ipi_send() and ipi_clear() callbacks in
platform operations, it will be much simpler for ipi driver
to directly register these operations as a device to sbi_ipi
implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Simplify timer platform operations
Anup Patel [Wed, 21 Apr 2021 16:34:17 +0000 (22:04 +0530)]
lib: sbi: Simplify timer platform operations

Instead of having timer_value(), timer_event_start(), and
timer_event_stop() callbacks in platform operations, it will
be much simpler for timer driver to directly register these
operations as device to the sbi_timer implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Simplify console platform operations
Anup Patel [Wed, 21 Apr 2021 12:33:50 +0000 (18:03 +0530)]
lib: sbi: Simplify console platform operations

Instead of having console_putc() and console_getc() callbacks in
platform operations, it will be much simpler for console driver to
directly register these operations as device to the sbi_console
implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sbi: Remove domains_root_regions() platform callback
Anup Patel [Wed, 21 Apr 2021 11:16:15 +0000 (16:46 +0530)]
lib: sbi: Remove domains_root_regions() platform callback

We now have sbi_domain_root_add_memregion() which allows platform
support to add root domain regions at boot-time so let's remove
the domains_root_regions() platform callback which was added
for this purpose.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agodocs: generic: Add T-HEAD C9xx series processors
Guo Ren [Tue, 27 Apr 2021 06:47:53 +0000 (06:47 +0000)]
docs: generic: Add T-HEAD C9xx series processors

Add description and dts examples for T-HEAD C9xx platforms.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: Remove platform/thead
Guo Ren [Tue, 27 Apr 2021 06:47:52 +0000 (06:47 +0000)]
platform: Remove platform/thead

We could use platform/generic instead, and won't use
platform/thead/c910 again.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Enable FW_PIC by default
Guo Ren [Tue, 27 Apr 2021 07:00:25 +0000 (07:00 +0000)]
firmware: Enable FW_PIC by default

Let's have FW_PIC enabled by default so that OpenSBI firmware
can by default run from any physical address.

Tested with qemu_rv32 & rv64, T-HEAD all hardwares.

Suggested-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Tested-by: Guo Ren <guoren@linux.alibaba.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Fix sbi_domain_root_add_memregion() for merging memregions
Anup Patel [Thu, 22 Apr 2021 11:42:26 +0000 (17:12 +0530)]
lib: sbi: Fix sbi_domain_root_add_memregion() for merging memregions

We should decrement root_memregs_count by one after merging two
memregions otherwise new memregion added after a merge will be
appended after last sentinel memregion of zero order.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils: reset: Add T-HEAD sample platform reset driver
Guo Ren [Sat, 17 Apr 2021 16:26:17 +0000 (16:26 +0000)]
lib: utils: reset: Add T-HEAD sample platform reset driver

This driver is for T-HEAD test chip, fpga. It could work with
all T-HEAD riscv processors: C9xx series.

example1: (Using io-regs for reset)
reset: reset-sample {
compatible = "thead,reset-sample";
plic-delegate = <0xff 0xd81ffffc>;
entry-reg = <0xff 0xff019050>;
entry-cnt = <4>;
control-reg = <0xff 0xff015004>;
control-val = <0x1c>;
csr-copy = <0x7f3 0x7c0 0x7c1 0x7c2 0x7c3 0x7c5 0x7cc>;
};

example2: (Using csr-regs for reset)
reset: reset-sample {
compatible = "thead,reset-sample";
plic-delegate = <0xff 0xd81ffffc>;
using-csr-reset;
csr-copy = <0x7c0 0x7c1 0x7c2 0x7c3 0x7c5 0x7cc
    0x3b0 0x3b1 0x3b2 0x3b3
    0x3b4 0x3b5 0x3b6 0x3b7
    0x3a0>;
};

example3: (Only delegate plic enable to S-mode)
reset: reset-sample {
compatible = "thead,reset-sample";
plic-delegate = <0xff 0xd81ffffc>;
};

After this patch, all T-HEAD c9xx would use platform/generic with fw_dynamic
as default:

CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y /usr/bin/make

The platform/thead will be deprecated.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils: Implement "64bit-mmio" property parsing
Guo Ren [Sat, 17 Apr 2021 16:26:16 +0000 (16:26 +0000)]
lib: utils: Implement "64bit-mmio" property parsing

Figure out CLINT has_64bit_mmio from DT node and using antonym for
compatibility.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Make sbi_domain_memregion_initfw() a local function
Anup Patel [Sat, 10 Apr 2021 04:38:23 +0000 (10:08 +0530)]
lib: sbi: Make sbi_domain_memregion_initfw() a local function

The sbi_domain_memregion_initfw() is no longer used outside
sbi_domain.c so let's make it a local function.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: utils: Copy over restricted root domain memregions to FDT domains
Anup Patel [Sat, 10 Apr 2021 04:07:23 +0000 (09:37 +0530)]
lib: utils: Copy over restricted root domain memregions to FDT domains

We should copy over all restricted memregions from the root domain
to the domains populated from FDT. These restricted root memregions
are typically firmware memregion and M-mode only mmio memregions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Make the root domain instance global variable
Anup Patel [Sat, 10 Apr 2021 03:39:00 +0000 (09:09 +0530)]
lib: sbi: Make the root domain instance global variable

We make the the root domain instance global variable so that
platform support and drivers can iterate over the root domain
regions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: utils/sys: Add CLINT memregion in the root domain
Anup Patel [Fri, 9 Apr 2021 12:39:06 +0000 (18:09 +0530)]
lib: utils/sys: Add CLINT memregion in the root domain

The CLINT memory should not be accessed by the supervisor-mode
software so let's protect it by adding CLINT memregion to the
root domain.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Add sbi_domain_root_add_memregion() API
Anup Patel [Fri, 9 Apr 2021 04:31:11 +0000 (10:01 +0530)]
lib: sbi: Add sbi_domain_root_add_memregion() API

We should allow platform support to add more root memory regions
before domains are finalized. This will help platform support to
protect critical M-mode only resources.

This patch adds sbi_domain_root_add_memregion() API for above
described purpose.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Add sbi_domain_memregion_init() API
Anup Patel [Fri, 9 Apr 2021 10:32:40 +0000 (16:02 +0530)]
lib: sbi: Add sbi_domain_memregion_init() API

This patch adds sbi_domain_memregion_init() helper API which can
be used by platform support to initialize a domain memory region
before adding it to the root domain.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: Domains can be registered only before finalizing domains
Anup Patel [Fri, 9 Apr 2021 03:50:08 +0000 (09:20 +0530)]
lib: sbi: Domains can be registered only before finalizing domains

The domains are boot-time system-level partitions so we should
allow platform support to register domains only before hart
domain assignments are finalized.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agodocs: fix link to OpenPiton documentation
hasheddan [Sat, 10 Apr 2021 12:08:03 +0000 (07:08 -0500)]
docs: fix link to OpenPiton documentation

Updates link in platforms documentation to point to the correct
OpenPiton document.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: fix atomic_add_return
Xiang W [Tue, 6 Apr 2021 03:34:38 +0000 (11:34 +0800)]
lib: sbi: fix atomic_add_return

The unsigned length may be 4 bytes or 8 bytes, amoadd.w only applies
to 4 bytes hence this patch.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Replace test-and-set locks by ticket locks
Christoph Muellner [Tue, 6 Apr 2021 01:53:54 +0000 (03:53 +0200)]
lib: sbi: Replace test-and-set locks by ticket locks

Replace the test-and-set spinlock implementation with ticket locks
in order to get fairness (in form of FIFO order).

The implementation uses a 32-bit wide struct, which consists of
two 16-bit counters (owner and next). This is inspired by similar
spinlock implementations on other architectures.
This allows that the code works for both, RV32 and RV64.

Signed-off-by: Christoph Muellner <cmuellner@linux.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agoinclude: sbi: Allow direct initialization via SPIN_LOCK_INIT()
Christoph Muellner [Tue, 6 Apr 2021 01:53:53 +0000 (03:53 +0200)]
include: sbi: Allow direct initialization via SPIN_LOCK_INIT()

The current implementation of SPIN_LOCK_INIT() provides the spinlock
to be initialized as reference. This does not allow a direct
initialization of the spinlock object at the creation site.

Let's pass the spinlock directly instead (like Linux does as well)
and adjust all users of the macro (in fact there is only one user).

Signed-off-by: Christoph Muellner <cmuellner@linux.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoinclude: types: Add __aligned(x) to define the minimum alignement
Christoph Muellner [Tue, 6 Apr 2021 01:53:52 +0000 (03:53 +0200)]
include: types: Add __aligned(x) to define the minimum alignement

The __aligned(x) macro is a common wrapper around compiler's
aligned attribute, which allow to define the minimum alignement
of a data type. Let's add this macro.

Signed-off-by: Christoph Muellner <cmuellner@linux.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Remove redundant add instruction from trap restore path
Anup Patel [Thu, 1 Apr 2021 11:01:00 +0000 (16:31 +0530)]
firmware: Remove redundant add instruction from trap restore path

The "add sp, a0, zero" instruction in the trap restore path is redundant
and can be avoided if TRAP_RESTORE_xyz() assembly macros use a0 as the
base register instead of sp.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: fix csr detect support
Xiang W [Thu, 1 Apr 2021 07:59:40 +0000 (15:59 +0800)]
lib: fix csr detect support

csr_read_allowed/csr_read_allowed requires trap.case to detect the results,
but if no exception occurs, the value of trap.case will remain unchanged,
which makes the detection results unreliable. Add code to initialize
trap.case to 0.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirware: optimize the exception exit code
Xiang W [Tue, 30 Mar 2021 12:07:35 +0000 (20:07 +0800)]
firware: optimize the exception exit code

There are two copies of the same abnormal exit code, this patch deletes one

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib/utils: Support fixing up the official DT bindings of PLIC
Bin Meng [Sat, 27 Mar 2021 05:05:27 +0000 (13:05 +0800)]
lib/utils: Support fixing up the official DT bindings of PLIC

Current fdt_plic_fixup() only does necessary fix-up against the legacy
"riscv,plic0" node. The upstream Linux kernel defines its official DT
bindings which uses "sifive,plic-1.0.0" as the compatible string and
we should check that first, and if not present fall back to legacy.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib/utils: Drop the 'compat' parameter of fdt_plic_fixup()
Bin Meng [Sat, 27 Mar 2021 05:05:26 +0000 (13:05 +0800)]
lib/utils: Drop the 'compat' parameter of fdt_plic_fixup()

At present fdt_plic_fixup() accepts a 'compat' parameter for PLIC
compatible string. In preparation to support the new DT bindings,
drop this and use "riscv,plic0" directly in fdt_plic_fixup().

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib/utils: Support the official clint DT bindings
Bin Meng [Sat, 27 Mar 2021 05:05:25 +0000 (13:05 +0800)]
lib/utils: Support the official clint DT bindings

Linux kernel commit a2770b57d083 ("dt-bindings: timer: Add CLINT bindings")
adds the official DT bindings for CLINT, which uses "sifive,clint0"
as the compatible string. "riscv,clint0" is now legacy and has to
be kept for backward compatibility of legacy systems.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoinclude: headers: Replace __ASSEMBLY__ with __ASSEMBLER__
Marouene Boubakri [Fri, 12 Mar 2021 11:00:01 +0000 (12:00 +0100)]
include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__

GCC has already a predefined macro __ASSEMBLER__ therefore, it can be
used without the need to define a new flag with -D__ASSEMBLY__.
This is useful when adding the library to projects having a build
system such one can build without the need to make changes.
THe build system does not use the Makefile in the sources tree.

Signed-off-by: Marouene Boubakri <marouene.boubakri@nxp.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: illegal CSR 0x306 access in hpm_allowed()
Heinrich Schuchardt [Fri, 19 Mar 2021 10:04:50 +0000 (11:04 +0100)]
lib: sbi: illegal CSR 0x306 access in hpm_allowed()

The trap handler sbi_emulate_csr_read() invokes hpm_allowed() which reads
CSR 0x306 (mcounteren). The K210 does not support CSR 0x306. While trying
to handle a trap occurring in S-mode code this creates an additional trap
in M-mode. This results in failure to redirect to S-mode and the system
hanging in sbi_hart_hang().

In hart_detect_features() we have already determined if CSR 0x306 is
available and stored that information in the scratch area. We can use this
information to decide if CSR 0x306 shall be accessed in hpm_allowed() and
thus avoid the M-mode trap.

Likewise if CSR scounteren is not available we have to avoid reading CSR
0x106.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Support position independent execution
Vincent Chen [Wed, 17 Mar 2021 01:16:38 +0000 (09:16 +0800)]
firmware: Support position independent execution

Enable OpenSBI to support position independent execution. Because the
position independent code will cause an additional GOT reference when
accessing the global variables, it will reduce performance a bit. Therefore,
the position independent execution is disabled by default. Users can
through specifying "FW_PIC=y" on the make command to enable this feature.

In theory, after enabling position-independent execution, the OpenSBI
can run at arbitrary address with appropriate alignment. Therefore, the
original relocation mechanism will be skipped. In other words, OpenSBI will
directly run at the load address without any code movement.

Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Use lla to access all global symbols
Vincent Chen [Wed, 17 Mar 2021 01:16:37 +0000 (09:16 +0800)]
firmware: Use lla to access all global symbols

When OpenSBI is compiled as fPIE mode, the assembler will translate "la"
to GOT reference pattern. It will cause to cost an additional load
instruction when obtaining the symbol address. However, if the symbol
locates within the positive or negative 2GB region, we can use "lla"
instead of "la" to avoid unneeded GOT references. This patch assumes that
the OpenSBI image excluding the payload does not exceed 2GB. Based on
this assumption, all "la" instructions are replaced by "lla" to avoid
performance degradation when compiling as fPIE mode.

Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoinclude: sbi: SBI function IDs for RFENCE extension
Heinrich Schuchardt [Tue, 9 Mar 2021 11:31:22 +0000 (12:31 +0100)]
include: sbi: SBI function IDs for RFENCE extension

The SBI function IDs for RFENCE extension must match the SBI specification.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: Remove redundant sbi_platform_ipi_clear() calls
Anup Patel [Fri, 19 Feb 2021 04:24:05 +0000 (09:54 +0530)]
lib: Remove redundant sbi_platform_ipi_clear() calls

The sbi_platform_ipi_clear() called from wait_for_coldboot() and
sbi_hsm_hart_wait() is redundant because IPI will be automatically
cleared by sbi_platform_ipi_init() called from sbi_ipi_init().

Further, wait_for_coldboot() is common for warm startup and warm
resume path so the sbi_platform_ipi_clear() called in warm resume
path cause resuming HART to miss an IPI injected other HART to
wakeup the HART.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoinclude: sbi: Upgrade SBI implementation version to v0.3
Anup Patel [Fri, 12 Feb 2021 06:28:50 +0000 (11:58 +0530)]
include: sbi: Upgrade SBI implementation version to v0.3

The OpenSBI SBI implementation is now compliant with latest draft
SBI v0.3 specification so let's upgrade SBI implementation version.

This will also help HSM suspend function detection in S-mode because
HSM suspend function is only present when HSM extension is present
and SBI implementation version is 0.3 (or higher).

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Implement SBI HSM suspend function
Anup Patel [Sat, 6 Feb 2021 09:18:56 +0000 (14:48 +0530)]
lib: sbi: Implement SBI HSM suspend function

This patch implements the SBI HSM suspend function. Using this
new SBI call, the S-mode software can put calling HART in platform
specific suspend (i.e. low-power) state. For a successful retentive
suspend, the SBI call will return without errors upon resuming
whereas for a successful non-retentive suspend, the SBI call will
resume from a user provided resume address.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoinclude: sbi: Add hart_suspend() platform callback
Anup Patel [Fri, 5 Feb 2021 12:17:48 +0000 (17:47 +0530)]
include: sbi: Add hart_suspend() platform callback

We add hart_suspend() callback in platform operations which will
be used by HSM implementation to enter retentive or non-retentive
suspend state.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Add sbi_hart_reinit() function
Anup Patel [Fri, 5 Feb 2021 12:02:30 +0000 (17:32 +0530)]
lib: sbi: Add sbi_hart_reinit() function

We add sbi_hart_reinit() function which will re-initialize HART CSRs
assuming HART features are already detected. This new function will
be useful in re-initializing HART after it resumes from HSM SUSPENDED
state.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoinclude: sbi: Add HSM suspend related defines
Anup Patel [Mon, 1 Feb 2021 11:54:54 +0000 (17:24 +0530)]
include: sbi: Add HSM suspend related defines

This patch adds SBI HSM suspend related defines to ecall interface
header.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Fix error codes returned by HSM start() and stop() functions
Anup Patel [Wed, 24 Feb 2021 09:56:44 +0000 (15:26 +0530)]
lib: sbi: Fix error codes returned by HSM start() and stop() functions

The sbi_hsm_hart_start() and sbi_hsm_hart_stop() functions should
only return error codes as defined by the SBI specification.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Remove redundant sbi_hsm_hart_started() function
Anup Patel [Tue, 2 Feb 2021 05:06:14 +0000 (10:36 +0530)]
lib: sbi: Remove redundant sbi_hsm_hart_started() function

The sbi_hsm_hart_started() function is only used by sbi_hsm_hart_stop()
for checking state of calling HART and current domain assignment.

The atomic_cmpxchg() called by sbi_hsm_hart_stop() will check state of
calling hart anyway and domain assignment can be checked by other domain
function such as sbi_domain_is_assigned_hart().

This means sbi_hsm_hart_started() is redundant and can be removed.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Rename sbi_hsm_hart_started_mask() function
Anup Patel [Tue, 2 Feb 2021 04:21:54 +0000 (09:51 +0530)]
lib: sbi: Rename sbi_hsm_hart_started_mask() function

A hart can take interrupt in the new HSM states introduced by the
SBI HSM suspend function (such as SUSPENDED state) so we rename
sbi_hsm_hart_started_mask() to something more generic such as
sbi_hsm_hart_interruptible_mask().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Use SBI_HSM_STATE_xyz defines instead of SBI_STATE_xyz defines
Anup Patel [Mon, 1 Feb 2021 10:43:03 +0000 (16:13 +0530)]
lib: sbi: Use SBI_HSM_STATE_xyz defines instead of SBI_STATE_xyz defines

We replace the use of SBI_STATE_xyz defines with SBI_HSM_STATE_xyz
defines because the HSM state defines are complete enough to implement
HSM state machine in OpenSBI. As a result of this, we can now remove
sbi_hsm_hart_state_to_status() function because it is now redundant
and sbi_hsm_hart_get_state() can directly return HSM state or error.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoinclude: sbi: Simplify HSM state define names
Anup Patel [Mon, 1 Feb 2021 04:42:47 +0000 (10:12 +0530)]
include: sbi: Simplify HSM state define names

We simplify HSM state define names so that these defines can directly
replace SBI_HART_xyz defines used by SBI HSM implementation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoplatform: implement K210 system reset
Heinrich Schuchardt [Fri, 26 Feb 2021 09:25:10 +0000 (09:25 +0000)]
platform: implement K210 system reset

Implement rebooting the K210 via the system reset extension.

All reset types are treated in the same way.
A request for shutdown results in a reboot.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoinclude: Bump-up version to 0.9
Anup Patel [Mon, 18 Jan 2021 13:17:19 +0000 (18:47 +0530)]
include: Bump-up version to 0.9

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

Signed-off-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: template: Fix compile error
Anup Patel [Mon, 18 Jan 2021 03:59:33 +0000 (09:29 +0530)]
platform: template: Fix compile error

This clint driver init functions were incorrectly used in
template platform which resulted in compile error. This patch
fixes clint driver function usage in template platform.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoinclude: sbi: Don't pack struct sbi_platform and sbi_platform_operations
Anup Patel [Mon, 11 Jan 2021 11:45:00 +0000 (17:15 +0530)]
include: sbi: Don't pack struct sbi_platform and sbi_platform_operations

We don't need to pack struct sbi_platform and sbi_platform_operations
because GCC ensures member offsets match member data type irrespective
to the target system (RV32 or RV64). This also allows GCC to generate
more optimized instruction sequence when accessing members of struct
sbi_platform and struct sbi_platform_operations.

Reported-by: Paul Campbell <taniwha@gmail.com>
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>
3 years agoinclude: sbi: No need to pack struct sbi_scratch
Anup Patel [Mon, 11 Jan 2021 11:15:14 +0000 (16:45 +0530)]
include: sbi: No need to pack struct sbi_scratch

All members in struct sbi_scrach are of machine word size so no need
to pack this structure. This also allows GCC to generate more optimized
instruction sequence when accessing members of struct sbi_scratch.

Reported-by: Paul Campbell <taniwha@gmail.com>
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>
3 years agoinclude: sbi: No need to pack struct sbi_trap_regs
Anup Patel [Mon, 11 Jan 2021 10:55:38 +0000 (16:25 +0530)]
include: sbi: No need to pack struct sbi_trap_regs

All members in struct sbi_trap_regs are of machine word size so
no need to pack this structure. This also allows GCC to generate
more optimized instruction sequence when accessing members of
struct sbi_trap_regs.

Reported-by: Paul Campbell <taniwha@gmail.com>
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>
3 years agolib: sbi: Allow platforms to provide root domain memory regions
Anup Patel [Fri, 8 Jan 2021 04:37:01 +0000 (10:07 +0530)]
lib: sbi: Allow platforms to provide root domain memory regions

Currently, the root domain memory regions are fixed in generic
code but some of the platforms may want to explicitly define
memory regions for the root domain.

This patch adds optional domains_root_regions() platform callback
which platforms can use to provide platform specific root domain
memory regions. Due to this changes, the root domain should also
undergo all sanity checks (just like regular domain) so we use
sbi_domain_register() to register root domain.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils: Fix shakti uart implementation
Vijai Kumar K [Mon, 7 Dec 2020 16:54:16 +0000 (22:24 +0530)]
lib: utils: Fix shakti uart implementation

Fix uart_putc implementation.
Due to a bug in the IP, this went unnoticed.
Use macros instead of magic numbers to make the code
more readable.

Signed-off-by: Vijai Kumar K <vijai@behindbytes.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Allow custom local TLB flush function
Anup Patel [Tue, 29 Dec 2020 08:21:06 +0000 (13:51 +0530)]
lib: sbi: Allow custom local TLB flush function

Currently, we have fixed TLB flush types supported by the
remote TLB library. This approach is not flexible and does
not allow custom local TLB flush function. For example,
after updating PMP entries on a set of HARTs at runtime,
we have to flush TLB on these HARTs as well.

To support custom local TLB flush function, we replace the
"type" field of "struct sbi_tlb_info" with a local TLB flush
function pointer. We also provide definitions of standard TLB
flush operations (such as fence_i, sfence.vma, hfence.vvma,
hfence.gvma, etc).

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Introduce sbi_trap_exit() API
Anup Patel [Tue, 29 Dec 2020 06:09:22 +0000 (11:39 +0530)]
lib: sbi: Introduce sbi_trap_exit() API

We introduce sbi_trap_exit() API which can help non-firmware
(i.e. generic or platform) code to force exit trap/interrupt
handling and resume execution at context pointed by parameter
"const struct sbi_trap_regs *regs".

This new sbi_trap_exit() API will help Keystone Enclave project
to resume execution of enclave from custom SBI call handler.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Replace args with trap registers in ecall handler
Anup Patel [Mon, 28 Dec 2020 12:55:18 +0000 (18:25 +0530)]
lib: sbi: Replace args with trap registers in ecall handler

We had added args pointer in ecall handler to ensure that ecall
handler only implements functionality and does not deal with
SBI calling convention. This also helped us to keep SBI calling
convention related code in one place at sbi_ecall_handler().

The Keystone Enclavce project needs access to the trap regsiters
in their ecall handler so that they can context switch enclaves
in custom SBI calls. To help the Keystone Enclave project, we
replace the args pointer in ecall handler parameter with a const
pointer to trap registers.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Fix sign-extension in sbi_misaligned_load_handler()
Anup Patel [Sat, 19 Dec 2020 12:09:57 +0000 (17:39 +0530)]
lib: sbi: Fix sign-extension in sbi_misaligned_load_handler()

The misaligned load emulation does not sign-extend values correctly
due to missing sign typecast in value passed to the SET_RD() macro.

A very easy way to reproduce this issue is to load 16-bit value
0xff1e from a byte aligned address using LH instruction on hardware
lacking misaligned load/store.

This patch fixes sbi_misaligned_load_handler() for above issue.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Remove domain_get() platform callback function
Anup Patel [Sun, 13 Dec 2020 10:14:22 +0000 (15:44 +0530)]
lib: sbi: Remove domain_get() platform callback function

The domain_get() platform callback function is now redundant
because fdt_domain_populate() register new domain explicitly
using the sbi_domain_register() function.

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>
3 years agolib: utils: Remove fdt_domain_get() function
Anup Patel [Sun, 13 Dec 2020 10:07:34 +0000 (15:37 +0530)]
lib: utils: Remove fdt_domain_get() function

The fdt_domain_get() function is now redundant because the
fdt_domains_populate() function can explicitly register new
domains using the sbi_domain_register() function.

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>
3 years agolib: sbi: Add function to register new domain
Anup Patel [Sun, 13 Dec 2020 09:39:42 +0000 (15:09 +0530)]
lib: sbi: Add function to register new domain

We add sbi_domain_register() function to help platform code register
a new domain explicitly instead of depending on domain_get() platform
callback. This function will eventually help us completely remove the
domain_get() platform callback.

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>
3 years agolib: utils: Allow FDT domain iteration functions to fail
Anup Patel [Sun, 13 Dec 2020 05:53:05 +0000 (11:23 +0530)]
lib: utils: Allow FDT domain iteration functions to fail

We extend fdt_iterate_each_domain() and fdt_iterate_each_memregion()
functions to allow underlying iteration function to fail. This will
help us catch more domain misconfiguration issues at boot time.

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>
3 years agolib: utils/libfdt: Upgrade to v1.6.0 release
Dimitri John Ledkov [Thu, 10 Dec 2020 11:03:57 +0000 (11:03 +0000)]
lib: utils/libfdt: Upgrade to v1.6.0 release

Sync with libfdt v1.6.0 release source codes.

Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: generic: Populate domains from FDT
Anup Patel [Thu, 19 Nov 2020 06:55:31 +0000 (12:25 +0530)]
platform: generic: Populate domains from FDT

The generic platform should populate domains from FDT using the
domain FDT helper routines.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils: Add helper routines to populate domains from FDT
Anup Patel [Wed, 18 Nov 2020 11:10:21 +0000 (16:40 +0530)]
lib: utils: Add helper routines to populate domains from FDT

We add various helper routines to populate domains, iterate domains,
iterate domain memregions, and parse HART to domain assignment from
the FDT.

These helper routines can be used by platform support code and FDT
fixup code.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agodocs: Add domain device tree binding documentation
Anup Patel [Sun, 15 Nov 2020 10:07:21 +0000 (15:37 +0530)]
docs: Add domain device tree binding documentation

This patch adds domain device tree binding documentation in the
OpenSBI domain support documentation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoinclude: sbi: Add domains_init() platform operation
Anup Patel [Fri, 20 Nov 2020 11:12:15 +0000 (16:42 +0530)]
include: sbi: Add domains_init() platform operation

We introduce domains_init() platform operation which can be used by
platform support to initialize/populate domains in the coldboot path.

The domains_init() is called late in the coldboot sequence from the
sbi_domain_finalize() so sbi_printf() can be used by platform support
to print errors/warnings at time of populating domains.

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>
3 years agolib: sbi: Add error prints in sbi_domain_finalize()
Anup Patel [Sun, 15 Nov 2020 09:41:21 +0000 (15:11 +0530)]
lib: sbi: Add error prints in sbi_domain_finalize()

We add error prints in sbi_domain_finalize() and sanitize_domain()
to help debug domain configuration issues.

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>
3 years agolib: sbi: Override domain boot HART when coldboot HART assigned to it
Anup Patel [Sun, 15 Nov 2020 08:00:29 +0000 (13:30 +0530)]
lib: sbi: Override domain boot HART when coldboot HART assigned to it

If coldboot HART is assigned to a domain then we should use coldboot
HART as the boot HART of the domain. This allows coldboot HART to
continue boot sequence even when it is assigned to some non-root domain.

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>
3 years agoinclude: sbi: Use lower bits for domain memory region permissions
Anup Patel [Sun, 15 Nov 2020 06:16:20 +0000 (11:46 +0530)]
include: sbi: Use lower bits for domain memory region permissions

We should use lower bits for domain memory region access permissions
and higher bits for other domain memory region attributes. This helps
us use same bit assignment for parsing domain memory region access
permissions from device tree.

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>
3 years agolib: sbi: Auto start domain only if boot HART within limits
Anup Patel [Wed, 11 Nov 2020 05:13:11 +0000 (10:43 +0530)]
lib: sbi: Auto start domain only if boot HART within limits

The sbi_domain_finalize() should auto start a domain only if the
boot HART is withing limits (i.e. less than SBI_HARTMASK_MAX_BITS).

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>
3 years agolib: sbi: Fix domain_count check in sbi_domain_finalize()
Anup Patel [Fri, 20 Nov 2020 04:47:38 +0000 (10:17 +0530)]
lib: sbi: Fix domain_count check in sbi_domain_finalize()

The domain_count check in sbi_domain_finalize() for newly discovered
domain is incorrect and should be reversed.

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>
3 years agolib: sbi: Fix typo in sbi_domain_finalize()
Anup Patel [Wed, 11 Nov 2020 04:01:39 +0000 (09:31 +0530)]
lib: sbi: Fix typo in sbi_domain_finalize()

There has been typo in automatic domain boot hart startup
for non-root domains so this patch fixes it.

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>