diff options
Diffstat (limited to 'include/linux/virtio.h')
-rw-r--r-- | include/linux/virtio.h | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 40d1709bdbf4..aff5b4f74041 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/spinlock.h> | 7 | #include <linux/spinlock.h> |
8 | #include <linux/device.h> | 8 | #include <linux/device.h> |
9 | #include <linux/mod_devicetable.h> | 9 | #include <linux/mod_devicetable.h> |
10 | #include <linux/gfp.h> | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * virtqueue - a queue to register buffers for sending or receiving. | 13 | * virtqueue - a queue to register buffers for sending or receiving. |
@@ -14,7 +15,6 @@ | |||
14 | * @callback: the function to call when buffers are consumed (can be NULL). | 15 | * @callback: the function to call when buffers are consumed (can be NULL). |
15 | * @name: the name of this virtqueue (mainly for debugging) | 16 | * @name: the name of this virtqueue (mainly for debugging) |
16 | * @vdev: the virtio device this queue was created for. | 17 | * @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. | 18 | * @priv: a pointer for the virtqueue implementation to use. |
19 | */ | 19 | */ |
20 | struct virtqueue { | 20 | struct virtqueue { |
@@ -22,60 +22,71 @@ struct virtqueue { | |||
22 | void (*callback)(struct virtqueue *vq); | 22 | void (*callback)(struct virtqueue *vq); |
23 | const char *name; | 23 | const char *name; |
24 | struct virtio_device *vdev; | 24 | struct virtio_device *vdev; |
25 | struct virtqueue_ops *vq_ops; | ||
26 | void *priv; | 25 | void *priv; |
27 | }; | 26 | }; |
28 | 27 | ||
29 | /** | 28 | /** |
30 | * virtqueue_ops - operations for virtqueue abstraction layer | 29 | * operations for virtqueue |
31 | * @add_buf: expose buffer to other end | 30 | * virtqueue_add_buf: expose buffer to other end |
32 | * vq: the struct virtqueue we're talking about. | 31 | * vq: the struct virtqueue we're talking about. |
33 | * sg: the description of the buffer(s). | 32 | * sg: the description of the buffer(s). |
34 | * out_num: the number of sg readable by other side | 33 | * out_num: the number of sg readable by other side |
35 | * in_num: the number of sg which are writable (after readable ones) | 34 | * in_num: the number of sg which are writable (after readable ones) |
36 | * data: the token identifying the buffer. | 35 | * data: the token identifying the buffer. |
36 | * gfp: how to do memory allocations (if necessary). | ||
37 | * Returns remaining capacity of queue (sg segments) or a negative error. | 37 | * Returns remaining capacity of queue (sg segments) or a negative error. |
38 | * @kick: update after add_buf | 38 | * virtqueue_kick: update after add_buf |
39 | * vq: the struct virtqueue | 39 | * vq: the struct virtqueue |
40 | * After one or more add_buf calls, invoke this to kick the other side. | 40 | * After one or more add_buf calls, invoke this to kick the other side. |
41 | * @get_buf: get the next used buffer | 41 | * virtqueue_get_buf: get the next used buffer |
42 | * vq: the struct virtqueue we're talking about. | 42 | * vq: the struct virtqueue we're talking about. |
43 | * len: the length written into the buffer | 43 | * len: the length written into the buffer |
44 | * Returns NULL or the "data" token handed to add_buf. | 44 | * Returns NULL or the "data" token handed to add_buf. |
45 | * @disable_cb: disable callbacks | 45 | * virtqueue_disable_cb: disable callbacks |
46 | * vq: the struct virtqueue we're talking about. | 46 | * vq: the struct virtqueue we're talking about. |
47 | * Note that this is not necessarily synchronous, hence unreliable and only | 47 | * Note that this is not necessarily synchronous, hence unreliable and only |
48 | * useful as an optimization. | 48 | * useful as an optimization. |
49 | * @enable_cb: restart callbacks after disable_cb. | 49 | * virtqueue_enable_cb: restart callbacks after disable_cb. |
50 | * vq: the struct virtqueue we're talking about. | 50 | * vq: the struct virtqueue we're talking about. |
51 | * This re-enables callbacks; it returns "false" if there are pending | 51 | * This re-enables callbacks; it returns "false" if there are pending |
52 | * buffers in the queue, to detect a possible race between the driver | 52 | * buffers in the queue, to detect a possible race between the driver |
53 | * checking for more work, and enabling callbacks. | 53 | * checking for more work, and enabling callbacks. |
54 | * @detach_unused_buf: detach first unused buffer | 54 | * virtqueue_detach_unused_buf: detach first unused buffer |
55 | * vq: the struct virtqueue we're talking about. | 55 | * vq: the struct virtqueue we're talking about. |
56 | * Returns NULL or the "data" token handed to add_buf | 56 | * Returns NULL or the "data" token handed to add_buf |
57 | * | 57 | * |
58 | * Locking rules are straightforward: the driver is responsible for | 58 | * Locking rules are straightforward: the driver is responsible for |
59 | * locking. No two operations may be invoked simultaneously, with the exception | 59 | * locking. No two operations may be invoked simultaneously, with the exception |
60 | * of @disable_cb. | 60 | * of virtqueue_disable_cb. |
61 | * | 61 | * |
62 | * All operations can be called in any context. | 62 | * All operations can be called in any context. |
63 | */ | 63 | */ |
64 | struct 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 | 64 | ||
71 | void (*kick)(struct virtqueue *vq); | 65 | int virtqueue_add_buf_gfp(struct virtqueue *vq, |
66 | struct scatterlist sg[], | ||
67 | unsigned int out_num, | ||
68 | unsigned int in_num, | ||
69 | void *data, | ||
70 | gfp_t gfp); | ||
72 | 71 | ||
73 | void *(*get_buf)(struct virtqueue *vq, unsigned int *len); | 72 | static inline int virtqueue_add_buf(struct virtqueue *vq, |
73 | struct scatterlist sg[], | ||
74 | unsigned int out_num, | ||
75 | unsigned int in_num, | ||
76 | void *data) | ||
77 | { | ||
78 | return virtqueue_add_buf_gfp(vq, sg, out_num, in_num, data, GFP_ATOMIC); | ||
79 | } | ||
74 | 80 | ||
75 | void (*disable_cb)(struct virtqueue *vq); | 81 | void virtqueue_kick(struct virtqueue *vq); |
76 | bool (*enable_cb)(struct virtqueue *vq); | 82 | |
77 | void *(*detach_unused_buf)(struct virtqueue *vq); | 83 | void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); |
78 | }; | 84 | |
85 | void virtqueue_disable_cb(struct virtqueue *vq); | ||
86 | |||
87 | bool virtqueue_enable_cb(struct virtqueue *vq); | ||
88 | |||
89 | void *virtqueue_detach_unused_buf(struct virtqueue *vq); | ||
79 | 90 | ||
80 | /** | 91 | /** |
81 | * virtio_device - representation of a device using virtio | 92 | * virtio_device - representation of a device using virtio |