1*11b8b9d5SCédric Le Goater /* 2*11b8b9d5SCédric Le Goater * VFIO Device interface 3*11b8b9d5SCédric Le Goater * 4*11b8b9d5SCédric Le Goater * Copyright Red Hat, Inc. 2012 5*11b8b9d5SCédric Le Goater * 6*11b8b9d5SCédric Le Goater * Authors: 7*11b8b9d5SCédric Le Goater * Alex Williamson <alex.williamson@redhat.com> 8*11b8b9d5SCédric Le Goater * 9*11b8b9d5SCédric Le Goater * This work is licensed under the terms of the GNU GPL, version 2. See 10*11b8b9d5SCédric Le Goater * the COPYING file in the top-level directory. 11*11b8b9d5SCédric Le Goater * 12*11b8b9d5SCédric Le Goater * Based on qemu-kvm device-assignment: 13*11b8b9d5SCédric Le Goater * Adapted for KVM by Qumranet. 14*11b8b9d5SCédric Le Goater * Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com) 15*11b8b9d5SCédric Le Goater * Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com) 16*11b8b9d5SCédric Le Goater * Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com) 17*11b8b9d5SCédric Le Goater * Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com) 18*11b8b9d5SCédric Le Goater * Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com) 19*11b8b9d5SCédric Le Goater */ 20*11b8b9d5SCédric Le Goater 21*11b8b9d5SCédric Le Goater #ifndef HW_VFIO_VFIO_COMMON_H 22*11b8b9d5SCédric Le Goater #define HW_VFIO_VFIO_COMMON_H 23*11b8b9d5SCédric Le Goater 24*11b8b9d5SCédric Le Goater #include "system/memory.h" 25*11b8b9d5SCédric Le Goater #include "qemu/queue.h" 26*11b8b9d5SCédric Le Goater #ifdef CONFIG_LINUX 27*11b8b9d5SCédric Le Goater #include <linux/vfio.h> 28*11b8b9d5SCédric Le Goater #endif 29*11b8b9d5SCédric Le Goater #include "system/system.h" 30*11b8b9d5SCédric Le Goater #include "hw/vfio/vfio-container-base.h" 31*11b8b9d5SCédric Le Goater #include "system/host_iommu_device.h" 32*11b8b9d5SCédric Le Goater #include "system/iommufd.h" 33*11b8b9d5SCédric Le Goater 34*11b8b9d5SCédric Le Goater #define VFIO_MSG_PREFIX "vfio %s: " 35*11b8b9d5SCédric Le Goater 36*11b8b9d5SCédric Le Goater enum { 37*11b8b9d5SCédric Le Goater VFIO_DEVICE_TYPE_PCI = 0, 38*11b8b9d5SCédric Le Goater VFIO_DEVICE_TYPE_PLATFORM = 1, 39*11b8b9d5SCédric Le Goater VFIO_DEVICE_TYPE_CCW = 2, 40*11b8b9d5SCédric Le Goater VFIO_DEVICE_TYPE_AP = 3, 41*11b8b9d5SCédric Le Goater }; 42*11b8b9d5SCédric Le Goater 43*11b8b9d5SCédric Le Goater typedef struct VFIODeviceOps VFIODeviceOps; 44*11b8b9d5SCédric Le Goater typedef struct VFIOMigration VFIOMigration; 45*11b8b9d5SCédric Le Goater 46*11b8b9d5SCédric Le Goater typedef struct IOMMUFDBackend IOMMUFDBackend; 47*11b8b9d5SCédric Le Goater typedef struct VFIOIOASHwpt VFIOIOASHwpt; 48*11b8b9d5SCédric Le Goater 49*11b8b9d5SCédric Le Goater typedef struct VFIODevice { 50*11b8b9d5SCédric Le Goater QLIST_ENTRY(VFIODevice) next; 51*11b8b9d5SCédric Le Goater QLIST_ENTRY(VFIODevice) container_next; 52*11b8b9d5SCédric Le Goater QLIST_ENTRY(VFIODevice) global_next; 53*11b8b9d5SCédric Le Goater struct VFIOGroup *group; 54*11b8b9d5SCédric Le Goater VFIOContainerBase *bcontainer; 55*11b8b9d5SCédric Le Goater char *sysfsdev; 56*11b8b9d5SCédric Le Goater char *name; 57*11b8b9d5SCédric Le Goater DeviceState *dev; 58*11b8b9d5SCédric Le Goater int fd; 59*11b8b9d5SCédric Le Goater int type; 60*11b8b9d5SCédric Le Goater bool mdev; 61*11b8b9d5SCédric Le Goater bool reset_works; 62*11b8b9d5SCédric Le Goater bool needs_reset; 63*11b8b9d5SCédric Le Goater bool no_mmap; 64*11b8b9d5SCédric Le Goater bool ram_block_discard_allowed; 65*11b8b9d5SCédric Le Goater OnOffAuto enable_migration; 66*11b8b9d5SCédric Le Goater OnOffAuto migration_multifd_transfer; 67*11b8b9d5SCédric Le Goater bool migration_events; 68*11b8b9d5SCédric Le Goater VFIODeviceOps *ops; 69*11b8b9d5SCédric Le Goater unsigned int num_irqs; 70*11b8b9d5SCédric Le Goater unsigned int num_regions; 71*11b8b9d5SCédric Le Goater unsigned int flags; 72*11b8b9d5SCédric Le Goater VFIOMigration *migration; 73*11b8b9d5SCédric Le Goater Error *migration_blocker; 74*11b8b9d5SCédric Le Goater OnOffAuto pre_copy_dirty_page_tracking; 75*11b8b9d5SCédric Le Goater OnOffAuto device_dirty_page_tracking; 76*11b8b9d5SCédric Le Goater bool dirty_pages_supported; 77*11b8b9d5SCédric Le Goater bool dirty_tracking; /* Protected by BQL */ 78*11b8b9d5SCédric Le Goater bool iommu_dirty_tracking; 79*11b8b9d5SCédric Le Goater HostIOMMUDevice *hiod; 80*11b8b9d5SCédric Le Goater int devid; 81*11b8b9d5SCédric Le Goater IOMMUFDBackend *iommufd; 82*11b8b9d5SCédric Le Goater VFIOIOASHwpt *hwpt; 83*11b8b9d5SCédric Le Goater QLIST_ENTRY(VFIODevice) hwpt_next; 84*11b8b9d5SCédric Le Goater } VFIODevice; 85*11b8b9d5SCédric Le Goater 86*11b8b9d5SCédric Le Goater struct VFIODeviceOps { 87*11b8b9d5SCédric Le Goater void (*vfio_compute_needs_reset)(VFIODevice *vdev); 88*11b8b9d5SCédric Le Goater int (*vfio_hot_reset_multi)(VFIODevice *vdev); 89*11b8b9d5SCédric Le Goater void (*vfio_eoi)(VFIODevice *vdev); 90*11b8b9d5SCédric Le Goater Object *(*vfio_get_object)(VFIODevice *vdev); 91*11b8b9d5SCédric Le Goater 92*11b8b9d5SCédric Le Goater /** 93*11b8b9d5SCédric Le Goater * @vfio_save_config 94*11b8b9d5SCédric Le Goater * 95*11b8b9d5SCédric Le Goater * Save device config state 96*11b8b9d5SCédric Le Goater * 97*11b8b9d5SCédric Le Goater * @vdev: #VFIODevice for which to save the config 98*11b8b9d5SCédric Le Goater * @f: #QEMUFile where to send the data 99*11b8b9d5SCédric Le Goater * @errp: pointer to Error*, to store an error if it happens. 100*11b8b9d5SCédric Le Goater * 101*11b8b9d5SCédric Le Goater * Returns zero to indicate success and negative for error 102*11b8b9d5SCédric Le Goater */ 103*11b8b9d5SCédric Le Goater int (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f, Error **errp); 104*11b8b9d5SCédric Le Goater 105*11b8b9d5SCédric Le Goater /** 106*11b8b9d5SCédric Le Goater * @vfio_load_config 107*11b8b9d5SCédric Le Goater * 108*11b8b9d5SCédric Le Goater * Load device config state 109*11b8b9d5SCédric Le Goater * 110*11b8b9d5SCédric Le Goater * @vdev: #VFIODevice for which to load the config 111*11b8b9d5SCédric Le Goater * @f: #QEMUFile where to get the data 112*11b8b9d5SCédric Le Goater * 113*11b8b9d5SCédric Le Goater * Returns zero to indicate success and negative for error 114*11b8b9d5SCédric Le Goater */ 115*11b8b9d5SCédric Le Goater int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); 116*11b8b9d5SCédric Le Goater }; 117*11b8b9d5SCédric Le Goater 118*11b8b9d5SCédric Le Goater void vfio_disable_irqindex(VFIODevice *vbasedev, int index); 119*11b8b9d5SCédric Le Goater void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index); 120*11b8b9d5SCédric Le Goater void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index); 121*11b8b9d5SCédric Le Goater bool vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, 122*11b8b9d5SCédric Le Goater int action, int fd, Error **errp); 123*11b8b9d5SCédric Le Goater 124*11b8b9d5SCédric Le Goater void vfio_reset_handler(void *opaque); 125*11b8b9d5SCédric Le Goater bool vfio_device_is_mdev(VFIODevice *vbasedev); 126*11b8b9d5SCédric Le Goater bool vfio_device_hiod_realize(VFIODevice *vbasedev, Error **errp); 127*11b8b9d5SCédric Le Goater bool vfio_attach_device(char *name, VFIODevice *vbasedev, 128*11b8b9d5SCédric Le Goater AddressSpace *as, Error **errp); 129*11b8b9d5SCédric Le Goater void vfio_detach_device(VFIODevice *vbasedev); 130*11b8b9d5SCédric Le Goater VFIODevice *vfio_get_vfio_device(Object *obj); 131*11b8b9d5SCédric Le Goater 132*11b8b9d5SCédric Le Goater typedef QLIST_HEAD(VFIODeviceList, VFIODevice) VFIODeviceList; 133*11b8b9d5SCédric Le Goater extern VFIODeviceList vfio_device_list; 134*11b8b9d5SCédric Le Goater 135*11b8b9d5SCédric Le Goater #ifdef CONFIG_LINUX 136*11b8b9d5SCédric Le Goater int vfio_get_region_info(VFIODevice *vbasedev, int index, 137*11b8b9d5SCédric Le Goater struct vfio_region_info **info); 138*11b8b9d5SCédric Le Goater int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, 139*11b8b9d5SCédric Le Goater uint32_t subtype, struct vfio_region_info **info); 140*11b8b9d5SCédric Le Goater bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type); 141*11b8b9d5SCédric Le Goater #endif 142*11b8b9d5SCédric Le Goater 143*11b8b9d5SCédric Le Goater /* Returns 0 on success, or a negative errno. */ 144*11b8b9d5SCédric Le Goater bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp); 145*11b8b9d5SCédric Le Goater void vfio_device_set_fd(VFIODevice *vbasedev, const char *str, Error **errp); 146*11b8b9d5SCédric Le Goater void vfio_device_init(VFIODevice *vbasedev, int type, VFIODeviceOps *ops, 147*11b8b9d5SCédric Le Goater DeviceState *dev, bool ram_discard); 148*11b8b9d5SCédric Le Goater int vfio_device_get_aw_bits(VFIODevice *vdev); 149*11b8b9d5SCédric Le Goater #endif /* HW_VFIO_VFIO_COMMON_H */ 150