aboutsummaryrefslogtreecommitdiff
path: root/include/linux
diff options
context:
space:
mode:
authorDaniel Thompson <daniel.thompson@linaro.org>2014-03-28 09:28:11 +0000
committerDaniel Thompson <daniel.thompson@linaro.org>2015-01-05 09:43:38 +0000
commit1b213f2e3b4bf0be4b3db2f77ba2ca3649142d18 (patch)
tree93e3f32aff2357b39688355179eeb8912d6dea09 /include/linux
parentb7392d2247cfe6771f95d256374f1a8e6a6f48d6 (diff)
serial: Emulate break using control characters
Currently the magic SysRq functions are accessed by sending a break. Unfortunately some networked serial proxies makes is difficult to send a break meaning SysRq functions cannot be reached. We avoid this problem by allowing the (fairly unlikely) sequence of ^B^R^K characters to emulate a real break. This approach is very nearly as robust as normal sysrq/break handling because all trigger recognition happens during interrupt handling however to emulate a break we must enter the ISR four times (instead of twice) and manage an extra byte of state. Signed-off-by: Daniel Thompson <daniel.thompson@linaro.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/serial_core.h83
1 files changed, 65 insertions, 18 deletions
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 057038cf2788..3dff1a7437b8 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -158,6 +158,9 @@ struct uart_port {
struct console *cons; /* struct console, if any */
#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(SUPPORT_SYSRQ)
unsigned long sysrq; /* sysrq timeout */
+#ifdef CONFIG_MAGIC_SYSRQ_BREAK_EMULATION
+ char sysrq_emul; /* sysrq break emulation */
+#endif
#endif
/* flags must be updated while holding port mutex */
@@ -403,24 +406,6 @@ extern void uart_handle_cts_change(struct uart_port *uport,
extern void uart_insert_char(struct uart_port *port, unsigned int status,
unsigned int overrun, unsigned int ch, unsigned int flag);
-#ifdef SUPPORT_SYSRQ
-static inline int
-uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
-{
- if (port->sysrq) {
- if (ch && time_before(jiffies, port->sysrq)) {
- handle_sysrq(ch);
- port->sysrq = 0;
- return 1;
- }
- port->sysrq = 0;
- }
- return 0;
-}
-#else
-#define uart_handle_sysrq_char(port,ch) ({ (void)port; 0; })
-#endif
-
/*
* We do the SysRQ and SAK checking like this...
*/
@@ -445,6 +430,68 @@ static inline int uart_handle_break(struct uart_port *port)
return 0;
}
+#if defined(SUPPORT_SYSRQ) && defined(CONFIG_MAGIC_SYSRQ_BREAK_EMULATION)
+/*
+ * Emulate a break if we are the serial console and receive ^B, ^R, ^K.
+ */
+static inline int
+uart_handle_sysrq_break_emulation(struct uart_port *port, unsigned int ch)
+{
+ const unsigned int ctrlb = 'B' & 31;
+ const unsigned int ctrlr = 'R' & 31;
+ const unsigned int ctrlk = 'K' & 31;
+
+ if (uart_console(port)) {
+ if ((port->sysrq_emul == 0 && ch == ctrlb) ||
+ (port->sysrq_emul == ctrlb && ch == ctrlr)) {
+ /* for either of the first two trigger characters
+ * update the state variable and move on.
+ */
+ port->sysrq_emul = ch;
+ return 1;
+ } else if (port->sysrq_emul == ctrlr &&
+ ch == ctrlk && uart_handle_break(port)) {
+ /* the break has already been emulated whilst
+ * evaluating the condition, tidy up and move on
+ */
+ port->sysrq_emul = 0;
+ return 1;
+ }
+ }
+
+ if (port->sysrq_emul) {
+ /* received a partial (false) trigger, tidy up and move on */
+ uart_insert_char(port, 0, 0, ctrlb, TTY_NORMAL);
+ if (port->sysrq_emul == ctrlr)
+ uart_insert_char(port, 0, 0, ctrlr, TTY_NORMAL);
+ port->sysrq_emul = 0;
+ }
+
+ return 0;
+}
+#else
+#define uart_handle_sysrq_break_emulation(port,ch) ({ (void)port; 0; })
+#endif
+
+#ifdef SUPPORT_SYSRQ
+static inline int
+uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
+{
+ if (port->sysrq) {
+ if (ch && time_before(jiffies, port->sysrq)) {
+ handle_sysrq(ch);
+ port->sysrq = 0;
+ return 1;
+ }
+ port->sysrq = 0;
+ }
+
+ return uart_handle_sysrq_break_emulation(port, ch);
+}
+#else
+#define uart_handle_sysrq_char(port,ch) ({ (void)port; 0; })
+#endif
+
/*
* UART_ENABLE_MS - determine if port should enable modem status irqs
*/