qemu/include/hw/xen/xen-bus.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2018  Citrix Systems Inc.
   3 *
   4 * This work is licensed under the terms of the GNU GPL, version 2 or later.
   5 * See the COPYING file in the top-level directory.
   6 */
   7
   8#ifndef HW_XEN_BUS_H
   9#define HW_XEN_BUS_H
  10
  11#include "hw/xen/xen_common.h"
  12#include "hw/sysbus.h"
  13#include "qemu/notify.h"
  14#include "qom/object.h"
  15
  16typedef void (*XenWatchHandler)(void *opaque);
  17
  18typedef struct XenWatchList XenWatchList;
  19typedef struct XenWatch XenWatch;
  20typedef struct XenEventChannel XenEventChannel;
  21
  22struct XenDevice {
  23    DeviceState qdev;
  24    domid_t frontend_id;
  25    char *name;
  26    struct xs_handle *xsh;
  27    XenWatchList *watch_list;
  28    char *backend_path, *frontend_path;
  29    enum xenbus_state backend_state, frontend_state;
  30    Notifier exit;
  31    XenWatch *backend_state_watch, *frontend_state_watch;
  32    bool backend_online;
  33    XenWatch *backend_online_watch;
  34    xengnttab_handle *xgth;
  35    bool feature_grant_copy;
  36    bool inactive;
  37    QLIST_HEAD(, XenEventChannel) event_channels;
  38    QLIST_ENTRY(XenDevice) list;
  39};
  40typedef struct XenDevice XenDevice;
  41
  42typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
  43typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
  44typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
  45                                         enum xenbus_state frontend_state,
  46                                         Error **errp);
  47typedef void (*XenDeviceUnrealize)(XenDevice *xendev);
  48
  49struct XenDeviceClass {
  50    /*< private >*/
  51    DeviceClass parent_class;
  52    /*< public >*/
  53    const char *backend;
  54    const char *device;
  55    XenDeviceGetName get_name;
  56    XenDeviceRealize realize;
  57    XenDeviceFrontendChanged frontend_changed;
  58    XenDeviceUnrealize unrealize;
  59};
  60
  61#define TYPE_XEN_DEVICE "xen-device"
  62OBJECT_DECLARE_TYPE(XenDevice, XenDeviceClass, XEN_DEVICE)
  63
  64struct XenBus {
  65    BusState qbus;
  66    domid_t backend_id;
  67    struct xs_handle *xsh;
  68    XenWatchList *watch_list;
  69    unsigned int backend_types;
  70    XenWatch **backend_watch;
  71    QLIST_HEAD(, XenDevice) inactive_devices;
  72};
  73
  74struct XenBusClass {
  75    /*< private >*/
  76    BusClass parent_class;
  77};
  78
  79#define TYPE_XEN_BUS "xen-bus"
  80OBJECT_DECLARE_TYPE(XenBus, XenBusClass,
  81                    XEN_BUS)
  82
  83void xen_bus_init(void);
  84
  85void xen_device_backend_set_state(XenDevice *xendev,
  86                                  enum xenbus_state state);
  87enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
  88
  89void xen_device_backend_printf(XenDevice *xendev, const char *key,
  90                               const char *fmt, ...)
  91    GCC_FMT_ATTR(3, 4);
  92void xen_device_frontend_printf(XenDevice *xendev, const char *key,
  93                                const char *fmt, ...)
  94    GCC_FMT_ATTR(3, 4);
  95
  96int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
  97                              const char *fmt, ...);
  98
  99void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
 100                                   Error **errp);
 101void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
 102                                unsigned int nr_refs, int prot,
 103                                Error **errp);
 104void xen_device_unmap_grant_refs(XenDevice *xendev, void *map,
 105                                 unsigned int nr_refs, Error **errp);
 106
 107typedef struct XenDeviceGrantCopySegment {
 108    union {
 109        void *virt;
 110        struct {
 111            uint32_t ref;
 112            off_t offset;
 113        } foreign;
 114    } source, dest;
 115    size_t len;
 116} XenDeviceGrantCopySegment;
 117
 118void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
 119                                XenDeviceGrantCopySegment segs[],
 120                                unsigned int nr_segs, Error **errp);
 121
 122typedef bool (*XenEventHandler)(void *opaque);
 123
 124XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
 125                                               unsigned int port,
 126                                               XenEventHandler handler,
 127                                               void *opaque, Error **errp);
 128void xen_device_set_event_channel_context(XenDevice *xendev,
 129                                          XenEventChannel *channel,
 130                                          AioContext *ctx,
 131                                          Error **errp);
 132void xen_device_notify_event_channel(XenDevice *xendev,
 133                                     XenEventChannel *channel,
 134                                     Error **errp);
 135void xen_device_unbind_event_channel(XenDevice *xendev,
 136                                     XenEventChannel *channel,
 137                                     Error **errp);
 138
 139#endif /* HW_XEN_BUS_H */
 140