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 | int vfio_pci_igd_init(struct vfio_pci_core_device *vdev); |
71 | #else |
72 | static inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev) |
73 | { |
74 | return -ENODEV; |
75 | } |
76 | #endif |
77 | |
78 | #ifdef CONFIG_VFIO_PCI_ZDEV_KVM |
79 | int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, |
80 | struct vfio_info_cap *caps); |
81 | int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev); |
82 | void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev); |
83 | #else |
84 | static inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, |
85 | struct vfio_info_cap *caps) |
86 | { |
87 | return -ENODEV; |
88 | } |
89 | |
90 | static inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) |
91 | { |
92 | return 0; |
93 | } |
94 | |
95 | static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev) |
96 | {} |
97 | #endif |
98 | |
99 | static inline bool vfio_pci_is_vga(struct pci_dev *pdev) |
100 | { |
101 | return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; |
102 | } |
103 | |
104 | #endif |
105 | |