aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/virtio.h
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2007-10-21 21:03:36 -0400
committerRusty Russell <rusty@rustcorp.com.au>2007-10-23 01:49:54 -0400
commitec3d41c4db4c21164332826ea8d812f94f2f6886 (patch)
tree9b947e900745cfcc4df7409c6ba5583428964215 /include/linux/virtio.h
parent47436aa4ad054c1c7c8231618e86ebd9305308dc (diff)
Virtio interface
This attempts to implement a "virtual I/O" layer which should allow common drivers to be efficiently used across most virtual I/O mechanisms. It will no-doubt need further enhancement. The virtio drivers add buffers to virtio queues; as the buffers are consumed the driver "interrupt" callbacks are invoked. There is also a generic implementation of config space which drivers can query to get setup information from the host. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Dor Laor <dor.laor@qumranet.com> Cc: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'include/linux/virtio.h')
-rw-r--r--include/linux/virtio.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
new file mode 100644
index 000000000000..14e1379876d3
--- /dev/null
+++ b/include/linux/virtio.h
@@ -0,0 +1,110 @@
1#ifndef _LINUX_VIRTIO_H
2#define _LINUX_VIRTIO_H
3/* Everything a virtio driver needs to work with any particular virtio
4 * implementation. */
5#include <linux/types.h>
6#include <linux/scatterlist.h>
7#include <linux/spinlock.h>
8#include <linux/device.h>
9#include <linux/mod_devicetable.h>
10
11/**
12 * virtqueue - a queue to register buffers for sending or receiving.
13 * @callback: the function to call when buffers are consumed (can be NULL).
14 * If this returns false, callbacks are suppressed until vq_ops->restart
15 * is called.
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.
19 */
20struct virtqueue
21{
22 bool (*callback)(struct virtqueue *vq);
23 struct virtio_device *vdev;
24 struct virtqueue_ops *vq_ops;
25 void *priv;
26};
27
28/**
29 * virtqueue_ops - operations for virtqueue abstraction layer
30 * @add_buf: expose buffer to other end
31 * vq: the struct virtqueue we're talking about.
32 * sg: the description of the buffer(s).
33 * out_num: the number of sg readable by other side
34 * in_num: the number of sg which are writable (after readable ones)
35 * data: the token identifying the buffer.
36 * Returns 0 or an error.
37 * @kick: update after add_buf
38 * vq: the struct virtqueue
39 * After one or more add_buf calls, invoke this to kick the other side.
40 * @get_buf: get the next used buffer
41 * vq: the struct virtqueue we're talking about.
42 * len: the length written into the buffer
43 * Returns NULL or the "data" token handed to add_buf.
44 * @restart: restart callbacks after callback returned false.
45 * vq: the struct virtqueue we're talking about.
46 * This returns "false" (and doesn't re-enable) if there are pending
47 * buffers in the queue, to avoid a race.
48 * @shutdown: "unadd" all buffers.
49 * vq: the struct virtqueue we're talking about.
50 * Remove everything from the queue.
51 *
52 * Locking rules are straightforward: the driver is responsible for
53 * locking. No two operations may be invoked simultaneously.
54 *
55 * All operations can be called in any context.
56 */
57struct virtqueue_ops {
58 int (*add_buf)(struct virtqueue *vq,
59 struct scatterlist sg[],
60 unsigned int out_num,
61 unsigned int in_num,
62 void *data);
63
64 void (*kick)(struct virtqueue *vq);
65
66 void *(*get_buf)(struct virtqueue *vq, unsigned int *len);
67
68 bool (*restart)(struct virtqueue *vq);
69
70 void (*shutdown)(struct virtqueue *vq);
71};
72
73/**
74 * virtio_device - representation of a device using virtio
75 * @index: unique position on the virtio bus
76 * @dev: underlying device.
77 * @id: the device type identification (used to match it with a driver).
78 * @config: the configuration ops for this device.
79 * @priv: private pointer for the driver's use.
80 */
81struct virtio_device
82{
83 int index;
84 struct device dev;
85 struct virtio_device_id id;
86 struct virtio_config_ops *config;
87 void *priv;
88};
89
90int register_virtio_device(struct virtio_device *dev);
91void unregister_virtio_device(struct virtio_device *dev);
92
93/**
94 * virtio_driver - operations for a virtio I/O driver
95 * @driver: underlying device driver (populate name and owner).
96 * @id_table: the ids serviced by this driver.
97 * @probe: the function to call when a device is found. Returns a token for
98 * remove, or PTR_ERR().
99 * @remove: the function when a device is removed.
100 */
101struct virtio_driver {
102 struct device_driver driver;
103 const struct virtio_device_id *id_table;
104 int (*probe)(struct virtio_device *dev);
105 void (*remove)(struct virtio_device *dev);
106};
107
108int register_virtio_driver(struct virtio_driver *drv);
109void unregister_virtio_driver(struct virtio_driver *drv);
110#endif /* _LINUX_VIRTIO_H */