From: Andrew Jones <ajones@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH v4 2/3] lib: sbi: Introduce register_extensions extension callback
Date: Thu, 11 May 2023 18:11:03 +0200 [thread overview]
Message-ID: <20230511161104.115168-3-ajones@ventanamicro.com> (raw)
In-Reply-To: <20230511161104.115168-1-ajones@ventanamicro.com>
The register_extensions callback is called from sbi_ecall_init() for
any extension that provides it. It's purpose is to register the
extension with one or more sbi_ecall_register_extension() calls after
possibly narrowing the range of extension IDs that should be handled.
More than one call of sbi_ecall_register_extension() is necessary
when the supported extension ID ranges have gaps. Additionally, when
an extension may not be available and has a probe function, then the
probe function should be consulted as to whether or not the extension
should be registered. In summary, when register_extensions() returns,
only valid extension IDs from the initial range, which are also
available, have been registered.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
include/sbi/sbi_ecall.h | 1 +
lib/sbi/sbi_ecall.c | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/include/sbi/sbi_ecall.h b/include/sbi/sbi_ecall.h
index ff9bf8e2b435..fac26429cf5d 100644
--- a/include/sbi/sbi_ecall.h
+++ b/include/sbi/sbi_ecall.h
@@ -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,
diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c
index 5a301fb7d403..1c4a26fde438 100644
--- a/lib/sbi/sbi_ecall.c
+++ b/lib/sbi/sbi_ecall.c
@@ -154,8 +154,12 @@ int sbi_ecall_init(void)
for (i = 0; i < sbi_ecall_exts_size; i++) {
ext = sbi_ecall_exts[i];
- if (ext->extid_start != ext->extid_end || !ext->probe ||
- (!ext->probe(ext->extid_end, &out_val) && out_val)) {
+ if (ext->register_extensions) {
+ ret = ext->register_extensions();
+ if (ret)
+ return ret;
+ } else if (ext->extid_start != ext->extid_end || !ext->probe ||
+ (!ext->probe(ext->extid_end, &out_val) && out_val)) {
ret = sbi_ecall_register_extension(ext);
if (ret)
return ret;
--
2.40.0
next prev parent reply other threads:[~2023-05-11 16:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-11 16:11 [PATCH v4 0/3] lib: sbi: Ensure SBI extension is available Andrew Jones
2023-05-11 16:11 ` [PATCH v4 1/3] lib: sbi: Don't register unavailable single ID extensions Andrew Jones
2023-05-11 16:11 ` Andrew Jones [this message]
2023-05-12 14:25 ` [PATCH v4 2/3] lib: sbi: Introduce register_extensions extension callback Anup Patel
2023-05-12 15:06 ` Andrew Jones
2023-05-12 16:47 ` Anup Patel
2023-05-15 6:01 ` Andrew Jones
2023-05-11 16:11 ` [PATCH v4 3/3] lib: sbi: Apply register_extensions to vendor extensions Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230511161104.115168-3-ajones@ventanamicro.com \
--to=ajones@ventanamicro.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox