diff options
author | Sven Schnelle <svens@linux.ibm.com> | 2022-11-28 19:22:28 +0100 |
---|---|---|
committer | Heiko Carstens <hca@linux.ibm.com> | 2023-01-09 14:33:56 +0100 |
commit | c17fe081ac1f397feaed6c8a279ebb3f647f359a (patch) | |
tree | 4e04c0c6f5de8c5cad576be6945762e81aba2edc /drivers/s390/char/tty3270.c | |
parent | a21e962e129db40ae08af9fc80ea7babf3632d77 (diff) | |
download | lwn-c17fe081ac1f397feaed6c8a279ebb3f647f359a.tar.gz lwn-c17fe081ac1f397feaed6c8a279ebb3f647f359a.zip |
s390/3270: unify con3270 + tty3270
There were two flavours of 3270 drivers: con3270, which provides a
console driver, and tty3270 providing a tty driver. A user could switch
with PF3 between the two views. While this sounds nice, it's a bit
annoying: If the user enters a command which triggers a kernel message,
he always has to switch back and forth to see the message. Unify both
views to have kernel messages and tty in one screen, like it is on almost
all other platforms. This also has the nice side effect of removing a lot
of duplicate code.
Signed-off-by: Sven Schnelle <svens@linux.ibm.com>
Acked-by: Heiko Carstens <hca@linux.ibm.com>
Tested-by: Niklas Schnelle <schnelle@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Diffstat (limited to 'drivers/s390/char/tty3270.c')
-rw-r--r-- | drivers/s390/char/tty3270.c | 181 |
1 files changed, 158 insertions, 23 deletions
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c index 3ea5df58b64b..1932077e9650 100644 --- a/drivers/s390/char/tty3270.c +++ b/drivers/s390/char/tty3270.c @@ -17,7 +17,8 @@ #include <linux/console.h> #include <linux/interrupt.h> #include <linux/workqueue.h> - +#include <linux/panic_notifier.h> +#include <linux/reboot.h> #include <linux/slab.h> #include <linux/memblock.h> #include <linux/compat.h> @@ -25,19 +26,19 @@ #include <asm/ccwdev.h> #include <asm/cio.h> #include <asm/ebcdic.h> +#include <asm/cpcmd.h> #include <linux/uaccess.h> #include "raw3270.h" -#include "tty3270.h" #include "keyboard.h" #define TTY3270_CHAR_BUF_SIZE 256 #define TTY3270_OUTPUT_BUFFER_SIZE 1024 #define TTY3270_STRING_PAGES 5 -struct tty_driver *tty3270_driver; +static struct tty_driver *tty3270_driver; static int tty3270_max_index; - +static struct tty3270 *condev; static struct raw3270_fn tty3270_fn; struct tty3270_cell { @@ -378,7 +379,7 @@ tty3270_update(struct timer_list *t) return; } - spin_lock(&tp->view.lock); + spin_lock_irq(&tp->view.lock); updated = 0; if (tp->update_flags & TTY_UPDATE_ALL) { tty3270_rebuild_update(tp); @@ -449,7 +450,7 @@ tty3270_update(struct timer_list *t) raw3270_request_reset(wrq); xchg(&tp->write, wrq); } - spin_unlock(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); } /* @@ -481,7 +482,7 @@ tty3270_rcl_backward(struct kbd_data *kbd) struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); struct string *s; - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); if (tp->inattr == TF_INPUT) { if (tp->rcl_walk && tp->rcl_walk->prev != &tp->rcl_lines) tp->rcl_walk = tp->rcl_walk->prev; @@ -496,7 +497,7 @@ tty3270_rcl_backward(struct kbd_data *kbd) tty3270_update_prompt(tp, NULL, 0); tty3270_set_timer(tp, 1); } - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); } /* @@ -519,7 +520,7 @@ tty3270_scroll_forward(struct kbd_data *kbd) struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); int nr_up; - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); nr_up = tp->nr_up - tp->view.rows + 2; if (nr_up < 0) nr_up = 0; @@ -529,7 +530,7 @@ tty3270_scroll_forward(struct kbd_data *kbd) tty3270_update_status(tp); tty3270_set_timer(tp, 1); } - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); } /* @@ -541,7 +542,7 @@ tty3270_scroll_backward(struct kbd_data *kbd) struct tty3270 *tp = container_of(kbd->port, struct tty3270, port); int nr_up; - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); nr_up = tp->nr_up + tp->view.rows - 2; if (nr_up + tp->view.rows - 2 > tp->nr_lines) nr_up = tp->nr_lines - tp->view.rows + 2; @@ -551,7 +552,7 @@ tty3270_scroll_backward(struct kbd_data *kbd) tty3270_update_status(tp); tty3270_set_timer(tp, 1); } - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); } /* @@ -566,7 +567,7 @@ tty3270_read_tasklet(unsigned long data) char *input; int len; - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); /* * Two AID keys are special: For 0x7d (enter) the input line * has to be emitted to the tty and for 0x6d the screen @@ -593,7 +594,7 @@ tty3270_read_tasklet(unsigned long data) tp->update_flags = TTY_UPDATE_ALL; tty3270_set_timer(tp, 1); } - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); /* Start keyboard reset command. */ raw3270_request_reset(tp->kreset); @@ -857,7 +858,7 @@ static void tty3270_resize_work(struct work_struct *work) if (IS_ERR(screen)) return; /* Switch to new output size */ - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); tty3270_blank_screen(tp); oscreen = tp->screen; orows = tp->view.rows; @@ -872,7 +873,7 @@ static void tty3270_resize_work(struct work_struct *work) while (tp->nr_lines < tp->view.rows - 2) tty3270_blank_line(tp); tp->update_flags = TTY_UPDATE_ALL; - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); tty3270_free_screen(oscreen, orows); tty3270_set_timer(tp, 1); /* Informat tty layer about new size */ @@ -969,7 +970,7 @@ tty3270_create_view(int index, struct tty3270 **newtp) rc = raw3270_add_view(&tp->view, &tty3270_fn, index + RAW3270_FIRSTMINOR, - RAW3270_VIEW_LOCK_BH); + RAW3270_VIEW_LOCK_IRQ); if (rc) { tty3270_free_view(tp); return rc; @@ -1648,7 +1649,7 @@ tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty, { int i_msg, i; - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); for (i_msg = 0; !tty->flow.stopped && i_msg < count; i_msg++) { if (tp->esc_state != 0) { /* Continue escape sequence. */ @@ -1710,7 +1711,7 @@ tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty, if (!timer_pending(&tp->timer)) tty3270_set_timer(tp, HZ/10); - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); } /* @@ -1777,7 +1778,7 @@ tty3270_set_termios(struct tty_struct *tty, const struct ktermios *old) tp = tty->driver_data; if (!tp) return; - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); if (L_ICANON(tty)) { new = L_ECHO(tty) ? TF_INPUT: TF_INPUTN; if (new != tp->inattr) { @@ -1786,7 +1787,7 @@ tty3270_set_termios(struct tty_struct *tty, const struct ktermios *old) tty3270_set_timer(tp, 1); } } - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); } /* @@ -1830,7 +1831,7 @@ tty3270_hangup(struct tty_struct *tty) tp = tty->driver_data; if (!tp) return; - spin_lock_bh(&tp->view.lock); + spin_lock_irq(&tp->view.lock); tp->cx = tp->saved_cx = 0; tp->cy = tp->saved_cy = 0; tp->highlight = tp->saved_highlight = TAX_RESET; @@ -1839,7 +1840,7 @@ tty3270_hangup(struct tty_struct *tty) while (tp->nr_lines < tp->view.rows - 2) tty3270_blank_line(tp); tp->update_flags = TTY_UPDATE_ALL; - spin_unlock_bh(&tp->view.lock); + spin_unlock_irq(&tp->view.lock); tty3270_set_timer(tp, 1); } @@ -1965,6 +1966,140 @@ tty3270_exit(void) tty3270_del_views(); } +#if IS_ENABLED(CONFIG_TN3270_CONSOLE) +static void +con3270_write(struct console *co, const char *str, unsigned int count) +{ + struct tty3270 *tp = co->data; + unsigned long flags; + char c; + + spin_lock_irqsave(&tp->view.lock, flags); + while (count--) { + c = *str++; + if (c == 0x0a) { + tty3270_cr(tp); + tty3270_lf(tp); + } else { + if (tp->cx >= tp->view.cols) { + tty3270_cr(tp); + tty3270_lf(tp); + } + tty3270_put_character(tp, c); + tp->cx++; + } + } + spin_unlock_irqrestore(&tp->view.lock, flags); +} + +static struct tty_driver * +con3270_device(struct console *c, int *index) +{ + *index = c->index; + return tty3270_driver; +} + +static void +con3270_wait_write(struct tty3270 *tp) +{ + while (!tp->write) { + raw3270_wait_cons_dev(tp->view.dev); + barrier(); + } +} + +/* + * The below function is called as a panic/reboot notifier before the + * system enters a disabled, endless loop. + * + * Notice we must use the spin_trylock() alternative, to prevent lockups + * in atomic context (panic routine runs with secondary CPUs, local IRQs + * and preemption disabled). + */ +static int con3270_notify(struct notifier_block *self, + unsigned long event, void *data) +{ + struct tty3270 *tp; + unsigned long flags; + + tp = condev; + if (!tp->view.dev) + return NOTIFY_DONE; + if (!raw3270_view_lock_unavailable(&tp->view)) + raw3270_activate_view(&tp->view); + if (!spin_trylock_irqsave(&tp->view.lock, flags)) + return NOTIFY_DONE; + con3270_wait_write(tp); + tp->nr_up = 0; + while (tp->update_flags != 0) { + spin_unlock_irqrestore(&tp->view.lock, flags); + tty3270_update(&tp->timer); + spin_lock_irqsave(&tp->view.lock, flags); + con3270_wait_write(tp); + } + spin_unlock_irqrestore(&tp->view.lock, flags); + return NOTIFY_DONE; +} + +static struct notifier_block on_panic_nb = { + .notifier_call = con3270_notify, + .priority = INT_MIN + 1, /* run the callback late */ +}; + +static struct notifier_block on_reboot_nb = { + .notifier_call = con3270_notify, + .priority = INT_MIN + 1, /* run the callback late */ +}; + +static struct console con3270 = { + .name = "tty3270", + .write = con3270_write, + .device = con3270_device, + .flags = CON_PRINTBUFFER, +}; + +static int __init +con3270_init(void) +{ + struct raw3270_view *view; + struct raw3270 *rp; + struct tty3270 *tp; + int rc; + + /* Check if 3270 is to be the console */ + if (!CONSOLE_IS_3270) + return -ENODEV; + + /* Set the console mode for VM */ + if (MACHINE_IS_VM) { + cpcmd("TERM CONMODE 3270", NULL, 0, NULL); + cpcmd("TERM AUTOCR OFF", NULL, 0, NULL); + } + + rp = raw3270_setup_console(); + if (IS_ERR(rp)) + return PTR_ERR(rp); + + /* Check if the tty3270 is already there. */ + view = raw3270_find_view(&tty3270_fn, RAW3270_FIRSTMINOR); + if (IS_ERR(view)) { + rc = tty3270_create_view(0, &tp); + if (rc) + return rc; + } else { + tp = container_of(view, struct tty3270, view); + tp->inattr = TF_INPUT; + } + con3270.data = tp; + condev = tp; + atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb); + register_reboot_notifier(&on_reboot_nb); + register_console(&con3270); + return 0; +} +console_initcall(con3270_init); +#endif + MODULE_LICENSE("GPL"); MODULE_ALIAS_CHARDEV_MAJOR(IBM_TTY3270_MAJOR); |