1 /******************************************************************************
2 *
3 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4 * Use is subject to license terms.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation;
9 * version 2.1 of the License.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Split out from xc_solaris.c
20 */
21
22 #include <errno.h>
23 #include <fcntl.h>
24 #include <unistd.h>
25
26 #include <sys/ioctl.h>
27
28 #include <xen/sys/evtchn.h>
29
30 #include "private.h"
31
osdep_evtchn_open(xenevtchn_handle * xce,unsigned int flags)32 int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags)
33 {
34 int fd;
35
36 if ( (fd = open("/dev/xen/evtchn", O_RDWR)) == -1 )
37 {
38 PERROR("Could not open event channel interface");
39 return -1;
40 }
41
42 xce->fd = fd;
43 return 0;
44 }
45
osdep_evtchn_close(xenevtchn_handle * xce)46 int osdep_evtchn_close(xenevtchn_handle *xce)
47 {
48 if ( xce->fd == -1 )
49 return 0;
50
51 return close(xce->fd);
52 }
53
osdep_evtchn_restrict(xenevtchn_handle * xce,domid_t domid)54 int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid)
55 {
56 errno = EOPNOTSUPP;
57 return -1;
58 }
59
xenevtchn_notify(xenevtchn_handle * xce,evtchn_port_t port)60 int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port)
61 {
62 int fd = xce->fd;
63 struct ioctl_evtchn_notify notify;
64
65 notify.port = port;
66
67 return ioctl(fd, IOCTL_EVTCHN_NOTIFY, ¬ify);
68 }
69
xenevtchn_bind_unbound_port(xenevtchn_handle * xce,uint32_t domid)70 xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce,
71 uint32_t domid)
72 {
73 int fd = xce->fd;
74 struct ioctl_evtchn_bind_unbound_port bind;
75
76 bind.remote_domain = domid;
77
78 return ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
79 }
80
xenevtchn_bind_interdomain(xenevtchn_handle * xce,uint32_t domid,evtchn_port_t remote_port)81 xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce,
82 uint32_t domid,
83 evtchn_port_t remote_port)
84 {
85 int fd = xce->fd;
86 struct ioctl_evtchn_bind_interdomain bind;
87
88 bind.remote_domain = domid;
89 bind.remote_port = remote_port;
90
91 return ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
92 }
93
xenevtchn_bind_virq(xenevtchn_handle * xce,unsigned int virq)94 xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce,
95 unsigned int virq)
96 {
97 int fd = xce->fd;
98 struct ioctl_evtchn_bind_virq bind;
99
100 bind.virq = virq;
101
102 return ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
103 }
104
xenevtchn_unbind(xenevtchn_handle * xce,evtchn_port_t port)105 int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port_t port)
106 {
107 int fd = xce->fd;
108 struct ioctl_evtchn_unbind unbind;
109
110 unbind.port = port;
111
112 return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
113 }
114
xenevtchn_pending(xenevtchn_handle * xce)115 xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn_handle *xce)
116 {
117 int fd = xce->fd;
118 evtchn_port_t port;
119
120 if ( read_exact(fd, (char *)&port, sizeof(port)) == -1 )
121 return -1;
122
123 return port;
124 }
125
xenevtchn_unmask(xenevtchn_handle * xce,evtchn_port_t port)126 int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port)
127 {
128 int fd = xce->fd;
129
130 return write_exact(fd, (char *)&port, sizeof(port));
131 }
132
133 /*
134 * Local variables:
135 * mode: C
136 * c-file-style: "BSD"
137 * c-basic-offset: 4
138 * tab-width: 4
139 * indent-tabs-mode: nil
140 * End:
141 */
142