Commit graph

151 commits

Author SHA1 Message Date
Damien Le Moal
fff48ee2bf docs/firmware: Update FW_JUMP documentation
Reformatting, typos, and various corrections.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-24 18:45:01 +05:30
Damien Le Moal
808fe4b82a docs/firmware: Add top level document file
Provide an overview of all supported firmware files and point to each
firmware type documentation file.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-24 18:45:01 +05:30
Damien Le Moal
e580b86a41 docs: Contribution guideline update
Explicitely mention that this project adheres to the Developer
Certificate of Origin (DCO) and include this short text.

Also reformat the file to have lines bounded at 80 chars and add some
more details regarding the expected commit message format.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-24 18:45:01 +05:30
Damien Le Moal
36195f52c1 top: Rename LICENSE file to COPYING.BSD
Also make sure that this file contains only the official BSD 2-clause
license text, nothing else.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-24 18:45:01 +05:30
Damien Le Moal
8c25dcbf76 platform: add template platform files
Create commented template files to use as a base for new platforms
support implementation.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-24 18:45:01 +05:30
Anup patel
20990ee0ab all: Update copyright header in all files
This patch updates copyright header in all files as follows:
1. Makes "SPDX-License-Identifier: BSD-2-Clause" as first line
2. Change copyright year to 2019 for Western Digital

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-24 14:07:47 +05:30
Anup Patel
d68741d8b1 include: Use TRUE/FALSE as return values in sbi_platform_hart_disabled()
The sbi_platform_hart_disabled() returns bool hence explicitly return
TRUE or FALSE instead of 1 or 0.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23 09:00:35 +05:30
Anup Patel
025d0ae994 include: Rename ipi_inject() to ipi_send() for sbi_platform
For better naming, we rename ipi_inject() to ipi_send() in
struct sbi_platform. We also replace term "inject" with
"send" in all related places.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23 08:39:26 +05:30
Anup Patel
36394d2f24 include: Drop MMIO from SBI_PLATFORM_HAS_MMIO_TIMER_VALUE
It is not necessary that platform has MMIO-based timer value
register. It can also have some custom (implementation specific)
CSR for timer value.

This patch renames SBI_PLATFORM_HAS_MMIO_TIMER_VALUE to
SBI_PLATFORM_HAS_TIMER_VALUE to imply "platform timer value"
instead of "mmio timer value".

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23 08:39:26 +05:30
Anup Patel
d25774ff96 include: Update documentation of sbi_platform after callback cleanup
The prototypes of sbi_platform callbacks have changed hence we
update related documentation.

Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-01-23 08:39:26 +05:30
Anup Patel
9895d446ae 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>
2019-01-23 08:39:26 +05:30
Anup Patel
74fd2e5bb2 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>
2019-01-23 08:39:26 +05:30
Anup patel
18ec89e46e 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>
2019-01-23 08:39:26 +05:30
Anup Patel
fea9e2b5f3 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>
2019-01-23 08:39:26 +05:30
Atish Patra
f293d21863 docs: Typo fixes.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-22 14:00:44 +05:30
Bin Meng
d9c06d0a8d 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>
2019-01-22 12:17:18 +05:30
Bin Meng
689c31f418 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>
2019-01-22 12:17:18 +05:30
Anup Patel
5c2ab99971 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>
2019-01-22 11:40:15 +05:30
Anup Patel
3fde8f3f64 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>
2019-01-22 11:40:15 +05:30
Anup Patel
f37f7e21e0 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>
2019-01-22 11:40:15 +05:30
Anup Patel
ac003ff6bf 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>
2019-01-22 11:40:15 +05:30
Atish Patra
023aa6bb04 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>
2019-01-22 10:03:49 +05:30
Atish Patra
bc545539d2 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>
2019-01-22 10:03:49 +05:30
Atish Patra
b9c517f559 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>
2019-01-22 10:03:49 +05:30
Atish Patra
312b6bf32f lib: Add atomic bit set/clear operations.
Add addtional functionlities for set/clear bits
atomically.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-22 10:03:49 +05:30
Atish Patra
784a4657c0 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>
2019-01-22 10:03:49 +05:30
Anup Patel
1ee745fe57 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>
2019-01-21 21:12:48 +05:30
Damien Le Moal
b5be19f9e5 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal
42283461d3 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal
868ad0b0e5 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal
58d9f2983a kendryte/k210: Fix console
Clear console input when intializing it.

Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
2019-01-21 09:58:33 +05:30
Damien Le Moal
9c4aca4f1b 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal
0df8269477 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal
f4373731e3 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal
6939d345ab 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>
2019-01-21 09:58:33 +05:30
Damien Le Moal
ac3041f4e9 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>
2019-01-21 09:58:33 +05:30
Anup Patel
ebfe231256 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>
2019-01-18 10:47:30 +05:30
Atish Patra
e0686ca844 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>
2019-01-18 10:05:12 +05:30
Atish Patra
3075da07b6 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>
2019-01-18 10:05:12 +05:30
Atish Patra
384ba7f7f1 docs: Add licensing seciton for external projects.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-18 10:05:12 +05:30
Atish Patra
00f77d9ba0 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>
2019-01-18 10:05:12 +05:30
Atish Patra
cf83b6e438 platform: Include libfdt & libc.
Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-01-18 10:05:12 +05:30
Atish Patra
57d5eaa5fb 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>
2019-01-18 10:05:12 +05:30
Atish Patra
e2ce15cb3b 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>
2019-01-18 10:05:12 +05:30
Atish Patra
1901e8a287 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>
2019-01-18 10:05:12 +05:30
Anup Patel
3298251f0c 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>
2019-01-16 11:25:25 +05:30
Anup Patel
4485b5cba8 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>
2019-01-16 11:25:25 +05:30
Anup Patel
924a26d82f 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>
2019-01-16 11:25:25 +05:30
Anup Patel
5f097cbf07 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>
2019-01-16 11:25:25 +05:30
Anup Patel
5ef104062d 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>
2019-01-16 11:25:25 +05:30