2018-10-15 09:21:01 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018, Tuomas Tynkkynen <tuomas.tynkkynen@iki.fi>
|
|
|
|
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
|
|
|
|
*
|
|
|
|
* virtio ring implementation
|
|
|
|
*/
|
|
|
|
|
2023-03-29 14:24:59 +00:00
|
|
|
#include <bouncebuf.h>
|
2018-10-15 09:21:01 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-10-15 09:21:01 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <virtio_types.h>
|
|
|
|
#include <virtio.h>
|
|
|
|
#include <virtio_ring.h>
|
2020-05-10 17:40:08 +00:00
|
|
|
#include <linux/bug.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <linux/compat.h>
|
2023-03-29 14:24:57 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
|
|
|
static void *virtio_alloc_pages(struct udevice *vdev, u32 npages)
|
|
|
|
{
|
|
|
|
return memalign(PAGE_SIZE, npages * PAGE_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void virtio_free_pages(struct udevice *vdev, void *ptr, u32 npages)
|
|
|
|
{
|
|
|
|
free(ptr);
|
|
|
|
}
|
2018-10-15 09:21:01 +00:00
|
|
|
|
2023-03-29 14:25:00 +00:00
|
|
|
static int __bb_force_page_align(struct bounce_buffer *state)
|
|
|
|
{
|
|
|
|
const ulong align_mask = PAGE_SIZE - 1;
|
|
|
|
|
|
|
|
if ((ulong)state->user_buffer & align_mask)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (state->len != state->len_aligned)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:41:30 +00:00
|
|
|
static unsigned int virtqueue_attach_desc(struct virtqueue *vq, unsigned int i,
|
|
|
|
struct virtio_sg *sg, u16 flags)
|
|
|
|
{
|
2022-05-16 10:41:31 +00:00
|
|
|
struct vring_desc_shadow *desc_shadow = &vq->vring_desc_shadow[i];
|
2022-05-16 10:41:30 +00:00
|
|
|
struct vring_desc *desc = &vq->vring.desc[i];
|
2023-03-29 14:25:00 +00:00
|
|
|
void *addr;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_BOUNCE_BUFFER) && vq->vring.bouncebufs) {
|
|
|
|
struct bounce_buffer *bb = &vq->vring.bouncebufs[i];
|
|
|
|
unsigned int bbflags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (flags & VRING_DESC_F_WRITE)
|
|
|
|
bbflags = GEN_BB_WRITE;
|
|
|
|
else
|
|
|
|
bbflags = GEN_BB_READ;
|
|
|
|
|
|
|
|
ret = bounce_buffer_start_extalign(bb, sg->addr, sg->length,
|
|
|
|
bbflags, PAGE_SIZE,
|
|
|
|
__bb_force_page_align);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: failed to allocate bounce buffer (length 0x%zx)\n",
|
|
|
|
vq->vdev->name, sg->length);
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = bb->bounce_buffer;
|
|
|
|
} else {
|
|
|
|
addr = sg->addr;
|
|
|
|
}
|
2022-05-16 10:41:30 +00:00
|
|
|
|
2022-05-16 10:41:31 +00:00
|
|
|
/* Update the shadow descriptor. */
|
2023-03-29 14:25:00 +00:00
|
|
|
desc_shadow->addr = (u64)(uintptr_t)addr;
|
2022-05-16 10:41:31 +00:00
|
|
|
desc_shadow->len = sg->length;
|
|
|
|
desc_shadow->flags = flags;
|
2022-05-16 10:41:30 +00:00
|
|
|
|
2022-05-16 10:41:31 +00:00
|
|
|
/* Update the shared descriptor to match the shadow. */
|
|
|
|
desc->addr = cpu_to_virtio64(vq->vdev, desc_shadow->addr);
|
|
|
|
desc->len = cpu_to_virtio32(vq->vdev, desc_shadow->len);
|
|
|
|
desc->flags = cpu_to_virtio16(vq->vdev, desc_shadow->flags);
|
|
|
|
desc->next = cpu_to_virtio16(vq->vdev, desc_shadow->next);
|
|
|
|
|
|
|
|
return desc_shadow->next;
|
2022-05-16 10:41:30 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 14:24:58 +00:00
|
|
|
static void virtqueue_detach_desc(struct virtqueue *vq, unsigned int idx)
|
|
|
|
{
|
2023-03-29 14:25:00 +00:00
|
|
|
struct vring_desc *desc = &vq->vring.desc[idx];
|
|
|
|
struct bounce_buffer *bb;
|
|
|
|
|
|
|
|
if (!IS_ENABLED(CONFIG_BOUNCE_BUFFER) || !vq->vring.bouncebufs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bb = &vq->vring.bouncebufs[idx];
|
|
|
|
bounce_buffer_stop(bb);
|
|
|
|
desc->addr = cpu_to_virtio64(vq->vdev, (u64)(uintptr_t)bb->user_buffer);
|
2023-03-29 14:24:58 +00:00
|
|
|
}
|
|
|
|
|
2018-10-15 09:21:01 +00:00
|
|
|
int virtqueue_add(struct virtqueue *vq, struct virtio_sg *sgs[],
|
|
|
|
unsigned int out_sgs, unsigned int in_sgs)
|
|
|
|
{
|
|
|
|
struct vring_desc *desc;
|
2022-05-16 10:41:29 +00:00
|
|
|
unsigned int descs_used = out_sgs + in_sgs;
|
|
|
|
unsigned int i, n, avail, uninitialized_var(prev);
|
2018-10-15 09:21:01 +00:00
|
|
|
int head;
|
|
|
|
|
2022-05-16 10:41:29 +00:00
|
|
|
WARN_ON(descs_used == 0);
|
2018-10-15 09:21:01 +00:00
|
|
|
|
|
|
|
head = vq->free_head;
|
|
|
|
|
|
|
|
desc = vq->vring.desc;
|
|
|
|
i = head;
|
|
|
|
|
|
|
|
if (vq->num_free < descs_used) {
|
|
|
|
debug("Can't add buf len %i - avail = %i\n",
|
|
|
|
descs_used, vq->num_free);
|
|
|
|
/*
|
|
|
|
* FIXME: for historical reasons, we force a notify here if
|
|
|
|
* there are outgoing parts to the buffer. Presumably the
|
|
|
|
* host should service the ring ASAP.
|
|
|
|
*/
|
|
|
|
if (out_sgs)
|
|
|
|
virtio_notify(vq->vdev, vq);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:41:30 +00:00
|
|
|
for (n = 0; n < descs_used; n++) {
|
|
|
|
u16 flags = VRING_DESC_F_NEXT;
|
2018-10-15 09:21:01 +00:00
|
|
|
|
2022-05-16 10:41:30 +00:00
|
|
|
if (n >= out_sgs)
|
|
|
|
flags |= VRING_DESC_F_WRITE;
|
2018-10-15 09:21:01 +00:00
|
|
|
prev = i;
|
2022-05-16 10:41:30 +00:00
|
|
|
i = virtqueue_attach_desc(vq, i, sgs[n], flags);
|
2018-10-15 09:21:01 +00:00
|
|
|
}
|
|
|
|
/* Last one doesn't continue */
|
2022-05-16 10:41:31 +00:00
|
|
|
vq->vring_desc_shadow[prev].flags &= ~VRING_DESC_F_NEXT;
|
|
|
|
desc[prev].flags = cpu_to_virtio16(vq->vdev, vq->vring_desc_shadow[prev].flags);
|
2018-10-15 09:21:01 +00:00
|
|
|
|
|
|
|
/* We're using some buffers from the free list. */
|
|
|
|
vq->num_free -= descs_used;
|
|
|
|
|
|
|
|
/* Update free pointer */
|
|
|
|
vq->free_head = i;
|
|
|
|
|
2022-05-16 10:41:32 +00:00
|
|
|
/* Mark the descriptor as the head of a chain. */
|
|
|
|
vq->vring_desc_shadow[head].chain_head = true;
|
|
|
|
|
2018-10-15 09:21:01 +00:00
|
|
|
/*
|
|
|
|
* Put entry in available array (but don't update avail->idx
|
|
|
|
* until they do sync).
|
|
|
|
*/
|
|
|
|
avail = vq->avail_idx_shadow & (vq->vring.num - 1);
|
|
|
|
vq->vring.avail->ring[avail] = cpu_to_virtio16(vq->vdev, head);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Descriptors and available array need to be set before we expose the
|
|
|
|
* new available array entries.
|
|
|
|
*/
|
|
|
|
virtio_wmb();
|
|
|
|
vq->avail_idx_shadow++;
|
|
|
|
vq->vring.avail->idx = cpu_to_virtio16(vq->vdev, vq->avail_idx_shadow);
|
|
|
|
vq->num_added++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is very unlikely, but theoretically possible.
|
|
|
|
* Kick just in case.
|
|
|
|
*/
|
|
|
|
if (unlikely(vq->num_added == (1 << 16) - 1))
|
|
|
|
virtqueue_kick(vq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool virtqueue_kick_prepare(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
u16 new, old;
|
|
|
|
bool needs_kick;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to expose available array entries before checking
|
|
|
|
* avail event.
|
|
|
|
*/
|
|
|
|
virtio_mb();
|
|
|
|
|
|
|
|
old = vq->avail_idx_shadow - vq->num_added;
|
|
|
|
new = vq->avail_idx_shadow;
|
|
|
|
vq->num_added = 0;
|
|
|
|
|
|
|
|
if (vq->event) {
|
|
|
|
needs_kick = vring_need_event(virtio16_to_cpu(vq->vdev,
|
|
|
|
vring_avail_event(&vq->vring)), new, old);
|
|
|
|
} else {
|
|
|
|
needs_kick = !(vq->vring.used->flags & cpu_to_virtio16(vq->vdev,
|
|
|
|
VRING_USED_F_NO_NOTIFY));
|
|
|
|
}
|
|
|
|
|
|
|
|
return needs_kick;
|
|
|
|
}
|
|
|
|
|
|
|
|
void virtqueue_kick(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
if (virtqueue_kick_prepare(vq))
|
|
|
|
virtio_notify(vq->vdev, vq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void detach_buf(struct virtqueue *vq, unsigned int head)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2022-05-16 10:41:32 +00:00
|
|
|
/* Unmark the descriptor as the head of a chain. */
|
|
|
|
vq->vring_desc_shadow[head].chain_head = false;
|
|
|
|
|
2018-10-15 09:21:01 +00:00
|
|
|
/* Put back on free list: unmap first-level descriptors and find end */
|
|
|
|
i = head;
|
|
|
|
|
2022-05-16 10:41:31 +00:00
|
|
|
while (vq->vring_desc_shadow[i].flags & VRING_DESC_F_NEXT) {
|
2023-03-29 14:24:58 +00:00
|
|
|
virtqueue_detach_desc(vq, i);
|
2022-05-16 10:41:31 +00:00
|
|
|
i = vq->vring_desc_shadow[i].next;
|
2018-10-15 09:21:01 +00:00
|
|
|
vq->num_free++;
|
|
|
|
}
|
|
|
|
|
2023-03-29 14:24:58 +00:00
|
|
|
virtqueue_detach_desc(vq, i);
|
2022-05-16 10:41:31 +00:00
|
|
|
vq->vring_desc_shadow[i].next = vq->free_head;
|
2018-10-15 09:21:01 +00:00
|
|
|
vq->free_head = head;
|
|
|
|
|
|
|
|
/* Plus final descriptor */
|
|
|
|
vq->num_free++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool more_used(const struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
return vq->last_used_idx != virtio16_to_cpu(vq->vdev,
|
|
|
|
vq->vring.used->idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
u16 last_used;
|
|
|
|
|
|
|
|
if (!more_used(vq)) {
|
|
|
|
debug("(%s.%d): No more buffers in queue\n",
|
|
|
|
vq->vdev->name, vq->index);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only get used array entries after they have been exposed by host */
|
|
|
|
virtio_rmb();
|
|
|
|
|
|
|
|
last_used = (vq->last_used_idx & (vq->vring.num - 1));
|
|
|
|
i = virtio32_to_cpu(vq->vdev, vq->vring.used->ring[last_used].id);
|
|
|
|
if (len) {
|
|
|
|
*len = virtio32_to_cpu(vq->vdev,
|
|
|
|
vq->vring.used->ring[last_used].len);
|
|
|
|
debug("(%s.%d): last used idx %u with len %u\n",
|
|
|
|
vq->vdev->name, vq->index, i, *len);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unlikely(i >= vq->vring.num)) {
|
|
|
|
printf("(%s.%d): id %u out of range\n",
|
|
|
|
vq->vdev->name, vq->index, i);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-05-16 10:41:32 +00:00
|
|
|
if (unlikely(!vq->vring_desc_shadow[i].chain_head)) {
|
|
|
|
printf("(%s.%d): id %u is not a head\n",
|
|
|
|
vq->vdev->name, vq->index, i);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-15 09:21:01 +00:00
|
|
|
detach_buf(vq, i);
|
|
|
|
vq->last_used_idx++;
|
|
|
|
/*
|
|
|
|
* If we expect an interrupt for the next entry, tell host
|
|
|
|
* by writing event index and flush out the write before
|
|
|
|
* the read in the next get_buf call.
|
|
|
|
*/
|
|
|
|
if (!(vq->avail_flags_shadow & VRING_AVAIL_F_NO_INTERRUPT))
|
|
|
|
virtio_store_mb(&vring_used_event(&vq->vring),
|
|
|
|
cpu_to_virtio16(vq->vdev, vq->last_used_idx));
|
|
|
|
|
2022-05-16 10:41:31 +00:00
|
|
|
return (void *)(uintptr_t)vq->vring_desc_shadow[i].addr;
|
2018-10-15 09:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct virtqueue *__vring_new_virtqueue(unsigned int index,
|
|
|
|
struct vring vring,
|
|
|
|
struct udevice *udev)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
struct virtqueue *vq;
|
2022-05-16 10:41:31 +00:00
|
|
|
struct vring_desc_shadow *vring_desc_shadow;
|
2018-10-15 09:21:01 +00:00
|
|
|
struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
|
|
|
|
struct udevice *vdev = uc_priv->vdev;
|
|
|
|
|
|
|
|
vq = malloc(sizeof(*vq));
|
|
|
|
if (!vq)
|
|
|
|
return NULL;
|
|
|
|
|
2022-05-16 10:41:31 +00:00
|
|
|
vring_desc_shadow = calloc(vring.num, sizeof(struct vring_desc_shadow));
|
|
|
|
if (!vring_desc_shadow) {
|
|
|
|
free(vq);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-15 09:21:01 +00:00
|
|
|
vq->vdev = vdev;
|
|
|
|
vq->index = index;
|
|
|
|
vq->num_free = vring.num;
|
|
|
|
vq->vring = vring;
|
2022-05-16 10:41:31 +00:00
|
|
|
vq->vring_desc_shadow = vring_desc_shadow;
|
2018-10-15 09:21:01 +00:00
|
|
|
vq->last_used_idx = 0;
|
|
|
|
vq->avail_flags_shadow = 0;
|
|
|
|
vq->avail_idx_shadow = 0;
|
|
|
|
vq->num_added = 0;
|
|
|
|
list_add_tail(&vq->list, &uc_priv->vqs);
|
|
|
|
|
|
|
|
vq->event = virtio_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX);
|
|
|
|
|
|
|
|
/* Tell other side not to bother us */
|
|
|
|
vq->avail_flags_shadow |= VRING_AVAIL_F_NO_INTERRUPT;
|
|
|
|
if (!vq->event)
|
|
|
|
vq->vring.avail->flags = cpu_to_virtio16(vdev,
|
|
|
|
vq->avail_flags_shadow);
|
|
|
|
|
|
|
|
/* Put everything in free lists */
|
|
|
|
vq->free_head = 0;
|
|
|
|
for (i = 0; i < vring.num - 1; i++)
|
2022-05-16 10:41:31 +00:00
|
|
|
vq->vring_desc_shadow[i].next = i + 1;
|
2018-10-15 09:21:01 +00:00
|
|
|
|
|
|
|
return vq;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct virtqueue *vring_create_virtqueue(unsigned int index, unsigned int num,
|
|
|
|
unsigned int vring_align,
|
|
|
|
struct udevice *udev)
|
|
|
|
{
|
2023-03-29 14:24:57 +00:00
|
|
|
struct virtio_dev_priv *uc_priv = dev_get_uclass_priv(udev);
|
|
|
|
struct udevice *vdev = uc_priv->vdev;
|
2018-10-15 09:21:01 +00:00
|
|
|
struct virtqueue *vq;
|
|
|
|
void *queue = NULL;
|
2023-03-29 14:24:59 +00:00
|
|
|
struct bounce_buffer *bbs = NULL;
|
2018-10-15 09:21:01 +00:00
|
|
|
struct vring vring;
|
|
|
|
|
|
|
|
/* We assume num is a power of 2 */
|
|
|
|
if (num & (num - 1)) {
|
|
|
|
printf("Bad virtqueue length %u\n", num);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: allocate each queue chunk individually */
|
|
|
|
for (; num && vring_size(num, vring_align) > PAGE_SIZE; num /= 2) {
|
2023-03-29 14:24:57 +00:00
|
|
|
size_t sz = vring_size(num, vring_align);
|
|
|
|
|
|
|
|
queue = virtio_alloc_pages(vdev, DIV_ROUND_UP(sz, PAGE_SIZE));
|
2018-10-15 09:21:01 +00:00
|
|
|
if (queue)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!num)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!queue) {
|
|
|
|
/* Try to get a single page. You are my only hope! */
|
2023-03-29 14:24:57 +00:00
|
|
|
queue = virtio_alloc_pages(vdev, 1);
|
2018-10-15 09:21:01 +00:00
|
|
|
}
|
|
|
|
if (!queue)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(queue, 0, vring_size(num, vring_align));
|
|
|
|
|
2023-03-29 14:24:59 +00:00
|
|
|
if (virtio_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
|
|
|
|
bbs = calloc(num, sizeof(*bbs));
|
|
|
|
if (!bbs)
|
|
|
|
goto err_free_queue;
|
2018-10-15 09:21:01 +00:00
|
|
|
}
|
2023-03-29 14:24:59 +00:00
|
|
|
|
|
|
|
vring_init(&vring, num, queue, vring_align, bbs);
|
|
|
|
|
|
|
|
vq = __vring_new_virtqueue(index, vring, udev);
|
|
|
|
if (!vq)
|
|
|
|
goto err_free_bbs;
|
|
|
|
|
2018-10-15 09:21:01 +00:00
|
|
|
debug("(%s): created vring @ %p for vq @ %p with num %u\n", udev->name,
|
|
|
|
queue, vq, num);
|
|
|
|
|
|
|
|
return vq;
|
2023-03-29 14:24:59 +00:00
|
|
|
|
|
|
|
err_free_bbs:
|
|
|
|
free(bbs);
|
|
|
|
err_free_queue:
|
|
|
|
virtio_free_pages(vdev, queue, DIV_ROUND_UP(vring.size, PAGE_SIZE));
|
|
|
|
return NULL;
|
2018-10-15 09:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void vring_del_virtqueue(struct virtqueue *vq)
|
|
|
|
{
|
2023-03-29 14:24:57 +00:00
|
|
|
virtio_free_pages(vq->vdev, vq->vring.desc,
|
|
|
|
DIV_ROUND_UP(vq->vring.size, PAGE_SIZE));
|
2022-05-16 10:41:31 +00:00
|
|
|
free(vq->vring_desc_shadow);
|
2018-10-15 09:21:01 +00:00
|
|
|
list_del(&vq->list);
|
2023-03-29 14:24:59 +00:00
|
|
|
free(vq->vring.bouncebufs);
|
2018-10-15 09:21:01 +00:00
|
|
|
free(vq);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int virtqueue_get_vring_size(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
return vq->vring.num;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong virtqueue_get_desc_addr(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
return (ulong)vq->vring.desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong virtqueue_get_avail_addr(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
return (ulong)vq->vring.desc +
|
|
|
|
((char *)vq->vring.avail - (char *)vq->vring.desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
ulong virtqueue_get_used_addr(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
return (ulong)vq->vring.desc +
|
|
|
|
((char *)vq->vring.used - (char *)vq->vring.desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool virtqueue_poll(struct virtqueue *vq, u16 last_used_idx)
|
|
|
|
{
|
|
|
|
virtio_mb();
|
|
|
|
|
|
|
|
return last_used_idx != virtio16_to_cpu(vq->vdev, vq->vring.used->idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void virtqueue_dump(struct virtqueue *vq)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
printf("virtqueue %p for dev %s:\n", vq, vq->vdev->name);
|
|
|
|
printf("\tindex %u, phys addr %p num %u\n",
|
|
|
|
vq->index, vq->vring.desc, vq->vring.num);
|
|
|
|
printf("\tfree_head %u, num_added %u, num_free %u\n",
|
|
|
|
vq->free_head, vq->num_added, vq->num_free);
|
|
|
|
printf("\tlast_used_idx %u, avail_flags_shadow %u, avail_idx_shadow %u\n",
|
|
|
|
vq->last_used_idx, vq->avail_flags_shadow, vq->avail_idx_shadow);
|
|
|
|
|
2022-05-16 10:41:31 +00:00
|
|
|
printf("Shadow descriptor dump:\n");
|
2018-10-15 09:21:01 +00:00
|
|
|
for (i = 0; i < vq->vring.num; i++) {
|
2022-05-16 10:41:31 +00:00
|
|
|
struct vring_desc_shadow *desc = &vq->vring_desc_shadow[i];
|
|
|
|
|
|
|
|
printf("\tdesc_shadow[%u] = { 0x%llx, len %u, flags %u, next %u }\n",
|
|
|
|
i, desc->addr, desc->len, desc->flags, desc->next);
|
2018-10-15 09:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("Avail ring dump:\n");
|
|
|
|
printf("\tflags %u, idx %u\n",
|
|
|
|
vq->vring.avail->flags, vq->vring.avail->idx);
|
|
|
|
for (i = 0; i < vq->vring.num; i++) {
|
|
|
|
printf("\tavail[%u] = %u\n",
|
|
|
|
i, vq->vring.avail->ring[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Used ring dump:\n");
|
|
|
|
printf("\tflags %u, idx %u\n",
|
|
|
|
vq->vring.used->flags, vq->vring.used->idx);
|
|
|
|
for (i = 0; i < vq->vring.num; i++) {
|
|
|
|
printf("\tused[%u] = { %u, %u }\n", i,
|
|
|
|
vq->vring.used->ring[i].id, vq->vring.used->ring[i].len);
|
|
|
|
}
|
|
|
|
}
|