xref: /openbmc/qemu/include/hw/xen/xen_pvdev.h (revision b8116f4c)
1 #ifndef QEMU_HW_XEN_PVDEV_H
2 #define QEMU_HW_XEN_PVDEV_H
3 
4 #include "hw/qdev-core.h"
5 #include "hw/xen/xen_backend_ops.h"
6 
7 /* ------------------------------------------------------------- */
8 
9 #define XEN_BUFSIZE 1024
10 
11 struct XenLegacyDevice;
12 
13 /* driver uses grant tables  ->  open gntdev device (xendev->gnttabdev) */
14 #define DEVOPS_FLAG_NEED_GNTDEV   1
15 /* don't expect frontend doing correct state transitions (aka console quirk) */
16 #define DEVOPS_FLAG_IGNORE_STATE  2
17 
18 struct XenDevOps {
19     size_t    size;
20     uint32_t  flags;
21     void      (*alloc)(struct XenLegacyDevice *xendev);
22     int       (*init)(struct XenLegacyDevice *xendev);
23     int       (*initialise)(struct XenLegacyDevice *xendev);
24     void      (*connected)(struct XenLegacyDevice *xendev);
25     void      (*event)(struct XenLegacyDevice *xendev);
26     void      (*disconnect)(struct XenLegacyDevice *xendev);
27     int       (*free)(struct XenLegacyDevice *xendev);
28     void      (*backend_changed)(struct XenLegacyDevice *xendev,
29                                  const char *node);
30     void      (*frontend_changed)(struct XenLegacyDevice *xendev,
31                                   const char *node);
32 };
33 
34 struct XenLegacyDevice {
35     DeviceState        qdev;
36     const char         *type;
37     int                dom;
38     int                dev;
39     char               name[64];
40     int                debug;
41 
42     struct qemu_xs_watch *watch;
43     enum xenbus_state  be_state;
44     enum xenbus_state  fe_state;
45     int                online;
46     char               be[XEN_BUFSIZE];
47     char               *fe;
48     char               *protocol;
49     int                remote_port;
50     int                local_port;
51 
52     xenevtchn_handle   *evtchndev;
53     xengnttab_handle   *gnttabdev;
54 
55     struct XenDevOps   *ops;
56     QTAILQ_ENTRY(XenLegacyDevice) next;
57 };
58 
59 /* ------------------------------------------------------------- */
60 
61 /* xenstore helper functions */
62 int xenstore_write_str(const char *base, const char *node, const char *val);
63 int xenstore_write_int(const char *base, const char *node, int ival);
64 int xenstore_write_int64(const char *base, const char *node, int64_t ival);
65 char *xenstore_read_str(const char *base, const char *node);
66 int xenstore_read_int(const char *base, const char *node, int *ival);
67 int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval);
68 
69 const char *xenbus_strstate(enum xenbus_state state);
70 
71 void xen_pv_evtchn_event(void *opaque);
72 void xen_pv_insert_xendev(struct XenLegacyDevice *xendev);
73 void xen_pv_del_xendev(struct XenLegacyDevice *xendev);
74 struct XenLegacyDevice *xen_pv_find_xendev(const char *type, int dom, int dev);
75 
76 void xen_pv_unbind_evtchn(struct XenLegacyDevice *xendev);
77 int xen_pv_send_notify(struct XenLegacyDevice *xendev);
78 
79 void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level,
80                    const char *fmt, ...)  G_GNUC_PRINTF(3, 4);
81 
82 #endif /* QEMU_HW_XEN_PVDEV_H */
83