platform/kernel/opensbi-spacemit.git
3 years agolib: sbi: Refine addr format in sbi_printf
Dong Du [Mon, 25 Oct 2021 08:06:15 +0000 (16:06 +0800)]
lib: sbi: Refine addr format in sbi_printf

Although we have PRILX to help us print unsigned long without
considering the 32bit/64bit differences, there are still some
places using 08lx and 016lx manually --- leading to redundant code.

This commit fixes the issue by using PRILX all the time.

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils/reset: Register separate GPIO system reset devices
Anup Patel [Thu, 21 Oct 2021 05:41:34 +0000 (11:11 +0530)]
lib: utils/reset: Register separate GPIO system reset devices

Now that sbi_system support multiple system reset devices, we should
register separate devices for GPIO restart and GPIO poweroff because
DT describes these as separate devices with different compatible
strings.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
3 years agolib: utils/irqchip: Automatically delegate T-HEAD PLIC access
Samuel Holland [Mon, 18 Oct 2021 05:33:50 +0000 (00:33 -0500)]
lib: utils/irqchip: Automatically delegate T-HEAD PLIC access

The T-HEAD PLIC implementation requires setting a delegation bit
to allow access from S-mode. Now that the T-HEAD PLIC has its own
compatible string, set this bit automatically from the PLIC driver,
instead of reaching into the PLIC's MMIO space from another driver.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoMakefile: Add build time and compiler info string
Wei Fu [Thu, 30 Sep 2021 10:11:20 +0000 (18:11 +0800)]
Makefile: Add build time and compiler info string

When we are doing opensbi development, we want to know the build time
and compiler info for debug purpose.

To enable this message, please add "BUILD_INFO=y", like:

```
make BUILD_INFO=y
```

NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will
violate "reproducible builds". So it's ONLY for development and debug
purpose, and should NOT be used in a product which follows "reproducible
builds".

Signed-off-by: Wei Fu <wefu@redhat.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
3 years agolib: sbi: system reset with invalid parameters
Heinrich Schuchardt [Fri, 15 Oct 2021 13:42:21 +0000 (15:42 +0200)]
lib: sbi: system reset with invalid parameters

The SBI specification requires that sbi_system_reset() returns
SBI_ERR_INVALID_PARAM if reset_type or reset_reason are not valid.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sbi: Save context for all non-retentive suspend types
Anup Patel [Mon, 11 Oct 2021 05:31:09 +0000 (11:01 +0530)]
lib: sbi: Save context for all non-retentive suspend types

Instead of saving context only for default non-retentive suspend,
we should save context for all non-retentive suspend types.

Fixes: 74756891cc35 ("lib: sbi: Implement SBI HSM suspend function")
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sbi: add priority for reset handler
Nikita Shubin [Fri, 1 Oct 2021 08:31:17 +0000 (11:31 +0300)]
lib: sbi: add priority for reset handler

Let's make system_reset_check returning priority instead of only
true/false. In that case 0 - means not supported, and anything above
means priority that makes existing reset handlers being used in first
place, unless it is decided to lower their priority.

The handler with the most priority wins.

Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: convert reset to list
Nikita Shubin [Fri, 1 Oct 2021 08:31:16 +0000 (11:31 +0300)]
lib: sbi: convert reset to list

To support different handlers for different types of resets, we are
adding a sbi_list of restart handlers.

Instead of sbi_system_reset_set_device we use
sbi_system_reset_add_device to reflect the actual meaning.

Signed-off-by: Nikita Shubin <n.shubin@yadro.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils: identify supported GPIO reset methods
Heinrich Schuchardt [Tue, 28 Sep 2021 11:42:46 +0000 (13:42 +0200)]
lib: utils: identify supported GPIO reset methods

The GPIO reset driver supports reset and poweroff. But not all boards
support both. gpio_system_reset_check() must detect this situation.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils/reset: use sbi_timer_mdelay() in gpio reset driver
Anup Patel [Wed, 15 Sep 2021 08:20:40 +0000 (13:50 +0530)]
lib: utils/reset: use sbi_timer_mdelay() in gpio reset driver

We should use sbi_timer_mdelay() instead of custom gpio_mdelay() in
the gpio reset driver.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sbi: Add generic timer delay loop function
Anup Patel [Wed, 15 Sep 2021 04:41:24 +0000 (10:11 +0530)]
lib: sbi: Add generic timer delay loop function

We now have frequency of the timer device provided by the platform
support so we can emulate desired delay using a loop where the number
loop iterations are based on timer frequency.

