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
14struct 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
26bool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev);
27void vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev);
28
29int 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
33ssize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf,
34 size_t count, loff_t *ppos, bool iswrite);
35
36ssize_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
40ssize_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
43static 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
51int vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset,
52 uint64_t data, int count, int fd);
53
54int vfio_pci_init_perm_bits(void);
55void vfio_pci_uninit_perm_bits(void);
56
57int vfio_config_init(struct vfio_pci_core_device *vdev);
58void vfio_config_free(struct vfio_pci_core_device *vdev);
59
60int vfio_pci_set_power_state(struct vfio_pci_core_device *vdev,
61 pci_power_t state);
62
63bool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev);
64void vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev);
65u16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev);
66void vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev,
67 u16 cmd);
68
69#ifdef CONFIG_VFIO_PCI_IGD
70int vfio_pci_igd_init(struct vfio_pci_core_device *vdev);
71#else
72static 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
79int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev,
80 struct vfio_info_cap *caps);
81int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev);
82void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev);
83#else
84static 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
90static inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev)
91{
92 return 0;
93}
94
95static inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev)
96{}
97#endif
98
99static 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

source code of linux/drivers/vfio/pci/vfio_pci_priv.h