platform/kernel/opensbi.git
5 years agolib: Remove target_hart and hartid parameter from TIMER callbacks
Anup Patel [Tue, 22 Jan 2019 09:17:03 +0000 (14:47 +0530)]
lib: Remove target_hart and hartid parameter from TIMER callbacks

The target_hart and hartid paramter of TIMER callbacks is not
required because it always current hartid which can be obtained
using sbi_current_hartid() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Remove hartid parameter from IRQCHIP callbacks
Anup Patel [Tue, 22 Jan 2019 09:03:41 +0000 (14:33 +0530)]
lib: Remove hartid parameter from IRQCHIP callbacks

The hartid parameter in IRQCHIP callbacks of sbi_platform
is not required because current hartid can be determined
using sbi_current_hartid() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Remove source_hart and hartid parameter from IPI callbacks
Anup patel [Tue, 22 Jan 2019 08:50:59 +0000 (14:20 +0530)]
lib: Remove source_hart and hartid parameter from IPI callbacks

The source_hart and hartid parameter is really not required in
IPI callbacks of sbi_platform because current hartid can always
be obtained by calling sbi_current_hartid() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Remove hartid paramter from early_init() and final_init() callbacks
Anup Patel [Tue, 22 Jan 2019 08:22:25 +0000 (13:52 +0530)]
lib: Remove hartid paramter from early_init() and final_init() callbacks

We simplify early_init() and final_init() callbacks of sbi_platform
by removing "hartid" parameter.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Typo fixes.
Atish Patra [Mon, 21 Jan 2019 08:01:23 +0000 (00:01 -0800)]
docs: Typo fixes.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agodocs: Fix nits in firmware/fw_jump.md
Bin Meng [Mon, 21 Jan 2019 14:29:59 +0000 (22:29 +0800)]
docs: Fix nits in firmware/fw_jump.md

Add a space before (FW_JUMP) to make it more readable.

This also fixes "No newline at end of file" warning.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
5 years agotop: Fix broken links in top-level README.md
Bin Meng [Mon, 21 Jan 2019 14:14:16 +0000 (22:14 +0800)]
top: Fix broken links in top-level README.md

There are 2 markdown links that are currently broken in top-level
README.md. Fix them so that github could render the URL correctly.

This also fixes "No newline at end of file" warning.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
5 years agolib: Add doxygen style documentation for sbi_platform
Anup Patel [Mon, 21 Jan 2019 17:53:23 +0000 (23:23 +0530)]
lib: Add doxygen style documentation for sbi_platform

This patch adds doxygen style documenation for struct sbi_platform
and related functions/macros/defines.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Update documentation of sbi_init()
Anup Patel [Tue, 22 Jan 2019 05:36:31 +0000 (11:06 +0530)]
lib: Update documentation of sbi_init()

We don't need to pre-enable MSIP in MIE CSR when
calling sbi_init() from firmware. This patch updates
documentation accordingly.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoMakefile: Don't install generic headers under <install_dir>/platform
Anup Patel [Mon, 21 Jan 2019 05:35:36 +0000 (11:05 +0530)]
Makefile: Don't install generic headers under <install_dir>/platform

We don't need to install generic headers separately for every
platforn under <install_dir>/platform. It is unnecessary duplication
of files hence updating install_libplatsbi in top-level makefile.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Add OpenSBI version to doxygen.cfg
Anup Patel [Mon, 21 Jan 2019 05:31:14 +0000 (11:01 +0530)]
docs: Add OpenSBI version to doxygen.cfg

The PDF document generated by doxygen should have OpenSBI version
hence this patch adds OpenSBI version to doxygen.cfg.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Do not access mi/edeleg register if S mode is not present.
Atish Patra [Tue, 22 Jan 2019 02:17:45 +0000 (18:17 -0800)]
lib: Do not access mi/edeleg register if S mode is not present.

As per the RISC-V ISA, mideleg and medeleg registers should not exist
if S-mode is not present for a hart.

We shouldn't access these CSRs if non S-mode harts.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Allow sending IPI to self.
Atish Patra [Tue, 22 Jan 2019 01:54:00 +0000 (17:54 -0800)]
lib: Allow sending IPI to self.

S-mode software may send IPI to self. For example,
tlbflush may be executed for the same hart.

Let the hart send IPI to itself. It's an overhead
but doesn't break anything. However, if we don't
allow it, it breaks if S-mode keep sending IPIs.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Fix ipi type update
Atish Patra [Mon, 21 Jan 2019 07:24:26 +0000 (23:24 -0800)]
lib: Fix ipi type update

