summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2019-10-03lib: Rename existing SBI implementation as 0.1.Atish Patra
Current SBI implementation is now considered as version 0.1 and will be removed/replaced with newer extension/functions in future. Rename the existing implementations accordingly to be in sync with the specification. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Zong Li <[email protected]>
2019-10-03lib: Align error codes as per SBI specification.Atish Patra
Follow the SBI specification for error codes. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-10-03Test: Move test payload related code out of interface headerAtish Patra
Test payload uses an SBI call and uses the macros defined in interface header which is not the correct place to have these definitions. The interface header file should be used to keep SBI specification related macros. Keep all the test payload related code in test itself. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-10-02lib: Fix coldboot race condition observed on emulators/simulatorsAnup Patel
If we are running on RISC-V emulator/simulator with large number of HARTs where each HART is a regular thread under UNIX host then it is possible that some of the secondary HARTs don't get chance to run and sbi_hart_wake_coldboot_harts() is called before secondary HARTs call sbi_hart_wait_for_coldboot(). In this situation, some of the secondary HARTs will never come-out of coldboot wait loop. To tackle this, we introduce a global flag coldboot_done which will be protected by coldboot lock and it will be set by primary HART from sbi_hart_wake_coldboot_harts() before waking-up secondary HARTs. We also re-arrange acquire/release of coldboot lock to reduce further chances of race-condition. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Zong Li <[email protected]> Reviewed-by: Nylon Chen<[email protected]>
2019-10-02Makefile: Minor fix in OPENSBI_VERSION_GITAnup Patel
Currently, if someone has forked OpenSBI repo quite sometime back and this fork is not having updated tags from upstream riscv/opensbi repo then "git describe" command can fail. To tackle this, we redirect error output of "git describe" to /dev/null. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2019-09-30lib: Emulate HTIMEDELTA CSR for platforms not having TIME CSRAnup Patel
For platforms not having TIME CSR, we trap-n-emulate TIME CSR read/write in OpenSBI. Same rationale applies to HTIMEDELTA CSR as well so we trap-n-emulate HTIMEDELTA CSR for platforms not having TIME CSR. Signed-off-by: Anup Patel <[email protected]>
2019-09-30include: Extend get_insn() to read instruction from VS/VU modeAnup Patel
Current implementation of get_insn() is not suitable for reading instruction from VS/VU mode because we have to set SSTATUS_MXR bit in VSSTATUS CSR for reading instruction from VS/VU mode. This patch extends get_insn() to read instruction from VS/VU mode. Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
2019-09-30lib: Redirect WFI trapped from VS/VU mode to HS-modeAnup Patel
The WFI will trap as illegal instruction trap when executed in VS/VU mode so we just forward/redirect it to HS-mode so that hypervisor can deal with it appropriately. Signed-off-by: Anup Patel <[email protected]>
2019-09-30lib: Extend sbi_trap_redirect() for hypervisor extensionAnup Patel
When hypervisor extension is available, we can get traps from VS/VU modes. We should be able to force redirect some of these traps to HS-mode. In other words, we should be able forward traps from VS/VU mode to HS-mode using sbi_trap_redirect() hence this patch. Signed-off-by: Atish Patra <[email protected]> Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
2019-09-30lib: Extend sbi_hart_switch_mode() to support hypervisor extensionAnup Patel
This patch extends sbi_hart_switch_mode() to support entering VS/VU modes when hypervisor extension is available. Signed-off-by: Anup Patel <[email protected]>
2019-09-30lib: Delegate supervisor ecall to HS-mode when H extension availableAnup Patel
When hypervisor extension is available, we only handle hypervisor ecalls coming from HS-mode and we let hypervisor handle ecalls coming from VS-mode. Signed-off-by: Anup Patel <[email protected]>
2019-09-28Write MSIP by using memory-mapped control registerZong Li
The machine-level MSIP bits are written by accesses to memory-mapped control registers. Only use CSR instruction for SSIP and USIP. There is no effect that using CSR instruction to write MSIP when testing on unleashed board and QEMU. Signed-off-by: Zong Li <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-09-28lib: Fix tlb flush range limit valueAtish Patra
Use platform defined flush range limit value only if it is non-zero. Otherwise, use the default value. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2019-09-28kendryte/k210: remove unused fileDamien Le Moal
Commit 9dfe72057957 ("kendryte/k210: remove sysctl code") missed removing the file sysctl.c. Fix this here. Fixes: 9dfe72057957 ("kendryte/k210: remove sysctl code") Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-09-25docs: platform: Update descriptions for qemu/sifive_u supportBin Meng
With QEMU v4.2 release that has improved the emulation fidelity of 'sifive_u' machine, OpenSBI v0.4 / U-Boot v2019.10-rc1 / Linux kernel v5.3-rc2 images built for the SiFive HiFive Unleashed board can be used out of the box without any special hack. Update our documents to mention 'qemu/sifive_u' platform should only be used with QEMU v4.1 or before, and it will be dropped sometime in the future release. Going forward, 'sifive/fu540' platform can be used on both real hardware and QEMU v4.2+ 'sifive_u' machine. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-09-10lib: provide a platform specific tlb range flush thresholdAtish Patra
Currently, the tlb range flush threshold is fixed and set to 4k for all platforms. However, it should be platform specific as it completely depends upon how platform actually implements sfence instruction. Define a platform feature that allows every individual platform to set different values. If a platform doesn't define it, just use a page size as the threshold. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-09-10lib: Change tlb range flush threshold to 4k page instead of 1GAtish Patra
In RISC-V, tlb flush happens at a page granularity. That's why OpenSBI also have a tlb range flush limit which decides the which tlb flush requests should be upgraded to full flush to avoid long delays. Currently, this is set to 1G which would result in a many sfence.vma execution in a tight loop for a large range. Change the threshold to 4k to speed things up. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-09-05README: Update license informationDamien Le Moal
With the Kendryte K210 platform code cleanup, none of the code copied from Kendryte standalone SDK remains and this platform code is now entirely licensed under OpenSBI BSD-2-clause license. Update the README.md and ThirdPartyNotices.md files to reflect this. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-09-05kendryte/k210: remove sysctl codeDamien Le Moal
Directly implement frequency discovery, making the sysctl code unnecessary. While at it, Move all macro definitions from platform.c into platform.h and cleanup that file, removing the need for the Apache 2.0 license and Canaan Inc copyright. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-09-05kendryte/k210: Use sifive UART driverDamien Le Moal
The Kendryte K210 UARTHS is compatible with SiFive UART. So use the sifive uart driver and remove the k210 uarths platform code. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-31docs: Update the fu540 platform guide as per U-Boot documents.Atish Patra
U-Boot readme for fu540 platform suggest that fdt_addr_r should be used as DT address after DT is copied via tftpboot. Update the OpenSBI docs to reflect that. Remove other stale informations as well. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-31lib: Upgrade to full flush if size is at least thresholdAtish Patra
Currently, we upgrade to a full tlb flush only If a tlb flush request size is greater than the threshold. This is done as sfence in RISC-V can only flush 4KB at a time. Doing a large number of flushes page by page impacts the performance. It is better to do a full tlbflush if the request size is at least equal to the threshold size. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-31lib: Support atomic swap instructionsAtish Patra
If compiler supports riscv atomic instructions, we should use them instead of legacy gcc built-in macros __sync_lock_test_and_set in atomic exchange functions. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-31lib: Fix timer for 32 bitAtish Patra
To read 64bit time in 32 bit we have to read lower & upper half separately and 'or' them together. However, upper half time may have changed by the time we read lower half. Thus, the resultant 64 bit time may not be accurate. Consider lower half time value only if upper half time value has not changed. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-31scripts: Add AE350 to platform list in the binary archive scriptNylon Chen
This patch adds Andes AE350 to RV64 platform list in the binary archive script. Signed-off-by: Nylon Chen <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-23platform: Add Andes AE350 initial supportNylon Chen
This commit provides basic support for the AE350 platform. Signed-off-by: Zong Li <[email protected]> Signed-off-by: Nylon Chen <[email protected]>
2019-08-19Include `git describe` in OpenSBIPalmer Dabbelt
OpenSBI includes a version, but that is only updated when tagged. For users that are using the git releases we instead end up with an ambiguous version number, which makes it hard to figure out what everyone is using. This patch checks for a git directory and prints out the result of `git describe`, which is a mix of pretty and unambiguous. Signed-off-by: Palmer Dabbelt <[email protected]> Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Tested-by: Bin Meng <[email protected]>
2019-08-16platform: Remove the ipi_sync method from all platforms.Atish Patra
OpenSBI manages outstanding TLB flush requests by queueing them in a fifo synchronously. An ipi sync which uses an atomic operation on MMIO address is no longer required. Remove the ipi sync method from platform header and all usage. Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-16lib: Fix race conditions in tlb fifo access.Atish Patra
Linux kernel expects tlb flush SBI call to be completely synchronous i.e. the SBI call should only return once corresponding *fence* instruction is executed. OpenSBI manages the outstanding TLB flush requests by keeping them in a per hart based fifo. However, there are few corner cases that may lead to race conditions while updating the fifo. Currently, the caller hart waits for IPI acknowledgement via clint address which is not a very good method as synchronization on MMIO may not be supported in every platform. Moreover, the waiter doesn't have any way of identifying if the IPI is received for specific tlb flush request or any other IPI. This may lead to unpredictable behavior in supervisor/user space. Fix this by waiting on individual fifo entries rather than MMIO address. Currently, a relaxed loop is being used because wfi again involves MMIO write which would be slower compared to relaxed loop. To avoid deadlock, fifo is processed every time a hart loops for fifo enqueue or fifo sync to consume the tlb flush requests sent by other harts. Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2019-08-16lib: Provide an atomic exchange function unsigned longAtish Patra
Signed-off-by: Anup Patel <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2019-08-13lib: Handle traps when doing unpriv load/store in get_insn()Anup Patel
We can get a page/access trap when doing unpriv load/store in get_insn() function because on a SMP system Linux swapper running on HART A can unmap pages from page table used by HART B. To tackle this we extend get_insn() implementation so that if we get trap in get_insn() then we redirect it to S-mode as fetch page/access fault. Signed-off-by: Anup Patel <[email protected]>
2019-08-13firmware: do not use relocated _boot_status before it is validLukas Auer
When OpenSBI is started from an address not equal to the link address, it is first relocated to the link address. Hart 0 performs the relocation and notifies the other harts of its completion with the _boot_status variable. It uses the copy of the variable relative to the link address. This copy contains valid data only after relocation has finished. The waiting harts will therefore read invalid data until relocation has finished. This can cause them to continue execution too early. Fix this by using the _boot_status variable relative to the load address while OpenSBI has not finished relocation. Signed-off-by: Lukas Auer <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-12lib: Correct null pointer checkJacob Garber
In order to prevent a possible null pointer dereference, return early if either one of 'in' or 'data' is null. Signed-off-by: Jacob Garber <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-08-12lib: Prevent unintended sign extensionsJacob Garber
In the last argument to sbi_memset() we essentially have the following multiplication: size_t = u16 * u16 Due to C's integer semantics, both u16's are implicitly converted to int before the multiplication, which cannot hold all possible values of a u16 * u16. If the multiplication overflows, the intermediate result will be a negative number. On 64-bit platforms, this will be sign-extended to a huge integer in the conversion to a u64 (aka size_t). Being the size argument to sbi_memset(), this could potentially cause a large out-of-bounds write. The solution is to manually cast one of the u16 to a size_t, which will make it large enough to avoid the implicit conversion and any overflow. Signed-off-by: Jacob Garber <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-08-12lib: Use correct type for return valueJacob Garber
The error check 'plic_off < 0' does nothing, since plic_off is stored as a u32. Fix this by changing it to an int, which matches the return type of fdt_node_offset_by_compatible(). Signed-off-by: Jacob Garber <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-08-12lib: Use bitwise & instead of boolean &&Jacob Garber
!(mipval && MIP_MSIP) simplifies to !mipval, which checks if the entire variable is zero, not just a single bit. Fix this to use bitwise & instead. Signed-off-by: Jacob Garber <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2019-08-09lib: Use sbi_dprintf() for invalid CSRsAnup Patel
We should sbi_dprintf() instead of sbi_printf() for invalid CSRs because we are forwarding invalid CSR access back to S-mode. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2019-08-09lib: Introduce sbi_dprintf() APIAnup Patel
This patch introduces new sbi_dprintf() API for runtime debug prints. The sbi_dprintf() will print to console for a given HART only when SBI_SCRATCH_DEBUG_PRINTS option in enabled in sbi_scratch for this HART. We can now add debug prints using sbi_dprintf() at important places in OpenSBI sources. These debug prints will only show up when previous booting stage or compile time parameter sets the SBI_SCRATCH_DEBUG_PRINTS option in scratch space. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2019-08-09firmware: Use macro instead of magic number for boot statusBin Meng
The boot status is currently hard-coded. Define some macros for it. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-09platform: sifive: fu540: Expand FDT size before any patchingBin Meng
We should expand the FDT size before any patching, otherwise it's possible the "status" fix up might fail due to insufficient space. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2019-08-07firmware: Fix the loop condition of _wait_relocate_copy_done sectionNylon Chen
If core-0 have finished _fdt_reloc_done but any of other cores has not yet left the loop in _wait_relocate_copy_done, they could never leave the loop because _boot_status is not equal to 1.
2019-07-26lib: Allow compiling without FP supportAnup Patel
Currently, we mandate 'F' and 'D' extension in riscv_fp.h so that misaligned load/store emulation has access to FP registers. The above is too restrictive and we should certainly allow compilation for soft-FP toolchains and explicit PLATFORM_RISCV_ISA not having 'F' and 'D' extensions. This patch extends riscv_fp.h and misaligned load/store emulation to allow compiling OpenSBI without FP support. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2019-07-25treewide: Use conventional names for 32-bit and 64-bitBin Meng
There are several places in the source tree that have: 32bit, 32 bit, 64bit, 64 bit Fix by using the conventional names with a hyphen. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Lukas Auer <[email protected]> Acked-by: Anup Patel <[email protected]>
2019-07-25README: Document 32-bit / 64-bit images buildBin Meng
At present the exact details of building 32-bit or 64-bit OpenSBI images are missing in the docs. This adds the missing part. Signed-off-by: Bin Meng <[email protected]> Reviewed-by: Lukas Auer <[email protected]> Acked-by: Anup Patel <[email protected]>
2019-07-25utils: Use cpu_to_fdt32() when writing to fdtGeorg Kotheimer
Although it does not make a functional difference, both cpu_to_fdt32() and fdt32_to_cpu() pass on to CPU_TO_FDT32, we should use cpu_to_fdt32() to be semantically correct. Signed-off-by: Georg Kotheimer <[email protected]> Reviewed-by: Atish Patra <[email protected]> Acked-by: Anup Patel <[email protected]>
2019-07-24platform: sifive/fu540: Move FDT further upAnup Patel
This patch changes FW_xyz_FDT_ADDR to RAM_START+128MB (i.e. 0x88000000) so that next stage bootloader (i.e. U-Boot) has enough space to unpack bigger kernel images. Reported-by: David Abdurachmanov <[email protected]> Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: David Abdurachmanov <[email protected]> Tested-by: David Abdurachmanov <[email protected]>
2019-07-22platform: sifive: fu540: Use standard value string for cpu node statusBin Meng
Per device tree spec, the standard value string for the "status" property of a cpu node is either "okay" or "disabled". "masked" was once used but it is unfortunately a spec violation. Signed-off-by: Bin Meng <[email protected]> Acked-by: Anup Patel <[email protected]>
2019-07-02include: Bump-up version to 0.4v0.4Anup Patel
This patch updates OpenSBI version to 0.4 as part of release preparation. Signed-off-by: Anup Patel <[email protected]>
2019-07-02platform: Remove the HiFive Unleashed expansion board DT.Atish Patra
The Linux kernel will maintain the device tree (DT) for HiFive Unleashed from release v5.2-rc6. This DT is incompatible with previous DT present for Microsemi expansion board in OpenSBI. Since, OpenSBI will directly load the pre-built DTB from kernel now onwards, no need to keep the out-of-date DT in openSBI. Remove this DT and it's related documentation. Signed-off-by: Atish Patra <[email protected]> Acked-by: Anup Patel <[email protected]>
2019-07-01firmware: For no relocation skip two stage wait for secondary HARTsAnup Patel
When relocation is not required (i.e. _load_start == _link_start), we can skip two stage wait for secondary HARTs. This means secondary HARTs can skip the _wait_relocate_copy_done() loop and directly jump to the _wait_for_boot_hart() loop when no relocation not required. Signed-off-by: Anup Patel <[email protected]>