summaryrefslogtreecommitdiff
path: root/lib/sbi/sbi_emulate_csr.c
AgeCommit message (Collapse)AuthorFilesLines
2023-01-06treewide: Replace TRUE/FALSE with true/falseBin Meng1-5/+5
C language standard uses true/false for the boolean type. Let's switch to that for better language compatibility. Signed-off-by: Bin Meng <bmeng@tinylab.org> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Samuel Holland <samuel@sholland.org> Tested-by: Samuel Holland <samuel@sholland.org>
2022-05-07lib: sbi: Remove MCOUNTEREN and SCOUNTEREN hart featuresAnup Patel1-2/+2
If a hart implements privileged spec v1.10 (or higher) then we can safely assume that [m|s]counteren CSR are present and we don't need MCOUNTEREN and SCOUNTEREN as hart features. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Atish Patra <atishp@rivosinc.com>
2021-03-22lib: sbi: illegal CSR 0x306 access in hpm_allowed()Heinrich Schuchardt1-5/+14
The trap handler sbi_emulate_csr_read() invokes hpm_allowed() which reads CSR 0x306 (mcounteren). The K210 does not support CSR 0x306. While trying to handle a trap occurring in S-mode code this creates an additional trap in M-mode. This results in failure to redirect to S-mode and the system hanging in sbi_hart_hang(). In hart_detect_features() we have already determined if CSR 0x306 is available and stored that information in the scratch area. We can use this information to decide if CSR 0x306 shall be accessed in hpm_allowed() and thus avoid the M-mode trap. Likewise if CSR scounteren is not available we have to avoid reading CSR 0x106. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Anup Patel <anup.patel@wdc.com>
2020-09-01lib: sbi: Improve HPM CSR read/write emulationAnup Patel1-72/+75
We improve HPM CSR read/write emulation as follows: 1. Fail for unimplemented counters so that trap is redirected to S-mode which can further help debugging S-mode software. 2. Check permissions in both MCOUNTEREN and SCOUNTEREN for HS-mode and U-mode. 3. Don't check permissions for TIME CSR because we emulate TIME CSR for both Host (HS/U-mode) and Guest (VS/VU-mode). Also, faster TIME CSR read is very helpful for good performance of S-mode software. 4. Don't emulate S-mode CSR read/write to M-mode HPM CSRs because these should not be accessible to S-mode software. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2020-03-28include: sbi_console: Remove scratch parameter from sbi_dprintf()Anup Patel1-5/+2
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 Patel1-12/+12
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-28lib: sbi_emulate_csr: Remove scratch and hartid parameterAnup Patel1-6/+9
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-08include: Move bits related defines and macros to sbi_bitops.hAnup Patel1-1/+1
The right location for all bits related defines and macros is sbi_bitops.h hence this patch. With this patch, the sbi_bits.h is redundant so we remove it. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
2019-09-30lib: Emulate HTIMEDELTA CSR for platforms not having TIME CSRAnup Patel1-11/+59
For platforms not having TIME CSR, we trap-n-emulate TIME CSR read/write in OpenSBI. Same rationale applies to HTIMEDELTA CSR as well so we trap-n-emulate HTIMEDELTA CSR for platforms not having TIME CSR. Signed-off-by: Anup Patel <anup.patel@wdc.com>
2019-08-09lib: Use sbi_dprintf() for invalid CSRsAnup Patel1-4/+4
We should sbi_dprintf() instead of sbi_printf() for invalid CSRs because we are forwarding invalid CSR access back to S-mode. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
2019-06-19lib: Move sbi core library to lib/sbiAtish Patra1-0/+137
Signed-off-by: Atish Patra <atish.patra@wdc.com> Acked-by: Anup Patel <anup.patel@wdc.com>