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
  15typedef void (*XenWatchHandler)(void *opaque);
  16
  17typedef struct XenWatchList XenWatchList;
  18typedef struct XenWatch XenWatch;
  19typedef struct XenEventChannel XenEventChannel;
  20
  21typedef struct XenDevice {
  22    DeviceState qdev;
  23    domid_t frontend_id;
  24    char *name;
  25    struct xs_handle *xsh;
  26    XenWatchList *watch_list;
  27    char *backend_path, *frontend_path;
  28    enum xenbus_state backend_state, frontend_state;
  29    Notifier exit;
  30    XenWatch *backend_state_watch, *frontend_state_watch;
  31    bool backend_online;
  32    XenWatch *backend_online_watch;
  33    xengnttab_handle *xgth;
  34    bool feature_grant_copy;
  35    bool inactive;
  36    QLIST_HEAD(, XenEventChannel) event_channels;
  37    QLIST_ENTRY(XenDevice) list;
  38} XenDevice;
  39
  40typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
  41typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
  42typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
  43                                         enum xenbus_state frontend_state,
  44                                         Error **errp);
  45typedef void (*XenDeviceUnrealize)(XenDevice *xendev, Error **errp);
  46
  47typedef struct XenDeviceClass {
  48    /*< private >*/
  49    DeviceClass parent_class;
  50    /*< public >*/
  51    const char *backend;
  52    const char *device;
  53    XenDeviceGetName get_name;
  54    XenDeviceRealize realize;
  55    XenDeviceFrontendChanged frontend_changed;
  56    XenDeviceUnrealize unrealize;
  57} XenDeviceClass;
  58
  59#define TYPE_XEN_DEVICE "xen-device"
  60#define XEN_DEVICE(obj) \
  61     OBJECT_CHECK(XenDevice, (obj), TYPE_XEN_DEVICE)
  62#define XEN_DEVICE_CLASS(class) \
  63     OBJECT_CLASS_CHECK(XenDeviceClass, (class), TYPE_XEN_DEVICE)
  64#define XEN_DEVICE_GET_CLASS(obj) \
  65     OBJECT_GET_CLASS(XenDeviceClass, (obj), TYPE_XEN_DEVICE)
  66
  67typedef struct XenBus {
  68    BusState qbus;
  69    domid_t backend_id;
  70    struct xs_handle *xsh;
  71    XenWatchList *watch_list;
  72    XenWatch *backend_watch;
  73    QLIST_HEAD(, XenDevice) inactive_devices;
  74} XenBus;
  75
  76typedef struct XenBusClass {
  77    /*< private >*/
  78    BusClass parent_class;
  79} XenBusClass;
  80
  81#define TYPE_XEN_BUS "xen-bus"
  82#define XEN_BUS(obj) \
  83    OBJECT_CHECK(XenBus, (obj), TYPE_XEN_BUS)
  84#define XEN_BUS_CLASS(class) \
  85    OBJECT_CLASS_CHECK(XenBusClass, (class), TYPE_XEN_BUS)
  86#define XEN_BUS_GET_CLASS(obj) \
  87    OBJECT_GET_CLASS(XenBusClass, (obj), TYPE_XEN_BUS)
  88
  89void xen_bus_init(void);
  90
  91void xen_device_backend_set_state(XenDevice *xendev,
  92                                  enum xenbus_state state);
  93enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
  94
  95void xen_device_backend_printf(XenDevice *xendev, const char *key,
  96                               const char *fmt, ...)
  97    GCC_FMT_ATTR(3, 4);
  98void xen_device_frontend_printf(XenDevice *xendev, const char *key,
  99                                const char *fmt, ...)
 100    GCC_FMT_ATTR(3, 4);
 101
 102int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
 103                              const char *fmt, ...);
 104
 105void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
 106                                   Error **errp);
 107void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
 108                                unsigned int nr_refs, int prot,
 109                                Error **errp);
 110void xen_device_unmap_grant_refs(XenDevice *xendev, void *map,
 111                                 unsigned int nr_refs, Error **errp);
 112
 113typedef struct XenDeviceGrantCopySegment {
 114    union {
 115        void *virt;
 116        struct {
 117            uint32_t ref;
 118            off_t offset;
 119        } foreign;
 120    } source, dest;
 121    size_t len;
 122} XenDeviceGrantCopySegment;
 123
 124void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
 125                                XenDeviceGrantCopySegment segs[],
 126                                unsigned int nr_segs, Error **errp);
 127
 128typedef bool (*XenEventHandler)(void *opaque);
 129
 130XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
 131                                               AioContext *ctx,
 132                                               unsigned int port,
 133                                               XenEventHandler handler,
 134                                               void *opaque, Error **errp);
 135void xen_device_notify_event_channel(XenDevice *xendev,
 136                                     XenEventChannel *channel,
 137                                     Error **errp);
 138void xen_device_unbind_event_channel(XenDevice *xendev,
 139                                     XenEventChannel *channel,
 140                                     Error **errp);
 141
 142#endif /* HW_XEN_BUS_H */
 143