2017-11-07 00:11:51 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
** mux.c:
|
|
|
|
** serial driver for the Mux console found in some PA-RISC servers.
|
|
|
|
**
|
|
|
|
** (c) Copyright 2002 Ryan Bradetich
|
|
|
|
** (c) Copyright 2002 Hewlett-Packard Company
|
|
|
|
**
|
|
|
|
** This Driver currently only supports the console (port 0) on the MUX.
|
|
|
|
** Additional work will be needed on this driver to enable the full
|
|
|
|
** functionality of the MUX.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/serial.h>
|
2011-09-01 21:20:57 +07:00
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/delay.h> /* for udelay */
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <asm/io.h>
|
2005-10-22 09:58:03 +07:00
|
|
|
#include <asm/irq.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/parisc-device.h>
|
|
|
|
|
|
|
|
#include <linux/sysrq.h>
|
|
|
|
#include <linux/serial_core.h>
|
|
|
|
|
|
|
|
#define MUX_OFFSET 0x800
|
|
|
|
#define MUX_LINE_OFFSET 0x80
|
|
|
|
|
|
|
|
#define MUX_FIFO_SIZE 255
|
|
|
|
#define MUX_POLL_DELAY (30 * HZ / 1000)
|
|
|
|
|
|
|
|
#define IO_DATA_REG_OFFSET 0x3c
|
|
|
|
#define IO_DCOUNT_REG_OFFSET 0x40
|
|
|
|
|
|
|
|
#define MUX_EOFIFO(status) ((status & 0xF000) == 0xF000)
|
|
|
|
#define MUX_STATUS(status) ((status & 0xF000) == 0x8000)
|
|
|
|
#define MUX_BREAK(status) ((status & 0xF000) == 0x2000)
|
|
|
|
|
|
|
|
#define MUX_NR 256
|
2006-03-28 02:52:15 +07:00
|
|
|
static unsigned int port_cnt __read_mostly;
|
2006-11-03 12:38:39 +07:00
|
|
|
struct mux_port {
|
|
|
|
struct uart_port port;
|
|
|
|
int enabled;
|
|
|
|
};
|
|
|
|
static struct mux_port mux_ports[MUX_NR];
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
static struct uart_driver mux_driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.driver_name = "ttyB",
|
|
|
|
.dev_name = "ttyB",
|
|
|
|
.major = MUX_MAJOR,
|
|
|
|
.minor = 0,
|
|
|
|
.nr = MUX_NR,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct timer_list mux_timer;
|
|
|
|
|
2005-11-18 04:36:52 +07:00
|
|
|
#define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + IO_DATA_REG_OFFSET)
|
|
|
|
#define UART_GET_FIFO_CNT(p) __raw_readl((p)->membase + IO_DCOUNT_REG_OFFSET)
|
2006-11-10 10:08:45 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* get_mux_port_count - Get the number of available ports on the Mux.
|
|
|
|
* @dev: The parisc device.
|
|
|
|
*
|
|
|
|
* This function is used to determine the number of ports the Mux
|
|
|
|
* supports. The IODC data reports the number of ports the Mux
|
|
|
|
* can support, but there are cases where not all the Mux ports
|
|
|
|
* are connected. This function can override the IODC and
|
|
|
|
* return the true port count.
|
|
|
|
*/
|
|
|
|
static int __init get_mux_port_count(struct parisc_device *dev)
|
|
|
|
{
|
2006-11-10 11:06:14 +07:00
|
|
|
int status;
|
2006-11-10 10:08:45 +07:00
|
|
|
u8 iodc_data[32];
|
|
|
|
unsigned long bytecnt;
|
|
|
|
|
|
|
|
/* If this is the built-in Mux for the K-Class (Eole CAP/MUX),
|
|
|
|
* we only need to allocate resources for 1 port since the
|
|
|
|
* other 7 ports are not connected.
|
|
|
|
*/
|
2006-11-10 11:06:14 +07:00
|
|
|
if(dev->id.hversion == 0x15)
|
2006-11-10 10:08:45 +07:00
|
|
|
return 1;
|
|
|
|
|
2006-11-10 11:06:14 +07:00
|
|
|
status = pdc_iodc_read(&bytecnt, dev->hpa.start, 0, iodc_data, 32);
|
|
|
|
BUG_ON(status != PDC_OK);
|
|
|
|
|
2006-11-10 10:08:45 +07:00
|
|
|
/* Return the number of ports specified in the iodc data. */
|
|
|
|
return ((((iodc_data)[4] & 0xf0) >> 4) * 8) + 8;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_tx_empty - Check if the transmitter fifo is empty.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* This function test if the transmitter fifo for the port
|
|
|
|
* described by 'port' is empty. If it is empty, this function
|
|
|
|
* should return TIOCSER_TEMT, otherwise return 0.
|
|
|
|
*/
|
|
|
|
static unsigned int mux_tx_empty(struct uart_port *port)
|
|
|
|
{
|
2005-11-18 04:36:52 +07:00
|
|
|
return UART_GET_FIFO_CNT(port) ? 0 : TIOCSER_TEMT;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_set_mctrl - Set the current state of the modem control inputs.
|
|
|
|
* @ports: Ptr to the uart_port.
|
|
|
|
* @mctrl: Modem control bits.
|
|
|
|
*
|
|
|
|
* The Serial MUX does not support CTS, DCD or DSR so this function
|
|
|
|
* is ignored.
|
|
|
|
*/
|
|
|
|
static void mux_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_get_mctrl - Returns the current state of modem control inputs.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* The Serial MUX does not support CTS, DCD or DSR so these lines are
|
|
|
|
* treated as permanently active.
|
|
|
|
*/
|
|
|
|
static unsigned int mux_get_mctrl(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_stop_tx - Stop transmitting characters.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* The Serial MUX does not support this function.
|
|
|
|
*/
|
2005-08-31 16:12:14 +07:00
|
|
|
static void mux_stop_tx(struct uart_port *port)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_start_tx - Start transmitting characters.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* The Serial Mux does not support this function.
|
|
|
|
*/
|
2005-08-31 16:12:14 +07:00
|
|
|
static void mux_start_tx(struct uart_port *port)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_stop_rx - Stop receiving characters.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* The Serial Mux does not support this function.
|
|
|
|
*/
|
|
|
|
static void mux_stop_rx(struct uart_port *port)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_break_ctl - Control the transmitssion of a break signal.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
* @break_state: Raise/Lower the break signal.
|
|
|
|
*
|
|
|
|
* The Serial Mux does not support this function.
|
|
|
|
*/
|
|
|
|
static void mux_break_ctl(struct uart_port *port, int break_state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_write - Write chars to the mux fifo.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* This function writes all the data from the uart buffer to
|
|
|
|
* the mux fifo.
|
|
|
|
*/
|
|
|
|
static void mux_write(struct uart_port *port)
|
|
|
|
{
|
|
|
|
int count;
|
2009-09-20 03:13:28 +07:00
|
|
|
struct circ_buf *xmit = &port->state->xmit;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if(port->x_char) {
|
|
|
|
UART_PUT_CHAR(port, port->x_char);
|
|
|
|
port->icount.tx++;
|
|
|
|
port->x_char = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(uart_circ_empty(xmit) || uart_tx_stopped(port)) {
|
2005-08-31 16:12:14 +07:00
|
|
|
mux_stop_tx(port);
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = (port->fifosize) - UART_GET_FIFO_CNT(port);
|
|
|
|
do {
|
|
|
|
UART_PUT_CHAR(port, xmit->buf[xmit->tail]);
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
port->icount.tx++;
|
|
|
|
if(uart_circ_empty(xmit))
|
|
|
|
break;
|
|
|
|
|
|
|
|
} while(--count > 0);
|
|
|
|
|
|
|
|
while(UART_GET_FIFO_CNT(port))
|
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
if(uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(port);
|
|
|
|
|
|
|
|
if (uart_circ_empty(xmit))
|
2005-08-31 16:12:14 +07:00
|
|
|
mux_stop_tx(port);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_read - Read chars from the mux fifo.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* This reads all available data from the mux's fifo and pushes
|
|
|
|
* the data to the tty layer.
|
|
|
|
*/
|
|
|
|
static void mux_read(struct uart_port *port)
|
|
|
|
{
|
2013-01-03 21:53:03 +07:00
|
|
|
struct tty_port *tport = &port->state->port;
|
2005-04-17 05:20:36 +07:00
|
|
|
int data;
|
|
|
|
__u32 start_count = port->icount.rx;
|
|
|
|
|
|
|
|
while(1) {
|
2005-11-18 04:36:52 +07:00
|
|
|
data = __raw_readl(port->membase + IO_DATA_REG_OFFSET);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if (MUX_STATUS(data))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (MUX_EOFIFO(data))
|
|
|
|
break;
|
|
|
|
|
|
|
|
port->icount.rx++;
|
|
|
|
|
|
|
|
if (MUX_BREAK(data)) {
|
|
|
|
port->icount.brk++;
|
|
|
|
if(uart_handle_break(port))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-10-07 09:47:23 +07:00
|
|
|
if (uart_handle_sysrq_char(port, data & 0xffu))
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
|
|
|
|
2013-01-03 21:53:03 +07:00
|
|
|
tty_insert_flip_char(tport, data & 0xFF, TTY_NORMAL);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2013-01-03 21:53:06 +07:00
|
|
|
if (start_count != port->icount.rx)
|
|
|
|
tty_flip_buffer_push(tport);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_startup - Initialize the port.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* Grab any resources needed for this port and start the
|
|
|
|
* mux timer.
|
|
|
|
*/
|
|
|
|
static int mux_startup(struct uart_port *port)
|
|
|
|
{
|
2006-11-03 12:38:39 +07:00
|
|
|
mux_ports[port->line].enabled = 1;
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_shutdown - Disable the port.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* Release any resources needed for the port.
|
|
|
|
*/
|
|
|
|
static void mux_shutdown(struct uart_port *port)
|
|
|
|
{
|
2006-11-03 12:38:39 +07:00
|
|
|
mux_ports[port->line].enabled = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_set_termios - Chane port parameters.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
* @termios: new termios settings.
|
|
|
|
* @old: old termios settings.
|
|
|
|
*
|
|
|
|
* The Serial Mux does not support this function.
|
|
|
|
*/
|
|
|
|
static void
|
2006-12-08 17:38:45 +07:00
|
|
|
mux_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_type - Describe the port.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* Return a pointer to a string constant describing the
|
|
|
|
* specified port.
|
|
|
|
*/
|
|
|
|
static const char *mux_type(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return "Mux";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_release_port - Release memory and IO regions.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* Release any memory and IO region resources currently in use by
|
|
|
|
* the port.
|
|
|
|
*/
|
|
|
|
static void mux_release_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_request_port - Request memory and IO regions.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
*
|
|
|
|
* Request any memory and IO region resources required by the port.
|
|
|
|
* If any fail, no resources should be registered when this function
|
|
|
|
* returns, and it should return -EBUSY on failure.
|
|
|
|
*/
|
|
|
|
static int mux_request_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_config_port - Perform port autoconfiguration.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
* @type: Bitmask of required configurations.
|
|
|
|
*
|
2006-11-03 12:38:39 +07:00
|
|
|
* Perform any autoconfiguration steps for the port. This function is
|
2005-04-17 05:20:36 +07:00
|
|
|
* called if the UPF_BOOT_AUTOCONF flag is specified for the port.
|
|
|
|
* [Note: This is required for now because of a bug in the Serial core.
|
|
|
|
* rmk has already submitted a patch to linus, should be available for
|
|
|
|
* 2.5.47.]
|
|
|
|
*/
|
|
|
|
static void mux_config_port(struct uart_port *port, int type)
|
|
|
|
{
|
|
|
|
port->type = PORT_MUX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_verify_port - Verify the port information.
|
|
|
|
* @port: Ptr to the uart_port.
|
|
|
|
* @ser: Ptr to the serial information.
|
|
|
|
*
|
|
|
|
* Verify the new serial port information contained within serinfo is
|
|
|
|
* suitable for this port type.
|
|
|
|
*/
|
|
|
|
static int mux_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|
|
|
{
|
|
|
|
if(port->membase == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_drv_poll - Mux poll function.
|
|
|
|
* @unused: Unused variable
|
|
|
|
*
|
|
|
|
* This function periodically polls the Serial MUX to check for new data.
|
|
|
|
*/
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-17 04:43:17 +07:00
|
|
|
static void mux_poll(struct timer_list *unused)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < port_cnt; ++i) {
|
2006-11-03 12:38:39 +07:00
|
|
|
if(!mux_ports[i].enabled)
|
2005-04-17 05:20:36 +07:00
|
|
|
continue;
|
|
|
|
|
2006-11-03 12:38:39 +07:00
|
|
|
mux_read(&mux_ports[i].port);
|
|
|
|
mux_write(&mux_ports[i].port);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_MUX_CONSOLE
|
|
|
|
static void mux_console_write(struct console *co, const char *s, unsigned count)
|
|
|
|
{
|
2006-11-03 12:52:41 +07:00
|
|
|
/* Wait until the FIFO drains. */
|
|
|
|
while(UART_GET_FIFO_CNT(&mux_ports[0].port))
|
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
while(count--) {
|
|
|
|
if(*s == '\n') {
|
|
|
|
UART_PUT_CHAR(&mux_ports[0].port, '\r');
|
|
|
|
}
|
|
|
|
UART_PUT_CHAR(&mux_ports[0].port, *s++);
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mux_console_setup(struct console *co, char *options)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct console mux_console = {
|
|
|
|
.name = "ttyB",
|
|
|
|
.write = mux_console_write,
|
2015-09-19 10:43:07 +07:00
|
|
|
.device = uart_console_device,
|
2005-04-17 05:20:36 +07:00
|
|
|
.setup = mux_console_setup,
|
|
|
|
.flags = CON_ENABLED | CON_PRINTBUFFER,
|
|
|
|
.index = 0,
|
2015-09-19 10:43:07 +07:00
|
|
|
.data = &mux_driver,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MUX_CONSOLE &mux_console
|
|
|
|
#else
|
|
|
|
#define MUX_CONSOLE NULL
|
|
|
|
#endif
|
|
|
|
|
2017-08-13 13:21:50 +07:00
|
|
|
static const struct uart_ops mux_pops = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.tx_empty = mux_tx_empty,
|
|
|
|
.set_mctrl = mux_set_mctrl,
|
|
|
|
.get_mctrl = mux_get_mctrl,
|
|
|
|
.stop_tx = mux_stop_tx,
|
|
|
|
.start_tx = mux_start_tx,
|
|
|
|
.stop_rx = mux_stop_rx,
|
|
|
|
.break_ctl = mux_break_ctl,
|
|
|
|
.startup = mux_startup,
|
|
|
|
.shutdown = mux_shutdown,
|
|
|
|
.set_termios = mux_set_termios,
|
|
|
|
.type = mux_type,
|
|
|
|
.release_port = mux_release_port,
|
|
|
|
.request_port = mux_request_port,
|
|
|
|
.config_port = mux_config_port,
|
|
|
|
.verify_port = mux_verify_port,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_probe - Determine if the Serial Mux should claim this device.
|
|
|
|
* @dev: The parisc device.
|
|
|
|
*
|
|
|
|
* Deterimine if the Serial Mux should claim this chip (return 0)
|
|
|
|
* or not (return 1).
|
|
|
|
*/
|
|
|
|
static int __init mux_probe(struct parisc_device *dev)
|
|
|
|
{
|
2006-11-10 10:08:45 +07:00
|
|
|
int i, status;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-11-10 10:08:45 +07:00
|
|
|
int port_count = get_mux_port_count(dev);
|
2006-11-09 11:45:08 +07:00
|
|
|
printk(KERN_INFO "Serial mux driver (%d ports) Revision: 0.6\n", port_count);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2006-11-05 08:21:44 +07:00
|
|
|
dev_set_drvdata(&dev->dev, (void *)(long)port_count);
|
|
|
|
request_mem_region(dev->hpa.start + MUX_OFFSET,
|
|
|
|
port_count * MUX_LINE_OFFSET, "Mux");
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
if(!port_cnt) {
|
|
|
|
mux_driver.cons = MUX_CONSOLE;
|
|
|
|
|
|
|
|
status = uart_register_driver(&mux_driver);
|
|
|
|
if(status) {
|
|
|
|
printk(KERN_ERR "Serial mux: Unable to register driver.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-05 08:21:44 +07:00
|
|
|
for(i = 0; i < port_count; ++i, ++port_cnt) {
|
|
|
|
struct uart_port *port = &mux_ports[port_cnt].port;
|
2005-04-17 05:20:36 +07:00
|
|
|
port->iobase = 0;
|
2005-10-22 09:58:03 +07:00
|
|
|
port->mapbase = dev->hpa.start + MUX_OFFSET +
|
|
|
|
(i * MUX_LINE_OFFSET);
|
2020-01-06 15:43:50 +07:00
|
|
|
port->membase = ioremap(port->mapbase, MUX_LINE_OFFSET);
|
2006-02-05 17:48:10 +07:00
|
|
|
port->iotype = UPIO_MEM;
|
2005-04-17 05:20:36 +07:00
|
|
|
port->type = PORT_MUX;
|
2012-01-27 00:44:09 +07:00
|
|
|
port->irq = 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
port->uartclk = 0;
|
|
|
|
port->fifosize = MUX_FIFO_SIZE;
|
|
|
|
port->ops = &mux_pops;
|
|
|
|
port->flags = UPF_BOOT_AUTOCONF;
|
|
|
|
port->line = port_cnt;
|
2019-12-13 07:06:25 +07:00
|
|
|
port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_MUX_CONSOLE);
|
2005-11-18 04:38:28 +07:00
|
|
|
|
|
|
|
/* The port->timeout needs to match what is present in
|
|
|
|
* uart_wait_until_sent in serial_core.c. Otherwise
|
|
|
|
* the time spent in msleep_interruptable will be very
|
|
|
|
* long, causing the appearance of a console hang.
|
|
|
|
*/
|
|
|
|
port->timeout = HZ / 50;
|
2005-10-22 09:58:03 +07:00
|
|
|
spin_lock_init(&port->lock);
|
2006-11-09 11:45:08 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
status = uart_add_one_port(&mux_driver, port);
|
|
|
|
BUG_ON(status);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-22 02:55:11 +07:00
|
|
|
static int __exit mux_remove(struct parisc_device *dev)
|
2006-11-05 08:21:44 +07:00
|
|
|
{
|
2006-11-09 11:45:08 +07:00
|
|
|
int i, j;
|
2006-11-05 08:21:44 +07:00
|
|
|
int port_count = (long)dev_get_drvdata(&dev->dev);
|
|
|
|
|
|
|
|
/* Find Port 0 for this card in the mux_ports list. */
|
|
|
|
for(i = 0; i < port_cnt; ++i) {
|
|
|
|
if(mux_ports[i].port.mapbase == dev->hpa.start + MUX_OFFSET)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
BUG_ON(i + port_count > port_cnt);
|
|
|
|
|
|
|
|
/* Release the resources associated with each port on the device. */
|
2006-11-09 11:45:08 +07:00
|
|
|
for(j = 0; j < port_count; ++j, ++i) {
|
2006-11-05 08:21:44 +07:00
|
|
|
struct uart_port *port = &mux_ports[i].port;
|
|
|
|
|
|
|
|
uart_remove_one_port(&mux_driver, port);
|
|
|
|
if(port->membase)
|
|
|
|
iounmap(port->membase);
|
|
|
|
}
|
|
|
|
|
|
|
|
release_mem_region(dev->hpa.start + MUX_OFFSET, port_count * MUX_LINE_OFFSET);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-09 11:45:08 +07:00
|
|
|
/* Hack. This idea was taken from the 8250_gsc.c on how to properly order
|
|
|
|
* the serial port detection in the proper order. The idea is we always
|
|
|
|
* want the builtin mux to be detected before addin mux cards, so we
|
|
|
|
* specifically probe for the builtin mux cards first.
|
|
|
|
*
|
|
|
|
* This table only contains the parisc_device_id of known builtin mux
|
|
|
|
* devices. All other mux cards will be detected by the generic mux_tbl.
|
|
|
|
*/
|
2017-08-22 02:55:11 +07:00
|
|
|
static const struct parisc_device_id builtin_mux_tbl[] __initconst = {
|
2006-11-09 11:45:08 +07:00
|
|
|
{ HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x15, 0x0000D }, /* All K-class */
|
|
|
|
{ HPHW_A_DIRECT, HVERSION_REV_ANY_ID, 0x44, 0x0000D }, /* E35, E45, and E55 */
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
2017-08-22 02:55:11 +07:00
|
|
|
static const struct parisc_device_id mux_tbl[] __initconst = {
|
2005-04-17 05:20:36 +07:00
|
|
|
{ HPHW_A_DIRECT, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x0000D },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
2006-11-09 11:45:08 +07:00
|
|
|
MODULE_DEVICE_TABLE(parisc, builtin_mux_tbl);
|
2005-04-17 05:20:36 +07:00
|
|
|
MODULE_DEVICE_TABLE(parisc, mux_tbl);
|
|
|
|
|
2017-08-22 02:55:11 +07:00
|
|
|
static struct parisc_driver builtin_serial_mux_driver __refdata = {
|
2006-11-09 11:45:08 +07:00
|
|
|
.name = "builtin_serial_mux",
|
|
|
|
.id_table = builtin_mux_tbl,
|
|
|
|
.probe = mux_probe,
|
2017-08-22 02:55:11 +07:00
|
|
|
.remove = __exit_p(mux_remove),
|
2006-11-09 11:45:08 +07:00
|
|
|
};
|
|
|
|
|
2017-08-22 02:55:11 +07:00
|
|
|
static struct parisc_driver serial_mux_driver __refdata = {
|
2005-10-22 09:36:23 +07:00
|
|
|
.name = "serial_mux",
|
2005-04-17 05:20:36 +07:00
|
|
|
.id_table = mux_tbl,
|
|
|
|
.probe = mux_probe,
|
2017-08-22 02:55:11 +07:00
|
|
|
.remove = __exit_p(mux_remove),
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2008-02-03 22:29:25 +07:00
|
|
|
* mux_init - Serial MUX initialization procedure.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Register the Serial MUX driver.
|
|
|
|
*/
|
|
|
|
static int __init mux_init(void)
|
|
|
|
{
|
2006-11-09 11:45:08 +07:00
|
|
|
register_parisc_driver(&builtin_serial_mux_driver);
|
|
|
|
register_parisc_driver(&serial_mux_driver);
|
2006-11-05 08:21:44 +07:00
|
|
|
|
|
|
|
if(port_cnt > 0) {
|
|
|
|
/* Start the Mux timer */
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-17 04:43:17 +07:00
|
|
|
timer_setup(&mux_timer, mux_poll, 0);
|
2006-11-05 08:21:44 +07:00
|
|
|
mod_timer(&mux_timer, jiffies + MUX_POLL_DELAY);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_MUX_CONSOLE
|
|
|
|
register_console(&mux_console);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-11-09 11:45:08 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* mux_exit - Serial MUX cleanup procedure.
|
|
|
|
*
|
|
|
|
* Unregister the Serial MUX driver from the tty layer.
|
|
|
|
*/
|
|
|
|
static void __exit mux_exit(void)
|
|
|
|
{
|
2006-11-05 08:21:44 +07:00
|
|
|
/* Delete the Mux timer. */
|
|
|
|
if(port_cnt > 0) {
|
2014-03-27 04:33:42 +07:00
|
|
|
del_timer_sync(&mux_timer);
|
2006-11-05 08:21:44 +07:00
|
|
|
#ifdef CONFIG_SERIAL_MUX_CONSOLE
|
|
|
|
unregister_console(&mux_console);
|
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2006-11-09 11:45:08 +07:00
|
|
|
unregister_parisc_driver(&builtin_serial_mux_driver);
|
2006-11-05 08:21:44 +07:00
|
|
|
unregister_parisc_driver(&serial_mux_driver);
|
2005-04-17 05:20:36 +07:00
|
|
|
uart_unregister_driver(&mux_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(mux_init);
|
|
|
|
module_exit(mux_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Ryan Bradetich");
|
|
|
|
MODULE_DESCRIPTION("Serial MUX driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_CHARDEV_MAJOR(MUX_MAJOR);
|