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