virtio_ring.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef _LINUX_VIRTIO_RING_H
  2. #define _LINUX_VIRTIO_RING_H
  3. #include <linux/irqreturn.h>
  4. #include <uapi/linux/virtio_ring.h>
  5. /*
  6. * Barriers in virtio are tricky. Non-SMP virtio guests can't assume
  7. * they're not on an SMP host system, so they need to assume real
  8. * barriers. Non-SMP virtio hosts could skip the barriers, but does
  9. * anyone care?
  10. *
  11. * For virtio_pci on SMP, we don't need to order with respect to MMIO
  12. * accesses through relaxed memory I/O windows, so smp_mb() et al are
  13. * sufficient.
  14. *
  15. * For using virtio to talk to real devices (eg. other heterogeneous
  16. * CPUs) we do need real barriers. In theory, we could be using both
  17. * kinds of virtio, so it's a runtime decision, and the branch is
  18. * actually quite cheap.
  19. */
  20. #ifdef CONFIG_SMP
  21. static inline void virtio_mb(bool weak_barriers)
  22. {
  23. if (weak_barriers)
  24. smp_mb();
  25. else
  26. mb();
  27. }
  28. static inline void virtio_rmb(bool weak_barriers)
  29. {
  30. if (weak_barriers)
  31. smp_rmb();
  32. else
  33. rmb();
  34. }
  35. static inline void virtio_wmb(bool weak_barriers)
  36. {
  37. if (weak_barriers)
  38. smp_wmb();
  39. else
  40. wmb();
  41. }
  42. #else
  43. static inline void virtio_mb(bool weak_barriers)
  44. {
  45. mb();
  46. }
  47. static inline void virtio_rmb(bool weak_barriers)
  48. {
  49. rmb();
  50. }
  51. static inline void virtio_wmb(bool weak_barriers)
  52. {
  53. wmb();
  54. }
  55. #endif
  56. struct virtio_device;
  57. struct virtqueue;
  58. struct virtqueue *vring_new_virtqueue(unsigned int index,
  59. unsigned int num,
  60. unsigned int vring_align,
  61. struct virtio_device *vdev,
  62. bool weak_barriers,
  63. void *pages,
  64. void (*notify)(struct virtqueue *vq),
  65. void (*callback)(struct virtqueue *vq),
  66. const char *name);
  67. void vring_del_virtqueue(struct virtqueue *vq);
  68. /* Filter out transport-specific feature bits. */
  69. void vring_transport_features(struct virtio_device *vdev);
  70. irqreturn_t vring_interrupt(int irq, void *_vq);
  71. #endif /* _LINUX_VIRTIO_RING_H */