From: Andrew Jones <ajones@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH] lib: sbi: Ensure SBI extension is available
Date: Wed, 26 Apr 2023 19:27:53 +0200 [thread overview]
Message-ID: <20230426172753.70664-1-ajones@ventanamicro.com> (raw)
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. By adding a new
status member to the extension which has three states
(uninitialized, available, unavailable), we ensure that the
probe function is only invoked once, lazily, upon first use.
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
---
include/sbi/sbi_ecall.h | 6 ++++++
lib/sbi/sbi_ecall.c | 18 ++++++++++++++----
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/include/sbi/sbi_ecall.h b/include/sbi/sbi_ecall.h
index ff9bf8e2b435..8e31d0d91620 100644
--- a/include/sbi/sbi_ecall.h
+++ b/include/sbi/sbi_ecall.h
@@ -20,10 +20,16 @@
struct sbi_trap_regs;
struct sbi_trap_info;
+enum sbi_ext_status {
+ SBI_EXT_AVAILABLE = 1,
+ SBI_EXT_UNAVAILABLE,
+};
+
struct sbi_ecall_extension {
struct sbi_dlist head;
unsigned long extid_start;
unsigned long extid_end;
+ enum sbi_ext_status status;
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 76a1ae9ab733..20ff06f32dad 100644
--- a/lib/sbi/sbi_ecall.c
+++ b/lib/sbi/sbi_ecall.c
@@ -42,16 +42,26 @@ static SBI_LIST_HEAD(ecall_exts_list);
struct sbi_ecall_extension *sbi_ecall_find_extension(unsigned long extid)
{
- struct sbi_ecall_extension *t, *ret = NULL;
+ struct sbi_ecall_extension *t;
+ unsigned long out_val;
sbi_list_for_each_entry(t, &ecall_exts_list, head) {
if (t->extid_start <= extid && extid <= t->extid_end) {
- ret = t;
- break;
+ if (t->status == SBI_EXT_AVAILABLE)
+ return t;
+ if (t->status == SBI_EXT_UNAVAILABLE)
+ return NULL;
+ if (t->probe && (t->probe(extid, &out_val) || !out_val)) {
+ t->status = SBI_EXT_UNAVAILABLE;
+ return NULL;
+ }
+
+ t->status = SBI_EXT_AVAILABLE;
+ return t;
}
}
- return ret;
+ return NULL;
}
int sbi_ecall_register_extension(struct sbi_ecall_extension *ext)
--
2.39.2
next reply other threads:[~2023-04-26 17:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-26 17:27 Andrew Jones [this message]
2023-04-27 1:02 ` [PATCH] lib: sbi: Ensure SBI extension is available Xiang W
2023-04-27 7:00 ` Andrew Jones
2023-04-27 7:18 ` Andrew Jones
2023-04-27 7:52 ` Xiang W
2023-04-27 8:04 ` Andrew Jones
2023-04-27 7:26 ` Xiang W
2023-04-27 8:01 ` Andrew Jones
2023-04-28 1:52 ` Xiang W
2023-04-28 10:40 ` Andrew Jones
2023-04-28 4:05 ` Anup Patel
2023-04-28 10:51 ` Andrew Jones
2023-04-28 11:05 ` Anup Patel
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=20230426172753.70664-1-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.