Skip to contentSkip to conversation

lib: sbi: Ensure SBI extension is available

PATCH Superseded Andrew Jones 2 participants 17 messages May 15, 2023

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover lib: sbi: Ensure SBI extension is available

Ensure attempts to invoke SBI extension functions fail with SBI_ERR_NOT_SUPPORTED when the extension's probe function has reported that the extension is not available. To avoid invoking probe too frequently, we check extension availability at init time and skip registering them in the extension list when their probe fails. If the probes succeed, we keep them, and then later seeing them is enough to know they're available. Extensions which have multiple IDs may also need to narrow their ID range or remove IDs from their range to ensure when the IDs are seen they are valid.

To handle both the available and valid cases at init time we introduce a new callback which gets invoked instead of just registering the extensions. We then modify the callbacks for probing and narrowing as necessary. Additionally, considering the Base extension probe function already knows how to set out_val to 1 for available extensions, we simply remove all the probe functions, as now they must all succeed and none of them return anything other than 1 on success.

v5:
Another rework where I finally take Anup's advice that he gave on the initial posting and more or less replace probe with a new init callback.

v4:
Almost a total redesign. Patch1 of the v4 (now series) does keep hunk 2 of the v3 patch, but the changes to sbi_ecall_find_extension() of the v3 patch have been dropped. Instead multi-ID extensions can now make use of a new extension callback (Patch2) which gets invoked at init time. This new callback has been applied to vendor extensions with Patch3.

v3: http://lists.infradead.org/pipermail/opensbi/2023-May/004894.html

Andrew Jones (6):
lib: sbi: Introduce register_extensions extension callback
lib: sbi: Narrow vendor extension range
lib: sbi: pmu: Remove unnecessary probe function
lib: sbi: Only register available extensions
lib: sbi: Remove 0/1 probe implementations
lib: sbi: Document sbi_ecall_extension members

Xiang W (1):
lib: sbi: Optimize probe of srst/susp

 include/sbi/sbi_ecall.h    | 36 ++++++++++++++++++++++++++++++++++++
 lib/sbi/sbi_ecall.c        |  5 ++++-
 lib/sbi/sbi_ecall_base.c   | 14 +++++++++++---
 lib/sbi/sbi_ecall_cppc.c   | 18 +++++++++++-------
 lib/sbi/sbi_ecall_dbcn.c   | 18 +++++++++++-------
 lib/sbi/sbi_ecall_hsm.c    | 14 +++++++++++---
 lib/sbi/sbi_ecall_ipi.c    | 14 +++++++++++---
 lib/sbi/sbi_ecall_legacy.c | 14 +++++++++++---
 lib/sbi/sbi_ecall_pmu.c    | 16 ++++++++--------
 lib/sbi/sbi_ecall_rfence.c | 14 +++++++++++---
 lib/sbi/sbi_ecall_srst.c   | 28 ++++++++++++++++++----------
 lib/sbi/sbi_ecall_susp.c   | 27 ++++++++++++++++++---------
 lib/sbi/sbi_ecall_time.c   | 14 +++++++++++---
 lib/sbi/sbi_ecall_vendor.c | 37 ++++++++++++++++++++-----------------
 14 files changed, 192 insertions(+), 77 deletions(-)
Signature · 1 line
2.40.0
#1 lore raw

PATCH v5 1/7 lib: sbi: Introduce register_extensions extension callback

Rather than registering all extensions on their behalf in sbi_ecall_init(), introduce another extension callback and invoke that instead. For now, implement each callback by simply registering the extension, which means this patch has no intended functional change. In later patches, extension callbacks will be modified to choose when to register and to possibly narrow the extension ID range prior to registering. When an extension range needs to remove IDs, leaving gaps, then multiple invocations of sbi_ecall_register_extension() may be used. In summary, later patches for current extensions and the introductions of future extensions will use the new callback to ensure that only valid extension IDs from the initial range, which are also available, will be registered.

---
 include/sbi/sbi_ecall.h    |  1 +
 lib/sbi/sbi_ecall.c        |  5 ++++-
 lib/sbi/sbi_ecall_base.c   | 14 +++++++++++---
 lib/sbi/sbi_ecall_cppc.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_dbcn.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_hsm.c    | 14 +++++++++++---
 lib/sbi/sbi_ecall_ipi.c    | 14 +++++++++++---
 lib/sbi/sbi_ecall_legacy.c | 14 +++++++++++---
 lib/sbi/sbi_ecall_pmu.c    | 16 ++++++++++++----
 lib/sbi/sbi_ecall_rfence.c | 14 +++++++++++---
 lib/sbi/sbi_ecall_srst.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_susp.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_time.c   | 14 +++++++++++---
 lib/sbi/sbi_ecall_vendor.c | 16 ++++++++++++----
 14 files changed, 143 insertions(+), 43 deletions(-)
include/sbi/sbi_ecall.h +1 -0
index ff9bf8e2b435..fac26429cf5d 100644
@@ -24,6 +24,7 @@ struct sbi_ecall_extension {
 	struct sbi_dlist head;
 	unsigned long extid_start;
 	unsigned long extid_end;
+	int (* register_extensions)(void);
 	int (* probe)(unsigned long extid, unsigned long *out_val);
 	int (* handle)(unsigned long extid, unsigned long funcid,
 		       const struct sbi_trap_regs *regs,
lib/sbi/sbi_ecall.c +4 -1
index 76a1ae9ab733..3eb4f0addb02 100644
@@ -154,7 +154,10 @@ int sbi_ecall_init(void)
 
 	for (i = 0; i < sbi_ecall_exts_size; i++) {
 		ext = sbi_ecall_exts[i];
-		ret = sbi_ecall_register_extension(ext);
+		ret = SBI_ENODEV;
+
+		if (ext->register_extensions)
+			ret = ext->register_extensions();
 		if (ret)
 			return ret;
 	}
lib/sbi/sbi_ecall_base.c +11 -3
index 786d2ac67924..74f05eb26a35 100644
@@ -72,8 +72,16 @@ static int sbi_ecall_base_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
+struct sbi_ecall_extension ecall_base;
+
+static int sbi_ecall_base_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_base);
+}
+
 struct sbi_ecall_extension ecall_base = {
-	.extid_start = SBI_EXT_BASE,
-	.extid_end = SBI_EXT_BASE,
-	.handle = sbi_ecall_base_handler,
+	.extid_start		= SBI_EXT_BASE,
+	.extid_end		= SBI_EXT_BASE,
+	.register_extensions	= sbi_ecall_base_register_extensions,
+	.handle			= sbi_ecall_base_handler,
 };
lib/sbi/sbi_ecall_cppc.c +12 -4
index 91585f3b74e3..42ec744c22ba 100644
@@ -55,9 +55,17 @@ static int sbi_ecall_cppc_probe(unsigned long extid, unsigned long *out_val)
 	return 0;
 }
 
+struct sbi_ecall_extension ecall_cppc;
+
+static int sbi_ecall_cppc_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_cppc);
+}
+
 struct sbi_ecall_extension ecall_cppc = {
-	.extid_start	= SBI_EXT_CPPC,
-	.extid_end	= SBI_EXT_CPPC,
-	.handle		= sbi_ecall_cppc_handler,
-	.probe		= sbi_ecall_cppc_probe,
+	.extid_start		= SBI_EXT_CPPC,
+	.extid_end		= SBI_EXT_CPPC,
+	.register_extensions	= sbi_ecall_cppc_register_extensions,
+	.probe			= sbi_ecall_cppc_probe,
+	.handle			= sbi_ecall_cppc_handler,
 };
