2008-07-17 04:53:31 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* su.c: Small serial driver for keyboard/mouse interface on sparc32/PCI
|
|
|
|
*
|
|
|
|
* Copyright (C) 1997 Eddie C. Dost (ecd@skynet.be)
|
|
|
|
* Copyright (C) 1998-1999 Pete Zaitcev (zaitcev@yahoo.com)
|
|
|
|
*
|
|
|
|
* This is mainly a variation of 8250.c, credits go to authors mentioned
|
|
|
|
* therein. In fact this driver should be merged into the generic 8250.c
|
|
|
|
* infrastructure perhaps using a 8250_sparc.c module.
|
|
|
|
*
|
|
|
|
* Fixed to use tty_get_baud_rate().
|
|
|
|
* Theodore Ts'o <tytso@mit.edu>, 2001-Oct-12
|
|
|
|
*
|
|
|
|
* Converted to new 2.5.x UART layer.
|
2006-06-30 06:14:17 +08:00
|
|
|
* David S. Miller (davem@davemloft.net), 2002-Jul-29
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/circ_buf.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/sysrq.h>
|
|
|
|
#include <linux/console.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
#include <linux/serio.h>
|
|
|
|
#endif
|
|
|
|
#include <linux/serial_reg.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
2008-08-12 05:30:53 +08:00
|
|
|
#include <linux/of_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
2006-06-30 06:14:03 +08:00
|
|
|
#include <asm/prom.h>
|
2012-03-29 01:30:03 +08:00
|
|
|
#include <asm/setup.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_SERIAL_SUNSU_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
|
|
|
|
#define SUPPORT_SYSRQ
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <linux/serial_core.h>
|
2012-02-10 07:48:19 +08:00
|
|
|
#include <linux/sunserialcore.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We are on a NS PC87303 clocked with 24.0 MHz, which results
|
|
|
|
* in a UART clock of 1.8462 MHz.
|
|
|
|
*/
|
|
|
|
#define SU_BASE_BAUD (1846200 / 16)
|
|
|
|
|
|
|
|
enum su_type { SU_PORT_NONE, SU_PORT_MS, SU_PORT_KBD, SU_PORT_PORT };
|
|
|
|
static char *su_typev[] = { "su(???)", "su(mouse)", "su(kbd)", "su(serial)" };
|
|
|
|
|
2012-08-21 07:56:28 +08:00
|
|
|
struct serial_uart_config {
|
|
|
|
char *name;
|
|
|
|
int dfl_xmit_fifo_size;
|
|
|
|
int flags;
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Here we define the default xmit fifo size used for each type of UART.
|
|
|
|
*/
|
2012-08-21 07:56:27 +08:00
|
|
|
static const struct serial_uart_config uart_config[] = {
|
2005-04-17 06:20:36 +08:00
|
|
|
{ "unknown", 1, 0 },
|
|
|
|
{ "8250", 1, 0 },
|
|
|
|
{ "16450", 1, 0 },
|
|
|
|
{ "16550", 1, 0 },
|
|
|
|
{ "16550A", 16, UART_CLEAR_FIFO | UART_USE_FIFO },
|
|
|
|
{ "Cirrus", 1, 0 },
|
|
|
|
{ "ST16650", 1, UART_CLEAR_FIFO | UART_STARTECH },
|
|
|
|
{ "ST16650V2", 32, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH },
|
|
|
|
{ "TI16750", 64, UART_CLEAR_FIFO | UART_USE_FIFO },
|
|
|
|
{ "Startech", 1, 0 },
|
|
|
|
{ "16C950/954", 128, UART_CLEAR_FIFO | UART_USE_FIFO },
|
|
|
|
{ "ST16654", 64, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH },
|
|
|
|
{ "XR16850", 128, UART_CLEAR_FIFO | UART_USE_FIFO | UART_STARTECH },
|
|
|
|
{ "RSA", 2048, UART_CLEAR_FIFO | UART_USE_FIFO }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uart_sunsu_port {
|
|
|
|
struct uart_port port;
|
|
|
|
unsigned char acr;
|
|
|
|
unsigned char ier;
|
|
|
|
unsigned short rev;
|
|
|
|
unsigned char lcr;
|
|
|
|
unsigned int lsr_break_flag;
|
|
|
|
unsigned int cflag;
|
|
|
|
|
|
|
|
/* Probing information. */
|
|
|
|
enum su_type su_type;
|
|
|
|
unsigned int type_probed; /* XXX Stupid */
|
2006-06-30 06:14:03 +08:00
|
|
|
unsigned long reg_size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIO
|
2006-06-30 06:14:03 +08:00
|
|
|
struct serio serio;
|
2005-04-17 06:20:36 +08:00
|
|
|
int serio_open;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2006-03-23 19:00:56 +08:00
|
|
|
static unsigned int serial_in(struct uart_sunsu_port *up, int offset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
offset <<= up->port.regshift;
|
|
|
|
|
|
|
|
switch (up->port.iotype) {
|
2006-02-05 18:48:10 +08:00
|
|
|
case UPIO_HUB6:
|
2005-04-17 06:20:36 +08:00
|
|
|
outb(up->port.hub6 - 1 + offset, up->port.iobase);
|
|
|
|
return inb(up->port.iobase + 1);
|
|
|
|
|
2006-02-05 18:48:10 +08:00
|
|
|
case UPIO_MEM:
|
2005-04-17 06:20:36 +08:00
|
|
|
return readb(up->port.membase + offset);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return inb(up->port.iobase + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-23 19:00:56 +08:00
|
|
|
static void serial_out(struct uart_sunsu_port *up, int offset, int value)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
#ifndef CONFIG_SPARC64
|
|
|
|
/*
|
|
|
|
* MrCoffee has weird schematics: IRQ4 & P10(?) pins of SuperIO are
|
|
|
|
* connected with a gate then go to SlavIO. When IRQ4 goes tristated
|
|
|
|
* gate outputs a logical one. Since we use level triggered interrupts
|
|
|
|
* we have lockup and watchdog reset. We cannot mask IRQ because
|
|
|
|
* keyboard shares IRQ with us (Word has it as Bob Smelik's design).
|
|
|
|
* This problem is similar to what Alpha people suffer, see serial.c.
|
|
|
|
*/
|
|
|
|
if (offset == UART_MCR)
|
|
|
|
value |= UART_MCR_OUT2;
|
|
|
|
#endif
|
|
|
|
offset <<= up->port.regshift;
|
|
|
|
|
|
|
|
switch (up->port.iotype) {
|
2006-02-05 18:48:10 +08:00
|
|
|
case UPIO_HUB6:
|
2005-04-17 06:20:36 +08:00
|
|
|
outb(up->port.hub6 - 1 + offset, up->port.iobase);
|
|
|
|
outb(value, up->port.iobase + 1);
|
|
|
|
break;
|
|
|
|
|
2006-02-05 18:48:10 +08:00
|
|
|
case UPIO_MEM:
|
2005-04-17 06:20:36 +08:00
|
|
|
writeb(value, up->port.membase + offset);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
outb(value, up->port.iobase + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We used to support using pause I/O for certain machines. We
|
|
|
|
* haven't supported this for a while, but just in case it's badly
|
|
|
|
* needed for certain old 386 machines, I've left these #define's
|
|
|
|
* in....
|
|
|
|
*/
|
|
|
|
#define serial_inp(up, offset) serial_in(up, offset)
|
|
|
|
#define serial_outp(up, offset, value) serial_out(up, offset, value)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the 16C950
|
|
|
|
*/
|
|
|
|
static void serial_icr_write(struct uart_sunsu_port *up, int offset, int value)
|
|
|
|
{
|
|
|
|
serial_out(up, UART_SCR, offset);
|
|
|
|
serial_out(up, UART_ICR, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* Unused currently */
|
|
|
|
static unsigned int serial_icr_read(struct uart_sunsu_port *up, int offset)
|
|
|
|
{
|
|
|
|
unsigned int value;
|
|
|
|
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr | UART_ACR_ICRRD);
|
|
|
|
serial_out(up, UART_SCR, offset);
|
|
|
|
value = serial_in(up, UART_ICR);
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
/*
|
|
|
|
* Attempts to turn on the RSA FIFO. Returns zero on failure.
|
|
|
|
* We set the port uart clock rate if we succeed.
|
|
|
|
*/
|
|
|
|
static int __enable_rsa(struct uart_sunsu_port *up)
|
|
|
|
{
|
|
|
|
unsigned char mode;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
mode = serial_inp(up, UART_RSA_MSR);
|
|
|
|
result = mode & UART_RSA_MSR_FIFO;
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
serial_outp(up, UART_RSA_MSR, mode | UART_RSA_MSR_FIFO);
|
|
|
|
mode = serial_inp(up, UART_RSA_MSR);
|
|
|
|
result = mode & UART_RSA_MSR_FIFO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
up->port.uartclk = SERIAL_RSA_BAUD_BASE * 16;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void enable_rsa(struct uart_sunsu_port *up)
|
|
|
|
{
|
|
|
|
if (up->port.type == PORT_RSA) {
|
|
|
|
if (up->port.uartclk != SERIAL_RSA_BAUD_BASE * 16) {
|
|
|
|
spin_lock_irq(&up->port.lock);
|
|
|
|
__enable_rsa(up);
|
|
|
|
spin_unlock_irq(&up->port.lock);
|
|
|
|
}
|
|
|
|
if (up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16)
|
|
|
|
serial_outp(up, UART_RSA_FRR, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempts to turn off the RSA FIFO. Returns zero on failure.
|
|
|
|
* It is unknown why interrupts were disabled in here. However,
|
|
|
|
* the caller is expected to preserve this behaviour by grabbing
|
|
|
|
* the spinlock before calling this function.
|
|
|
|
*/
|
|
|
|
static void disable_rsa(struct uart_sunsu_port *up)
|
|
|
|
{
|
|
|
|
unsigned char mode;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (up->port.type == PORT_RSA &&
|
|
|
|
up->port.uartclk == SERIAL_RSA_BAUD_BASE * 16) {
|
|
|
|
spin_lock_irq(&up->port.lock);
|
|
|
|
|
|
|
|
mode = serial_inp(up, UART_RSA_MSR);
|
|
|
|
result = !(mode & UART_RSA_MSR_FIFO);
|
|
|
|
|
|
|
|
if (!result) {
|
|
|
|
serial_outp(up, UART_RSA_MSR, mode & ~UART_RSA_MSR_FIFO);
|
|
|
|
mode = serial_inp(up, UART_RSA_MSR);
|
|
|
|
result = !(mode & UART_RSA_MSR_FIFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
up->port.uartclk = SERIAL_RSA_BAUD_BASE_LO * 16;
|
|
|
|
spin_unlock_irq(&up->port.lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SERIAL_8250_RSA */
|
|
|
|
|
2005-08-31 17:12:14 +08:00
|
|
|
static inline void __stop_tx(struct uart_sunsu_port *p)
|
|
|
|
{
|
|
|
|
if (p->ier & UART_IER_THRI) {
|
|
|
|
p->ier &= ~UART_IER_THRI;
|
|
|
|
serial_out(p, UART_IER, p->ier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_stop_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
|
2005-08-31 17:12:14 +08:00
|
|
|
__stop_tx(up);
|
|
|
|
|
2005-09-06 14:35:05 +08:00
|
|
|
/*
|
|
|
|
* We really want to stop the transmitter from sending.
|
|
|
|
*/
|
|
|
|
if (up->port.type == PORT_16C950) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->acr |= UART_ACR_TXDIS;
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-31 17:12:14 +08:00
|
|
|
static void sunsu_start_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
|
|
|
|
if (!(up->ier & UART_IER_THRI)) {
|
|
|
|
up->ier |= UART_IER_THRI;
|
|
|
|
serial_out(up, UART_IER, up->ier);
|
|
|
|
}
|
2005-09-06 14:35:05 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-09-06 14:35:05 +08:00
|
|
|
* Re-enable the transmitter if we disabled it.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-09-06 14:35:05 +08:00
|
|
|
if (up->port.type == PORT_16C950 && up->acr & UART_ACR_TXDIS) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->acr &= ~UART_ACR_TXDIS;
|
|
|
|
serial_icr_write(up, UART_ACR, up->acr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_stop_rx(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
|
|
|
|
up->ier &= ~UART_IER_RLSI;
|
|
|
|
up->port.read_status_mask &= ~UART_LSR_DR;
|
|
|
|
serial_out(up, UART_IER, up->ier);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_enable_ms(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
up->ier |= UART_IER_MSI;
|
|
|
|
serial_out(up, UART_IER, up->ier);
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
2013-01-03 22:53:06 +08:00
|
|
|
static void
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
receive_chars(struct uart_sunsu_port *up, unsigned char *status)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-01-03 22:53:03 +08:00
|
|
|
struct tty_port *port = &up->port.state->port;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
unsigned char ch, flag;
|
2005-04-17 06:20:36 +08:00
|
|
|
int max_count = 256;
|
|
|
|
int saw_console_brk = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
ch = serial_inp(up, UART_RX);
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
flag = TTY_NORMAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
up->port.icount.rx++;
|
|
|
|
|
|
|
|
if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
|
|
|
|
UART_LSR_FE | UART_LSR_OE))) {
|
|
|
|
/*
|
|
|
|
* For statistics only
|
|
|
|
*/
|
|
|
|
if (*status & UART_LSR_BI) {
|
|
|
|
*status &= ~(UART_LSR_FE | UART_LSR_PE);
|
|
|
|
up->port.icount.brk++;
|
|
|
|
if (up->port.cons != NULL &&
|
|
|
|
up->port.line == up->port.cons->index)
|
|
|
|
saw_console_brk = 1;
|
|
|
|
/*
|
|
|
|
* We do the SysRQ and SAK checking
|
|
|
|
* here because otherwise the break
|
|
|
|
* may get masked by ignore_status_mask
|
|
|
|
* or read_status_mask.
|
|
|
|
*/
|
|
|
|
if (uart_handle_break(&up->port))
|
|
|
|
goto ignore_char;
|
|
|
|
} else if (*status & UART_LSR_PE)
|
|
|
|
up->port.icount.parity++;
|
|
|
|
else if (*status & UART_LSR_FE)
|
|
|
|
up->port.icount.frame++;
|
|
|
|
if (*status & UART_LSR_OE)
|
|
|
|
up->port.icount.overrun++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mask off conditions which should be ingored.
|
|
|
|
*/
|
|
|
|
*status &= up->port.read_status_mask;
|
|
|
|
|
|
|
|
if (up->port.cons != NULL &&
|
|
|
|
up->port.line == up->port.cons->index) {
|
|
|
|
/* Recover the break flag from console xmit */
|
|
|
|
*status |= up->lsr_break_flag;
|
|
|
|
up->lsr_break_flag = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*status & UART_LSR_BI) {
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
flag = TTY_BREAK;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else if (*status & UART_LSR_PE)
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
flag = TTY_PARITY;
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (*status & UART_LSR_FE)
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
flag = TTY_FRAME;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
if (uart_handle_sysrq_char(&up->port, ch))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto ignore_char;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
if ((*status & up->port.ignore_status_mask) == 0)
|
2013-01-03 22:53:03 +08:00
|
|
|
tty_insert_flip_char(port, ch, flag);
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
if (*status & UART_LSR_OE)
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Overrun is special, since it's reported
|
|
|
|
* immediately, and doesn't affect the current
|
|
|
|
* character.
|
|
|
|
*/
|
2013-01-03 22:53:03 +08:00
|
|
|
tty_insert_flip_char(port, 0, TTY_OVERRUN);
|
2005-04-17 06:20:36 +08:00
|
|
|
ignore_char:
|
|
|
|
*status = serial_inp(up, UART_LSR);
|
|
|
|
} while ((*status & UART_LSR_DR) && (max_count-- > 0));
|
|
|
|
|
|
|
|
if (saw_console_brk)
|
|
|
|
sun_do_break();
|
|
|
|
}
|
|
|
|
|
2006-03-23 19:00:56 +08:00
|
|
|
static void transmit_chars(struct uart_sunsu_port *up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-09-20 04:13:28 +08:00
|
|
|
struct circ_buf *xmit = &up->port.state->xmit;
|
2005-04-17 06:20:36 +08:00
|
|
|
int count;
|
|
|
|
|
|
|
|
if (up->port.x_char) {
|
|
|
|
serial_outp(up, UART_TX, up->port.x_char);
|
|
|
|
up->port.icount.tx++;
|
|
|
|
up->port.x_char = 0;
|
|
|
|
return;
|
|
|
|
}
|
2005-08-31 17:12:14 +08:00
|
|
|
if (uart_tx_stopped(&up->port)) {
|
|
|
|
sunsu_stop_tx(&up->port);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (uart_circ_empty(xmit)) {
|
|
|
|
__stop_tx(up);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = up->port.fifosize;
|
|
|
|
do {
|
|
|
|
serial_out(up, UART_TX, xmit->buf[xmit->tail]);
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
up->port.icount.tx++;
|
|
|
|
if (uart_circ_empty(xmit))
|
|
|
|
break;
|
|
|
|
} while (--count > 0);
|
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(&up->port);
|
|
|
|
|
|
|
|
if (uart_circ_empty(xmit))
|
2005-08-31 17:12:14 +08:00
|
|
|
__stop_tx(up);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-03-23 19:00:56 +08:00
|
|
|
static void check_modem_status(struct uart_sunsu_port *up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
|
|
|
status = serial_in(up, UART_MSR);
|
|
|
|
|
|
|
|
if ((status & UART_MSR_ANY_DELTA) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (status & UART_MSR_TERI)
|
|
|
|
up->port.icount.rng++;
|
|
|
|
if (status & UART_MSR_DDSR)
|
|
|
|
up->port.icount.dsr++;
|
|
|
|
if (status & UART_MSR_DDCD)
|
|
|
|
uart_handle_dcd_change(&up->port, status & UART_MSR_DCD);
|
|
|
|
if (status & UART_MSR_DCTS)
|
|
|
|
uart_handle_cts_change(&up->port, status & UART_MSR_CTS);
|
|
|
|
|
2009-09-20 04:13:31 +08:00
|
|
|
wake_up_interruptible(&up->port.state->port.delta_msr_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t sunsu_serial_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = dev_id;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char status;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
|
|
|
do {
|
|
|
|
status = serial_inp(up, UART_LSR);
|
|
|
|
if (status & UART_LSR_DR)
|
2013-01-03 22:53:06 +08:00
|
|
|
receive_chars(up, &status);
|
2005-04-17 06:20:36 +08:00
|
|
|
check_modem_status(up);
|
|
|
|
if (status & UART_LSR_THRE)
|
|
|
|
transmit_chars(up);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
|
2013-01-03 22:53:06 +08:00
|
|
|
tty_flip_buffer_push(&up->port.state->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
|
|
|
} while (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT));
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Separate interrupt handling path for keyboard/mouse ports. */
|
|
|
|
|
|
|
|
static void
|
|
|
|
sunsu_change_speed(struct uart_port *port, unsigned int cflag,
|
|
|
|
unsigned int iflag, unsigned int quot);
|
|
|
|
|
|
|
|
static void sunsu_change_mouse_baud(struct uart_sunsu_port *up)
|
|
|
|
{
|
|
|
|
unsigned int cur_cflag = up->cflag;
|
|
|
|
int quot, new_baud;
|
|
|
|
|
|
|
|
up->cflag &= ~CBAUD;
|
|
|
|
up->cflag |= suncore_mouse_baud_cflag_next(cur_cflag, &new_baud);
|
|
|
|
|
|
|
|
quot = up->port.uartclk / (16 * new_baud);
|
|
|
|
|
|
|
|
sunsu_change_speed(&up->port, up->cflag, 0, quot);
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static void receive_kbd_ms_chars(struct uart_sunsu_port *up, int is_break)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
do {
|
|
|
|
unsigned char ch = serial_inp(up, UART_RX);
|
|
|
|
|
|
|
|
/* Stop-A is handled by drivers/char/keyboard.c now. */
|
|
|
|
if (up->su_type == SU_PORT_KBD) {
|
|
|
|
#ifdef CONFIG_SERIO
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
serio_interrupt(&up->serio, ch, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
} else if (up->su_type == SU_PORT_MS) {
|
|
|
|
int ret = suncore_mouse_baud_detection(ch, is_break);
|
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case 2:
|
|
|
|
sunsu_change_mouse_baud(up);
|
|
|
|
/* fallthru */
|
|
|
|
case 1:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
#ifdef CONFIG_SERIO
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
serio_interrupt(&up->serio, ch, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
break;
|
2013-10-09 07:14:21 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} while (serial_in(up, UART_LSR) & UART_LSR_DR);
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t sunsu_kbd_ms_interrupt(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = dev_id;
|
|
|
|
|
|
|
|
if (!(serial_in(up, UART_IIR) & UART_IIR_NO_INT)) {
|
|
|
|
unsigned char status = serial_inp(up, UART_LSR);
|
|
|
|
|
|
|
|
if ((status & UART_LSR_DR) || (status & UART_LSR_BI))
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
receive_kbd_ms_chars(up, (status & UART_LSR_BI) != 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int sunsu_tx_empty(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int sunsu_get_mctrl(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned char status;
|
|
|
|
unsigned int ret;
|
|
|
|
|
|
|
|
status = serial_in(up, UART_MSR);
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
if (status & UART_MSR_DCD)
|
|
|
|
ret |= TIOCM_CAR;
|
|
|
|
if (status & UART_MSR_RI)
|
|
|
|
ret |= TIOCM_RNG;
|
|
|
|
if (status & UART_MSR_DSR)
|
|
|
|
ret |= TIOCM_DSR;
|
|
|
|
if (status & UART_MSR_CTS)
|
|
|
|
ret |= TIOCM_CTS;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned char mcr = 0;
|
|
|
|
|
|
|
|
if (mctrl & TIOCM_RTS)
|
|
|
|
mcr |= UART_MCR_RTS;
|
|
|
|
if (mctrl & TIOCM_DTR)
|
|
|
|
mcr |= UART_MCR_DTR;
|
|
|
|
if (mctrl & TIOCM_OUT1)
|
|
|
|
mcr |= UART_MCR_OUT1;
|
|
|
|
if (mctrl & TIOCM_OUT2)
|
|
|
|
mcr |= UART_MCR_OUT2;
|
|
|
|
if (mctrl & TIOCM_LOOP)
|
|
|
|
mcr |= UART_MCR_LOOP;
|
|
|
|
|
|
|
|
serial_out(up, UART_MCR, mcr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_break_ctl(struct uart_port *port, int break_state)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
if (break_state == -1)
|
|
|
|
up->lcr |= UART_LCR_SBC;
|
|
|
|
else
|
|
|
|
up->lcr &= ~UART_LCR_SBC;
|
|
|
|
serial_out(up, UART_LCR, up->lcr);
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunsu_startup(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned long flags;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (up->port.type == PORT_16C950) {
|
|
|
|
/* Wake up and initialize UART */
|
|
|
|
up->acr = 0;
|
|
|
|
serial_outp(up, UART_LCR, 0xBF);
|
|
|
|
serial_outp(up, UART_EFR, UART_EFR_ECB);
|
|
|
|
serial_outp(up, UART_IER, 0);
|
|
|
|
serial_outp(up, UART_LCR, 0);
|
|
|
|
serial_icr_write(up, UART_CSR, 0); /* Reset the UART */
|
|
|
|
serial_outp(up, UART_LCR, 0xBF);
|
|
|
|
serial_outp(up, UART_EFR, UART_EFR_ECB);
|
|
|
|
serial_outp(up, UART_LCR, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
/*
|
|
|
|
* If this is an RSA port, see if we can kick it up to the
|
|
|
|
* higher speed clock.
|
|
|
|
*/
|
|
|
|
enable_rsa(up);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the FIFO buffers and disable them.
|
2006-03-28 17:56:53 +08:00
|
|
|
* (they will be reenabled in set_termios())
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
if (uart_config[up->port.type].flags & UART_CLEAR_FIFO) {
|
|
|
|
serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
|
|
|
|
UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
|
|
|
|
serial_outp(up, UART_FCR, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the interrupt registers.
|
|
|
|
*/
|
|
|
|
(void) serial_inp(up, UART_LSR);
|
|
|
|
(void) serial_inp(up, UART_RX);
|
|
|
|
(void) serial_inp(up, UART_IIR);
|
|
|
|
(void) serial_inp(up, UART_MSR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point, there's no way the LSR could still be 0xff;
|
|
|
|
* if it is, then bail out, because there's likely no UART
|
|
|
|
* here.
|
|
|
|
*/
|
2006-01-22 03:28:15 +08:00
|
|
|
if (!(up->port.flags & UPF_BUGGY_UART) &&
|
2005-04-17 06:20:36 +08:00
|
|
|
(serial_inp(up, UART_LSR) == 0xff)) {
|
|
|
|
printk("ttyS%d: LSR safety check engaged!\n", up->port.line);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (up->su_type != SU_PORT_PORT) {
|
|
|
|
retval = request_irq(up->port.irq, sunsu_kbd_ms_interrupt,
|
2006-07-02 10:29:43 +08:00
|
|
|
IRQF_SHARED, su_typev[up->su_type], up);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
retval = request_irq(up->port.irq, sunsu_serial_interrupt,
|
2006-07-02 10:29:43 +08:00
|
|
|
IRQF_SHARED, su_typev[up->su_type], up);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (retval) {
|
|
|
|
printk("su: Cannot register IRQ %d\n", up->port.irq);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now, initialize the UART
|
|
|
|
*/
|
|
|
|
serial_outp(up, UART_LCR, UART_LCR_WLEN8);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
|
|
|
up->port.mctrl |= TIOCM_OUT2;
|
|
|
|
|
|
|
|
sunsu_set_mctrl(&up->port, up->port.mctrl);
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, enable interrupts. Note: Modem status interrupts
|
|
|
|
* are set via set_termios(), which will be occurring imminently
|
|
|
|
* anyway, so we don't enable them here.
|
|
|
|
*/
|
|
|
|
up->ier = UART_IER_RLSI | UART_IER_RDI;
|
|
|
|
serial_outp(up, UART_IER, up->ier);
|
|
|
|
|
2006-01-22 03:28:15 +08:00
|
|
|
if (up->port.flags & UPF_FOURPORT) {
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int icp;
|
|
|
|
/*
|
|
|
|
* Enable interrupts on the AST Fourport board
|
|
|
|
*/
|
|
|
|
icp = (up->port.iobase & 0xfe0) | 0x01f;
|
|
|
|
outb_p(0x80, icp);
|
|
|
|
(void) inb_p(icp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* And clear the interrupt registers again for luck.
|
|
|
|
*/
|
|
|
|
(void) serial_inp(up, UART_LSR);
|
|
|
|
(void) serial_inp(up, UART_RX);
|
|
|
|
(void) serial_inp(up, UART_IIR);
|
|
|
|
(void) serial_inp(up, UART_MSR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_shutdown(struct uart_port *port)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable interrupts from this port
|
|
|
|
*/
|
|
|
|
up->ier = 0;
|
|
|
|
serial_outp(up, UART_IER, 0);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
2006-01-22 03:28:15 +08:00
|
|
|
if (up->port.flags & UPF_FOURPORT) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* reset interrupts on the AST Fourport board */
|
|
|
|
inb((up->port.iobase & 0xfe0) | 0x1f);
|
|
|
|
up->port.mctrl |= TIOCM_OUT1;
|
|
|
|
} else
|
|
|
|
up->port.mctrl &= ~TIOCM_OUT2;
|
|
|
|
|
|
|
|
sunsu_set_mctrl(&up->port, up->port.mctrl);
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable break condition and FIFOs
|
|
|
|
*/
|
|
|
|
serial_out(up, UART_LCR, serial_inp(up, UART_LCR) & ~UART_LCR_SBC);
|
|
|
|
serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO |
|
|
|
|
UART_FCR_CLEAR_RCVR |
|
|
|
|
UART_FCR_CLEAR_XMIT);
|
|
|
|
serial_outp(up, UART_FCR, 0);
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
/*
|
|
|
|
* Reset the RSA board back to 115kbps compat mode.
|
|
|
|
*/
|
|
|
|
disable_rsa(up);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read data port to reset things.
|
|
|
|
*/
|
|
|
|
(void) serial_in(up, UART_RX);
|
|
|
|
|
|
|
|
free_irq(up->port.irq, up);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sunsu_change_speed(struct uart_port *port, unsigned int cflag,
|
|
|
|
unsigned int iflag, unsigned int quot)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
unsigned char cval, fcr = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
switch (cflag & CSIZE) {
|
|
|
|
case CS5:
|
|
|
|
cval = 0x00;
|
|
|
|
break;
|
|
|
|
case CS6:
|
|
|
|
cval = 0x01;
|
|
|
|
break;
|
|
|
|
case CS7:
|
|
|
|
cval = 0x02;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case CS8:
|
|
|
|
cval = 0x03;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cflag & CSTOPB)
|
|
|
|
cval |= 0x04;
|
|
|
|
if (cflag & PARENB)
|
|
|
|
cval |= UART_LCR_PARITY;
|
|
|
|
if (!(cflag & PARODD))
|
|
|
|
cval |= UART_LCR_EPAR;
|
|
|
|
#ifdef CMSPAR
|
|
|
|
if (cflag & CMSPAR)
|
|
|
|
cval |= UART_LCR_SPAR;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Work around a bug in the Oxford Semiconductor 952 rev B
|
|
|
|
* chip which causes it to seriously miscalculate baud rates
|
|
|
|
* when DLL is 0.
|
|
|
|
*/
|
|
|
|
if ((quot & 0xff) == 0 && up->port.type == PORT_16C950 &&
|
|
|
|
up->rev == 0x5201)
|
|
|
|
quot ++;
|
|
|
|
|
|
|
|
if (uart_config[up->port.type].flags & UART_USE_FIFO) {
|
|
|
|
if ((up->port.uartclk / quot) < (2400 * 16))
|
|
|
|
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
else if (up->port.type == PORT_RSA)
|
|
|
|
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_14;
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
|
|
|
|
}
|
|
|
|
if (up->port.type == PORT_16750)
|
|
|
|
fcr |= UART_FCR7_64BYTE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, we're now changing the port state. Do it with
|
|
|
|
* interrupts disabled.
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the per-port timeout.
|
|
|
|
*/
|
|
|
|
uart_update_timeout(port, cflag, (port->uartclk / (16 * quot)));
|
|
|
|
|
|
|
|
up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
|
|
|
|
if (iflag & INPCK)
|
|
|
|
up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
|
2014-06-16 20:10:41 +08:00
|
|
|
if (iflag & (IGNBRK | BRKINT | PARMRK))
|
2005-04-17 06:20:36 +08:00
|
|
|
up->port.read_status_mask |= UART_LSR_BI;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Characteres to ignore
|
|
|
|
*/
|
|
|
|
up->port.ignore_status_mask = 0;
|
|
|
|
if (iflag & IGNPAR)
|
|
|
|
up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
|
|
|
|
if (iflag & IGNBRK) {
|
|
|
|
up->port.ignore_status_mask |= UART_LSR_BI;
|
|
|
|
/*
|
|
|
|
* If we're ignoring parity and break indicators,
|
|
|
|
* ignore overruns too (for real raw support).
|
|
|
|
*/
|
|
|
|
if (iflag & IGNPAR)
|
|
|
|
up->port.ignore_status_mask |= UART_LSR_OE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ignore all characters if CREAD is not set
|
|
|
|
*/
|
|
|
|
if ((cflag & CREAD) == 0)
|
|
|
|
up->port.ignore_status_mask |= UART_LSR_DR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CTS flow control flag and modem status interrupts
|
|
|
|
*/
|
|
|
|
up->ier &= ~UART_IER_MSI;
|
|
|
|
if (UART_ENABLE_MS(&up->port, cflag))
|
|
|
|
up->ier |= UART_IER_MSI;
|
|
|
|
|
|
|
|
serial_out(up, UART_IER, up->ier);
|
|
|
|
|
|
|
|
if (uart_config[up->port.type].flags & UART_STARTECH) {
|
|
|
|
serial_outp(up, UART_LCR, 0xBF);
|
|
|
|
serial_outp(up, UART_EFR, cflag & CRTSCTS ? UART_EFR_CTS :0);
|
|
|
|
}
|
|
|
|
serial_outp(up, UART_LCR, cval | UART_LCR_DLAB);/* set DLAB */
|
|
|
|
serial_outp(up, UART_DLL, quot & 0xff); /* LS of divisor */
|
|
|
|
serial_outp(up, UART_DLM, quot >> 8); /* MS of divisor */
|
|
|
|
if (up->port.type == PORT_16750)
|
|
|
|
serial_outp(up, UART_FCR, fcr); /* set fcr */
|
|
|
|
serial_outp(up, UART_LCR, cval); /* reset DLAB */
|
|
|
|
up->lcr = cval; /* Save LCR */
|
|
|
|
if (up->port.type != PORT_16750) {
|
|
|
|
if (fcr & UART_FCR_ENABLE_FIFO) {
|
|
|
|
/* emulated UARTs (Lucent Venus 167x) need two steps */
|
|
|
|
serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
}
|
|
|
|
serial_outp(up, UART_FCR, fcr); /* set fcr */
|
|
|
|
}
|
|
|
|
|
|
|
|
up->cflag = cflag;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-12-08 18:38:45 +08:00
|
|
|
sunsu_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int baud, quot;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ask the core to calculate the divisor for us.
|
|
|
|
*/
|
|
|
|
baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
|
|
|
|
quot = uart_get_divisor(port, baud);
|
|
|
|
|
|
|
|
sunsu_change_speed(port, termios->c_cflag, termios->c_iflag, quot);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_release_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunsu_request_port(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_config_port(struct uart_port *port, int flags)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *) port;
|
|
|
|
|
|
|
|
if (flags & UART_CONFIG_TYPE) {
|
|
|
|
/*
|
|
|
|
* We are supposed to call autoconfig here, but this requires
|
|
|
|
* splitting all the OBP probing crap from the UART probing.
|
|
|
|
* We'll do it when we kill sunsu.c altogether.
|
|
|
|
*/
|
|
|
|
port->type = up->type_probed; /* XXX */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sunsu_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
sunsu_type(struct uart_port *port)
|
|
|
|
{
|
|
|
|
int type = port->type;
|
|
|
|
|
|
|
|
if (type >= ARRAY_SIZE(uart_config))
|
|
|
|
type = 0;
|
|
|
|
return uart_config[type].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct uart_ops sunsu_pops = {
|
|
|
|
.tx_empty = sunsu_tx_empty,
|
|
|
|
.set_mctrl = sunsu_set_mctrl,
|
|
|
|
.get_mctrl = sunsu_get_mctrl,
|
|
|
|
.stop_tx = sunsu_stop_tx,
|
|
|
|
.start_tx = sunsu_start_tx,
|
|
|
|
.stop_rx = sunsu_stop_rx,
|
|
|
|
.enable_ms = sunsu_enable_ms,
|
|
|
|
.break_ctl = sunsu_break_ctl,
|
|
|
|
.startup = sunsu_startup,
|
|
|
|
.shutdown = sunsu_shutdown,
|
|
|
|
.set_termios = sunsu_set_termios,
|
|
|
|
.type = sunsu_type,
|
|
|
|
.release_port = sunsu_release_port,
|
|
|
|
.request_port = sunsu_request_port,
|
|
|
|
.config_port = sunsu_config_port,
|
|
|
|
.verify_port = sunsu_verify_port,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define UART_NR 4
|
|
|
|
|
|
|
|
static struct uart_sunsu_port sunsu_ports[UART_NR];
|
2013-02-24 07:01:15 +08:00
|
|
|
static int nr_inst; /* Number of already registered ports */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
|
|
|
|
static DEFINE_SPINLOCK(sunsu_serio_lock);
|
|
|
|
|
|
|
|
static int sunsu_serio_write(struct serio *serio, unsigned char ch)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = serio->port_data;
|
|
|
|
unsigned long flags;
|
|
|
|
int lsr;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sunsu_serio_lock, flags);
|
|
|
|
|
|
|
|
do {
|
|
|
|
lsr = serial_in(up, UART_LSR);
|
|
|
|
} while (!(lsr & UART_LSR_THRE));
|
|
|
|
|
|
|
|
/* Send the character out. */
|
|
|
|
serial_out(up, UART_TX, ch);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sunsu_serio_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sunsu_serio_open(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = serio->port_data;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sunsu_serio_lock, flags);
|
|
|
|
if (!up->serio_open) {
|
|
|
|
up->serio_open = 1;
|
|
|
|
ret = 0;
|
|
|
|
} else
|
|
|
|
ret = -EBUSY;
|
|
|
|
spin_unlock_irqrestore(&sunsu_serio_lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sunsu_serio_close(struct serio *serio)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = serio->port_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sunsu_serio_lock, flags);
|
|
|
|
up->serio_open = 0;
|
|
|
|
spin_unlock_irqrestore(&sunsu_serio_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_SERIO */
|
|
|
|
|
|
|
|
static void sunsu_autoconfig(struct uart_sunsu_port *up)
|
|
|
|
{
|
|
|
|
unsigned char status1, status2, scratch, scratch2, scratch3;
|
|
|
|
unsigned char save_lcr, save_mcr;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
if (up->su_type == SU_PORT_NONE)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
up->type_probed = PORT_UNKNOWN;
|
2006-02-05 18:48:10 +08:00
|
|
|
up->port.iotype = UPIO_MEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
|
|
|
|
2006-01-22 03:28:15 +08:00
|
|
|
if (!(up->port.flags & UPF_BUGGY_UART)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Do a simple existence test first; if we fail this, there's
|
|
|
|
* no point trying anything else.
|
|
|
|
*
|
|
|
|
* 0x80 is used as a nonsense port to prevent against false
|
|
|
|
* positives due to ISA bus float. The assumption is that
|
|
|
|
* 0x80 is a non-existent port; which should be safe since
|
|
|
|
* include/asm/io.h also makes this assumption.
|
|
|
|
*/
|
|
|
|
scratch = serial_inp(up, UART_IER);
|
|
|
|
serial_outp(up, UART_IER, 0);
|
|
|
|
#ifdef __i386__
|
|
|
|
outb(0xff, 0x080);
|
|
|
|
#endif
|
|
|
|
scratch2 = serial_inp(up, UART_IER);
|
|
|
|
serial_outp(up, UART_IER, 0x0f);
|
|
|
|
#ifdef __i386__
|
|
|
|
outb(0, 0x080);
|
|
|
|
#endif
|
|
|
|
scratch3 = serial_inp(up, UART_IER);
|
|
|
|
serial_outp(up, UART_IER, scratch);
|
|
|
|
if (scratch2 != 0 || scratch3 != 0x0F)
|
|
|
|
goto out; /* We failed; there's nothing here */
|
|
|
|
}
|
|
|
|
|
|
|
|
save_mcr = serial_in(up, UART_MCR);
|
|
|
|
save_lcr = serial_in(up, UART_LCR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check to see if a UART is really there. Certain broken
|
|
|
|
* internal modems based on the Rockwell chipset fail this
|
|
|
|
* test, because they apparently don't implement the loopback
|
|
|
|
* test mode. So this test is skipped on the COM 1 through
|
|
|
|
* COM 4 ports. This *should* be safe, since no board
|
|
|
|
* manufacturer would be stupid enough to design a board
|
|
|
|
* that conflicts with COM 1-4 --- we hope!
|
|
|
|
*/
|
2006-01-22 03:28:15 +08:00
|
|
|
if (!(up->port.flags & UPF_SKIP_TEST)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
serial_outp(up, UART_MCR, UART_MCR_LOOP | 0x0A);
|
|
|
|
status1 = serial_inp(up, UART_MSR) & 0xF0;
|
|
|
|
serial_outp(up, UART_MCR, save_mcr);
|
|
|
|
if (status1 != 0x90)
|
|
|
|
goto out; /* We failed loopback test */
|
|
|
|
}
|
|
|
|
serial_outp(up, UART_LCR, 0xBF); /* set up for StarTech test */
|
|
|
|
serial_outp(up, UART_EFR, 0); /* EFR is the same as FCR */
|
|
|
|
serial_outp(up, UART_LCR, 0);
|
|
|
|
serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
scratch = serial_in(up, UART_IIR) >> 6;
|
|
|
|
switch (scratch) {
|
|
|
|
case 0:
|
|
|
|
up->port.type = PORT_16450;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
up->port.type = PORT_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
up->port.type = PORT_16550;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
up->port.type = PORT_16550A;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (up->port.type == PORT_16550A) {
|
|
|
|
/* Check for Startech UART's */
|
|
|
|
serial_outp(up, UART_LCR, UART_LCR_DLAB);
|
|
|
|
if (serial_in(up, UART_EFR) == 0) {
|
|
|
|
up->port.type = PORT_16650;
|
|
|
|
} else {
|
|
|
|
serial_outp(up, UART_LCR, 0xBF);
|
|
|
|
if (serial_in(up, UART_EFR) == 0)
|
|
|
|
up->port.type = PORT_16650V2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (up->port.type == PORT_16550A) {
|
|
|
|
/* Check for TI 16750 */
|
|
|
|
serial_outp(up, UART_LCR, save_lcr | UART_LCR_DLAB);
|
|
|
|
serial_outp(up, UART_FCR,
|
|
|
|
UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
|
|
|
|
scratch = serial_in(up, UART_IIR) >> 5;
|
|
|
|
if (scratch == 7) {
|
|
|
|
/*
|
|
|
|
* If this is a 16750, and not a cheap UART
|
|
|
|
* clone, then it should only go into 64 byte
|
|
|
|
* mode if the UART_FCR7_64BYTE bit was set
|
|
|
|
* while UART_LCR_DLAB was latched.
|
|
|
|
*/
|
|
|
|
serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
serial_outp(up, UART_LCR, 0);
|
|
|
|
serial_outp(up, UART_FCR,
|
|
|
|
UART_FCR_ENABLE_FIFO | UART_FCR7_64BYTE);
|
|
|
|
scratch = serial_in(up, UART_IIR) >> 5;
|
|
|
|
if (scratch == 6)
|
|
|
|
up->port.type = PORT_16750;
|
|
|
|
}
|
|
|
|
serial_outp(up, UART_FCR, UART_FCR_ENABLE_FIFO);
|
|
|
|
}
|
|
|
|
serial_outp(up, UART_LCR, save_lcr);
|
|
|
|
if (up->port.type == PORT_16450) {
|
|
|
|
scratch = serial_in(up, UART_SCR);
|
|
|
|
serial_outp(up, UART_SCR, 0xa5);
|
|
|
|
status1 = serial_in(up, UART_SCR);
|
|
|
|
serial_outp(up, UART_SCR, 0x5a);
|
|
|
|
status2 = serial_in(up, UART_SCR);
|
|
|
|
serial_outp(up, UART_SCR, scratch);
|
|
|
|
|
|
|
|
if ((status1 != 0xa5) || (status2 != 0x5a))
|
|
|
|
up->port.type = PORT_8250;
|
|
|
|
}
|
|
|
|
|
|
|
|
up->port.fifosize = uart_config[up->port.type].dfl_xmit_fifo_size;
|
|
|
|
|
|
|
|
if (up->port.type == PORT_UNKNOWN)
|
|
|
|
goto out;
|
|
|
|
up->type_probed = up->port.type; /* XXX */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the UART.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_SERIAL_8250_RSA
|
|
|
|
if (up->port.type == PORT_RSA)
|
|
|
|
serial_outp(up, UART_RSA_FRR, 0);
|
|
|
|
#endif
|
|
|
|
serial_outp(up, UART_MCR, save_mcr);
|
|
|
|
serial_outp(up, UART_FCR, (UART_FCR_ENABLE_FIFO |
|
|
|
|
UART_FCR_CLEAR_RCVR |
|
|
|
|
UART_FCR_CLEAR_XMIT));
|
|
|
|
serial_outp(up, UART_FCR, 0);
|
|
|
|
(void)serial_in(up, UART_RX);
|
|
|
|
serial_outp(up, UART_IER, 0);
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct uart_driver sunsu_reg = {
|
|
|
|
.owner = THIS_MODULE,
|
2008-05-01 16:14:27 +08:00
|
|
|
.driver_name = "sunsu",
|
2005-04-17 06:20:36 +08:00
|
|
|
.dev_name = "ttyS",
|
|
|
|
.major = TTY_MAJOR,
|
|
|
|
};
|
|
|
|
|
2012-11-20 02:21:50 +08:00
|
|
|
static int sunsu_kbd_ms_init(struct uart_sunsu_port *up)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-04-22 13:06:13 +08:00
|
|
|
int quot, baud;
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
struct serio *serio;
|
|
|
|
#endif
|
|
|
|
|
2005-04-22 13:06:13 +08:00
|
|
|
if (up->su_type == SU_PORT_KBD) {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->cflag = B1200 | CS8 | CLOCAL | CREAD;
|
2005-04-22 13:06:13 +08:00
|
|
|
baud = 1200;
|
|
|
|
} else {
|
2005-04-17 06:20:36 +08:00
|
|
|
up->cflag = B4800 | CS8 | CLOCAL | CREAD;
|
2005-04-22 13:06:13 +08:00
|
|
|
baud = 4800;
|
|
|
|
}
|
|
|
|
quot = up->port.uartclk / (16 * baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
sunsu_autoconfig(up);
|
|
|
|
if (up->port.type == PORT_UNKNOWN)
|
2006-06-30 06:14:03 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-08-26 06:17:31 +08:00
|
|
|
printk("%s: %s port at %llx, irq %u\n",
|
2010-08-06 23:25:50 +08:00
|
|
|
up->port.dev->of_node->full_name,
|
2006-07-14 07:05:57 +08:00
|
|
|
(up->su_type == SU_PORT_KBD) ? "Keyboard" : "Mouse",
|
2007-08-26 06:17:31 +08:00
|
|
|
(unsigned long long) up->port.mapbase,
|
|
|
|
up->port.irq);
|
2006-07-14 07:05:57 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_SERIO
|
2006-06-30 06:14:03 +08:00
|
|
|
serio = &up->serio;
|
|
|
|
serio->port_data = up;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
serio->id.type = SERIO_RS232;
|
|
|
|
if (up->su_type == SU_PORT_KBD) {
|
|
|
|
serio->id.proto = SERIO_SUNKBD;
|
|
|
|
strlcpy(serio->name, "sukbd", sizeof(serio->name));
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2006-06-30 06:14:03 +08:00
|
|
|
serio->id.proto = SERIO_SUN;
|
|
|
|
serio->id.extra = 1;
|
|
|
|
strlcpy(serio->name, "sums", sizeof(serio->name));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-06-30 06:14:03 +08:00
|
|
|
strlcpy(serio->phys,
|
|
|
|
(!(up->port.line & 1) ? "su/serio0" : "su/serio1"),
|
|
|
|
sizeof(serio->phys));
|
|
|
|
|
|
|
|
serio->write = sunsu_serio_write;
|
|
|
|
serio->open = sunsu_serio_open;
|
|
|
|
serio->close = sunsu_serio_close;
|
|
|
|
serio->dev.parent = up->port.dev;
|
|
|
|
|
|
|
|
serio_register_port(serio);
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
2005-04-22 13:06:13 +08:00
|
|
|
sunsu_change_speed(&up->port, up->cflag, 0, quot);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
sunsu_startup(&up->port);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
* Serial console driver
|
|
|
|
* ------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_SUNSU_CONSOLE
|
|
|
|
|
|
|
|
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for transmitter & holding register to empty
|
|
|
|
*/
|
|
|
|
static __inline__ void wait_for_xmitr(struct uart_sunsu_port *up)
|
|
|
|
{
|
|
|
|
unsigned int status, tmout = 10000;
|
|
|
|
|
|
|
|
/* Wait up to 10ms for the character(s) to be sent. */
|
|
|
|
do {
|
|
|
|
status = serial_in(up, UART_LSR);
|
|
|
|
|
|
|
|
if (status & UART_LSR_BI)
|
|
|
|
up->lsr_break_flag = UART_LSR_BI;
|
|
|
|
|
|
|
|
if (--tmout == 0)
|
|
|
|
break;
|
|
|
|
udelay(1);
|
|
|
|
} while ((status & BOTH_EMPTY) != BOTH_EMPTY);
|
|
|
|
|
|
|
|
/* Wait up to 1s for flow control if necessary */
|
2006-01-22 03:28:15 +08:00
|
|
|
if (up->port.flags & UPF_CONS_FLOW) {
|
2005-04-17 06:20:36 +08:00
|
|
|
tmout = 1000000;
|
|
|
|
while (--tmout &&
|
|
|
|
((serial_in(up, UART_MSR) & UART_MSR_CTS) == 0))
|
|
|
|
udelay(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 04:00:09 +08:00
|
|
|
static void sunsu_console_putchar(struct uart_port *port, int ch)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = (struct uart_sunsu_port *)port;
|
|
|
|
|
|
|
|
wait_for_xmitr(up);
|
|
|
|
serial_out(up, UART_TX, ch);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Print a string to the serial port trying not to disturb
|
|
|
|
* any possible real use of the port...
|
|
|
|
*/
|
|
|
|
static void sunsu_console_write(struct console *co, const char *s,
|
|
|
|
unsigned int count)
|
|
|
|
{
|
|
|
|
struct uart_sunsu_port *up = &sunsu_ports[co->index];
|
2007-07-16 14:53:32 +08:00
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int ier;
|
2007-07-16 14:53:32 +08:00
|
|
|
int locked = 1;
|
|
|
|
|
2014-03-05 04:28:35 +08:00
|
|
|
if (up->port.sysrq || oops_in_progress)
|
|
|
|
locked = spin_trylock_irqsave(&up->port.lock, flags);
|
|
|
|
else
|
|
|
|
spin_lock_irqsave(&up->port.lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* First save the UER then disable the interrupts
|
|
|
|
*/
|
|
|
|
ier = serial_in(up, UART_IER);
|
|
|
|
serial_out(up, UART_IER, 0);
|
|
|
|
|
2006-03-21 04:00:09 +08:00
|
|
|
uart_console_write(&up->port, s, count, sunsu_console_putchar);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, wait for transmitter to become empty
|
|
|
|
* and restore the IER
|
|
|
|
*/
|
|
|
|
wait_for_xmitr(up);
|
|
|
|
serial_out(up, UART_IER, ier);
|
2007-07-16 14:53:32 +08:00
|
|
|
|
|
|
|
if (locked)
|
2014-03-05 04:28:35 +08:00
|
|
|
spin_unlock_irqrestore(&up->port.lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup initial baud/bits/parity. We do two things here:
|
|
|
|
* - construct a cflag setting for the first su_open()
|
|
|
|
* - initialize the serial port
|
|
|
|
* Return non-zero if we didn't find a serial port.
|
|
|
|
*/
|
2007-05-07 15:14:13 +08:00
|
|
|
static int __init sunsu_console_setup(struct console *co, char *options)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-11-25 06:12:50 +08:00
|
|
|
static struct ktermios dummy;
|
|
|
|
struct ktermios termios;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct uart_port *port;
|
|
|
|
|
|
|
|
printk("Console: ttyS%d (SU)\n",
|
|
|
|
(sunsu_reg.minor - 64) + co->index);
|
|
|
|
|
2013-02-24 07:01:15 +08:00
|
|
|
if (co->index > nr_inst)
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
port = &sunsu_ports[co->index].port;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Temporary fix.
|
|
|
|
*/
|
|
|
|
spin_lock_init(&port->lock);
|
|
|
|
|
2009-11-25 06:12:50 +08:00
|
|
|
/* Get firmware console settings. */
|
2010-08-06 23:25:50 +08:00
|
|
|
sunserial_console_termios(co, port->dev->of_node);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-25 06:12:50 +08:00
|
|
|
memset(&termios, 0, sizeof(struct ktermios));
|
|
|
|
termios.c_cflag = co->cflag;
|
|
|
|
port->mctrl |= TIOCM_DTR;
|
|
|
|
port->ops->set_termios(port, &termios, &dummy);
|
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-05-07 15:14:13 +08:00
|
|
|
static struct console sunsu_console = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.name = "ttyS",
|
|
|
|
.write = sunsu_console_write,
|
|
|
|
.device = uart_console_device,
|
|
|
|
.setup = sunsu_console_setup,
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
|
|
|
.data = &sunsu_reg,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Register console.
|
|
|
|
*/
|
|
|
|
|
2007-07-21 07:59:26 +08:00
|
|
|
static inline struct console *SUNSU_CONSOLE(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-05-07 15:14:13 +08:00
|
|
|
return &sunsu_console;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#else
|
2007-07-21 07:59:26 +08:00
|
|
|
#define SUNSU_CONSOLE() (NULL)
|
2005-04-17 06:20:36 +08:00
|
|
|
#define sunsu_serial_console_init() do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2012-11-20 02:21:50 +08:00
|
|
|
static enum su_type su_get_type(struct device_node *dp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-06-30 06:14:03 +08:00
|
|
|
struct device_node *ap = of_find_node_by_path("/aliases");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
if (ap) {
|
2007-03-29 15:49:54 +08:00
|
|
|
const char *keyb = of_get_property(ap, "keyboard", NULL);
|
|
|
|
const char *ms = of_get_property(ap, "mouse", NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
if (keyb) {
|
|
|
|
if (dp == of_find_node_by_path(keyb))
|
|
|
|
return SU_PORT_KBD;
|
|
|
|
}
|
|
|
|
if (ms) {
|
|
|
|
if (dp == of_find_node_by_path(ms))
|
|
|
|
return SU_PORT_MS;
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
return SU_PORT_PORT;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-11-20 02:21:50 +08:00
|
|
|
static int su_probe(struct platform_device *op)
|
2006-06-30 06:14:03 +08:00
|
|
|
{
|
2010-04-14 07:12:29 +08:00
|
|
|
struct device_node *dp = op->dev.of_node;
|
2006-06-30 06:14:03 +08:00
|
|
|
struct uart_sunsu_port *up;
|
|
|
|
struct resource *rp;
|
2006-07-13 12:04:21 +08:00
|
|
|
enum su_type type;
|
2009-11-25 06:11:40 +08:00
|
|
|
bool ignore_line;
|
2006-06-30 06:14:03 +08:00
|
|
|
int err;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-13 12:04:21 +08:00
|
|
|
type = su_get_type(dp);
|
|
|
|
if (type == SU_PORT_PORT) {
|
2013-02-24 07:01:15 +08:00
|
|
|
if (nr_inst >= UART_NR)
|
2006-07-13 12:04:21 +08:00
|
|
|
return -EINVAL;
|
2013-02-24 07:01:15 +08:00
|
|
|
up = &sunsu_ports[nr_inst];
|
2006-07-13 12:04:21 +08:00
|
|
|
} else {
|
|
|
|
up = kzalloc(sizeof(*up), GFP_KERNEL);
|
|
|
|
if (!up)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-02-24 07:01:15 +08:00
|
|
|
up->port.line = nr_inst;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
spin_lock_init(&up->port.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-13 12:04:21 +08:00
|
|
|
up->su_type = type;
|
2006-02-21 06:39:16 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
rp = &op->resource[0];
|
2006-07-13 12:04:21 +08:00
|
|
|
up->port.mapbase = rp->start;
|
2011-06-10 00:13:32 +08:00
|
|
|
up->reg_size = resource_size(rp);
|
2006-06-30 06:14:03 +08:00
|
|
|
up->port.membase = of_ioremap(rp, 0, up->reg_size, "su");
|
2006-07-13 12:04:21 +08:00
|
|
|
if (!up->port.membase) {
|
|
|
|
if (type != SU_PORT_PORT)
|
|
|
|
kfree(up);
|
2006-06-30 06:14:03 +08:00
|
|
|
return -ENOMEM;
|
2006-07-13 12:04:21 +08:00
|
|
|
}
|
2006-02-14 12:09:10 +08:00
|
|
|
|
2010-06-19 01:09:58 +08:00
|
|
|
up->port.irq = op->archdata.irqs[0];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
up->port.dev = &op->dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
up->port.type = PORT_UNKNOWN;
|
|
|
|
up->port.uartclk = (SU_BASE_BAUD * 16);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
err = 0;
|
|
|
|
if (up->su_type == SU_PORT_KBD || up->su_type == SU_PORT_MS) {
|
|
|
|
err = sunsu_kbd_ms_init(up);
|
2006-07-13 12:04:21 +08:00
|
|
|
if (err) {
|
2010-03-30 13:33:28 +08:00
|
|
|
of_iounmap(&op->resource[0],
|
|
|
|
up->port.membase, up->reg_size);
|
2006-07-13 12:04:21 +08:00
|
|
|
kfree(up);
|
2010-03-30 13:33:28 +08:00
|
|
|
return err;
|
2006-07-13 12:04:21 +08:00
|
|
|
}
|
2013-05-23 18:39:36 +08:00
|
|
|
platform_set_drvdata(op, up);
|
2006-06-30 10:40:19 +08:00
|
|
|
|
2013-02-24 07:01:15 +08:00
|
|
|
nr_inst++;
|
|
|
|
|
2006-06-30 10:40:19 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
up->port.flags |= UPF_BOOT_AUTOCONF;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
sunsu_autoconfig(up);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
err = -ENODEV;
|
|
|
|
if (up->port.type == PORT_UNKNOWN)
|
|
|
|
goto out_unmap;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
up->port.ops = &sunsu_pops;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-25 06:11:40 +08:00
|
|
|
ignore_line = false;
|
|
|
|
if (!strcmp(dp->name, "rsc-console") ||
|
|
|
|
!strcmp(dp->name, "lom-console"))
|
|
|
|
ignore_line = true;
|
|
|
|
|
2007-07-21 07:59:26 +08:00
|
|
|
sunserial_console_match(SUNSU_CONSOLE(), dp,
|
2009-11-25 06:03:34 +08:00
|
|
|
&sunsu_reg, up->port.line,
|
2009-11-25 06:11:40 +08:00
|
|
|
ignore_line);
|
2006-06-30 06:14:03 +08:00
|
|
|
err = uart_add_one_port(&sunsu_reg, &up->port);
|
|
|
|
if (err)
|
|
|
|
goto out_unmap;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-05-23 18:39:36 +08:00
|
|
|
platform_set_drvdata(op, up);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-02-24 07:01:15 +08:00
|
|
|
nr_inst++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out_unmap:
|
2006-12-29 13:01:32 +08:00
|
|
|
of_iounmap(&op->resource[0], up->port.membase, up->reg_size);
|
2006-06-30 06:14:03 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:18 +08:00
|
|
|
static int su_remove(struct platform_device *op)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2013-05-23 18:39:36 +08:00
|
|
|
struct uart_sunsu_port *up = platform_get_drvdata(op);
|
2010-05-27 12:17:29 +08:00
|
|
|
bool kbdms = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
if (up->su_type == SU_PORT_MS ||
|
2010-05-27 12:17:29 +08:00
|
|
|
up->su_type == SU_PORT_KBD)
|
|
|
|
kbdms = true;
|
|
|
|
|
|
|
|
if (kbdms) {
|
2006-06-30 06:14:03 +08:00
|
|
|
#ifdef CONFIG_SERIO
|
|
|
|
serio_unregister_port(&up->serio);
|
|
|
|
#endif
|
2010-05-27 12:17:29 +08:00
|
|
|
} else if (up->port.type != PORT_UNKNOWN)
|
2006-06-30 06:14:03 +08:00
|
|
|
uart_remove_one_port(&sunsu_reg, &up->port);
|
2006-07-13 12:04:21 +08:00
|
|
|
|
2006-10-01 14:29:25 +08:00
|
|
|
if (up->port.membase)
|
2006-12-29 13:01:32 +08:00
|
|
|
of_iounmap(&op->resource[0], up->port.membase, up->reg_size);
|
2006-10-01 14:29:25 +08:00
|
|
|
|
2010-05-27 12:17:29 +08:00
|
|
|
if (kbdms)
|
|
|
|
kfree(up);
|
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-08-31 16:23:17 +08:00
|
|
|
static const struct of_device_id su_match[] = {
|
2006-06-30 06:14:03 +08:00
|
|
|
{
|
|
|
|
.name = "su",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "su_pnp",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "serial",
|
|
|
|
.compatible = "su",
|
|
|
|
},
|
2009-11-25 05:58:52 +08:00
|
|
|
{
|
|
|
|
.type = "serial",
|
|
|
|
.compatible = "su",
|
|
|
|
},
|
2006-06-30 06:14:03 +08:00
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, su_match);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-02-23 12:10:26 +08:00
|
|
|
static struct platform_driver su_driver = {
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "su",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = su_match,
|
|
|
|
},
|
2006-06-30 06:14:03 +08:00
|
|
|
.probe = su_probe,
|
2012-11-20 02:21:34 +08:00
|
|
|
.remove = su_remove,
|
2006-06-30 06:14:03 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
static int __init sunsu_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *dp;
|
|
|
|
int err;
|
2007-12-11 19:37:04 +08:00
|
|
|
int num_uart = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
for_each_node_by_name(dp, "su") {
|
|
|
|
if (su_get_type(dp) == SU_PORT_PORT)
|
|
|
|
num_uart++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-06-30 06:14:03 +08:00
|
|
|
for_each_node_by_name(dp, "su_pnp") {
|
|
|
|
if (su_get_type(dp) == SU_PORT_PORT)
|
|
|
|
num_uart++;
|
|
|
|
}
|
|
|
|
for_each_node_by_name(dp, "serial") {
|
|
|
|
if (of_device_is_compatible(dp, "su")) {
|
|
|
|
if (su_get_type(dp) == SU_PORT_PORT)
|
|
|
|
num_uart++;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-11-25 05:58:52 +08:00
|
|
|
for_each_node_by_type(dp, "serial") {
|
|
|
|
if (of_device_is_compatible(dp, "su")) {
|
|
|
|
if (su_get_type(dp) == SU_PORT_PORT)
|
|
|
|
num_uart++;
|
|
|
|
}
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
if (num_uart) {
|
2007-12-11 19:37:04 +08:00
|
|
|
err = sunserial_register_minors(&sunsu_reg, num_uart);
|
2006-06-30 06:14:03 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-02-23 12:10:26 +08:00
|
|
|
err = platform_driver_register(&su_driver);
|
2006-06-30 06:14:03 +08:00
|
|
|
if (err && num_uart)
|
2007-12-11 19:37:04 +08:00
|
|
|
sunserial_unregister_minors(&sunsu_reg, num_uart);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sunsu_exit(void)
|
|
|
|
{
|
2013-04-27 08:13:16 +08:00
|
|
|
platform_driver_unregister(&su_driver);
|
2007-12-11 19:37:04 +08:00
|
|
|
if (sunsu_reg.nr)
|
|
|
|
sunserial_unregister_minors(&sunsu_reg, sunsu_reg.nr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-06-30 06:14:03 +08:00
|
|
|
module_init(sunsu_init);
|
2005-04-17 06:20:36 +08:00
|
|
|
module_exit(sunsu_exit);
|
2006-06-30 06:14:17 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Eddie C. Dost, Peter Zaitcev, and David S. Miller");
|
|
|
|
MODULE_DESCRIPTION("Sun SU serial port driver");
|
|
|
|
MODULE_VERSION("2.0");
|
2006-05-16 05:10:11 +08:00
|
|
|
MODULE_LICENSE("GPL");
|