IPIs are updated in scratch space by source hart.
However, different harts or same hart may want to
send different IPIs before previous IPI was read
by the target hart. Currently, previous IPI type
is overwritten in that case.

Use atomic bit set/clear operations to update IPIs.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Add atomic bit set/clear operations.
Atish Patra [Mon, 21 Jan 2019 07:23:28 +0000 (23:23 -0800)]
lib: Add atomic bit set/clear operations.

Add addtional functionlities for set/clear bits
atomically.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Move software interrupt enablement from firmware to lib
Atish Patra [Fri, 18 Jan 2019 21:35:47 +0000 (13:35 -0800)]
lib: Move software interrupt enablement from firmware to lib

The secondary hart waits for an IPI signal from the boot hart to
executing boot code (hot boot). As a result, software generated
interrupts have to be enabled for secondary harts before waiting for
the boot hart boot completion IPI signal.

Enabling software generated interrupts (IPI) can be done independently
of the firmware code and moved to libsbi code so that the different
firmware do not have to implement this.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Use AMO instructions whenever __riscv_atomic is defined
Anup Patel [Mon, 21 Jan 2019 11:23:46 +0000 (16:53 +0530)]
lib: Use AMO instructions whenever __riscv_atomic is defined

We should use AMO instructions whenever __riscv_atomic is
defined (i.e. atomics are supported). We use LR/SC only when
__riscv_atomic is not defined.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agosbi: Add ecall helpers
Damien Le Moal [Fri, 18 Jan 2019 07:28:32 +0000 (16:28 +0900)]
sbi: Add ecall helpers

Define sbi_ecall_console_puts() using sbi_ecall_console_putchar()
renamed as sbi_ecall_console_putc() and remove the hardcoded version
of the same funtion in the test payload code.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agopayload: rename dummy payload to test payload
Damien Le Moal [Fri, 18 Jan 2019 07:09:14 +0000 (16:09 +0900)]
payload: rename dummy payload to test payload

Use a more neutral term more representative of this payload intent.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agokendryte/k210: Add device tree support
Damien Le Moal [Mon, 14 Jan 2019 04:00:37 +0000 (13:00 +0900)]
kendryte/k210: Add device tree support

The Kendryte k210 board initial loader does not provide a device tree
for the firmware and subsequent payload. Add the k210.dts device tree
description file to solve this. This file describes only the SoC core
components: CPUs, memory and PLIC.

Automatically compile and add this file to the firmware generated
using the FW_PAYLOAD_FDT_PATH configuration parameter.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agokendryte/k210: Fix console
Damien Le Moal [Fri, 18 Jan 2019 04:46:31 +0000 (13:46 +0900)]
kendryte/k210: Fix console

Clear console input when intializing it.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMakefile: Improve readability
Damien Le Moal [Fri, 18 Jan 2019 06:57:31 +0000 (15:57 +0900)]
Makefile: Improve readability

Repeating "ifdef CROSS_COMPILE" multiple times does not help with
readability. Simplify by grouping compilation command setup under a
single ifdef statement.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMakefile: Add support for device tree compilation
Damien Le Moal [Fri, 18 Jan 2019 06:49:37 +0000 (15:49 +0900)]
Makefile: Add support for device tree compilation

Add rules to compile dts files into dtb files using the device tree
compiler (dtc). A platform can specify the DTS file to compile using
the platform-dtb-y variable. The flattened device tree binary file to be
used for building the final polatform firmware can be specified using
the new FW_PAYLOAD_FDT firmware configuration option to point to the
automatically compiled FDT file. Using the existing FW_PAYLOAD_FDT_PATH
configuration option is still possible and will take precedence over
the FW_PAYLOAD_FDT definition.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agolib: code cleanup
Damien Le Moal [Fri, 18 Jan 2019 04:45:08 +0000 (13:45 +0900)]
lib: code cleanup

Use commonly accepted styles: newlines after declarations and before
return to make the code more readable.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agolib: Fix banner
Damien Le Moal [Fri, 18 Jan 2019 04:18:25 +0000 (13:18 +0900)]
lib: Fix banner

Define the "OpenSBI" logo string as a macro renamed BANNER, since
it is one rather than a logo.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agobuild: Introduce FW_PAYLOAD_ALIGN
Damien Le Moal [Mon, 14 Jan 2019 02:17:25 +0000 (11:17 +0900)]
build: Introduce FW_PAYLOAD_ALIGN

The firmware payload offset defined by FW_PAYLOAD_OFFSET must
specify a value large enough so the the payload does not overlap
with the base firmware data, bss and text. For platforms without
any strong requirement on the payload address, introduce the
FW_PAYLOAD_ALIGN build parameter to automatically place the payload
right after the base firmware at an address aligned with the defined
value.

Either FW_PAYLOAD_OFFSET or FW_PAYLOAD_ALIGN should be defined by a
platform configuration. If both FW_PAYLOAD_OFFSET and FW_PAYLOAD_ALIGN
are defined by a platform, FW_PAYLOAD_OFFSET has precedence and is
used for building the final firmawre image.

Using FW_PAYLOAD_ALIGN=4096 with the Kendryte platform rather than
the abitrary FW_PAYLOAD_OFFSET=0x10000 value reduces the final
firmware image size by about 20KB.

Add a description of the FW_PAYLOAD_ALIGN configuration parameter in the
fw_payload documentation file as well. And while at it, also fix
various grammar and style issues in that file..

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoplatform: Fix compile error caused by standard includes
Anup Patel [Fri, 18 Jan 2019 04:58:58 +0000 (10:28 +0530)]
platform: Fix compile error caused by standard includes

Avoid using standard includes namely stdint.h, string.h, stdlib.h, etc.

All standard include except stddef.h give compilation error due
to differences in RISC-V toolchain configuration. Typically, the
compilation error is related to "gnu-stubs-lp64.h".

This patch fixes compile error caused by standard includes by
providing substitutes of definetions provided by standard includes
wherever required.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoplatform: No need to pass context id for plic fixup.
Atish Patra [Wed, 9 Jan 2019 09:17:41 +0000 (01:17 -0800)]
platform: No need to pass context id for plic fixup.

PLIC DT entry fixup can be done by comparing external
interrupt number instead of context id. No need to invoke
fixup for each plic context.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoplatform: Modify DT using libfdt
Atish Patra [Wed, 9 Jan 2019 08:52:02 +0000 (00:52 -0800)]
platform: Modify DT using libfdt

Perform following DT updates.
1. Mask hart if mmu is not supported.
2. Add stdout-path under chosen node.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agodocs: Add licensing seciton for external projects.
Atish Patra [Wed, 9 Jan 2019 08:49:35 +0000 (00:49 -0800)]
docs: Add licensing seciton for external projects.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoplatform: Remove string functions from tinyfdt.c
Atish Patra [Fri, 18 Jan 2019 00:42:41 +0000 (16:42 -0800)]
platform: Remove string functions from tinyfdt.c

There are couple of string function defined in platform
code. We no longer need them as we can directly link minimal
libc.

Every platform required to inclde this as PLIC driver required
libc functions.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoplatform: Include libfdt & libc.
Atish Patra [Wed, 9 Jan 2019 08:49:10 +0000 (00:49 -0800)]
platform: Include libfdt & libc.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoplatform: Rename fdt.c to tinyfdt.c
Atish Patra [Wed, 9 Jan 2019 08:47:14 +0000 (00:47 -0800)]
platform: Rename fdt.c to tinyfdt.c

Libfdt already have fdt.c and fdt.h.
Rename both fdt.* present in openSBI to tinyfdt.*

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoplatform: Add libfdt support.
Atish Patra [Wed, 9 Jan 2019 08:42:37 +0000 (00:42 -0800)]
platform: Add libfdt support.

Some of the platform (i.e. SiFive FU540) requires Device
Tree modification before it is passed to higher stages.
Add libfdt support now to help this process. Libfdt should
only be included per platform basis.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoplatform: Add minimal libc support.
Atish Patra [Fri, 18 Jan 2019 00:38:55 +0000 (16:38 -0800)]
platform: Add minimal libc support.

libfdt requires minimal libc support. Absoultely
minimum functions are added in libc.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoinclude: Add documentation for sbi_trap_regs and friends
Anup Patel [Mon, 14 Jan 2019 09:30:15 +0000 (15:00 +0530)]
include: Add documentation for sbi_trap_regs and friends

This patch adds doxygen style documentation for struct sbi_trap_regs
and related macros/defines/functions.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Add __packed define for packed structures
Anup Patel [Mon, 14 Jan 2019 09:23:52 +0000 (14:53 +0530)]
include: Add __packed define for packed structures

This patch adds __packed define for specifying packed
attribute of structures.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Add documentation for sbi_scratch and friends
Anup Patel [Mon, 14 Jan 2019 08:30:32 +0000 (14:00 +0530)]
include: Add documentation for sbi_scratch and friends

This patch adds doxygen style documentation for struct sbi_scratch
and related helper macros/defines.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Add documentation for sbi_init() API
Anup Patel [Mon, 14 Jan 2019 08:28:29 +0000 (13:58 +0530)]
lib: Add documentation for sbi_init() API

This patch adds doxygen style documentation for sbi_init() API.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Add __noreturn define for noreturn function attribute
Anup Patel [Mon, 14 Jan 2019 08:25:35 +0000 (13:55 +0530)]
include: Add __noreturn define for noreturn function attribute

There are quite a few noreturn functions in OpenSBI hence
we add commong __noreturn define for noreturn functin attribute.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Update title in contributing.md
Anup Patel [Mon, 14 Jan 2019 06:56:32 +0000 (12:26 +0530)]
docs: Update title in contributing.md

The patch updates title in contributing.md to match
other .md files under docs/ directory.

Signed-off-by: Anup Patel <anup.pate@wdc.com>
5 years agotop: Update top-level README.md to build/install documentation PDF
Anup Patel [Mon, 14 Jan 2019 06:18:38 +0000 (11:48 +0530)]
top: Update top-level README.md to build/install documentation PDF

This patch updates top-level README.md for steps required to build
and install documentation PDF.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoMakefile: Add make targets to build and install documentation
Anup Patel [Mon, 14 Jan 2019 06:55:01 +0000 (12:25 +0530)]
Makefile: Add make targets to build and install documentation

This patch extends top-level makefile to build and install
documentation. The 'docs' make target is for building the
documentation PDF whereas 'install_docs' make target is for
installing the documentation PDF.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoMakefile: Use '=' instead of '?=' for make variables
Anup Patel [Fri, 4 Jan 2019 03:15:36 +0000 (08:45 +0530)]
Makefile: Use '=' instead of '?=' for make variables

The '?=' will not assign value if the target make variable is
overriden via command-line or is set in environment variable.
On other hand, '=' will not assign value only if variable is
overriden via command-line parameter.

It is quite common to have CC, AS, CPP, LD, etc to be set as
environment variables pointing to native compiler and binutils.
If '-rR' option is not set in MAKEFLAGS then this results in
compile error because '?=' will use the native compiler and
binutils. If '-rR' option is set in MAKEFLAGS then this again
results in compile error because CC, AS, CPP, etc are set to
empty strings which causes '?=' to use empty string as compiler
and binutils.

To handle this, we use '?=' only when CROSS_COMPILE is not
defined and we use '=' when CROSS_COMPILE is defined.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Add a contributing document
Alistair Francis [Wed, 2 Jan 2019 22:44:35 +0000 (14:44 -0800)]
docs: Add a contributing document

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoMakefile: Force GCC to preprocess the linker file
Alistair Francis [Wed, 2 Jan 2019 21:59:49 +0000 (13:59 -0800)]
Makefile: Force GCC to preprocess the linker file

To avoid this message (and subsequent errors):
    warning: linker input file unused because linking not done
force GCC to treat the linker script preprocessing as a C file.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoMakefile: Convert to a more standard format
Alistair Francis [Sat, 22 Dec 2018 00:44:55 +0000 (16:44 -0800)]
Makefile: Convert to a more standard format

Convert the Makefile to a more standard format and don't forcefully
overwrite a users enviroment.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoMakefile: Use generic flags for the firmware
Alistair Francis [Sat, 22 Dec 2018 00:09:03 +0000 (16:09 -0800)]
Makefile: Use generic flags for the firmware

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoMakefile: Use generic flags for the platform
Alistair Francis [Wed, 2 Jan 2019 18:16:15 +0000 (10:16 -0800)]
Makefile: Use generic flags for the platform

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agoMakefile: Support verbosity using standard V=1
Alistair Francis [Wed, 2 Jan 2019 18:14:40 +0000 (10:14 -0800)]
Makefile: Support verbosity using standard V=1

Instead of using a confusing and custom option, allow verbose Makefile
with the standard V=1.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
5 years agolib: Handle misaligned load/store on FP regs
Anup Patel [Thu, 3 Jan 2019 06:48:47 +0000 (12:18 +0530)]
lib: Handle misaligned load/store on FP regs

This patch extends misaligned load/store trap handling to
handle FP regs as well.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Add hard FP access macros and defines
Anup Patel [Thu, 3 Jan 2019 05:07:43 +0000 (10:37 +0530)]
include: Add hard FP access macros and defines

This patch adds hardware floating-point (hard FP) access
macros and defines.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoMerge pull request #16 from damien-lemoal/master
Alistair Francis [Thu, 3 Jan 2019 15:52:42 +0000 (07:52 -0800)]
Merge pull request #16 from damien-lemoal/master

Various fixes

5 years agoplatform: kendryte/k210: Simplify sysctl code
Damien Le Moal [Thu, 3 Jan 2019 05:32:25 +0000 (14:32 +0900)]
platform: kendryte/k210: Simplify sysctl code

Simplify sysctl.c code to only the used CPU freqency function.
This reduces the size of the final firmware by 4KB.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoplatform: kendryte/k210: Declare local function static
Damien Le Moal [Thu, 3 Jan 2019 04:34:32 +0000 (13:34 +0900)]
platform: kendryte/k210: Declare local function static

k210_console_putc() and k210_console_init() are local functions. Declare
them as static.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMakefile: Fix messages
Damien Le Moal [Mon, 31 Dec 2018 04:00:39 +0000 (13:00 +0900)]
Makefile: Fix messages

Instead of printing the generic "<build_directory>" and
"<install_directory>" strings, print the actual paths for the build
and install directories during "make clean" and "make distclean".

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoinclude: Remove redundant tmp0 from struct sbi_scratch
Anup Patel [Wed, 2 Jan 2019 09:21:30 +0000 (14:51 +0530)]
include: Remove redundant tmp0 from struct sbi_scratch

The tmp0 member was added in struct sbi_scratch to assist
register save/restore at time of trap handling. This tmp0
is not unsed any more hence removing it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Move RISCV_TRAP_REGS_xyz defines to sbi_trap.h
Anup Patel [Mon, 31 Dec 2018 07:07:28 +0000 (12:37 +0530)]
include: Move RISCV_TRAP_REGS_xyz defines to sbi_trap.h

The struct sbi_trap_regs related defines RISCV_TRAP_REGS_xyz should
be in sbi_trap.h so that we can keep these defines in-sync with changes
in struct sbi_trap_regs.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Move RISCV_PLATFORM_xyz defines to sbi_platform.h
Anup Patel [Mon, 31 Dec 2018 06:00:55 +0000 (11:30 +0530)]
include: Move RISCV_PLATFORM_xyz defines to sbi_platform.h

The struct sbi_platform related defines RISCV_PLATFORM_xyz should
be in sbi_platform.h so that we can keep these defines in-sync
with changes in struct sbi_platform.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Move RISCV_SCRATCH_xyz defines to sbi_scratch.h
Anup Patel [Mon, 31 Dec 2018 05:49:20 +0000 (11:19 +0530)]
include: Move RISCV_SCRATCH_xyz defines to sbi_scratch.h

The struct sbi_scratch related defines RISCV_SCRATCH_xyz should
be in sbi_scratch.h so that we can keep these defines in-sync
with changes in struct sbi_scratch.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Replace #csr with __ASM_STR(csr) in csr_xyz() macros
Anup Patel [Mon, 31 Dec 2018 04:59:49 +0000 (10:29 +0530)]
include: Replace #csr with __ASM_STR(csr) in csr_xyz() macros

We replace #csr with __ASM_STR(csr) in all csr_xyz() macros
so that we can pass CSR number instead of CSR name when GCC
is not aware of CSR name.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoinclude: Remove redundant csr_read_n() and csr_write_n()
Anup Patel [Mon, 31 Dec 2018 04:55:42 +0000 (10:25 +0530)]
include: Remove redundant csr_read_n() and csr_write_n()

The patch removes redundant csr_read_n() and csr_write_n()
because same thing can be achieved by using __ASM_STR()
macro in csr_read() and csr_write() macros.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agodocs: Add documenation for QEMU platforms
Anup Patel [Fri, 28 Dec 2018 08:51:57 +0000 (14:21 +0530)]
docs: Add documenation for QEMU platforms

This patch adds documentation for qemu/virt and
qemu/sifive_u platform supports.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agotop: Minor typo fixes in top-level README.md
Anup Patel [Fri, 28 Dec 2018 08:50:25 +0000 (14:20 +0530)]
top: Minor typo fixes in top-level README.md

