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