Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 197857
b: refs/heads/master
c: 7c5e9ed
h: refs/heads/master
i:
  197855: 253131d
v: v3
  • Loading branch information
Michael S. Tsirkin authored and Rusty Russell committed May 19, 2010
1 parent f8633b1 commit a03ecd3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 74 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1915a712f210f0b63d10bc4f875e8e66aac7a2c4
refs/heads/master: 7c5e9ed0c84e7d70d887878574590638d5572659
36 changes: 16 additions & 20 deletions trunk/drivers/virtio/virtio_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ static int vring_add_indirect(struct vring_virtqueue *vq,
return head;
}

static int vring_add_buf(struct virtqueue *_vq,
struct scatterlist sg[],
unsigned int out,
unsigned int in,
void *data)
int virtqueue_add_buf(struct virtqueue *_vq,
struct scatterlist sg[],
unsigned int out,
unsigned int in,
void *data)
{
struct vring_virtqueue *vq = to_vvq(_vq);
unsigned int i, avail, head, uninitialized_var(prev);
Expand Down Expand Up @@ -232,8 +232,9 @@ static int vring_add_buf(struct virtqueue *_vq,
return vq->num_free ? vq->vring.num : 0;
return vq->num_free;
}
EXPORT_SYMBOL_GPL(virtqueue_add_buf);

static void vring_kick(struct virtqueue *_vq)
void virtqueue_kick(struct virtqueue *_vq)
{
struct vring_virtqueue *vq = to_vvq(_vq);
START_USE(vq);
Expand All @@ -253,6 +254,7 @@ static void vring_kick(struct virtqueue *_vq)

END_USE(vq);
}
EXPORT_SYMBOL_GPL(virtqueue_kick);

static void detach_buf(struct vring_virtqueue *vq, unsigned int head)
{
Expand Down Expand Up @@ -284,7 +286,7 @@ static inline bool more_used(const struct vring_virtqueue *vq)
return vq->last_used_idx != vq->vring.used->idx;
}

static void *vring_get_buf(struct virtqueue *_vq, unsigned int *len)
void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len)
{
struct vring_virtqueue *vq = to_vvq(_vq);
void *ret;
Expand Down Expand Up @@ -325,15 +327,17 @@ static void *vring_get_buf(struct virtqueue *_vq, unsigned int *len)
END_USE(vq);
return ret;
}
EXPORT_SYMBOL_GPL(virtqueue_get_buf);

static void vring_disable_cb(struct virtqueue *_vq)
void virtqueue_disable_cb(struct virtqueue *_vq)
{
struct vring_virtqueue *vq = to_vvq(_vq);

vq->vring.avail->flags |= VRING_AVAIL_F_NO_INTERRUPT;
}
EXPORT_SYMBOL_GPL(virtqueue_disable_cb);

static bool vring_enable_cb(struct virtqueue *_vq)
bool virtqueue_enable_cb(struct virtqueue *_vq)
{
struct vring_virtqueue *vq = to_vvq(_vq);

Expand All @@ -351,8 +355,9 @@ static bool vring_enable_cb(struct virtqueue *_vq)
END_USE(vq);
return true;
}
EXPORT_SYMBOL_GPL(virtqueue_enable_cb);

static void *vring_detach_unused_buf(struct virtqueue *_vq)
void *virtqueue_detach_unused_buf(struct virtqueue *_vq)
{
struct vring_virtqueue *vq = to_vvq(_vq);
unsigned int i;
Expand All @@ -375,6 +380,7 @@ static void *vring_detach_unused_buf(struct virtqueue *_vq)
END_USE(vq);
return NULL;
}
EXPORT_SYMBOL_GPL(virtqueue_detach_unused_buf);

irqreturn_t vring_interrupt(int irq, void *_vq)
{
Expand All @@ -396,15 +402,6 @@ irqreturn_t vring_interrupt(int irq, void *_vq)
}
EXPORT_SYMBOL_GPL(vring_interrupt);

static struct virtqueue_ops vring_vq_ops = {
.add_buf = vring_add_buf,
.get_buf = vring_get_buf,
.kick = vring_kick,
.disable_cb = vring_disable_cb,
.enable_cb = vring_enable_cb,
.detach_unused_buf = vring_detach_unused_buf,
};

