summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2021-08-04platform: generic: Change FW_JUMP_FDT_ADDR to 128MB offsetREL_DUBHE_SEPT2021REL_DUBHE_PRERELEASEstarfive-dubheLey Foon Tan1-1/+1
OpenSBI defaults to place the FDT 32MB after the start of the kernel but this is not sufficient for a kernel with a large builtin initrd rootfs. This patch change FW_JUMP_FDT_ADDR to 128MB after the FW_TEXT_START to support > 32MB kernel image. This is known limitation, see detail in https://github.com/riscv/opensbi/issues/169 Signed-off-by: Ley Foon Tan <leyfoon.tan@starfivetech.com>
2021-07-27lib: utils: support both of gpio-poweroff, gpio-resetHeinrich Schuchardt2-2/+12
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>
2021-07-27lib: utils: remove unused variable in fdt_reset_initHeinrich Schuchardt1-3/+0
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>
2021-07-27generic: fu740: add workaround for CIP-1200 errataDavid Abdurachmanov3-0/+39
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>
2021-07-27firmware: use _fw_start for load addressXiang W2-4/+4
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>
2021-07-27Makefile: Manually forward RELAX_FLAG to the assembler when linking with LLDBin Meng1-0/+5
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>
2021-07-17README: Update toolchain informationBin Meng1-5/+13
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>
2021-07-17docs: Document FW_PIC compile time optionBin Meng1-0/+6
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>
2021-07-17docs: Document parameters passed to firmware and alignment requirementBin Meng2-2/+10
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>
2021-07-17firmware: Remove the unhelpful alignment codes before fdt relocationBin Meng1-4/+1
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>
2021-07-17include: types: Use __builtin_offsetof when supportedAlex Richardson1-1/+7
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>
2021-07-17firmware: use __SIZEOF_LONG__ for field offsets in fw_dynamic.hAlex Richardson1-6/+6
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>
2021-07-17lib: utils/reset: Add generic GPIO reset driverGreen Wan3-0/+144
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>
2021-07-17lib: utils/gpio: Add minimal SiFive GPIO driverGreen Wan3-0/+109
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>
2021-07-17lib: utils/gpio: Add simple FDT based GPIO frameworkAnup Patel3-0/+167
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>
2021-07-17lib: utils/gpio: Add generic GPIO configuration libraryAnup Patel3-0/+225
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>
2021-07-17lib: utils/fdt: Add fdt_parse_phandle_with_args() APIAnup Patel2-0/+58
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>
2021-07-11lib: utils: Drop dependency on libgcc by importing part of FreeBSD's libquadJessica Clarke11-1/+683
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>
2021-07-11Makefile: Support building with Clang and LLVM binutilsJessica Clarke2-9/+105
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>
2021-07-11firmware: Only default FW_PIC to y if supportedJessica Clarke2-1/+4
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>
2021-07-11firmware: Explicitly pass -pie to the linker, not just the driverJessica Clarke1-1/+1
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>
2021-07-11fw_base: Put data in .data rather than .textJessica Clarke1-0/+1
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>
2021-07-11fw_base: Don't mark fw_platform_init as both global and weakJessica Clarke1-1/+0
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>
2021-07-11lib: sbi: Fix sbi_pmu_exit() for systems not having MCOUNTINHIBIT csrAnup Patel1-0/+4
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>
2021-07-11firmware: Define a macro for version of struct fw_dynamic_infoBin Meng2-3/+4
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>
2021-07-11firmware: Remove the sanity checks in fw_save_info()Bin Meng1-8/+0
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>
2021-07-11docs: Make <xyz> visible in the rendered platform guideBin Meng1-8/+8
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>
2021-07-11docs: Correct a typo in platform_guide.mdBin Meng1-1/+1
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>
2021-07-11firmware: Minor optimization in _scratch_init()Bin Meng1-4/+9
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>
2021-07-11platform: generic: Add PMU supportAtish Patra1-0/+30
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>
2021-07-11lib: sbi: Improve TLB function namingAtish Patra1-21/+20
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>
2021-07-11lib: sbi: Implement firmware countersAtish Patra6-0/+60
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>
2021-07-11lib: sbi: Implement SBI PMU extensionAtish Patra5-1/+99
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>
2021-07-11utils: fdt: Add fdt helper functions to parse PMU DT nodesAtish Patra4-0/+160
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>
2021-07-11lib: sbi: Add PMU supportAtish Patra6-1/+844
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>
2021-07-11lib: sbi: Add PMU specific platform hooksAtish Patra1-0/+39
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>
2021-07-11lib: sbi: Use csr_read/write_num to read/update PMU countersAtish Patra1-0/+35
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>
2021-07-11lib: sbi: Remove redundant boot time print statementAtish Patra1-2/+0
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>
2021-07-11include: Add a list empty check functionAtish Patra1-0/+11
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>
2021-07-11lib: sbi: Disable m/scounteren & enable mcountinhibitAtish Patra1-4/+21
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>
2021-07-11lib: sbi: Detect number of bits implemented in mhpmcounterAtish Patra2-0/+49
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>
2021-07-11lib: sbi: Remove stray '\' characterAtish Patra1-1/+1
Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11lib: sbi: Detect mcountinihibit support at runtimeAtish Patra2-1/+14
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>
2021-07-11docs: Add device tree bindings for SBI PMU extensionAtish Patra1-0/+79
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>
2021-07-06platform: generic: Terminate platform.name with nullBin Meng1-1/+1
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>
2021-07-06docs/platform: thead-c9xx: Remove FW_PIC=yBin Meng1-1/+1
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>
2021-07-05lib: utils: reset: unify naming of 'sifive_test' deviceGreen Wan3-4/+4
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>
2021-06-24platform: Replace CLINT library usage with ACLINT libraryAnup Patel9-337/+107
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>
2021-06-24lib: utils/timer: Add FDT based ACLINT MTIMER driverAnup Patel4-60/+77
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>
2021-06-24lib: utils/ipi: Add FDT based ACLINT MSWI IPI driverAnup Patel4-54/+70
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>