aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/virtio.h
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2010-04-12 09:19:07 -0400
committerRusty Russell <rusty@rustcorp.com.au>2010-05-19 08:45:43 -0400
commit7c5e9ed0c84e7d70d887878574590638d5572659 (patch)
treec929c367c6854f021b787fa99fc56d37f64d9bc0 /include/linux/virtio.h
parent1915a712f210f0b63d10bc4f875e8e66aac7a2c4 (diff)
virtio_ring: remove a level of indirection
We have a single virtqueue_ops implementation, and it seems unlikely we'll get another one at this point. So let's remove an unnecessary level of indirection: it would be very easy to re-add it if another implementation surfaces. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'include/linux/virtio.h')
-rw-r--r--include/linux/virtio.h71
1 files changed, 18 insertions, 53 deletions
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 18ccc686a429..5b0fce0d2aa2 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -14,7 +14,6 @@
14 * @callback: the function to call when buffers are consumed (can be NULL). 14 * @callback: the function to call when buffers are consumed (can be NULL).
15 * @name: the name of this virtqueue (mainly for debugging) 15 * @name: the name of this virtqueue (mainly for debugging)
16 * @vdev: the virtio device this queue was created for. 16 * @vdev: the virtio device this queue was created for.
17 * @vq_ops: the operations for this virtqueue (see below).
18 * @priv: a pointer for the virtqueue implementation to use. 17 * @priv: a pointer for the virtqueue implementation to use.
19 */ 18 */
20struct virtqueue { 19struct virtqueue {
@@ -22,94 +21,60 @@ struct virtqueue {
22 void (*callback)(struct virtqueue *vq); 21 void (*callback)(struct virtqueue *vq);
23 const char *name; 22 const char *name;
24 struct virtio_device *vdev; 23 struct virtio_device *vdev;
25 struct virtqueue_ops *vq_ops;
26 void *priv; 24 void *priv;
27}; 25};
28 26
29/** 27/**
30 * virtqueue_ops - operations for virtqueue abstraction layer 28 * operations for virtqueue
31 * @add_buf: expose buffer to other end 29 * virtqueue_add_buf: expose buffer to other end
32 * vq: the struct virtqueue we're talking about. 30 * vq: the struct virtqueue we're talking about.
33 * sg: the description of the buffer(s). 31 * sg: the description of the buffer(s).
34 * out_num: the number of sg readable by other side 32 * out_num: the number of sg readable by other side
35 * in_num: the number of sg which are writable (after readable ones) 33 * in_num: the number of sg which are writable (after readable ones)
36 * data: the token identifying the buffer. 34 * data: the token identifying the buffer.
37 * Returns remaining capacity of queue (sg segments) or a negative error. 35 * Returns remaining capacity of queue (sg segments) or a negative error.
38 * @kick: update after add_buf 36 * virtqueue_kick: update after add_buf
39 * vq: the struct virtqueue 37 * vq: the struct virtqueue
40 * After one or more add_buf calls, invoke this to kick the other side. 38 * After one or more add_buf calls, invoke this to kick the other side.
41 * @get_buf: get the next used buffer 39 * virtqueue_get_buf: get the next used buffer
42 * vq: the struct virtqueue we're talking about. 40 * vq: the struct virtqueue we're talking about.
43 * len: the length written into the buffer 41 * len: the length written into the buffer
44 * Returns NULL or the "data" token handed to add_buf. 42 * Returns NULL or the "data" token handed to add_buf.
45 * @disable_cb: disable callbacks 43 * virtqueue_disable_cb: disable callbacks
46 * vq: the struct virtqueue we're talking about. 44 * vq: the struct virtqueue we're talking about.
47 * Note that this is not necessarily synchronous, hence unreliable and only 45 * Note that this is not necessarily synchronous, hence unreliable and only
48 * useful as an optimization. 46 * useful as an optimization.
49 * @enable_cb: restart callbacks after disable_cb. 47 * virtqueue_enable_cb: restart callbacks after disable_cb.
50 * vq: the struct virtqueue we're talking about. 48 * vq: the struct virtqueue we're talking about.
51 * This re-enables callbacks; it returns "false" if there are pending 49 * This re-enables callbacks; it returns "false" if there are pending
52 * buffers in the queue, to detect a possible race between the driver 50 * buffers in the queue, to detect a possible race between the driver
53 * checking for more work, and enabling callbacks. 51 * checking for more work, and enabling callbacks.
54 * @detach_unused_buf: detach first unused buffer 52 * virtqueue_detach_unused_buf: detach first unused buffer
55 * vq: the struct virtqueue we're talking about. 53 * vq: the struct virtqueue we're talking about.
56 * Returns NULL or the "data" token handed to add_buf 54 * Returns NULL or the "data" token handed to add_buf
57 * 55 *
58 * Locking rules are straightforward: the driver is responsible for 56 * Locking rules are straightforward: the driver is responsible for
59 * locking. No two operations may be invoked simultaneously, with the exception 57 * locking. No two operations may be invoked simultaneously, with the exception
60 * of @disable_cb. 58 * of virtqueue_disable_cb.
61 * 59 *
62 * All operations can be called in any context. 60 * All operations can be called in any context.
63 */ 61 */
64struct virtqueue_ops {
65 int (*add_buf)(struct virtqueue *vq,
66 struct scatterlist sg[],
67 unsigned int out_num,
68 unsigned int in_num,
69 void *data);
70 62
71 void (*kick)(struct virtqueue *vq); 63int virtqueue_add_buf(struct virtqueue *vq,
64 struct scatterlist sg[],
65 unsigned int out_num,
66 unsigned int in_num,
67 void *data);
72 68
73 void *(*get_buf)(struct virtqueue *vq, unsigned int *len); 69void virtqueue_kick(struct virtqueue *vq);
74 70
75 void (*disable_cb)(struct virtqueue *vq); 71void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
76 bool (*enable_cb)(struct virtqueue *vq);
77 void *(*detach_unused_buf)(struct virtqueue *vq);
78};
79
80static inline int virtqueue_add_buf(struct virtqueue *vq,
81 struct scatterlist sg[],
82 unsigned int out_num,
83 unsigned int in_num,
84 void *data)
85{
86 return vq->vq_ops->add_buf(vq, sg, out_num, in_num, data);
87}
88
89static inline int void virtqueue_kick(struct virtqueue *vq)
90{
91 return vq->vq_ops->kick(vq);
92}
93
94static inline void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len)
95{
96 return vq->vq_ops->get_buf(vq, len);
97}
98 72
99static inline void virtqueue_disable_cb(struct virtqueue *vq) 73void virtqueue_disable_cb(struct virtqueue *vq);
100{
101 vq->vq_ops->disable_cb(vq);
102}
103 74
104static inline bool virtqueue_enable_cb(struct virtqueue *vq) 75bool virtqueue_enable_cb(struct virtqueue *vq);
105{
106 return vq->vq_ops->enable_cb(vq);
107}
108 76
109static inline void *virtqueue_detach_unused_buf(struct virtqueue *vq) 77void *virtqueue_detach_unused_buf(struct virtqueue *vq);
110{
111 return vq->vq_ops->detach_unused_buf(vq);
112}
113 78
114/** 79/**
115 * virtio_device - representation of a device using virtio 80 * virtio_device - representation of a device using virtio