2007-10-21 19:03:40 -06:00
|
|
|
#ifndef _LINUX_VIRTIO_RING_H
|
|
|
|
#define _LINUX_VIRTIO_RING_H
|
|
|
|
|
2013-07-07 20:01:06 -06:00
|
|
|
#include <asm/barrier.h>
|
2007-10-21 19:03:40 -06:00
|
|
|
#include <linux/irqreturn.h>
|
2012-10-13 03:46:48 -06:00
|
|
|
#include <uapi/linux/virtio_ring.h>
|
|
|
|
|
2013-03-17 20:52:19 -06:00
|
|
|
/*
|
|
|
|
* Barriers in virtio are tricky. Non-SMP virtio guests can't assume
|
|
|
|
* they're not on an SMP host system, so they need to assume real
|
|
|
|
* barriers. Non-SMP virtio hosts could skip the barriers, but does
|
|
|
|
* anyone care?
|
|
|
|
*
|
|
|
|
* For virtio_pci on SMP, we don't need to order with respect to MMIO
|
|
|
|
* accesses through relaxed memory I/O windows, so smp_mb() et al are
|
|
|
|
* sufficient.
|
|
|
|
*
|
|
|
|
* For using virtio to talk to real devices (eg. other heterogeneous
|
|
|
|
* CPUs) we do need real barriers. In theory, we could be using both
|
|
|
|
* kinds of virtio, so it's a runtime decision, and the branch is
|
|
|
|
* actually quite cheap.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
static inline void virtio_mb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
if (weak_barriers)
|
|
|
|
smp_mb();
|
|
|
|
else
|
|
|
|
mb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_rmb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
if (weak_barriers)
|
|
|
|
smp_rmb();
|
|
|
|
else
|
|
|
|
rmb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_wmb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
if (weak_barriers)
|
|
|
|
smp_wmb();
|
|
|
|
else
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline void virtio_mb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
mb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_rmb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
rmb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_wmb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-10-21 19:03:40 -06:00
|
|
|
struct virtio_device;
|
|
|
|
struct virtqueue;
|
|
|
|
|
2012-08-28 05:54:13 -06:00
|
|
|
struct virtqueue *vring_new_virtqueue(unsigned int index,
|
|
|
|
unsigned int num,
|
2008-12-30 08:26:03 -07:00
|
|
|
unsigned int vring_align,
|
2007-10-21 19:03:40 -06:00
|
|
|
struct virtio_device *vdev,
|
2012-01-11 22:14:42 -07:00
|
|
|
bool weak_barriers,
|
2007-10-21 19:03:40 -06:00
|
|
|
void *pages,
|
2013-10-28 17:08:50 -06:00
|
|
|
bool (*notify)(struct virtqueue *vq),
|
2009-06-12 22:16:35 -06:00
|
|
|
void (*callback)(struct virtqueue *vq),
|
|
|
|
const char *name);
|
2007-10-21 19:03:40 -06:00
|
|
|
void vring_del_virtqueue(struct virtqueue *vq);
|
2008-07-25 11:06:13 -06:00
|
|
|
/* Filter out transport-specific feature bits. */
|
|
|
|
void vring_transport_features(struct virtio_device *vdev);
|
2007-10-21 19:03:40 -06:00
|
|
|
|
|
|
|
irqreturn_t vring_interrupt(int irq, void *_vq);
|
|
|
|
#endif /* _LINUX_VIRTIO_RING_H */
|