lib: sbi: Only register available extensions

When an extension implements a probe function it means there's a
chance that the extension is not available. Use this function in the
register_extensions callback to determine if the extension should be
registered at all. Where the probe implementation is simple, just
open code the check.

Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Andrew Jones
2023-05-15 13:12:37 +02:00
committed by Anup Patel
parent 042f0c3ea2
commit 8b952d4fcd
6 changed files with 35 additions and 22 deletions

View File

@@ -22,24 +22,11 @@ static inline unsigned long sbi_ecall_vendor_id(void)
(SBI_EXT_VENDOR_END - SBI_EXT_VENDOR_START));
}
static int sbi_ecall_vendor_probe(unsigned long extid,
unsigned long *out_val)
{
if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()))
*out_val = 0;
else
*out_val = 1;
return 0;
}
static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid,
const struct sbi_trap_regs *regs,
unsigned long *out_val,
struct sbi_trap_info *out_trap)
{
if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()))
return SBI_ERR_NOT_SUPPORTED;
return sbi_platform_vendor_ext_provider(sbi_platform_thishart_ptr(),
funcid, regs,
out_val, out_trap);
@@ -51,6 +38,9 @@ static int sbi_ecall_vendor_register_extensions(void)
{
unsigned long extid = sbi_ecall_vendor_id();
if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()))
return 0;
ecall_vendor.extid_start = extid;
ecall_vendor.extid_end = extid;
@@ -61,6 +51,5 @@ struct sbi_ecall_extension ecall_vendor = {
.extid_start = SBI_EXT_VENDOR_START,
.extid_end = SBI_EXT_VENDOR_END,
.register_extensions = sbi_ecall_vendor_register_extensions,
.probe = sbi_ecall_vendor_probe,
.handle = sbi_ecall_vendor_handler,
};