aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/virtio_config.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/virtio_config.h')
-rw-r--r--include/linux/virtio_config.h161
1 files changed, 134 insertions, 27 deletions
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 29b9104232b4..e8f8f71e843c 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -96,33 +96,6 @@ static inline bool virtio_has_feature(const struct virtio_device *vdev,
96 return test_bit(fbit, vdev->features); 96 return test_bit(fbit, vdev->features);
97} 97}
98 98
99/**
100 * virtio_config_val - look for a feature and get a virtio config entry.
101 * @vdev: the virtio device
102 * @fbit: the feature bit
103 * @offset: the type to search for.
104 * @v: a pointer to the value to fill in.
105 *
106 * The return value is -ENOENT if the feature doesn't exist. Otherwise
107 * the config value is copied into whatever is pointed to by v. */
108#define virtio_config_val(vdev, fbit, offset, v) \
109 virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(*v))
110
111#define virtio_config_val_len(vdev, fbit, offset, v, len) \
112 virtio_config_buf((vdev), (fbit), (offset), (v), (len))
113
114static inline int virtio_config_buf(struct virtio_device *vdev,
115 unsigned int fbit,
116 unsigned int offset,
117 void *buf, unsigned len)
118{
119 if (!virtio_has_feature(vdev, fbit))
120 return -ENOENT;
121
122 vdev->config->get(vdev, offset, buf, len);
123 return 0;
124}
125
126static inline 99static inline
127struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev, 100struct virtqueue *virtio_find_single_vq(struct virtio_device *vdev,
128 vq_callback_t *c, const char *n) 101 vq_callback_t *c, const char *n)
@@ -162,5 +135,139 @@ int virtqueue_set_affinity(struct virtqueue *vq, int cpu)
162 return 0; 135 return 0;
163} 136}
164 137
138/* Config space accessors. */
139#define virtio_cread(vdev, structname, member, ptr) \
140 do { \
141 /* Must match the member's type, and be integer */ \
142 if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
143 (*ptr) = 1; \
144 \
145 switch (sizeof(*ptr)) { \
146 case 1: \
147 *(ptr) = virtio_cread8(vdev, \
148 offsetof(structname, member)); \
149 break; \
150 case 2: \
151 *(ptr) = virtio_cread16(vdev, \
152 offsetof(structname, member)); \
153 break; \
154 case 4: \
155 *(ptr) = virtio_cread32(vdev, \
156 offsetof(structname, member)); \
157 break; \
158 case 8: \
159 *(ptr) = virtio_cread64(vdev, \
160 offsetof(structname, member)); \
161 break; \
162 default: \
163 BUG(); \
164 } \
165 } while(0)
166
167/* Config space accessors. */
168#define virtio_cwrite(vdev, structname, member, ptr) \
169 do { \
170 /* Must match the member's type, and be integer */ \
171 if (!typecheck(typeof((((structname*)0)->member)), *(ptr))) \
172 BUG_ON((*ptr) == 1); \
173 \
174 switch (sizeof(*ptr)) { \
175 case 1: \
176 virtio_cwrite8(vdev, \
177 offsetof(structname, member), \
178 *(ptr)); \
179 break; \
180 case 2: \
181 virtio_cwrite16(vdev, \
182 offsetof(structname, member), \
183 *(ptr)); \
184 break; \
185 case 4: \
186 virtio_cwrite32(vdev, \
187 offsetof(structname, member), \
188 *(ptr)); \
189 break; \
190 case 8: \
191 virtio_cwrite64(vdev, \
192 offsetof(structname, member), \
193 *(ptr)); \
194 break; \
195 default: \
196 BUG(); \
197 } \
198 } while(0)
199
200static inline u8 virtio_cread8(struct virtio_device *vdev, unsigned int offset)
201{
202 u8 ret;
203 vdev->config->get(vdev, offset, &ret, sizeof(ret));
204 return ret;
205}
206
207static inline void virtio_cread_bytes(struct virtio_device *vdev,
208 unsigned int offset,
209 void *buf, size_t len)
210{
211 vdev->config->get(vdev, offset, buf, len);
212}
213
214static inline void virtio_cwrite8(struct virtio_device *vdev,
215 unsigned int offset, u8 val)
216{
217 vdev->config->set(vdev, offset, &val, sizeof(val));
218}
219
220static inline u16 virtio_cread16(struct virtio_device *vdev,
221 unsigned int offset)
222{
223 u16 ret;
224 vdev->config->get(vdev, offset, &ret, sizeof(ret));
225 return ret;
226}
227
228static inline void virtio_cwrite16(struct virtio_device *vdev,
229 unsigned int offset, u16 val)
230{
231 vdev->config->set(vdev, offset, &val, sizeof(val));
232}
233
234static inline u32 virtio_cread32(struct virtio_device *vdev,
235 unsigned int offset)
236{
237 u32 ret;
238 vdev->config->get(vdev, offset, &ret, sizeof(ret));
239 return ret;
240}
241
242static inline void virtio_cwrite32(struct virtio_device *vdev,
243 unsigned int offset, u32 val)
244{
245 vdev->config->set(vdev, offset, &val, sizeof(val));
246}
247
248static inline u64 virtio_cread64(struct virtio_device *vdev,
249 unsigned int offset)
250{
251 u64 ret;
252 vdev->config->get(vdev, offset, &ret, sizeof(ret));
253 return ret;
254}
255
256static inline void virtio_cwrite64(struct virtio_device *vdev,
257 unsigned int offset, u64 val)
258{
259 vdev->config->set(vdev, offset, &val, sizeof(val));
260}
261
262/* Conditional config space accessors. */
263#define virtio_cread_feature(vdev, fbit, structname, member, ptr) \
264 ({ \
265 int _r = 0; \
266 if (!virtio_has_feature(vdev, fbit)) \
267 _r = -ENOENT; \
268 else \
269 virtio_cread((vdev), structname, member, ptr); \
270 _r; \
271 })
165 272
166#endif /* _LINUX_VIRTIO_CONFIG_H */ 273#endif /* _LINUX_VIRTIO_CONFIG_H */