This patch does minor typo fixes in top-level README.md.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Redirect illegal instruction trap to S-mode when not handled
Anup Patel [Thu, 27 Dec 2018 16:09:13 +0000 (21:39 +0530)]
lib: Redirect illegal instruction trap to S-mode when not handled

Currently, we fail with error SBI_ENOTSUPP when we are not able
to handle illegal instruction trap. Instead, we should just
redirect illegal instruction trap to S-mode when not handled.

This redirection of illegal instruction trap will help lazy
save/restore of floating point registers to work correctly in
Linux kernel.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoplatform: Fix author name for Kendryte K210 platform
Anup Patel [Fri, 28 Dec 2018 05:31:37 +0000 (11:01 +0530)]
platform: Fix author name for Kendryte K210 platform

The Kendryte K210 platform support was contributed by Damien
hence fix author name.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoplatform: Rename sifive/hifive_u540 to sifive/fu540
Anup Patel [Fri, 28 Dec 2018 05:21:15 +0000 (10:51 +0530)]
platform: Rename sifive/hifive_u540 to sifive/fu540

We rename sifive/hifive_u540 platform support to sifive/fu540
to match the SoC name which is SiFive FU540 (as-per user manual).

In fact, we can expect no (or very minimal) board specific
quirks in sifive/fu540 platform support. These board specific
quirks can be turned on/off in-future using PLATFORM_<xyz>
make command-line option.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agolib: Print mtval in sbi_trap_error()
Anup Patel [Thu, 27 Dec 2018 04:36:38 +0000 (10:06 +0530)]
lib: Print mtval in sbi_trap_error()

The mtval CSR is very useful information when debugging hence
print it upon trap error in sbi_trap_error().

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Rename target_hart parameter to hartid for PMP platform callbacks
Anup Patel [Wed, 26 Dec 2018 13:19:55 +0000 (18:49 +0530)]
lib: Rename target_hart parameter to hartid for PMP platform callbacks

We rename target_hart parameter of PMP platform callbacks to
hartid for clarity because the parameter represents current
hartid.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Simplify sbi_platform timer_init() hooks
Anup Patel [Wed, 26 Dec 2018 13:14:54 +0000 (18:44 +0530)]
lib: Simplify sbi_platform timer_init() hooks

Instead of having separate timer_init() hooks for cold and
warm boot, this patch updates struct sbi_platform to have just
one timer_init() hook. The type of boot (cold or warm) is now
a boolean flag parameter for the updated timer_init() hook.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Simplify sbi_platform ipi_init() hooks
Anup Patel [Wed, 26 Dec 2018 13:06:11 +0000 (18:36 +0530)]
lib: Simplify sbi_platform ipi_init() hooks

Instead of having separate ipi_init() hooks for cold and warm boot,
this patch updates struct sbi_platform to have just one ipi_init()
hook. The type of boot (cold or warm) is now a boolean flag parameter
for the updated ipi_init() hook.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Simplify sbi_platform irqchip_init() hooks
Anup Patel [Wed, 26 Dec 2018 12:57:35 +0000 (18:27 +0530)]
lib: Simplify sbi_platform irqchip_init() hooks

Instead of having separate irqchip_init() hooks for cold and
warm boot, this patch updates struct sbi_platform to have just
one irqchip_init() hook. The type of boot (cold or warm) is now
a boolean flag parameter for the updated irqchip_init() hook.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Simplify sbi_platform early_init() and final_init() hooks
Anup Patel [Wed, 26 Dec 2018 12:51:22 +0000 (18:21 +0530)]
lib: Simplify sbi_platform early_init() and final_init() hooks

Instead of having separate early_init() and final_init() hooks
for cold and warm boot, this patch updates struct sbi_platform
to have just one early_init() and one final_init() hook. The
type of boot (cold or warm) is now a boolean flag parameter for
the updated early_init() and final_init() hooks.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agofirmware: Rename fw_common.S to fw_base.S
Anup Patel [Wed, 26 Dec 2018 05:13:15 +0000 (10:43 +0530)]
firmware: Rename fw_common.S to fw_base.S

The fw_common.S is the base firmware extendend by fw_jump and
fw_payload. This patch renames fw_common.S to fw_base.S to
have more clear/intutive name for base firmware.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agotop: Improve 'clean' and 'distclean' makefile targets
Anup Patel [Wed, 26 Dec 2018 05:36:54 +0000 (11:06 +0530)]
top: Improve 'clean' and 'distclean' makefile targets

