apic: move target-dependent definitions to cpu.h
[qemu.git] / include / hw / xen / xen_backend.h
1 #ifndef QEMU_HW_XEN_BACKEND_H
2 #define QEMU_HW_XEN_BACKEND_H 1
3
4 #include "hw/xen/xen_common.h"
5 #include "sysemu/sysemu.h"
6 #include "net/net.h"
7
8 /* ------------------------------------------------------------- */
9
10 #define XEN_BUFSIZE 1024
11
12 struct XenDevice;
13
14 /* driver uses grant tables -> open gntdev device (xendev->gnttabdev) */
15 #define DEVOPS_FLAG_NEED_GNTDEV 1
16 /* don't expect frontend doing correct state transitions (aka console quirk) */
17 #define DEVOPS_FLAG_IGNORE_STATE 2
18
19 struct XenDevOps {
20 size_t size;
21 uint32_t flags;
22 void (*alloc)(struct XenDevice *xendev);
23 int (*init)(struct XenDevice *xendev);
24 int (*initialise)(struct XenDevice *xendev);
25 void (*connected)(struct XenDevice *xendev);
26 void (*event)(struct XenDevice *xendev);
27 void (*disconnect)(struct XenDevice *xendev);
28 int (*free)(struct XenDevice *xendev);
29 void (*backend_changed)(struct XenDevice *xendev, const char *node);
30 void (*frontend_changed)(struct XenDevice *xendev, const char *node);
31 };
32
33 struct XenDevice {
34 const char *type;
35 int dom;
36 int dev;
37 char name[64];
38 int debug;
39
40 enum xenbus_state be_state;
41 enum xenbus_state fe_state;
42 int online;
43 char be[XEN_BUFSIZE];
44 char *fe;
45 char *protocol;
46 int remote_port;
47 int local_port;
48
49 xenevtchn_handle *evtchndev;
50 xengnttab_handle *gnttabdev;
51
52 struct XenDevOps *ops;
53 QTAILQ_ENTRY(XenDevice) next;
54 };
55
56 /* ------------------------------------------------------------- */
57
58 /* variables */
59 extern xc_interface *xen_xc;
60 extern xenforeignmemory_handle *xen_fmem;
61 extern struct xs_handle *xenstore;
62 extern const char *xen_protocol;
63
64 /* xenstore helper functions */
65 int xenstore_write_str(const char *base, const char *node, const char *val);
66 int xenstore_write_int(const char *base, const char *node, int ival);
67 int xenstore_write_int64(const char *base, const char *node, int64_t ival);
68 char *xenstore_read_str(const char *base, const char *node);
69 int xenstore_read_int(const char *base, const char *node, int *ival);
70
71 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val);
72 int xenstore_write_be_int(struct XenDevice *xendev, const char *node, int ival);
73 int xenstore_write_be_int64(struct XenDevice *xendev, const char *node, int64_t ival);
74 char *xenstore_read_be_str(struct XenDevice *xendev, const char *node);
75 int xenstore_read_be_int(struct XenDevice *xendev, const char *node, int *ival);
76 char *xenstore_read_fe_str(struct XenDevice *xendev, const char *node);
77 int xenstore_read_fe_int(struct XenDevice *xendev, const char *node, int *ival);
78 int xenstore_read_uint64(const char *base, const char *node, uint64_t *uval);
79 int xenstore_read_fe_uint64(struct XenDevice *xendev, const char *node, uint64_t *uval);
80
81 const char *xenbus_strstate(enum xenbus_state state);
82 struct XenDevice *xen_be_find_xendev(const char *type, int dom, int dev);
83 void xen_be_check_state(struct XenDevice *xendev);
84
85 /* xen backend driver bits */
86 int xen_be_init(void);
87 int xen_be_register(const char *type, struct XenDevOps *ops);
88 int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state);
89 int xen_be_bind_evtchn(struct XenDevice *xendev);
90 void xen_be_unbind_evtchn(struct XenDevice *xendev);
91 int xen_be_send_notify(struct XenDevice *xendev);
92 void xen_be_printf(struct XenDevice *xendev, int msg_level, const char *fmt, ...)
93 GCC_FMT_ATTR(3, 4);
94
95 /* actual backend drivers */
96 extern struct XenDevOps xen_console_ops; /* xen_console.c */
97 extern struct XenDevOps xen_kbdmouse_ops; /* xen_framebuffer.c */
98 extern struct XenDevOps xen_framebuffer_ops; /* xen_framebuffer.c */
99 extern struct XenDevOps xen_blkdev_ops; /* xen_disk.c */
100 extern struct XenDevOps xen_netdev_ops; /* xen_nic.c */
101
102 void xen_init_display(int domid);
103
104 /* configuration (aka xenbus setup) */
105 void xen_config_cleanup(void);
106 int xen_config_dev_blk(DriveInfo *disk);
107 int xen_config_dev_nic(NICInfo *nic);
108 int xen_config_dev_vfb(int vdev, const char *type);
109 int xen_config_dev_vkbd(int vdev);
110 int xen_config_dev_console(int vdev);
111
112 #endif /* QEMU_HW_XEN_BACKEND_H */