Skip to content

Commit

Permalink
virtio: console: ensure add_inbuf can work for multiple ports as well
Browse files Browse the repository at this point in the history
add_inbuf() assumed one port and one inbuf per port. Remove that
assumption.

Also move the function so that put_chars and get_chars are together.

Signed-off-by: Amit Shah <amit.shah@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
Amit Shah authored and Rusty Russell committed Feb 24, 2010
1 parent fdb9a05 commit e27b519
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ static struct port_buffer *alloc_buf(size_t buf_size)
return NULL;
}

/*
* Create a scatter-gather list representing our input buffer and put
* it in the queue.
*
* Callers should take appropriate locks.
*/
static void add_inbuf(struct virtqueue *vq, struct port_buffer *buf)
{
struct scatterlist sg[1];
sg_init_one(sg, buf->buf, buf->size);

if (vq->vq_ops->add_buf(vq, sg, 0, 1, buf) < 0)
BUG();
vq->vq_ops->kick(vq);
}

/*
* The put_chars() callback is pretty straightforward.
*
Expand Down Expand Up @@ -111,21 +127,6 @@ static int put_chars(u32 vtermno, const char *buf, int count)
return count;
}

/*
* Create a scatter-gather list representing our input buffer and put
* it in the queue.
*/
static void add_inbuf(struct port *port)
{
struct scatterlist sg[1];
sg_init_one(sg, port->inbuf->buf, PAGE_SIZE);

/* Should always be able to add one buffer to an empty queue. */
if (port->in_vq->vq_ops->add_buf(port->in_vq, sg, 0, 1, port) < 0)
BUG();
port->in_vq->vq_ops->kick(port->in_vq);
}

/*
* get_chars() is the callback from the hvc_console infrastructure
* when an interrupt is received.
Expand Down Expand Up @@ -162,7 +163,7 @@ static int get_chars(u32 vtermno, char *buf, int count)

/* Finished? Re-register buffer so Host will use it again. */
if (port->inbuf->offset == port->inbuf->len)
add_inbuf(port);
add_inbuf(port->in_vq, port->inbuf);

return count;
}
Expand Down Expand Up @@ -294,7 +295,7 @@ static int __devinit virtcons_probe(struct virtio_device *vdev)
}

/* Register the input buffer the first time. */
add_inbuf(port);
add_inbuf(port->in_vq, port->inbuf);

/* Start using the new console output. */
early_put_chars = NULL;
Expand Down

0 comments on commit e27b519

Please sign in to comment.