xref: /openbmc/qemu/include/hw/xen/xen_pvdev.h (revision cdd684b8)
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     int       (*backend_register)(void);
33 };
34 
35 struct XenLegacyDevice {
36     DeviceState        qdev;
37     const char         *type;
38     int                dom;
39     int                dev;
40     char               name[64];
41     int                debug;
42 
43     struct qemu_xs_watch *watch;
44     enum xenbus_state  be_state;
45     enum xenbus_state  fe_state;
46     int                online;
47     char               be[XEN_BUFSIZE];
48     char               *fe;
49     char               *protocol;
50     int                remote_port;
51     int                local_port;
52 
53     xenevtchn_handle   *evtchndev;
54     xengnttab_handle   *gnttabdev;
55 
56     struct XenDevOps   *ops;
57     QTAILQ_ENTRY(XenLegacyDevice) next;
58 };
59 
60 /* ------------------------------------------------------------- */
61 
62 /* xenstore helper functions */
63 int xenstore_write_str(const char *base, const char *node, const char *val);
64 int xenstore_write_int(const char *base, const char *node, int ival);
65 int xenstore_write_int64(const char *base, const char *node, int64_t ival);
66 char *xenstore_read_str(const char *base, const char *node);
67 int xenstore_read_int(const char *base, const char *node, int *ival);
68 int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval);
69 
70 const char *xenbus_strstate(enum xenbus_state state);
71 
72 void xen_pv_evtchn_event(void *opaque);
73 void xen_pv_insert_xendev(struct XenLegacyDevice *xendev);
74 void xen_pv_del_xendev(struct XenLegacyDevice *xendev);
75 struct XenLegacyDevice *xen_pv_find_xendev(const char *type, int dom, int dev);
76 
77 void xen_pv_unbind_evtchn(struct XenLegacyDevice *xendev);
78 int xen_pv_send_notify(struct XenLegacyDevice *xendev);
79 
80 void xen_pv_printf(struct XenLegacyDevice *xendev, int msg_level,
81                    const char *fmt, ...)  G_GNUC_PRINTF(3, 4);
82 
83 #endif /* QEMU_HW_XEN_PVDEV_H */
84