mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 02:50:43 +00:00
![David Howells](/assets/img/avatar_default.png)
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)
250 lines
6 KiB
C
250 lines
6 KiB
C
/*
|
|
* Input device TTY line discipline
|
|
*
|
|
* Copyright (c) 1999-2002 Vojtech Pavlik
|
|
*
|
|
* This is a module that converts a tty line into a much simpler
|
|
* 'serial io port' abstraction that the input device drivers use.
|
|
*/
|
|
|
|
/*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
* the Free Software Foundation.
|
|
*/
|
|
|
|
#include <asm/uaccess.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/serio.h>
|
|
#include <linux/tty.h>
|
|
|
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
|
|
MODULE_DESCRIPTION("Input device TTY line discipline");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS_LDISC(N_MOUSE);
|
|
|
|
#define SERPORT_BUSY 1
|
|
#define SERPORT_ACTIVE 2
|
|
#define SERPORT_DEAD 3
|
|
|
|
struct serport {
|
|
struct tty_struct *tty;
|
|
wait_queue_head_t wait;
|
|
struct serio *serio;
|
|
struct serio_device_id id;
|
|
spinlock_t lock;
|
|
unsigned long flags;
|
|
};
|
|
|
|
/*
|
|
* Callback functions from the serio code.
|
|
*/
|
|
|
|
static int serport_serio_write(struct serio *serio, unsigned char data)
|
|
{
|
|
struct serport *serport = serio->port_data;
|
|
return -(serport->tty->driver->write(serport->tty, &data, 1) != 1);
|
|
}
|
|
|
|
static int serport_serio_open(struct serio *serio)
|
|
{
|
|
struct serport *serport = serio->port_data;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&serport->lock, flags);
|
|
set_bit(SERPORT_ACTIVE, &serport->flags);
|
|
spin_unlock_irqrestore(&serport->lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static void serport_serio_close(struct serio *serio)
|
|
{
|
|
struct serport *serport = serio->port_data;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&serport->lock, flags);
|
|
clear_bit(SERPORT_ACTIVE, &serport->flags);
|
|
set_bit(SERPORT_DEAD, &serport->flags);
|
|
spin_unlock_irqrestore(&serport->lock, flags);
|
|
|
|
wake_up_interruptible(&serport->wait);
|
|
}
|
|
|
|
/*
|
|
* serport_ldisc_open() is the routine that is called upon setting our line
|
|
* discipline on a tty. It prepares the serio struct.
|
|
*/
|
|
|
|
static int serport_ldisc_open(struct tty_struct *tty)
|
|
{
|
|
struct serport *serport;
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
return -EPERM;
|
|
|
|
serport = kzalloc(sizeof(struct serport), GFP_KERNEL);
|
|
if (!serport)
|
|
return -ENOMEM;
|
|
|
|
serport->tty = tty;
|
|
spin_lock_init(&serport->lock);
|
|
init_waitqueue_head(&serport->wait);
|
|
|
|
tty->disc_data = serport;
|
|
tty->receive_room = 256;
|
|
set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* serport_ldisc_close() is the opposite of serport_ldisc_open()
|
|
*/
|
|
|
|
static void serport_ldisc_close(struct tty_struct *tty)
|
|
{
|
|
struct serport *serport = (struct serport *) tty->disc_data;
|
|
|
|
kfree(serport);
|
|
}
|
|
|
|
/*
|
|
* serport_ldisc_receive() is called by the low level tty driver when characters
|
|
* are ready for us. We forward the characters, one by one to the 'interrupt'
|
|
* routine.
|
|
*/
|
|
|
|
static void serport_ldisc_receive(struct tty_struct *tty, const unsigned char *cp, char *fp, int count)
|
|
{
|
|
struct serport *serport = (struct serport*) tty->disc_data;
|
|
unsigned long flags;
|
|
int i;
|
|
|
|
spin_lock_irqsave(&serport->lock, flags);
|
|
|
|
if (!test_bit(SERPORT_ACTIVE, &serport->flags))
|
|
goto out;
|
|
|
|
for (i = 0; i < count; i++)
|
|
serio_interrupt(serport->serio, cp[i], 0);
|
|
|
|
out:
|
|
spin_unlock_irqrestore(&serport->lock, flags);
|
|
}
|
|
|
|
/*
|
|
* serport_ldisc_read() just waits indefinitely if everything goes well.
|
|
* However, when the serio driver closes the serio port, it finishes,
|
|
* returning 0 characters.
|
|
*/
|
|
|
|
static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file, unsigned char __user * buf, size_t nr)
|
|
{
|
|
struct serport *serport = (struct serport*) tty->disc_data;
|
|
struct serio *serio;
|
|
char name[64];
|
|
|
|
if (test_and_set_bit(SERPORT_BUSY, &serport->flags))
|
|
return -EBUSY;
|
|
|
|
serport->serio = serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
|
|
if (!serio)
|
|
return -ENOMEM;
|
|
|
|
strlcpy(serio->name, "Serial port", sizeof(serio->name));
|
|
snprintf(serio->phys, sizeof(serio->phys), "%s/serio0", tty_name(tty, name));
|
|
serio->id = serport->id;
|
|
serio->id.type = SERIO_RS232;
|
|
serio->write = serport_serio_write;
|
|
serio->open = serport_serio_open;
|
|
serio->close = serport_serio_close;
|
|
serio->port_data = serport;
|
|
|
|
serio_register_port(serport->serio);
|
|
printk(KERN_INFO "serio: Serial port %s\n", tty_name(tty, name));
|
|
|
|
wait_event_interruptible(serport->wait, test_bit(SERPORT_DEAD, &serport->flags));
|
|
serio_unregister_port(serport->serio);
|
|
serport->serio = NULL;
|
|
|
|
clear_bit(SERPORT_DEAD, &serport->flags);
|
|
clear_bit(SERPORT_BUSY, &serport->flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* serport_ldisc_ioctl() allows to set the port protocol, and device ID
|
|
*/
|
|
|
|
static int serport_ldisc_ioctl(struct tty_struct * tty, struct file * file, unsigned int cmd, unsigned long arg)
|
|
{
|
|
struct serport *serport = (struct serport*) tty->disc_data;
|
|
unsigned long type;
|
|
|
|
if (cmd == SPIOCSTYPE) {
|
|
if (get_user(type, (unsigned long __user *) arg))
|
|
return -EFAULT;
|
|
|
|
serport->id.proto = type & 0x000000ff;
|
|
serport->id.id = (type & 0x0000ff00) >> 8;
|
|
serport->id.extra = (type & 0x00ff0000) >> 16;
|
|
|
|
return 0;
|
|
}
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
static void serport_ldisc_write_wakeup(struct tty_struct * tty)
|
|
{
|
|
struct serport *serport = (struct serport *) tty->disc_data;
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&serport->lock, flags);
|
|
if (test_bit(SERPORT_ACTIVE, &serport->flags))
|
|
serio_drv_write_wakeup(serport->serio);
|
|
spin_unlock_irqrestore(&serport->lock, flags);
|
|
}
|
|
|
|
/*
|
|
* The line discipline structure.
|
|
*/
|
|
|
|
static struct tty_ldisc serport_ldisc = {
|
|
.owner = THIS_MODULE,
|
|
.name = "input",
|
|
.open = serport_ldisc_open,
|
|
.close = serport_ldisc_close,
|
|
.read = serport_ldisc_read,
|
|
.ioctl = serport_ldisc_ioctl,
|
|
.receive_buf = serport_ldisc_receive,
|
|
.write_wakeup = serport_ldisc_write_wakeup
|
|
};
|
|
|
|
/*
|
|
* The functions for insering/removing us as a module.
|
|
*/
|
|
|
|
static int __init serport_init(void)
|
|
{
|
|
int retval;
|
|
retval = tty_register_ldisc(N_MOUSE, &serport_ldisc);
|
|
if (retval)
|
|
printk(KERN_ERR "serport.c: Error registering line discipline.\n");
|
|
|
|
return retval;
|
|
}
|
|
|
|
static void __exit serport_exit(void)
|
|
{
|
|
tty_unregister_ldisc(N_MOUSE);
|
|
}
|
|
|
|
module_init(serport_init);
|
|
module_exit(serport_exit);
|