diff options
Diffstat (limited to 'include/linux/virtio_config.h')
-rw-r--r-- | include/linux/virtio_config.h | 49 |
1 files changed, 39 insertions, 10 deletions
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 */ |