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