1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 #ifndef VFIO_PCI_PRIV_H 3 #define VFIO_PCI_PRIV_H 4 5 #include <linux/vfio_pci_core.h> 6 7 /* Special capability IDs predefined access */ 8 #define PCI_CAP_ID_INVALID 0xFF /* default raw access */ 9 #define PCI_CAP_ID_INVALID_VIRT 0xFE /* default virt access */ 10 11 /* Cap maximum number of ioeventfds per device (arbitrary) */ 12 #define VFIO_PCI_IOEVENTFD_MAX 1000 13 14 struct vfio_pci_ioeventfd { 15 struct list_head next; 16 struct vfio_pci_core_device *vdev; 17 struct virqfd *virqfd; 18 void __iomem *addr; 19 uint64_t data; 20 loff_t pos; 21 int bar; 22 int count; 23 bool test_mem; 24 }; 25 26 bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev); 27 void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev); 28 29 int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, 30 unsigned index, unsigned start, unsigned count, 31 void *data); 32 33 ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf, 34 size_t count, loff_t *ppos, bool iswrite); 35 36 ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf, 37 size_t count, loff_t *ppos, bool iswrite); 38 39 #ifdef CONFIG_VFIO_PCI_VGA 40 ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf, 41 size_t count, loff_t *ppos, bool iswrite); 42 #else 43 static inline ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, 44 char __user *buf, size_t count, 45 loff_t *ppos, bool iswrite) 46 { 47 return -EINVAL; 48 } 49 #endif 50 51 int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, 52 uint64_t data, int count, int fd); 53 54 int vfio_pci_init_perm_bits(void); 55 void vfio_pci_uninit_perm_bits(void); 56 57 int vfio_config_init(struct vfio_pci_core_device *vdev); 58 void vfio_config_free(struct vfio_pci_core_device *vdev); 59 60 int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, 61 pci_power_t state); 62 63 bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev); 64 void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev); 65 u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev); 66 void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev, 67 u16 cmd); 68 69 #ifdef CONFIG_VFIO_PCI_IGD 70 bool vfio_pci_is_intel_display(struct pci_dev *pdev); 71 int vfio_pci_igd_init(struct vfio_pci_core_device *vdev); 72 #else 73 static inline bool vfio_pci_is_intel_display(struct pci_dev *pdev) 74 { 75 return false; 76 } 77 78 static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev) 79 { 80 return -ENODEV; 81 } 82 #endif 83 84 #ifdef CONFIG_VFIO_PCI_ZDEV_KVM 85 int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 86 struct vfio_info_cap *caps); 87 int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev); 88 void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev); 89 #else 90 static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 91 struct vfio_info_cap *caps) 92 { 93 return -ENODEV; 94 } 95 96 static inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) 97 { 98 return 0; 99 } 100 101 static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev) 102 {} 103 #endif 104 105 static inline bool vfio_pci_is_vga(struct pci_dev *pdev) 106 { 107 return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; 108 } 109 110 #endif 111