This improves 'clean' and 'distclean' makefile target as follows:
1. Remove only .o, .a, .elf, and .bin files for 'clean'
2. Remove .dep in-addition to what 'clean' does for 'distclean'
3. Remove default build and install directory for 'distclean'

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agotop: Improve inst_file_list() in Makefile for payloads installation
Anup Patel [Mon, 24 Dec 2018 06:45:32 +0000 (12:15 +0530)]
top: Improve inst_file_list() in Makefile for payloads installation

We now have payloads sub-directory under firmware directory which
means payload BINs and ELFs should be installed under firmware/payloads.

This patch improves inst_file_list() to handle payloads sub-directory
under firmware installation directory.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agofirmware: Use dummy payload for FW_PAYLOAD
Anup Patel [Mon, 24 Dec 2018 05:23:10 +0000 (10:53 +0530)]
firmware: Use dummy payload for FW_PAYLOAD

We use recently added separate dummy payload for FW_PAYLOAD
when FW_PAYLOAD_PATH is not specified.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agofirmware: Add separate dummy payload for FW_PAYLOAD
Anup Patel [Wed, 26 Dec 2018 04:14:49 +0000 (09:44 +0530)]
firmware: Add separate dummy payload for FW_PAYLOAD

Currently, the default payload for FW_PAYLOAD is embedded
fw_payload.S itself. This means people have to hack fw_payload.S
if they want to have some temporary S-mode test code.

This patch adds a separate dummy payload for FW_PAYLOAD which
can be easily hacked for some S-mode testing.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Move ECALL defines to sbi_ecall_interface.h
Anup Patel [Wed, 26 Dec 2018 04:12:26 +0000 (09:42 +0530)]
lib: Move ECALL defines to sbi_ecall_interface.h

This patch moves all ECALL defines to sbi_ecall_interface.h so
that it can be shared with firmware payloads.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Add misaligned load/store trap handling
Anup Patel [Mon, 24 Dec 2018 11:19:01 +0000 (16:49 +0530)]
lib: Add misaligned load/store trap handling

