Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio/pci: Split linux/vfio_pci_core.h

The header in include/linux should have only the exported interface for
other vfio_pci modules to use. Internal definitions for vfio_pci.ko
should be in a "priv" header along side the .c files.

Move the internal declarations out of vfio_pci_core.h. They either move to
vfio_pci_priv.h or to the C file that is the only user.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Link: https://lore.kernel.org/r/1-v2-1bd95d72f298+e0e-vfio_pci_priv_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Jason Gunthorpe and committed by
Alex Williamson
e34a0425 b90cb105

+145 -140
+1 -1
drivers/vfio/pci/vfio_pci.c
··· 25 25 #include <linux/types.h> 26 26 #include <linux/uaccess.h> 27 27 28 - #include <linux/vfio_pci_core.h> 28 + #include "vfio_pci_priv.h" 29 29 30 30 #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>" 31 31 #define DRIVER_DESC "VFIO PCI - User Level meta-driver"
+1 -1
drivers/vfio/pci/vfio_pci_config.c
··· 26 26 #include <linux/vfio.h> 27 27 #include <linux/slab.h> 28 28 29 - #include <linux/vfio_pci_core.h> 29 + #include "vfio_pci_priv.h" 30 30 31 31 /* Fake capability ID for standard config space */ 32 32 #define PCI_CAP_ID_BASIC 0
+18 -1
drivers/vfio/pci/vfio_pci_core.c
··· 28 28 #include <linux/nospec.h> 29 29 #include <linux/sched/mm.h> 30 30 31 - #include <linux/vfio_pci_core.h> 31 + #include "vfio_pci_priv.h" 32 32 33 33 #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>" 34 34 #define DRIVER_DESC "core driver for VFIO based PCI devices" ··· 40 40 /* List of PF's that vfio_pci_core_sriov_configure() has been called on */ 41 41 static DEFINE_MUTEX(vfio_pci_sriov_pfs_mutex); 42 42 static LIST_HEAD(vfio_pci_sriov_pfs); 43 + 44 + struct vfio_pci_dummy_resource { 45 + struct resource resource; 46 + int index; 47 + struct list_head res_next; 48 + }; 49 + 50 + struct vfio_pci_vf_token { 51 + struct mutex lock; 52 + uuid_t uuid; 53 + int users; 54 + }; 55 + 56 + struct vfio_pci_mmap_vma { 57 + struct vm_area_struct *vma; 58 + struct list_head vma_next; 59 + }; 43 60 44 61 static inline bool vfio_vga_disabled(void) 45 62 {
+1 -1
drivers/vfio/pci/vfio_pci_igd.c
··· 15 15 #include <linux/uaccess.h> 16 16 #include <linux/vfio.h> 17 17 18 - #include <linux/vfio_pci_core.h> 18 + #include "vfio_pci_priv.h" 19 19 20 20 #define OPREGION_SIGNATURE "IntelGraphicsMem" 21 21 #define OPREGION_SIZE (8 * 1024)
+15 -1
drivers/vfio/pci/vfio_pci_intrs.c
··· 20 20 #include <linux/wait.h> 21 21 #include <linux/slab.h> 22 22 23 - #include <linux/vfio_pci_core.h> 23 + #include "vfio_pci_priv.h" 24 + 25 + #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX) 26 + #define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX) 27 + #define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev))) 28 + #define irq_is(vdev, type) (vdev->irq_type == type) 29 + 30 + struct vfio_pci_irq_ctx { 31 + struct eventfd_ctx *trigger; 32 + struct virqfd *unmask; 33 + struct virqfd *mask; 34 + char *name; 35 + bool masked; 36 + struct irq_bypass_producer producer; 37 + }; 24 38 25 39 /* 26 40 * INTx
+106
drivers/vfio/pci/vfio_pci_priv.h
··· 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 + #define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX) 27 + 28 + void vfio_pci_intx_mask(struct vfio_pci_core_device *vdev); 29 + void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev); 30 + 31 + int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, 32 + unsigned index, unsigned start, unsigned count, 33 + void *data); 34 + 35 + ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf, 36 + size_t count, loff_t *ppos, bool iswrite); 37 + 38 + ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf, 39 + size_t count, loff_t *ppos, bool iswrite); 40 + 41 + #ifdef CONFIG_VFIO_PCI_VGA 42 + ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf, 43 + size_t count, loff_t *ppos, bool iswrite); 44 + #else 45 + static inline ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, 46 + char __user *buf, size_t count, 47 + loff_t *ppos, bool iswrite) 48 + { 49 + return -EINVAL; 50 + } 51 + #endif 52 + 53 + long vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, 54 + uint64_t data, int count, int fd); 55 + 56 + int vfio_pci_init_perm_bits(void); 57 + void vfio_pci_uninit_perm_bits(void); 58 + 59 + int vfio_config_init(struct vfio_pci_core_device *vdev); 60 + void vfio_config_free(struct vfio_pci_core_device *vdev); 61 + 62 + int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, 63 + pci_power_t state); 64 + 65 + bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev); 66 + void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev); 67 + u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev); 68 + void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev, 69 + u16 cmd); 70 + 71 + #ifdef CONFIG_VFIO_PCI_IGD 72 + int vfio_pci_igd_init(struct vfio_pci_core_device *vdev); 73 + #else 74 + static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev) 75 + { 76 + return -ENODEV; 77 + } 78 + #endif 79 + 80 + #ifdef CONFIG_VFIO_PCI_ZDEV_KVM 81 + int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 82 + struct vfio_info_cap *caps); 83 + int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev); 84 + void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev); 85 + #else 86 + static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 87 + struct vfio_info_cap *caps) 88 + { 89 + return -ENODEV; 90 + } 91 + 92 + static inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) 93 + { 94 + return 0; 95 + } 96 + 97 + static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev) 98 + {} 99 + #endif 100 + 101 + static inline bool vfio_pci_is_vga(struct pci_dev *pdev) 102 + { 103 + return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; 104 + } 105 + 106 + #endif
+1 -1
drivers/vfio/pci/vfio_pci_rdwr.c
··· 17 17 #include <linux/vfio.h> 18 18 #include <linux/vgaarb.h> 19 19 20 - #include <linux/vfio_pci_core.h> 20 + #include "vfio_pci_priv.h" 21 21 22 22 #ifdef __LITTLE_ENDIAN 23 23 #define vfio_ioread64 ioread64
+1 -1
drivers/vfio/pci/vfio_pci_zdev.c
··· 15 15 #include <asm/pci_clp.h> 16 16 #include <asm/pci_io.h> 17 17 18 - #include <linux/vfio_pci_core.h> 18 + #include "vfio_pci_priv.h" 19 19 20 20 /* 21 21 * Add the Base PCI Function information to the device info region.
+1 -133
include/linux/vfio_pci_core.h
··· 20 20 #define VFIO_PCI_CORE_H 21 21 22 22 #define VFIO_PCI_OFFSET_SHIFT 40 23 - 24 23 #define VFIO_PCI_OFFSET_TO_INDEX(off) (off >> VFIO_PCI_OFFSET_SHIFT) 25 24 #define VFIO_PCI_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_PCI_OFFSET_SHIFT) 26 25 #define VFIO_PCI_OFFSET_MASK (((u64)(1) << VFIO_PCI_OFFSET_SHIFT) - 1) 27 - 28 - /* Special capability IDs predefined access */ 29 - #define PCI_CAP_ID_INVALID 0xFF /* default raw access */ 30 - #define PCI_CAP_ID_INVALID_VIRT 0xFE /* default virt access */ 31 - 32 - /* Cap maximum number of ioeventfds per device (arbitrary) */ 33 - #define VFIO_PCI_IOEVENTFD_MAX 1000 34 - 35 - struct vfio_pci_ioeventfd { 36 - struct list_head next; 37 - struct vfio_pci_core_device *vdev; 38 - struct virqfd *virqfd; 39 - void __iomem *addr; 40 - uint64_t data; 41 - loff_t pos; 42 - int bar; 43 - int count; 44 - bool test_mem; 45 - }; 46 - 47 - struct vfio_pci_irq_ctx { 48 - struct eventfd_ctx *trigger; 49 - struct virqfd *unmask; 50 - struct virqfd *mask; 51 - char *name; 52 - bool masked; 53 - struct irq_bypass_producer producer; 54 - }; 55 26 56 27 struct vfio_pci_core_device; 57 28 struct vfio_pci_region; ··· 47 76 void *data; 48 77 size_t size; 49 78 u32 flags; 50 - }; 51 - 52 - struct vfio_pci_dummy_resource { 53 - struct resource resource; 54 - int index; 55 - struct list_head res_next; 56 - }; 57 - 58 - struct vfio_pci_vf_token { 59 - struct mutex lock; 60 - uuid_t uuid; 61 - int users; 62 - }; 63 - 64 - struct vfio_pci_mmap_vma { 65 - struct vm_area_struct *vma; 66 - struct list_head vma_next; 67 79 }; 68 80 69 81 struct vfio_pci_core_device { ··· 95 141 struct rw_semaphore memory_lock; 96 142 }; 97 143 98 - #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX) 99 - #define is_msi(vdev) (vdev->irq_type == VFIO_PCI_MSI_IRQ_INDEX) 100 - #define is_msix(vdev) (vdev->irq_type == VFIO_PCI_MSIX_IRQ_INDEX) 101 - #define is_irq_none(vdev) (!(is_intx(vdev) || is_msi(vdev) || is_msix(vdev))) 102 - #define irq_is(vdev, type) (vdev->irq_type == type) 103 - 104 - void vfio_pci_intx_mask(struct vfio_pci_core_device *vdev); 105 - void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev); 106 - 107 - int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, 108 - uint32_t flags, unsigned index, 109 - unsigned start, unsigned count, void *data); 110 - 111 - ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, 112 - char __user *buf, size_t count, 113 - loff_t *ppos, bool iswrite); 114 - 115 - ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf, 116 - size_t count, loff_t *ppos, bool iswrite); 117 - 118 - #ifdef CONFIG_VFIO_PCI_VGA 119 - ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf, 120 - size_t count, loff_t *ppos, bool iswrite); 121 - #else 122 - static inline ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, 123 - char __user *buf, size_t count, 124 - loff_t *ppos, bool iswrite) 125 - { 126 - return -EINVAL; 127 - } 128 - #endif 129 - 130 - long vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, 131 - uint64_t data, int count, int fd); 132 - 133 - int vfio_pci_init_perm_bits(void); 134 - void vfio_pci_uninit_perm_bits(void); 135 - 136 - int vfio_config_init(struct vfio_pci_core_device *vdev); 137 - void vfio_config_free(struct vfio_pci_core_device *vdev); 138 - 144 + /* Will be exported for vfio pci drivers usage */ 139 145 int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, 140 146 unsigned int type, unsigned int subtype, 141 147 const struct vfio_pci_regops *ops, 142 148 size_t size, u32 flags, void *data); 143 - 144 - int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, 145 - pci_power_t state); 146 - 147 - bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev); 148 - void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev); 149 - u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev); 150 - void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev, 151 - u16 cmd); 152 - 153 - #ifdef CONFIG_VFIO_PCI_IGD 154 - int vfio_pci_igd_init(struct vfio_pci_core_device *vdev); 155 - #else 156 - static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev) 157 - { 158 - return -ENODEV; 159 - } 160 - #endif 161 - 162 - #ifdef CONFIG_VFIO_PCI_ZDEV_KVM 163 - int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 164 - struct vfio_info_cap *caps); 165 - int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev); 166 - void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev); 167 - #else 168 - static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 169 - struct vfio_info_cap *caps) 170 - { 171 - return -ENODEV; 172 - } 173 - 174 - static inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) 175 - { 176 - return 0; 177 - } 178 - 179 - static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev) 180 - {} 181 - #endif 182 - 183 - /* Will be exported for vfio pci drivers usage */ 184 149 void vfio_pci_core_set_params(bool nointxmask, bool is_disable_vga, 185 150 bool is_disable_idle_d3); 186 151 void vfio_pci_core_close_device(struct vfio_device *core_vdev); ··· 128 255 void vfio_pci_core_finish_enable(struct vfio_pci_core_device *vdev); 129 256 pci_ers_result_t vfio_pci_core_aer_err_detected(struct pci_dev *pdev, 130 257 pci_channel_state_t state); 131 - 132 - static inline bool vfio_pci_is_vga(struct pci_dev *pdev) 133 - { 134 - return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; 135 - } 136 258 137 259 #endif /* VFIO_PCI_CORE_H */