lib/sbi/sbi_ecall_dbcn.c +12 -4
index fe7e175a64c1..58b19e4468ef 100644
@@ -64,9 +64,17 @@ static int sbi_ecall_dbcn_probe(unsigned long extid, unsigned long *out_val)
 	return 0;
 }
 
+struct sbi_ecall_extension ecall_dbcn;
+
+static int sbi_ecall_dbcn_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_dbcn);
+}
+
 struct sbi_ecall_extension ecall_dbcn = {
-	.extid_start = SBI_EXT_DBCN,
-	.extid_end = SBI_EXT_DBCN,
-	.handle = sbi_ecall_dbcn_handler,
-	.probe = sbi_ecall_dbcn_probe,
+	.extid_start		= SBI_EXT_DBCN,
+	.extid_end		= SBI_EXT_DBCN,
+	.register_extensions	= sbi_ecall_dbcn_register_extensions,
+	.probe			= sbi_ecall_dbcn_probe,
+	.handle			= sbi_ecall_dbcn_handler,
 };
lib/sbi/sbi_ecall_hsm.c +11 -3
index f1b41d073b22..20705c395131 100644
@@ -54,8 +54,16 @@ static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
+struct sbi_ecall_extension ecall_hsm;
+
+static int sbi_ecall_hsm_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_hsm);
+}
+
 struct sbi_ecall_extension ecall_hsm = {
-	.extid_start = SBI_EXT_HSM,
-	.extid_end = SBI_EXT_HSM,
-	.handle = sbi_ecall_hsm_handler,
+	.extid_start		= SBI_EXT_HSM,
+	.extid_end		= SBI_EXT_HSM,
+	.register_extensions	= sbi_ecall_hsm_register_extensions,
+	.handle			= sbi_ecall_hsm_handler,
 };
lib/sbi/sbi_ecall_ipi.c +11 -3
index f4797e117a34..a40d6b8cc8a8 100644
@@ -29,8 +29,16 @@ static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
+struct sbi_ecall_extension ecall_ipi;
+
+static int sbi_ecall_ipi_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_ipi);
+}
+
 struct sbi_ecall_extension ecall_ipi = {
-	.extid_start = SBI_EXT_IPI,
-	.extid_end = SBI_EXT_IPI,
-	.handle = sbi_ecall_ipi_handler,
+	.extid_start		= SBI_EXT_IPI,
+	.extid_end		= SBI_EXT_IPI,
+	.register_extensions	= sbi_ecall_ipi_register_extensions,
+	.handle			= sbi_ecall_ipi_handler,
 };
lib/sbi/sbi_ecall_legacy.c +11 -3
index 8237498b538f..99e862e0f19f 100644
@@ -117,8 +117,16 @@ static int sbi_ecall_legacy_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
+struct sbi_ecall_extension ecall_legacy;
+
+static int sbi_ecall_legacy_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_legacy);
+}
+
 struct sbi_ecall_extension ecall_legacy = {
-	.extid_start = SBI_EXT_0_1_SET_TIMER,
-	.extid_end = SBI_EXT_0_1_SHUTDOWN,
-	.handle = sbi_ecall_legacy_handler,
+	.extid_start		= SBI_EXT_0_1_SET_TIMER,
+	.extid_end		= SBI_EXT_0_1_SHUTDOWN,
+	.register_extensions	= sbi_ecall_legacy_register_extensions,
+	.handle			= sbi_ecall_legacy_handler,
 };
lib/sbi/sbi_ecall_pmu.c +12 -4
index 367e92774261..b0589d0ecfa1 100644
@@ -88,9 +88,17 @@ static int sbi_ecall_pmu_probe(unsigned long extid, unsigned long *out_val)
 	return 0;
 }
 
+struct sbi_ecall_extension ecall_pmu;
+
+static int sbi_ecall_pmu_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_pmu);
+}
+
 struct sbi_ecall_extension ecall_pmu = {
-	.extid_start = SBI_EXT_PMU,
-	.extid_end = SBI_EXT_PMU,
-	.handle = sbi_ecall_pmu_handler,
-	.probe = sbi_ecall_pmu_probe,
+	.extid_start		= SBI_EXT_PMU,
+	.extid_end		= SBI_EXT_PMU,
+	.register_extensions	= sbi_ecall_pmu_register_extensions,
+	.probe			= sbi_ecall_pmu_probe,
+	.handle			= sbi_ecall_pmu_handler,
 };
lib/sbi/sbi_ecall_rfence.c +11 -3
index 6334c001d450..22c665227826 100644
@@ -79,8 +79,16 @@ static int sbi_ecall_rfence_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
+struct sbi_ecall_extension ecall_rfence;
+
+static int sbi_ecall_rfence_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_rfence);
+}
+
 struct sbi_ecall_extension ecall_rfence = {
-	.extid_start = SBI_EXT_RFENCE,
-	.extid_end = SBI_EXT_RFENCE,
-	.handle = sbi_ecall_rfence_handler,
+	.extid_start		= SBI_EXT_RFENCE,
+	.extid_end		= SBI_EXT_RFENCE,
+	.register_extensions	= sbi_ecall_rfence_register_extensions,
+	.handle			= sbi_ecall_rfence_handler,
 };
lib/sbi/sbi_ecall_srst.c +12 -4
index 93b012ce024c..ad31537604a3 100644
@@ -67,9 +67,17 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 	return 0;
 }
 
+struct sbi_ecall_extension ecall_srst;
+
+static int sbi_ecall_srst_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_srst);
+}
+
 struct sbi_ecall_extension ecall_srst = {
-	.extid_start = SBI_EXT_SRST,
-	.extid_end = SBI_EXT_SRST,
-	.handle = sbi_ecall_srst_handler,
-	.probe = sbi_ecall_srst_probe,
+	.extid_start		= SBI_EXT_SRST,
+	.extid_end		= SBI_EXT_SRST,
+	.register_extensions	= sbi_ecall_srst_register_extensions,
+	.probe			= sbi_ecall_srst_probe,
+	.handle			= sbi_ecall_srst_handler,
 };
lib/sbi/sbi_ecall_susp.c +12 -4
index f20126c49a60..bfbdbe648625 100644
@@ -40,9 +40,17 @@ static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
 	return 0;
 }
 
+struct sbi_ecall_extension ecall_susp;
+
+static int sbi_ecall_susp_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_susp);
+}
+
 struct sbi_ecall_extension ecall_susp = {
-	.extid_start = SBI_EXT_SUSP,
-	.extid_end = SBI_EXT_SUSP,
-	.handle = sbi_ecall_susp_handler,
-	.probe = sbi_ecall_susp_probe,
+	.extid_start		= SBI_EXT_SUSP,
+	.extid_end		= SBI_EXT_SUSP,
+	.register_extensions	= sbi_ecall_susp_register_extensions,
+	.probe			= sbi_ecall_susp_probe,
+	.handle			= sbi_ecall_susp_handler,
 };