We generally don't get misaligned load/store traps from Linux/U-Boot
compiled using GCC 8.2 or higher but this is not true with older
GCC toolchains. To tackle this we add misaligned load/store trap
handling adopted from BBL sources but much more simpler.
(Note: BBL sources can be found at https://github.com/riscv/riscv-pk.git)

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agolib: Move instruction encoding macros to riscv_encoding.h
Anup Patel [Mon, 24 Dec 2018 11:15:00 +0000 (16:45 +0530)]
lib: Move instruction encoding macros to riscv_encoding.h

This patch moves all instruction encoding macros to
riscv_encoding.h.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agotop: Rename back CROSS_COMPILE_PREFIX to CROSS_COMPILE
Anup Patel [Wed, 26 Dec 2018 05:27:15 +0000 (10:57 +0530)]
top: Rename back CROSS_COMPILE_PREFIX to CROSS_COMPILE

The name CROSS_COMPILE is an industry standard used across
open-source project to specify cross-compiler prefix.

In fact, distro build systems such as buildroot and yocto
assume CROSS_COMPILE to be supported by projects added
as packages to these build systems.

This patch rename back CROSS_COMPILE_PREFIX to CROSS_COMPILE.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoREADME: Update
Damien Le Moal [Tue, 25 Dec 2018 06:37:04 +0000 (15:37 +0900)]
README: Update

Some rewrite with a more formal style.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMakefile: Fix clean
Damien Le Moal [Tue, 25 Dec 2018 06:50:29 +0000 (15:50 +0900)]
Makefile: Fix clean

Clean was doing nothing. Fix it to remove all compiled files, leaving
only dependency files.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMakefile: Rename CROSS_COMPILE to CROSS_COMPILE_PREFIX
Damien Le Moal [Tue, 25 Dec 2018 06:37:48 +0000 (15:37 +0900)]
Makefile: Rename CROSS_COMPILE to CROSS_COMPILE_PREFIX

Make it clear what this environment variable defines and update
the README.md file to explain that.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoMerge pull request #4 from riscv/avpatel/master
Atish Patra [Sat, 22 Dec 2018 18:02:52 +0000 (10:02 -0800)]
Merge pull request #4 from riscv/avpatel/master

Remove PLAT_<xyz> defines from platform and firmwares

5 years agotop: Typo fix in top-level README.md
Anup Patel [Sat, 22 Dec 2018 15:44:23 +0000 (21:14 +0530)]
top: Typo fix in top-level README.md

The platform specific options will be PLATFORM_<xyz> and not
PLAT_<xyz> hence this patch fixes typo in top-level README.md.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoplatform: Remove PLAT_HART_COUNT and PLAT_HART_STACK_SIZE
Anup Patel [Sat, 22 Dec 2018 15:31:40 +0000 (21:01 +0530)]
platform: Remove PLAT_HART_COUNT and PLAT_HART_STACK_SIZE

The PLAT_HART_COUNT and PLAT_HART_STACK_SIZE are only used
by platform code so no need of exposing these to everyone
by adding it to platform-cppflags-y.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agofirmware: Don't depend on PLAT_HART_COUNT and PLAT_HART_STACK_SIZE
Anup Patel [Sat, 22 Dec 2018 07:10:54 +0000 (12:40 +0530)]
firmware: Don't depend on PLAT_HART_COUNT and PLAT_HART_STACK_SIZE

The hart_count and hart_stack_size information is already available
in "struct sbi_platform" so we use that instead of depending on
PLAT_HART_COUNT and PLAT_HART_STACK_SIZE.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agofirmware: Remove stack section from common linker script
Anup Patel [Sat, 22 Dec 2018 06:32:31 +0000 (12:02 +0530)]
firmware: Remove stack section from common linker script

We don't need a separate stack section for per-HART stack
instead we create per-HART stack at the end of firmware
(i.e. after _fw_end symbol).

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoplatform: Remove PLAT_NAME from all platforms
Anup Patel [Sat, 22 Dec 2018 05:45:37 +0000 (11:15 +0530)]
platform: Remove PLAT_NAME from all platforms

The PLAT_NAME is used only in platform.c for all platforms hence
remove it.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoMerge pull request #3 from riscv/unleashed_working_12_21
Anup Patel [Sat, 22 Dec 2018 15:12:48 +0000 (20:42 +0530)]
Merge pull request #3 from riscv/unleashed_working_12_21

Unleashed working 12 21

5 years agoDisable all interrupts during warm irqchip init.
Atish Patra [Sat, 22 Dec 2018 05:31:12 +0000 (21:31 -0800)]
Disable all interrupts during warm irqchip init.

M mode is not expected to recieve any interrupts.
S mode interrupts shouldn't be enabled in M mode.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoIntroduce hart disabled parameter in platform.
Atish Patra [Fri, 21 Dec 2018 19:29:28 +0000 (11:29 -0800)]
Introduce hart disabled parameter in platform.

As of now, uboot doesn't have support for SMP.
Moreover, unleashed board has a E51 hart which
doesn't not support S mode.

We should only boot only 1 non-zero hart.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoFix plic warm init in platform code.
Anup Patel [Fri, 21 Dec 2018 23:46:37 +0000 (15:46 -0800)]
Fix plic warm init in platform code.

Pass S-Mode and M-mode context id separately to common warm init.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoFix plic warm init in common code.
Anup Patel [Fri, 21 Dec 2018 23:45:14 +0000 (15:45 -0800)]
Fix plic warm init in common code.

Unleashed doesn't have S mode for hart 0.
PLIC register base calculation is current wrong because of that.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agoMove hardcoded uart constant to macros.
Atish Patra [Fri, 21 Dec 2018 23:16:59 +0000 (15:16 -0800)]
Move hardcoded uart constant to macros.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
5 years agoIntroduce HAS_MFAULTS_DELEGATION feature
Damien Le Moal [Fri, 21 Dec 2018 10:19:54 +0000 (19:19 +0900)]
Introduce HAS_MFAULTS_DELEGATION feature

Conditionnally delegate page fault exceptions from M mode to S mode
based on the platform features.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
5 years agoplatform: kendryte/k210: Don't include math.h
Anup Patel [Fri, 21 Dec 2018 10:02:28 +0000 (15:32 +0530)]
platform: kendryte/k210: Don't include math.h

The math.h is not required anymore and it also gives
compile error for certain toolchains hence thsi patch
removes math.h include from kendryte/k210/sysctl.c.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
5 years agofirmware: Remove redundant write to mideleg and medeleg
Anup Patel [Fri, 21 Dec 2018 09:35:59 +0000 (15:05 +0530)]
firmware: Remove redundant write to mideleg and medeleg

The mideleg and medeleg are already programmed in delegate_traps()
so no need to set it here.

Any CSR setup in our reference firmware becomes a requirement
for bootloader linking to libsbi.a so we should have minimum
possible CSR setup in our reference firmware.

Signed-off-by: Anup Patel <anup.patel@wdc.com>