diff options
author | Hendrik Brueckner <brueckner@linux.vnet.ibm.com> | 2008-10-14 01:02:09 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2008-10-21 20:00:25 -0400 |
commit | febde3711992a64ea83a47a719f68a90c4b0927a (patch) | |
tree | 27f975fe9b3bd3b99a1a7043c34cf32176b7067d | |
parent | 3feebbb5492e9e463467cefb633e23a3dfcec132 (diff) |
hvc_console: Add support for tty window resizing
The patch provides the hvc_resize() function to update the terminal
window dimensions (struct winsize) for a specified hvc console.
The function stores the new window size and schedules a function
that finally updates the tty winsize and signals the change to
user space (SIGWINCH).
Because the winsize update must acquire a mutex and might sleep,
the function is scheduled instead of being called from hvc_poll()
or khvcd.
This patch uses the tty_do_resize() routine from the tty layer.
A pending resize work is canceled in hvc_close() and hvc_hangup().
Signed-off-by: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
-rw-r--r-- | drivers/char/hvc_console.c | 58 | ||||
-rw-r--r-- | drivers/char/hvc_console.h | 6 |
2 files changed, 64 insertions, 0 deletions
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c index 3650c904401e..2d256dc80529 100644 --- a/drivers/char/hvc_console.c +++ b/drivers/char/hvc_console.c | |||
@@ -374,6 +374,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) | |||
374 | if (hp->ops->notifier_del) | 374 | if (hp->ops->notifier_del) |
375 | hp->ops->notifier_del(hp, hp->data); | 375 | hp->ops->notifier_del(hp, hp->data); |
376 | 376 | ||
377 | /* cancel pending tty resize work */ | ||
378 | cancel_work_sync(&hp->tty_resize); | ||
379 | |||
377 | /* | 380 | /* |
378 | * Chain calls chars_in_buffer() and returns immediately if | 381 | * Chain calls chars_in_buffer() and returns immediately if |
379 | * there is no buffered data otherwise sleeps on a wait queue | 382 | * there is no buffered data otherwise sleeps on a wait queue |
@@ -399,6 +402,9 @@ static void hvc_hangup(struct tty_struct *tty) | |||
399 | if (!hp) | 402 | if (!hp) |
400 | return; | 403 | return; |
401 | 404 | ||
405 | /* cancel pending tty resize work */ | ||
406 | cancel_work_sync(&hp->tty_resize); | ||
407 | |||
402 | spin_lock_irqsave(&hp->lock, flags); | 408 | spin_lock_irqsave(&hp->lock, flags); |
403 | 409 | ||
404 | /* | 410 | /* |
@@ -494,6 +500,39 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count | |||
494 | return written; | 500 | return written; |
495 | } | 501 | } |
496 | 502 | ||
503 | /** | ||
504 | * hvc_set_winsz() - Resize the hvc tty terminal window. | ||
505 | * @work: work structure. | ||
506 | * | ||
507 | * The routine shall not be called within an atomic context because it | ||
508 | * might sleep. | ||
509 | * | ||
510 | * Locking: hp->lock | ||
511 | */ | ||
512 | static void hvc_set_winsz(struct work_struct *work) | ||
513 | { | ||
514 | struct hvc_struct *hp; | ||
515 | unsigned long hvc_flags; | ||
516 | struct tty_struct *tty; | ||
517 | struct winsize ws; | ||
518 | |||
519 | hp = container_of(work, struct hvc_struct, tty_resize); | ||
520 | if (!hp) | ||
521 | return; | ||
522 | |||
523 | spin_lock_irqsave(&hp->lock, hvc_flags); | ||
524 | if (!hp->tty) { | ||
525 | spin_unlock_irqrestore(&hp->lock, hvc_flags); | ||
526 | return; | ||
527 | } | ||
528 | ws = hp->ws; | ||
529 | tty = tty_kref_get(hp->tty); | ||
530 | spin_unlock_irqrestore(&hp->lock, hvc_flags); | ||
531 | |||
532 | tty_do_resize(tty, tty, &ws); | ||
533 | tty_kref_put(tty); | ||
534 | } | ||
535 | |||
497 | /* | 536 | /* |
498 | * This is actually a contract between the driver and the tty layer outlining | 537 | * This is actually a contract between the driver and the tty layer outlining |
499 | * how much write room the driver can guarantee will be sent OR BUFFERED. This | 538 | * how much write room the driver can guarantee will be sent OR BUFFERED. This |
@@ -638,6 +677,24 @@ int hvc_poll(struct hvc_struct *hp) | |||
638 | } | 677 | } |
639 | EXPORT_SYMBOL_GPL(hvc_poll); | 678 | EXPORT_SYMBOL_GPL(hvc_poll); |
640 | 679 | ||
680 | /** | ||
681 | * hvc_resize() - Update terminal window size information. | ||
682 | * @hp: HVC console pointer | ||
683 | * @ws: Terminal window size structure | ||
684 | * | ||
685 | * Stores the specified window size information in the hvc structure of @hp. | ||
686 | * The function schedule the tty resize update. | ||
687 | * | ||
688 | * Locking: Locking free; the function MUST be called holding hp->lock | ||
689 | */ | ||
690 | void hvc_resize(struct hvc_struct *hp, struct winsize ws) | ||
691 | { | ||
692 | if ((hp->ws.ws_row != ws.ws_row) || (hp->ws.ws_col != ws.ws_col)) { | ||
693 | hp->ws = ws; | ||
694 | schedule_work(&hp->tty_resize); | ||
695 | } | ||
696 | } | ||
697 | |||
641 | /* | 698 | /* |
642 | * This kthread is either polling or interrupt driven. This is determined by | 699 | * This kthread is either polling or interrupt driven. This is determined by |
643 | * calling hvc_poll() who determines whether a console adapter support | 700 | * calling hvc_poll() who determines whether a console adapter support |
@@ -720,6 +777,7 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data, | |||
720 | 777 | ||
721 | kref_init(&hp->kref); | 778 | kref_init(&hp->kref); |
722 | 779 | ||
780 | INIT_WORK(&hp->tty_resize, hvc_set_winsz); | ||
723 | spin_lock_init(&hp->lock); | 781 | spin_lock_init(&hp->lock); |
724 | spin_lock(&hvc_structs_lock); | 782 | spin_lock(&hvc_structs_lock); |
725 | 783 | ||
diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h index ec0e9bb0e5e6..e3359f3c9b2a 100644 --- a/drivers/char/hvc_console.h +++ b/drivers/char/hvc_console.h | |||
@@ -27,6 +27,7 @@ | |||
27 | #ifndef HVC_CONSOLE_H | 27 | #ifndef HVC_CONSOLE_H |
28 | #define HVC_CONSOLE_H | 28 | #define HVC_CONSOLE_H |
29 | #include <linux/kref.h> | 29 | #include <linux/kref.h> |
30 | #include <linux/tty.h> | ||
30 | 31 | ||
31 | /* | 32 | /* |
32 | * This is the max number of console adapters that can/will be found as | 33 | * This is the max number of console adapters that can/will be found as |
@@ -56,6 +57,8 @@ struct hvc_struct { | |||
56 | struct hv_ops *ops; | 57 | struct hv_ops *ops; |
57 | int irq_requested; | 58 | int irq_requested; |
58 | int data; | 59 | int data; |
60 | struct winsize ws; | ||
61 | struct work_struct tty_resize; | ||
59 | struct list_head next; | 62 | struct list_head next; |
60 | struct kref kref; /* ref count & hvc_struct lifetime */ | 63 | struct kref kref; /* ref count & hvc_struct lifetime */ |
61 | }; | 64 | }; |
@@ -84,6 +87,9 @@ extern int __devexit hvc_remove(struct hvc_struct *hp); | |||
84 | int hvc_poll(struct hvc_struct *hp); | 87 | int hvc_poll(struct hvc_struct *hp); |
85 | void hvc_kick(void); | 88 | void hvc_kick(void); |
86 | 89 | ||
90 | /* Resize hvc tty terminal window */ | ||
91 | extern void hvc_resize(struct hvc_struct *hp, struct winsize ws); | ||
92 | |||
87 | /* default notifier for irq based notification */ | 93 | /* default notifier for irq based notification */ |
88 | extern int notifier_add_irq(struct hvc_struct *hp, int data); | 94 | extern int notifier_add_irq(struct hvc_struct *hp, int data); |
89 | extern void notifier_del_irq(struct hvc_struct *hp, int data); | 95 | extern void notifier_del_irq(struct hvc_struct *hp, int data); |