mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 01:03:55 -06:00
hw/xen: Add evtchn operations to allow redirection to internal emulation
The existing implementation calling into the real libxenevtchn moves to a new file hw/xen/xen-operations.c, and is called via a function table which in a subsequent commit will also be able to invoke the emulated event channel support. Signed-off-by: David Woodhouse <dwmw@amazon.co.uk> Reviewed-by: Paul Durrant <paul@xen.org>
This commit is contained in:
parent
831b0db8ab
commit
b6cacfea0b
13 changed files with 242 additions and 57 deletions
|
@ -8,6 +8,7 @@
|
|||
#ifndef HW_XEN_BUS_H
|
||||
#define HW_XEN_BUS_H
|
||||
|
||||
#include "hw/xen/xen_backend_ops.h"
|
||||
#include "hw/xen/xen_common.h"
|
||||
#include "hw/sysbus.h"
|
||||
#include "qemu/notify.h"
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define HW_XEN_LEGACY_BACKEND_H
|
||||
|
||||
#include "hw/xen/xen_common.h"
|
||||
#include "hw/xen/xen_backend_ops.h"
|
||||
#include "hw/xen/xen_pvdev.h"
|
||||
#include "net/net.h"
|
||||
#include "qom/object.h"
|
||||
|
|
118
include/hw/xen/xen_backend_ops.h
Normal file
118
include/hw/xen/xen_backend_ops.h
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* QEMU Xen backend support
|
||||
*
|
||||
* Copyright © 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
*
|
||||
* Authors: David Woodhouse <dwmw2@infradead.org>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#ifndef QEMU_XEN_BACKEND_OPS_H
|
||||
#define QEMU_XEN_BACKEND_OPS_H
|
||||
|
||||
/*
|
||||
* For the time being, these operations map fairly closely to the API of
|
||||
* the actual Xen libraries, e.g. libxenevtchn. As we complete the migration
|
||||
* from XenLegacyDevice back ends to the new XenDevice model, they may
|
||||
* evolve to slightly higher-level APIs.
|
||||
*
|
||||
* The internal emulations do not emulate the Xen APIs entirely faithfully;
|
||||
* only enough to be used by the Xen backend devices. For example, only one
|
||||
* event channel can be bound to each handle, since that's sufficient for
|
||||
* the device support (only the true Xen HVM backend uses more). And the
|
||||
* behaviour of unmask() and pending() is different too because the device
|
||||
* backends don't care.
|
||||
*/
|
||||
|
||||
typedef struct xenevtchn_handle xenevtchn_handle;
|
||||
typedef int xenevtchn_port_or_error_t;
|
||||
typedef uint32_t evtchn_port_t;
|
||||
|
||||
struct evtchn_backend_ops {
|
||||
xenevtchn_handle *(*open)(void);
|
||||
int (*bind_interdomain)(xenevtchn_handle *xc, uint32_t domid,
|
||||
evtchn_port_t guest_port);
|
||||
int (*unbind)(xenevtchn_handle *xc, evtchn_port_t port);
|
||||
int (*close)(struct xenevtchn_handle *xc);
|
||||
int (*get_fd)(struct xenevtchn_handle *xc);
|
||||
int (*notify)(struct xenevtchn_handle *xc, evtchn_port_t port);
|
||||
int (*unmask)(struct xenevtchn_handle *xc, evtchn_port_t port);
|
||||
int (*pending)(struct xenevtchn_handle *xc);
|
||||
};
|
||||
|
||||
extern struct evtchn_backend_ops *xen_evtchn_ops;
|
||||
|
||||
static inline xenevtchn_handle *qemu_xen_evtchn_open(void)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return NULL;
|
||||
}
|
||||
return xen_evtchn_ops->open();
|
||||
}
|
||||
|
||||
static inline int qemu_xen_evtchn_bind_interdomain(xenevtchn_handle *xc,
|
||||
uint32_t domid,
|
||||
evtchn_port_t guest_port)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
return xen_evtchn_ops->bind_interdomain(xc, domid, guest_port);
|
||||
}
|
||||
|
||||
static inline int qemu_xen_evtchn_unbind(xenevtchn_handle *xc,
|
||||
evtchn_port_t port)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
return xen_evtchn_ops->unbind(xc, port);
|
||||
}
|
||||
|
||||
static inline int qemu_xen_evtchn_close(xenevtchn_handle *xc)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
return xen_evtchn_ops->close(xc);
|
||||
}
|
||||
|
||||
static inline int qemu_xen_evtchn_fd(xenevtchn_handle *xc)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
return xen_evtchn_ops->get_fd(xc);
|
||||
}
|
||||
|
||||
static inline int qemu_xen_evtchn_notify(xenevtchn_handle *xc,
|
||||
evtchn_port_t port)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
return xen_evtchn_ops->notify(xc, port);
|
||||
}
|
||||
|
||||
static inline int qemu_xen_evtchn_unmask(xenevtchn_handle *xc,
|
||||
evtchn_port_t port)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
return xen_evtchn_ops->unmask(xc, port);
|
||||
}
|
||||
|
||||
static inline int qemu_xen_evtchn_pending(xenevtchn_handle *xc)
|
||||
{
|
||||
if (!xen_evtchn_ops) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
return xen_evtchn_ops->pending(xc);
|
||||
}
|
||||
|
||||
void setup_xen_backend_ops(void);
|
||||
|
||||
#endif /* QEMU_XEN_BACKEND_OPS_H */
|
|
@ -28,18 +28,7 @@ extern xc_interface *xen_xc;
|
|||
#if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40701
|
||||
|
||||
typedef xc_interface xenforeignmemory_handle;
|
||||
typedef xc_evtchn xenevtchn_handle;
|
||||
typedef xc_gnttab xengnttab_handle;
|
||||
typedef evtchn_port_or_error_t xenevtchn_port_or_error_t;
|
||||
|
||||
#define xenevtchn_open(l, f) xc_evtchn_open(l, f);
|
||||
#define xenevtchn_close(h) xc_evtchn_close(h)
|
||||
#define xenevtchn_fd(h) xc_evtchn_fd(h)
|
||||
#define xenevtchn_pending(h) xc_evtchn_pending(h)
|
||||
#define xenevtchn_notify(h, p) xc_evtchn_notify(h, p)
|
||||
#define xenevtchn_bind_interdomain(h, d, p) xc_evtchn_bind_interdomain(h, d, p)
|
||||
#define xenevtchn_unmask(h, p) xc_evtchn_unmask(h, p)
|
||||
#define xenevtchn_unbind(h, p) xc_evtchn_unbind(h, p)
|
||||
|
||||
#define xengnttab_open(l, f) xc_gnttab_open(l, f)
|
||||
#define xengnttab_close(h) xc_gnttab_close(h)
|
||||
|
@ -69,7 +58,6 @@ static inline void *xenforeignmemory_map(xc_interface *h, uint32_t dom,
|
|||
|
||||
#else /* CONFIG_XEN_CTRL_INTERFACE_VERSION >= 40701 */
|
||||
|
||||
#include <xenevtchn.h>
|
||||
#include <xengnttab.h>
|
||||
#include <xenforeignmemory.h>
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef QEMU_HW_XEN_PVDEV_H
|
||||
#define QEMU_HW_XEN_PVDEV_H
|
||||
|
||||
#include "hw/xen/xen_backend_ops.h"
|
||||
#include "hw/xen/xen_common.h"
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue