Statistics
| Branch: | Revision:

root / include / hw / virtio / dataplane / vring.h @ 9154b02c

History | View | Annotate | Download (2 kB)

1 88807f89 Stefan Hajnoczi
/* Copyright 2012 Red Hat, Inc. and/or its affiliates
2 88807f89 Stefan Hajnoczi
 * Copyright IBM, Corp. 2012
3 88807f89 Stefan Hajnoczi
 *
4 88807f89 Stefan Hajnoczi
 * Based on Linux 2.6.39 vhost code:
5 88807f89 Stefan Hajnoczi
 * Copyright (C) 2009 Red Hat, Inc.
6 88807f89 Stefan Hajnoczi
 * Copyright (C) 2006 Rusty Russell IBM Corporation
7 88807f89 Stefan Hajnoczi
 *
8 88807f89 Stefan Hajnoczi
 * Author: Michael S. Tsirkin <mst@redhat.com>
9 88807f89 Stefan Hajnoczi
 *         Stefan Hajnoczi <stefanha@redhat.com>
10 88807f89 Stefan Hajnoczi
 *
11 88807f89 Stefan Hajnoczi
 * Inspiration, some code, and most witty comments come from
12 88807f89 Stefan Hajnoczi
 * Documentation/virtual/lguest/lguest.c, by Rusty Russell
13 88807f89 Stefan Hajnoczi
 *
14 88807f89 Stefan Hajnoczi
 * This work is licensed under the terms of the GNU GPL, version 2.
15 88807f89 Stefan Hajnoczi
 */
16 88807f89 Stefan Hajnoczi
17 88807f89 Stefan Hajnoczi
#ifndef VRING_H
18 88807f89 Stefan Hajnoczi
#define VRING_H
19 88807f89 Stefan Hajnoczi
20 88807f89 Stefan Hajnoczi
#include <linux/virtio_ring.h>
21 88807f89 Stefan Hajnoczi
#include "qemu-common.h"
22 83c9f4ca Paolo Bonzini
#include "hostmem.h"
23 0d09e41a Paolo Bonzini
#include "hw/virtio/virtio.h"
24 88807f89 Stefan Hajnoczi
25 88807f89 Stefan Hajnoczi
typedef struct {
26 88807f89 Stefan Hajnoczi
    HostMem hostmem;                /* guest memory mapper */
27 88807f89 Stefan Hajnoczi
    struct vring vr;                /* virtqueue vring mapped to host memory */
28 88807f89 Stefan Hajnoczi
    uint16_t last_avail_idx;        /* last processed avail ring index */
29 88807f89 Stefan Hajnoczi
    uint16_t last_used_idx;         /* last processed used ring index */
30 88807f89 Stefan Hajnoczi
    uint16_t signalled_used;        /* EVENT_IDX state */
31 88807f89 Stefan Hajnoczi
    bool signalled_used_valid;
32 88807f89 Stefan Hajnoczi
    bool broken;                    /* was there a fatal error? */
33 88807f89 Stefan Hajnoczi
} Vring;
34 88807f89 Stefan Hajnoczi
35 88807f89 Stefan Hajnoczi
static inline unsigned int vring_get_num(Vring *vring)
36 88807f89 Stefan Hajnoczi
{
37 88807f89 Stefan Hajnoczi
    return vring->vr.num;
38 88807f89 Stefan Hajnoczi
}
39 88807f89 Stefan Hajnoczi
40 88807f89 Stefan Hajnoczi
/* Are there more descriptors available? */
41 88807f89 Stefan Hajnoczi
static inline bool vring_more_avail(Vring *vring)
42 88807f89 Stefan Hajnoczi
{
43 88807f89 Stefan Hajnoczi
    return vring->vr.avail->idx != vring->last_avail_idx;
44 88807f89 Stefan Hajnoczi
}
45 88807f89 Stefan Hajnoczi
46 88807f89 Stefan Hajnoczi
/* Fail future vring_pop() and vring_push() calls until reset */
47 88807f89 Stefan Hajnoczi
static inline void vring_set_broken(Vring *vring)
48 88807f89 Stefan Hajnoczi
{
49 88807f89 Stefan Hajnoczi
    vring->broken = true;
50 88807f89 Stefan Hajnoczi
}
51 88807f89 Stefan Hajnoczi
52 88807f89 Stefan Hajnoczi
bool vring_setup(Vring *vring, VirtIODevice *vdev, int n);
53 9154b02c Stefan Hajnoczi
void vring_teardown(Vring *vring, VirtIODevice *vdev, int n);
54 88807f89 Stefan Hajnoczi
void vring_disable_notification(VirtIODevice *vdev, Vring *vring);
55 88807f89 Stefan Hajnoczi
bool vring_enable_notification(VirtIODevice *vdev, Vring *vring);
56 88807f89 Stefan Hajnoczi
bool vring_should_notify(VirtIODevice *vdev, Vring *vring);
57 88807f89 Stefan Hajnoczi
int vring_pop(VirtIODevice *vdev, Vring *vring,
58 88807f89 Stefan Hajnoczi
              struct iovec iov[], struct iovec *iov_end,
59 88807f89 Stefan Hajnoczi
              unsigned int *out_num, unsigned int *in_num);
60 88807f89 Stefan Hajnoczi
void vring_push(Vring *vring, unsigned int head, int len);
61 88807f89 Stefan Hajnoczi
62 88807f89 Stefan Hajnoczi
#endif /* VRING_H */