1 #ifndef HW_XEN_HVM_COMMON_H
2 #define HW_XEN_HVM_COMMON_H
3
4 #include "qemu/queue.h"
5 #include "exec/hwaddr.h"
6 #include "hw/xen/xen_native.h"
7 #include "hw/xen/xen_backend_ops.h"
8 #include <xen/hvm/ioreq.h>
9
10 extern MemoryRegion xen_memory;
11 extern MemoryRegion xen_grants;
12 extern MemoryListener xen_io_listener;
13 extern DeviceListener xen_device_listener;
14
15 //#define DEBUG_XEN_HVM
16
17 #ifdef DEBUG_XEN_HVM
18 #define DPRINTF(fmt, ...) \
19 do { fprintf(stderr, "xen: " fmt, ## __VA_ARGS__); } while (0)
20 #else
21 #define DPRINTF(fmt, ...) \
22 do { } while (0)
23 #endif
24
25 #define XEN_GRANT_ADDR_OFF (1ULL << 63)
26
xen_vcpu_eport(shared_iopage_t * shared_page,int i)27 static inline uint32_t xen_vcpu_eport(shared_iopage_t *shared_page, int i)
28 {
29 return shared_page->vcpu_ioreq[i].vp_eport;
30 }
xen_vcpu_ioreq(shared_iopage_t * shared_page,int vcpu)31 static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu)
32 {
33 return &shared_page->vcpu_ioreq[vcpu];
34 }
35
36 #define BUFFER_IO_MAX_DELAY 100
37
38 typedef struct XenPhysmap {
39 hwaddr start_addr;
40 ram_addr_t size;
41 const char *name;
42 hwaddr phys_offset;
43
44 QLIST_ENTRY(XenPhysmap) list;
45 } XenPhysmap;
46
47 typedef struct XenPciDevice {
48 PCIDevice *pci_dev;
49 uint32_t sbdf;
50 QLIST_ENTRY(XenPciDevice) entry;
51 } XenPciDevice;
52
53 typedef struct XenIOState {
54 ioservid_t ioservid;
55 shared_iopage_t *shared_page;
56 buffered_iopage_t *buffered_io_page;
57 xenforeignmemory_resource_handle *fres;
58 QEMUTimer *buffered_io_timer;
59 CPUState **cpu_by_vcpu_id;
60 /* the evtchn port for polling the notification, */
61 evtchn_port_t *ioreq_local_port;
62 /* evtchn remote and local ports for buffered io */
63 evtchn_port_t bufioreq_remote_port;
64 evtchn_port_t bufioreq_local_port;
65 /* the evtchn fd for polling */
66 xenevtchn_handle *xce_handle;
67 /* which vcpu we are serving */
68 int send_vcpu;
69
70 struct xs_handle *xenstore;
71 MemoryListener memory_listener;
72 MemoryListener io_listener;
73 QLIST_HEAD(, XenPciDevice) dev_list;
74 DeviceListener device_listener;
75
76 bool has_bufioreq;
77
78 Notifier exit;
79 } XenIOState;
80
81 void xen_exit_notifier(Notifier *n, void *data);
82
83 void xen_region_add(MemoryListener *listener, MemoryRegionSection *section);
84 void xen_region_del(MemoryListener *listener, MemoryRegionSection *section);
85 void xen_io_add(MemoryListener *listener, MemoryRegionSection *section);
86 void xen_io_del(MemoryListener *listener, MemoryRegionSection *section);
87 void xen_device_realize(DeviceListener *listener, DeviceState *dev);
88 void xen_device_unrealize(DeviceListener *listener, DeviceState *dev);
89
90 void xen_hvm_change_state_handler(void *opaque, bool running, RunState rstate);
91 void xen_register_ioreq(XenIOState *state, unsigned int max_cpus,
92 uint8_t handle_bufioreq,
93 const MemoryListener *xen_memory_listener);
94
95 void cpu_ioreq_pio(ioreq_t *req);
96 #endif /* HW_XEN_HVM_COMMON_H */
97