virtio_ring.h 1.9 KB

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