vfio_pci_priv.h 3.0 KB

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