summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrusty <rusty@0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652>2014-03-13 03:14:50 +0000
committerrusty <rusty@0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652>2014-03-13 03:14:50 +0000
commit711c7742e232597cdf213b45f7c13eee4e6d6bf8 (patch)
tree3c635780b2301b3d7ecb486ff2ba3584518851d4
parentc4ab14e84b4ed80e360fd1467d4ec6610af1234b (diff)
VIRTIO-60: avoid vring and VIRTIO_RING.
These are never introduced, so use simpler names: virtq* for structures and VIRTIO_ for features. I added two notes about the old names, for helping people coming from the old spec. Signed-off-by: Rusty Russell <rusty@au1.ibm.com> git-svn-id: https://tools.oasis-open.org/version-control/svn/virtio@327 0c8fb4dd-22a2-4bb5-bc14-6c75a5f43652
-rw-r--r--conformance.tex2
-rw-r--r--content.tex121
-rw-r--r--introduction.tex4
-rw-r--r--virtio-ring.h100
4 files changed, 102 insertions, 125 deletions
diff --git a/conformance.tex b/conformance.tex
index 4896729..942afac 100644
--- a/conformance.tex
+++ b/conformance.tex
@@ -252,7 +252,7 @@ REQUIRED level requirements for the legacy interface
for the transitional devices and drivers.
The requirements for the legacy interface for transitional implementations
-are located in sections named "Legacy Interface" listed below:
+are located in sections named ``Legacy Interface'' listed below:
\begin{itemize}
\item Section \ref{sec:Basic Facilities of a Virtio Device /
Feature Bits / Legacy Interface: A Note on Feature Bits}
diff --git a/content.tex b/content.tex
index 9775c44..58c3ebc 100644
--- a/content.tex
+++ b/content.tex
@@ -290,10 +290,10 @@ according to the following formula:
\begin{lstlisting}
#define ALIGN(x) (((x) + PAGE_SIZE) & ~PAGE_SIZE)
-static inline unsigned vring_size(unsigned int qsz)
+static inline unsigned virtq_size(unsigned int qsz)
{
- return ALIGN(sizeof(struct vring_desc)*qsz + sizeof(u16)*(3 + qsz))
- + ALIGN(sizeof(u16)*3 + sizeof(struct vring_used_elem)*qsz);
+ return ALIGN(sizeof(struct virtq_desc)*qsz + sizeof(u16)*(3 + qsz))
+ + ALIGN(sizeof(u16)*3 + sizeof(struct virtq_used_elem)*qsz);
}
\end{lstlisting}
@@ -303,18 +303,18 @@ devices and drivers MUST use the following virtqueue layout
structure to locate elements of the virtqueue:
\begin{lstlisting}
-struct vring {
+struct virtq {
// The actual descriptors (16 bytes each)
- struct vring_desc desc[ Queue Size ];
+ struct virtq_desc desc[ Queue Size ];
// A ring of available descriptor heads with free-running index.
- struct vring_avail avail;
+ struct virtq_avail avail;
// Padding to the next PAGE_SIZE boundary.
u8 pad[ Padding ];
// A ring of used descriptor heads with free-running index.
- struct vring_used used;
+ struct virtq_used used;
};
\end{lstlisting}
@@ -384,18 +384,18 @@ device type. Most common is to begin the data with a header
it with a status tailer for the device to write.
\begin{lstlisting}
-struct vring_desc {
+struct virtq_desc {
/* Address (guest-physical). */
le64 addr;
/* Length. */
le32 len;
/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT 1
+#define VIRTQ_DESC_F_NEXT 1
/* This marks a buffer as device write-only (otherwise device read-only). */
-#define VRING_DESC_F_WRITE 2
+#define VIRTQ_DESC_F_WRITE 2
/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT 4
+#define VIRTQ_DESC_F_INDIRECT 4
/* The flags as indicated above. */
le16 flags;
/* Next field if flags & NEXT */
@@ -406,6 +406,12 @@ struct vring_desc {
The number of descriptors in the table is defined by the queue size
for this virtqueue.
+\begin{note}
+The legacy \hyperref[intro:Virtio PCI Draft]{[Virtio PCI Draft]}
+referred to this structure as vring_desc, and the constants as
+VRING_DESC_F_NEXT, etc, but the layout and values were identical.
+\end{note}
+
\devicenormative{\subsubsection}{The Virtqueue Descriptor Table}{Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table}
A device MUST NOT write to a device-readable buffer, and a device SHOULD NOT
read a device-writable buffer (it MAY do so for debugging or diagnostic
@@ -418,10 +424,10 @@ this implies that loops in the descriptor chain are forbidden!
\subsubsection{Indirect Descriptors}\label{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors}
Some devices benefit by concurrently dispatching a large number
-of large requests. The VIRTIO_RING_F_INDIRECT_DESC feature allows this (see \ref{sec:virtio-ring.h}~\nameref{sec:virtio-ring.h}). To increase
+of large requests. The VIRTIO_F_INDIRECT_DESC feature allows this (see \ref{sec:virtio-ring.h}~\nameref{sec:virtio-ring.h}). To increase
ring capacity the driver can store a table of indirect
descriptors anywhere in memory, and insert a descriptor in main
-virtqueue (with \field{flags}\&VRING_DESC_F_INDIRECT on) that refers to memory buffer
+virtqueue (with \field{flags}\&VIRTQ_DESC_F_INDIRECT on) that refers to memory buffer
containing this indirect descriptor table; \field{addr} and \field{len}
refer to the indirect table address and length in bytes,
respectively.
@@ -433,35 +439,35 @@ which is a variable, so this code won't compile):
\begin{lstlisting}
struct indirect_descriptor_table {
/* The actual descriptors (16 bytes each) */
- struct vring_desc desc[len / 16];
+ struct virtq_desc desc[len / 16];
};
\end{lstlisting}
The first indirect descriptor is located at start of the indirect
descriptor table (index 0), additional indirect descriptors are
chained by \field{next}. An indirect descriptor without a valid \field{next}
-(with \field{flags}\&VRING_DESC_F_NEXT off) signals the end of the descriptor.
+(with \field{flags}\&VIRTQ_DESC_F_NEXT off) signals the end of the descriptor.
A single indirect descriptor
table can include both device-readable and device-writable descriptors.
\drivernormative{\paragraph}{Indirect Descriptors}{Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors}
-The driver MUST NOT set the VRING_DESC_F_INDIRECT flag unless the
-VIRTIO_RING_F_INDIRECT_DESC feature was negotiated. The driver MUST NOT
-set the VRING_DESC_F_INDIRECT flag within an indirect descriptor (ie. only
+The driver MUST NOT set the VIRTQ_DESC_F_INDIRECT flag unless the
+VIRTIO_F_INDIRECT_DESC feature was negotiated. The driver MUST NOT
+set the VIRTQ_DESC_F_INDIRECT flag within an indirect descriptor (ie. only
one table per descriptor).
\devicenormative{\paragraph}{Indirect Descriptors}{Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors}
-The device MUST ignore the write-only flag (\field{flags}\&VRING_DESC_F_WRITE) in the descriptor that refers to an indirect table.
+The device MUST ignore the write-only flag (\field{flags}\&VIRTQ_DESC_F_WRITE) in the descriptor that refers to an indirect table.
\subsection{The Virtqueue Available Ring}\label{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Available Ring}
\begin{lstlisting}
-struct vring_avail {
-#define VRING_AVAIL_F_NO_INTERRUPT 1
+struct virtq_avail {
+#define VIRTQ_AVAIL_F_NO_INTERRUPT 1
le16 flags;
le16 idx;
le16 ring[ /* Queue Size */ ];
- le16 used_event; /* Only if VIRTIO_RING_F_EVENT_IDX */
+ le16 used_event; /* Only if VIRTIO_F_EVENT_IDX */
};
\end{lstlisting}
@@ -472,9 +478,15 @@ written by the driver and read by the device.
\field{idx} field indicates where the driver would put the next descriptor
entry in the ring (modulo the queue size). This starts at 0, and increases.
+\begin{note}
+The legacy \hyperref[intro:Virtio PCI Draft]{[Virtio PCI Draft]}
+referred to this structure as vring_avail, and the constant as
+VRING_AVAIL_F_NO_INTERRUPT, but the layout and value were identical.
+\end{note}
+
\subsection{Virtqueue Interrupt Suppression}\label{sec:Basic Facilities of a Virtio Device / Virtqueues / Virtqueue Interrupt Suppression}
-If the VIRTIO_RING_F_EVENT_IDX feature bit is not negotiated,
+If the VIRTIO_F_EVENT_IDX feature bit is not negotiated,
the \field{flags} field in the available ring offers a crude mechanism for the driver to inform
the device that it doesn't want interrupts when buffers are used. Otherwise
\field{used_event} is a more performant alterative where the driver
@@ -485,14 +497,14 @@ are not synchronized with the device, but they serve as
useful optimizations.
\drivernormative{\subsubsection}{Virtqueue Interrupt Suppression}{Basic Facilities of a Virtio Device / Virtqueues / Virtqueue Interrupt Suppression}
-If the VIRTIO_RING_F_EVENT_IDX feature bit is not negotiated:
+If the VIRTIO_F_EVENT_IDX feature bit is not negotiated:
\begin{itemize}
\item The driver MUST set \field{flags} to 0 or 1.
\item The driver MAY set \field{flags} to 1 to advise
the device that interrupts are not needed.
\end{itemize}
-Otherwise, if the VIRTIO_RING_F_EVENT_IDX feature bit is negotiated:
+Otherwise, if the VIRTIO_F_EVENT_IDX feature bit is negotiated:
\begin{itemize}
\item The driver MUST set \field{flags} to 0.
\item The driver MAY use \field{used_event} to advise the device that interrupts are unnecessary until the device writes entry with an index specified by \field{used_event} into the used ring (equivalently, until \field{idx} in the
@@ -503,7 +515,7 @@ The driver MUST handle spurious interrupts from the device.
\devicenormative{\subsubsection}{Virtqueue Interrupt Suppression}{Basic Facilities of a Virtio Device / Virtqueues / Virtqueue Interrupt Suppression}
-If the VIRTIO_RING_F_EVENT_IDX feature bit is not negotiated:
+If the VIRTIO_F_EVENT_IDX feature bit is not negotiated:
\begin{itemize}
\item The device MUST ignore the \field{used_event} value.
\item After the device writes a descriptor index into the used ring:
@@ -513,7 +525,7 @@ If the VIRTIO_RING_F_EVENT_IDX feature bit is not negotiated:
\end{itemize}
\end{itemize}
-Otherwise, if the VIRTIO_RING_F_EVENT_IDX feature bit is negotiated:
+Otherwise, if the VIRTIO_F_EVENT_IDX feature bit is negotiated:
\begin{itemize}
\item The device MUST ignore the lower bit of \field{flags}.
\item After the device writes a descriptor index into the used ring:
@@ -527,23 +539,23 @@ Otherwise, if the VIRTIO_RING_F_EVENT_IDX feature bit is negotiated:
\begin{note}
For example, if \field{used_event} is 0, then a device using
- VIRTIO_RING_F_EVENT_IDX would interrupt after the first buffer is
+ VIRTIO_F_EVENT_IDX would interrupt after the first buffer is
used (and again after the 65536th buffer, etc).
\end{note}
\subsection{The Virtqueue Used Ring}\label{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Used Ring}
\begin{lstlisting}
-struct vring_used {
-#define VRING_USED_F_NO_NOTIFY 1
+struct virtq_used {
+#define VIRTQ_USED_F_NO_NOTIFY 1
le16 flags;
le16 idx;
- struct vring_used_elem ring[ /* Queue Size */];
- le16 avail_event; /* Only if VIRTIO_RING_F_EVENT_IDX */
+ struct virtq_used_elem ring[ /* Queue Size */];
+ le16 avail_event; /* Only if VIRTIO_F_EVENT_IDX */
};
/* le32 is used here for ids for padding reasons. */
-struct vring_used_elem {
+struct virtq_used_elem {
/* Index of start of used descriptor chain. */
le32 id;
/* Total length of the descriptor chain which was used (written to) */
@@ -562,6 +574,13 @@ for drivers using untrusted buffers: if you do not know exactly
how much has been written by the device, you usually have to zero
the buffer to ensure no data leakage occurs.
+\begin{note}
+The legacy \hyperref[intro:Virtio PCI Draft]{[Virtio PCI Draft]}
+referred to these structures as vring_used and vring_used_elem, and
+the constant as VRING_USED_F_NO_NOTIFY, but the layout and value were
+identical.
+\end{note}
+
\subsection{Virtqueue Notification Suppression}\label{sec:Basic Facilities of a Virtio Device / Virtqueues / Virtqueue Notification Suppression}
The device can suppress notifications in a manner analogous to the way
@@ -574,7 +593,7 @@ same way the driver manipulates \field{flags} or \field{used_event} in the avail
The driver MUST initialize \field{flags} in the used ring to 0 when
allocating the used ring.
-If the VIRTIO_RING_F_EVENT_IDX feature bit is not negotiated:
+If the VIRTIO_F_EVENT_IDX feature bit is not negotiated:
\begin{itemize}
\item The driver MUST ignore the \field{avail_event} value.
\item After the driver writes a descriptor index into the available ring:
@@ -584,7 +603,7 @@ If the VIRTIO_RING_F_EVENT_IDX feature bit is not negotiated:
\end{itemize}
\end{itemize}
-Otherwise, if the VIRTIO_RING_F_EVENT_IDX feature bit is negotiated:
+Otherwise, if the VIRTIO_F_EVENT_IDX feature bit is negotiated:
\begin{itemize}
\item The driver MUST ignore the lower bit of \field{flags}.
\item After the driver writes a descriptor index into the available ring:
@@ -597,14 +616,14 @@ Otherwise, if the VIRTIO_RING_F_EVENT_IDX feature bit is negotiated:
\end{itemize}
\devicenormative{\subsubsection}{Virtqueue Notification Suppression}{Basic Facilities of a Virtio Device / Virtqueues / Virtqueue Notification Suppression}
-If the VIRTIO_RING_F_EVENT_IDX feature bit is not negotiated:
+If the VIRTIO_F_EVENT_IDX feature bit is not negotiated:
\begin{itemize}
\item The device MUST set \field{flags} to 0 or 1.
\item The device MAY set \field{flags} to 1 to advise
the driver that notifications are not needed.
\end{itemize}
-Otherwise, if the VIRTIO_RING_F_EVENT_IDX feature bit is negotiated:
+Otherwise, if the VIRTIO_F_EVENT_IDX feature bit is negotiated:
\begin{itemize}
\item The device MUST set \field{flags} to 0.
\item The device MAY use \field{avail_event} to advise the driver that notifications are unnecessary until the driver writes entry with an index specified by \field{avail_event} into the available ring (equivalently, until \field{idx} in the
@@ -778,13 +797,13 @@ for each buffer element, b:
\item Get the next free descriptor table entry, d
\item Set \field{d.addr} to the physical address of the start of b
\item Set \field{d.len} to the length of b.
-\item If b is device-writable, set \field{d.flags} to VRING_DESC_F_WRITE,
+\item If b is device-writable, set \field{d.flags} to VIRTQ_DESC_F_WRITE,
otherwise 0.
\item If there is a buffer element after this:
\begin{enumerate}
\item Set \field{d.next} to the index of the next free descriptor
element.
- \item Set the VRING_DESC_F_NEXT bit in \field{d.flags}.
+ \item Set the VIRTQ_DESC_F_NEXT bit in \field{d.flags}.
\end{enumerate}
\end{enumerate}
@@ -855,20 +874,20 @@ emptying the ring and reenabling interrupts. This is usually handled by
re-checking for more used buffers after interrups are re-enabled:
\begin{lstlisting}
-vring_disable_interrupts(vq);
+virtq_disable_interrupts(vq);
for (;;) {
- if (vq->last_seen_used != le16_to_cpu(vring->used.idx)) {
- vring_enable_interrupts(vq);
+ if (vq->last_seen_used != le16_to_cpu(virtq->used.idx)) {
+ virtq_enable_interrupts(vq);
mb();
- if (vq->last_seen_used != le16_to_cpu(vring->used.idx))
+ if (vq->last_seen_used != le16_to_cpu(virtq->used.idx))
break;
- vring_disable_interrupts(vq);
+ virtq_disable_interrupts(vq);
}
- struct vring_used_elem *e = vring.used->ring[vq->last_seen_used%vsz];
+ struct virtq_used_elem *e = virtq.used->ring[vq->last_seen_used%vsz];
process_buffer(e);
vq->last_seen_used++;
}
@@ -2487,11 +2506,11 @@ The calculation for total size is as follows:
\begin{lstlisting}
#define ALIGN(x) (((x) + align) & ~align)
-static inline unsigned vring_size(unsigned int num)
+static inline unsigned virtq_size(unsigned int num)
{
- return ALIGN(sizeof(struct vring_desc)*num
+ return ALIGN(sizeof(struct virtq_desc)*num
+ sizeof(u16)*(3 + num))
- + ALIGN(sizeof(u16)*3 + sizeof(struct vring_used_elem)*num);
+ + ALIGN(sizeof(u16)*3 + sizeof(struct virtq_used_elem)*num);
}
\end{lstlisting}
@@ -3135,7 +3154,7 @@ which case it MUST set the VIRTIO_NET_HDR_GSO_ECN bit in \field{gso_type}.
\paragraph{Packet Transmission Interrupt}\label{sec:Device Types / Network Device / Device Operation / Packet Transmission / Packet Transmission Interrupt}
Often a driver will suppress transmission interrupts using the
-VRING_AVAIL_F_NO_INTERRUPT flag
+VIRTQ_AVAIL_F_NO_INTERRUPT flag
(see \ref{sec:General Initialization And Device Operation / Device Operation / Receiving Used Buffers From The Device}~\nameref{sec:General Initialization And Device Operation / Device Operation / Receiving Used Buffers From The Device})
and check for used packets in the transmit path of following
packets.
@@ -4948,7 +4967,7 @@ Currently there are three device-independent feature bits defined:
\begin{description}
\item[VIRTIO_F_RING_INDIRECT_DESC (28)] Negotiating this feature indicates
- that the driver can use descriptors with the VRING_DESC_F_INDIRECT
+ that the driver can use descriptors with the VIRTQ_DESC_F_INDIRECT
flag set, as described in \ref{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors}~\nameref{sec:Basic Facilities of a Virtio Device / Virtqueues / The Virtqueue Descriptor Table / Indirect Descriptors}.
\item[VIRTIO_F_RING_EVENT_IDX(29)] This feature enables the \field{used_event}
@@ -4976,7 +4995,7 @@ Transitional devices MAY offer the following:
has been negotiated by driver, the device MUST issue
an interrupt if the device runs
out of available descriptors on a virtqueue, even though
- interrupts are suppressed using the VRING_AVAIL_F_NO_INTERRUPT
+ interrupts are suppressed using the VIRTQ_AVAIL_F_NO_INTERRUPT
flag or the \field{used_event} field.
\begin{note}
An example of a driver using this feature is the legacy
diff --git a/introduction.tex b/introduction.tex
index f8ea424..ac7eefa 100644
--- a/introduction.tex
+++ b/introduction.tex
@@ -38,8 +38,8 @@ between different transports.
\begin{longtable}{l p{5in}}
\phantomsection\label{intro:rfc2119}\textbf{[RFC2119]} &
-Bradner S., "Key words for use in RFCs to Indicate Requirement
-Levels", BCP 14, RFC 2119, March 1997. \newline\url{http://www.ietf.org/rfc/rfc2119.txt}\\
+Bradner S., ``Key words for use in RFCs to Indicate Requirement
+Levels'', BCP 14, RFC 2119, March 1997. \newline\url{http://www.ietf.org/rfc/rfc2119.txt}\\
\phantomsection\label{intro:S390 PoP}\textbf{[S390 PoP]} & z/Architecture Principles of Operation, IBM Publication SA22-7832, \newline\url{http://publibfi.boulder.ibm.com/epubs/pdf/dz9zr009.pdf}, and any future revisions\\
\phantomsection\label{intro:S390 Common I/O}\textbf{[S390 Common I/O]} & ESA/390 Common I/O-Device and Self-Description, IBM Publication SA22-7204, \newline\url{http://publibfp.dhe.ibm.com/cgi-bin/bookmgr/BOOKS/dz9ar501/CCONTENTS}, and any future revisions\\
\phantomsection\label{intro:PCI}\textbf{[PCI]} &
diff --git a/virtio-ring.h b/virtio-ring.h
index 6d1e2dd..aa01d92 100644
--- a/virtio-ring.h
+++ b/virtio-ring.h
@@ -1,5 +1,5 @@
-#ifndef VIRTIO_RING_H
-#define VIRTIO_RING_H
+#ifndef VIRTQUEUE_H
+#define VIRTQUEUE_H
/* An interface for efficient virtio implementation.
*
* This header is BSD licensed so anyone can use the definitions
@@ -35,33 +35,33 @@
#include <stdint.h>
/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT 1
+#define VIRTQ_DESC_F_NEXT 1
/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE 2
+#define VIRTQ_DESC_F_WRITE 2
/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT 4
+#define VIRTQ_DESC_F_INDIRECT 4
/* The device uses this in used->flags to advise the driver: don't kick me
* when you add a buffer. It's unreliable, so it's simply an
* optimization. */
-#define VRING_USED_F_NO_NOTIFY 1
+#define VIRTQ_USED_F_NO_NOTIFY 1
/* The driver uses this in avail->flags to advise the device: don't
* interrupt me when you consume a buffer. It's unreliable, so it's
* simply an optimization. */
-#define VRING_AVAIL_F_NO_INTERRUPT 1
+#define VIRTQ_AVAIL_F_NO_INTERRUPT 1
/* Support for indirect descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC 28
+#define VIRTIO_F_INDIRECT_DESC 28
/* Support for avail_idx and used_idx fields */
-#define VIRTIO_RING_F_EVENT_IDX 29
+#define VIRTIO_F_EVENT_IDX 29
/* Arbitrary descriptor layouts. */
-#define VIRTIO_F_ANY_LAYOUT 27
+#define VIRTIO_F_ANY_LAYOUT 27
-/* Virtio ring descriptors: 16 bytes.
+/* Virtqueue descriptors: 16 bytes.
* These can chain together via "next". */
-struct vring_desc {
+struct virtq_desc {
/* Address (guest-physical). */
le64 addr;
/* Length. */
@@ -72,93 +72,51 @@ struct vring_desc {
le16 next;
};
-struct vring_avail {
+struct virtq_avail {
le16 flags;
le16 idx;
le16 ring[];
- /* Only if VIRTIO_RING_F_EVENT_IDX: le16 used_event; */
+ /* Only if VIRTIO_F_EVENT_IDX: le16 used_event; */
};
/* le32 is used here for ids for padding reasons. */
-struct vring_used_elem {
+struct virtq_used_elem {
/* Index of start of used descriptor chain. */
le32 id;
/* Total length of the descriptor chain which was written to. */
le32 len;
};
-struct vring_used {
+struct virtq_used {
le16 flags;
le16 idx;
- struct vring_used_elem ring[];
- /* Only if VIRTIO_RING_F_EVENT_IDX: le16 avail_event; */
+ struct virtq_used_elem ring[];
+ /* Only if VIRTIO_F_EVENT_IDX: le16 avail_event; */
};
-struct vring {
+struct virtq {
unsigned int num;
- struct vring_desc *desc;
- struct vring_avail *avail;
- struct vring_used *used;
+ struct virtq_desc *desc;
+ struct virtq_avail *avail;
+ struct virtq_used *used;
};
-/* The standard layout for the ring is a continuous chunk of memory which
- * looks like this. We assume num is a power of 2.
- *
- * struct vring {
- * // The actual descriptors (16 bytes each)
- * struct vring_desc desc[num];
- *
- * // A ring of available descriptor heads with free-running index.
- * le16 avail_flags;
- * le16 avail_idx;
- * le16 available[num];
- * le16 used_event_idx; // Only if VIRTIO_RING_F_EVENT_IDX
- *
- * // Padding to the next align boundary.
- * char pad[];
- *
- * // A ring of used descriptor heads with free-running index.
- * le16 used_flags;
- * le16 used_idx;
- * struct vring_used_elem used[num];
- * le16 avail_event_idx; // Only if VIRTIO_RING_F_EVENT_IDX
- * };
- * Note: for virtio PCI, align is 4096.
- */
-static inline void vring_init(struct vring *vr, unsigned int num, void *p,
- unsigned long align)
-{
- vr->num = num;
- vr->desc = p;
- vr->avail = p + num*sizeof(struct vring_desc);
- vr->used = (void *)(((unsigned long)&vr->avail->ring[num] + sizeof(le16)
- + align-1)
- & ~(align - 1));
-}
-
-static inline unsigned vring_size(unsigned int num, unsigned long align)
-{
- return ((sizeof(struct vring_desc)*num + sizeof(le16)*(3+num)
- + align - 1) & ~(align - 1))
- + sizeof(le16)*3 + sizeof(struct vring_used_elem)*num;
-}
-
-static inline int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old_idx)
+static inline int virtq_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old_idx)
{
return (uint16_t)(new_idx - event_idx - 1) < (uint16_t)(new_idx - old_idx);
}
-/* Get location of event indices (only with VIRTIO_RING_F_EVENT_IDX) */
-static inline le16 *vring_used_event(struct vring *vr)
+/* Get location of event indices (only with VIRTIO_F_EVENT_IDX) */
+static inline le16 *virtq_used_event(struct virtq *vq)
{
/* For backwards compat, used event index is at *end* of avail ring. */
- return &vr->avail->ring[vr->num];
+ return &vq->avail->ring[vq->num];
}
-static inline le16 *vring_avail_event(struct vring *vr)
+static inline le16 *virtq_avail_event(struct virtq *vq)
{
/* For backwards compat, avail event index is at *end* of used ring. */
- return (le16 *)&vr->used->ring[vr->num];
+ return (le16 *)&vq->used->ring[vq->num];
}
-#endif /* VIRTIO_RING_H */
+#endif /* VIRTQUEUE_H */