aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-05-21 20:22:52 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-05-21 20:22:52 -0400
commit1756ac3d3c41341297ea25b818b7fce505bb2a9a (patch)
tree96382220afbb82fd5c576c4c08b3c3e13282851f /include
parent98edb6ca4174f17a64890a02f44c211c8b44fb3c (diff)
parent0643e4c6e4fd67778fa886a89e6ec2320e0ff4d3 (diff)
Merge branch 'virtio' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
* 'virtio' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus: (27 commits) drivers/char: Eliminate use after free virtio: console: Accept console size along with resize control message virtio: console: Store each console's size in the console structure virtio: console: Resize console port 0 on config intr only if multiport is off virtio: console: Add support for nonblocking write()s virtio: console: Rename wait_is_over() to will_read_block() virtio: console: Don't always create a port 0 if using multiport virtio: console: Use a control message to add ports virtio: console: Move code around for future patches virtio: console: Remove config work handler virtio: console: Don't call hvc_remove() on unplugging console ports virtio: console: Return -EPIPE to hvc_console if we lost the connection virtio: console: Let host know of port or device add failures virtio: console: Add a __send_control_msg() that can send messages without a valid port virtio: Revert "virtio: disable multiport console support." virtio: add_buf_gfp trans_virtio: use virtqueue_xxx wrappers virtio-rng: use virtqueue_xxx wrappers virtio_ring: remove a level of indirection virtio_net: use virtqueue_xxx wrappers ... Fix up conflicts in drivers/net/virtio_net.c due to new virtqueue_xxx wrappers changes conflicting with some other cleanups.
Diffstat (limited to 'include')
-rw-r--r--include/linux/virtio.h55
-rw-r--r--include/linux/virtio_blk.h5
-rw-r--r--include/linux/virtio_console.h25
3 files changed, 63 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 */
20struct virtqueue { 20struct 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 */
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 64
71 void (*kick)(struct virtqueue *vq); 65int 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); 72static 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); 81void virtqueue_kick(struct virtqueue *vq);
76 bool (*enable_cb)(struct virtqueue *vq); 82
77 void *(*detach_unused_buf)(struct virtqueue *vq); 83void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
78}; 84
85void virtqueue_disable_cb(struct virtqueue *vq);
86
87bool virtqueue_enable_cb(struct virtqueue *vq);
88
89void *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
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h
index e52029e98919..167720d695ed 100644
--- a/include/linux/virtio_blk.h
+++ b/include/linux/virtio_blk.h
@@ -17,6 +17,8 @@
17#define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */ 17#define VIRTIO_BLK_F_FLUSH 9 /* Cache flush command support */
18#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */ 18#define VIRTIO_BLK_F_TOPOLOGY 10 /* Topology information is available */
19 19
20#define VIRTIO_BLK_ID_BYTES 20 /* ID string length */
21
20struct virtio_blk_config { 22struct virtio_blk_config {
21 /* The capacity (in 512-byte sectors). */ 23 /* The capacity (in 512-byte sectors). */
22 __u64 capacity; 24 __u64 capacity;
@@ -67,6 +69,9 @@ struct virtio_blk_config {
67/* Cache flush command */ 69/* Cache flush command */
68#define VIRTIO_BLK_T_FLUSH 4 70#define VIRTIO_BLK_T_FLUSH 4
69 71
72/* Get device ID command */
73#define VIRTIO_BLK_T_GET_ID 8
74
70/* Barrier before this op. */ 75/* Barrier before this op. */
71#define VIRTIO_BLK_T_BARRIER 0x80000000 76#define VIRTIO_BLK_T_BARRIER 0x80000000
72 77
diff --git a/include/linux/virtio_console.h b/include/linux/virtio_console.h
index 92228a8fbcbc..a85064db8f94 100644
--- a/include/linux/virtio_console.h
+++ b/include/linux/virtio_console.h
@@ -12,14 +12,39 @@
12 12
13/* Feature bits */ 13/* Feature bits */
14#define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */ 14#define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */
15#define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */
16
17#define VIRTIO_CONSOLE_BAD_ID (~(u32)0)
15 18
16struct virtio_console_config { 19struct virtio_console_config {
17 /* colums of the screens */ 20 /* colums of the screens */
18 __u16 cols; 21 __u16 cols;
19 /* rows of the screens */ 22 /* rows of the screens */
20 __u16 rows; 23 __u16 rows;
24 /* max. number of ports this device can hold */
25 __u32 max_nr_ports;
21} __attribute__((packed)); 26} __attribute__((packed));
22 27
28/*
29 * A message that's passed between the Host and the Guest for a
30 * particular port.
31 */
32struct virtio_console_control {
33 __u32 id; /* Port number */
34 __u16 event; /* The kind of control event (see below) */
35 __u16 value; /* Extra information for the key */
36};
37
38/* Some events for control messages */
39#define VIRTIO_CONSOLE_DEVICE_READY 0
40#define VIRTIO_CONSOLE_PORT_ADD 1
41#define VIRTIO_CONSOLE_PORT_REMOVE 2
42#define VIRTIO_CONSOLE_PORT_READY 3
43#define VIRTIO_CONSOLE_CONSOLE_PORT 4
44#define VIRTIO_CONSOLE_RESIZE 5
45#define VIRTIO_CONSOLE_PORT_OPEN 6
46#define VIRTIO_CONSOLE_PORT_NAME 7
47
23#ifdef __KERNEL__ 48#ifdef __KERNEL__
24int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)); 49int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int));
25#endif /* __KERNEL__ */ 50#endif /* __KERNEL__ */