1 #ifndef HW_XEN_LEGACY_BACKEND_H
2 #define HW_XEN_LEGACY_BACKEND_H
3 
4 #include "hw/xen/xen_common.h"
5 #include "hw/xen/xen_pvdev.h"
6 #include "net/net.h"
7 
8 #define TYPE_XENSYSDEV "xen-sysdev"
9 #define TYPE_XENSYSBUS "xen-sysbus"
10 #define TYPE_XENBACKEND "xen-backend"
11 
12 #define XENBACKEND_DEVICE(obj) \
13     OBJECT_CHECK(XenLegacyDevice, (obj), TYPE_XENBACKEND)
14 
15 /* variables */
16 extern struct xs_handle *xenstore;
17 extern const char *xen_protocol;
18 extern DeviceState *xen_sysdev;
19 extern BusState *xen_sysbus;
20 
21 int xenstore_mkdir(char *path, int p);
22 int xenstore_write_be_str(struct XenLegacyDevice *xendev, const char *node,
23                           const char *val);
24 int xenstore_write_be_int(struct XenLegacyDevice *xendev, const char *node,
25                           int ival);
26 int xenstore_write_be_int64(struct XenLegacyDevice *xendev, const char *node,
27                             int64_t ival);
28 char *xenstore_read_be_str(struct XenLegacyDevice *xendev, const char *node);
29 int xenstore_read_be_int(struct XenLegacyDevice *xendev, const char *node,
30                          int *ival);
31 void xenstore_update_fe(char *watch, struct XenLegacyDevice *xendev);
32 void xenstore_update_be(char *watch, char *type, int dom,
33                         struct XenDevOps *ops);
34 char *xenstore_read_fe_str(struct XenLegacyDevice *xendev, const char *node);
35 int xenstore_read_fe_int(struct XenLegacyDevice *xendev, const char *node,
36                          int *ival);
37 int xenstore_read_fe_uint64(struct XenLegacyDevice *xendev, const char *node,
38                             uint64_t *uval);
39 
40 void xen_be_check_state(struct XenLegacyDevice *xendev);
41 
42 /* xen backend driver bits */
43 int xen_be_init(void);
44 void xen_be_register_common(void);
45 int xen_be_register(const char *type, struct XenDevOps *ops);
46 int xen_be_set_state(struct XenLegacyDevice *xendev, enum xenbus_state state);
47 int xen_be_bind_evtchn(struct XenLegacyDevice *xendev);
48 void xen_be_set_max_grant_refs(struct XenLegacyDevice *xendev,
49                                unsigned int nr_refs);
50 void *xen_be_map_grant_refs(struct XenLegacyDevice *xendev, uint32_t *refs,
51                             unsigned int nr_refs, int prot);
52 void xen_be_unmap_grant_refs(struct XenLegacyDevice *xendev, void *ptr,
53                              unsigned int nr_refs);
54 
55 typedef struct XenGrantCopySegment {
56     union {
57         void *virt;
58         struct {
59             uint32_t ref;
60             off_t offset;
61         } foreign;
62     } source, dest;
63     size_t len;
64 } XenGrantCopySegment;
65 
66 int xen_be_copy_grant_refs(struct XenLegacyDevice *xendev,
67                            bool to_domain, XenGrantCopySegment segs[],
68                            unsigned int nr_segs);
69 
70 static inline void *xen_be_map_grant_ref(struct XenLegacyDevice *xendev,
71                                          uint32_t ref, int prot)
72 {
73     return xen_be_map_grant_refs(xendev, &ref, 1, prot);
74 }
75 
76 static inline void xen_be_unmap_grant_ref(struct XenLegacyDevice *xendev,
77                                           void *ptr)
78 {
79     return xen_be_unmap_grant_refs(xendev, ptr, 1);
80 }
81 
82 /* actual backend drivers */
83 extern struct XenDevOps xen_console_ops;      /* xen_console.c     */
84 extern struct XenDevOps xen_kbdmouse_ops;     /* xen_framebuffer.c */
85 extern struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
86 extern struct XenDevOps xen_blkdev_ops;       /* xen_disk.c        */
87 #ifdef CONFIG_VIRTFS
88 extern struct XenDevOps xen_9pfs_ops;       /* xen-9p-backend.c        */
89 #endif
90 extern struct XenDevOps xen_netdev_ops;       /* xen_nic.c         */
91 #ifdef CONFIG_USB_LIBUSB
92 extern struct XenDevOps xen_usb_ops;          /* xen-usb.c         */
93 #endif
94 
95 /* configuration (aka xenbus setup) */
96 void xen_config_cleanup(void);
97 int xen_config_dev_blk(DriveInfo *disk);
98 int xen_config_dev_nic(NICInfo *nic);
99 int xen_config_dev_vfb(int vdev, const char *type);
100 int xen_config_dev_vkbd(int vdev);
101 int xen_config_dev_console(int vdev);
102 
103 #endif /* HW_XEN_LEGACY_BACKEND_H */
104