From 5852dd2b1a1bcb58e9611e9b74a69db8dcad27d0 Mon Sep 17 00:00:00 2001 From: Dmytro Firsov Date: Tue, 14 Feb 2023 14:40:38 +0200 Subject: [PATCH] xen: events: add event channel allocation for domain-0 This commit adds interface for evtchn allocation that can be used by privilaged domain. Domain 0 can specify both dom and remote_dom parameters for hypercall, where in others domains dom should be always DOMID_SELF. It is needed for creating pre-defined channels during domain setup in Zephyr Dom0. Signed-off-by: Dmytro Firsov --- drivers/xen/events.c | 18 ++++++++++++++++++ include/zephyr/xen/events.h | 11 +++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/xen/events.c b/drivers/xen/events.c index e077b0f6cf..a16cce8b5c 100644 --- a/drivers/xen/events.c +++ b/drivers/xen/events.c @@ -47,6 +47,24 @@ int alloc_unbound_event_channel(domid_t remote_dom) return rc; } +#ifdef CONFIG_XEN_DOM0 +int alloc_unbound_event_channel_dom0(domid_t dom, domid_t remote_dom) +{ + int rc; + struct evtchn_alloc_unbound alloc = { + .dom = dom, + .remote_dom = remote_dom, + }; + + rc = HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &alloc); + if (rc == 0) { + rc = alloc.port; + } + + return rc; +} +#endif /* CONFIG_XEN_DOM0 */ + int bind_interdomain_event_channel(domid_t remote_dom, evtchn_port_t remote_port, evtchn_cb_t cb, void *data) { diff --git a/include/zephyr/xen/events.h b/include/zephyr/xen/events.h index d2a936a59e..cbad8162cb 100644 --- a/include/zephyr/xen/events.h +++ b/include/zephyr/xen/events.h @@ -36,6 +36,17 @@ void notify_evtchn(evtchn_port_t port); */ int alloc_unbound_event_channel(domid_t remote_dom); +#ifdef CONFIG_XEN_DOM0 +/* + * Allocate event-channel between remote domains. Can be used only from Dom0. + * + * @param dom - first remote domain domid (may be DOMID_SELF) + * @param remote_dom - second remote domain domid + * @return - local event channel port on success, negative on error + */ +int alloc_unbound_event_channel_dom0(domid_t dom, domid_t remote_dom); +#endif /* CONFIG_XEN_DOM0 */ + /* * Allocate local event channel, binded to remote port and attach specified callback * to it