lib/sbi/sbi_ecall_time.c +11 -3
index 668cb17680c0..e79196f77adc 100644
@@ -33,8 +33,16 @@ static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
+struct sbi_ecall_extension ecall_time;
+
+static int sbi_ecall_time_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_time);
+}
+
 struct sbi_ecall_extension ecall_time = {
-	.extid_start = SBI_EXT_TIME,
-	.extid_end = SBI_EXT_TIME,
-	.handle = sbi_ecall_time_handler,
+	.extid_start		= SBI_EXT_TIME,
+	.extid_end		= SBI_EXT_TIME,
+	.register_extensions	= sbi_ecall_time_register_extensions,
+	.handle			= sbi_ecall_time_handler,
 };
lib/sbi/sbi_ecall_vendor.c +12 -4
index 8b8dab00c92d..126156f79a12 100644
@@ -47,9 +47,17 @@ static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid,
 						out_val, out_trap);
 }
 
+struct sbi_ecall_extension ecall_vendor;
+
+static int sbi_ecall_vendor_register_extensions(void)
+{
+	return sbi_ecall_register_extension(&ecall_vendor);
+}
+
 struct sbi_ecall_extension ecall_vendor = {
-	.extid_start = SBI_EXT_VENDOR_START,
-	.extid_end = SBI_EXT_VENDOR_END,
-	.probe = sbi_ecall_vendor_probe,
-	.handle = sbi_ecall_vendor_handler,
+	.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,
 };
Signature · 1 line
2.40.0
#2 lore raw

PATCH v5 1/7 lib: sbi: Introduce register_extensions extension callback

Quoted 15 lines · On Mon, May 15, 2023 at 3:04?PM Andrew Jones <[email protected]> wrote:

Rather than registering all extensions on their behalf in sbi_ecall_init(), introduce another extension callback and invoke that instead. For now, implement each callback by simply registering the extension, which means this patch has no intended functional change. In later patches, extension callbacks will be modified to choose when to register and to possibly narrow the extension ID range prior to registering. When an extension range needs to remove IDs, leaving gaps, then multiple invocations of sbi_ecall_register_extension() may be used. In summary, later patches for current extensions and the introductions of future extensions will use the new callback to ensure that only valid extension IDs from the initial range, which are also available, will be registered.

Quoted 1 line

Looks good to me.

Thanks,
Anup

Quoted 348 lines
---
 include/sbi/sbi_ecall.h    |  1 +
 lib/sbi/sbi_ecall.c        |  5 ++++-
 lib/sbi/sbi_ecall_base.c   | 14 +++++++++++---
 lib/sbi/sbi_ecall_cppc.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_dbcn.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_hsm.c    | 14 +++++++++++---
 lib/sbi/sbi_ecall_ipi.c    | 14 +++++++++++---
 lib/sbi/sbi_ecall_legacy.c | 14 +++++++++++---
 lib/sbi/sbi_ecall_pmu.c    | 16 ++++++++++++----
 lib/sbi/sbi_ecall_rfence.c | 14 +++++++++++---
 lib/sbi/sbi_ecall_srst.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_susp.c   | 16 ++++++++++++----
 lib/sbi/sbi_ecall_time.c   | 14 +++++++++++---
 lib/sbi/sbi_ecall_vendor.c | 16 ++++++++++++----
 14 files changed, 143 insertions(+), 43 deletions(-)
include/sbi/sbi_ecall.h +1 -0
index ff9bf8e2b435..fac26429cf5d 100644
@@ -24,6 +24,7 @@ struct sbi_ecall_extension {
        struct sbi_dlist head;
        unsigned long extid_start;
        unsigned long extid_end;
+       int (* register_extensions)(void);
        int (* probe)(unsigned long extid, unsigned long *out_val);
        int (* handle)(unsigned long extid, unsigned long funcid,
                       const struct sbi_trap_regs *regs,
lib/sbi/sbi_ecall.c +4 -1
index 76a1ae9ab733..3eb4f0addb02 100644
@@ -154,7 +154,10 @@ int sbi_ecall_init(void)
 
        for (i = 0; i < sbi_ecall_exts_size; i++) {
                ext = sbi_ecall_exts[i];
-               ret = sbi_ecall_register_extension(ext);
+               ret = SBI_ENODEV;
+
+               if (ext->register_extensions)
+                       ret = ext->register_extensions();
                if (ret)
                        return ret;
        }
lib/sbi/sbi_ecall_base.c +11 -3
index 786d2ac67924..74f05eb26a35 100644
@@ -72,8 +72,16 @@ static int sbi_ecall_base_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
+struct sbi_ecall_extension ecall_base;
+
+static int sbi_ecall_base_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_base);
+}
+
 struct sbi_ecall_extension ecall_base = {
-       .extid_start = SBI_EXT_BASE,
-       .extid_end = SBI_EXT_BASE,
-       .handle = sbi_ecall_base_handler,
+       .extid_start            = SBI_EXT_BASE,
+       .extid_end              = SBI_EXT_BASE,
+       .register_extensions    = sbi_ecall_base_register_extensions,
+       .handle                 = sbi_ecall_base_handler,
 };
lib/sbi/sbi_ecall_cppc.c +12 -4
index 91585f3b74e3..42ec744c22ba 100644
@@ -55,9 +55,17 @@ static int sbi_ecall_cppc_probe(unsigned long extid, unsigned long *out_val)
        return 0;
 }
 
+struct sbi_ecall_extension ecall_cppc;
+
+static int sbi_ecall_cppc_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_cppc);
+}
+
 struct sbi_ecall_extension ecall_cppc = {
-       .extid_start    = SBI_EXT_CPPC,
-       .extid_end      = SBI_EXT_CPPC,
-       .handle         = sbi_ecall_cppc_handler,
-       .probe          = sbi_ecall_cppc_probe,
+       .extid_start            = SBI_EXT_CPPC,
+       .extid_end              = SBI_EXT_CPPC,
+       .register_extensions    = sbi_ecall_cppc_register_extensions,
+       .probe                  = sbi_ecall_cppc_probe,
+       .handle                 = sbi_ecall_cppc_handler,
 };
lib/sbi/sbi_ecall_dbcn.c +12 -4
index fe7e175a64c1..58b19e4468ef 100644
@@ -64,9 +64,17 @@ static int sbi_ecall_dbcn_probe(unsigned long extid, unsigned long *out_val)
        return 0;
 }
 
+struct sbi_ecall_extension ecall_dbcn;
+
+static int sbi_ecall_dbcn_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_dbcn);
+}
+
 struct sbi_ecall_extension ecall_dbcn = {
-       .extid_start = SBI_EXT_DBCN,
-       .extid_end = SBI_EXT_DBCN,
-       .handle = sbi_ecall_dbcn_handler,
-       .probe = sbi_ecall_dbcn_probe,
+       .extid_start            = SBI_EXT_DBCN,
+       .extid_end              = SBI_EXT_DBCN,
+       .register_extensions    = sbi_ecall_dbcn_register_extensions,
+       .probe                  = sbi_ecall_dbcn_probe,
+       .handle                 = sbi_ecall_dbcn_handler,
 };
lib/sbi/sbi_ecall_hsm.c +11 -3
index f1b41d073b22..20705c395131 100644
@@ -54,8 +54,16 @@ static int sbi_ecall_hsm_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
+struct sbi_ecall_extension ecall_hsm;
+
+static int sbi_ecall_hsm_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_hsm);
+}
+
 struct sbi_ecall_extension ecall_hsm = {
-       .extid_start = SBI_EXT_HSM,
-       .extid_end = SBI_EXT_HSM,
-       .handle = sbi_ecall_hsm_handler,
+       .extid_start            = SBI_EXT_HSM,
+       .extid_end              = SBI_EXT_HSM,
+       .register_extensions    = sbi_ecall_hsm_register_extensions,
+       .handle                 = sbi_ecall_hsm_handler,
 };
lib/sbi/sbi_ecall_ipi.c +11 -3
index f4797e117a34..a40d6b8cc8a8 100644
@@ -29,8 +29,16 @@ static int sbi_ecall_ipi_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
+struct sbi_ecall_extension ecall_ipi;
+
+static int sbi_ecall_ipi_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_ipi);
+}
+
 struct sbi_ecall_extension ecall_ipi = {
-       .extid_start = SBI_EXT_IPI,
-       .extid_end = SBI_EXT_IPI,
-       .handle = sbi_ecall_ipi_handler,
+       .extid_start            = SBI_EXT_IPI,
+       .extid_end              = SBI_EXT_IPI,
+       .register_extensions    = sbi_ecall_ipi_register_extensions,
+       .handle                 = sbi_ecall_ipi_handler,
 };
lib/sbi/sbi_ecall_legacy.c +11 -3
index 8237498b538f..99e862e0f19f 100644
@@ -117,8 +117,16 @@ static int sbi_ecall_legacy_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
+struct sbi_ecall_extension ecall_legacy;
+
+static int sbi_ecall_legacy_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_legacy);
+}
+
 struct sbi_ecall_extension ecall_legacy = {
-       .extid_start = SBI_EXT_0_1_SET_TIMER,
-       .extid_end = SBI_EXT_0_1_SHUTDOWN,
-       .handle = sbi_ecall_legacy_handler,
+       .extid_start            = SBI_EXT_0_1_SET_TIMER,
+       .extid_end              = SBI_EXT_0_1_SHUTDOWN,
+       .register_extensions    = sbi_ecall_legacy_register_extensions,
+       .handle                 = sbi_ecall_legacy_handler,
 };
lib/sbi/sbi_ecall_pmu.c +12 -4
index 367e92774261..b0589d0ecfa1 100644
@@ -88,9 +88,17 @@ static int sbi_ecall_pmu_probe(unsigned long extid, unsigned long *out_val)
        return 0;
 }
 
+struct sbi_ecall_extension ecall_pmu;
+
+static int sbi_ecall_pmu_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_pmu);
+}
+
 struct sbi_ecall_extension ecall_pmu = {
-       .extid_start = SBI_EXT_PMU,
-       .extid_end = SBI_EXT_PMU,
-       .handle = sbi_ecall_pmu_handler,
-       .probe = sbi_ecall_pmu_probe,
+       .extid_start            = SBI_EXT_PMU,
+       .extid_end              = SBI_EXT_PMU,
+       .register_extensions    = sbi_ecall_pmu_register_extensions,
+       .probe                  = sbi_ecall_pmu_probe,
+       .handle                 = sbi_ecall_pmu_handler,
 };
lib/sbi/sbi_ecall_rfence.c +11 -3
index 6334c001d450..22c665227826 100644
@@ -79,8 +79,16 @@ static int sbi_ecall_rfence_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
+struct sbi_ecall_extension ecall_rfence;
+
+static int sbi_ecall_rfence_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_rfence);
+}
+
 struct sbi_ecall_extension ecall_rfence = {
-       .extid_start = SBI_EXT_RFENCE,
-       .extid_end = SBI_EXT_RFENCE,
-       .handle = sbi_ecall_rfence_handler,
+       .extid_start            = SBI_EXT_RFENCE,
+       .extid_end              = SBI_EXT_RFENCE,
+       .register_extensions    = sbi_ecall_rfence_register_extensions,
+       .handle                 = sbi_ecall_rfence_handler,
 };
lib/sbi/sbi_ecall_srst.c +12 -4
index 93b012ce024c..ad31537604a3 100644
@@ -67,9 +67,17 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
        return 0;
 }
 
+struct sbi_ecall_extension ecall_srst;
+
+static int sbi_ecall_srst_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_srst);
+}
+
 struct sbi_ecall_extension ecall_srst = {
-       .extid_start = SBI_EXT_SRST,
-       .extid_end = SBI_EXT_SRST,
-       .handle = sbi_ecall_srst_handler,
-       .probe = sbi_ecall_srst_probe,
+       .extid_start            = SBI_EXT_SRST,
+       .extid_end              = SBI_EXT_SRST,
+       .register_extensions    = sbi_ecall_srst_register_extensions,
+       .probe                  = sbi_ecall_srst_probe,
+       .handle                 = sbi_ecall_srst_handler,
 };
lib/sbi/sbi_ecall_susp.c +12 -4
index f20126c49a60..bfbdbe648625 100644
@@ -40,9 +40,17 @@ static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
        return 0;
 }
 
+struct sbi_ecall_extension ecall_susp;
+
+static int sbi_ecall_susp_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_susp);
+}
+
 struct sbi_ecall_extension ecall_susp = {
-       .extid_start = SBI_EXT_SUSP,
-       .extid_end = SBI_EXT_SUSP,
-       .handle = sbi_ecall_susp_handler,
-       .probe = sbi_ecall_susp_probe,
+       .extid_start            = SBI_EXT_SUSP,
+       .extid_end              = SBI_EXT_SUSP,
+       .register_extensions    = sbi_ecall_susp_register_extensions,
+       .probe                  = sbi_ecall_susp_probe,
+       .handle                 = sbi_ecall_susp_handler,
 };
lib/sbi/sbi_ecall_time.c +11 -3
index 668cb17680c0..e79196f77adc 100644
@@ -33,8 +33,16 @@ static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
+struct sbi_ecall_extension ecall_time;
+
+static int sbi_ecall_time_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_time);
+}
+
 struct sbi_ecall_extension ecall_time = {
-       .extid_start = SBI_EXT_TIME,
-       .extid_end = SBI_EXT_TIME,
-       .handle = sbi_ecall_time_handler,
+       .extid_start            = SBI_EXT_TIME,
+       .extid_end              = SBI_EXT_TIME,
+       .register_extensions    = sbi_ecall_time_register_extensions,
+       .handle                 = sbi_ecall_time_handler,
 };
lib/sbi/sbi_ecall_vendor.c +12 -5
index 8b8dab00c92d..126156f79a12 100644
@@ -47,9 +47,17 @@ static int sbi_ecall_vendor_handler(unsigned long extid, unsigned long funcid,
                                                out_val, out_trap);
 }
 
+struct sbi_ecall_extension ecall_vendor;
+
+static int sbi_ecall_vendor_register_extensions(void)
+{
+       return sbi_ecall_register_extension(&ecall_vendor);
+}
+
 struct sbi_ecall_extension ecall_vendor = {
-       .extid_start = SBI_EXT_VENDOR_START,
-       .extid_end = SBI_EXT_VENDOR_END,
-       .probe = sbi_ecall_vendor_probe,
-       .handle = sbi_ecall_vendor_handler,
+       .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,
 };