This patch provides sbi_timer_delay_loop() for above purpose.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sbi: Print timer frequency at boot time
Anup Patel [Wed, 15 Sep 2021 03:21:42 +0000 (08:51 +0530)]
lib: sbi: Print timer frequency at boot time

We now have frequency in timer device instance provided by platform
so let's print timer frequency as part of the boot prints.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sbi: Add timer frequency to struct sbi_timer_device
Anup Patel [Tue, 14 Sep 2021 16:21:48 +0000 (21:51 +0530)]
lib: sbi: Add timer frequency to struct sbi_timer_device

Generic mdelay() and udelay() functions can be provided by the
sbi_timer framework if timer frequency is available in the timer
instance provided by the platform support or timer driver.

This patch adds timer frequency (timer_freq) member in the
struct sbi_timer_device for above purpose.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils/fdt: Add fdt_parse_timebase_frequency() function
Anup Patel [Tue, 14 Sep 2021 15:35:42 +0000 (21:05 +0530)]
lib: utils/fdt: Add fdt_parse_timebase_frequency() function

We add fdt_parse_timebase_frequency() function which can be used
by ACLINT mtimer driver and platform code to get timebase frequency.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: sbi: Add BUG() macro for csr_read/write_num() and misa_string()
Xiang W [Thu, 16 Sep 2021 04:32:50 +0000 (12:32 +0800)]
lib: sbi: Add BUG() macro for csr_read/write_num() and misa_string()

We use BUG() macro in csr_read_num(), csr_write_num(), and
misa_string() functions for unhandled cases.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: add some macros to detect BUG at runtime
Xiang W [Thu, 16 Sep 2021 04:32:49 +0000 (12:32 +0800)]
lib: sbi: add some macros to detect BUG at runtime

Three macros are added. One is called BUG, which is used to put in an
unreachable branch. One is called BUG_ON, which is used to check bugs
and assert conditions are opposite. One is called SBI_ASSERT, used for
assertion checking.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: fix ctz bug
Xiang W [Wed, 15 Sep 2021 06:50:52 +0000 (14:50 +0800)]
lib: sbi: fix ctz bug

The original version of ctz will cause an endless loop, if the parameter
passed in is 0. This commit fixes this bug.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils/reset: Add a sunxi watchdog reset driver
Samuel Holland [Thu, 9 Sep 2021 02:10:09 +0000 (21:10 -0500)]
lib: utils/reset: Add a sunxi watchdog reset driver

One of the watchdogs in the D1 SoC provides a "soft reset" function,
which allows software to immediately reset the entire SoC. Add a driver
so it can implement the SBI system reset function.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils/reset: Sort fdt_reset driver list
Samuel Holland [Thu, 9 Sep 2021 02:10:08 +0000 (21:10 -0500)]
lib: utils/reset: Sort fdt_reset driver list

In preparation for adding a new fdt_reset driver, ensure the existing
lists are sorted alphabetically.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Refine the way to construct platform features
Dong Du [Wed, 1 Sep 2021 03:06:24 +0000 (11:06 +0800)]
lib: sbi: Refine the way to construct platform features

sbi_platform_get_features_str() uses sbi_snprintf() to construct the
features_str. However, it passes the wrong length value (i.e., the nfstr),
which should be (nfstr-offset) as the starting point of str (i.e.,
features_str + offset) changes.

This commit also checks the return value of snprintf, and handles the
corner case that the string buffer is full.

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Checking fifo validness in sbi_fifo_is_empty and is_full
Dong Du [Fri, 27 Aug 2021 14:46:28 +0000 (22:46 +0800)]
lib: sbi: Checking fifo validness in sbi_fifo_is_empty and is_full

As other exported fifo functions, we should check whether the fifo is
valid in sbi_fifo_is_empty and sbi_fifo_is_full. To this end, this patch
changes the retval from bool to int, and the two functions will return
SBI_EINVAL in the case the fifo is invalid.

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: protect dprintf output with spinlock
Dong Du [Sat, 28 Aug 2021 06:45:02 +0000 (14:45 +0800)]
lib: sbi: protect dprintf output with spinlock

Avoid getting messages from multiple harts (using dprintf and printf)
concurrently with a spinlock serializaing calls to sbi_dprintf(),
sbi_printf() and sbi_puts()

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Correct typo in faults delegation CSR name
Rahul Pathak [Thu, 26 Aug 2021 09:54:18 +0000 (15:24 +0530)]
lib: sbi: Correct typo in faults delegation CSR name

Correcting the name of faults delegation CSR
%s/mfdeleg/medeleg

Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agopayloads/test: Add support for SBI v0.2 ecalls
Samuel Holland [Sat, 14 Aug 2021 13:52:10 +0000 (08:52 -0500)]
payloads/test: Add support for SBI v0.2 ecalls

