aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/virtio_console.c
diff options
context:
space:
mode:
authorAmit Shah <amit.shah@redhat.com>2010-01-18 08:45:03 -0500
committerRusty Russell <rusty@rustcorp.com.au>2010-02-23 22:52:38 -0500
commita3cde44908429e52b2ec052ad5a70ef60e1f2d56 (patch)
tree5470aabeb5fcb10c5372b4771ea7d4c48746446e /drivers/char/virtio_console.c
parente27b519807e04d950802cb89f7b22933d8d2f837 (diff)
virtio: console: introduce a get_inbuf helper to fetch bufs from in_vq
This makes taking locks around the get_buf vq operation easier, as well as complements the add_inbuf() operation. Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/char/virtio_console.c')
-rw-r--r--drivers/char/virtio_console.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 1dbd46cb1a26..df45e5e9a947 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -77,6 +77,22 @@ fail:
77 return NULL; 77 return NULL;
78} 78}
79 79
80/* Callers should take appropriate locks */
81static void *get_inbuf(struct port *port)
82{
83 struct port_buffer *buf;
84 struct virtqueue *vq;
85 unsigned int len;
86
87 vq = port->in_vq;
88 buf = vq->vq_ops->get_buf(vq, &len);
89 if (buf) {
90 buf->len = len;
91 buf->offset = 0;
92 }
93 return buf;
94}
95
80/* 96/*
81 * Create a scatter-gather list representing our input buffer and put 97 * Create a scatter-gather list representing our input buffer and put
82 * it in the queue. 98 * it in the queue.
@@ -138,7 +154,6 @@ static int put_chars(u32 vtermno, const char *buf, int count)
138static int get_chars(u32 vtermno, char *buf, int count) 154static int get_chars(u32 vtermno, char *buf, int count)
139{ 155{
140 struct port *port; 156 struct port *port;
141 unsigned int len;
142 157
143 port = &console; 158 port = &console;
144 159
@@ -147,10 +162,8 @@ static int get_chars(u32 vtermno, char *buf, int count)
147 162
148 /* No more in buffer? See if they've (re)used it. */ 163 /* No more in buffer? See if they've (re)used it. */
149 if (port->inbuf->offset == port->inbuf->len) { 164 if (port->inbuf->offset == port->inbuf->len) {
150 if (!port->in_vq->vq_ops->get_buf(port->in_vq, &len)) 165 if (!get_inbuf(port))
151 return 0; 166 return 0;
152 port->inbuf->offset = 0;
153 port->inbuf->len = len;
154 } 167 }
155 168
156 /* You want more than we have to give? Well, try wanting less! */ 169 /* You want more than we have to give? Well, try wanting less! */