--

2.40.0

#3 lore raw

PATCH v5 2/7 lib: sbi: Narrow vendor extension range

In reply to Andrew Jones

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.

---
 lib/sbi/sbi_ecall_vendor.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/sbi/sbi_ecall_vendor.c +7 -4
index 126156f79a12..39c58c8b6fd5 100644
@@ -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);
 }
 
Signature · 1 line
2.40.0
#4 lore raw

PATCH v5 2/7 lib: sbi: Narrow vendor extension range

Quoted 38 lines · On Mon, May 15, 2023 at 3:04?PM Andrew Jones <[email protected]> wrote:

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.

---
 lib/sbi/sbi_ecall_vendor.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/sbi/sbi_ecall_vendor.c +2 -4
index 126156f79a12..39c58c8b6fd5 100644
@@ -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(),

lib/sbi/sbi_ecall_vendor.c struct sbi_ecall_extension ecall_vendor; · line 57

Quoted 9 lines
lib/sbi/sbi_ecall_vendor.c +5 -0
@@ -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);

Actually, we should register vendor extension only if sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) is true.

This way we can remove the if-check from
sbi_ecall_vendor_handler() and
sbi_ecall_vendor_probe().

Regards,
Anup

Quoted 5 lines
lib/sbi/sbi_ecall_vendor.c +0 -1
 }
 
--

2.40.0

#5 lore raw

PATCH v5 2/7 lib: sbi: Narrow vendor extension range

Quoted 40 lines · Anup Patel
Quoted 39 lines · On Mon, May 15, 2023 at 3:04?PM Andrew Jones <[email protected]> wrote:

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.

---
 lib/sbi/sbi_ecall_vendor.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/sbi/sbi_ecall_vendor.c +2 -4
index 126156f79a12..39c58c8b6fd5 100644
@@ -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;
 
Quoted 12 lines

lib/sbi/sbi_ecall_vendor.c struct sbi_ecall_extension ecall_vendor; · line 57

Quoted 8 lines
lib/sbi/sbi_ecall_vendor.c +5 -0
 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);

Actually, we should register vendor extension only if sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) is true.

That's done in a later patch.

Quoted 4 lines

This way we can remove the if-check from
sbi_ecall_vendor_handler() and
sbi_ecall_vendor_probe().

The extid != sbi_ecall_vendor_id part can be / is removed in this patch, but I forgot to remove the other part in the later patch after adding it to sbi_ecall_vendor_register_extensions(). I'll do that for v6.

Thanks,
drew

#6 lore raw

PATCH v5 2/7 lib: sbi: Narrow vendor extension range

Quoted 55 lines · On Mon, May 15, 2023 at 4:08?PM Andrew Jones <[email protected]> wrote:
Quoted 40 lines · Anup Patel
Quoted 39 lines · On Mon, May 15, 2023 at 3:04?PM Andrew Jones <[email protected]> wrote:

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.

---
 lib/sbi/sbi_ecall_vendor.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/sbi/sbi_ecall_vendor.c +2 -4
index 126156f79a12..39c58c8b6fd5 100644
@@ -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;
 
Quoted 12 lines

lib/sbi/sbi_ecall_vendor.c struct sbi_ecall_extension ecall_vendor; · line 57

Quoted 8 lines
lib/sbi/sbi_ecall_vendor.c +5 -0
 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);

Actually, we should register vendor extension only if sbi_platform_vendor_ext_check(sbi_platform_thishart_ptr()) is true.

Quoted 1 line

That's done in a later patch.

Yes, I realized that after looking at a later patch.

Quoted 9 lines
Quoted 5 lines

This way we can remove the if-check from
sbi_ecall_vendor_handler() and
sbi_ecall_vendor_probe().

The extid != sbi_ecall_vendor_id part can be / is removed in this patch, but I forgot to remove the other part in the later patch after adding it to sbi_ecall_vendor_register_extensions(). I'll do that for v6.

Okay, no problem.

Regards,
Anup

#7 lore raw

PATCH v5 3/7 lib: sbi: pmu: Remove unnecessary probe function

In reply to Andrew Jones

The absence of a probe implementation means that the extension is always available. Remove the implementation for the PMU extension, which does no checking, and indeed even has a comment saying it's always available.

---
 lib/sbi/sbi_ecall_pmu.c | 8 --------
 1 file changed, 8 deletions(-)
lib/sbi/sbi_ecall_pmu.c +0 -8
index b0589d0ecfa1..1d5d512eeed7 100644
@@ -81,13 +81,6 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
-static int sbi_ecall_pmu_probe(unsigned long extid, unsigned long *out_val)
-{
-	/* PMU extension is always enabled */
-	*out_val = 1;
-	return 0;
-}
-
 struct sbi_ecall_extension ecall_pmu;
 
 static int sbi_ecall_pmu_register_extensions(void)
@@ -99,6 +92,5 @@ struct sbi_ecall_extension ecall_pmu = {
 	.extid_start		= SBI_EXT_PMU,
 	.extid_end		= SBI_EXT_PMU,
 	.register_extensions	= sbi_ecall_pmu_register_extensions,
-	.probe			= sbi_ecall_pmu_probe,
 	.handle			= sbi_ecall_pmu_handler,
 };
Signature · 1 line
2.40.0
#8 lore raw

PATCH v5 3/7 lib: sbi: pmu: Remove unnecessary probe function

Quoted 7 lines · On Mon, May 15, 2023 at 3:04?PM Andrew Jones <[email protected]> wrote:

The absence of a probe implementation means that the extension is always available. Remove the implementation for the PMU extension, which does no checking, and indeed even has a comment saying it's always available.

Looks good to me.

Thanks,
Anup

Quoted 32 lines
---
 lib/sbi/sbi_ecall_pmu.c | 8 --------
 1 file changed, 8 deletions(-)
lib/sbi/sbi_ecall_pmu.c +0 -9
index b0589d0ecfa1..1d5d512eeed7 100644
@@ -81,13 +81,6 @@ static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
-static int sbi_ecall_pmu_probe(unsigned long extid, unsigned long *out_val)
-{
-       /* PMU extension is always enabled */
-       *out_val = 1;
-       return 0;
-}
-
 struct sbi_ecall_extension ecall_pmu;
 
 static int sbi_ecall_pmu_register_extensions(void)
@@ -99,6 +92,5 @@ struct sbi_ecall_extension ecall_pmu = {
        .extid_start            = SBI_EXT_PMU,
        .extid_end              = SBI_EXT_PMU,
        .register_extensions    = sbi_ecall_pmu_register_extensions,
-       .probe                  = sbi_ecall_pmu_probe,
        .handle                 = sbi_ecall_pmu_handler,
 };
--

2.40.0

#9 lore raw

PATCH v5 4/7 lib: sbi: Only register available extensions

In reply to Andrew Jones

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.

---
 lib/sbi/sbi_ecall_cppc.c   | 3 +++
 lib/sbi/sbi_ecall_dbcn.c   | 3 +++
 lib/sbi/sbi_ecall_srst.c   | 6 ++++++
 lib/sbi/sbi_ecall_susp.c   | 6 ++++++
 lib/sbi/sbi_ecall_vendor.c | 3 +++
 5 files changed, 21 insertions(+)
