summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2019-09-30lib: Extend sbi_trap_redirect() for hypervisor extensionAnup Patel4-26/+156
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 <atish.patra@wdc.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-09-30lib: Extend sbi_hart_switch_mode() to support hypervisor extensionAnup Patel4-5/+44
This patch extends sbi_hart_switch_mode() to support entering VS/VU modes when hypervisor extension is available. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-09-30lib: Delegate supervisor ecall to HS-mode when H extension availableAnup Patel1-0/+8
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 <anup.patel@wdc.com>
2019-09-28Write MSIP by using memory-mapped control registerZong Li1-1/+1
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 <zong.li@sifive.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-09-28lib: Fix tlb flush range limit valueAtish Patra1-1/+1
Use platform defined flush range limit value only if it is non-zero. Otherwise, use the default value. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-09-28kendryte/k210: remove unused fileDamien Le Moal1-57/+0
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 <damien.lemoal@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-09-25docs: platform: Update descriptions for qemu/sifive_u supportBin Meng2-0/+20
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 <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-09-10lib: provide a platform specific tlb range flush thresholdAtish Patra4-4/+29
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 <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-09-10lib: Change tlb range flush threshold to 4k page instead of 1GAtish Patra1-1/+1
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 <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-09-05README: Update license informationDamien Le Moal2-196/+4
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 <damien.lemoal@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-09-05kendryte/k210: remove sysctl codeDamien Le Moal4-967/+60
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 <damien.lemoal@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-09-05kendryte/k210: Use sifive UART driverDamien Le Moal4-253/+9
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 <damien.lemoal@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-31docs: Update the fu540 platform guide as per U-Boot documents.Atish Patra1-10/+12
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 <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-31lib: Upgrade to full flush if size is at least thresholdAtish Patra1-1/+1
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 <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-31lib: Support atomic swap instructionsAtish Patra1-18/+36
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 <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-31lib: Fix timer for 32 bitAtish Patra1-5/+13
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 <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-31scripts: Add AE350 to platform list in the binary archive scriptNylon Chen1-0/+1
This patch adds Andes AE350 to RV64 platform list in the binary archive script. Signed-off-by: Nylon Chen <nylon7@andestech.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-23platform: Add Andes AE350 initial supportNylon Chen10-0/+650
This commit provides basic support for the AE350 platform. Signed-off-by: Zong Li <zongbox@gmail.com> Signed-off-by: Nylon Chen <nylon7@andestech.com>
2019-08-19Include `git describe` in OpenSBIPalmer Dabbelt2-0/+9
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 <palmer@sifive.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com>
2019-08-16platform: Remove the ipi_sync method from all platforms.Atish Patra8-53/+0
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 <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-16lib: Fix race conditions in tlb fifo access.Atish Patra6-147/+259
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 <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-08-16lib: Provide an atomic exchange function unsigned longAtish Patra2-0/+19
Signed-off-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2019-08-13lib: Handle traps when doing unpriv load/store in get_insn()Anup Patel4-46/+65
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 <anup.patel@wdc.com>
2019-08-13firmware: do not use relocated _boot_status before it is validLukas Auer1-3/+10
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 <lukas.auer@aisec.fraunhofer.de> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-12lib: Correct null pointer checkJacob Garber1-1/+1
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 <jgarber1@ualberta.ca> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-08-12lib: Prevent unintended sign extensionsJacob Garber1-2/+4
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 <jgarber1@ualberta.ca> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-08-12lib: Use correct type for return valueJacob Garber1-1/+1
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 <jgarber1@ualberta.ca> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-08-12lib: Use bitwise & instead of boolean &&Jacob Garber1-1/+1
!(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 <jgarber1@ualberta.ca> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-08-09lib: Use sbi_dprintf() for invalid CSRsAnup Patel1-4/+4
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 <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-08-09lib: Introduce sbi_dprintf() APIAnup Patel3-0/+19
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 <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-08-09firmware: Use macro instead of magic number for boot statusBin Meng1-4/+7
The boot status is currently hard-coded. Define some macros for it. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-09platform: sifive: fu540: Expand FDT size before any patchingBin Meng1-5/+6
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 <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2019-08-07firmware: Fix the loop condition of _wait_relocate_copy_done sectionNylon Chen1-1/+1
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 Patel3-13/+16
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 <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-07-25treewide: Use conventional names for 32-bit and 64-bitBin Meng6-15/+15
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 <bmeng.cn@gmail.com> Reviewed-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-07-25README: Document 32-bit / 64-bit images buildBin Meng1-0/+19
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 <bmeng.cn@gmail.com> Reviewed-by: Lukas Auer <lukas.auer@aisec.fraunhofer.de> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-07-25utils: Use cpu_to_fdt32() when writing to fdtGeorg Kotheimer1-1/+1
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 <georg.kotheimer@kernkonzept.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-07-24platform: sifive/fu540: Move FDT further upAnup Patel1-2/+2
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 <david.abdurachmanov@sifive.com> Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: David Abdurachmanov <david.abdurachmanov@sifive.com> Tested-by: David Abdurachmanov <david.abdurachmanov@sifive.com>
2019-07-22platform: sifive: fu540: Use standard value string for cpu node statusBin Meng1-1/+2
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 <bmeng.cn@gmail.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-07-02include: Bump-up version to 0.4v0.4Anup Patel1-1/+1
This patch updates OpenSBI version to 0.4 as part of release preparation. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-07-02platform: Remove the HiFive Unleashed expansion board DT.Atish Patra2-603/+0
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 <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-07-01firmware: For no relocation skip two stage wait for secondary HARTsAnup Patel1-0/+1
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 <anup.patel@wdc.com>
2019-06-30scripts: Add Ariane FPGA to platform list in binary archive scriptAnup Patel1-0/+1
This patch adds Ariane FPGA to RV64 platform list in the binary archive script. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-06-30docs: Update the fu540 platform guide for new DT.Atish Patra1-50/+62
With 5.2-rc6 release, Linux kernel hosts the DT for Unleashed board which is incompatible with the default DT from FSBL. Update the document to use the DT from kernel. Signed-off-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-29include: Add firmware context to sbi_platformAbner Chang1-0/+4
Add firmware context field struct sbi_platform to carry firmware specific information. Signed-off-by: Abner Chang <abner.chang@hpe.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-29include: Add version info to struct sbi_platformAbner Chang10-13/+55
Add version control of sbi_platform structure - Add opensbi_version, this gives information of opensbi revision on which the sbi_platform table was created. - Add platform_version field in sbi_platform structure for platform level version control. Signed-off-by: Abner Chang <abner.chang@hpe.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-29include: Move callbacks in sbi_platform to separate structAbner Chang7-172/+198
Move platform opensbi functions to sbi_platform_operations structure. Both sbi_platform and sbi_platform_operations structures are maintained by platform vendors. Signed-off-by: Abner Chang <abner.chang@hpe.com> Acked-by: Anup Patel <anup.patel@wdc.com>
2019-06-29Add documentation for Ariane FPGA platformPanagiotis Peristerakis2-0/+41
Signed-off-by: Panagiotis Peristerakis <perister@ics.forth.gr>
2019-06-29Add support for Ariane FPGA SoCPanagiotis Peristerakis3-0/+250
This patch adds support for Ariane platform. We needed to enable PLIC interrupts early(like on BBL) due to some issue of the design. Otherwise, Linux would not get any external interrupts. Signed-off-by: Panagiotis Peristerakis <perister@ics.forth.gr>
2019-06-29Changed plic_set_thresh() and plic_set_ie() to publicPanagiotis Peristerakis2-2/+6
Signed-off-by: Panagiotis Peristerakis <perister@ics.forth.gr>