diff options
author | Amit Shah <amit.shah@redhat.com> | 2010-01-18 08:45:09 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2010-02-23 22:52:47 -0500 |
commit | 4f23c573c0dbebfd193cfb90b003d67929c58b31 (patch) | |
tree | e7ba84a7ecbff8f8d837e47375de17ef82210084 /drivers/char/virtio_console.c | |
parent | cb06e3676b22013e9b759627e41656ddb07dee6d (diff) |
virtio: console: Separate out console-specific data into a separate struct
Move out console-specific stuff into a separate struct from 'struct
port' as we need to maintain two lists: one for all the ports (which
includes consoles) and one only for consoles since the hvc callbacks
only give us the vtermno.
This makes console handling cleaner.
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.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c index debc86542858..c6c6f52043b5 100644 --- a/drivers/char/virtio_console.c +++ b/drivers/char/virtio_console.c | |||
@@ -51,6 +51,24 @@ static struct ports_driver_data pdrvdata; | |||
51 | 51 | ||
52 | DEFINE_SPINLOCK(pdrvdata_lock); | 52 | DEFINE_SPINLOCK(pdrvdata_lock); |
53 | 53 | ||
54 | /* This struct holds information that's relevant only for console ports */ | ||
55 | struct console { | ||
56 | /* We'll place all consoles in a list in the pdrvdata struct */ | ||
57 | struct list_head list; | ||
58 | |||
59 | /* The hvc device associated with this console port */ | ||
60 | struct hvc_struct *hvc; | ||
61 | |||
62 | /* | ||
63 | * This number identifies the number that we used to register | ||
64 | * with hvc in hvc_instantiate() and hvc_alloc(); this is the | ||
65 | * number passed on by the hvc callbacks to us to | ||
66 | * differentiate between the other console ports handled by | ||
67 | * this driver | ||
68 | */ | ||
69 | u32 vtermno; | ||
70 | }; | ||
71 | |||
54 | /* | 72 | /* |
55 | * This is a per-device struct that stores data common to all the | 73 | * This is a per-device struct that stores data common to all the |
56 | * ports for that device (vdev->priv). | 74 | * ports for that device (vdev->priv). |
@@ -83,15 +101,11 @@ struct port { | |||
83 | /* The IO vqs for this port */ | 101 | /* The IO vqs for this port */ |
84 | struct virtqueue *in_vq, *out_vq; | 102 | struct virtqueue *in_vq, *out_vq; |
85 | 103 | ||
86 | /* For console ports, hvc != NULL and these are valid. */ | 104 | /* |
87 | /* The hvc device */ | 105 | * The entries in this struct will be valid if this port is |
88 | struct hvc_struct *hvc; | 106 | * hooked up to an hvc console |
89 | 107 | */ | |
90 | /* We'll place all consoles in a list in the pdrvdata struct */ | 108 | struct console cons; |
91 | struct list_head list; | ||
92 | |||
93 | /* Our vterm number. */ | ||
94 | u32 vtermno; | ||
95 | }; | 109 | }; |
96 | 110 | ||
97 | /* This is the very early arch-specified put chars function. */ | 111 | /* This is the very early arch-specified put chars function. */ |
@@ -100,12 +114,15 @@ static int (*early_put_chars)(u32, const char *, int); | |||
100 | static struct port *find_port_by_vtermno(u32 vtermno) | 114 | static struct port *find_port_by_vtermno(u32 vtermno) |
101 | { | 115 | { |
102 | struct port *port; | 116 | struct port *port; |
117 | struct console *cons; | ||
103 | unsigned long flags; | 118 | unsigned long flags; |
104 | 119 | ||
105 | spin_lock_irqsave(&pdrvdata_lock, flags); | 120 | spin_lock_irqsave(&pdrvdata_lock, flags); |
106 | list_for_each_entry(port, &pdrvdata.consoles, list) { | 121 | list_for_each_entry(cons, &pdrvdata.consoles, list) { |
107 | if (port->vtermno == vtermno) | 122 | if (cons->vtermno == vtermno) { |
123 | port = container_of(cons, struct port, cons); | ||
108 | goto out; | 124 | goto out; |
125 | } | ||
109 | } | 126 | } |
110 | port = NULL; | 127 | port = NULL; |
111 | out: | 128 | out: |
@@ -264,7 +281,7 @@ static void resize_console(struct port *port) | |||
264 | vdev->config->get(vdev, | 281 | vdev->config->get(vdev, |
265 | offsetof(struct virtio_console_config, rows), | 282 | offsetof(struct virtio_console_config, rows), |
266 | &ws.ws_row, sizeof(u16)); | 283 | &ws.ws_row, sizeof(u16)); |
267 | hvc_resize(port->hvc, ws); | 284 | hvc_resize(port->cons.hvc, ws); |
268 | } | 285 | } |
269 | } | 286 | } |
270 | 287 | ||
@@ -295,11 +312,11 @@ static void notifier_del_vio(struct hvc_struct *hp, int data) | |||
295 | 312 | ||
296 | static void hvc_handle_input(struct virtqueue *vq) | 313 | static void hvc_handle_input(struct virtqueue *vq) |
297 | { | 314 | { |
298 | struct port *port; | 315 | struct console *cons; |
299 | bool activity = false; | 316 | bool activity = false; |
300 | 317 | ||
301 | list_for_each_entry(port, &pdrvdata.consoles, list) | 318 | list_for_each_entry(cons, &pdrvdata.consoles, list) |
302 | activity |= hvc_poll(port->hvc); | 319 | activity |= hvc_poll(cons->hvc); |
303 | 320 | ||
304 | if (activity) | 321 | if (activity) |
305 | hvc_kick(); | 322 | hvc_kick(); |
@@ -361,17 +378,17 @@ static int __devinit add_port(struct ports_device *portdev) | |||
361 | * pointers. The final argument is the output buffer size: we | 378 | * pointers. The final argument is the output buffer size: we |
362 | * can do any size, so we put PAGE_SIZE here. | 379 | * can do any size, so we put PAGE_SIZE here. |
363 | */ | 380 | */ |
364 | port->vtermno = pdrvdata.next_vtermno; | 381 | port->cons.vtermno = pdrvdata.next_vtermno; |
365 | port->hvc = hvc_alloc(port->vtermno, 0, &hv_ops, PAGE_SIZE); | 382 | port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE); |
366 | if (IS_ERR(port->hvc)) { | 383 | if (IS_ERR(port->cons.hvc)) { |
367 | err = PTR_ERR(port->hvc); | 384 | err = PTR_ERR(port->cons.hvc); |
368 | goto free_inbuf; | 385 | goto free_inbuf; |
369 | } | 386 | } |
370 | 387 | ||
371 | /* Add to vtermno list. */ | 388 | /* Add to vtermno list. */ |
372 | spin_lock_irq(&pdrvdata_lock); | 389 | spin_lock_irq(&pdrvdata_lock); |
373 | pdrvdata.next_vtermno++; | 390 | pdrvdata.next_vtermno++; |
374 | list_add(&port->list, &pdrvdata.consoles); | 391 | list_add(&port->cons.list, &pdrvdata.consoles); |
375 | spin_unlock_irq(&pdrvdata_lock); | 392 | spin_unlock_irq(&pdrvdata_lock); |
376 | 393 | ||
377 | /* Register the input buffer the first time. */ | 394 | /* Register the input buffer the first time. */ |