linux/include/linux/virtio_ring.h
<<
>>
Prefs
   1#ifndef _LINUX_VIRTIO_RING_H
   2#define _LINUX_VIRTIO_RING_H
   3
   4#include <linux/irqreturn.h>
   5#include <uapi/linux/virtio_ring.h>
   6
   7/*
   8 * Barriers in virtio are tricky.  Non-SMP virtio guests can't assume
   9 * they're not on an SMP host system, so they need to assume real
  10 * barriers.  Non-SMP virtio hosts could skip the barriers, but does
  11 * anyone care?
  12 *
  13 * For virtio_pci on SMP, we don't need to order with respect to MMIO
  14 * accesses through relaxed memory I/O windows, so smp_mb() et al are
  15 * sufficient.
  16 *
  17 * For using virtio to talk to real devices (eg. other heterogeneous
  18 * CPUs) we do need real barriers.  In theory, we could be using both
  19 * kinds of virtio, so it's a runtime decision, and the branch is
  20 * actually quite cheap.
  21 */
  22
  23static inline void virtio_mb(bool weak_barriers)
  24{
  25#ifdef CONFIG_SMP
  26        if (weak_barriers)
  27                smp_mb();
  28        else
  29#endif
  30                mb();
  31}
  32
  33static inline void virtio_rmb(bool weak_barriers)
  34{
  35        if (weak_barriers)
  36                dma_rmb();
  37        else
  38                rmb();
  39}
  40
  41static inline void virtio_wmb(bool weak_barriers)
  42{
  43        if (weak_barriers)
  44                dma_wmb();
  45        else
  46                wmb();
  47}
  48
  49struct virtio_device;
  50struct virtqueue;
  51
  52/*
  53 * Creates a virtqueue and allocates the descriptor ring.  If
  54 * may_reduce_num is set, then this may allocate a smaller ring than
  55 * expected.  The caller should query virtqueue_get_ring_size to learn
  56 * the actual size of the ring.
  57 */
  58struct virtqueue *vring_create_virtqueue(unsigned int index,
  59                                         unsigned int num,
  60                                         unsigned int vring_align,
  61                                         struct virtio_device *vdev,
  62                                         bool weak_barriers,
  63                                         bool may_reduce_num,
  64                                         bool (*notify)(struct virtqueue *vq),
  65                                         void (*callback)(struct virtqueue *vq),
  66                                         const char *name);
  67
  68/* Creates a virtqueue with a custom layout. */
  69struct virtqueue *__vring_new_virtqueue(unsigned int index,
  70                                        struct vring vring,
  71                                        struct virtio_device *vdev,
  72                                        bool weak_barriers,
  73                                        bool (*notify)(struct virtqueue *),
  74                                        void (*callback)(struct virtqueue *),
  75                                        const char *name);
  76
  77/*
  78 * Creates a virtqueue with a standard layout but a caller-allocated
  79 * ring.
  80 */
  81struct virtqueue *vring_new_virtqueue(unsigned int index,
  82                                      unsigned int num,
  83                                      unsigned int vring_align,
  84                                      struct virtio_device *vdev,
  85                                      bool weak_barriers,
  86                                      void *pages,
  87                                      bool (*notify)(struct virtqueue *vq),
  88                                      void (*callback)(struct virtqueue *vq),
  89                                      const char *name);
  90
  91/*
  92 * Destroys a virtqueue.  If created with vring_create_virtqueue, this
  93 * also frees the ring.
  94 */
  95void vring_del_virtqueue(struct virtqueue *vq);
  96
  97/* Filter out transport-specific feature bits. */
  98void vring_transport_features(struct virtio_device *vdev);
  99
 100irqreturn_t vring_interrupt(int irq, void *_vq);
 101#endif /* _LINUX_VIRTIO_RING_H */
 102