xref: /freebsd/sys/xen/evtchn/evtchnvar.h (revision 9f23cbd6cae82fd77edfad7173432fa8dccd0a95)
1 /******************************************************************************
2  * evtchn.h
3  *
4  * Data structures and definitions private to the FreeBSD implementation
5  * of the Xen event channel API.
6  *
7  * Copyright (c) 2004, K A Fraser
8  * Copyright (c) 2012, Spectra Logic Corporation
9  * Copyright © 2022, Elliott Mitchell
10  *
11  * This file may be distributed separately from the Linux kernel, or
12  * incorporated into other software packages, subject to the following license:
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a copy
15  * of this source file (the "Software"), to deal in the Software without
16  * restriction, including without limitation the rights to use, copy, modify,
17  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18  * and to permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included in
22  * all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * IN THE SOFTWARE.
31  *
32  * $FreeBSD$
33  */
34 
35 #ifndef __XEN_EVTCHN_EVTCHNVAR_H__
36 #define __XEN_EVTCHN_EVTCHNVAR_H__
37 
38 #include <xen/hypervisor.h>
39 #include <contrib/xen/event_channel.h>
40 
41 /** Submit a port notification for delivery to a userland evtchn consumer */
42 void evtchn_device_upcall(evtchn_port_t port);
43 
44 /* Macros for accessing event channel values */
45 #define	EVTCHN_PTR(type, port) \
46 	(HYPERVISOR_shared_info->evtchn_##type + ((port) / __LONG_BIT))
47 #define	EVTCHN_BIT(port)	((port) & (__LONG_BIT - 1))
48 #define	EVTCHN_MASK(port)	(1UL << EVTCHN_BIT(port))
49 
50 /**
51  * Disable signal delivery for an event channel port, returning its
52  * previous mask state.
53  *
54  * \param port  The event channel port to query and mask.
55  *
56  * \returns  1 if event delivery was previously disabled.  Otherwise 0.
57  */
58 static inline int
59 evtchn_test_and_set_mask(evtchn_port_t port)
60 {
61 
62 	return (atomic_testandset_long(EVTCHN_PTR(mask, port),
63 	    EVTCHN_BIT(port)));
64 }
65 
66 /**
67  * Clear any pending event for the given event channel port.
68  *
69  * \param port  The event channel port to clear.
70  */
71 static inline void
72 evtchn_clear_port(evtchn_port_t port)
73 {
74 
75 	atomic_clear_long(EVTCHN_PTR(pending, port), EVTCHN_MASK(port));
76 }
77 
78 /**
79  * Disable signal delivery for an event channel port.
80  *
81  * \param port  The event channel port to mask.
82  */
83 static inline void
84 evtchn_mask_port(evtchn_port_t port)
85 {
86 
87 	atomic_set_long(EVTCHN_PTR(mask, port), EVTCHN_MASK(port));
88 }
89 
90 /**
91  * Enable signal delivery for an event channel port.
92  *
93  * \param port  The event channel port to enable.
94  */
95 static inline void
96 evtchn_unmask_port(evtchn_port_t port)
97 {
98 	evtchn_unmask_t op = { .port = port };
99 
100 	HYPERVISOR_event_channel_op(EVTCHNOP_unmask, &op);
101 }
102 
103 #endif /* __XEN_EVTCHN_EVTCHNVAR_H__ */
104