It can be useful to make SBI v0.2 or newer ecalls from this payload
for testing purposes. To support this, convert the macros to use the
extension/function parameter convention.

Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi_trap: Restore redirect for access faults
Samuel Holland [Sat, 14 Aug 2021 13:41:47 +0000 (08:41 -0500)]
lib: sbi_trap: Restore redirect for access faults

commit 764a17d852a8 ("lib: sbi: Implement firmware counters") added
switch cases for CAUSE_LOAD_ACCESS and CAUSE_STORE_ACCESS. This caused
them to stop being redirected to U or S mode, as that is handled in the
default switch case. As a result, an error in userspace could cause the
system to hang. Fix this by allowing the acces fault case to fall
through to the default case.

Fixes: 764a17d852a8 ("lib: sbi: Implement firmware counters")
Signed-off-by: Samuel Holland <samuel@sholland.org>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
3 years agolib: sbi: Fix bug in sbi_ecall_rfence that misses checking
Dong Du [Fri, 13 Aug 2021 12:33:00 +0000 (20:33 +0800)]
lib: sbi: Fix bug in sbi_ecall_rfence that misses checking

In sbi_ecall_rfence_handler, it will compare the funcid with
REMOTE_HFENCE_GVMA and REMOTE_HFENCE_VVMA_ASID. Later it check
whether the misa includes H-extension. This checking is incomplete
which misses REMOTE_HFENCE_GVMA_VMID and REMOTE_HFENCE_VVMA.

Fix the issue by updating the checking range.

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/timer: Simplify MTIMER synchronization
Anup Patel [Sat, 24 Jul 2021 05:05:01 +0000 (10:35 +0530)]
lib: utils/timer: Simplify MTIMER synchronization

We simplify MTIMER synchronization as follows:

1) Detect MTIMER devices with unique (or non-shared) MTIME
   register at boot-time
2) Select first MTIMER device with no associated HART as our
   reference MTIMER device
3) Only synchronize MTIMER devices with unique (or non-shared)
   MTIME register using reference MTIMER device
4) Directly update the MTIME register at time of synchronization
   because MTIME is a read/write register.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/timer: Allow ACLINT MTIMER supporting only 32-bit MMIO
Anup Patel [Sat, 24 Jul 2021 04:59:56 +0000 (10:29 +0530)]
lib: utils/timer: Allow ACLINT MTIMER supporting only 32-bit MMIO

We can have ACLINT MTIMER devices which only support 32-bit MMIO
accesses on RV64 system so this patch adds a boolean DT property
"mtimer,no-64bit-mmio" to detect this from MTIMER DT node.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/fdt: Extend fdt_parse_aclint_node() function
Anup Patel [Fri, 23 Jul 2021 10:07:51 +0000 (15:37 +0530)]
lib: utils/fdt: Extend fdt_parse_aclint_node() function

The fdt_parse_aclint_node() is used to parse DT node for SiFive
CLINT, ACLINT MTIMER, and ACLINT MSWI devices.

The ACLINT MTIMER has undergone following changes:
1) MTIMER DT node now requires separate addresses in for MTIME
   register and MTIMECMPx registers in the reg DT property.
2) MTIMER DT node might have no interrupts-extended DT property
   when the MTIMER device has no associated HARTs (i.e. the
   MTIMER device has no MTIMECMPx registers)

This patch extends fdt_parse_aclint_node() to handle above
mentioned changes in ACLINT MTIMER DT bindings.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils: Extend fdt_get_node_addr_size() for multiple register sets
Anup Patel [Wed, 21 Apr 2021 08:41:55 +0000 (14:11 +0530)]
lib: utils: Extend fdt_get_node_addr_size() for multiple register sets

We add "index" parameter to fdt_get_node_addr_size() API so that
calling function can specify index of desired register set. This
will allow fdt_get_node_addr_size() to handle DT nodes with
multiple register sets.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/timer: Allow separate base addresses for MTIME and MTIMECMP
Anup Patel [Fri, 23 Jul 2021 08:39:43 +0000 (14:09 +0530)]
lib: utils/timer: Allow separate base addresses for MTIME and MTIMECMP

We extend the ACLINT library to support separate base addresses
for MTIME and MTIMECMP registers.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/fdt: Change addr and size to uint64_t
Bin Meng [Thu, 5 Aug 2021 07:41:13 +0000 (15:41 +0800)]
lib: utils/fdt: Change addr and size to uint64_t

