iPXE
Data Structures | Defines | Functions
virtio-ring.h File Reference
#include <ipxe/virtio-pci.h>

Go to the source code of this file.

Data Structures

struct  vring_desc
struct  vring_avail
struct  vring_used_elem
struct  vring_used
struct  vring
struct  vring_virtqueue
struct  vring_list

Defines

#define VIRTIO_CONFIG_S_ACKNOWLEDGE   1
#define VIRTIO_CONFIG_S_DRIVER   2
#define VIRTIO_CONFIG_S_DRIVER_OK   4
#define VIRTIO_CONFIG_S_FEATURES_OK   8
#define VIRTIO_CONFIG_S_FAILED   0x80
#define VIRTIO_F_ANY_LAYOUT   27
#define VIRTIO_F_VERSION_1   32
#define VIRTIO_F_IOMMU_PLATFORM   33
#define MAX_QUEUE_NUM   (256)
#define VRING_DESC_F_NEXT   1
#define VRING_DESC_F_WRITE   2
#define VRING_AVAIL_F_NO_INTERRUPT   1
#define VRING_USED_F_NO_NOTIFY   1
#define vring_size(num)

Functions

static void vring_init (struct vring *vr, unsigned int num, unsigned char *queue)
static void vring_enable_cb (struct vring_virtqueue *vq)
static void vring_disable_cb (struct vring_virtqueue *vq)
static int vring_more_used (struct vring_virtqueue *vq)
void vring_detach (struct vring_virtqueue *vq, unsigned int head)
void * vring_get_buf (struct vring_virtqueue *vq, unsigned int *len)
void vring_add_buf (struct vring_virtqueue *vq, struct vring_list list[], unsigned int out, unsigned int in, void *index, int num_added)
void vring_kick (struct virtio_pci_modern_device *vdev, unsigned int ioaddr, struct vring_virtqueue *vq, int num_added)

Define Documentation

Definition at line 8 of file virtio-ring.h.

Referenced by virtnet_probe_modern().

#define VIRTIO_CONFIG_S_DRIVER   2

Definition at line 10 of file virtio-ring.h.

Referenced by virtnet_open_legacy(), and virtnet_probe_modern().

#define VIRTIO_CONFIG_S_DRIVER_OK   4

Definition at line 12 of file virtio-ring.h.

Referenced by virtnet_open_legacy(), and virtnet_open_modern().

Definition at line 14 of file virtio-ring.h.

Referenced by virtnet_open_modern().

#define VIRTIO_CONFIG_S_FAILED   0x80

Definition at line 16 of file virtio-ring.h.

Referenced by virtnet_open_modern().

#define VIRTIO_F_ANY_LAYOUT   27

Definition at line 20 of file virtio-ring.h.

Referenced by virtnet_open_modern().

#define VIRTIO_F_VERSION_1   32

Definition at line 22 of file virtio-ring.h.

Referenced by virtnet_open_modern().

#define VIRTIO_F_IOMMU_PLATFORM   33

Definition at line 23 of file virtio-ring.h.

Referenced by virtnet_open_modern().

#define MAX_QUEUE_NUM   (256)

Definition at line 25 of file virtio-ring.h.

Referenced by vpm_find_vqs().

#define VRING_DESC_F_NEXT   1

Definition at line 27 of file virtio-ring.h.

Referenced by vring_add_buf(), and vring_detach().

#define VRING_DESC_F_WRITE   2

Definition at line 28 of file virtio-ring.h.

Referenced by vring_add_buf().

Definition at line 30 of file virtio-ring.h.

Referenced by vring_disable_cb(), and vring_enable_cb().

#define VRING_USED_F_NO_NOTIFY   1

Definition at line 32 of file virtio-ring.h.

Referenced by vring_kick().

#define vring_size (   num)
Value:
(((((sizeof(struct vring_desc) * num) + \
      (sizeof(struct vring_avail) + sizeof(u16) * num)) \
         + PAGE_MASK) & ~PAGE_MASK) + \
         (sizeof(struct vring_used) + sizeof(struct vring_used_elem) * num))

Definition at line 69 of file virtio-ring.h.

Referenced by vp_alloc_vq().


Function Documentation

static void vring_init ( struct vring vr,
unsigned int  num,
unsigned char *  queue 
) [inline, static]

Definition at line 91 of file virtio-ring.h.

References vring::avail, vring::desc, vring_desc::next, num, vring::num, PAGE_MASK, phys_to_virt(), vring_avail::ring, vring::used, and virt_to_phys().

Referenced by vp_find_vq(), and vpm_find_vqs().

