forked from mirrors/linux
		
	serial_core: Move sysrq functions from header file
It's not worth to have them in every serial driver and I'm about to add another helper function. Signed-off-by: Dmitry Safonov <dima@arista.com> Link: https://lore.kernel.org/r/20200109215444.95995-2-dima@arista.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
		
							parent
							
								
									8c44f9b566
								
							
						
					
					
						commit
						8e20fc3917
					
				
					 2 changed files with 88 additions and 79 deletions
				
			
		| 
						 | 
					@ -3082,6 +3082,89 @@ void uart_insert_char(struct uart_port *port, unsigned int status,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(uart_insert_char);
 | 
					EXPORT_SYMBOL_GPL(uart_insert_char);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!IS_ENABLED(CONFIG_MAGIC_SYSRQ_SERIAL))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!port->has_sysrq || !port->sysrq)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ch && time_before(jiffies, port->sysrq)) {
 | 
				
			||||||
 | 
							handle_sysrq(ch);
 | 
				
			||||||
 | 
							port->sysrq = 0;
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						port->sysrq = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(uart_handle_sysrq_char);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (!IS_ENABLED(CONFIG_MAGIC_SYSRQ_SERIAL))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!port->has_sysrq || !port->sysrq)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (ch && time_before(jiffies, port->sysrq)) {
 | 
				
			||||||
 | 
							port->sysrq_ch = ch;
 | 
				
			||||||
 | 
							port->sysrq = 0;
 | 
				
			||||||
 | 
							return 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						port->sysrq = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(uart_prepare_sysrq_char);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int sysrq_ch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!port->has_sysrq) {
 | 
				
			||||||
 | 
							spin_unlock_irqrestore(&port->lock, irqflags);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						sysrq_ch = port->sysrq_ch;
 | 
				
			||||||
 | 
						port->sysrq_ch = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						spin_unlock_irqrestore(&port->lock, irqflags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (sysrq_ch)
 | 
				
			||||||
 | 
							handle_sysrq(sysrq_ch);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(uart_unlock_and_check_sysrq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * We do the SysRQ and SAK checking like this...
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					int uart_handle_break(struct uart_port *port)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct uart_state *state = port->state;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (port->handle_break)
 | 
				
			||||||
 | 
							port->handle_break(port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (port->has_sysrq) {
 | 
				
			||||||
 | 
							if (port->cons && port->cons->index == port->line) {
 | 
				
			||||||
 | 
								if (!port->sysrq) {
 | 
				
			||||||
 | 
									port->sysrq = jiffies + HZ*5;
 | 
				
			||||||
 | 
									return 1;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								port->sysrq = 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (port->flags & UPF_SAK)
 | 
				
			||||||
 | 
							do_SAK(state->port.tty);
 | 
				
			||||||
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					EXPORT_SYMBOL_GPL(uart_handle_break);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EXPORT_SYMBOL(uart_write_wakeup);
 | 
					EXPORT_SYMBOL(uart_write_wakeup);
 | 
				
			||||||
EXPORT_SYMBOL(uart_register_driver);
 | 
					EXPORT_SYMBOL(uart_register_driver);
 | 
				
			||||||
EXPORT_SYMBOL(uart_unregister_driver);
 | 
					EXPORT_SYMBOL(uart_unregister_driver);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -460,85 +460,11 @@ extern void uart_handle_cts_change(struct uart_port *uport,
 | 
				
			||||||
extern void uart_insert_char(struct uart_port *port, unsigned int status,
 | 
					extern void uart_insert_char(struct uart_port *port, unsigned int status,
 | 
				
			||||||
		 unsigned int overrun, unsigned int ch, unsigned int flag);
 | 
							 unsigned int overrun, unsigned int ch, unsigned int flag);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static inline int
 | 
					extern int uart_handle_sysrq_char(struct uart_port *port, unsigned int ch);
 | 
				
			||||||
uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
 | 
					extern int uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch);
 | 
				
			||||||
{
 | 
					extern void uart_unlock_and_check_sysrq(struct uart_port *port,
 | 
				
			||||||
	if (!IS_ENABLED(CONFIG_MAGIC_SYSRQ_SERIAL))
 | 
										unsigned long irqflags);
 | 
				
			||||||
		return 0;
 | 
					extern int uart_handle_break(struct uart_port *port);
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!port->has_sysrq || !port->sysrq)
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (ch && time_before(jiffies, port->sysrq)) {
 | 
					 | 
				
			||||||
		handle_sysrq(ch);
 | 
					 | 
				
			||||||
		port->sysrq = 0;
 | 
					 | 
				
			||||||
		return 1;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	port->sysrq = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
static inline int
 | 
					 | 
				
			||||||
uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	if (!IS_ENABLED(CONFIG_MAGIC_SYSRQ_SERIAL))
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!port->has_sysrq || !port->sysrq)
 | 
					 | 
				
			||||||
		return 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (ch && time_before(jiffies, port->sysrq)) {
 | 
					 | 
				
			||||||
		port->sysrq_ch = ch;
 | 
					 | 
				
			||||||
		port->sysrq = 0;
 | 
					 | 
				
			||||||
		return 1;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	port->sysrq = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
static inline void
 | 
					 | 
				
			||||||
uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int sysrq_ch;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!port->has_sysrq) {
 | 
					 | 
				
			||||||
		spin_unlock_irqrestore(&port->lock, irqflags);
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	sysrq_ch = port->sysrq_ch;
 | 
					 | 
				
			||||||
	port->sysrq_ch = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	spin_unlock_irqrestore(&port->lock, irqflags);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (sysrq_ch)
 | 
					 | 
				
			||||||
		handle_sysrq(sysrq_ch);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/*
 | 
					 | 
				
			||||||
 * We do the SysRQ and SAK checking like this...
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static inline int uart_handle_break(struct uart_port *port)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct uart_state *state = port->state;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (port->handle_break)
 | 
					 | 
				
			||||||
		port->handle_break(port);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (port->has_sysrq) {
 | 
					 | 
				
			||||||
		if (port->cons && port->cons->index == port->line) {
 | 
					 | 
				
			||||||
			if (!port->sysrq) {
 | 
					 | 
				
			||||||
				port->sysrq = jiffies + HZ*5;
 | 
					 | 
				
			||||||
				return 1;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			port->sysrq = 0;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (port->flags & UPF_SAK)
 | 
					 | 
				
			||||||
		do_SAK(state->port.tty);
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 *	UART_ENABLE_MS - determine if port should enable modem status irqs
 | 
					 *	UART_ENABLE_MS - determine if port should enable modem status irqs
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue