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