lib: sbi: Ensure SBI extension is available
v6 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.
v6:
- Remove the check in sbi_ecall_vendor_handler() when adding it tosbi_ecall_vendor_register_extensions()
- Better line wrapping of the comments added for documenting the extension struct members
- Added Anup's r-b's
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 | 38 +++++++++++++++++++------------------- 14 files changed, 191 insertions(+), 79 deletions(-)
Signature · 1 line
2.40.0
PATCH v6 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Anup Patel
AppliedPATCH v6 1/7 lib: sbi: Introduce register_extensions extension callback
Quoted 15 lines · On Mon, May 15, 2023 at 4:42?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 ofsbi_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 2 lines
Signed-off-by Andrew Jones <[email protected]>Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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@@ -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
PATCH v6 2/7 lib: sbi: Narrow vendor extension range
In reply to Andrew JonesThe 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
@@ -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
PATCH v6 2/7 lib: sbi: Narrow vendor extension range
Quoted 9 lines · On Mon, May 15, 2023 at 4:42?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_extensionscallback. 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 <[email protected]>
Looks good to me.
Thanks,
Anup
Quoted 43 lines
--- lib/sbi/sbi_ecall_vendor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)lib/sbi/sbi_ecall_vendor.c +7
-5@@ -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); } --2.40.0
Anup Patel
AppliedPATCH v6 2/7 lib: sbi: Narrow vendor extension range
In reply to Andrew JonesQuoted 9 lines · On Mon, May 15, 2023 at 4:42?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_extensionscallback. 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 <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 43 lines
--- lib/sbi/sbi_ecall_vendor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)lib/sbi/sbi_ecall_vendor.c +7
-5@@ -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); } --2.40.0
PATCH v6 3/7 lib: sbi: pmu: Remove unnecessary probe function
In reply to Andrew JonesThe 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
@@ -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
Anup Patel
AppliedPATCH v6 3/7 lib: sbi: pmu: Remove unnecessary probe function
Quoted 8 lines · On Mon, May 15, 2023 at 4:42?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.
Signed-off-by Andrew Jones <[email protected]>Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
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@@ -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
PATCH v6 4/7 lib: sbi: Only register available extensions
In reply to Andrew JonesWhen 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 | 17 +++-------------- 5 files changed, 21 insertions(+), 14 deletions(-)
lib/sbi/sbi_ecall_cppc.c +3 -0
@@ -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
@@ -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
@@ -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
@@ -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 -14
@@ -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, };
Signature · 1 line
2.40.0
Anup Patel
AppliedPATCH v6 4/7 lib: sbi: Only register available extensions
Quoted 9 lines · On Mon, May 15, 2023 at 4:42?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_extensionscallback 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 <[email protected]>Reviewed-by Anup Patel <[email protected]>
The sbi_ecall_init() needs to be called after sbi_platform_final_init() so that platform devices registered by sbi_platform_final_init() can be considered at the time of registering SBI extensions.
Applied this patch to the riscv/opensbi repo with above change included.
Thanks,
Anup
Quoted 119 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 | 17 +++-------------- 5 files changed, 21 insertions(+), 14 deletions(-)lib/sbi/sbi_ecall_cppc.c +3
-0@@ -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@@ -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@@ -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@@ -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
-15@@ -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, }; --2.40.0
PATCH v6 5/7 lib: sbi: Optimize probe of srst/susp
In reply to Andrew JonesFrom: 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
@@ -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
@@ -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
Anup Patel
AppliedPATCH v6 5/7 lib: sbi: Optimize probe of srst/susp
Quoted 9 lines · On Mon, May 15, 2023 at 4:42?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
Signed-off-by Xiang W <[email protected]>Signed-off-by Andrew Jones <[email protected]>Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
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@@ -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@@ -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
PATCH v6 6/7 lib: sbi: Remove 0/1 probe implementations
In reply to Andrew JonesWhen 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 +++++------------ 4 files changed, 10 insertions(+), 39 deletions(-)
lib/sbi/sbi_ecall_cppc.c +0 -7
@@ -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
@@ -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
@@ -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
@@ -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, };
Signature · 1 line
2.40.0
Anup Patel
AppliedPATCH v6 6/7 lib: sbi: Remove 0/1 probe implementations
Quoted 10 lines · On Mon, May 15, 2023 at 4:42?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_valto 1 if not probe function is implemented. Currently all probe functions only return zero or one, so remove them all.Signed-off-by Andrew Jones <[email protected]>Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 159 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 +++++------------ 4 files changed, 10 insertions(+), 39 deletions(-)lib/sbi/sbi_ecall_cppc.c +0
-7@@ -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@@ -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@@ -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
-13@@ -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, }; --2.40.0
PATCH v6 7/7 lib: sbi: Document sbi_ecall_extension members
In reply to Andrew JonesWith 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
@@ -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
Anup Patel
AppliedPATCH v6 7/7 lib: sbi: Document sbi_ecall_extension members
Quoted 9 lines · On Mon, May 15, 2023 at 4:42?PM Andrew Jones <[email protected]> wrote:
With the introduction of the
register_extensionscallback the range members (extid_startandextid_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 theregister_extensionscallback.Signed-off-by Andrew Jones <[email protected]>Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 58 lines
--- include/sbi/sbi_ecall.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)include/sbi/sbi_ecall.h +35
-1@@ -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