virtio.h 3.4 KB
Newer Older
R
Rusty Russell 已提交
1 2 3 4 5 6 7 8 9
#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>
M
Michael S. Tsirkin 已提交
10
#include <linux/gfp.h>
R
Rusty Russell 已提交
11 12 13

/**
 * virtqueue - a queue to register buffers for sending or receiving.
14
 * @list: the chain of virtqueues for this device
R
Rusty Russell 已提交
15
 * @callback: the function to call when buffers are consumed (can be NULL).
16
 * @name: the name of this virtqueue (mainly for debugging)
R
Rusty Russell 已提交
17 18 19
 * @vdev: the virtio device this queue was created for.
 * @priv: a pointer for the virtqueue implementation to use.
 */
20 21
struct virtqueue {
	struct list_head list;
22
	void (*callback)(struct virtqueue *vq);
23
	const char *name;
R
Rusty Russell 已提交
24 25 26 27
	struct virtio_device *vdev;
	void *priv;
};

28 29 30 31 32 33
int virtqueue_add_buf(struct virtqueue *vq,
		      struct scatterlist sg[],
		      unsigned int out_num,
		      unsigned int in_num,
		      void *data,
		      gfp_t gfp);
R
Rusty Russell 已提交
34

35
void virtqueue_kick(struct virtqueue *vq);
R
Rusty Russell 已提交
36

37 38 39 40
bool virtqueue_kick_prepare(struct virtqueue *vq);

void virtqueue_notify(struct virtqueue *vq);

41
void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
42

43
void virtqueue_disable_cb(struct virtqueue *vq);
44

45
bool virtqueue_enable_cb(struct virtqueue *vq);
46

47 48
bool virtqueue_enable_cb_delayed(struct virtqueue *vq);

49
void *virtqueue_detach_unused_buf(struct virtqueue *vq);
50

R
Rick Jones 已提交
51 52
unsigned int virtqueue_get_vring_size(struct virtqueue *vq);

R
Rusty Russell 已提交
53 54 55 56 57 58
/**
 * virtio_device - representation of a device using virtio
 * @index: unique position on the virtio bus
 * @dev: underlying device.
 * @id: the device type identification (used to match it with a driver).
 * @config: the configuration ops for this device.
59
 * @vqs: the list of virtqueues for this device.
60
 * @features: the features supported by both driver and device.
R
Rusty Russell 已提交
61 62
 * @priv: private pointer for the driver's use.
 */
63
struct virtio_device {
R
Rusty Russell 已提交
64 65 66 67
	int index;
	struct device dev;
	struct virtio_device_id id;
	struct virtio_config_ops *config;
68
	struct list_head vqs;
69 70
	/* Note that this is a Linux set_bit-style bitmap. */
	unsigned long features[1];
R
Rusty Russell 已提交
71 72 73
	void *priv;
};

74
#define dev_to_virtio(dev) container_of(dev, struct virtio_device, dev)
R
Rusty Russell 已提交
75 76 77 78 79 80 81
int register_virtio_device(struct virtio_device *dev);
void unregister_virtio_device(struct virtio_device *dev);

/**
 * 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.
82
 * @feature_table: an array of feature numbers supported by this driver.
83
 * @feature_table_size: number of entries in the feature table array.
84
 * @probe: the function to call when a device is found.  Returns 0 or -errno.
85
 * @remove: the function to call when a device is removed.
86 87
 * @config_changed: optional function to call when the device configuration
 *    changes; may be called in interrupt context.
R
Rusty Russell 已提交
88 89 90 91
 */
struct virtio_driver {
	struct device_driver driver;
	const struct virtio_device_id *id_table;
92 93
	const unsigned int *feature_table;
	unsigned int feature_table_size;
R
Rusty Russell 已提交
94 95
	int (*probe)(struct virtio_device *dev);
	void (*remove)(struct virtio_device *dev);
96
	void (*config_changed)(struct virtio_device *dev);
97 98 99 100
#ifdef CONFIG_PM
	int (*freeze)(struct virtio_device *dev);
	int (*restore)(struct virtio_device *dev);
#endif
R
Rusty Russell 已提交
101 102 103 104 105
};

int register_virtio_driver(struct virtio_driver *drv);
void unregister_virtio_driver(struct virtio_driver *drv);
#endif /* _LINUX_VIRTIO_H */