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