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_eventfd_replace_locked(struct vfio_pci_core_device *vdev,
30 struct vfio_pci_eventfd __rcu **peventfd,
31 struct eventfd_ctx *ctx);
32
33 int vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags,
34 unsigned index, unsigned start, unsigned count,
35 void *data);
36
37 ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf,
38 size_t count, loff_t *ppos, bool iswrite);
39
40 ssize_t vfio_pci_config_rw_single(struct vfio_pci_core_device *vdev,
41 char __user *buf, size_t count, loff_t *ppos,
42 bool iswrite);
43
44 ssize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf,
45 size_t count, loff_t *ppos, bool iswrite);
46
47 #ifdef CONFIG_VFIO_PCI_VGA
48 ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf,
49 size_t count, loff_t *ppos, bool iswrite);
50 #else
vfio_pci_vga_rw(struct vfio_pci_core_device * vdev,char __user * buf,size_t count,loff_t * ppos,bool iswrite)51 static inline ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev,
52 char __user *buf, size_t count,
53 loff_t *ppos, bool iswrite)
54 {
55 return -EINVAL;
56 }
57 #endif
58
59 int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset,
60 uint64_t data, int count, int fd);
61
62 int vfio_pci_init_perm_bits(void);
63 void vfio_pci_uninit_perm_bits(void);
64
65 int vfio_config_init(struct vfio_pci_core_device *vdev);
66 void vfio_config_free(struct vfio_pci_core_device *vdev);
67
68 int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev,
69 pci_power_t state);
70
71 void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev);
72 u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev);
73 void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev,
74 u16 cmd);
75
76 #ifdef CONFIG_VFIO_PCI_IGD
77 bool vfio_pci_is_intel_display(struct pci_dev *pdev);
78 int vfio_pci_igd_init(struct vfio_pci_core_device *vdev);
79 #else
vfio_pci_is_intel_display(struct pci_dev * pdev)80 static inline bool vfio_pci_is_intel_display(struct pci_dev *pdev)
81 {
82 return false;
83 }
84
vfio_pci_igd_init(struct vfio_pci_core_device * vdev)85 static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev)
86 {
87 return -ENODEV;
88 }
89 #endif
90
91 #ifdef CONFIG_VFIO_PCI_ZDEV_KVM
92 int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
93 struct vfio_info_cap *caps);
94 int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev);
95 void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev);
96 int vfio_pci_zdev_feature_err(struct vfio_device *device, u32 flags,
97 void __user *arg, size_t argsz);
98 #else
vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device * vdev,struct vfio_info_cap * caps)99 static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
100 struct vfio_info_cap *caps)
101 {
102 return -ENODEV;
103 }
104
vfio_pci_zdev_open_device(struct vfio_pci_core_device * vdev)105 static inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)
106 {
107 return 0;
108 }
109
vfio_pci_zdev_close_device(struct vfio_pci_core_device * vdev)110 static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev)
111 {}
112
vfio_pci_zdev_feature_err(struct vfio_device * device,u32 flags,void __user * arg,size_t argsz)113 static inline int vfio_pci_zdev_feature_err(struct vfio_device *device,
114 u32 flags, void __user *arg,
115 size_t argsz)
116 {
117 return -ENOTTY;
118 }
119 #endif
120
vfio_pci_is_vga(struct pci_dev * pdev)121 static inline bool vfio_pci_is_vga(struct pci_dev *pdev)
122 {
123 return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA;
124 }
125
126 #ifdef CONFIG_VFIO_PCI_DMABUF
127 int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
128 struct vfio_device_feature_dma_buf __user *arg,
129 size_t argsz);
130 void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev);
131 void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, bool revoked);
132 #else
133 static inline int
vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device * vdev,u32 flags,struct vfio_device_feature_dma_buf __user * arg,size_t argsz)134 vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags,
135 struct vfio_device_feature_dma_buf __user *arg,
136 size_t argsz)
137 {
138 return -ENOTTY;
139 }
vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device * vdev)140 static inline void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev)
141 {
142 }
vfio_pci_dma_buf_move(struct vfio_pci_core_device * vdev,bool revoked)143 static inline void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev,
144 bool revoked)
145 {
146 }
147 #endif
148
149 #endif
150