lib: sbi_domain: Add domain notifier infrastructure

Introduce a notifier callback mechanism that allows subsystems to
register interest in domain events (such as registration). Whenever
such events happen for a domain, all registered notifiers are invoked.

The following public interfaces are added to sbi_domain.h:

  - sbi_domain_register_notifier(): registers a notifier callback.
    Duplicate (fn, event, priv) pairs are silently ignored.

  - sbi_domain_unregister_notifier(): removes a previously registered
    notifier callback.

Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Oza Pawandeep <pawandeep.oza@oss.qualcomm.com>
Reviewed-by: Pawandeep Oza <pawandeep.oza@oss.qualcomm.com>
Tested-by: Pawandeep Oza <pawandeep.oza@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20260923032359.4041876-11-anup.patel@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Oza Pawandeep authored and Anup Patel committed 2026-10-25 14:30:46 +05:30
1 parent f909590830
commit f4ed5aa8b7
2 files changed
+118

No files matched your search

+40
View File
@@ -387,4 +387,44 @@ int sbi_domain_finalize(struct sbi_scratch *scratch);
/** Initialize domains */
int sbi_domain_init(struct sbi_scratch *scratch, u32 cold_hartid);
/** Possible domain notify events */
enum sbi_domain_notify_event {
SBI_DOMAIN_NOTIFY_EVENT_REGISTER = 0,
SBI_DOMAIN_NOTIFY_EVENT_MAX,
};
/**
* Domain notify callback.
* @param dom pointer to domain
* @param event domain notify event
* @param priv private data of the callback
* @return 0 on success (informs framework to continue notifications)
* @return negative error code on failure (informs framework to not continue notifications)
*/
typedef int (*sbi_domain_notify_fn)(struct sbi_domain *dom,
enum sbi_domain_notify_event event,
void *priv);
/**
* Register domain notifier
* @param fn domain notify callback
* @param event domain notify event
* @param priv private data of the callback
* @return 0 on success
* @return negative error code on failure
*/
int sbi_domain_register_notifier(sbi_domain_notify_fn fn,
enum sbi_domain_notify_event event, void *priv);
/**
* Unregister domain notifier
* @param fn domain notify callback
* @param event domain notify event
* @param priv private data of the callback
* @return 0 on success
* @return negative error code on failure
*/
int sbi_domain_unregister_notifier(sbi_domain_notify_fn fn,
enum sbi_domain_notify_event event, void *priv);
#endif
+78
View File
@@ -35,6 +35,74 @@ struct sbi_domain root = {
static unsigned long domain_hart_ptr_offset;
struct sbi_domain_notify_entry {
struct sbi_dlist node;
sbi_domain_notify_fn fn;
enum sbi_domain_notify_event event;
void *priv;
};
static SBI_LIST_HEAD(domain_notifier_list);
int sbi_domain_register_notifier(sbi_domain_notify_fn fn,
enum sbi_domain_notify_event event, void *priv)
{
struct sbi_domain_notify_entry *entry;
if (!fn || SBI_DOMAIN_NOTIFY_EVENT_MAX <= event)
return SBI_EINVAL;
sbi_list_for_each_entry(entry, &domain_notifier_list, node) {
if (entry->fn == fn && entry->event == event && entry->priv == priv)
return SBI_OK;
}
entry = sbi_zalloc(sizeof(*entry));
if (!entry)
return SBI_ENOMEM;
entry->fn = fn;
entry->event = event;
entry->priv = priv;
sbi_list_add_tail(&entry->node, &domain_notifier_list);
return SBI_OK;
}
int sbi_domain_unregister_notifier(sbi_domain_notify_fn fn,
enum sbi_domain_notify_event event, void *priv)
{
struct sbi_domain_notify_entry *entry, *tmp;
if (!fn || SBI_DOMAIN_NOTIFY_EVENT_MAX <= event)
return SBI_EINVAL;
sbi_list_for_each_entry_safe(entry, tmp, &domain_notifier_list, node) {
if (entry->fn == fn && entry->event == event && entry->priv == priv) {
sbi_list_del(&entry->node);
sbi_free(entry);
return SBI_OK;
}
}
return SBI_ENODEV;
}
static int sbi_domain_notify_all(struct sbi_domain *dom, enum sbi_domain_notify_event event)
{
struct sbi_domain_notify_entry *entry, *tmp;
int rc;
sbi_list_for_each_entry_safe(entry, tmp, &domain_notifier_list, node) {
if (entry->event == event) {
rc = entry->fn(dom, event, entry->priv);
if (rc)
return rc;
}
}
return 0;
}
struct sbi_domain *sbi_hartindex_to_domain(u32 hartindex)
{
struct sbi_scratch *scratch;
@@ -719,6 +787,16 @@ int sbi_domain_register(struct sbi_domain *dom)
return rc;
}
/* Notify everyone */
rc = sbi_domain_notify_all(dom, SBI_DOMAIN_NOTIFY_EVENT_REGISTER);
if (rc) {
sbi_printf("%s: domain notification failed for %s (error %d)\n",
__func__, dom->name, rc);
sbi_domain_cleanup_state(dom);
sbi_list_del(&dom->node);
return rc;
}
return 0;
}