1 /*
2  * Copyright (c) 2021 EPAM Systems
3  * Copyright (c) 2022 Arm Limited (or its affiliates). All rights reserved.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 #ifndef __XEN_EVENTS_H__
8 #define __XEN_EVENTS_H__
9 
10 #include <zephyr/xen/public/event_channel.h>
11 
12 #include <zephyr/kernel.h>
13 
14 typedef void (*evtchn_cb_t)(void *priv);
15 
16 struct event_channel_handle {
17 	evtchn_cb_t cb;
18 	void *priv;
19 };
20 typedef struct event_channel_handle evtchn_handle_t;
21 
22 /*
23  * Following functions just wrap Xen hypercalls, detailed description
24  * of parameters and return values are located in include/xen/public/event_channel.h
25  */
26 int evtchn_status(evtchn_status_t *status);
27 int evtchn_close(evtchn_port_t port);
28 int evtchn_set_priority(evtchn_port_t port, uint32_t priority);
29 void notify_evtchn(evtchn_port_t port);
30 
31 /*
32  * Allocate event-channel between caller and remote domain
33  *
34  * @param remote_dom - remote domain domid
35  * @return - local event channel port on success, negative on error
36  */
37 int alloc_unbound_event_channel(domid_t remote_dom);
38 
39 #ifdef CONFIG_XEN_DOM0
40 /*
41  * Allocate event-channel between remote domains. Can be used only from Dom0.
42  *
43  * @param dom - first remote domain domid (may be DOMID_SELF)
44  * @param remote_dom - second remote domain domid
45  * @return - local event channel port on success, negative on error
46  */
47 int alloc_unbound_event_channel_dom0(domid_t dom, domid_t remote_dom);
48 #endif /* CONFIG_XEN_DOM0 */
49 
50 /*
51  * Allocate local event channel, binded to remote port and attach specified callback
52  * to it
53  *
54  * @param remote_dom - remote domain domid
55  * @param remote_port - remote domain event channel port number
56  * @param cb - callback, attached to locat port
57  * @param data - private data, that will be passed to cb
58  * @return - local event channel port on success, negative on error
59  */
60 int bind_interdomain_event_channel(domid_t remote_dom, evtchn_port_t remote_port,
61 		evtchn_cb_t cb, void *data);
62 
63 /*
64  * Bind user-defined handler to specified event-channel
65  *
66  * @param port - event channel number
67  * @param cb - pointer to event channel handler
68  * @param data - private data, that will be passed to handler as parameter
69  * @return - zero on success
70  */
71 int bind_event_channel(evtchn_port_t port, evtchn_cb_t cb, void *data);
72 
73 /*
74  * Unbind handler from event channel, substitute it with empty callback
75  *
76  * @param port - event channel number to unbind
77  * @return - zero on success
78  */
79 int unbind_event_channel(evtchn_port_t port);
80 int get_missed_events(evtchn_port_t port);
81 
82 int xen_events_init(void);
83 
84 #endif /* __XEN_EVENTS_H__ */
85