162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci#ifndef VFIO_PCI_PRIV_H 362306a36Sopenharmony_ci#define VFIO_PCI_PRIV_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/vfio_pci_core.h> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci/* Special capability IDs predefined access */ 862306a36Sopenharmony_ci#define PCI_CAP_ID_INVALID 0xFF /* default raw access */ 962306a36Sopenharmony_ci#define PCI_CAP_ID_INVALID_VIRT 0xFE /* default virt access */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/* Cap maximum number of ioeventfds per device (arbitrary) */ 1262306a36Sopenharmony_ci#define VFIO_PCI_IOEVENTFD_MAX 1000 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_cistruct vfio_pci_ioeventfd { 1562306a36Sopenharmony_ci struct list_head next; 1662306a36Sopenharmony_ci struct vfio_pci_core_device *vdev; 1762306a36Sopenharmony_ci struct virqfd *virqfd; 1862306a36Sopenharmony_ci void __iomem *addr; 1962306a36Sopenharmony_ci uint64_t data; 2062306a36Sopenharmony_ci loff_t pos; 2162306a36Sopenharmony_ci int bar; 2262306a36Sopenharmony_ci int count; 2362306a36Sopenharmony_ci bool test_mem; 2462306a36Sopenharmony_ci}; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_cibool vfio_pci_intx_mask(struct vfio_pci_core_device *vdev); 2762306a36Sopenharmony_civoid vfio_pci_intx_unmask(struct vfio_pci_core_device *vdev); 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ciint vfio_pci_set_irqs_ioctl(struct vfio_pci_core_device *vdev, uint32_t flags, 3062306a36Sopenharmony_ci unsigned index, unsigned start, unsigned count, 3162306a36Sopenharmony_ci void *data); 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_cissize_t vfio_pci_config_rw(struct vfio_pci_core_device *vdev, char __user *buf, 3462306a36Sopenharmony_ci size_t count, loff_t *ppos, bool iswrite); 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cissize_t vfio_pci_bar_rw(struct vfio_pci_core_device *vdev, char __user *buf, 3762306a36Sopenharmony_ci size_t count, loff_t *ppos, bool iswrite); 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#ifdef CONFIG_VFIO_PCI_VGA 4062306a36Sopenharmony_cissize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, char __user *buf, 4162306a36Sopenharmony_ci size_t count, loff_t *ppos, bool iswrite); 4262306a36Sopenharmony_ci#else 4362306a36Sopenharmony_cistatic inline ssize_t vfio_pci_vga_rw(struct vfio_pci_core_device *vdev, 4462306a36Sopenharmony_ci char __user *buf, size_t count, 4562306a36Sopenharmony_ci loff_t *ppos, bool iswrite) 4662306a36Sopenharmony_ci{ 4762306a36Sopenharmony_ci return -EINVAL; 4862306a36Sopenharmony_ci} 4962306a36Sopenharmony_ci#endif 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ciint vfio_pci_ioeventfd(struct vfio_pci_core_device *vdev, loff_t offset, 5262306a36Sopenharmony_ci uint64_t data, int count, int fd); 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ciint vfio_pci_init_perm_bits(void); 5562306a36Sopenharmony_civoid vfio_pci_uninit_perm_bits(void); 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ciint vfio_config_init(struct vfio_pci_core_device *vdev); 5862306a36Sopenharmony_civoid vfio_config_free(struct vfio_pci_core_device *vdev); 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ciint vfio_pci_set_power_state(struct vfio_pci_core_device *vdev, 6162306a36Sopenharmony_ci pci_power_t state); 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cibool __vfio_pci_memory_enabled(struct vfio_pci_core_device *vdev); 6462306a36Sopenharmony_civoid vfio_pci_zap_and_down_write_memory_lock(struct vfio_pci_core_device *vdev); 6562306a36Sopenharmony_ciu16 vfio_pci_memory_lock_and_enable(struct vfio_pci_core_device *vdev); 6662306a36Sopenharmony_civoid vfio_pci_memory_unlock_and_restore(struct vfio_pci_core_device *vdev, 6762306a36Sopenharmony_ci u16 cmd); 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_ci#ifdef CONFIG_VFIO_PCI_IGD 7062306a36Sopenharmony_ciint vfio_pci_igd_init(struct vfio_pci_core_device *vdev); 7162306a36Sopenharmony_ci#else 7262306a36Sopenharmony_cistatic inline int vfio_pci_igd_init(struct vfio_pci_core_device *vdev) 7362306a36Sopenharmony_ci{ 7462306a36Sopenharmony_ci return -ENODEV; 7562306a36Sopenharmony_ci} 7662306a36Sopenharmony_ci#endif 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#ifdef CONFIG_VFIO_PCI_ZDEV_KVM 7962306a36Sopenharmony_ciint vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 8062306a36Sopenharmony_ci struct vfio_info_cap *caps); 8162306a36Sopenharmony_ciint vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev); 8262306a36Sopenharmony_civoid vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev); 8362306a36Sopenharmony_ci#else 8462306a36Sopenharmony_cistatic inline int vfio_pci_info_zdev_add_caps(struct vfio_pci_core_device *vdev, 8562306a36Sopenharmony_ci struct vfio_info_cap *caps) 8662306a36Sopenharmony_ci{ 8762306a36Sopenharmony_ci return -ENODEV; 8862306a36Sopenharmony_ci} 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_cistatic inline int vfio_pci_zdev_open_device(struct vfio_pci_core_device *vdev) 9162306a36Sopenharmony_ci{ 9262306a36Sopenharmony_ci return 0; 9362306a36Sopenharmony_ci} 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_cistatic inline void vfio_pci_zdev_close_device(struct vfio_pci_core_device *vdev) 9662306a36Sopenharmony_ci{} 9762306a36Sopenharmony_ci#endif 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_cistatic inline bool vfio_pci_is_vga(struct pci_dev *pdev) 10062306a36Sopenharmony_ci{ 10162306a36Sopenharmony_ci return (pdev->class >> 8) == PCI_CLASS_DISPLAY_VGA; 10262306a36Sopenharmony_ci} 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci#endif 105