The maximum address and size encoded in DT are 64-bit numbers, so we
should use uint64_t for 'addr' and 'size' in fdt_get_node_addr_size().

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Fix bug in strncmp function when count is 0
Dong Du [Wed, 28 Jul 2021 16:15:35 +0000 (00:15 +0800)]
lib: sbi: Fix bug in strncmp function when count is 0

No need to compare characters when the count turns to 0.
Fix the issue in sbi_strncmp.

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils: support both of gpio-poweroff, gpio-reset
Heinrich Schuchardt [Thu, 22 Jul 2021 10:53:59 +0000 (12:53 +0200)]
lib: utils: support both of gpio-poweroff, gpio-reset

The generic GPIO reset driver has two entries in the match table:
"gpio-poweroff", "gpio-reset". Only the first entry is considered by
fdt_reset_init().

Define "gpio-poweroff" and "gpio-reset" as compatibility strings of two
separate reset drivers. They still can share code.

Fixes: e3d6919d10d7 ("lib: utils/reset: Add generic GPIO reset driver")
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils: remove unused variable in fdt_reset_init
Heinrich Schuchardt [Thu, 22 Jul 2021 10:53:58 +0000 (12:53 +0200)]
lib: utils: remove unused variable in fdt_reset_init

The value of variable current_driver is unused. Remove the variable.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agogeneric: fu740: add workaround for CIP-1200 errata
David Abdurachmanov [Tue, 20 Jul 2021 17:02:39 +0000 (19:02 +0200)]
generic: fu740: add workaround for CIP-1200 errata

Instruction TLB can fail to respect a non-global SFENCE thus we need to
flush the TLB using SFENCE.VMA x0, x0

See full description of CIP-1200 in Errata_FU740-C000_20210205 from
https://www.sifive.com/boards/hifive-unmatched

Signed-off-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
3 years agofirmware: use _fw_start for load address
Xiang W [Wed, 14 Jul 2021 07:14:39 +0000 (15:14 +0800)]
firmware: use _fw_start for load address

The previous code uses _start as the load address, this default .entry is
the first segment, using _fw_start does not need to make this assumption.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoMakefile: Manually forward RELAX_FLAG to the assembler when linking with LLD
Bin Meng [Mon, 12 Jul 2021 02:12:53 +0000 (10:12 +0800)]
Makefile: Manually forward RELAX_FLAG to the assembler when linking with LLD

When generating code with -mno-relax, GCC puts .option norelax in
the generated assembly, and so doesn’t bother passing on -mno-relax
to the assembler. This has the unfortunate effect that, when using
GCC to assemble hand-written assembly, -mno-relax does nothing,
and we have to pass -Wa,-mno-relax to manually forward it to the
assembler.

This is an old GCC bug that was fixed [1] recently. For the time
being, let's pass "-Wa,-mno-relax" to ASFLAGS for the GCC + LLD
combination to work, e.g.:

  $ make CC=riscv64-unknown-elf-gcc LLVM=1 PLATFORM=generic

[1] https://github.com/gcc-mirror/gcc/commit/3b0a7d624e64eeb81e4d5e8c62c46d86ef521857

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoREADME: Update toolchain information
Bin Meng [Mon, 12 Jul 2021 01:20:16 +0000 (09:20 +0800)]
README: Update toolchain information

Recent FW_PIC=y changes actually require toolchains with PIE support
and it is on by default. Existing doc uses a GNU bare-metal toolchain
as examples but it does not support PIE.

Replace references of bare-metal toolchain prefix with Linux toolchain
prefix everywhere in documentation.

Also indicate that "riscv64-unknown-freebsd-" as an alternative to
"riscv64-linux-" GNU toolchain.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs: Document FW_PIC compile time option
Bin Meng [Mon, 12 Jul 2021 00:48:02 +0000 (08:48 +0800)]
docs: Document FW_PIC compile time option

FW_PIC=y is on by default, but the doc is missing when this was
introduced. Add some description for it.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs: Document parameters passed to firmware and alignment requirement
Bin Meng [Sat, 10 Jul 2021 14:28:21 +0000 (22:28 +0800)]
docs: Document parameters passed to firmware and alignment requirement

This updates documentation to describe parameters passed to firmware
from previous booting stage, and corresponding address alignment
requirement.

