diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-12 12:31:52 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-06-12 12:31:52 -0400 |
commit | 16ffc3eeaa00d513b0076b7b2b96419f28acc912 (patch) | |
tree | 82503d25fb9091fc6628961d953ffc0d305adf27 /include/linux | |
parent | c34752bc8b3196aee3115d1aa41972604ab0aea8 (diff) | |
parent | e3353853730eb99c56b7b0aed1667d51c0e3699a (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-virtio
* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-virtio:
virtio: enhance id_matching for virtio drivers
virtio: fix id_matching for virtio drivers
virtio: handle short buffers in virtio_rng.
virtio_blk: add missing __dev{init,exit} markings
virtio: indirect ring entries (VIRTIO_RING_F_INDIRECT_DESC)
virtio: teach virtio_has_feature() about transport features
virtio: expose features in sysfs
virtio_pci: optional MSI-X support
virtio_pci: split up vp_interrupt
virtio: find_vqs/del_vqs virtio operations
virtio: add names to virtqueue struct, mapping from devices to queues.
virtio: meet virtio spec by finalizing features before using device
virtio: fix obsolete documentation on probe function
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/virtio.h | 15 | ||||
-rw-r--r-- | include/linux/virtio_config.h | 49 | ||||
-rw-r--r-- | include/linux/virtio_pci.h | 10 | ||||
-rw-r--r-- | include/linux/virtio_ring.h | 8 |
4 files changed, 64 insertions, 18 deletions
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 06005fa9e982..4fca4f5440ba 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h | |||
@@ -10,14 +10,17 @@ | |||
10 | 10 | ||
11 | /** | 11 | /** |
12 | * virtqueue - a queue to register buffers for sending or receiving. | 12 | * virtqueue - a queue to register buffers for sending or receiving. |
13 | * @list: the chain of virtqueues for this device | ||
13 | * @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) | ||
14 | * @vdev: the virtio device this queue was created for. | 16 | * @vdev: the virtio device this queue was created for. |
15 | * @vq_ops: the operations for this virtqueue (see below). | 17 | * @vq_ops: the operations for this virtqueue (see below). |
16 | * @priv: a pointer for the virtqueue implementation to use. | 18 | * @priv: a pointer for the virtqueue implementation to use. |
17 | */ | 19 | */ |
18 | struct virtqueue | 20 | struct virtqueue { |
19 | { | 21 | struct list_head list; |
20 | void (*callback)(struct virtqueue *vq); | 22 | void (*callback)(struct virtqueue *vq); |
23 | const char *name; | ||
21 | struct virtio_device *vdev; | 24 | struct virtio_device *vdev; |
22 | struct virtqueue_ops *vq_ops; | 25 | struct virtqueue_ops *vq_ops; |
23 | void *priv; | 26 | void *priv; |
@@ -76,15 +79,16 @@ struct virtqueue_ops { | |||
76 | * @dev: underlying device. | 79 | * @dev: underlying device. |
77 | * @id: the device type identification (used to match it with a driver). | 80 | * @id: the device type identification (used to match it with a driver). |
78 | * @config: the configuration ops for this device. | 81 | * @config: the configuration ops for this device. |
82 | * @vqs: the list of virtqueues for this device. | ||
79 | * @features: the features supported by both driver and device. | 83 | * @features: the features supported by both driver and device. |
80 | * @priv: private pointer for the driver's use. | 84 | * @priv: private pointer for the driver's use. |
81 | */ | 85 | */ |
82 | struct virtio_device | 86 | struct virtio_device { |
83 | { | ||
84 | int index; | 87 | int index; |
85 | struct device dev; | 88 | struct device dev; |
86 | struct virtio_device_id id; | 89 | struct virtio_device_id id; |
87 | struct virtio_config_ops *config; | 90 | struct virtio_config_ops *config; |
91 | struct list_head vqs; | ||
88 | /* Note that this is a Linux set_bit-style bitmap. */ | 92 | /* Note that this is a Linux set_bit-style bitmap. */ |
89 | unsigned long features[1]; | 93 | unsigned long features[1]; |
90 | void *priv; | 94 | void *priv; |
@@ -99,8 +103,7 @@ void unregister_virtio_device(struct virtio_device *dev); | |||
99 | * @id_table: the ids serviced by this driver. | 103 | * @id_table: the ids serviced by this driver. |
100 | * @feature_table: an array of feature numbers supported by this device. | 104 | * @feature_table: an array of feature numbers supported by this device. |
101 | * @feature_table_size: number of entries in the feature table array. | 105 | * @feature_table_size: number of entries in the feature table array. |
102 | * @probe: the function to call when a device is found. Returns a token for | 106 | * @probe: the function to call when a device is found. Returns 0 or -errno. |
103 | * remove, or PTR_ERR(). | ||
104 | * @remove: the function when a device is removed. | 107 | * @remove: the function when a device is removed. |
105 | * @config_changed: optional function to call when the device configuration | 108 | * @config_changed: optional function to call when the device configuration |
106 | * changes; may be called in interrupt context. | 109 | * changes; may be called in interrupt context. |
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h index bf8ec283b232..99f514575f6a 100644 --- a/include/linux/virtio_config.h +++ b/include/linux/virtio_config.h | |||
@@ -29,6 +29,7 @@ | |||
29 | #define VIRTIO_F_NOTIFY_ON_EMPTY 24 | 29 | #define VIRTIO_F_NOTIFY_ON_EMPTY 24 |
30 | 30 | ||
31 | #ifdef __KERNEL__ | 31 | #ifdef __KERNEL__ |
32 | #include <linux/err.h> | ||
32 | #include <linux/virtio.h> | 33 | #include <linux/virtio.h> |
33 | 34 | ||
34 | /** | 35 | /** |
@@ -49,15 +50,26 @@ | |||
49 | * @set_status: write the status byte | 50 | * @set_status: write the status byte |
50 | * vdev: the virtio_device | 51 | * vdev: the virtio_device |
51 | * status: the new status byte | 52 | * status: the new status byte |
53 | * @request_vqs: request the specified number of virtqueues | ||
54 | * vdev: the virtio_device | ||
55 | * max_vqs: the max number of virtqueues we want | ||
56 | * If supplied, must call before any virtqueues are instantiated. | ||
57 | * To modify the max number of virtqueues after request_vqs has been | ||
58 | * called, call free_vqs and then request_vqs with a new value. | ||
59 | * @free_vqs: cleanup resources allocated by request_vqs | ||
60 | * vdev: the virtio_device | ||
61 | * If supplied, must call after all virtqueues have been deleted. | ||
52 | * @reset: reset the device | 62 | * @reset: reset the device |
53 | * vdev: the virtio device | 63 | * vdev: the virtio device |
54 | * After this, status and feature negotiation must be done again | 64 | * After this, status and feature negotiation must be done again |
55 | * @find_vq: find a virtqueue and instantiate it. | 65 | * @find_vqs: find virtqueues and instantiate them. |
56 | * vdev: the virtio_device | 66 | * vdev: the virtio_device |
57 | * index: the 0-based virtqueue number in case there's more than one. | 67 | * nvqs: the number of virtqueues to find |
58 | * callback: the virqtueue callback | 68 | * vqs: on success, includes new virtqueues |
59 | * Returns the new virtqueue or ERR_PTR() (eg. -ENOENT). | 69 | * callbacks: array of callbacks, for each virtqueue |
60 | * @del_vq: free a virtqueue found by find_vq(). | 70 | * names: array of virtqueue names (mainly for debugging) |
71 | * Returns 0 on success or error status | ||
72 | * @del_vqs: free virtqueues found by find_vqs(). | ||
61 | * @get_features: get the array of feature bits for this device. | 73 | * @get_features: get the array of feature bits for this device. |
62 | * vdev: the virtio_device | 74 | * vdev: the virtio_device |
63 | * Returns the first 32 feature bits (all we currently need). | 75 | * Returns the first 32 feature bits (all we currently need). |
@@ -66,6 +78,7 @@ | |||
66 | * This gives the final feature bits for the device: it can change | 78 | * This gives the final feature bits for the device: it can change |
67 | * the dev->feature bits if it wants. | 79 | * the dev->feature bits if it wants. |
68 | */ | 80 | */ |
81 | typedef void vq_callback_t(struct virtqueue *); | ||
69 | struct virtio_config_ops | 82 | struct virtio_config_ops |
70 | { | 83 | { |
71 | void (*get)(struct virtio_device *vdev, unsigned offset, | 84 | void (*get)(struct virtio_device *vdev, unsigned offset, |
@@ -75,10 +88,11 @@ struct virtio_config_ops | |||
75 | u8 (*get_status)(struct virtio_device *vdev); | 88 | u8 (*get_status)(struct virtio_device *vdev); |
76 | void (*set_status)(struct virtio_device *vdev, u8 status); | 89 | void (*set_status)(struct virtio_device *vdev, u8 status); |
77 | void (*reset)(struct virtio_device *vdev); | 90 | void (*reset)(struct virtio_device *vdev); |
78 | struct virtqueue *(*find_vq)(struct virtio_device *vdev, | 91 | int (*find_vqs)(struct virtio_device *, unsigned nvqs, |
79 | unsigned index, | 92 | struct virtqueue *vqs[], |
80 | void (*callback)(struct virtqueue *)); | 93 | vq_callback_t *callbacks[], |
81 | void (*del_vq)(struct virtqueue *vq); | 94 | const char *names[]); |
95 | void (*del_vqs)(struct virtio_device *); | ||
82 | u32 (*get_features)(struct virtio_device *vdev); | 96 | u32 (*get_features)(struct virtio_device *vdev); |
83 | void (*finalize_features)(struct virtio_device *vdev); | 97 | void (*finalize_features)(struct virtio_device *vdev); |
84 | }; | 98 | }; |
@@ -99,7 +113,9 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev, | |||
99 | if (__builtin_constant_p(fbit)) | 113 | if (__builtin_constant_p(fbit)) |
100 | BUILD_BUG_ON(fbit >= 32); | 114 | BUILD_BUG_ON(fbit >= 32); |
101 | 115 | ||
102 | virtio_check_driver_offered_feature(vdev, fbit); | 116 | if (fbit < VIRTIO_TRANSPORT_F_START) |
117 | virtio_check_driver_offered_feature(vdev, fbit); | ||
118 | |||
103 | return test_bit(fbit, vdev->features); | 119 | return test_bit(fbit, vdev->features); |
104 | } | 120 | } |
105 | 121 | ||
@@ -126,5 +142,18 @@ static inline int virtio_config_buf(struct virtio_device *vdev, | |||
126 | vdev->config->get(vdev, offset, buf, len); | 142 | vdev->config->get(vdev, offset, buf, len); |
127 | return 0; | 143 | return 0; |
128 | } | 144 | } |
145 | |||
146 | static inline | ||
147 | struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev, | ||
148 | vq_callback_t *c, const char *n) | ||
149 | { | ||
150 | vq_callback_t *callbacks[] = { c }; | ||
151 | const char *names[] = { n }; | ||
152 | struct virtqueue *vq; | ||
153 | int err = vdev->config->find_vqs(vdev, 1, &vq, callbacks, names); | ||
154 | if (err < 0) | ||
155 | return ERR_PTR(err); | ||
156 | return vq; | ||
157 | } | ||
129 | #endif /* __KERNEL__ */ | 158 | #endif /* __KERNEL__ */ |
130 | #endif /* _LINUX_VIRTIO_CONFIG_H */ | 159 | #endif /* _LINUX_VIRTIO_CONFIG_H */ |
diff --git a/include/linux/virtio_pci.h b/include/linux/virtio_pci.h index cd0fd5d181a6..9a3d7c48c622 100644 --- a/include/linux/virtio_pci.h +++ b/include/linux/virtio_pci.h | |||
@@ -47,9 +47,17 @@ | |||
47 | /* The bit of the ISR which indicates a device configuration change. */ | 47 | /* The bit of the ISR which indicates a device configuration change. */ |
48 | #define VIRTIO_PCI_ISR_CONFIG 0x2 | 48 | #define VIRTIO_PCI_ISR_CONFIG 0x2 |
49 | 49 | ||
50 | /* MSI-X registers: only enabled if MSI-X is enabled. */ | ||
51 | /* A 16-bit vector for configuration changes. */ | ||
52 | #define VIRTIO_MSI_CONFIG_VECTOR 20 | ||
53 | /* A 16-bit vector for selected queue notifications. */ | ||
54 | #define VIRTIO_MSI_QUEUE_VECTOR 22 | ||
55 | /* Vector value used to disable MSI for queue */ | ||
56 | #define VIRTIO_MSI_NO_VECTOR 0xffff | ||
57 | |||
50 | /* The remaining space is defined by each driver as the per-driver | 58 | /* The remaining space is defined by each driver as the per-driver |
51 | * configuration space */ | 59 | * configuration space */ |
52 | #define VIRTIO_PCI_CONFIG 20 | 60 | #define VIRTIO_PCI_CONFIG(dev) ((dev)->msix_enabled ? 24 : 20) |
53 | 61 | ||
54 | /* Virtio ABI version, this must match exactly */ | 62 | /* Virtio ABI version, this must match exactly */ |
55 | #define VIRTIO_PCI_ABI_VERSION 0 | 63 | #define VIRTIO_PCI_ABI_VERSION 0 |
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index 71e03722fb59..693e0ec5afa6 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h | |||
@@ -14,6 +14,8 @@ | |||
14 | #define VRING_DESC_F_NEXT 1 | 14 | #define VRING_DESC_F_NEXT 1 |
15 | /* This marks a buffer as write-only (otherwise read-only). */ | 15 | /* This marks a buffer as write-only (otherwise read-only). */ |
16 | #define VRING_DESC_F_WRITE 2 | 16 | #define VRING_DESC_F_WRITE 2 |
17 | /* This means the buffer contains a list of buffer descriptors. */ | ||
18 | #define VRING_DESC_F_INDIRECT 4 | ||
17 | 19 | ||
18 | /* The Host uses this in used->flags to advise the Guest: don't kick me when | 20 | /* The Host uses this in used->flags to advise the Guest: don't kick me when |
19 | * you add a buffer. It's unreliable, so it's simply an optimization. Guest | 21 | * you add a buffer. It's unreliable, so it's simply an optimization. Guest |
@@ -24,6 +26,9 @@ | |||
24 | * optimization. */ | 26 | * optimization. */ |
25 | #define VRING_AVAIL_F_NO_INTERRUPT 1 | 27 | #define VRING_AVAIL_F_NO_INTERRUPT 1 |
26 | 28 | ||
29 | /* We support indirect buffer descriptors */ | ||
30 | #define VIRTIO_RING_F_INDIRECT_DESC 28 | ||
31 | |||
27 | /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ | 32 | /* Virtio ring descriptors: 16 bytes. These can chain together via "next". */ |
28 | struct vring_desc | 33 | struct vring_desc |
29 | { | 34 | { |
@@ -119,7 +124,8 @@ struct virtqueue *vring_new_virtqueue(unsigned int num, | |||
119 | struct virtio_device *vdev, | 124 | struct virtio_device *vdev, |
120 | void *pages, | 125 | void *pages, |
121 | void (*notify)(struct virtqueue *vq), | 126 | void (*notify)(struct virtqueue *vq), |
122 | void (*callback)(struct virtqueue *vq)); | 127 | void (*callback)(struct virtqueue *vq), |
128 | const char *name); | ||
123 | void vring_del_virtqueue(struct virtqueue *vq); | 129 | void vring_del_virtqueue(struct virtqueue *vq); |
124 | /* Filter out transport-specific feature bits. */ | 130 | /* Filter out transport-specific feature bits. */ |
125 | void vring_transport_features(struct virtio_device *vdev); | 131 | void vring_transport_features(struct virtio_device *vdev); |