aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-01-18 08:44:56 -0500
committerRusty Russell <rusty@rustcorp.com.au>2010-02-23 22:52:31 -0500
commit971f3390003619ea4ac0b20ee93dfd3209025790 (patch)
treeeb25f42019387f1881defce1636fdf6e21b8d13c /drivers/char
parenta23ea92474e558b071d3e43d961ec767c31faebd (diff)
virtio: console: statically initialize virtio_cons
That way, we can make it const as is good kernel style. We use a separate indirection for the early console, rather than mugging ops.put_chars. We rename it hv_ops, too. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Amit Shah <amit.shah@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/virtio_console.c60
1 files changed, 34 insertions, 26 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 26e238cd7d2f..1d844a43a6bf 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -28,12 +28,12 @@ static struct virtio_device *vdev;
28static unsigned int in_len; 28static unsigned int in_len;
29static char *in, *inbuf; 29static char *in, *inbuf;
30 30
31/* The operations for our console. */
32static struct hv_ops virtio_cons;
33
34/* The hvc device */ 31/* The hvc device */
35static struct hvc_struct *hvc; 32static struct hvc_struct *hvc;
36 33
34/* This is the very early arch-specified put chars function. */
35static int (*early_put_chars)(u32, const char *, int);
36
37/* 37/*
38 * The put_chars() callback is pretty straightforward. 38 * The put_chars() callback is pretty straightforward.
39 * 39 *
@@ -47,6 +47,9 @@ static int put_chars(u32 vtermno, const char *buf, int count)
47 struct scatterlist sg[1]; 47 struct scatterlist sg[1];
48 unsigned int len; 48 unsigned int len;
49 49
50 if (unlikely(early_put_chars))
51 return early_put_chars(vtermno, buf, count);
52
50 /* This is a convenient routine to initialize a single-elem sg list */ 53 /* This is a convenient routine to initialize a single-elem sg list */
51 sg_init_one(sg, buf, count); 54 sg_init_one(sg, buf, count);
52 55
@@ -118,21 +121,6 @@ static int get_chars(u32 vtermno, char *buf, int count)
118} 121}
119 122
120/* 123/*
121 * Console drivers are initialized very early so boot messages can go
122 * out, so we do things slightly differently from the generic virtio
123 * initialization of the net and block drivers.
124 *
125 * At this stage, the console is output-only. It's too early to set
126 * up a virtqueue, so we let the drivers do some boutique early-output
127 * thing.
128 */
129int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
130{
131 virtio_cons.put_chars = put_chars;
132 return hvc_instantiate(0, 0, &virtio_cons);
133}
134
135/*
136 * virtio console configuration. This supports: 124 * virtio console configuration. This supports:
137 * - console resize 125 * - console resize
138 */ 126 */
@@ -174,6 +162,30 @@ static void hvc_handle_input(struct virtqueue *vq)
174 hvc_kick(); 162 hvc_kick();
175} 163}
176 164
165/* The operations for the console. */
166static struct hv_ops hv_ops = {
167 .get_chars = get_chars,
168 .put_chars = put_chars,
169 .notifier_add = notifier_add_vio,
170 .notifier_del = notifier_del_vio,
171 .notifier_hangup = notifier_del_vio,
172};
173
174/*
175 * Console drivers are initialized very early so boot messages can go
176 * out, so we do things slightly differently from the generic virtio
177 * initialization of the net and block drivers.
178 *
179 * At this stage, the console is output-only. It's too early to set
180 * up a virtqueue, so we let the drivers do some boutique early-output
181 * thing.
182 */
183int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
184{
185 early_put_chars = put_chars;
186 return hvc_instantiate(0, 0, &hv_ops);
187}
188
177/* 189/*
178 * Once we're further in boot, we get probed like any other virtio 190 * Once we're further in boot, we get probed like any other virtio
179 * device. At this stage we set up the output virtqueue. 191 * device. At this stage we set up the output virtqueue.
@@ -209,13 +221,6 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
209 in_vq = vqs[0]; 221 in_vq = vqs[0];
210 out_vq = vqs[1]; 222 out_vq = vqs[1];
211 223
212 /* Start using the new console output. */
213 virtio_cons.get_chars = get_chars;
214 virtio_cons.put_chars = put_chars;
215 virtio_cons.notifier_add = notifier_add_vio;
216 virtio_cons.notifier_del = notifier_del_vio;
217 virtio_cons.notifier_hangup = notifier_del_vio;
218
219 /* 224 /*
220 * The first argument of hvc_alloc() is the virtual console 225 * The first argument of hvc_alloc() is the virtual console
221 * number, so we use zero. The second argument is the 226 * number, so we use zero. The second argument is the
@@ -228,7 +233,7 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
228 * pointers. The final argument is the output buffer size: we 233 * pointers. The final argument is the output buffer size: we
229 * can do any size, so we put PAGE_SIZE here. 234 * can do any size, so we put PAGE_SIZE here.
230 */ 235 */
231 hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); 236 hvc = hvc_alloc(0, 0, &hv_ops, PAGE_SIZE);
232 if (IS_ERR(hvc)) { 237 if (IS_ERR(hvc)) {
233 err = PTR_ERR(hvc); 238 err = PTR_ERR(hvc);
234 goto free_vqs; 239 goto free_vqs;
@@ -236,6 +241,9 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
236 241
237 /* Register the input buffer the first time. */ 242 /* Register the input buffer the first time. */
238 add_inbuf(); 243 add_inbuf();
244
245 /* Start using the new console output. */
246 early_put_chars = NULL;
239 return 0; 247 return 0;
240 248
241free_vqs: 249free_vqs: