Blame view
include/linux/virtio.h
7.13 KB
b24413180 License cleanup: ... |
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
ec3d41c4d Virtio interface |
2 3 4 5 6 7 8 9 10 |
#ifndef _LINUX_VIRTIO_H #define _LINUX_VIRTIO_H /* Everything a virtio driver needs to work with any particular virtio * implementation. */ #include <linux/types.h> #include <linux/scatterlist.h> #include <linux/spinlock.h> #include <linux/device.h> #include <linux/mod_devicetable.h> |
bbd603efb virtio: add_buf_gfp |
11 |
#include <linux/gfp.h> |
3beee86a4 virtio: Introduce... |
12 |
#include <linux/vringh.h> |
ec3d41c4d Virtio interface |
13 14 15 |
/** * virtqueue - a queue to register buffers for sending or receiving. |
9499f5e7e virtio: add names... |
16 |
* @list: the chain of virtqueues for this device |
ec3d41c4d Virtio interface |
17 |
* @callback: the function to call when buffers are consumed (can be NULL). |
9499f5e7e virtio: add names... |
18 |
* @name: the name of this virtqueue (mainly for debugging) |
ec3d41c4d Virtio interface |
19 |
* @vdev: the virtio device this queue was created for. |
ec3d41c4d Virtio interface |
20 |
* @priv: a pointer for the virtqueue implementation to use. |
06ca287db virtio: move queu... |
21 22 23 24 25 26 |
* @index: the zero-based ordinal number for this queue. * @num_free: number of elements we expect to be able to fit. * * A note on @num_free: with indirect buffers, each buffer needs one * element in the queue, otherwise a buffer will need one element per * sg element. |
ec3d41c4d Virtio interface |
27 |
*/ |
9499f5e7e virtio: add names... |
28 29 |
struct virtqueue { struct list_head list; |
18445c4d5 virtio: explicit ... |
30 |
void (*callback)(struct virtqueue *vq); |
9499f5e7e virtio: add names... |
31 |
const char *name; |
ec3d41c4d Virtio interface |
32 |
struct virtio_device *vdev; |
06ca287db virtio: move queu... |
33 34 |
unsigned int index; unsigned int num_free; |
ec3d41c4d Virtio interface |
35 36 |
void *priv; }; |
282edb364 virtio_ring: virt... |
37 38 39 40 41 42 43 44 45 |
int virtqueue_add_outbuf(struct virtqueue *vq, struct scatterlist sg[], unsigned int num, void *data, gfp_t gfp); int virtqueue_add_inbuf(struct virtqueue *vq, struct scatterlist sg[], unsigned int num, void *data, gfp_t gfp); |
5a08b04f6 virtio: allow ext... |
46 47 48 49 50 |
int virtqueue_add_inbuf_ctx(struct virtqueue *vq, struct scatterlist sg[], unsigned int num, void *data, void *ctx, gfp_t gfp); |
13816c768 virtio_ring: virt... |
51 52 53 54 55 56 |
int virtqueue_add_sgs(struct virtqueue *vq, struct scatterlist *sgs[], unsigned int out_sgs, unsigned int in_sgs, void *data, gfp_t gfp); |
5b1bf7cb6 virtio_ring: let ... |
57 |
bool virtqueue_kick(struct virtqueue *vq); |
ec3d41c4d Virtio interface |
58 |
|
41f0377f7 virtio: support u... |
59 |
bool virtqueue_kick_prepare(struct virtqueue *vq); |
5b1bf7cb6 virtio_ring: let ... |
60 |
bool virtqueue_notify(struct virtqueue *vq); |
41f0377f7 virtio: support u... |
61 |
|
7c5e9ed0c virtio_ring: remo... |
62 |
void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); |
316f25f5b virtio: add virtq... |
63 |
|
5a08b04f6 virtio: allow ext... |
64 65 |
void *virtqueue_get_buf_ctx(struct virtqueue *vq, unsigned int *len, void **ctx); |
7c5e9ed0c virtio_ring: remo... |
66 |
void virtqueue_disable_cb(struct virtqueue *vq); |
316f25f5b virtio: add virtq... |
67 |
|
7c5e9ed0c virtio_ring: remo... |
68 |
bool virtqueue_enable_cb(struct virtqueue *vq); |
316f25f5b virtio: add virtq... |
69 |
|
cc229884d virtio: support u... |
70 71 72 |
unsigned virtqueue_enable_cb_prepare(struct virtqueue *vq); bool virtqueue_poll(struct virtqueue *vq, unsigned); |
7ab358c23 virtio: add api f... |
73 |
bool virtqueue_enable_cb_delayed(struct virtqueue *vq); |
7c5e9ed0c virtio_ring: remo... |
74 |
void *virtqueue_detach_unused_buf(struct virtqueue *vq); |
316f25f5b virtio: add virtq... |
75 |
|
8f9f4668b Add ethtool -g su... |
76 |
unsigned int virtqueue_get_vring_size(struct virtqueue *vq); |
17bb6d408 virtio-ring: move... |
77 |
|
b3b32c941 virtio_ring: add ... |
78 |
bool virtqueue_is_broken(struct virtqueue *vq); |
2a2d1382f virtio: Add impro... |
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
const struct vring *virtqueue_get_vring(struct virtqueue *vq); dma_addr_t virtqueue_get_desc_addr(struct virtqueue *vq); dma_addr_t virtqueue_get_avail_addr(struct virtqueue *vq); dma_addr_t virtqueue_get_used_addr(struct virtqueue *vq); /* * Legacy accessors -- in almost all cases, these are the wrong functions * to use. */ static inline void *virtqueue_get_desc(struct virtqueue *vq) { return virtqueue_get_vring(vq)->desc; } static inline void *virtqueue_get_avail(struct virtqueue *vq) { return virtqueue_get_vring(vq)->avail; } static inline void *virtqueue_get_used(struct virtqueue *vq) { return virtqueue_get_vring(vq)->used; } |
890626521 virtio: allow tra... |
100 |
|
ec3d41c4d Virtio interface |
101 102 103 |
/** * virtio_device - representation of a device using virtio * @index: unique position on the virtio bus |
cbd7f8d68 virtio: Fix comme... |
104 |
* @failed: saved value for VIRTIO_CONFIG_S_FAILED bit (for restore) |
22b7050a0 virtio: defer con... |
105 106 107 |
* @config_enabled: configuration change reporting enabled * @config_change_pending: configuration change reported while disabled * @config_lock: protects configuration change reporting |
ec3d41c4d Virtio interface |
108 109 110 |
* @dev: underlying device. * @id: the device type identification (used to match it with a driver). * @config: the configuration ops for this device. |
3beee86a4 virtio: Introduce... |
111 |
* @vringh_config: configuration ops for host vrings. |
9499f5e7e virtio: add names... |
112 |
* @vqs: the list of virtqueues for this device. |
c45a6816c virtio: explicit ... |
113 |
* @features: the features supported by both driver and device. |
ec3d41c4d Virtio interface |
114 115 |
* @priv: private pointer for the driver's use. */ |
9499f5e7e virtio: add names... |
116 |
struct virtio_device { |
ec3d41c4d Virtio interface |
117 |
int index; |
c6716bae5 virtio-pci: move ... |
118 |
bool failed; |
22b7050a0 virtio: defer con... |
119 120 121 |
bool config_enabled; bool config_change_pending; spinlock_t config_lock; |
ec3d41c4d Virtio interface |
122 123 |
struct device dev; struct virtio_device_id id; |
935039323 virtio: make conf... |
124 |
const struct virtio_config_ops *config; |
3beee86a4 virtio: Introduce... |
125 |
const struct vringh_config_ops *vringh_config; |
9499f5e7e virtio: add names... |
126 |
struct list_head vqs; |
d02547736 virtio: add suppo... |
127 |
u64 features; |
ec3d41c4d Virtio interface |
128 129 |
void *priv; }; |
9bffdca8c virtio: use dev_t... |
130 131 132 133 |
static inline struct virtio_device *dev_to_virtio(struct device *_dev) { return container_of(_dev, struct virtio_device, dev); } |
9fe7bfce8 virtio_net: refac... |
134 |
void virtio_add_status(struct virtio_device *dev, unsigned int status); |
ec3d41c4d Virtio interface |
135 136 |
int register_virtio_device(struct virtio_device *dev); void unregister_virtio_device(struct virtio_device *dev); |
e2dcdfe95 virtio: virtio_br... |
137 |
void virtio_break_device(struct virtio_device *dev); |
016c98c6f virtio: unify con... |
138 |
void virtio_config_changed(struct virtio_device *dev); |
9fe7bfce8 virtio_net: refac... |
139 140 141 |
void virtio_config_disable(struct virtio_device *dev); void virtio_config_enable(struct virtio_device *dev); int virtio_finalize_features(struct virtio_device *dev); |
c6716bae5 virtio-pci: move ... |
142 143 144 145 |
#ifdef CONFIG_PM_SLEEP int virtio_device_freeze(struct virtio_device *dev); int virtio_device_restore(struct virtio_device *dev); #endif |
016c98c6f virtio: unify con... |
146 |
|
7ae93ff13 virtio: add abili... |
147 148 |
#define virtio_device_for_each_vq(vdev, vq) \ list_for_each_entry(vq, &vdev->vqs, list) |
ec3d41c4d Virtio interface |
149 150 151 152 |
/** * virtio_driver - operations for a virtio I/O driver * @driver: underlying device driver (populate name and owner). * @id_table: the ids serviced by this driver. |
5f41f8bfc virtio.h: correct... |
153 |
* @feature_table: an array of feature numbers supported by this driver. |
c45a6816c virtio: explicit ... |
154 |
* @feature_table_size: number of entries in the feature table array. |
b3bb62d11 virtio: add legac... |
155 156 |
* @feature_table_legacy: same as feature_table but when working in legacy mode. * @feature_table_size_legacy: number of entries in feature table legacy array. |
20f77f565 virtio: fix obsol... |
157 |
* @probe: the function to call when a device is found. Returns 0 or -errno. |
9ea762a5a virtio: virtio_dr... |
158 159 |
* @scan: optional function to call after successful probe; intended * for virtio-scsi to invoke a scan. |
5f41f8bfc virtio.h: correct... |
160 |
* @remove: the function to call when a device is removed. |
f957d1f05 virtio: configura... |
161 162 |
* @config_changed: optional function to call when the device configuration * changes; may be called in interrupt context. |
9ea762a5a virtio: virtio_dr... |
163 164 |
* @freeze: optional function to call during suspend/hibernation. * @restore: optional function to call on resume. |
ec3d41c4d Virtio interface |
165 166 167 168 |
*/ struct virtio_driver { struct device_driver driver; const struct virtio_device_id *id_table; |
c45a6816c virtio: explicit ... |
169 170 |
const unsigned int *feature_table; unsigned int feature_table_size; |
b3bb62d11 virtio: add legac... |
171 172 |
const unsigned int *feature_table_legacy; unsigned int feature_table_size_legacy; |
404123c2d virtio: allow dri... |
173 |
int (*validate)(struct virtio_device *dev); |
ec3d41c4d Virtio interface |
174 |
int (*probe)(struct virtio_device *dev); |
59057fbc3 [SCSI] virtio-scs... |
175 |
void (*scan)(struct virtio_device *dev); |
ec3d41c4d Virtio interface |
176 |
void (*remove)(struct virtio_device *dev); |
f957d1f05 virtio: configura... |
177 |
void (*config_changed)(struct virtio_device *dev); |
f0fe6f115 virtio: pci: add ... |
178 179 |
#ifdef CONFIG_PM int (*freeze)(struct virtio_device *dev); |
f0fe6f115 virtio: pci: add ... |
180 181 |
int (*restore)(struct virtio_device *dev); #endif |
ec3d41c4d Virtio interface |
182 |
}; |
9a2bdcc85 virtio: add drv_t... |
183 184 185 186 |
static inline struct virtio_driver *drv_to_virtio(struct device_driver *drv) { return container_of(drv, struct virtio_driver, driver); } |
ec3d41c4d Virtio interface |
187 188 |
int register_virtio_driver(struct virtio_driver *drv); void unregister_virtio_driver(struct virtio_driver *drv); |
6e105e059 virtio: Add modul... |
189 190 191 192 193 194 195 196 197 |
/* module_virtio_driver() - Helper macro for drivers that don't do * anything special in module init/exit. This eliminates a lot of * boilerplate. Each module may only use this macro once, and * calling it replaces module_init() and module_exit() */ #define module_virtio_driver(__virtio_driver) \ module_driver(__virtio_driver, register_virtio_driver, \ unregister_virtio_driver) |
ec3d41c4d Virtio interface |
198 |
#endif /* _LINUX_VIRTIO_H */ |