summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)AuthorFilesLines
2020-05-01lib: utils: Add simple FDT timer frameworkAnup Patel3-0/+167
We add simple timer framework which will select and use timer driver based on details in FDT passed by previous booting stage. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-01lib: utils: Add fdt_parse_plic_node() functionAnup Patel1-6/+20
We add fdt_parse_plic_node() function which will allow us to parse a particular DT node as PLIC node. This will be useful in parsing the DT node which we have found by matching compatible string. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-01lib: utils: Add fdt_parse_max_hart_id() APIAnup Patel1-0/+28
We add fdt_parse_max_hart_id() API which return max HART id based on CPU DT nodes. This will be used by generic FDT based drivers in subsequent patches. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-05-01lib: utils: Add fdt_parse_hart_id() functionAnup Patel2-15/+33
Parsing HART id from a CPU DT node is a common requirement for RISC-V systems. The newly added fdt_parse_hart_id() also helps reduce duplicate code between fdt_cpu_fixup() function and fdt_parse_hart_count() function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-05-01lib: utils: Add fdt_parse_sifive_uart_node() functionAnup Patel1-0/+43
We add fdt_parse_sifive_uart_node() function which will allow us to parse a particular DT node as SiFive UART node. This will be useful in parsing the node pointed by stdout-path. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-01lib: utils: Make fdt_get_node_addr_size() public functionAnup Patel1-2/+2
The fdt_get_node_addr_size() will be useful in FDT based simple driver frameworks so we make it a public function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-05-01lib: utils: Add FDT match table based node lookupAnup Patel1-0/+41
This patch adds FDT match table based node lookup funcitons. These functions will be useful in implementing simple FDT based driver frameworks. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-01lib: utils: Rename fdt_parse_clint() to fdt_parse_compat_addr()Anup Patel1-4/+4
The fdt_parse_clint() is quite generic and can be used for other types of devices so we rename it to fdt_parse_compat_addr(). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-01lib: utils: Add fdt_parse_uart8250_node() functionAnup Patel1-14/+23
We add fdt_parse_uart8250_node() function which will allow us to parse a particular DT node as UART 8250 node. This will be useful in parsing the node pointed by stdout-path. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-01lib: utils: Improve fdt_parse_uart8250() APIAnup Patel1-0/+21
The information parsed by fdt_parse_uart8250() API is not complete. We need to parse reg-shift and reg-io-width for UART 8520 as well. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-05-01lib: utils/serial: Skip baudrate config if input frequency is zeroAnup Patel2-5/+10
We should skip baudrate config for UART8250 and SiFive UART when input frequency is zero. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2020-04-27lib: utils: Add SiFive test deviceAnup Patel2-0/+45
This patch factor-out SiFive test device related stuff into it's own source file from qemu/virt platform. In future, we can find SiFive test device address from device tree as well. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-04-27include: sbi_platform: Combine reboot and shutdown into one callbackAnup Patel3-31/+8
We can achieve shutdown, cold reboot, and warm reboot using just one sbi_platform callback so we combine system_reboot() and system_shutdown() callbacks into one system_reset() callback. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-04-27lib: No need to provide default PMP region using platform callbacksAnup Patel1-9/+15
The default (usually last) PMP region provides S-mode access to complete memory range not covered by other PMP regions. Currently, the default PMP region is described as platform specific PMP region which is not appropriate because all platforms need it and default PMP region should be part of generic library. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2020-04-19lib: Allow overriding SBI implementation IDAnup Patel2-1/+13
Ideally, the SBI implementation ID for OpenSBI should always be 0x1 (as mentioned in SBI v0.2 spec) but external firmware (such as EDK2) which use OpenSBI as library might want to override the SBI implementation ID with their custom implementation ID. 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-04-17lib: Support vector extensionAtish Patra1-1/+8
Enable vector context in mstatus by updating the corresponding bits in mstatus if vector extension is supported by the hart. 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>
2020-04-06lib: irqchip/plic: Fix maximum priority threshold valueAtish Patra1-2/+2
As per the PLIC specification, maximum priority threshold value is 0x7. Even though, writing a higher value doesn't cause any error in qemu hifive unleashed, there may be some implementation which checks the upper and may result in an illegal access. 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>
2020-03-28include: sbi_console: Remove scratch parameter from sbi_dprintf()Anup Patel3-9/+8
This patch removes scratch parameter from sbi_dprintf() function because sbi_dprintf() can use sbi_scratch_thishart_ptr() to get current HART scratch space. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28include: sbi_timer: Remove scratch parameter from most funcitonsAnup Patel5-38/+36
This patch removes scratch parameter from most sbi_timer functions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28include: sbi_system: Remove scratch parameter and redundant functionsAnup Patel3-27/+9
This patch removes scratch parameter and redundant functions from sbi_system. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28include: sbi_ipi: Remove scratch parameter from most functionsAnup Patel6-18/+17
This patch removes scratch parameter from most sbi_ipi functions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28include: sbi_tlb: Remove scratch parameter from sbi_tlb_request()Anup Patel3-14/+13
The sbi_ipi_send_many() should get current HART scratch pointer on it's own using eventually hence removing scratch parameter from sbi_tlb_request(). Signed-off-by: Anup Patel <anup.patel@wdc.com>
2020-03-28lib: sbi_scratch: Introduce sbi_scratch_last_hartid() APIAnup Patel3-4/+7
The patch adds sbi_scratch_last_hartid() API which returns last HART id having a scratch space. We can use this new API to optimize places where we iterate over HART id from 0 to SBI_HARTMASK_MAX_BITS. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28include: Use more consistent name for atomic xchg() and cmpxchg()Anup Patel3-11/+11
We should remove the "arch_" prefix from atomic xchg() and cmpxchg() function names to have consistent naming of all atomic functions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28include: sbi_platform: Remove priv parameter from hart_start() callbackAnup Patel1-1/+1
The priv parameter in hart_start() platform callback is 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: sbi_trap: Simplify sbi_trap_handler() APIAnup Patel1-11/+9
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 Patel7-32/+28
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 Patel2-16/+8
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 Patel2-25/+12
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 Patel2-9/+11
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 Patel4-14/+11
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 Patel4-22/+16
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 Patel5-122/+124
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-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-24lib: utils: Move fdt fixup helper routines to a different fileAtish Patra3-187/+204
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 Patra1-0/+116
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-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-19include: sbi_platform: Introduce HART index to HART id tableAnup Patel3-6/+7
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 Patel4-8/+6
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-19lib: Handle failure of sbi_hartid_to_scratch() APIAnup Patel5-8/+28
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 Patel2-6/+7
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 Patel5-7/+7
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 Patel2-0/+22
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>