{
   unsigned int i;
   unsigned long pa;

   vr->num = num;

   /* physical address of desc must be page aligned */

   pa = virt_to_phys(queue);
   pa = (pa + PAGE_MASK) & ~PAGE_MASK;
   vr->desc = phys_to_virt(pa);

   vr->avail = (struct vring_avail *)&vr->desc[num];

   /* physical address of used must be page aligned */

   pa = virt_to_phys(&vr->avail->ring[num]);
   pa = (pa + PAGE_MASK) & ~PAGE_MASK;
   vr->used = phys_to_virt(pa);

   for (i = 0; i < num - 1; i++)
           vr->desc[i].next = i + 1;
   vr->desc[i].next = 0;
}
static void vring_enable_cb ( struct vring_virtqueue vq) [inline, static]
static void vring_disable_cb ( struct vring_virtqueue vq) [inline, static]
static int vring_more_used ( struct vring_virtqueue vq) [inline, static]
void vring_detach ( struct vring_virtqueue vq,
unsigned int  head 
)

Definition at line 37 of file virtio-ring.c.

References vring::desc, vring_desc::flags, vring_virtqueue::free_head, head, vring_desc::next, vring_virtqueue::vring, VRING_DESC_F_NEXT, and wmb.

Referenced by vring_get_buf().

{
   struct vring *vr = &vq->vring;
   unsigned int i;

   /* find end of given descriptor */

   i = head;
   while (vr->desc[i].flags & VRING_DESC_F_NEXT)
           i = vr->desc[i].next;

   /* link it with free list and point to it */

   vr->desc[i].next = vq->free_head;
   wmb();
   vq->free_head = head;
}
void* vring_get_buf ( struct vring_virtqueue vq,
unsigned int *  len 
)

Definition at line 62 of file virtio-ring.c.

References BUG_ON, vring_used_elem::id, id, vring_virtqueue::last_used_idx, vring_used_elem::len, NULL, vring::num, vring_used::ring, vring::used, vring_virtqueue::vdata, vring_virtqueue::vring, vring_detach(), vring_more_used(), and wmb.

Referenced by virtnet_process_rx_packets(), and virtnet_process_tx_packets().

{
   struct vring *vr = &vq->vring;
   struct vring_used_elem *elem;
   u32 id;
   void *opaque;

   BUG_ON(!vring_more_used(vq));

   elem = &vr->used->ring[vq->last_used_idx % vr->num];
   wmb();
   id = elem->id;
   if (len != NULL)
           *len = elem->len;

   opaque = vq->vdata[id];

   vring_detach(vq, id);

   vq->last_used_idx++;

   return opaque;
}
void vring_add_buf ( struct vring_virtqueue vq,
struct vring_list  list[],
unsigned int  out,
unsigned int  in,
void *  index,
int  num_added 
)

Definition at line 86 of file virtio-ring.c.

References vring_desc::addr, vring_list::addr, vring::avail, BUG_ON, vring::desc, vring_desc::flags, vring_virtqueue::free_head, head, vring_avail::idx, in, vring_desc::len, vring_list::length, vring_desc::next, vring::num, out, vring_avail::ring, vring_virtqueue::vdata, virt_to_phys(), vring_virtqueue::vring, VRING_DESC_F_NEXT, VRING_DESC_F_WRITE, and wmb.

Referenced by virtnet_enqueue_iob().

{
   struct vring *vr = &vq->vring;
   int i, avail, head, prev;

   BUG_ON(out + in == 0);

   prev = 0;
   head = vq->free_head;
   for (i = head; out; i = vr->desc[i].next, out--) {

           vr->desc[i].flags = VRING_DESC_F_NEXT;
           vr->desc[i].addr = (u64)virt_to_phys(list->addr);
           vr->desc[i].len = list->length;
           prev = i;
           list++;
   }
   for ( ; in; i = vr->desc[i].next, in--) {

           vr->desc[i].flags = VRING_DESC_F_NEXT|VRING_DESC_F_WRITE;
           vr->desc[i].addr = (u64)virt_to_phys(list->addr);
           vr->desc[i].len = list->length;
           prev = i;
           list++;
   }
   vr->desc[prev].flags &= ~VRING_DESC_F_NEXT;

   vq->free_head = i;

   vq->vdata[head] = opaque;

   avail = (vr->avail->idx + num_added) % vr->num;
   vr->avail->ring[avail] = head;
   wmb();
}
void vring_kick ( struct virtio_pci_modern_device vdev,
unsigned int  ioaddr,
struct vring_virtqueue vq,
int  num_added 
)

Definition at line 125 of file virtio-ring.c.

References vring::avail, vring_used::flags, vring_avail::idx, mb(), vring_virtqueue::queue_index, vring::used, vp_notify(), vpm_notify(), vring_virtqueue::vring, VRING_USED_F_NO_NOTIFY, and wmb.

Referenced by virtnet_enqueue_iob().

{
   struct vring *vr = &vq->vring;

   wmb();
   vr->avail->idx += num_added;

   mb();
   if (!(vr->used->flags & VRING_USED_F_NO_NOTIFY)) {
           if (vdev) {
                   /* virtio 1.0 */
                   vpm_notify(vdev, vq);
           } else {
                   /* legacy virtio */
                   vp_notify(ioaddr, vq->queue_index);
           }
   }
}