This source file includes following definitions.
- dev_to_virtio
- drv_to_virtio
1
2 #ifndef _LINUX_VIRTIO_H
3 #define _LINUX_VIRTIO_H
4
5
6 #include <linux/types.h>
7 #include <linux/scatterlist.h>
8 #include <linux/spinlock.h>
9 #include <linux/device.h>
10 #include <linux/mod_devicetable.h>
11 #include <linux/gfp.h>
12 #include <linux/vringh.h>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 struct virtqueue {
29 struct list_head list;
30 void (*callback)(struct virtqueue *vq);
31 const char *name;
32 struct virtio_device *vdev;
33 unsigned int index;
34 unsigned int num_free;
35 void *priv;
36 };
37
38 int virtqueue_add_outbuf(struct virtqueue *vq,
39 struct scatterlist sg[], unsigned int num,
40 void *data,
41 gfp_t gfp);
42
43 int virtqueue_add_inbuf(struct virtqueue *vq,
44 struct scatterlist sg[], unsigned int num,
45 void *data,
46 gfp_t gfp);
47
48 int virtqueue_add_inbuf_ctx(struct virtqueue *vq,
49 struct scatterlist sg[], unsigned int num,
50 void *data,
51 void *ctx,
52 gfp_t gfp);
53
54 int virtqueue_add_sgs(struct virtqueue *vq,
55 struct scatterlist *sgs[],
56 unsigned int out_sgs,
57 unsigned int in_sgs,
58 void *data,
59 gfp_t gfp);
60
61 bool virtqueue_kick(struct virtqueue *vq);
62
63 bool virtqueue_kick_prepare(struct virtqueue *vq);
64
65 bool virtqueue_notify(struct virtqueue *vq);
66
67 void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
68
69 void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len,
70 void **ctx);
71
72 void virtqueue_disable_cb(struct virtqueue *vq);
73
74 bool virtqueue_enable_cb(struct virtqueue *vq);
75
76 unsigned virtqueue_enable_cb_prepare(struct virtqueue *vq);
77
78 bool virtqueue_poll(struct virtqueue *vq, unsigned);
79
80 bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
81
82 void *virtqueue_detach_unused_buf(struct virtqueue *vq);
83
84 unsigned int virtqueue_get_vring_size(struct virtqueue *vq);
85
86 bool virtqueue_is_broken(struct virtqueue *vq);
87
88 const struct vring *virtqueue_get_vring(struct virtqueue *vq);
89 dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq);
90 dma_addr_t virtqueue_get_avail_addr(struct virtqueue *vq);
91 dma_addr_t virtqueue_get_used_addr(struct virtqueue *vq);
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 struct virtio_device {
109 int index;
110 bool failed;
111 bool config_enabled;
112 bool config_change_pending;
113 spinlock_t config_lock;
114 struct device dev;
115 struct virtio_device_id id;
116 const struct virtio_config_ops *config;
117 const struct vringh_config_ops *vringh_config;
118 struct list_head vqs;
119 u64 features;
120 void *priv;
121 };
122
123 static inline struct virtio_device *dev_to_virtio(struct device *_dev)
124 {
125 return container_of(_dev, struct virtio_device, dev);
126 }
127
128 void virtio_add_status(struct virtio_device *dev, unsigned int status);
129 int register_virtio_device(struct virtio_device *dev);
130 void unregister_virtio_device(struct virtio_device *dev);
131
132 void virtio_break_device(struct virtio_device *dev);
133
134 void virtio_config_changed(struct virtio_device *dev);
135 void virtio_config_disable(struct virtio_device *dev);
136 void virtio_config_enable(struct virtio_device *dev);
137 int virtio_finalize_features(struct virtio_device *dev);
138 #ifdef CONFIG_PM_SLEEP
139 int virtio_device_freeze(struct virtio_device *dev);
140 int virtio_device_restore(struct virtio_device *dev);
141 #endif
142
143 size_t virtio_max_dma_size(struct virtio_device *vdev);
144
145 #define virtio_device_for_each_vq(vdev, vq) \
146 list_for_each_entry(vq, &vdev->vqs, list)
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165 struct virtio_driver {
166 struct device_driver driver;
167 const struct virtio_device_id *id_table;
168 const unsigned int *feature_table;
169 unsigned int feature_table_size;
170 const unsigned int *feature_table_legacy;
171 unsigned int feature_table_size_legacy;
172 int (*validate)(struct virtio_device *dev);
173 int (*probe)(struct virtio_device *dev);
174 void (*scan)(struct virtio_device *dev);
175 void (*remove)(struct virtio_device *dev);
176 void (*config_changed)(struct virtio_device *dev);
177 #ifdef CONFIG_PM
178 int (*freeze)(struct virtio_device *dev);
179 int (*restore)(struct virtio_device *dev);
180 #endif
181 };
182
183 static inline struct virtio_driver *drv_to_virtio(struct device_driver *drv)
184 {
185 return container_of(drv, struct virtio_driver, driver);
186 }
187
188 int register_virtio_driver(struct virtio_driver *drv);
189 void unregister_virtio_driver(struct virtio_driver *drv);
190
191
192
193
194
195
196 #define module_virtio_driver(__virtio_driver) \
197 module_driver(__virtio_driver, register_virtio_driver, \
198 unregister_virtio_driver)
199 #endif