mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
[PATCH] Serial: Adjust serial locking
This patch changes the way serial ports are locked when getting modem status. This change is necessary because we will need to atomically read the modem status and take action depending on the CTS status. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
This commit is contained in:
parent
a839688362
commit
c5f4644e6c
12 changed files with 29 additions and 41 deletions
|
@ -107,8 +107,8 @@ hardware.
|
||||||
indicate that the signal is permanently active. If RI is
|
indicate that the signal is permanently active. If RI is
|
||||||
not available, the signal should not be indicated as active.
|
not available, the signal should not be indicated as active.
|
||||||
|
|
||||||
Locking: none.
|
Locking: port->lock taken.
|
||||||
Interrupts: caller dependent.
|
Interrupts: locally disabled.
|
||||||
This call must not sleep
|
This call must not sleep
|
||||||
|
|
||||||
stop_tx(port,tty_stop)
|
stop_tx(port,tty_stop)
|
||||||
|
|
|
@ -1376,13 +1376,10 @@ static unsigned int serial8250_tx_empty(struct uart_port *port)
|
||||||
static unsigned int serial8250_get_mctrl(struct uart_port *port)
|
static unsigned int serial8250_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct uart_8250_port *up = (struct uart_8250_port *)port;
|
struct uart_8250_port *up = (struct uart_8250_port *)port;
|
||||||
unsigned long flags;
|
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
spin_lock_irqsave(&up->port.lock, flags);
|
|
||||||
status = serial_in(up, UART_MSR);
|
status = serial_in(up, UART_MSR);
|
||||||
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (status & UART_MSR_DCD)
|
if (status & UART_MSR_DCD)
|
||||||
|
|
|
@ -556,13 +556,10 @@ static unsigned int serial8250_tx_empty(struct uart_port *port)
|
||||||
static unsigned int serial8250_get_mctrl(struct uart_port *port)
|
static unsigned int serial8250_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct uart_8250_port *up = (struct uart_8250_port *)port;
|
struct uart_8250_port *up = (struct uart_8250_port *)port;
|
||||||
unsigned long flags;
|
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
spin_lock_irqsave(&up->port.lock, flags);
|
|
||||||
status = serial_in(up, UART_MSR);
|
status = serial_in(up, UART_MSR);
|
||||||
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (status & UART_MSR_DCD)
|
if (status & UART_MSR_DCD)
|
||||||
|
|
|
@ -518,27 +518,28 @@ static irqreturn_t ip22zilog_interrupt(int irq, void *dev_id, struct pt_regs *re
|
||||||
static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
|
static __inline__ unsigned char ip22zilog_read_channel_status(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct zilog_channel *channel;
|
struct zilog_channel *channel;
|
||||||
unsigned long flags;
|
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
|
|
||||||
spin_lock_irqsave(&port->lock, flags);
|
|
||||||
|
|
||||||
channel = ZILOG_CHANNEL_FROM_PORT(port);
|
channel = ZILOG_CHANNEL_FROM_PORT(port);
|
||||||
status = readb(&channel->control);
|
status = readb(&channel->control);
|
||||||
ZSDELAY();
|
ZSDELAY();
|
||||||
|
|
||||||
spin_unlock_irqrestore(&port->lock, flags);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The port lock is not held. */
|
/* The port lock is not held. */
|
||||||
static unsigned int ip22zilog_tx_empty(struct uart_port *port)
|
static unsigned int ip22zilog_tx_empty(struct uart_port *port)
|
||||||
{
|
{
|
||||||
|
unsigned long flags;
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
|
|
||||||
status = ip22zilog_read_channel_status(port);
|
status = ip22zilog_read_channel_status(port);
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
|
|
||||||
if (status & Tx_BUF_EMP)
|
if (status & Tx_BUF_EMP)
|
||||||
ret = TIOCSER_TEMT;
|
ret = TIOCSER_TEMT;
|
||||||
else
|
else
|
||||||
|
@ -547,7 +548,7 @@ static unsigned int ip22zilog_tx_empty(struct uart_port *port)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The port lock is not held. */
|
/* The port lock is held and interrupts are disabled. */
|
||||||
static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
|
static unsigned int ip22zilog_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
|
|
|
@ -1058,12 +1058,9 @@ mpsc_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
|
struct mpsc_port_info *pi = (struct mpsc_port_info *)port;
|
||||||
u32 mflags, status;
|
u32 mflags, status;
|
||||||
ulong iflags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&pi->port.lock, iflags);
|
|
||||||
status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m :
|
status = (pi->mirror_regs) ? pi->MPSC_CHR_10_m :
|
||||||
readl(pi->mpsc_base + MPSC_CHR_10);
|
readl(pi->mpsc_base + MPSC_CHR_10);
|
||||||
spin_unlock_irqrestore(&pi->port.lock, iflags);
|
|
||||||
|
|
||||||
mflags = 0;
|
mflags = 0;
|
||||||
if (status & 0x1)
|
if (status & 0x1)
|
||||||
|
|
|
@ -604,7 +604,7 @@ static void pmz_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
||||||
/*
|
/*
|
||||||
* Get Modem Control bits (only the input ones, the core will
|
* Get Modem Control bits (only the input ones, the core will
|
||||||
* or that with a cached value of the control ones)
|
* or that with a cached value of the control ones)
|
||||||
* The port lock is not held.
|
* The port lock is held and interrupts are disabled.
|
||||||
*/
|
*/
|
||||||
static unsigned int pmz_get_mctrl(struct uart_port *port)
|
static unsigned int pmz_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
|
@ -615,7 +615,7 @@ static unsigned int pmz_get_mctrl(struct uart_port *port)
|
||||||
if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
|
if (ZS_IS_ASLEEP(uap) || uap->node == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
status = pmz_peek_status(to_pmz(port));
|
status = read_zsreg(uap, R0);
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (status & DCD)
|
if (status & DCD)
|
||||||
|
|
|
@ -274,14 +274,11 @@ static unsigned int serial_pxa_tx_empty(struct uart_port *port)
|
||||||
static unsigned int serial_pxa_get_mctrl(struct uart_port *port)
|
static unsigned int serial_pxa_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct uart_pxa_port *up = (struct uart_pxa_port *)port;
|
struct uart_pxa_port *up = (struct uart_pxa_port *)port;
|
||||||
unsigned long flags;
|
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
|
return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
|
||||||
spin_lock_irqsave(&up->port.lock, flags);
|
|
||||||
status = serial_in(up, UART_MSR);
|
status = serial_in(up, UART_MSR);
|
||||||
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (status & UART_MSR_DCD)
|
if (status & UART_MSR_DCD)
|
||||||
|
|
|
@ -828,7 +828,10 @@ static int uart_tiocmget(struct tty_struct *tty, struct file *file)
|
||||||
if ((!file || !tty_hung_up_p(file)) &&
|
if ((!file || !tty_hung_up_p(file)) &&
|
||||||
!(tty->flags & (1 << TTY_IO_ERROR))) {
|
!(tty->flags & (1 << TTY_IO_ERROR))) {
|
||||||
result = port->mctrl;
|
result = port->mctrl;
|
||||||
|
|
||||||
|
spin_lock_irq(&port->lock);
|
||||||
result |= port->ops->get_mctrl(port);
|
result |= port->ops->get_mctrl(port);
|
||||||
|
spin_unlock_irq(&port->lock);
|
||||||
}
|
}
|
||||||
up(&state->sem);
|
up(&state->sem);
|
||||||
|
|
||||||
|
@ -1369,6 +1372,7 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
|
||||||
DECLARE_WAITQUEUE(wait, current);
|
DECLARE_WAITQUEUE(wait, current);
|
||||||
struct uart_info *info = state->info;
|
struct uart_info *info = state->info;
|
||||||
struct uart_port *port = state->port;
|
struct uart_port *port = state->port;
|
||||||
|
unsigned int mctrl;
|
||||||
|
|
||||||
info->blocked_open++;
|
info->blocked_open++;
|
||||||
state->count--;
|
state->count--;
|
||||||
|
@ -1416,7 +1420,10 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
|
||||||
* and wait for the carrier to indicate that the
|
* and wait for the carrier to indicate that the
|
||||||
* modem is ready for us.
|
* modem is ready for us.
|
||||||
*/
|
*/
|
||||||
if (port->ops->get_mctrl(port) & TIOCM_CAR)
|
spin_lock_irq(&port->lock);
|
||||||
|
mctrl = port->ops->get_mctrl(port);
|
||||||
|
spin_unlock_irq(&port->lock);
|
||||||
|
if (mctrl & TIOCM_CAR)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
up(&state->sem);
|
up(&state->sem);
|
||||||
|
@ -1618,7 +1625,9 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
|
||||||
|
|
||||||
if(capable(CAP_SYS_ADMIN))
|
if(capable(CAP_SYS_ADMIN))
|
||||||
{
|
{
|
||||||
|
spin_lock_irq(&port->lock);
|
||||||
status = port->ops->get_mctrl(port);
|
status = port->ops->get_mctrl(port);
|
||||||
|
spin_unlock_irq(&port->lock);
|
||||||
|
|
||||||
ret += sprintf(buf + ret, " tx:%d rx:%d",
|
ret += sprintf(buf + ret, " tx:%d rx:%d",
|
||||||
port->icount.tx, port->icount.rx);
|
port->icount.tx, port->icount.rx);
|
||||||
|
|
|
@ -442,13 +442,10 @@ static unsigned int serial_txx9_tx_empty(struct uart_port *port)
|
||||||
static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
|
static unsigned int serial_txx9_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct uart_txx9_port *up = (struct uart_txx9_port *)port;
|
struct uart_txx9_port *up = (struct uart_txx9_port *)port;
|
||||||
unsigned long flags;
|
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
spin_lock_irqsave(&up->port.lock, flags);
|
|
||||||
ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS)
|
ret = ((sio_in(up, TXX9_SIFLCR) & TXX9_SIFLCR_RTSSC) ? 0 : TIOCM_RTS)
|
||||||
| ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS);
|
| ((sio_in(up, TXX9_SICISR) & TXX9_SICISR_CTSS) ? 0 : TIOCM_CTS);
|
||||||
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,18 +426,15 @@ static void sunsab_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
||||||
sunsab_tx_idle(up);
|
sunsab_tx_idle(up);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* port->lock is not held. */
|
/* port->lock is held by caller and interrupts are disabled. */
|
||||||
static unsigned int sunsab_get_mctrl(struct uart_port *port)
|
static unsigned int sunsab_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
|
struct uart_sunsab_port *up = (struct uart_sunsab_port *) port;
|
||||||
unsigned long flags;
|
|
||||||
unsigned char val;
|
unsigned char val;
|
||||||
unsigned int result;
|
unsigned int result;
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
spin_lock_irqsave(&up->port.lock, flags);
|
|
||||||
|
|
||||||
val = readb(&up->regs->r.pvr);
|
val = readb(&up->regs->r.pvr);
|
||||||
result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR;
|
result |= (val & up->pvr_dsr_bit) ? 0 : TIOCM_DSR;
|
||||||
|
|
||||||
|
@ -447,8 +444,6 @@ static unsigned int sunsab_get_mctrl(struct uart_port *port)
|
||||||
val = readb(&up->regs->r.star);
|
val = readb(&up->regs->r.star);
|
||||||
result |= (val & SAB82532_STAR_CTS) ? TIOCM_CTS : 0;
|
result |= (val & SAB82532_STAR_CTS) ? TIOCM_CTS : 0;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -572,13 +572,10 @@ static unsigned int sunsu_tx_empty(struct uart_port *port)
|
||||||
static unsigned int sunsu_get_mctrl(struct uart_port *port)
|
static unsigned int sunsu_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
||||||
unsigned long flags;
|
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
spin_lock_irqsave(&up->port.lock, flags);
|
|
||||||
status = serial_in(up, UART_MSR);
|
status = serial_in(up, UART_MSR);
|
||||||
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
if (status & UART_MSR_DCD)
|
if (status & UART_MSR_DCD)
|
||||||
|
|
|
@ -610,27 +610,28 @@ static irqreturn_t sunzilog_interrupt(int irq, void *dev_id, struct pt_regs *reg
|
||||||
static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port)
|
static __inline__ unsigned char sunzilog_read_channel_status(struct uart_port *port)
|
||||||
{
|
{
|
||||||
struct zilog_channel __iomem *channel;
|
struct zilog_channel __iomem *channel;
|
||||||
unsigned long flags;
|
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
|
|
||||||
spin_lock_irqsave(&port->lock, flags);
|
|
||||||
|
|
||||||
channel = ZILOG_CHANNEL_FROM_PORT(port);
|
channel = ZILOG_CHANNEL_FROM_PORT(port);
|
||||||
status = sbus_readb(&channel->control);
|
status = sbus_readb(&channel->control);
|
||||||
ZSDELAY();
|
ZSDELAY();
|
||||||
|
|
||||||
spin_unlock_irqrestore(&port->lock, flags);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The port lock is not held. */
|
/* The port lock is not held. */
|
||||||
static unsigned int sunzilog_tx_empty(struct uart_port *port)
|
static unsigned int sunzilog_tx_empty(struct uart_port *port)
|
||||||
{
|
{
|
||||||
|
unsigned long flags;
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
unsigned int ret;
|
unsigned int ret;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
|
|
||||||
status = sunzilog_read_channel_status(port);
|
status = sunzilog_read_channel_status(port);
|
||||||
|
|
||||||
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
|
|
||||||
if (status & Tx_BUF_EMP)
|
if (status & Tx_BUF_EMP)
|
||||||
ret = TIOCSER_TEMT;
|
ret = TIOCSER_TEMT;
|
||||||
else
|
else
|
||||||
|
@ -639,7 +640,7 @@ static unsigned int sunzilog_tx_empty(struct uart_port *port)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The port lock is not held. */
|
/* The port lock is held and interrupts are disabled. */
|
||||||
static unsigned int sunzilog_get_mctrl(struct uart_port *port)
|
static unsigned int sunzilog_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
unsigned char status;
|
unsigned char status;
|
||||||
|
|
Loading…
Reference in a new issue