iPXE
virtio-ring.h
Go to the documentation of this file.
1#ifndef _VIRTIO_RING_H_
2# define _VIRTIO_RING_H_
3
4#include <ipxe/virtio-pci.h>
5#include <ipxe/dma.h>
6
7/* Status byte for guest to report progress, and synchronize features. */
8/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
9#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
10/* We have found a driver for the device. */
11#define VIRTIO_CONFIG_S_DRIVER 2
12/* Driver has used its parts of the config, and is happy */
13#define VIRTIO_CONFIG_S_DRIVER_OK 4
14/* Driver has finished configuring features */
15#define VIRTIO_CONFIG_S_FEATURES_OK 8
16/* We've given up on this device. */
17#define VIRTIO_CONFIG_S_FAILED 0x80
18
19/* Virtio feature flags used to negotiate device and driver features. */
20/* Can the device handle any descriptor layout? */
21#define VIRTIO_F_ANY_LAYOUT 27
22/* v1.0 compliant. */
23#define VIRTIO_F_VERSION_1 32
24#define VIRTIO_F_IOMMU_PLATFORM 33
25
26#define MAX_QUEUE_NUM (256)
27
28#define VRING_DESC_F_NEXT 1
29#define VRING_DESC_F_WRITE 2
30
31#define VRING_AVAIL_F_NO_INTERRUPT 1
32
33#define VRING_USED_F_NO_NOTIFY 1
34
42
49
55
62
63struct vring {
64 unsigned int num;
68};
69
70#define vring_size(num) \
71 (((((sizeof(struct vring_desc) * num) + \
72 (sizeof(struct vring_avail) + sizeof(u16) * num)) \
73 + PAGE_MASK) & ~PAGE_MASK) + \
74 (sizeof(struct vring_used) + sizeof(struct vring_used_elem) * num))
75
90
91struct vring_list {
93 unsigned int length;
94};
95
96static inline void vring_init(struct vring *vr,
97 unsigned int num, unsigned char *queue)
98{
99 unsigned int i;
100 unsigned long pa;
101
102 vr->num = num;
103
104 /* physical address of desc must be page aligned */
105
106 pa = virt_to_phys(queue);
107 pa = (pa + PAGE_MASK) & ~PAGE_MASK;
108 vr->desc = phys_to_virt(pa);
109
110 vr->avail = (struct vring_avail *)&vr->desc[num];
111
112 /* physical address of used must be page aligned */
113
114 pa = virt_to_phys(&vr->avail->ring[num]);
115 pa = (pa + PAGE_MASK) & ~PAGE_MASK;
116 vr->used = phys_to_virt(pa);
117
118 for (i = 0; i < num - 1; i++)
119 vr->desc[i].next = i + 1;
120 vr->desc[i].next = 0;
121}
122
123static inline void vring_enable_cb(struct vring_virtqueue *vq)
124{
126}
127
128static inline void vring_disable_cb(struct vring_virtqueue *vq)
129{
131}
132
133
134/*
135 * vring_more_used
136 *
137 * is there some used buffers ?
138 *
139 */
140
141static inline int vring_more_used(struct vring_virtqueue *vq)
142{
143 wmb();
144 return vq->last_used_idx != vq->vring.used->idx;
145}
146
147void vring_detach(struct vring_virtqueue *vq, unsigned int head);
148void *vring_get_buf(struct vring_virtqueue *vq, unsigned int *len);
149void vring_add_buf(struct vring_virtqueue *vq, struct vring_list list[],
150 unsigned int out, unsigned int in,
151 void *index, int num_added);
152void vring_kick(struct virtio_pci_modern_device *vdev, unsigned int ioaddr,
153 struct vring_virtqueue *vq, int num_added);
154
155#endif /* _VIRTIO_RING_H_ */
__be32 in[4]
Definition CIB_PRM.h:7
__be32 out[4]
Definition CIB_PRM.h:8
unsigned long physaddr_t
Definition stdint.h:20
long index
Definition bigint.h:65
static unsigned long ioaddr
Definition davicom.c:129
ring len
Length.
Definition dwmac.h:226
uint16_t queue
Queue ID.
Definition ena.h:11
uint8_t head
Head number.
Definition int13.h:23
#define wmb()
Definition io.h:546
#define PAGE_MASK
Page mask.
Definition io.h:31
uint64_t u64
Definition stdint.h:26
DMA mappings.
uint32_t num
Definition multiboot.h:0
A DMA-capable device.
Definition dma.h:48
A DMA mapping.
Definition dma.h:33
u16 ring[0]
Definition virtio-ring.h:47
physaddr_t addr
Definition virtio-ring.h:92
unsigned int length
Definition virtio-ring.h:93
struct vring_used_elem ring[]
Definition virtio-ring.h:60
struct virtio_net_hdr_modern * empty_header
Definition virtio-ring.h:85
unsigned char * queue
Definition virtio-ring.h:77
struct vring vring
Definition virtio-ring.h:81
struct dma_mapping map
Definition virtio-ring.h:79
struct dma_device * dma
Definition virtio-ring.h:80
struct virtio_pci_region notification
Definition virtio-ring.h:88
struct vring_desc * desc
Definition virtio-ring.h:65
struct vring_avail * avail
Definition virtio-ring.h:66
unsigned int num
Definition virtio-ring.h:64
struct vring_used * used
Definition virtio-ring.h:67
#define u16
Definition vga.h:20
#define u32
Definition vga.h:21
static void vring_disable_cb(struct vring_virtqueue *vq)
void vring_kick(struct virtio_pci_modern_device *vdev, unsigned int ioaddr, struct vring_virtqueue *vq, int num_added)
static void vring_init(struct vring *vr, unsigned int num, unsigned char *queue)
Definition virtio-ring.h:96
static void vring_enable_cb(struct vring_virtqueue *vq)
#define VRING_AVAIL_F_NO_INTERRUPT
Definition virtio-ring.h:31
static int vring_more_used(struct vring_virtqueue *vq)
void vring_detach(struct vring_virtqueue *vq, unsigned int head)
Definition virtio-ring.c:37
void vring_add_buf(struct vring_virtqueue *vq, struct vring_list list[], unsigned int out, unsigned int in, void *index, int num_added)
Definition virtio-ring.c:86
void * vring_get_buf(struct vring_virtqueue *vq, unsigned int *len)
Definition virtio-ring.c:62