virtio_ring.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. static inline void virtio_mb(bool weak_barriers)
  22. {
  23. #ifdef CONFIG_SMP
  24. if (weak_barriers)
  25. smp_mb();
  26. else
  27. #endif
  28. mb();
  29. }
  30. static inline void virtio_rmb(bool weak_barriers)
  31. {
  32. if (weak_barriers)
  33. dma_rmb();
  34. else
  35. rmb();
  36. }
  37. static inline void virtio_wmb(bool weak_barriers)
  38. {
  39. if (weak_barriers)
  40. dma_wmb();
  41. else
  42. wmb();
  43. }
  44. struct virtio_device;
  45. struct virtqueue;
  46. struct virtqueue *vring_new_virtqueue(unsigned int index,
  47. unsigned int num,
  48. unsigned int vring_align,
  49. struct virtio_device *vdev,
  50. bool weak_barriers,
  51. void *pages,
  52. bool (*notify)(struct virtqueue *vq),
  53. void (*callback)(struct virtqueue *vq),
  54. const char *name);
  55. void vring_del_virtqueue(struct virtqueue *vq);
  56. /* Filter out transport-specific feature bits. */
  57. void vring_transport_features(struct virtio_device *vdev);
  58. irqreturn_t vring_interrupt(int irq, void *_vq);
  59. #endif /* _LINUX_VIRTIO_RING_H */