struct virtqueue *vring_new_virtqueue(unsigned int num,
unsigned int vring_align,
struct virtio_device *vdev,
Expand All @@ -429,7 +426,6 @@ struct virtqueue *vring_new_virtqueue(unsigned int num,
vring_init(&vq->vring, num, pages, vring_align);
vq->vq.callback = callback;
vq->vq.vdev = vdev;
vq->vq.vq_ops = &vring_vq_ops;
vq->vq.name = name;
vq->notify = notify;
vq->broken = false;
Expand Down
71 changes: 18 additions & 53 deletions trunk/include/linux/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,102 +14,67 @@
* @callback: the function to call when buffers are consumed (can be NULL).
* @name: the name of this virtqueue (mainly for debugging)
* @vdev: the virtio device this queue was created for.
* @vq_ops: the operations for this virtqueue (see below).
* @priv: a pointer for the virtqueue implementation to use.
*/
struct virtqueue {
struct list_head list;
void (*callback)(struct virtqueue *vq);
const char *name;
struct virtio_device *vdev;
struct virtqueue_ops *vq_ops;
void *priv;
};

/**
* virtqueue_ops - operations for virtqueue abstraction layer
* @add_buf: expose buffer to other end
* operations for virtqueue
* virtqueue_add_buf: expose buffer to other end
* vq: the struct virtqueue we're talking about.
* sg: the description of the buffer(s).
* out_num: the number of sg readable by other side
* in_num: the number of sg which are writable (after readable ones)
* data: the token identifying the buffer.
* Returns remaining capacity of queue (sg segments) or a negative error.
* @kick: update after add_buf
* virtqueue_kick: update after add_buf
* vq: the struct virtqueue
* After one or more add_buf calls, invoke this to kick the other side.
* @get_buf: get the next used buffer
* virtqueue_get_buf: get the next used buffer
* vq: the struct virtqueue we're talking about.
* len: the length written into the buffer
* Returns NULL or the "data" token handed to add_buf.
* @disable_cb: disable callbacks
* virtqueue_disable_cb: disable callbacks
* vq: the struct virtqueue we're talking about.
* Note that this is not necessarily synchronous, hence unreliable and only
* useful as an optimization.
* @enable_cb: restart callbacks after disable_cb.
* virtqueue_enable_cb: restart callbacks after disable_cb.
* vq: the struct virtqueue we're talking about.
* This re-enables callbacks; it returns "false" if there are pending
* buffers in the queue, to detect a possible race between the driver
* checking for more work, and enabling callbacks.
* @detach_unused_buf: detach first unused buffer
* virtqueue_detach_unused_buf: detach first unused buffer
* vq: the struct virtqueue we're talking about.
* Returns NULL or the "data" token handed to add_buf
*
* Locking rules are straightforward: the driver is responsible for
* locking. No two operations may be invoked simultaneously, with the exception
* of @disable_cb.
* of virtqueue_disable_cb.
*
* All operations can be called in any context.
*/
struct virtqueue_ops {
int (*add_buf)(struct virtqueue *vq,
struct scatterlist sg[],
unsigned int out_num,
unsigned int in_num,
void *data);

void (*kick)(struct virtqueue *vq);
int virtqueue_add_buf(struct virtqueue *vq,
struct scatterlist sg[],
unsigned int out_num,
unsigned int in_num,
void *data);

void *(*get_buf)(struct virtqueue *vq, unsigned int *len);
void virtqueue_kick(struct virtqueue *vq);

void (*disable_cb)(struct virtqueue *vq);
bool (*enable_cb)(struct virtqueue *vq);
void *(*detach_unused_buf)(struct virtqueue *vq);
};

static inline int virtqueue_add_buf(struct virtqueue *vq,
struct scatterlist sg[],
unsigned int out_num,
unsigned int in_num,
void *data)
{
return vq->vq_ops->add_buf(vq, sg, out_num, in_num, data);
}

static inline int void virtqueue_kick(struct virtqueue *vq)
{
return vq->vq_ops->kick(vq);
}

static inline void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len)
{
return vq->vq_ops->get_buf(vq, len);
}
void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len);

static inline void virtqueue_disable_cb(struct virtqueue *vq)
{
vq->vq_ops->disable_cb(vq);
}
void virtqueue_disable_cb(struct virtqueue *vq);

static inline bool virtqueue_enable_cb(struct virtqueue *vq)
{
return vq->vq_ops->enable_cb(vq);
}
bool virtqueue_enable_cb(struct virtqueue *vq);

static inline void *virtqueue_detach_unused_buf(struct virtqueue *vq)
{
return vq->vq_ops->detach_unused_buf(vq);
}
void *virtqueue_detach_unused_buf(struct virtqueue *vq);

/**
* virtio_device - representation of a device using virtio
Expand Down

0 comments on commit a03ecd3

Please sign in to comment.