lib/sbi/sbi_ecall_cppc.c +3 -0
index 42ec744c22ba..a6398ac78226 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_dbcn.c +3 -0
index 58b19e4468ef..cbb2e802e615 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_srst.c +6 -0
index ad31537604a3..ea0dc73f010d 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_susp.c +6 -0
index bfbdbe648625..c4124046b929 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_vendor.c +3 -0
index 39c58c8b6fd5..c4a4c1c45b14 100644
@@ -51,6 +51,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;
 
Signature · 1 line
2.40.0
#10 lore raw

PATCH v5 4/7 lib: sbi: Only register available extensions

Quoted 8 lines · On Mon, May 15, 2023 at 3:04?PM Andrew Jones <[email protected]> wrote:

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.

Looks good to me.

Thanks,
Anup

Quoted 87 lines
---
 lib/sbi/sbi_ecall_cppc.c   | 3 +++
 lib/sbi/sbi_ecall_dbcn.c   | 3 +++
 lib/sbi/sbi_ecall_srst.c   | 6 ++++++
 lib/sbi/sbi_ecall_susp.c   | 6 ++++++
 lib/sbi/sbi_ecall_vendor.c | 3 +++
 5 files changed, 21 insertions(+)
lib/sbi/sbi_ecall_cppc.c +3 -0
index 42ec744c22ba..a6398ac78226 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_dbcn.c +3 -0
index 58b19e4468ef..cbb2e802e615 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_srst.c +6 -0
index ad31537604a3..ea0dc73f010d 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_susp.c +6 -0
index bfbdbe648625..c4124046b929 100644
@@ -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);
 }
 
lib/sbi/sbi_ecall_vendor.c +3 -1
index 39c58c8b6fd5..c4a4c1c45b14 100644
@@ -51,6 +51,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;
 
--

2.40.0

#11 lore raw

PATCH v5 5/7 lib: sbi: Optimize probe of srst/susp

In reply to Andrew Jones

From: Xiang W <[email protected]>

No need to do a fully comprehensive count, just find a supported reset or suspend type

---
 lib/sbi/sbi_ecall_srst.c | 10 ++++++----
 lib/sbi/sbi_ecall_susp.c | 10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)
lib/sbi/sbi_ecall_srst.c +6 -4
index ea0dc73f010d..fd2dc0d251f3 100644
@@ -50,7 +50,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one standard reset types should be supported by
@@ -59,11 +59,13 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 
 	for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
 		if (sbi_system_reset_supported(type,
-					SBI_SRST_RESET_REASON_NONE))
-			count++;
+					SBI_SRST_RESET_REASON_NONE)) {
+			*out_val = 1;
+			return 0;
+		}
 	}
 
-	*out_val = (count) ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
lib/sbi/sbi_ecall_susp.c +6 -4
index c4124046b929..716a6d585af7 100644
@@ -25,18 +25,20 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
 {
-	u32 type, count = 0;
+	u32 type;
 
 	/*
 	 * At least one suspend type should be supported by the
 	 * platform for the SBI SUSP extension to be usable.
 	 */
 	for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
-		if (sbi_system_suspend_supported(type))
-			count++;
+		if (sbi_system_suspend_supported(type)) {
+			*out_val = 1;
+			return 0;
+		}
 	}
 
-	*out_val = count ? 1 : 0;
+	*out_val = 0;
 	return 0;
 }
 
Signature · 1 line
2.40.0
#12 lore raw

PATCH v5 5/7 lib: sbi: Optimize probe of srst/susp

Quoted 8 lines · On Mon, May 15, 2023 at 3:05?PM Andrew Jones <[email protected]> wrote:

From: Xiang W <[email protected]>

No need to do a fully comprehensive count, just find a supported reset or suspend type

Looks good to me.

Thanks,
Anup

Quoted 67 lines
---
 lib/sbi/sbi_ecall_srst.c | 10 ++++++----
 lib/sbi/sbi_ecall_susp.c | 10 ++++++----
 2 files changed, 12 insertions(+), 8 deletions(-)
lib/sbi/sbi_ecall_srst.c +6 -4
index ea0dc73f010d..fd2dc0d251f3 100644
@@ -50,7 +50,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 {
-       u32 type, count = 0;
+       u32 type;
 
        /*
         * At least one standard reset types should be supported by
@@ -59,11 +59,13 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 
        for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
                if (sbi_system_reset_supported(type,
-                                       SBI_SRST_RESET_REASON_NONE))
-                       count++;
+                                       SBI_SRST_RESET_REASON_NONE)) {
+                       *out_val = 1;
+                       return 0;
+               }
        }
 
-       *out_val = (count) ? 1 : 0;
+       *out_val = 0;
        return 0;
 }
 
lib/sbi/sbi_ecall_susp.c +6 -5
index c4124046b929..716a6d585af7 100644
@@ -25,18 +25,20 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
 
 static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
 {
-       u32 type, count = 0;
+       u32 type;
 
        /*
         * At least one suspend type should be supported by the
         * platform for the SBI SUSP extension to be usable.
         */
        for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
-               if (sbi_system_suspend_supported(type))
-                       count++;
+               if (sbi_system_suspend_supported(type)) {
+                       *out_val = 1;
+                       return 0;
+               }
        }
 
-       *out_val = count ? 1 : 0;
+       *out_val = 0;
        return 0;
 }
 
--

2.40.0

#13 lore raw

PATCH v5 6/7 lib: sbi: Remove 0/1 probe implementations

In reply to Andrew Jones

When a probe implementation just returns zero for not available and one for available then we don't need it, as the extension won't be registered at all if it would return zero and the Base extension probe function will already set out_val to 1 if not probe function is implemented. Currently all probe functions only return zero or one, so remove them all.

---
 lib/sbi/sbi_ecall_cppc.c   |  7 -------
 lib/sbi/sbi_ecall_dbcn.c   |  7 -------
 lib/sbi/sbi_ecall_srst.c   | 18 +++++-------------
 lib/sbi/sbi_ecall_susp.c   | 17 +++++------------
 lib/sbi/sbi_ecall_vendor.c | 11 -----------
 5 files changed, 10 insertions(+), 50 deletions(-)
lib/sbi/sbi_ecall_cppc.c +0 -7
index a6398ac78226..b54d54ec684c 100644
@@ -49,12 +49,6 @@ static int sbi_ecall_cppc_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
-static int sbi_ecall_cppc_probe(unsigned long extid, unsigned long *out_val)
-{
-	*out_val = sbi_cppc_get_device() ? 1 : 0;
-	return 0;
-}
-
 struct sbi_ecall_extension ecall_cppc;
 
 static int sbi_ecall_cppc_register_extensions(void)
@@ -69,6 +63,5 @@ struct sbi_ecall_extension ecall_cppc = {
 	.extid_start		= SBI_EXT_CPPC,
 	.extid_end		= SBI_EXT_CPPC,
 	.register_extensions	= sbi_ecall_cppc_register_extensions,
-	.probe			= sbi_ecall_cppc_probe,
 	.handle			= sbi_ecall_cppc_handler,
 };
