summaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2022-09-13lib: utils/fdt: Fix DT parsing in fdt_pmu_setup()Anup Patel1-32/+42
This patch does following fixes in fdt_pmu_setup(): 1) If any of the event mapping DT property is absent or too small then don't skip parsing of other DT properties. 2) Return failure if sbi_pmu_add_hw_event_counter_map() fails. 3) Return failure if sbi_pmu_add_raw_event_counter_map() fails. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-13lib: sbi_misaligned_ldst: Set GVA if not emulatingVivian Wang1-2/+2
If a particular misaligned load or store cannot be emulated at all, for the redirected trap, trap.gva is set to 0, but it should be the same as mstatus[h].GVA of the original trap. Fix this so that if the trap is destined for HS-mode, hstatus.GVA is then set correctly. Fixes: 1c4ce74f5128 ("lib: sbi: Set gva when creating sbi_trap_info") Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-09-13lib: sbi_trap: Add helper to get GVA in sbi_trap_regsVivian Wang2-13/+19
The GVA bit is in mstatus on RV64, and in mstatush in RV32. Refactor code handling this in sbi_trap_handler into a helper function to extract GVA from sbi_trap_regs, so that future code accessing GVA can be XLEN-agnostic. Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-09-13docs: pmu: extend bindings example for UnmatchedNikita Shubin1-0/+30
Extend example for Unmatched board to provide SBI PMU bindings for generalized and cache event's where they are applicable. Signed-off-by: Nikita Shubin <n.shubin@yadro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-09-13docs: pmu: fix Unmatched example typoNikita Shubin1-3/+3
bitmap for MHPMCOUNTERx should be 0x18 and not 0x0c, we check against SBI_PMU_FIXED_CTR_MASK which assumes than first 3 bits are dedicated to mcycle, mtime and minstret, u74 has 2 hardware counters. Reported-by: Zhang Xin <zhangxin.xa@gmail.com> Signed-off-by: Nikita Shubin <n.shubin@yadro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-09-01include: sbi: Reduce includes in sbi_pmu.hAnup Patel3-3/+5
The sbi_pmu.h should only include minimal required headers whereas sbi_pmu.c should include all required headers. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-01lib: sbi: Print platform PMU device at boot-timeAnup Patel1-0/+4
Let us print the platform PMU device name at the boot-time so that users know whether the underlying platform has custom per-HART PMU operations. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-01lib: sbi_pmu: Add custom PMU device operationsAnup Patel2-21/+144
We extend SBI PMU implementation to allow custom PMU device operations which a platform can use for platform specific quirks. The custom PMU device operations added by this patch include: 1) Operations to allow a platform implement custom firmware events. These custom firmware events can be SBI vendor extension related events or platform specific per-HART events are not possible to count through HPM CSRs. 2) Operations to allow a platform implement custom way for enabling (or disabling) an overflow interrupt (e.g. T-Head C9xx). Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-01lib: sbi_pmu: Simplify FW counters to reduce memory usageAnup Patel2-45/+36
Currently, we have 32 elements (i.e. SBI_PMU_FW_EVENT_MAX) array of "struct sbi_pmu_fw_event" for each of 128 possible HARTs (i.e. SBI_HARTMASK_MAX_BITS). To reduce memory usage of OpenSBI, we update FW counter implementation as follows: 1) Remove SBI_PMU_FW_EVENT_MAX 2) Remove "struct sbi_pmu_fw_event" 3) Create per-HART bitmap of XLEN bits to track FW counters which are started on each HART 4) Create per-HART uint64_t array to track values of FW counters on each HART. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-01lib: sbi_pmu: Firmware counters are always 64 bits wideAnup Patel1-3/+3
As-per SBI specification, all firmware counters are always 64 bits wide so let us update the SBI PMU implementation to reflect this fact. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-01lib: sbi_pmu: Replace sbi_pmu_ctr_read() with sbi_pmu_ctr_fw_read()Anup Patel3-40/+10
The "read a firmware counter" SBI call should only work for firmware counters so let us replace sbi_pmu_ctr_read() with sbi_pmu_ctr_fw_read() which works only on firmware counters. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-01lib: sbi_pmu: Remove "event_idx" member from struct sbi_pmu_fw_eventAnup Patel1-3/+0
The "event_idx" member of struct sbi_pmu_fw_event is not used anywhere so let us remove it. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-09-01include: Remove sideleg and sedelegRahul Pathak1-2/+0
sideleg and sedeleg csrs are not part of riscv isa spec anymore, these csrs were part of N extension which is removed from the riscv isa specification. These commits removed all traces of these csrs from riscv spec (https://github.com/riscv/riscv-isa-manual) - commit f8d27f805b65 ("Remove or downgrade more references to N extension (#674)") commit b6cade07034d ("Remove N extension chapter for now") Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-23lib: utils: serial: Add Cadence UART driverJun Liang Tan9-6/+199
Add Cadence UART driver Signed-off-by: Jun Liang Tan <junliang.tan@linux.starfivetech.com> Signed-off-by: Wei Liang Lim <weiliang.lim@linux.starfivetech.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-22lib: sbi: Use the official extension name for AIA M-mode CSRsAnup Patel3-7/+7
The arch review of AIA spec is completed and we now have official extension names for AIA: Smaia (M-mode AIA CSRs) and Ssaia (S-mode AIA CSRs). Refer, section 1.6 of the latest AIA v0.3.1 stable specification at https://github.com/riscv/riscv-aia/releases/download/0.3.1-draft.32/riscv-interrupts-032.pdf) Based on above, we update generic library to use "Smaia" extension name for AIA M-mode CSRs. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2022-08-22lib: sbi_illegal_insn: Fix FENCE.TSO emulation infinite trap loopRahul Pathak1-0/+1
In case of missing "FENCE.TSO" instruction implementation, opensbi can emulate the "FENCE.TSO" with "FENCE RW,RW", but mepc was not incremented to continue from the next instruction causing infinite trap. Fixes: cb8271c8 ("lib: sbi_illegal_insn: Add emulation for fence.tso") Signed-off-by: Rahul Pathak <rpathak@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Samuel Holland <samuel@sholland.org>
2022-08-22lib: sbi_trap: Set hstatus.GVA when going to HS-modeVivian Wang1-0/+2
The privileged spec specifies that on a trap to HS-mode, hstatus.GVA should be set to 1 if stval is written with a guest virtual address, and to 0 otherwise. Implement this by setting hstatus.GVA to trap->gva when redirecting traps to HS-mode. Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-22lib: sbi_trap: Set hypervisor CSRs for HS-modeVivian Wang1-5/+7
The hypervisor CSRs hstatus, htval, htinst should always be set if the trap is to be taken in HS-mode, regardless of which mode it came from. Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-22lib: sbi: Set gva when creating sbi_trap_infoVivian Wang3-0/+17
In some cases the sbi_trap_info argument passed to sbi_trap_redirect is created from scratch by filling its fields. Since we previously added a gva field to struct sbi_trap_info, initialize gva in these cases also. Suggested-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-22lib: sbi_trap: Save mstatus[h].GVA in trap->gvaVivian Wang2-3/+20
The machine mode GVA field is available if the hypervisor extension is implemented, and indicates if mtval is a guest virtual address. Add a gva field to sbi_trap_info for this, and in __sbi_expected_trap_hext, save mstatus[h].GVA to it, so that gva indicates if tval is a guest virtual address. If the hypervisor extension is not implemented, always set gva to 0. Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-22include: Add mstatus[h].GVA encodingsVivian Wang1-0/+4
The machine mode GVA field is in mstatus for RV64 and mstatush for RV32, and is available if the hypervisor extension is available. If an exception occurs, we may need to redirect the trap to HS-mode, in which case, hstatus.GVA should be set to same as the machine mode GVA bit. Add MSTATUS_GVA for RV64, MSTATUSH_GVA for RV32, and their SHIFT encodings. The SHIFT index is helpful in assembly code, since field extraction can be implemented in only one register. In pseudocode: - For RV32: gva = (mstatus >> MSTATUS_GVA_SHIFT) & 1; - For RV64: gva = (mstatush >> MSTATUSH_GVA_SHIFT) & 1; Signed-off-by: Vivian Wang <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-08-08Makefile: Fix typo related to object.mkAnup Patel1-1/+1
The "object.mk" name referred in top-level makefile should be "objects.mk". Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08docs: Update documentation for kconfig supportAnup Patel6-14/+36
We update all documentation files to: 1) Remove references to platform specific config.mk file since it is has been removed. 2) Add details about platform specific configs/defconfig and Kconfig files mandatory for each platform. 3) Add required packages in top-level README.md 4) Fix typo releated to object.mk in docs/platform/platform.md Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08platform: Remove redundant config.mk from all platformsAnup Patel16-277/+240
The options defined in config.mk can be specified in objects.mk of each platform so let us remove config.mk from all platforms. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08platform: generic: Use kconfig to set platform version and default nameAnup Patel2-2/+18
The generic platform version and default name should be set based on kconfig options so that users can override it. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08platform: generic: Use kconfig for enabling/disabling overridesAnup Patel4-6/+27
We update generic platform to use kconfig for enabling/disabling platform overrides. We also enable all platform overrides in generic platform defconfig. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/fdt: Use kconfig for enabling/disablingAnup Patel21-6/+66
We update FDT support makefile to use kconfig for enabling/disabling. To avoid compilation errors, we also enable FDT for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/gpio: Use kconfig for enabling/disabling driversAnup Patel5-5/+32
We update gpio drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate gpio drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/i2c: Use kconfig for enabling/disabling driversAnup Patel4-5/+31
We update i2c drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate i2c drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/irqchip: Use kconfig for enabling/disabling driversAnup Patel12-11/+83
We update irqchip drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate irqchip drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/ipi: Use kconfig for enabling/disabling driversAnup Patel10-5/+45
We update ipi drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate ipi drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/timer: Use kconfig for enabling/disabling driversAnup Patel10-5/+45
We update timer drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate timer drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/sys: Use kconfig for enabling/disabling driversAnup Patel5-2/+20
We update system drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate system drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/reset: Use kconfig for enabling/disabling driversAnup Patel5-14/+67
We update reset drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate reset drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08lib: utils/serial: Use kconfig for enabling/disabling driversAnup Patel11-22/+121
We update serial drivers makefile to use kconfig for enabling/disabling drivers. To avoid compile errors, we also enable appropriate serial drivers for each platform. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08Makefile: Compile lib/utils sources separately for each platformAnup Patel3-30/+26
Currently, if same build directory is used to compile two different platforms then lib/utils objects are shared for these platforms. We will be having platform specific configs to enable/disable drivers in lib/utils and select compile time options for lib/utils sources. This means lib/utils sources will now be compiled in a platform specific way. To tackle above, we update top-level Makefile as follows: 1) Don't create libsbiutils.a anymore because this can't be shared between platforms. 2) Compile lib/utils sources separately for each platform. 3) Add comments showing which make rules are for lib/sbi, lib/utils, firmware, and platform sources. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08Makefile: Add initial kconfig support for each platformAnup Patel18-12/+127
We extend the top-level makefile to allow kconfig based configuration for each platform where each platform has it's own set of configs with "defconfig" being the default config. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-08-08scripts: Add Kconfiglib v14.1.0 under scripts directoryAnup Patel11-0/+11156
We adopt Kconfiglib v14.1.0 sources under scripts directory so that top-level OpenSBI makefile can directly use Kconfiglib scripts without expecting users to install a particular version of Kconfiglib on their build system. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Tested-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Atish Patra <atishp@rivosinc.com> Tested-by: Atish Patra <atishp@rivosinc.com>
2022-07-30lib: sbi: Fix printf handling of long longdramforever1-28/+2
Read long long arguments directly using va_arg. Remove original hack for RV32 that read a long long arg as two long args. This un-breaks the case on RV64 where e.g. the long long is followed by an odd number of ints: sbi_printf("%d %lld", (int) 1, (long long) 2LL); Also remove the acnt variable, which is now unused. Signed-off-by: dramforever <dramforever@live.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: utils/serial: Ensure baudrate is non-zero before usingAndrew Jones4-6/+13
RISC-V doesn't generate exceptions on divide-by-zero, but the result, all bits set, is not likely what people expect either. In all cases where we divide by baudrate there's a chance it's zero (when the DT it came from is "bad"). To avoid difficult to debug situations, leave baudrate dependent registers alone when baudrate is zero, as, also in all cases, it appears we can skip initialization of those registers and still [hopefully] have a functioning UART. Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: serial: Clean up coding style in sifive-uart.cAndrew Jones1-3/+8
Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Xiang W <wxjstz@126.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: utils/serial: Initialize platform_uart_data to zeroAndrew Jones6-6/+6
While it doesn't look like there are any current cases of using uninitialized data, let's zero all the UART data members to be safe. Zero may not actually be better than a random number in some cases, so all structure members should still be validated before use, but at least zero is usually easier to debug than some random stack garbage... Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: utils/fdt: Factor out common uart node codeAndrew Jones1-92/+39
Factor out the common code used by the fdt UART node parsers, allowing us to drop duplicate code. Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: sbi: Fix fw_event_map initializationAtish Patra1-1/+1
fw_event_map represents array of firmware events. It should initialized for maximum number of firmware events not counters. Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: sbi: Fix possible buffer overrun in counter validationAtish Patra1-4/+4
The active_events array is accessed with counter ID passed from the supervisor software before the counter ID bound check. This may cause a buffer overrun if a supervisor passes an invalid counter ID. Fix this by moving the access part after the bound check. Reported-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: sbi: Add the bound check for events during config matchAtish Patra2-2/+55
Currently, there is no sanity check for firmware event code. We don't see any issue as Linux kernel driver does a bound check on firmware events already. However, OpenSBI can't assume sane supervisor mode software always. Thus, an invalid event idx can cause a buffer overflow error. For hardware events, the match will fail for invalid event code anyways. However, a search is unecessary if event code is invalid. Add a event ID validation function to solve the issue. Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: sbi: Fix counter index sanity checkAtish Patra1-16/+17
The current implementation computes the possible counter range by doing a left shift of counter base. However, this may overflow depending on the counter base value. In case of overflow, the highest counter id may be computed incorrectly. As per the SBI specification, the respective function should return an error if any of the counter is not valid. Fix the counter index check by avoiding left shifting while doing the sanity checks. Without the shift, the implementation just iterates over the counter mask and computes the correct counter index by adding the base to it. Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-30lib: sbi: Fix sbi_snprintfAndrew Jones1-16/+23
printc would happily write to 'out' even when 'out_len' was zero, potentially overflowing buffers. Rework printc to not do that and also ensure the null byte is written at the last position when necessary, as stated in the snprintf man page. Also, panic if sprintf or snprintf are called with NULL output strings (except the special case of snprintf having a NULL output string and a zero output size, allowing it to be used to get the number of characters that would have been written). Finally, rename a goto label which clashed with 'out'. Fixes: 9e8ff05cb61f ("Initial commit.") Signed-off-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
2022-07-20lib: utils/serial: Update Shakti UART based on latest implementationPrasanna T1-3/+3
The age old version of Shakti UART was upgraded long back, but we missed updating the driver in OpenSBI. The old version of UART is not supported anymore, hence removed the inline comment which is also outdated now. Signed-off-by: Prasanna T <ptprasanna@gmail.com> Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Xiang W <wxjstz@126.com>
2022-07-20lib: sbi_hart: Shorten the code to set MPV bitgagachang1-10/+3
MPV bit is set when the value of next_virt boolean variable equals true. Since the value of next_virt is either 0 or 1, we can set MPV bit without if-else logic. Signed-off-by: Che-Chia Chang <alvinga@andestech.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>