vring.h 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/* Copyright 2012 Red Hat, Inc. and/or its affiliates
 * Copyright IBM, Corp. 2012
 *
 * Based on Linux 2.6.39 vhost code:
 * Copyright (C) 2009 Red Hat, Inc.
 * Copyright (C) 2006 Rusty Russell IBM Corporation
 *
 * Author: Michael S. Tsirkin <mst@redhat.com>
 *         Stefan Hajnoczi <stefanha@redhat.com>
 *
 * Inspiration, some code, and most witty comments come from
 * Documentation/virtual/lguest/lguest.c, by Rusty Russell
 *
 * This work is licensed under the terms of the GNU GPL, version 2.
 */

#ifndef VRING_H
#define VRING_H

#include "qemu-common.h"
21
#include "standard-headers/linux/virtio_ring.h"
P
Paolo Bonzini 已提交
22
#include "hw/virtio/virtio.h"
23 24

typedef struct {
25 26 27
    MemoryRegion *mr_desc;          /* memory region for the vring desc */
    MemoryRegion *mr_avail;         /* memory region for the vring avail */
    MemoryRegion *mr_used;          /* memory region for the vring used */
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
    struct vring vr;                /* virtqueue vring mapped to host memory */
    uint16_t last_avail_idx;        /* last processed avail ring index */
    uint16_t last_used_idx;         /* last processed used ring index */
    uint16_t signalled_used;        /* EVENT_IDX state */
    bool signalled_used_valid;
    bool broken;                    /* was there a fatal error? */
} Vring;

/* Fail future vring_pop() and vring_push() calls until reset */
static inline void vring_set_broken(Vring *vring)
{
    vring->broken = true;
}

bool vring_setup(Vring *vring, VirtIODevice *vdev, int n);
43
void vring_teardown(Vring *vring, VirtIODevice *vdev, int n);
44
void vring_disable_notification(VirtIODevice *vdev, Vring *vring);
45
void vring_enable_notification(VirtIODevice *vdev, Vring *vring);
46
bool vring_should_notify(VirtIODevice *vdev, Vring *vring);
47
void *vring_pop(VirtIODevice *vdev, Vring *vring, size_t sz);
48 49
void vring_push(VirtIODevice *vdev, Vring *vring, VirtQueueElement *elem,
                int len);
50 51

#endif /* VRING_H */