lib/sbi/sbi_ecall_dbcn.c +0 -7
index cbb2e802e615..e0b892c2ed6b 100644
@@ -58,12 +58,6 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
 	return SBI_ENOTSUPP;
 }
 
-static int sbi_ecall_dbcn_probe(unsigned long extid, unsigned long *out_val)
-{
-	*out_val = sbi_console_get_device() ? 1 : 0;
-	return 0;
-}
-
 struct sbi_ecall_extension ecall_dbcn;
 
 static int sbi_ecall_dbcn_register_extensions(void)
@@ -78,6 +72,5 @@ struct sbi_ecall_extension ecall_dbcn = {
 	.extid_start		= SBI_EXT_DBCN,
 	.extid_end		= SBI_EXT_DBCN,
 	.register_extensions	= sbi_ecall_dbcn_register_extensions,
-	.probe			= sbi_ecall_dbcn_probe,
 	.handle			= sbi_ecall_dbcn_handler,
 };
lib/sbi/sbi_ecall_srst.c +5 -13
index fd2dc0d251f3..dcd560d22f9d 100644
@@ -48,7 +48,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
 	return SBI_ENOTSUPP;
 }
 
-static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
+static bool srst_available(void)
 {
 	u32 type;
 
@@ -56,27 +56,20 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
 	 * At least one standard reset types should be supported by
 	 * the platform for SBI SRST extension to be usable.
 	 */
-
 	for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
 		if (sbi_system_reset_supported(type,
-					SBI_SRST_RESET_REASON_NONE)) {
-			*out_val = 1;
-			return 0;
-		}
+					SBI_SRST_RESET_REASON_NONE))
+			return true;
 	}
 
-	*out_val = 0;
-	return 0;
+	return false;
 }
 
 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)
+	if (!srst_available())
 		return 0;
 
 	return sbi_ecall_register_extension(&ecall_srst);
@@ -86,6 +79,5 @@ struct sbi_ecall_extension ecall_srst = {
 	.extid_start		= SBI_EXT_SRST,
 	.extid_end		= SBI_EXT_SRST,
 	.register_extensions	= sbi_ecall_srst_register_extensions,
-	.probe			= sbi_ecall_srst_probe,
 	.handle			= sbi_ecall_srst_handler,
 };
lib/sbi/sbi_ecall_susp.c +5 -12
index 716a6d585af7..2bfd99ae8720 100644
@@ -23,7 +23,7 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
 	return ret;
 }
 
-static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
+static bool susp_available(void)
 {
 	u32 type;
 
@@ -32,24 +32,18 @@ static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
 	 * platform for the SBI SUSP extension to be usable.
 	 */
 	for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
-		if (sbi_system_suspend_supported(type)) {
-			*out_val = 1;
-			return 0;
-		}
+		if (sbi_system_suspend_supported(type))
+			return true;
 	}
 
-	*out_val = 0;
-	return 0;
+	return false;
 }
 
 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)
+	if (!susp_available())
 		return 0;
 
 	return sbi_ecall_register_extension(&ecall_susp);
@@ -59,6 +53,5 @@ struct sbi_ecall_extension ecall_susp = {
 	.extid_start		= SBI_EXT_SUSP,
 	.extid_end		= SBI_EXT_SUSP,
 	.register_extensions	= sbi_ecall_susp_register_extensions,
-	.probe			= sbi_ecall_susp_probe,
 	.handle			= sbi_ecall_susp_handler,
 };
lib/sbi/sbi_ecall_vendor.c +0 -11
index c4a4c1c45b14..fc0d43ef7e13 100644
@@ -22,16 +22,6 @@ 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,
@@ -64,6 +54,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,
 };
Signature · 1 line
2.40.0
#14 lore raw

PATCH v5 6/7 lib: sbi: Remove 0/1 probe implementations

Quoted 9 lines · On Mon, May 15, 2023 at 3:05?PM Andrew Jones <[email protected]> wrote:

When a probe implementation just returns zero for not available and one for available then we don't need it, as the extension won't be registered at all if it would return zero and the Base extension probe function will already set out_val to 1 if not probe function is implemented. Currently all probe functions only return zero or one, so remove them all.

Looks good to me.

Thanks,
Anup

Quoted 188 lines
---
 lib/sbi/sbi_ecall_cppc.c   |  7 -------
 lib/sbi/sbi_ecall_dbcn.c   |  7 -------
 lib/sbi/sbi_ecall_srst.c   | 18 +++++-------------
 lib/sbi/sbi_ecall_susp.c   | 17 +++++------------
 lib/sbi/sbi_ecall_vendor.c | 11 -----------
 5 files changed, 10 insertions(+), 50 deletions(-)
lib/sbi/sbi_ecall_cppc.c +0 -7
index a6398ac78226..b54d54ec684c 100644
@@ -49,12 +49,6 @@ static int sbi_ecall_cppc_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
-static int sbi_ecall_cppc_probe(unsigned long extid, unsigned long *out_val)
-{
-       *out_val = sbi_cppc_get_device() ? 1 : 0;
-       return 0;
-}
-
 struct sbi_ecall_extension ecall_cppc;
 
 static int sbi_ecall_cppc_register_extensions(void)
@@ -69,6 +63,5 @@ struct sbi_ecall_extension ecall_cppc = {
        .extid_start            = SBI_EXT_CPPC,
        .extid_end              = SBI_EXT_CPPC,
        .register_extensions    = sbi_ecall_cppc_register_extensions,
-       .probe                  = sbi_ecall_cppc_probe,
        .handle                 = sbi_ecall_cppc_handler,
 };
lib/sbi/sbi_ecall_dbcn.c +0 -7
index cbb2e802e615..e0b892c2ed6b 100644
@@ -58,12 +58,6 @@ static int sbi_ecall_dbcn_handler(unsigned long extid, unsigned long funcid,
        return SBI_ENOTSUPP;
 }
 
-static int sbi_ecall_dbcn_probe(unsigned long extid, unsigned long *out_val)
-{
-       *out_val = sbi_console_get_device() ? 1 : 0;
-       return 0;
-}
-
 struct sbi_ecall_extension ecall_dbcn;
 
 static int sbi_ecall_dbcn_register_extensions(void)
@@ -78,6 +72,5 @@ struct sbi_ecall_extension ecall_dbcn = {
        .extid_start            = SBI_EXT_DBCN,
        .extid_end              = SBI_EXT_DBCN,
        .register_extensions    = sbi_ecall_dbcn_register_extensions,
-       .probe                  = sbi_ecall_dbcn_probe,
        .handle                 = sbi_ecall_dbcn_handler,
 };
lib/sbi/sbi_ecall_srst.c +5 -13
index fd2dc0d251f3..dcd560d22f9d 100644
@@ -48,7 +48,7 @@ static int sbi_ecall_srst_handler(unsigned long extid, unsigned long funcid,
        return SBI_ENOTSUPP;
 }
 
-static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
+static bool srst_available(void)
 {
        u32 type;
 
@@ -56,27 +56,20 @@ static int sbi_ecall_srst_probe(unsigned long extid, unsigned long *out_val)
         * At least one standard reset types should be supported by
         * the platform for SBI SRST extension to be usable.
         */
-
        for (type = 0; type <= SBI_SRST_RESET_TYPE_LAST; type++) {
                if (sbi_system_reset_supported(type,
-                                       SBI_SRST_RESET_REASON_NONE)) {
-                       *out_val = 1;
-                       return 0;
-               }
+                                       SBI_SRST_RESET_REASON_NONE))
+                       return true;
        }
 
