virtio_pci_modern.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_VIRTIO_PCI_MODERN_H
  3. #define _LINUX_VIRTIO_PCI_MODERN_H
  4. #include <linux/pci.h>
  5. #include <linux/virtio_pci.h>
  6. struct virtio_pci_modern_common_cfg {
  7. struct virtio_pci_common_cfg cfg;
  8. __le16 queue_notify_data; /* read-write */
  9. __le16 queue_reset; /* read-write */
  10. };
  11. struct virtio_pci_modern_device {
  12. struct pci_dev *pci_dev;
  13. struct virtio_pci_common_cfg __iomem *common;
  14. /* Device-specific data (non-legacy mode) */
  15. void __iomem *device;
  16. /* Base of vq notifications (non-legacy mode). */
  17. void __iomem *notify_base;
  18. /* Physical base of vq notifications */
  19. resource_size_t notify_pa;
  20. /* Where to read and clear interrupt */
  21. u8 __iomem *isr;
  22. /* So we can sanity-check accesses. */
  23. size_t notify_len;
  24. size_t device_len;
  25. /* Capability for when we need to map notifications per-vq. */
  26. int notify_map_cap;
  27. /* Multiply queue_notify_off by this value. (non-legacy mode). */
  28. u32 notify_offset_multiplier;
  29. int modern_bars;
  30. struct virtio_device_id id;
  31. };
  32. /*
  33. * Type-safe wrappers for io accesses.
  34. * Use these to enforce at compile time the following spec requirement:
  35. *
  36. * The driver MUST access each field using the “natural” access
  37. * method, i.e. 32-bit accesses for 32-bit fields, 16-bit accesses
  38. * for 16-bit fields and 8-bit accesses for 8-bit fields.
  39. */
  40. static inline u8 vp_ioread8(const u8 __iomem *addr)
  41. {
  42. return ioread8(addr);
  43. }
  44. static inline u16 vp_ioread16 (const __le16 __iomem *addr)
  45. {
  46. return ioread16(addr);
  47. }
  48. static inline u32 vp_ioread32(const __le32 __iomem *addr)
  49. {
  50. return ioread32(addr);
  51. }
  52. static inline void vp_iowrite8(u8 value, u8 __iomem *addr)
  53. {
  54. iowrite8(value, addr);
  55. }
  56. static inline void vp_iowrite16(u16 value, __le16 __iomem *addr)
  57. {
  58. iowrite16(value, addr);
  59. }
  60. static inline void vp_iowrite32(u32 value, __le32 __iomem *addr)
  61. {
  62. iowrite32(value, addr);
  63. }
  64. static inline void vp_iowrite64_twopart(u64 val,
  65. __le32 __iomem *lo,
  66. __le32 __iomem *hi)
  67. {
  68. vp_iowrite32((u32)val, lo);
  69. vp_iowrite32(val >> 32, hi);
  70. }
  71. u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev);
  72. u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev);
  73. void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
  74. u64 features);
  75. u32 vp_modern_generation(struct virtio_pci_modern_device *mdev);
  76. u8 vp_modern_get_status(struct virtio_pci_modern_device *mdev);
  77. void vp_modern_set_status(struct virtio_pci_modern_device *mdev,
  78. u8 status);
  79. u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
  80. u16 idx, u16 vector);
  81. u16 vp_modern_config_vector(struct virtio_pci_modern_device *mdev,
  82. u16 vector);
  83. void vp_modern_queue_address(struct virtio_pci_modern_device *mdev,
  84. u16 index, u64 desc_addr, u64 driver_addr,
  85. u64 device_addr);
  86. void vp_modern_set_queue_enable(struct virtio_pci_modern_device *mdev,
  87. u16 idx, bool enable);
  88. bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev,
  89. u16 idx);
  90. void vp_modern_set_queue_size(struct virtio_pci_modern_device *mdev,
  91. u16 idx, u16 size);
  92. u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev,
  93. u16 idx);
  94. u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev);
  95. void __iomem * vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev,
  96. u16 index, resource_size_t *pa);
  97. int vp_modern_probe(struct virtio_pci_modern_device *mdev);
  98. void vp_modern_remove(struct virtio_pci_modern_device *mdev);
  99. int vp_modern_get_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
  100. void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
  101. #endif