summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2020-03-28lib: sbi_trap: Simplify sbi_trap_handler() APIAnup Patel3-16/+10
This patch simplify sbi_trap_handler() API as follows: 1. Remove current hartid local variable because sbi_trap_handler() itself does not need it. 2. Remove scratch parameter because none of the functions directly called by sbi_trap_handler() require it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: sbi_ecall: Remove mcause, scratch and hartid parametersAnup Patel9-39/+33
We remove mcause, scratch and hartid parameters from various functions for ecall handling because we can always get current HART id and current scratch pointer using just one CSR access. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: sbi_misaligned_ldst: Remove mcause, scratch and hartid parametersAnup Patel3-25/+12
We remove mcause, scratch and hartid parameters from various functions for misaligned load/store handling because we can always get current HART id and current scratch pointer using just one CSR access. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: sbi_illegal_insn: Remove mcause, scratch and hartid parametersAnup Patel3-29/+13
We remove mcause, scratch and hartid parameters from various functions for illegal instruction handling because we can always get current HART id and current scratch pointer using just one CSR access. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: sbi_emulate_csr: Remove scratch and hartid parameterAnup Patel3-14/+15
We remove scratch and hartid parameter from various functions for CSR emulation because we can always get current HART id and current scratch pointer using just one CSR access. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: sbi_trap: Remove scratch parameter from sbi_trap_redirect()Anup Patel5-16/+12
The scratch parameter of sbi_trap_redirect() is not used hence we remove it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: Remove scratch parameter from unpriv load/store functionsAnup Patel5-26/+17
The scratch parameter of unpriv load/store functions is now redundant hence we remove it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: Optimize unpriv load/store implementationAnup Patel7-125/+147
This patch optimize unpriv load/store implementation by having dedicated unpriv trap handler (just like KVM RISC-V). As a result of this optimization: 1. We have reduced roughly 13+ instruction in all unpriv load/store functions. The reduced instruction also include two function calls. 2. Per-HART trap info pointer in scratch space is now redundant hence removed. 3. The sbi_trap_handler() is now much cleaner because we don't have to handle unpriv load/store traps. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28lib: utils: Improve fdt_cpu_fixup() implementationAnup Patel1-11/+24
Currently, the fdt_cpu_fixup() implementation assumes: 1. We have one CPU DT for each HART under /cpus DT node 2. The CPU DT nodes are named sequentially (i.e cpu@0, cpu@1, ...) which is not true for discontinuous and sparse HART ids (i.e. cpu@0, cpu@4, cpu@5). Generally, CPU DT node are named based on HART id and not HART index If any of the above assumptions are violated then the fdt_cpu_fixup() will not work. This improves fdt_cpu_fixup() implementation and makes it independent of above assumptions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28scripts: Extend create-binary-archive.sh for unified binary tar ballAnup Patel1-75/+101
This patch extends/revamps create-binary-archive.sh to allow creating unified binary tar ball containing both RV32 and RV64 images. Users can also create "RV32 only" or "RV64 only" tar balls as well. Few example commands are as follows: ./scripts/create-binary-archive.sh (Build both RV32 & RV64 images) ./scripts/create-binary-archive.sh -x 32 (Build RV32 only images) ./scripts/create-binary-archive.sh -x 64 (Build RV64 only images) Signed-off-by: Anup Patel <anup.patel@wdc.com>
2020-03-26lib: prevent coldboot_lottery from overflowingXiang Wang1-1/+1
HSM_STOP will trigger multiple executions of sbi_init, atomic_add_return may trigger coldboot_lottery overflow Signed-off-by: Xiang Wang <merle@hardenedlinux.org> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-24platform: openpiton: Read the device configurations from device treeAtish Patra1-25/+57
OpenPiton is designed to run on different FPGAs with different configurations. Use the fdt parser to retrieve the required values from device tree instead of using fixed values. Signed-off-by: Atish Patra <atish.patra@wdc.com> Tested-by: Jonathan Balkind <jbalkind@cs.princeton.edu> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-24lib: utils: Move fdt fixup helper routines to a different fileAtish Patra10-244/+276
FDT helper file contain both fdt fixup and parsing functions. Split the fixup related functions to a separate file for a better code organization. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-24platform: fpga/common: Add a fdt parsing helper functionsAtish Patra2-0/+136
Different DT based platforms from the sam family may reuse IP blocks with different configurations. These different configurations can be obtained by parsing the device tree. Add a FDT parser framework that can parse various device configurations from device tree. Currently, the parsing algorithms doesn't cover all the use cases or possible combination of DT configurations. It will be improved over time. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-24platform: Add OpenPiton platform supportAtish Patra6-0/+280
OpenPiton is a research platform from Princeton University [1]. "OpenPiton is the world's first open source, general purpose, multithreaded manycore processor. It is a tiled manycore framework scalable from one to 1/2 billion cores." Add OpenSBI support for OpenPiton. As it is based on ariane core, it reuses the platform code from arine project. [1]. https://github.com/PrincetonUniversity/openpiton Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-24platform: fpga/ariane: Remove redundant plic address macrosAtish Patra1-9/+4
All the common PLIC specific macros are already defined in plic.c. Remove it from platform code. While at it, Fix the other coding style issues. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-24platform: Move ariane standalone fpga project to its own projectAtish Patra6-4/+4
Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-21lib: Check MSIP bit after returning from WFIAtish Patra1-2/+5
Commit 71d2b837c46e (lib: Move all coldboot wait APIs to sbi_init.c) caused a regression while moving the code from sbi_hart.c to sbi_init.c. As per original commit text, WFI can be implemented as a NOP according to the RISC-V privilege specification. Software should ensure that relevant interrupt pending bits are set. Otherwise, loop back to WFI. Fix the regression by applying the original patch to sbi_init.c. Fixes: 71d2b837c46e ("lib: Move all coldboot wait APIs to sbi_init.c") Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-19lib: Fix sbi_ecall_register_extension to prevent extension IDs overlapXiang Wang1-3/+11
The original code does not prevent the following scenarios: > sbi_ecall_register_extension(ext1); /* extension id (70-80) */ > sbi_ecall_register_extension(ext2); /* extension id (50-100) */ Signed-off-by: Xiang Wang <merle@hardenedlinux.org> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-19platform: sifive/fu540: Remove FU540_ENABLED_HART_MASK optionAnup Patel3-23/+2
The FU540_ENABLED_HART_MASK compile time option was added for initial bring-up on SiFive Unleashed. This option is redundant now because disabled_hart_mask is already removed. Based on this rationale, we remove FU540_ENABLED_HART_MASK compile time option. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19include: sbi_platform: Introduce HART index to HART id tableAnup Patel6-28/+89
A platform can have discontinuous and/or sparse HART ids so we cannot always assume a set of HARTs with continuous HART ids. This patch adds support for discontinuous and sparse HART ids by introducing HART index to HART id table. This table has platform hart_count entries and it maps HART index to HART id. The HART index to HART id table has only two restrictions: 1. HART index < sbi_platform hart_count 2. HART id < SBI_HARTMASK_MAX_BITS Example1: Let's say we have a platform with 2 HART ids 11 and 22, for such a a platform: hart_count = 2 hart_index2id[0] = 11 hart_index2id[1] = 22 Example2: Let's say we have a platform with 5 HARTs ids 0, 1, 2, 3, and 4 but out of these HART with id 0 is not usable so for such a platform: hart_count = 5 hart_index2id[0] = -1U hart_index2id[1] = 1 hart_index2id[2] = 2 hart_index2id[3] = 3 hart_index2id[4] = 4 OR hart_count = 4 hart_index2id[0] = 1 hart_index2id[1] = 2 hart_index2id[2] = 3 hart_index2id[3] = 4 With HART index to HART id table in place, the hart_disabled() callback is now redundant so we remove it as well. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: Don't use sbi_platform_hart_count() APIAnup Patel2-13/+5
We don't need to use sbi_platform_hart_count() in sbi_init and sbi_scratch because checking sbi_platform_hart_disabled() or return value of sbi_hartid_to_scratch() is sufficient. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: sbi_hsm: Don't use sbi_platform_hart_disabled() APIAnup Patel1-5/+1
Checking return value of sbi_hartid_to_scratch() is sufficient so no need to explicitly check for disabled HART using the sbi_platform_hart_disabled() API. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: sbi_hsm: Remove scratch parameter from hart_started_mask() APIAnup Patel5-10/+7
The scratch parameter in sbi_hsm_hart_started_mask() API is now redundant hence removing it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: sbi_hsm: Don't use sbi_platform_hart_count() APIAnup Patel1-15/+4
We remove usage of sbi_platform_hart_count() API from sbi_hsm so that discontinuous and sparse HART ids can be supported. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-03-19lib: sbi_scratch: Don't set hartid_to_scratch table for disabled HARTAnup Patel1-1/+4
As a step towards supporting discontinuous and sparse HART ids, we don't set hartid_to_scratch table for disabled HARTs. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19include: sbi_platform: Improve sbi_platform_hart_disabled() APIAnup Patel1-16/+20
The sbi_platform_hart_disabled() should return TRUE for HART id greater than platform hart count. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-03-19lib: Handle failure of sbi_hartid_to_scratch() APIAnup Patel6-8/+29
The sbi_hartid_to_scratch() API can fail for non-existent HARTs so all uses of sbi_hartid_to_scratch() API should check return value. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: sbi_tlb: Simplify sbi_tlb_entry_process() functionAnup Patel1-4/+3
We remove redundant scratch parameter from sbi_tlb_entry_process() function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: sbi_hsm: Simplify hart_get_state() and hart_started() APIsAnup Patel3-8/+9
We remove redundant scratch parameter from sbi_hsm_hart_get_state() and sbi_hsm_hart_started() APIs. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19include: Simplify HART id to scratch macroAnup Patel6-8/+8
This patch simplify HART id to scratch macro as follows: 1. Remove current "scratch" pointer argument because now we use HART id to scratch table 2. Rename sbi_hart_id_to_scratch() to sbi_hartid_to_scratch() to have macro name consistent with the name of callback in struct sbi_scratch Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-19lib: sbi_scratch: Introduce HART id to scratch tableAnup Patel3-2/+28
Instead of calling hartid_to_scratch() callback every time when we want sbi_scratch pointer from HART id, we create a table of sbi_scratch pointers and use that to get sbi_scratch pointer. As a result of HART id to scratch table, the conversion of HART id to sbi_scratch pointer is just 2-3 instructions which was 9 instructions previously. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18platform: Update to call general DT fix-up helperBin Meng4-12/+5
Platform andes/ae350, ariane-fpga, qemu/virt and sifive/fu540 codes have been updated to call this general DT fix-up helper. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-18lib: utils: Add a general device tree fix-up helperBin Meng2-0/+20
This adds a general device tree fix-up helper to do all required device tree fix-ups for a typical platform. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-18platform: sifive/fu540: Replace cpu0 node fix-up with the new helperBin Meng1-25/+1
This replaces the FU540 specific cpu0 node "status" property fix-up with the newly introduced generic fdt_cpu_fixup() helper. Unlike previous logic, the helper routine does not test the "mmu-type" property to determine which node we should fix up, instead it uses sbi_platform_hart_disabled() API. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-18lib: utils: Add a fdt_cpu_fixup() helperBin Meng2-0/+38
Add a helper routine to updates the "status" property of a CPU node in the device tree to "disabled" if that hart is in disabled state. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-18platform: sifive/fu540: Remove "stdout-path" fix-upBin Meng1-5/+1
As of today the upstream U-Boot & Linux kernel ships a device tree that already has "stdout-path" properly set in the "/chosen" node. This is the same with the QEMU 'sifive_u' machine. Hence the codes to fix up the "stdout-path" in OpenSBI is not necessary. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18platform: sifive/fu540: Fix up DT for reserved memoryBin Meng1-0/+2
This calls fdt_reserved_memory_fixup() helper in the platform's final_init() routine. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18platform: qemu/virt: Fix up DT for reserved memoryBin Meng1-0/+2
This calls fdt_reserved_memory_fixup() helper in the platform's final_init() routine. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-18platform: ariane-fpga: Fix up DT for reserved memoryBin Meng1-0/+3
This calls fdt_reserved_memory_fixup() helper in the platform's final_init() routine. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18platform: andes/ae350: Fix up DT for reserved memoryBin Meng1-0/+2
This calls fdt_reserved_memory_fixup() helper in the platform's final_init() routine. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18lib: utils: Move PLIC DT fix up codes to fdt_helper.cBin Meng8-33/+46
Now that we have a dedicated fdt_helper.c file for DT releated helper routines, move plic_fdt_fixup() codes from plic.c to fdt_helper.c and rename it to fdt_plic_fixup() at the same time, to keep name consistency in the same file. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18platform: Clean up include header filesBin Meng6-16/+12
Adjust the order of include header files in alphabetical order in platform codes. Also remove unnecessary inclusions. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18lib: utils: Add a fdt_reserved_memory_fixup() helperBin Meng3-0/+174
Add a helper routine to insert a child node of the reserved memory node in the device tree that describes the protected memory region done by OpenSBI via PMP. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18libfdt: Compile fdt_addresses.cBin Meng1-2/+2
Pull fdt_addresses.o in for fdt_address_cells() & fdt_size_cells(). Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-18lib: sbi: Update pmp_get() to return decoded size directlyBin Meng3-17/+11
Currently pmp_get() returns the log2 length of the PMP memory region size. The caller has to calculate the size based on that and the same codes are duplicated. Update this function to return decoded size directly. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-17scripts: Cover sifive/fu540 in the 32-bit buildBin Meng1-0/+1
We now support building sifive/fu540 as a 32-bit platform. Add it in the 32-bit platform list of binary archive script. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-14platform: Use one unified per-HART stack size macro for all platformsBin Meng12-14/+11
As of today all platforms use 8KB of per-HART stack hence there is no need for each platform to define its own macro or use the magic number. Create one macro for all platforms. Platform still can use its own version if needed. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-14platform: Set per-HART stack size to 8KB in the template platform codesBin Meng1-1/+1
The template platform codes should set per-HART stack size to 8KB to avoid possible mistakes of future platform ports. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-03-14platform: ariane-fpga: Set per-HART stack size to 8KBBin Meng1-1/+1
Recent commit 4a603eb ("platform: kendryte/k210: Set per-HART stack size to 8KB") forgot to update ariane-fpga codes, and the following commit 678c3c3 ("include: sbi_scratch: Set per-HART scratch size to 4KB") changed the per-HART scratch size to 4KB, which potentially breaks ariane-fpga platform. This patch set per-HART stack size of ariane-fpga to 8KB for consistency. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>