-       *out_val = 0;
-       return 0;
+       return false;
 }
 
 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)
+       if (!srst_available())
                return 0;
 
        return sbi_ecall_register_extension(&ecall_srst);
@@ -86,6 +79,5 @@ struct sbi_ecall_extension ecall_srst = {
        .extid_start            = SBI_EXT_SRST,
        .extid_end              = SBI_EXT_SRST,
        .register_extensions    = sbi_ecall_srst_register_extensions,
-       .probe                  = sbi_ecall_srst_probe,
        .handle                 = sbi_ecall_srst_handler,
 };
lib/sbi/sbi_ecall_susp.c +5 -12
index 716a6d585af7..2bfd99ae8720 100644
@@ -23,7 +23,7 @@ static int sbi_ecall_susp_handler(unsigned long extid, unsigned long funcid,
        return ret;
 }
 
-static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
+static bool susp_available(void)
 {
        u32 type;
 
@@ -32,24 +32,18 @@ static int sbi_ecall_susp_probe(unsigned long extid, unsigned long *out_val)
         * platform for the SBI SUSP extension to be usable.
         */
        for (type = 0; type <= SBI_SUSP_SLEEP_TYPE_LAST; type++) {
-               if (sbi_system_suspend_supported(type)) {
-                       *out_val = 1;
-                       return 0;
-               }
+               if (sbi_system_suspend_supported(type))
+                       return true;
        }
 
-       *out_val = 0;
-       return 0;
+       return false;
 }
 
 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)
+       if (!susp_available())
                return 0;
 
        return sbi_ecall_register_extension(&ecall_susp);
@@ -59,6 +53,5 @@ struct sbi_ecall_extension ecall_susp = {
        .extid_start            = SBI_EXT_SUSP,
        .extid_end              = SBI_EXT_SUSP,
        .register_extensions    = sbi_ecall_susp_register_extensions,
-       .probe                  = sbi_ecall_susp_probe,
        .handle                 = sbi_ecall_susp_handler,
 };
lib/sbi/sbi_ecall_vendor.c +0 -12
index c4a4c1c45b14..fc0d43ef7e13 100644
@@ -22,16 +22,6 @@ 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,
@@ -64,6 +54,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,
 };
--

2.40.0

#15 lore raw

PATCH v5 7/7 lib: sbi: Document sbi_ecall_extension members

In reply to Andrew Jones

With the introduction of the register_extensions callback the range members (extid_start and extid_end) may now change and it has become a bit subtle as to when a probe function should be implemented. Document all the members and their relationship to the register_extensions callback.

---
 include/sbi/sbi_ecall.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
include/sbi/sbi_ecall.h +35 -0
index fac26429cf5d..3cb25ae80fb0 100644
@@ -21,11 +21,46 @@ struct sbi_trap_regs;
 struct sbi_trap_info;
 
 struct sbi_ecall_extension {
+	/* head is used by the extension list */
 	struct sbi_dlist head;
+	/*
+	 * extid_start and extid_end specify the range for this extension.
+	 * As the initial range may be wider than the valid runtime range,
+	 * the register_extensions callback is responsible for narrowing
+	 * the range before other callbacks may be invoked.
+	 */
 	unsigned long extid_start;
 	unsigned long extid_end;
+	/*
+	 * register_extensions
+	 *
+	 * Calls sbi_ecall_register_extension() one or more times to
+	 * register extension ID range(s) which should be handled by this
+	 * extension. More than one sbi_ecall_extension struct and
+	 * sbi_ecall_register_extension() call is necessary when the supported
+	 * extension ID ranges have gaps. Additionally, extension availability
+	 * must be checked before registering, which means, when this callback
+	 * returns, only valid extension IDs from the initial range, which are
+	 * also available, have been registered.
+	 */
 	int (* register_extensions)(void);
+	/*
+	 * probe
+	 *
+	 * Implements the Base extension's probe function for the extension. As
+	 * the register_extensions callback ensures that no other extension
+	 * callbacks will be invoked when the extension is not available, then
+	 * probe can never fail. However, an extension may choose to set out_val
+	 * to a nonzero value other than one. In those cases, it should implement
+	 * this callback.
+	 */
 	int (* probe)(unsigned long extid, unsigned long *out_val);
+	/*
+	 * handle
+	 *
+	 * This is the extension handler. register_extensions ensures it is
+	 * never invoked with an invalid or unavailable extension ID.
+	 */
 	int (* handle)(unsigned long extid, unsigned long funcid,
 		       const struct sbi_trap_regs *regs,
 		       unsigned long *out_val,
Signature · 1 line
2.40.0
#16 lore raw

PATCH v5 7/7 lib: sbi: Document sbi_ecall_extension members

Quoted 8 lines · On Mon, May 15, 2023 at 3:05?PM Andrew Jones <[email protected]> wrote:

With the introduction of the register_extensions callback the range members (extid_start and extid_end) may now change and it has become a bit subtle as to when a probe function should be implemented. Document all the members and their relationship to the register_extensions callback.

Looks good to me.

Thanks,
Anup

Quoted 58 lines
---
 include/sbi/sbi_ecall.h | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
include/sbi/sbi_ecall.h +35 -1
index fac26429cf5d..3cb25ae80fb0 100644
@@ -21,11 +21,46 @@ struct sbi_trap_regs;
 struct sbi_trap_info;
 
 struct sbi_ecall_extension {
+       /* head is used by the extension list */
        struct sbi_dlist head;
+       /*
+        * extid_start and extid_end specify the range for this extension.
+        * As the initial range may be wider than the valid runtime range,
+        * the register_extensions callback is responsible for narrowing
+        * the range before other callbacks may be invoked.
+        */
        unsigned long extid_start;
        unsigned long extid_end;
+       /*
+        * register_extensions
+        *
+        * Calls sbi_ecall_register_extension() one or more times to
+        * register extension ID range(s) which should be handled by this
+        * extension. More than one sbi_ecall_extension struct and
+        * sbi_ecall_register_extension() call is necessary when the supported
+        * extension ID ranges have gaps. Additionally, extension availability
+        * must be checked before registering, which means, when this callback
+        * returns, only valid extension IDs from the initial range, which are
+        * also available, have been registered.
+        */
        int (* register_extensions)(void);
+       /*
+        * probe
+        *
+        * Implements the Base extension's probe function for the extension. As
+        * the register_extensions callback ensures that no other extension
+        * callbacks will be invoked when the extension is not available, then
+        * probe can never fail. However, an extension may choose to set out_val
+        * to a nonzero value other than one. In those cases, it should implement
+        * this callback.
+        */
        int (* probe)(unsigned long extid, unsigned long *out_val);
+       /*
+        * handle
+        *
+        * This is the extension handler. register_extensions ensures it is
+        * never invoked with an invalid or unavailable extension ID.
+        */
        int (* handle)(unsigned long extid, unsigned long funcid,
                       const struct sbi_trap_regs *regs,
                       unsigned long *out_val,
--

2.40.0