Files
xen/tools/libs/evtchn/freebsd.c
T
Ian Campbell bc8baa9673 libxenevtchn: rename evtchn_port_or_errot_t as xenevtchn_port...
Otherwise the name clashes with the libxc evtchn_compat use of the
name (which is compat, so can't really change), and triggers an error
with older gcc relating to redefining typedefs (which are not allowed
per the spec, but which are tolerated by newer gcc)

None of qemu-trad, qemu-xen or mini-os actually use this type, so this
should be fine. Note that the library API is not actually stable until
4.7 is releases.

Reported-by: Olaf Hering <olaf@aepfle.de>
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Tested-by: Olaf Hering <olaf@aepfle.de>
Acked-by: Wei Liu <wei.liu2@citrix.com>
2016-02-04 15:19:30 +00:00

139 lines
3.2 KiB
C

/******************************************************************************
*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; If not, see <http://www.gnu.org/licenses/>.
*
* Split off from xc_freebsd_osdep.c
*/
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <xen/sys/evtchn.h>
#include "private.h"
#define EVTCHN_DEV "/dev/xen/evtchn"
int osdep_evtchn_open(xenevtchn_handle *xce)
{
int fd = open(EVTCHN_DEV, O_RDWR|O_CLOEXEC);
if ( fd == -1 )
return -1;
xce->fd = fd;
return 0;
}
int osdep_evtchn_close(xenevtchn_handle *xce)
{
if ( xce->fd == -1 )
return 0;
return close(xce->fd);
}
int xenevtchn_fd(xenevtchn_handle *xce)
{
return xce->fd;
}
int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port)
{
int fd = xce->fd;
struct ioctl_evtchn_notify notify;
notify.port = port;
return ioctl(fd, IOCTL_EVTCHN_NOTIFY, &notify);
}
xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, uint32_t domid)
{
int ret, fd = xce->fd;
struct ioctl_evtchn_bind_unbound_port bind;
bind.remote_domain = domid;
ret = ioctl(fd, IOCTL_EVTCHN_BIND_UNBOUND_PORT, &bind);
return ( ret == 0 ) ? bind.port : ret;
}
xenevtchn_port_or_error_t
xenevtchn_bind_interdomain(xenevtchn_handle *xce, uint32_t domid, evtchn_port_t remote_port)
{
int ret, fd = xce->fd;
struct ioctl_evtchn_bind_interdomain bind;
bind.remote_domain = domid;
bind.remote_port = remote_port;
ret = ioctl(fd, IOCTL_EVTCHN_BIND_INTERDOMAIN, &bind);
return ( ret == 0 ) ? bind.port : ret;
}
xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsigned int virq)
{
int ret, fd = xce->fd;
struct ioctl_evtchn_bind_virq bind;
bind.virq = virq;
ret = ioctl(fd, IOCTL_EVTCHN_BIND_VIRQ, &bind);
return ( ret == 0 ) ? bind.port : ret;
}
int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port_t port)
{
int fd = xce->fd;
struct ioctl_evtchn_unbind unbind;
unbind.port = port;
return ioctl(fd, IOCTL_EVTCHN_UNBIND, &unbind);
}
xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn_handle *xce)
{
int fd = xce->fd;
evtchn_port_t port;
if ( read(fd, &port, sizeof(port)) != sizeof(port) )
return -1;
return port;
}
int xenevtchn_unmask(xenevtchn_handle *xce, evtchn_port_t port)
{
int fd = xce->fd;
if ( write(fd, &port, sizeof(port)) != sizeof(port) )
return -1;
return 0;
}
/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* tab-width: 4
* indent-tabs-mode: nil
* End:
*/