2007-10-21 19:03:36 -06:00
|
|
|
#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>
|
2010-04-29 08:26:37 -06:00
|
|
|
#include <linux/gfp.h>
|
2007-10-21 19:03:36 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virtqueue - a queue to register buffers for sending or receiving.
|
2009-06-12 22:16:35 -06:00
|
|
|
* @list: the chain of virtqueues for this device
|
2007-10-21 19:03:36 -06:00
|
|
|
* @callback: the function to call when buffers are consumed (can be NULL).
|
2009-06-12 22:16:35 -06:00
|
|
|
* @name: the name of this virtqueue (mainly for debugging)
|
2007-10-21 19:03:36 -06:00
|
|
|
* @vdev: the virtio device this queue was created for.
|
|
|
|
* @priv: a pointer for the virtqueue implementation to use.
|
|
|
|
*/
|
2009-06-12 22:16:35 -06:00
|
|
|
struct virtqueue {
|
|
|
|
struct list_head list;
|
2008-02-04 21:49:57 -07:00
|
|
|
void (*callback)(struct virtqueue *vq);
|
2009-06-12 22:16:35 -06:00
|
|
|
const char *name;
|
2007-10-21 19:03:36 -06:00
|
|
|
struct virtio_device *vdev;
|
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
2012-01-11 22:14:42 -07:00
|
|
|
int virtqueue_add_buf(struct virtqueue *vq,
|
|
|
|
struct scatterlist sg[],
|
|
|
|
unsigned int out_num,
|
|
|
|
unsigned int in_num,
|
|
|
|
void *data,
|
|
|
|
gfp_t gfp);
|
2007-10-21 19:03:36 -06:00
|
|
|
|
2010-04-12 07:19:07 -06:00
|
|
|
void virtqueue_kick(struct virtqueue *vq);
|
2007-10-21 19:03:36 -06:00
|
|
|
|
2012-01-11 22:14:43 -07:00
|
|
|
bool virtqueue_kick_prepare(struct virtqueue *vq);
|
|
|
|
|
|
|
|
void virtqueue_notify(struct virtqueue *vq);
|
|
|
|
|
2010-04-12 07:19:07 -06:00
|
|
|
void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);
|
2010-04-12 07:18:25 -06:00
|
|
|
|
2010-04-12 07:19:07 -06:00
|
|
|
void virtqueue_disable_cb(struct virtqueue *vq);
|
2010-04-12 07:18:25 -06:00
|
|
|
|
2010-04-12 07:19:07 -06:00
|
|
|
bool virtqueue_enable_cb(struct virtqueue *vq);
|
2010-04-12 07:18:25 -06:00
|
|
|
|
2011-05-19 17:11:14 -06:00
|
|
|
bool virtqueue_enable_cb_delayed(struct virtqueue *vq);
|
|
|
|
|
2010-04-12 07:19:07 -06:00
|
|
|
void *virtqueue_detach_unused_buf(struct virtqueue *vq);
|
2010-04-12 07:18:25 -06:00
|
|
|
|
2011-10-19 02:10:59 -06:00
|
|
|
unsigned int virtqueue_get_vring_size(struct virtqueue *vq);
|
2012-08-28 05:54:13 -06:00
|
|
|
|
|
|
|
int virtqueue_get_queue_index(struct virtqueue *vq);
|
2011-10-19 02:10:59 -06:00
|
|
|
|
2007-10-21 19:03:36 -06:00
|
|
|
/**
|
|
|
|
* 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.
|
2009-06-12 22:16:35 -06:00
|
|
|
* @vqs: the list of virtqueues for this device.
|
2008-05-02 20:50:50 -06:00
|
|
|
* @features: the features supported by both driver and device.
|
2007-10-21 19:03:36 -06:00
|
|
|
* @priv: private pointer for the driver's use.
|
|
|
|
*/
|
2009-06-12 22:16:35 -06:00
|
|
|
struct virtio_device {
|
2007-10-21 19:03:36 -06:00
|
|
|
int index;
|
|
|
|
struct device dev;
|
|
|
|
struct virtio_device_id id;
|
|
|
|
struct virtio_config_ops *config;
|
2009-06-12 22:16:35 -06:00
|
|
|
struct list_head vqs;
|
2008-05-02 20:50:50 -06:00
|
|
|
/* Note that this is a Linux set_bit-style bitmap. */
|
|
|
|
unsigned long features[1];
|
2007-10-21 19:03:36 -06:00
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
2010-03-05 21:44:15 -07:00
|
|
|
#define dev_to_virtio(dev) container_of(dev, struct virtio_device, dev)
|
2007-10-21 19:03:36 -06:00
|
|
|
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.
|
2011-08-25 07:04:05 -06:00
|
|
|
* @feature_table: an array of feature numbers supported by this driver.
|
2008-05-02 20:50:50 -06:00
|
|
|
* @feature_table_size: number of entries in the feature table array.
|
2009-06-12 22:16:33 -06:00
|
|
|
* @probe: the function to call when a device is found. Returns 0 or -errno.
|
2011-08-25 07:04:05 -06:00
|
|
|
* @remove: the function to call when a device is removed.
|
2008-02-04 21:49:58 -07:00
|
|
|
* @config_changed: optional function to call when the device configuration
|
|
|
|
* changes; may be called in interrupt context.
|
2007-10-21 19:03:36 -06:00
|
|
|
*/
|
|
|
|
struct virtio_driver {
|
|
|
|
struct device_driver driver;
|
|
|
|
const struct virtio_device_id *id_table;
|
2008-05-02 20:50:50 -06:00
|
|
|
const unsigned int *feature_table;
|
|
|
|
unsigned int feature_table_size;
|
2007-10-21 19:03:36 -06:00
|
|
|
int (*probe)(struct virtio_device *dev);
|
2012-07-11 15:22:16 -06:00
|
|
|
void (*scan)(struct virtio_device *dev);
|
2007-10-21 19:03:36 -06:00
|
|
|
void (*remove)(struct virtio_device *dev);
|
2008-02-04 21:49:58 -07:00
|
|
|
void (*config_changed)(struct virtio_device *dev);
|
2011-12-22 04:28:26 -07:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
int (*freeze)(struct virtio_device *dev);
|
|
|
|
int (*restore)(struct virtio_device *dev);
|
|
|
|
#endif
|
2007-10-21 19:03:36 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
int register_virtio_driver(struct virtio_driver *drv);
|
|
|
|
void unregister_virtio_driver(struct virtio_driver *drv);
|
|
|
|
#endif /* _LINUX_VIRTIO_H */
|