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

@ -59,6 +59,9 @@ struct sbi_ecall_extension ecall_cppc;
static int sbi_ecall_cppc_register_extensions(void)
{
if (!sbi_cppc_get_device())
return 0;
return sbi_ecall_register_extension(&ecall_cppc);
}

View file

@ -68,6 +68,9 @@ struct sbi_ecall_extension ecall_dbcn;
static int sbi_ecall_dbcn_register_extensions(void)
{
if (!sbi_console_get_device())
return 0;
return sbi_ecall_register_extension(&ecall_dbcn);
}

View file

@ -71,6 +71,12 @@ struct sbi_ecall_extension ecall_srst;
static int sbi_ecall_srst_register_extensions(void)
{
unsigned long out_val;
sbi_ecall_srst_probe(SBI_EXT_SRST, &out_val);
if (!out_val)
return 0;
return sbi_ecall_register_extension(&ecall_srst);
}

View file

@ -44,6 +44,12 @@ struct sbi_ecall_extension ecall_susp;
static int sbi_ecall_susp_register_extensions(void)
{
unsigned long out_val;
sbi_ecall_susp_probe(SBI_EXT_SUSP, &out_val);
if (!out_val)
return 0;
return sbi_ecall_register_extension(&ecall_susp);
}

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,
};

View file

@ -323,12 +323,6 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
sbi_hart_hang();
}
rc = sbi_ecall_init();
if (rc) {
sbi_printf("%s: ecall init failed (error %d)\n", __func__, rc);
sbi_hart_hang();
}
/*
* Note: Finalize domains after HSM initialization so that we
* can startup non-root domains.
@ -350,8 +344,9 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
}
/*
* Note: Platform final initialization should be last so that
* it sees correct domain assignment and PMP configuration.
* Note: Platform final initialization should be after finalizing
* domains so that it sees correct domain assignment and PMP
* configuration for FDT fixups.
*/
rc = sbi_platform_final_init(plat, true);
if (rc) {
@ -360,6 +355,17 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid)
sbi_hart_hang();
}
/*
* Note: Ecall initialization should be after platform final
* initialization so that all available platform devices are
* already registered.
*/
rc = sbi_ecall_init();
if (rc) {
sbi_printf("%s: ecall init failed (error %d)\n", __func__, rc);
sbi_hart_hang();
}
sbi_boot_print_general(scratch);
sbi_boot_print_domains(scratch);