lib: sbi: Narrow vendor extension range
authorAndrew Jones <ajones@ventanamicro.com>
Mon, 15 May 2023 11:12:35 +0000 (13:12 +0200)
committerAnup Patel <anup@brainfault.org>
Sun, 21 May 2023 10:59:46 +0000 (16:29 +0530)
The vendor extension ID range is large, but at runtime at most
a single ID will be available. Narrow the range in the
register_extensions callback. After narrowing, we no longer
need to check that the extension ID is correct in the other
callbacks, as those callbacks will never be invoked with
anything other than the single ID.

Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
lib/sbi/sbi_ecall_vendor.c

index 126156f79a12603dee7253125ba62f07da38bc44..39c58c8b6fd5e03cc84ca3a1c964877d8cc7b953 100644 (file)
@@ -25,8 +25,7 @@ static inline unsigned long sbi_ecall_vendor_id(void)
 static int sbi_ecall_vendor_probe(unsigned long extid,
                                  unsigned long *out_val)
 {
-       if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) ||
-           extid != sbi_ecall_vendor_id())
+       if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()))
                *out_val = 0;
        else
                *out_val = 1;
@@ -38,8 +37,7 @@ static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid,
                                    unsigned long *out_val,
                                    struct sbi_trap_info *out_trap)
 {
-       if (!sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) ||
-           extid != sbi_ecall_vendor_id())
+       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(),
@@ -51,6 +49,11 @@ struct sbi_ecall_extension ecall_vendor;
 
 static int sbi_ecall_vendor_register_extensions(void)
 {
+       unsigned long extid = sbi_ecall_vendor_id();
+
+       ecall_vendor.extid_start = extid;
+       ecall_vendor.extid_end = extid;
+
        return sbi_ecall_register_extension(&ecall_vendor);
 }