Add qemu 2.4.0
[kvmfornfv.git] / qemu / include / hw / virtio / dataplane / vring.h
1 /* Copyright 2012 Red Hat, Inc. and/or its affiliates
2  * Copyright IBM, Corp. 2012
3  *
4  * Based on Linux 2.6.39 vhost code:
5  * Copyright (C) 2009 Red Hat, Inc.
6  * Copyright (C) 2006 Rusty Russell IBM Corporation
7  *
8  * Author: Michael S. Tsirkin <mst@redhat.com>
9  *         Stefan Hajnoczi <stefanha@redhat.com>
10  *
11  * Inspiration, some code, and most witty comments come from
12  * Documentation/virtual/lguest/lguest.c, by Rusty Russell
13  *
14  * This work is licensed under the terms of the GNU GPL, version 2.
15  */
16
17 #ifndef VRING_H
18 #define VRING_H
19
20 #include "qemu-common.h"
21 #include "standard-headers/linux/virtio_ring.h"
22 #include "hw/virtio/virtio.h"
23
24 typedef struct {
25     MemoryRegion *mr;               /* memory region containing the vring */
26     struct vring vr;                /* virtqueue vring mapped to host memory */
27     uint16_t last_avail_idx;        /* last processed avail ring index */
28     uint16_t last_used_idx;         /* last processed used ring index */
29     uint16_t signalled_used;        /* EVENT_IDX state */
30     bool signalled_used_valid;
31     bool broken;                    /* was there a fatal error? */
32 } Vring;
33
34 /* Fail future vring_pop() and vring_push() calls until reset */
35 static inline void vring_set_broken(Vring *vring)
36 {
37     vring->broken = true;
38 }
39
40 bool vring_setup(Vring *vring, VirtIODevice *vdev, int n);
41 void vring_teardown(Vring *vring, VirtIODevice *vdev, int n);
42 void vring_disable_notification(VirtIODevice *vdev, Vring *vring);
43 bool vring_enable_notification(VirtIODevice *vdev, Vring *vring);
44 bool vring_should_notify(VirtIODevice *vdev, Vring *vring);
45 int vring_pop(VirtIODevice *vdev, Vring *vring, VirtQueueElement *elem);
46 void vring_push(VirtIODevice *vdev, Vring *vring, VirtQueueElement *elem,
47                 int len);
48
49 #endif /* VRING_H */