diff options
| author | Bo Gan <ganboing@gmail.com> | 2024-03-05 18:35:40 -0800 |
|---|---|---|
| committer | Anup Patel <anup@brainfault.org> | 2024-03-11 10:56:02 +0530 |
| commit | 81e3ba77a6dae8763972fffb6e4a833adccbeb1b (patch) | |
| tree | 9609952f22d5fa24ebeb95c5836d9ea881a5e72a /include | |
| parent | ddf3b649f1edd9eb5ad171c7faadf34acfb942f0 (diff) | |
| download | opensbi-81e3ba77a6dae8763972fffb6e4a833adccbeb1b.tar.gz opensbi-81e3ba77a6dae8763972fffb6e4a833adccbeb1b.tar.bz2 opensbi-81e3ba77a6dae8763972fffb6e4a833adccbeb1b.zip | |
lib: sbi: call platform load/store emulators
sbi_load/store_access_handler now tries to call platform emulators
if defined. Otherwise, redirects the fault. If the platform code
returns failure, this means the H/S/U has accessed the emulated
devices in an unexpected manner, which is very likely caused by
buggy code in H/S/U. We redirect the fault, so lower privileged
level can get notified, and act accordingly. (E.g., oops in Linux)
We let the handler truly fail if the trap was originated from M mode.
In this case, something must be very wrong and we should just fail.
Signed-off-by: Bo Gan <ganboing@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/sbi/sbi_platform.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index f962aa46..581935ab 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -48,6 +48,7 @@ #include <sbi/sbi_error.h> #include <sbi/sbi_scratch.h> #include <sbi/sbi_version.h> +#include <sbi/sbi_trap_ldst.h> struct sbi_domain_memregion; struct sbi_ecall_return; @@ -683,6 +684,50 @@ static inline int sbi_platform_vendor_ext_provider( return SBI_ENOTSUPP; } +/** + * Ask platform to emulate the trapped load + * + * @param plat pointer to struct sbi_platform + * @param rlen length of the load: 1/2/4/8... + * @param addr virtual address of the load. Platform needs to page-walk and + * find the physical address if necessary + * @param out_val value loaded + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_emulate_load(const struct sbi_platform *plat, + int rlen, unsigned long addr, + union sbi_ldst_data *out_val) +{ + if (plat && sbi_platform_ops(plat)->emulate_load) { + return sbi_platform_ops(plat)->emulate_load(rlen, addr, + out_val); + } + return SBI_ENOTSUPP; +} + +/** + * Ask platform to emulate the trapped store + * + * @param plat pointer to struct sbi_platform + * @param wlen length of the store: 1/2/4/8... + * @param addr virtual address of the store. Platform needs to page-walk and + * find the physical address if necessary + * @param in_val value to store + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_emulate_store(const struct sbi_platform *plat, + int wlen, unsigned long addr, + union sbi_ldst_data in_val) +{ + if (plat && sbi_platform_ops(plat)->emulate_store) { + return sbi_platform_ops(plat)->emulate_store(wlen, addr, + in_val); + } + return SBI_ENOTSUPP; +} + #endif #endif |
