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