summaryrefslogtreecommitdiff
path: root/lib/utils
AgeCommit message (Collapse)AuthorFilesLines
2021-04-28Add "snps,dw-apb-uart" in uart8250 driver.Tekkaman Ninja1-0/+1
This patch add "snps,dw-apb-uart".compatible ID in uart8250 driver for StarFive VIC-7100. Signed-off-by: Tekkaman Ninja <tekkamanninja@163.com>
2021-03-22include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__Marouene Boubakri1-1/+1
GCC has already a predefined macro __ASSEMBLER__ therefore, it can be used without the need to define a new flag with -D__ASSEMBLY__. This is useful when adding the library to projects having a build system such one can build without the need to make changes. THe build system does not use the Makefile in the sources tree. Signed-off-by: Marouene Boubakri <marouene.boubakri@nxp.com> Signed-off-by: Anup Patel <anup.patel@wdc.com>
2021-01-07lib: utils: Fix shakti uart implementationVijai Kumar K1-2/+6
Fix uart_putc implementation. Due to a bug in the IP, this went unnoticed. Use macros instead of magic numbers to make the code more readable. Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-12-16lib: utils: Remove fdt_domain_get() functionAnup Patel1-47/+36
The fdt_domain_get() function is now redundant because the fdt_domains_populate() function can explicitly register new domains using the sbi_domain_register() function. 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-12-16lib: utils: Allow FDT domain iteration functions to failAnup Patel1-47/+68
We extend fdt_iterate_each_domain() and fdt_iterate_each_memregion() functions to allow underlying iteration function to fail. This will help us catch more domain misconfiguration issues at boot time. 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-12-13lib: utils/libfdt: Upgrade to v1.6.0 releaseDimitri John Ledkov11-154/+356
Sync with libfdt v1.6.0 release source codes. Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-12-04lib: utils: Add helper routines to populate domains from FDTAnup Patel2-0/+446
We add various helper routines to populate domains, iterate domains, iterate domain memregions, and parse HART to domain assignment from the FDT. These helper routines can be used by platform support code and FDT fixup code. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01lib: sbi: Improve system reset platform operationsAnup Patel5-9/+36
To implement the SBI SRST extension, we need two platform operations for system reset: 1) system_reset_check() - This operation will check whether given reset type and reason are supported by the platform 2) system_reset() - This operation will do the actual platform system reset and it will not return if reset type and reason are supported by the platform This patch updates system reset related code everywhere as-per above. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-12-01include: sbi: Remove opensbi specific reset type definesAnup Patel1-3/+3
We can now use the standard SBI SRST extension reset types instead of the opensbi specific (SBI_PLATFORM_RESET_xyz) reset types hence remove related opensbi specific defines. The "platform_" prefix of the reset type parameter of sbi_system_reset() function should also be removed. 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-10-23lib: utils: Implement "ranges" property parsingAtish Patra1-2/+48
The "reg" property in a device node may not be the correct address always. If a parent node defines a "ranges" property, the child address need to be translated with respect to parents address. If the ranges property is not present, it will just use 1:1 translation. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-10-20lib: utils: Update fdt_cpu_fixup() to use current domainAnup Patel1-5/+3
The fdt_cpu_fixup() should disable a HART in DT if the HART is not assigned to the current HART domain. This patch updates fdt_cpu_fixup() accordingly. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-10-20lib: utils: Update fdt_reserved_memory_fixup() to use current domainAnup Patel1-25/+22
Now that each HART is mapped to a domain having a set of memory regions, we update fdt_reserved_memory_fixup() to use domain memory regions for adding reserved memory nodes in device tree. We also change reserved memory node name prefix from "mmode_pmp" to "mmode_resv" because domain memory regions can impact other hardware configurations (such as IOPMP, etc) along with PMP. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-16lib: utils: Improve fdt_cpu_fixup() implementationAnup Patel1-2/+11
The fdt_cpu_fixup() should work fine even if HARTs without MMU are not marked invalid by platform support code. In future, we plan to treat HARTs without MMU as valid in the generic platform support so that we can hold these HARTs in HSM STOPPED state. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-09-01lib: sbi: Remove redundant SBI_HART_HAS_PMP featureAnup Patel1-1/+1
The SBI_HART_HAS_PMP feature is redundant because we already have number of PMP regions returned by sbi_hart_pmp_count(). Checking whether PMP is supported for a HART can be simply done by checking non-zero value returned by sbi_hart_pmp_count(). 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-07-29lib: utils: Use strncmp in fdt_parse_hart_id()Abner Chang1-1/+1
Use strncmp instead of using sbi_strcmp directly in fdt_parse_hart_id() to allow compiling fdt_helper.c by external firmware. Signed-off-by: Abner Chang <abner.chang@hpe.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-07-29lib: utils: Add a macro in libfdt_env.h for strncmpAbner Chang1-0/+1
This commit add a macro to replace strncmp with sbi_strncmp. Signed-off-by: Abner Chang <abner.chang@hpe.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-07-06lib/utils: fdt: Update FDT expand size to 1024 for reserved memory nodeBin Meng1-2/+8
Currently 256 bytes is used for the FDT expand size when fixing up reserved memory node. Increase it to 1024 bytes with an estimated size of 64 bytes per PMP memory region by 16 regions in total. Signed-off-by: Bin Meng <bin.meng@windriver.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-06-19platform: Add support for Shakti C-class SoC from IIT-MVijai Kumar K5-0/+120
C-Class is a member of the SHAKTI family of processors from Indian Institute of Technology - Madras(IIT-M). It is an extremely configurable and commercial-grade 5-stage in-order core supporting the standard RV64GCSUN ISA extensions. https://gitlab.com/shaktiproject/cores/c-class/blob/master/README.md We add OpenSBI support for Shakti C-class SoC. Signed-off-by: Vijai Kumar K <vijai@behindbytes.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-06-15platform/lib: Allow the OS to map the regions that are protected by PMPAlexandre Ghiti1-11/+38
This is achieved by removing the 'no-map' property from the 'reserved-memory' node when PMP is present, otherwise we keep it as it offers a small protection if the OS does not map this region at all. A new callback in platform_override is introduced and allows to fixup the device-tree. It is used here to override this new default behaviour on SiFive Fu540 platforms that has an erratum that prevents S-mode software to access a PMP protected region using 1GB page table mapping. If PMP is present, telling the OS not to map the reserved regions does not add much protection since it only avoids access to regions that are already protected by PMP. But by not allowing the OS to map those regions, it creates holes in the OS system memory map and prevents the use of hugepages which would generate, among other benefits, less TLB miss. Signed-off-by: Alexandre Ghiti <alex@ghiti.fr> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-05-23lib: utils/timer: Initialize all matching timer DT nodesAnup Patel2-13/+26
We can have multiple matching DT nodes of the same FDT timer driver so in this case we should call cold_init() for all matching DT nodes instead of just first matching DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils/ipi: Initialize all matching ipi DT nodesAnup Patel2-13/+24
We can have multiple matching DT nodes of the same FDT ipi driver so in this case we should call cold_init() for all matching DT nodes instead of just first matching DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Add fdt_parse_clint_node() functionAnup Patel3-26/+71
We add fdt_parse_clint_node() function which will be used by fdt_ipi_clint and fdt_timer_clint drivers to parse CLINT details from DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Allow CLINT functions to be used for multiple CLINTsAnup Patel3-51/+110
We extend CLINT cold init function to have a "struct clint_data *" parameter pointing to CLINT details. This allows platforms to use CLINT functions for multiple CLINT instances. When multiple CLINTs are present, the platform can also provide one of the CLINT as reference CLINT for other CLINTs. This will help CLINTs to sync their time value with reference CLINT using a time_delta computed in warm init function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils/irqchip: Initialize all matching irqchip DT nodesAnup Patel2-22/+40
We can have multiple matching DT nodes of the same FDT irqchip driver so in this case we should call cold_init() for all matching DT nodes instead of just first matching DT node. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Extend fdt_find_match() ImplementationAnup Patel6-7/+8
We extend fdt_find_match() implementation by adding node offset parameter which represents the first node to match from. The improved fdt_find_match() can be used to find multiple match nodes. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Allow PLIC functions to be used for multiple PLICsAnup Patel3-32/+45
We extend all PLIC functions to have a "struct plic_data *" parameter pointing to PLIC details. This allows platforms to use these functions for multiple PLIC instances. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-23lib: utils: Remove redundant parameters from PLIC init functionsAnup Patel2-15/+4
The "target_hart" and "hart_count" parameters of PLIC cold and warm init functions are only used for sanity checks and not required in PLIC initialization. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-19lib: sbi_hart: Detect number of supported PMP regionsAnup Patel1-16/+18
It is not mandatory for a RISC-V systems to implement all PMP regions so we have to check all PMPADDRx CSRs to determine excat number of supported PMP regions. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2020-05-19include: sbi: Use scratch pointer as parmeter in HART feature APIsAnup Patel1-3/+4
It makes more sense to have scratch pointer as parameter in HART feature APIs because: 1. We already have scratch pointer at places where these APIs are used. 2. This is consistent with lot of other APIs in sbi_hart.h Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-05-10platform: Move platform features to hartAtish Patra1-2/+2
PMP & performance counters belong to a hart rather than a platform. In addition to that, these features enable reading/writing from a particular csr. Thus, they can be detected and set at runtime rather than compile time. Move PMP/MCOUNTEREN/SCOUNTEREN features to hart and detect them at runtime. 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-05-10lib: utils: Update reserved memory fdt node even if PMP is not presentAtish Patra1-52/+71
As per RISC-V ISA, pmp is not mandatory. Currently, we only add reserved memory node in DT only if PMP is present. That allows supervisor to access the memory where OpenSBI continue to exist without realizing it for non-pmp based platforms. It may result in corrupting OpenSBI. That's why OpenSBI should at least let the supervisor know where it continue to exist. This a best effort service provided by OpenSBI expecting that supervisor software is not buggy and properly sets up its memory after parsing the reserved-memory device tree node. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-05-01lib: utils: Add simple FDT reset frameworkAnup Patel4-0/+126
We add simple reset framework which will select and use reset 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 simple FDT serial frameworkAnup Patel5-0/+214
We add simple serial framework which will select and use serial 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 simple FDT irqchip frameworkAnup Patel3-0/+184
We add simple irqchip framework which will select and use irqchip 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 simple FDT ipi frameworkAnup Patel3-0/+154
We add simple ipi framework which will select and use ipi 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 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 Patel1-1/+1
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-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-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>