This also fixes a typo in fw_dynamic.md (it's => its).

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Remove the unhelpful alignment codes before fdt relocation
Bin Meng [Sat, 10 Jul 2021 14:28:20 +0000 (22:28 +0800)]
firmware: Remove the unhelpful alignment codes before fdt relocation

If the device tree is at an address that is not __SIZEOF_POINTER__
aligned, the fdt relocation code tries to align both source and
destination address to __SIZEOF_POINTER__ before the memory copy.
But such alignment can lead to unexpected results if either source
or destination address is not aligned.

In fact libfdt requires that the device tree must be at an 8-byte
aligned address. Hence remove the unhelpful alignment codes.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoinclude: types: Use __builtin_offsetof when supported
Alex Richardson [Mon, 12 Jul 2021 12:39:59 +0000 (13:39 +0100)]
include: types: Use __builtin_offsetof when supported

Clang provides a __builtin_offsetof which can be detected using
__has_builtin().

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: use __SIZEOF_LONG__ for field offsets in fw_dynamic.h
Alex Richardson [Mon, 12 Jul 2021 09:24:05 +0000 (10:24 +0100)]
firmware: use __SIZEOF_LONG__ for field offsets in fw_dynamic.h

The fields are of type unsigned long and are not pointers. While this
happens to be the same for RV32/RV64, it is not correct when compiling
for a CHERI-RISC-V system where pointers are twice the size of long.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils/reset: Add generic GPIO reset driver
Green Wan [Tue, 13 Jul 2021 03:23:45 +0000 (11:23 +0800)]
lib: utils/reset: Add generic GPIO reset driver

We add generic GPIO reset driver inspired from gpio-restart
and gpio-poweroff drivers of Linux kernel.

Signed-off-by: Green Wan <green.wan@sifive.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/gpio: Add minimal SiFive GPIO driver
Green Wan [Tue, 13 Jul 2021 03:23:44 +0000 (11:23 +0800)]
lib: utils/gpio: Add minimal SiFive GPIO driver

We add a minimal SiFive GPIO driver so that we can do GPIO based
system power-off and reset.

Signed-off-by: Green Wan <green.wan@sifive.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/gpio: Add simple FDT based GPIO framework
Anup Patel [Tue, 13 Jul 2021 03:23:43 +0000 (11:23 +0800)]
lib: utils/gpio: Add simple FDT based GPIO framework

We add a simple FDT based GPIO framework which is built on top
of generic GPIO library. The phandle of FDT GPIO chip DT node
is treated as unique GPIO chip ID required by the generic GPIO
library. The FDT based GPIO chip drivers will be probed on-demand
from fdt_gpio_pin_get() called by the GPIO client drivers.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/gpio: Add generic GPIO configuration library
Anup Patel [Tue, 13 Jul 2021 03:23:42 +0000 (11:23 +0800)]
lib: utils/gpio: Add generic GPIO configuration library

We add generic GPIO configuration library which is independent of
hardware description format (FDT or ACPI). The OpenSBI platform
support or GPIO drivers can register GPIO chip instances which
can be discovered and used by different GPIO clients. Each GPIO
chip instance has a unique ID which can be used by GPIO clients
to lookup GPIO chip instance.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils/fdt: Add fdt_parse_phandle_with_args() API
Anup Patel [Tue, 13 Jul 2021 03:23:41 +0000 (11:23 +0800)]
lib: utils/fdt: Add fdt_parse_phandle_with_args() API

The libfdt project does not have a generic API to parse phandle
with args from a DT node so we add fdt_parse_phandle_with_args()
for this purpose. This new API will be useful to FDT based drivers.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: utils: Drop dependency on libgcc by importing part of FreeBSD's libquad
Jessica Clarke [Sun, 11 Jul 2021 02:28:24 +0000 (03:28 +0100)]
lib: utils: Drop dependency on libgcc by importing part of FreeBSD's libquad

We only need libgcc for 64-bit division on RV32. Whilst GCC toolchains
bundle libgcc, Clang toolchains tend not to ship libclang_rt.builtins
given every compiler is a cross-compiler for every target and so you
would need a silly number of builds of it, with only the native library
available; only vendor-provided Clang toolchains specifically for bare
metal cross-compiling are likely to provide it.

Thus, import part of FreeBSD's implementation of the division support
functions needed and stop linking against libgcc.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Tested-by: Anup Patel <anup.patel@wdc.com>
3 years agoMakefile: Support building with Clang and LLVM binutils
Jessica Clarke [Sun, 11 Jul 2021 02:28:23 +0000 (03:28 +0100)]
Makefile: Support building with Clang and LLVM binutils

This is intended to mirror the Linux kernel. Building with CC=clang will
use Clang as the compiler but default to using the existing binutils.
Building with LLVM=1 will default to using Clang and LLVM binutils.

Whilst GCC will accept the -N linker option and forward it on to the
linker, Clang will not, and so in order to support both compilers we
must use -Wl, to forward it to the linker as is required for most other
linker options.

Note that there is currently a bug when using Clang as the compiler and
riscv64-linux-gnu-ld as the linker for FW_PIC=y. At first glance this
appears to be a bug in GNU binutils, but this could also be Clang or
OpenSBI at fault in some subtle way. Thus, for now, advise that this
combination be avoided.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Tested-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Only default FW_PIC to y if supported
Jessica Clarke [Sun, 11 Jul 2021 02:28:22 +0000 (03:28 +0100)]
firmware: Only default FW_PIC to y if supported

Bare-metal GNU ld does not support PIE, so if using it this will result
in a failure to build. Instead, default to FW_PIC=n if not supported.
Note that an explicit FW_PIC=y is not overridden, to ensure the build
fails rather than silently producing a position-dependent binary.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Explicitly pass -pie to the linker, not just the driver
Jessica Clarke [Sun, 11 Jul 2021 02:28:21 +0000 (03:28 +0100)]
firmware: Explicitly pass -pie to the linker, not just the driver

When using Clang with a bare-metal triple, -pie does not get passed to
the linker as it's not normally a thing that makes sense, unlike GCC
which will unconditionally forward it on and potentially result in a
linker error. However, LLD does support it, and manually forwarding it
on works as desired, so do so to fully support FW_PIC with Clang and
LLD.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofw_base: Put data in .data rather than .text
Jessica Clarke [Sun, 11 Jul 2021 02:28:20 +0000 (03:28 +0100)]
fw_base: Put data in .data rather than .text

The -N linker option is supposed to make .text writable, but GNU ld and
LLD differ in interpreting what that means. GNU ld will happily let you
have relocations in it, but LLD will see that the input section is
read-only (even though the output section is writable) and give an
error. It's unclear if either of them intend to have that behaviour in
this edge case, but regardless there's no reason not to just put the
data in a writable .data section.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofw_base: Don't mark fw_platform_init as both global and weak
Jessica Clarke [Sun, 11 Jul 2021 02:28:19 +0000 (03:28 +0100)]
fw_base: Don't mark fw_platform_init as both global and weak

These are mutually exclusive. GNU as and LLVM both let later binding
directives override earlier ones so this works as intended, but LLVM 12
turned this into a warning as there's no good reason to do such a thing
and could be a potential bug. Thus, remove the redundant and incorrect
.globl directive for fw_platform_init.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: sbi: Fix sbi_pmu_exit() for systems not having MCOUNTINHIBIT csr
Anup Patel [Sun, 11 Jul 2021 08:58:19 +0000 (14:28 +0530)]
lib: sbi: Fix sbi_pmu_exit() for systems not having MCOUNTINHIBIT csr

The sbi_pmu_exit() crashes on systems not having MCOUNTINHIBIT csr
so to fix this we check SBI_HART_HAS_MCOUNTINHIBIT feature in
sbi_pmu_exit() and do nothing if it is not available.

Fixes: 13d40f21d588 ("lib: sbi: Add PMU support")
Signed-off-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Define a macro for version of struct fw_dynamic_info
Bin Meng [Wed, 7 Jul 2021 08:22:41 +0000 (16:22 +0800)]
firmware: Define a macro for version of struct fw_dynamic_info

Avoid using a magic number, instead use a macro for the version of
struct fw_dynamic_info.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Remove the sanity checks in fw_save_info()
Bin Meng [Wed, 7 Jul 2021 10:00:21 +0000 (18:00 +0800)]
firmware: Remove the sanity checks in fw_save_info()

The sanity checks on the magic and version was already done in
fw_boot_hart(), which happens before fw_save_info() is called.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs: Make <xyz> visible in the rendered platform guide
Bin Meng [Thu, 8 Jul 2021 11:07:29 +0000 (19:07 +0800)]
docs: Make <xyz> visible in the rendered platform guide

At present in the rendered platform guide, all instances of <xyz>
are missing. Use &lt; and &gt; to replace <> to make them visible.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs: Correct a typo in platform_guide.md
Bin Meng [Thu, 8 Jul 2021 11:07:28 +0000 (19:07 +0800)]
docs: Correct a typo in platform_guide.md

It's riscv-pk, not riskv-pk.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agofirmware: Minor optimization in _scratch_init()
Bin Meng [Sat, 10 Jul 2021 14:00:31 +0000 (22:00 +0800)]
firmware: Minor optimization in _scratch_init()

Before entering _scratch_init(), register t3 already holds a copy
of the firmware end address, hence there is no need to calculate
it again. This reduces 3 instructions in each _scratch_init() loop.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Atish Patra <atish.patra@wdc.com>
3 years agoplatform: generic: Add PMU support
Atish Patra [Sat, 10 Jul 2021 16:18:16 +0000 (09:18 -0700)]
platform: generic: Add PMU support

Add PMU support for generic platform. Generic platform solely relies on
the device tree to parse all pmu related information. If any event is
not described in device tree, generic platform will not support it.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Improve TLB function naming
Atish Patra [Sat, 10 Jul 2021 16:18:15 +0000 (09:18 -0700)]
lib: sbi: Improve TLB function naming

Follow the standard conventon for static function names:

All global functions should be start with sbi_<module name>_
All static functions should be start with <module name>_

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Implement firmware counters
Atish Patra [Sat, 10 Jul 2021 16:18:14 +0000 (09:18 -0700)]
lib: sbi: Implement firmware counters

RISC-V SBI v0.3 specification defines a set of firmware events that can
provide additional information about the current firmware context. All
of the firmware event monitoring are enabled now. The firmware
events must be defined as raw perf event with MSB set as specified in the
specification.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Implement SBI PMU extension
Atish Patra [Sat, 10 Jul 2021 16:18:13 +0000 (09:18 -0700)]
lib: sbi: Implement SBI PMU extension

RISC-V SBI specfication 0.3 defines a PMU extension that allows supervisor
mode to start/stop/configure pmu related events. This patch implements
all of the functionality defined in the specification.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agoutils: fdt: Add fdt helper functions to parse PMU DT nodes
Atish Patra [Sat, 10 Jul 2021 16:18:12 +0000 (09:18 -0700)]
utils: fdt: Add fdt helper functions to parse PMU DT nodes

The PMU DT node bindings are defined in docs/pmu_support.md
Add few fdt helper functions to parse the DT node and update the
event-counter mapping tables.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Add PMU support
Atish Patra [Sat, 10 Jul 2021 16:18:11 +0000 (09:18 -0700)]
lib: sbi: Add PMU support

RISC-V SBI v0.3 specification defined a PMU extension to configure/start/stop
the hardware/firmware pmu events.

Implement PMU support in OpenSBI library. The implementation is agnostic of
event to counter mapping & mhpmevent value configuration. That means, it
expects platform hooks will be used to set up the mapping and provide
the mhpmevent value at runtime.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Add PMU specific platform hooks
Atish Patra [Sat, 10 Jul 2021 16:18:10 +0000 (09:18 -0700)]
lib: sbi: Add PMU specific platform hooks

A platform hook to initialize PMU allows platform vendors to provide
their own mechanism to define pmu event-counter mappings in addition
to the DT based approach.

Another platform hook that allows platform vendors customize the
final mhpmevent value configuration.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Use csr_read/write_num to read/update PMU counters
Atish Patra [Sat, 10 Jul 2021 16:18:09 +0000 (09:18 -0700)]
lib: sbi: Use csr_read/write_num to read/update PMU counters

Currently, csr_read/write_num functions are used to read/write PMP related
CSRs where CSR value is decided at runtime. Expand this function to include
PMU related CSRs as well.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Remove redundant boot time print statement
Atish Patra [Sat, 10 Jul 2021 16:18:08 +0000 (09:18 -0700)]
lib: sbi: Remove redundant boot time print statement

This patch removes redundant print from sbi_boot_print_hart().

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agoinclude: Add a list empty check function
Atish Patra [Sat, 10 Jul 2021 16:18:07 +0000 (09:18 -0700)]
include: Add a list empty check function

Implement a list helper function that checks for empty lists.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Xiang W <wxjstz@126.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Disable m/scounteren & enable mcountinhibit
Atish Patra [Sat, 10 Jul 2021 16:18:06 +0000 (09:18 -0700)]
lib: sbi: Disable m/scounteren & enable mcountinhibit

Currently, all bits in mcountern are enabled unconditionally at boot time.
With SBI PMU extension, all the programmable counters should enabled only
during performance monitoring for a particular event. However, this is done
only if mcountinhibit is implemented because the supervisor mode can not
start/stop any event without mcountinhibit.

Similarly, supervisor should take care enabling scounteren which allows
U-mode to access programmable pmu counters. All the non-programmable ones
(CY, TM, IR) should be enabled in M-mode because some userspace may rely on
builtins such as __builtin_readcyclecounter. Supervisor OS can still disable
them during initial configuration.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Detect number of bits implemented in mhpmcounter
Atish Patra [Sat, 10 Jul 2021 16:18:05 +0000 (09:18 -0700)]
lib: sbi: Detect number of bits implemented in mhpmcounter

RISC-V privilege specification allows the implementation to have less
than 64 bits.

Add a function to detect the number of implemented bits in mhpmcounter
dynamically at runtime.

Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Remove stray '\' character
Atish Patra [Sat, 10 Jul 2021 16:18:04 +0000 (09:18 -0700)]
lib: sbi: Remove stray '\' character

Reviewed-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agolib: sbi: Detect mcountinihibit support at runtime
Atish Patra [Sat, 10 Jul 2021 16:18:03 +0000 (09:18 -0700)]
lib: sbi: Detect mcountinihibit support at runtime

RISC-V ISA specification v1.11 defined mcountinhibit CSR that allows
software to stop any counter from incrementing. The SBI PMU extension
depends on this CSR support in hardware.

Define mcountinhibit as a hart specific feature and detect it at runtime.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agodocs: Add device tree bindings for SBI PMU extension
Atish Patra [Sat, 10 Jul 2021 16:18:02 +0000 (09:18 -0700)]
docs: Add device tree bindings for SBI PMU extension

SBI PMU extension requires a firmware to be aware of the event to
counter/mhpmevent mappings supported by the hardware. One approach
is to encode that information in the device tree.

Define a device tree binding that allows a hardware to describe
all the PMU mappings required in concise format.

Reviewed-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
3 years agoplatform: generic: Terminate platform.name with null
Bin Meng [Sun, 4 Jul 2021 15:01:13 +0000 (23:01 +0800)]
platform: generic: Terminate platform.name with null

fw_platform_init() fills platform.name without considering the
ending null character. Fix it.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agodocs/platform: thead-c9xx: Remove FW_PIC=y
Bin Meng [Sat, 3 Jul 2021 15:09:29 +0000 (23:09 +0800)]
docs/platform: thead-c9xx: Remove FW_PIC=y

FW_PIC is on by default. Hence no need to explicitly require it.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agolib: utils: reset: unify naming of 'sifive_test' device
Green Wan [Thu, 1 Jul 2021 07:39:55 +0000 (15:39 +0800)]
lib: utils: reset: unify naming of 'sifive_test' device

Unify all the file and function names of 'sifive_test' device, to use
the same prefix. This is also a preparatory patch for upcoming sifive
reset device.

Signed-off-by: Green Wan <green.wan@sifive.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
3 years agoplatform: Replace CLINT library usage with ACLINT library
Anup Patel [Fri, 21 May 2021 11:03:33 +0000 (16:33 +0530)]
platform: Replace CLINT library usage with ACLINT library

The ACLINT devices are backward compatible with SiFive CLINT
so we replace all CLINT library usage in various platforms
with ACLINT library. As a result of this replacement, the
CLINT library is not used by any part of OpenSBI hence we
remove it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils/timer: Add FDT based ACLINT MTIMER driver
Anup Patel [Thu, 20 May 2021 10:02:46 +0000 (15:32 +0530)]
lib: utils/timer: Add FDT based ACLINT MTIMER driver

We add a new FDT based ACLINT MTIMER driver which works for
both CLINT device and standalone ACLINT MTIMER device.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils/ipi: Add FDT based ACLINT MSWI IPI driver
Anup Patel [Thu, 20 May 2021 09:13:06 +0000 (14:43 +0530)]
lib: utils/ipi: Add FDT based ACLINT MSWI IPI driver

We add a new FDT based ACLINT MSWI IPI driver which works for both
CLINT device and standalone ACLINT MSWI device.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils: Add FDT parsing API common for both ACLINT and CLINT
Anup Patel [Thu, 20 May 2021 08:08:38 +0000 (13:38 +0530)]
lib: utils: Add FDT parsing API common for both ACLINT and CLINT

We add fdt_parse_aclint_node() which can parse both ACLINT and
CLINT DT nodes. This means fdt_parse_clint_node() is not required
anymore 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: Xiang W <wxjstz@126.com>
3 years agolib: utils/ipi: Add ACLINT MSWI library
Anup Patel [Thu, 20 May 2021 07:30:46 +0000 (13:00 +0530)]
lib: utils/ipi: Add ACLINT MSWI library

We add common ACLINT MSWI library similar to the CLINT library
so that OpenSBI platforms can use it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: utils/timer: Add ACLINT MTIMER library
Anup Patel [Thu, 20 May 2021 05:31:57 +0000 (11:01 +0530)]
lib: utils/timer: Add ACLINT MTIMER library

We add common ACLINT MTIMER library similar to the CLINT library
so that OpenSBI platforms can use it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Xiang W <wxjstz@126.com>
3 years agolib: simplify sbi_fifo_inplace_update()
Heinrich Schuchardt [Mon, 21 Jun 2021 19:03:16 +0000 (21:03 +0200)]
lib: simplify sbi_fifo_inplace_update()

Don't assign an unused value to variable index.

Use operator '-=' where applicable.

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 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>