summaryrefslogtreecommitdiff
path: root/lib
AgeCommit message (Collapse)Author
2021-11-11lib: sbi: Always enable access for all countersAtish Patra
OpenSBI doesn't use any counters for its own usage. Thus, all the counters can be made accessible for lower privilege mode always. However, the mcountinhibit must be set so that the counter doesn't increment. As a result, we don't have to enable/disable mcounteren at every start/stop. Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2021-11-11lib: sbi: Support sscofpmf extension in OpenSBIAtish Patra
This patch adds sscofpmf extension in pmu module which includes following things. 1. Enable overflow irq when starting a counter. 2. Setting the correct event filters passed from supervisor. 3. Delegating the overflow interrupt to the supervisor. 4. Add RV32 support for sscofpmf. Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2021-11-11lib: sbi: Delegate PMU counter overflow interrupt to S modeAtish Patra
OpenSBI doesn't handle PMU counters for now. Delegate the overflow counter to S-mode always. Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2021-11-11lib: sbi: Detect Sscofpmf extension at run timeAtish Patra
Sscofpmf ISA extension introduces PMU counter overflow and filtering support. It introduces a read only `scountovf` csr that can be used to detect if a hart supports this extension at runtime. However, this feature is only useful if the hart already supports mcounteren and mcountinhibit. Add a dynamic detection mechanism and boot time print message if sscofpmf is present. Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2021-11-11lib: sbi: Update csr_read/write_num for PMUAtish Patra
The Sscofpmf extension introduces mhpmevent[h] csrs to handle filtering /overflow bits in RV32. There is no way to read/write mcountinhibit using mcountinhibit csr using a variable. Updated the support to read/write mhpmevent[h] and mcountinhibit csr. Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Signed-off-by: Atish Patra <[email protected]>
2021-11-08lib: sbi: error handling in fdt_reset_init()Heinrich Schuchardt
The initialization of a reset driver may fail for various reasons, like a PMIC based reset driver not finding the required I2C driver. The return code of the init routine may take other error values than -ENODEV. If the initialization of a reset driver fails, this should not lead to the board hanging. It is enough that the reset driver does not call sbi_system_reset_add_device() to avoid invoking the driver for a device that could not be initialized. Change the return type of fdt_reset_init() to void. Print a message if an error occurs. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Dong Du <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-11-08lib: sbi: move sbi_boot_print_general()Heinrich Schuchardt
Moving the sbi_boot_print_general() call after the sbi_platform_final_init() call allows to print devices initialized in the latter. To keep the overall print sequence the same also move sbi_boot_print_domains(). Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-11-03lib: utils/gpio: use list for driversNikita Shubin
Convert static array to sbi_list. This removes size limitation, makes add/remove more efficient and saves space. Signed-off-by: Nikita Shubin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-11-02lib: sbi: Fix GPA passed to __sbi_hfence_gvma_xyz() functionsAnup Patel
The parameter passed to HFENCE.GVMA instruction in rs1 register is guest physical address right shifted by 2 (i.e. divided by 4). Unfortunately, we overlooked the semantics of rs1 registers for HFENCE.GVMA instruction and never right shifted guest physical address by 2. This issue did not manifest for hypervisors till now because all H-extension implementations (such as QEMU, Spike, Rocket Core FPGA, etc) we tried till now were conservatively flushing everything upon any HFENCE.GVMA instruction. This patch fixes GPA passed to __sbi_hfence_gvma_vmid_gpa() and __sbi_hfence_gvma_gpa() functions. Fixes: 331ff6a162c1 ("lib: Support stage1 and stage2 tlb flushing") Reported-by: Ian Huang <[email protected]> Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Dong Du <[email protected]>
2021-11-02include: sbi_utils: Introduce an helper to get fdt base addressAlexandre Ghiti
This simply adds an helper to get fdt address which is more explicit than sbi_scratch_thishart_arg1_ptr. Signed-off-by: Alexandre Ghiti <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-11-02lib: sbi: Refine addr format in sbi_printfDong Du
Although we have PRILX to help us print unsigned long without considering the 32bit/64bit differences, there are still some places using 08lx and 016lx manually --- leading to redundant code. This commit fixes the issue by using PRILX all the time. Signed-off-by: Dong Du <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-11-02lib: utils/reset: Register separate GPIO system reset devicesAnup Patel
Now that sbi_system support multiple system reset devices, we should register separate devices for GPIO restart and GPIO poweroff because DT describes these as separate devices with different compatible strings. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Dong Du <[email protected]>
2021-10-21lib: utils/irqchip: Automatically delegate T-HEAD PLIC accessSamuel Holland
The T-HEAD PLIC implementation requires setting a delegation bit to allow access from S-mode. Now that the T-HEAD PLIC has its own compatible string, set this bit automatically from the PLIC driver, instead of reaching into the PLIC's MMIO space from another driver. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-10-20Makefile: Add build time and compiler info stringWei Fu
When we are doing opensbi development, we want to know the build time and compiler info for debug purpose. To enable this message, please add "BUILD_INFO=y", like: ``` make BUILD_INFO=y ``` NOTE: Using `BUILD_INFO=y` without specifying SOURCE_DATE_EPOCH will violate "reproducible builds". So it's ONLY for development and debug purpose, and should NOT be used in a product which follows "reproducible builds". Signed-off-by: Wei Fu <[email protected]> Reviewed-by: Anup Patel <[email protected]> Reviewed-by: Alistair Francis <[email protected]>
2021-10-18lib: sbi: system reset with invalid parametersHeinrich Schuchardt
The SBI specification requires that sbi_system_reset() returns SBI_ERR_INVALID_PARAM if reset_type or reset_reason are not valid. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Xiang W <[email protected]>
2021-10-18lib: sbi: Save context for all non-retentive suspend typesAnup Patel
Instead of saving context only for default non-retentive suspend, we should save context for all non-retentive suspend types. Fixes: 74756891cc35 ("lib: sbi: Implement SBI HSM suspend function") Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Dong Du <[email protected]> Reviewed-by: Xiang W <[email protected]>
2021-10-11lib: sbi: add priority for reset handlerNikita Shubin
Let's make system_reset_check returning priority instead of only true/false. In that case 0 - means not supported, and anything above means priority that makes existing reset handlers being used in first place, unless it is decided to lower their priority. The handler with the most priority wins. Signed-off-by: Nikita Shubin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-10-11lib: sbi: convert reset to listNikita Shubin
To support different handlers for different types of resets, we are adding a sbi_list of restart handlers. Instead of sbi_system_reset_set_device we use sbi_system_reset_add_device to reflect the actual meaning. Signed-off-by: Nikita Shubin <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-10-01lib: utils: identify supported GPIO reset methodsHeinrich Schuchardt
The GPIO reset driver supports reset and poweroff. But not all boards support both. gpio_system_reset_check() must detect this situation. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-09-26lib: utils/reset: use sbi_timer_mdelay() in gpio reset driverAnup Patel
We should use sbi_timer_mdelay() instead of custom gpio_mdelay() in the gpio reset driver. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2021-09-26lib: sbi: Add generic timer delay loop functionAnup Patel
We now have frequency of the timer device provided by the platform support so we can emulate desired delay using a loop where the number loop iterations are based on timer frequency. This patch provides sbi_timer_delay_loop() for above purpose. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2021-09-26lib: sbi: Print timer frequency at boot timeAnup Patel
We now have frequency in timer device instance provided by platform so let's print timer frequency as part of the boot prints. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2021-09-26lib: sbi: Add timer frequency to struct sbi_timer_deviceAnup Patel
Generic mdelay() and udelay() functions can be provided by the sbi_timer framework if timer frequency is available in the timer instance provided by the platform support or timer driver. This patch adds timer frequency (timer_freq) member in the struct sbi_timer_device for above purpose. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2021-09-26lib: utils/fdt: Add fdt_parse_timebase_frequency() functionAnup Patel
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 <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Xiang W <[email protected]>
2021-09-22lib: sbi: Add BUG() macro for csr_read/write_num() and misa_string()Xiang W
We use BUG() macro in csr_read_num(), csr_write_num(), and misa_string() functions for unhandled cases. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-09-22lib: sbi: fix ctz bugXiang W
The original version of ctz will cause an endless loop, if the parameter passed in is 0. This commit fixes this bug. Signed-off-by: Xiang W <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-09-14lib: utils/reset: Add a sunxi watchdog reset driverSamuel Holland
One of the watchdogs in the D1 SoC provides a "soft reset" function, which allows software to immediately reset the entire SoC. Add a driver so it can implement the SBI system reset function. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-09-14lib: utils/reset: Sort fdt_reset driver listSamuel Holland
In preparation for adding a new fdt_reset driver, ensure the existing lists are sorted alphabetically. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-09-03lib: sbi: Refine the way to construct platform featuresDong Du
sbi_platform_get_features_str() uses sbi_snprintf() to construct the features_str. However, it passes the wrong length value (i.e., the nfstr), which should be (nfstr-offset) as the starting point of str (i.e., features_str + offset) changes. This commit also checks the return value of snprintf, and handles the corner case that the string buffer is full. Signed-off-by: Dong Du <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-09-03lib: sbi: Checking fifo validness in sbi_fifo_is_empty and is_fullDong Du
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-30lib: sbi: protect dprintf output with spinlockDong Du
Avoid getting messages from multiple harts (using dprintf and printf) concurrently with a spinlock serializaing calls to sbi_dprintf(), sbi_printf() and sbi_puts() Signed-off-by: Dong Du <[email protected]> Reviewed-by: Xiang W <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-08-30lib: sbi: Correct typo in faults delegation CSR nameRahul Pathak
Correcting the name of faults delegation CSR %s/mfdeleg/medeleg Signed-off-by: Rahul Pathak <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-08-20lib: sbi_trap: Restore redirect for access faultsSamuel Holland
commit 764a17d852a8 ("lib: sbi: Implement firmware counters") added switch cases for CAUSE_LOAD_ACCESS and CAUSE_STORE_ACCESS. This caused them to stop being redirected to U or S mode, as that is handled in the default switch case. As a result, an error in userspace could cause the system to hang. Fix this by allowing the acces fault case to fall through to the default case. Fixes: 764a17d852a8 ("lib: sbi: Implement firmware counters") Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Atish Patra <[email protected]> Reviewed-by: Bin Meng <[email protected]>
2021-08-20lib: sbi: Fix bug in sbi_ecall_rfence that misses checkingDong Du
In sbi_ecall_rfence_handler, it will compare the funcid with REMOTE_HFENCE_GVMA and REMOTE_HFENCE_VVMA_ASID. Later it check whether the misa includes H-extension. This checking is incomplete which misses REMOTE_HFENCE_GVMA_VMID and REMOTE_HFENCE_VVMA. Fix the issue by updating the checking range. Signed-off-by: Dong Du <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-14lib: utils/timer: Simplify MTIMER synchronizationAnup Patel
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-14lib: utils/timer: Allow ACLINT MTIMER supporting only 32-bit MMIOAnup Patel
We can have ACLINT MTIMER devices which only support 32-bit MMIO accesses on RV64 system so this patch adds a boolean DT property "mtimer,no-64bit-mmio" to detect this from MTIMER DT node. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-14lib: utils/fdt: Extend fdt_parse_aclint_node() functionAnup Patel
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-14lib: utils: Extend fdt_get_node_addr_size() for multiple register setsAnup Patel
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-14lib: utils/timer: Allow separate base addresses for MTIME and MTIMECMPAnup Patel
We extend the ACLINT library to support separate base addresses for MTIME and MTIMECMP registers. Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-08-07lib: utils/fdt: Change addr and size to uint64_tBin Meng
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 <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-08-07lib: sbi: Fix bug in strncmp function when count is 0Dong Du
No need to compare characters when the count turns to 0. Fix the issue in sbi_strncmp. Signed-off-by: Dong Du <[email protected]> Reviewed-by: Bin Meng <[email protected]> Reviewed-by: Anup Patel <[email protected]>
2021-07-27lib: utils: support both of gpio-poweroff, gpio-resetHeinrich Schuchardt
The generic GPIO reset driver has two entries in the match table: "gpio-poweroff", "gpio-reset". Only the first entry is considered by fdt_reset_init(). Define "gpio-poweroff" and "gpio-reset" as compatibility strings of two separate reset drivers. They still can share code. Fixes: e3d6919d10d7 ("lib: utils/reset: Add generic GPIO reset driver") Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-07-27lib: utils: remove unused variable in fdt_reset_initHeinrich Schuchardt
The value of variable current_driver is unused. Remove the variable. Signed-off-by: Heinrich Schuchardt <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-07-17lib: utils/reset: Add generic GPIO reset driverGreen Wan
We add generic GPIO reset driver inspired from gpio-restart and gpio-poweroff drivers of Linux kernel. Signed-off-by: Green Wan <[email protected]> Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-07-17lib: utils/gpio: Add minimal SiFive GPIO driverGreen Wan
We add a minimal SiFive GPIO driver so that we can do GPIO based system power-off and reset. Signed-off-by: Green Wan <[email protected]> Signed-off-by: Anup Patel <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-07-17lib: utils/gpio: Add simple FDT based GPIO frameworkAnup Patel
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-07-17lib: utils/gpio: Add generic GPIO configuration libraryAnup Patel
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-07-17lib: utils/fdt: Add fdt_parse_phandle_with_args() APIAnup Patel
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 <[email protected]> Reviewed-by: Atish Patra <[email protected]>
2021-07-11lib: utils: Drop dependency on libgcc by importing part of FreeBSD's libquadJessica Clarke
We only need libgcc for 64-bit division on RV32. Whilst GCC toolchains bundle libgcc, Clang toolchains tend not to ship libclang_rt.builtins given every compiler is a cross-compiler for every target and so you would need a silly number of builds of it, with only the native library available; only vendor-provided Clang toolchains specifically for bare metal cross-compiling are likely to provide it. Thus, import part of FreeBSD's implementation of the division support functions needed and stop linking against libgcc. Signed-off-by: Jessica Clarke <[email protected]> Reviewed-by: Anup Patel <[email protected]> Tested-by: Anup Patel <[email protected]>
2021-07-11lib: sbi: Fix sbi_pmu_exit() for systems not having MCOUNTINHIBIT csrAnup Patel
The sbi_pmu_exit() crashes on systems not having MCOUNTINHIBIT csr so to fix this we check SBI_HART_HAS_MCOUNTINHIBIT feature in sbi_pmu_exit() and do nothing if it is not available. Fixes: 13d40f21d588 ("lib: sbi: Add PMU support") Signed-off-by: Anup Patel <[email protected]>