summaryrefslogtreecommitdiff
path: root/include
AgeCommit message (Collapse)AuthorFilesLines
2021-09-26lib: utils/fdt: Add fdt_parse_timebase_frequency() functionAnup Patel1-0/+2
We add fdt_parse_timebase_frequency() function which can be used by ACLINT mtimer driver and platform code to get timebase frequency. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-09-22lib: sbi: add some macros to detect BUG at runtimeXiang W1-0/+20
Three macros are added. One is called BUG, which is used to put in an unreachable branch. One is called BUG_ON, which is used to check bugs and assert conditions are opposite. One is called SBI_ASSERT, used for assertion checking. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-09-03lib: sbi: Checking fifo validness in sbi_fifo_is_empty and is_fullDong Du1-2/+2
As other exported fifo functions, we should check whether the fifo is valid in sbi_fifo_is_empty and sbi_fifo_is_full. To this end, this patch changes the retval from bool to int, and the two functions will return SBI_EINVAL in the case the fifo is invalid. Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-14lib: utils/timer: Simplify MTIMER synchronizationAnup Patel1-1/+6
We simplify MTIMER synchronization as follows: 1) Detect MTIMER devices with unique (or non-shared) MTIME register at boot-time 2) Select first MTIMER device with no associated HART as our reference MTIMER device 3) Only synchronize MTIMER devices with unique (or non-shared) MTIME register using reference MTIMER device 4) Directly update the MTIME register at time of synchronization because MTIME is a read/write register. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-14lib: utils/fdt: Extend fdt_parse_aclint_node() functionAnup Patel1-1/+2
The fdt_parse_aclint_node() is used to parse DT node for SiFive CLINT, ACLINT MTIMER, and ACLINT MSWI devices. The ACLINT MTIMER has undergone following changes: 1) MTIMER DT node now requires separate addresses in for MTIME register and MTIMECMPx registers in the reg DT property. 2) MTIMER DT node might have no interrupts-extended DT property when the MTIMER device has no associated HARTs (i.e. the MTIMER device has no MTIMECMPx registers) This patch extends fdt_parse_aclint_node() to handle above mentioned changes in ACLINT MTIMER DT bindings. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-14lib: utils: Extend fdt_get_node_addr_size() for multiple register setsAnup Patel1-2/+2
We add "index" parameter to fdt_get_node_addr_size() API so that calling function can specify index of desired register set. This will allow fdt_get_node_addr_size() to handle DT nodes with multiple register sets. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-14lib: utils/timer: Allow separate base addresses for MTIME and MTIMECMPAnup Patel1-5/+11
We extend the ACLINT library to support separate base addresses for MTIME and MTIMECMP registers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-08-07lib: utils/fdt: Change addr and size to uint64_tBin Meng1-3/+3
The maximum address and size encoded in DT are 64-bit numbers, so we should use uint64_t for 'addr' and 'size' in fdt_get_node_addr_size(). Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-07-17include: types: Use __builtin_offsetof when supportedAlex Richardson1-1/+7
Clang provides a __builtin_offsetof which can be detected using __has_builtin(). Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-07-17firmware: use __SIZEOF_LONG__ for field offsets in fw_dynamic.hAlex Richardson1-6/+6
The fields are of type unsigned long and are not pointers. While this happens to be the same for RV32/RV64, it is not correct when compiling for a CHERI-RISC-V system where pointers are twice the size of long. Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-07-17lib: utils/gpio: Add simple FDT based GPIO frameworkAnup Patel1-0/+34
We add a simple FDT based GPIO framework which is built on top of generic GPIO library. The phandle of FDT GPIO chip DT node is treated as unique GPIO chip ID required by the generic GPIO library. The FDT based GPIO chip drivers will be probed on-demand from fdt_gpio_pin_get() called by the GPIO client drivers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-07-17lib: utils/gpio: Add generic GPIO configuration libraryAnup Patel1-0/+99
We add generic GPIO configuration library which is independent of hardware description format (FDT or ACPI). The OpenSBI platform support or GPIO drivers can register GPIO chip instances which can be discovered and used by different GPIO clients. Each GPIO chip instance has a unique ID which can be used by GPIO clients to lookup GPIO chip instance. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-07-17lib: utils/fdt: Add fdt_parse_phandle_with_args() APIAnup Patel1-0/+11
The libfdt project does not have a generic API to parse phandle with args from a DT node so we add fdt_parse_phandle_with_args() for this purpose. This new API will be useful to FDT based drivers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-07-11firmware: Define a macro for version of struct fw_dynamic_infoBin Meng1-1/+2
Avoid using a magic number, instead use a macro for the version of struct fw_dynamic_info. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-07-11lib: sbi: Implement SBI PMU extensionAtish Patra1-0/+1
RISC-V SBI specfication 0.3 defines a PMU extension that allows supervisor mode to start/stop/configure pmu related events. This patch implements all of the functionality defined in the specification. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11utils: fdt: Add fdt helper functions to parse PMU DT nodesAtish Patra1-0/+46
The PMU DT node bindings are defined in docs/pmu_support.md Add few fdt helper functions to parse the DT node and update the event-counter mapping tables. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11lib: sbi: Add PMU supportAtish Patra3-1/+212
RISC-V SBI v0.3 specification defined a PMU extension to configure/start/stop the hardware/firmware pmu events. Implement PMU support in OpenSBI library. The implementation is agnostic of event to counter mapping & mhpmevent value configuration. That means, it expects platform hooks will be used to set up the mapping and provide the mhpmevent value at runtime. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11lib: sbi: Add PMU specific platform hooksAtish Patra1-0/+39
A platform hook to initialize PMU allows platform vendors to provide their own mechanism to define pmu event-counter mappings in addition to the DT based approach. Another platform hook that allows platform vendors customize the final mhpmevent value configuration. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11include: Add a list empty check functionAtish Patra1-0/+11
Implement a list helper function that checks for empty lists. Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11lib: sbi: Detect number of bits implemented in mhpmcounterAtish Patra1-0/+1
RISC-V privilege specification allows the implementation to have less than 64 bits. Add a function to detect the number of implemented bits in mhpmcounter dynamically at runtime. Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-07-11lib: sbi: Detect mcountinihibit support at runtimeAtish Patra1-1/+3
RISC-V ISA specification v1.11 defined mcountinhibit CSR that allows software to stop any counter from incrementing. The SBI PMU extension depends on this CSR support in hardware. Define mcountinhibit as a hart specific feature and detect it at runtime. Reviewed-by: Anup Patel <anup.patel@wdc.com> Signed-off-by: Atish Patra <atish.patra@wdc.com>
2021-06-24platform: Replace CLINT library usage with ACLINT libraryAnup Patel1-41/+0
The ACLINT devices are backward compatible with SiFive CLINT so we replace all CLINT library usage in various platforms with ACLINT library. As a result of this replacement, the CLINT library is not used by any part of OpenSBI hence we remove it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-06-24lib: utils: Add FDT parsing API common for both ACLINT and CLINTAnup Patel1-4/+3
We add fdt_parse_aclint_node() which can parse both ACLINT and CLINT DT nodes. This means fdt_parse_clint_node() is not required anymore 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: Xiang W <wxjstz@126.com>
2021-06-24lib: utils/ipi: Add ACLINT MSWI libraryAnup Patel1-0/+33
We add common ACLINT MSWI library similar to the CLINT library so that OpenSBI platforms can use it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-06-24lib: utils/timer: Add ACLINT MTIMER libraryAnup Patel1-0/+41
We add common ACLINT MTIMER library similar to the CLINT library so that OpenSBI platforms can use it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-06-12lib: sbi: Fix GET_F64_REG inline assemblyCharles Papon1-3/+16
Current, GET_F64_REG() macro does not generate correct inline assembly for the RV32 systems. This patch provides separate definitions of GET_F64_REG() macro for RV32 and RV64 systems. Signed-off-by: Charles Papon <charles.papon.90@gmail.com> Signed-off-by: Anup Patel <anup.patel@wdc.com>
2021-06-02lib: sbi_scratch: remove owner from sbi_scratch_alloc_offsetHeinrich Schuchardt1-1/+1
The parameter owner of function sbi_scratch_alloc_offset() is never used. The scratch memory is small. We should not use it for debug information in future. Hence eliminate the parameter. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-05-14lib: sbi: Have spinlock checks return boolDaniel Schaefer1-2/+2
spin_lock_check already returned bool in the source file but not in the header. With some toolchains that causes an error, as it should. Because it and related functions all essentially return a bool, we can use this opportunity to change them. Signed-off-by: Daniel Schaefer <git@danielschaefer.me> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-05-06lib: utils/serial: Add support for Gaisler APBUARTDaniel Cederman2-0/+20
This patch adds support for the UART used by the NOEL-V processor. Cobham Gaisler's NOEL-V RISC-V processor IP is available under GPL and commercial license and is described in more detail at https://www.gaisler.com/noelv. Signed-off-by: Daniel Cederman <cederman@gaisler.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2021-04-28lib: sbi: Simplify HSM platform operationsAnup Patel2-82/+32
Instead of having hsm_start(), hsm_stop() and hsm_suspend() callbacks in platform operations, it will be much simpler for HSM driver to directly register these operations as a device to the sbi_hsm implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-28lib: sbi: Simplify system reset platform operationsAnup Patel5-53/+17
Instead of having system_reset_check() and system_reset() callbacks in platform operations, it will be much simpler for reset driver to directly register these operations as a device to the sbi_system implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-28lib: sbi: Simplify ipi platform operationsAnup Patel4-40/+18
Instead of having ipi_send() and ipi_clear() callbacks in platform operations, it will be much simpler for ipi driver to directly register these operations as a device to sbi_ipi implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-28lib: sbi: Simplify timer platform operationsAnup Patel4-69/+25
Instead of having timer_value(), timer_event_start(), and timer_event_stop() callbacks in platform operations, it will be much simpler for timer driver to directly register these operations as device to the sbi_timer implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-28lib: sbi: Simplify console platform operationsAnup Patel7-52/+16
Instead of having console_putc() and console_getc() callbacks in platform operations, it will be much simpler for console driver to directly register these operations as device to the sbi_console implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-04-28lib: sbi: Remove domains_root_regions() platform callbackAnup Patel1-18/+0
We now have sbi_domain_root_add_memregion() which allows platform support to add root domain regions at boot-time so let's remove the domains_root_regions() platform callback which was added for this purpose. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-04-22lib: utils: reset: Add T-HEAD sample platform reset driverGuo Ren2-0/+8
This driver is for T-HEAD test chip, fpga. It could work with all T-HEAD riscv processors: C9xx series. example1: (Using io-regs for reset) reset: reset-sample { compatible = "thead,reset-sample"; plic-delegate = <0xff 0xd81ffffc>; entry-reg = <0xff 0xff019050>; entry-cnt = <4>; control-reg = <0xff 0xff015004>; control-val = <0x1c>; csr-copy = <0x7f3 0x7c0 0x7c1 0x7c2 0x7c3 0x7c5 0x7cc>; }; example2: (Using csr-regs for reset) reset: reset-sample { compatible = "thead,reset-sample"; plic-delegate = <0xff 0xd81ffffc>; using-csr-reset; csr-copy = <0x7c0 0x7c1 0x7c2 0x7c3 0x7c5 0x7cc 0x3b0 0x3b1 0x3b2 0x3b3 0x3b4 0x3b5 0x3b6 0x3b7 0x3a0>; }; example3: (Only delegate plic enable to S-mode) reset: reset-sample { compatible = "thead,reset-sample"; plic-delegate = <0xff 0xd81ffffc>; }; After this patch, all T-HEAD c9xx would use platform/generic with fw_dynamic as default: CROSS_COMPILE=riscv64-linux-gnu- PLATFORM=generic FW_PIC=y /usr/bin/make The platform/thead will be deprecated. Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-04-13lib: sbi: Make sbi_domain_memregion_initfw() a local functionAnup Patel1-3/+0
The sbi_domain_memregion_initfw() is no longer used outside sbi_domain.c so let's make it a local function. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-13lib: sbi: Make the root domain instance global variableAnup Patel1-0/+3
We make the the root domain instance global variable so that platform support and drivers can iterate over the root domain regions. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-13lib: sbi: Add sbi_domain_root_add_memregion() APIAnup Patel1-0/+8
We should allow platform support to add more root memory regions before domains are finalized. This will help platform support to protect critical M-mode only resources. This patch adds sbi_domain_root_add_memregion() API for above described purpose. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-13lib: sbi: Add sbi_domain_memregion_init() APIAnup Patel1-0/+14
This patch adds sbi_domain_memregion_init() helper API which can be used by platform support to initialize a domain memory region before adding it to the root domain. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
2021-04-09lib: sbi: Replace test-and-set locks by ticket locksChristoph Muellner1-11/+22
Replace the test-and-set spinlock implementation with ticket locks in order to get fairness (in form of FIFO order). The implementation uses a 32-bit wide struct, which consists of two 16-bit counters (owner and next). This is inspired by similar spinlock implementations on other architectures. This allows that the code works for both, RV32 and RV64. Signed-off-by: Christoph Muellner <cmuellner@linux.com> Reviewed-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Xiang W <wxjstz@126.com>
2021-04-09include: sbi: Allow direct initialization via SPIN_LOCK_INIT()Christoph Muellner1-1/+1
The current implementation of SPIN_LOCK_INIT() provides the spinlock to be initialized as reference. This does not allow a direct initialization of the spinlock object at the creation site. Let's pass the spinlock directly instead (like Linux does as well) and adjust all users of the macro (in fact there is only one user). Signed-off-by: Christoph Muellner <cmuellner@linux.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-04-09include: types: Add __aligned(x) to define the minimum alignementChristoph Muellner1-0/+1
The __aligned(x) macro is a common wrapper around compiler's aligned attribute, which allow to define the minimum alignement of a data type. Let's add this macro. Signed-off-by: Christoph Muellner <cmuellner@linux.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-04-05lib: fix csr detect supportXiang W1-0/+3
csr_read_allowed/csr_read_allowed requires trap.case to detect the results, but if no exception occurs, the value of trap.case will remain unchanged, which makes the detection results unreliable. Add code to initialize trap.case to 0. Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-04-01firware: optimize the exception exit codeXiang W1-1/+1
There are two copies of the same abnormal exit code, this patch deletes one Signed-off-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-04-01lib/utils: Drop the 'compat' parameter of fdt_plic_fixup()Bin Meng1-2/+1
At present fdt_plic_fixup() accepts a 'compat' parameter for PLIC compatible string. In preparation to support the new DT bindings, drop this and use "riscv,plic0" directly in fdt_plic_fixup(). Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-03-22include: headers: Replace __ASSEMBLY__ with __ASSEMBLER__Marouene Boubakri6-10/+10
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-03-19firmware: Support position independent executionVincent Chen1-0/+14
Enable OpenSBI to support position independent execution. Because the position independent code will cause an additional GOT reference when accessing the global variables, it will reduce performance a bit. Therefore, the position independent execution is disabled by default. Users can through specifying "FW_PIC=y" on the make command to enable this feature. In theory, after enabling position-independent execution, the OpenSBI can run at arbitrary address with appropriate alignment. Therefore, the original relocation mechanism will be skipped. In other words, OpenSBI will directly run at the load address without any code movement. Signed-off-by: Vincent Chen <vincent.chen@sifive.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2021-03-12include: sbi: SBI function IDs for RFENCE extensionHeinrich Schuchardt1-4/+4
The SBI function IDs for RFENCE extension must match the SBI specification. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2021-03-03include: sbi: Upgrade SBI implementation version to v0.3Anup Patel1-1/+1
The OpenSBI SBI implementation is now compliant with latest draft SBI v0.3 specification so let's upgrade SBI implementation version. This will also help HSM suspend function detection in S-mode because HSM suspend function is only present when HSM extension is present and SBI implementation version is 0.3 (or higher). Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>