Commit 971f3390 authored by Rusty Russell's avatar Rusty Russell

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: default avatarRusty Russell <rusty@rustcorp.com.au>
Signed-off-by: default avatarAmit Shah <amit.shah@redhat.com>
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent a23ea924
...@@ -28,12 +28,12 @@ static struct virtio_device *vdev; ...@@ -28,12 +28,12 @@ static struct virtio_device *vdev;
static unsigned int in_len; static unsigned int in_len;
static char *in, *inbuf; static char *in, *inbuf;
/* The operations for our console. */
static struct hv_ops virtio_cons;
/* The hvc device */ /* The hvc device */
static struct hvc_struct *hvc; static struct hvc_struct *hvc;
/* This is the very early arch-specified put chars function. */
static int (*early_put_chars)(u32, const char *, int);
/* /*
* The put_chars() callback is pretty straightforward. * The put_chars() callback is pretty straightforward.
* *
...@@ -47,6 +47,9 @@ static int put_chars(u32 vtermno, const char *buf, int count) ...@@ -47,6 +47,9 @@ static int put_chars(u32 vtermno, const char *buf, int count)
struct scatterlist sg[1]; struct scatterlist sg[1];
unsigned int len; unsigned int len;
if (unlikely(early_put_chars))
return early_put_chars(vtermno, buf, count);
/* This is a convenient routine to initialize a single-elem sg list */ /* This is a convenient routine to initialize a single-elem sg list */
sg_init_one(sg, buf, count); sg_init_one(sg, buf, count);
...@@ -117,21 +120,6 @@ static int get_chars(u32 vtermno, char *buf, int count) ...@@ -117,21 +120,6 @@ static int get_chars(u32 vtermno, char *buf, int count)
return count; return count;
} }
/*
* Console drivers are initialized very early so boot messages can go
* out, so we do things slightly differently from the generic virtio
* initialization of the net and block drivers.
*
* At this stage, the console is output-only. It's too early to set
* up a virtqueue, so we let the drivers do some boutique early-output
* thing.
*/
int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
{
virtio_cons.put_chars = put_chars;
return hvc_instantiate(0, 0, &virtio_cons);
}
/* /*
* virtio console configuration. This supports: * virtio console configuration. This supports:
* - console resize * - console resize
...@@ -174,6 +162,30 @@ static void hvc_handle_input(struct virtqueue *vq) ...@@ -174,6 +162,30 @@ static void hvc_handle_input(struct virtqueue *vq)
hvc_kick(); hvc_kick();
} }
/* The operations for the console. */
static struct hv_ops hv_ops = {
.get_chars = get_chars,
.put_chars = put_chars,
.notifier_add = notifier_add_vio,
.notifier_del = notifier_del_vio,
.notifier_hangup = notifier_del_vio,
};
/*
* Console drivers are initialized very early so boot messages can go
* out, so we do things slightly differently from the generic virtio
* initialization of the net and block drivers.
*
* At this stage, the console is output-only. It's too early to set
* up a virtqueue, so we let the drivers do some boutique early-output
* thing.
*/
int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int))
{
early_put_chars = put_chars;
return hvc_instantiate(0, 0, &hv_ops);
}
/* /*
* Once we're further in boot, we get probed like any other virtio * Once we're further in boot, we get probed like any other virtio
* device. At this stage we set up the output virtqueue. * device. At this stage we set up the output virtqueue.
...@@ -209,13 +221,6 @@ static int __devinit virtcons_probe(struct virtio_device *dev) ...@@ -209,13 +221,6 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
in_vq = vqs[0]; in_vq = vqs[0];
out_vq = vqs[1]; out_vq = vqs[1];
/* Start using the new console output. */
virtio_cons.get_chars = get_chars;
virtio_cons.put_chars = put_chars;
virtio_cons.notifier_add = notifier_add_vio;
virtio_cons.notifier_del = notifier_del_vio;
virtio_cons.notifier_hangup = notifier_del_vio;
/* /*
* The first argument of hvc_alloc() is the virtual console * The first argument of hvc_alloc() is the virtual console
* number, so we use zero. The second argument is the * number, so we use zero. The second argument is the
...@@ -228,7 +233,7 @@ static int __devinit virtcons_probe(struct virtio_device *dev) ...@@ -228,7 +233,7 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
* pointers. The final argument is the output buffer size: we * pointers. The final argument is the output buffer size: we
* can do any size, so we put PAGE_SIZE here. * can do any size, so we put PAGE_SIZE here.
*/ */
hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); hvc = hvc_alloc(0, 0, &hv_ops, PAGE_SIZE);
if (IS_ERR(hvc)) { if (IS_ERR(hvc)) {
err = PTR_ERR(hvc); err = PTR_ERR(hvc);
goto free_vqs; goto free_vqs;
...@@ -236,6 +241,9 @@ static int __devinit virtcons_probe(struct virtio_device *dev) ...@@ -236,6 +241,9 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
/* Register the input buffer the first time. */ /* Register the input buffer the first time. */
add_inbuf(); add_inbuf();
/* Start using the new console output. */
early_put_chars = NULL;
return 0; return 0;
free_vqs: free_vqs:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment