2007-10-22 09:03:40 +08:00
|
|
|
#ifndef _LINUX_VIRTIO_RING_H
|
|
|
|
#define _LINUX_VIRTIO_RING_H
|
|
|
|
|
2013-07-08 10:01:06 +08:00
|
|
|
#include <asm/barrier.h>
|
2007-10-22 09:03:40 +08:00
|
|
|
#include <linux/irqreturn.h>
|
2012-10-13 17:46:48 +08:00
|
|
|
#include <uapi/linux/virtio_ring.h>
|
|
|
|
|
2013-03-18 10:52:19 +08: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
|
2015-12-27 23:55:35 +08:00
|
|
|
* accesses through relaxed memory I/O windows, so virt_mb() et al are
|
2013-03-18 10:52:19 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline void virtio_mb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
if (weak_barriers)
|
2015-12-27 23:55:35 +08:00
|
|
|
virt_mb();
|
2013-03-18 10:52:19 +08:00
|
|
|
else
|
|
|
|
mb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_rmb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
if (weak_barriers)
|
2015-12-27 23:55:35 +08:00
|
|
|
virt_rmb();
|
2013-03-18 10:52:19 +08:00
|
|
|
else
|
|
|
|
rmb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void virtio_wmb(bool weak_barriers)
|
|
|
|
{
|
|
|
|
if (weak_barriers)
|
2015-12-27 23:55:35 +08:00
|
|
|
virt_wmb();
|
2013-03-18 10:52:19 +08:00
|
|
|
else
|
|
|
|
wmb();
|
|
|
|
}
|
|
|
|
|
2015-12-17 18:20:39 +08:00
|
|
|
static inline void virtio_store_mb(bool weak_barriers,
|
|
|
|
__virtio16 *p, __virtio16 v)
|
|
|
|
{
|
|
|
|
if (weak_barriers) {
|
|
|
|
virt_store_mb(*p, v);
|
|
|
|
} else {
|
|
|
|
WRITE_ONCE(*p, v);
|
|
|
|
mb();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-22 09:03:40 +08:00
|
|
|
struct virtio_device;
|
|
|
|
struct virtqueue;
|
|
|
|
|
2016-02-03 13:46:37 +08:00
|
|
|
/*
|
|
|
|
* Creates a virtqueue and allocates the descriptor ring. If
|
|
|
|
* may_reduce_num is set, then this may allocate a smaller ring than
|
|
|
|
* expected. The caller should query virtqueue_get_ring_size to learn
|
|
|
|
* the actual size of the ring.
|
|
|
|
*/
|
|
|
|
struct virtqueue *vring_create_virtqueue(unsigned int index,
|
|
|
|
unsigned int num,
|
|
|
|
unsigned int vring_align,
|
|
|
|
struct virtio_device *vdev,
|
|
|
|
bool weak_barriers,
|
|
|
|
bool may_reduce_num,
|
2017-03-07 00:32:29 +08:00
|
|
|
bool ctx,
|
2016-02-03 13:46:37 +08:00
|
|
|
bool (*notify)(struct virtqueue *vq),
|
|
|
|
void (*callback)(struct virtqueue *vq),
|
|
|
|
const char *name);
|
|
|
|
|
|
|
|
/* Creates a virtqueue with a custom layout. */
|
|
|
|
struct virtqueue *__vring_new_virtqueue(unsigned int index,
|
|
|
|
struct vring vring,
|
|
|
|
struct virtio_device *vdev,
|
|
|
|
bool weak_barriers,
|
2017-03-07 00:32:29 +08:00
|
|
|
bool ctx,
|
2016-02-03 13:46:37 +08:00
|
|
|
bool (*notify)(struct virtqueue *),
|
|
|
|
void (*callback)(struct virtqueue *),
|
|
|
|
const char *name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Creates a virtqueue with a standard layout but a caller-allocated
|
|
|
|
* ring.
|
|
|
|
*/
|
2012-08-28 19:54:13 +08:00
|
|
|
struct virtqueue *vring_new_virtqueue(unsigned int index,
|
|
|
|
unsigned int num,
|
2008-12-30 23:26:03 +08:00
|
|
|
unsigned int vring_align,
|
2007-10-22 09:03:40 +08:00
|
|
|
struct virtio_device *vdev,
|
2012-01-12 13:14:42 +08:00
|
|
|
bool weak_barriers,
|
2017-03-07 00:32:29 +08:00
|
|
|
bool ctx,
|
2007-10-22 09:03:40 +08:00
|
|
|
void *pages,
|
2013-10-29 07:08:50 +08:00
|
|
|
bool (*notify)(struct virtqueue *vq),
|
2009-06-13 12:16:35 +08:00
|
|
|
void (*callback)(struct virtqueue *vq),
|
|
|
|
const char *name);
|
2016-02-03 13:46:37 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroys a virtqueue. If created with vring_create_virtqueue, this
|
|
|
|
* also frees the ring.
|
|
|
|
*/
|
2007-10-22 09:03:40 +08:00
|
|
|
void vring_del_virtqueue(struct virtqueue *vq);
|
2016-02-03 13:46:37 +08:00
|
|
|
|
2008-07-26 01:06:13 +08:00
|
|
|
/* Filter out transport-specific feature bits. */
|
|
|
|
void vring_transport_features(struct virtio_device *vdev);
|
2007-10-22 09:03:40 +08:00
|
|
|
|
|
|
|
irqreturn_t vring_interrupt(int irq, void *_vq);
|
|
|
|
#endif /* _LINUX_VIRTIO_RING_H */
|