linux_dsm_epyc7002/drivers/parport/parport_atari.c
David Howells 7d12e780e0 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 15:10:12 +01:00

241 lines
5.7 KiB
C

/* Low-level parallel port routines for the Atari builtin port
*
* Author: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
*
* Based on parport_amiga.c.
*
* The built-in Atari parallel port provides one port at a fixed address
* with 8 output data lines (D0 - D7), 1 output control line (STROBE)
* and 1 input status line (BUSY) able to cause an interrupt.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/parport.h>
#include <linux/interrupt.h>
#include <asm/setup.h>
#include <asm/atarihw.h>
#include <asm/irq.h>
#include <asm/atariints.h>
static struct parport *this_port = NULL;
static unsigned char
parport_atari_read_data(struct parport *p)
{
unsigned long flags;
unsigned char data;
local_irq_save(flags);
sound_ym.rd_data_reg_sel = 15;
data = sound_ym.rd_data_reg_sel;
local_irq_restore(flags);
return data;
}
static void
parport_atari_write_data(struct parport *p, unsigned char data)
{
unsigned long flags;
local_irq_save(flags);
sound_ym.rd_data_reg_sel = 15;
sound_ym.wd_data = data;
local_irq_restore(flags);
}
static unsigned char
parport_atari_read_control(struct parport *p)
{
unsigned long flags;
unsigned char control = 0;
local_irq_save(flags);
sound_ym.rd_data_reg_sel = 14;
if (!(sound_ym.rd_data_reg_sel & (1 << 5)))
control = PARPORT_CONTROL_STROBE;
local_irq_restore(flags);
return control;
}
static void
parport_atari_write_control(struct parport *p, unsigned char control)
{
unsigned long flags;
local_irq_save(flags);
sound_ym.rd_data_reg_sel = 14;
if (control & PARPORT_CONTROL_STROBE)
sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~(1 << 5);
else
sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
local_irq_restore(flags);
}
static unsigned char
parport_atari_frob_control(struct parport *p, unsigned char mask,
unsigned char val)
{
unsigned char old = parport_atari_read_control(p);
parport_atari_write_control(p, (old & ~mask) ^ val);
return old;
}
static unsigned char
parport_atari_read_status(struct parport *p)
{
return ((mfp.par_dt_reg & 1 ? 0 : PARPORT_STATUS_BUSY) |
PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR);
}
static void
parport_atari_init_state(struct pardevice *d, struct parport_state *s)
{
}
static void
parport_atari_save_state(struct parport *p, struct parport_state *s)
{
}
static void
parport_atari_restore_state(struct parport *p, struct parport_state *s)
{
}
static irqreturn_t
parport_atari_interrupt(int irq, void *dev_id)
{
parport_generic_irq(irq, (struct parport *) dev_id);
return IRQ_HANDLED;
}
static void
parport_atari_enable_irq(struct parport *p)
{
enable_irq(IRQ_MFP_BUSY);
}
static void
parport_atari_disable_irq(struct parport *p)
{
disable_irq(IRQ_MFP_BUSY);
}
static void
parport_atari_data_forward(struct parport *p)
{
unsigned long flags;
local_irq_save(flags);
/* Soundchip port B as output. */
sound_ym.rd_data_reg_sel = 7;
sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x40;
local_irq_restore(flags);
}
static void
parport_atari_data_reverse(struct parport *p)
{
#if 0 /* too dangerous, can kill sound chip */
unsigned long flags;
local_irq_save(flags);
/* Soundchip port B as input. */
sound_ym.rd_data_reg_sel = 7;
sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~0x40;
local_irq_restore(flags);
#endif
}
static struct parport_operations parport_atari_ops = {
.write_data = parport_atari_write_data,
.read_data = parport_atari_read_data,
.write_control = parport_atari_write_control,
.read_control = parport_atari_read_control,
.frob_control = parport_atari_frob_control,
.read_status = parport_atari_read_status,
.enable_irq = parport_atari_enable_irq,
.disable_irq = parport_atari_disable_irq,
.data_forward = parport_atari_data_forward,
.data_reverse = parport_atari_data_reverse,
.init_state = parport_atari_init_state,
.save_state = parport_atari_save_state,
.restore_state = parport_atari_restore_state,
.epp_write_data = parport_ieee1284_epp_write_data,
.epp_read_data = parport_ieee1284_epp_read_data,
.epp_write_addr = parport_ieee1284_epp_write_addr,
.epp_read_addr = parport_ieee1284_epp_read_addr,
.ecp_write_data = parport_ieee1284_ecp_write_data,
.ecp_read_data = parport_ieee1284_ecp_read_data,
.ecp_write_addr = parport_ieee1284_ecp_write_addr,
.compat_write_data = parport_ieee1284_write_compat,
.nibble_read_data = parport_ieee1284_read_nibble,
.byte_read_data = parport_ieee1284_read_byte,
.owner = THIS_MODULE,
};
static int __init parport_atari_init(void)
{
struct parport *p;
unsigned long flags;
if (MACH_IS_ATARI) {
local_irq_save(flags);
/* Soundchip port A/B as output. */
sound_ym.rd_data_reg_sel = 7;
sound_ym.wd_data = (sound_ym.rd_data_reg_sel & 0x3f) | 0xc0;
/* STROBE high. */
sound_ym.rd_data_reg_sel = 14;
sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5);
local_irq_restore(flags);
/* MFP port I0 as input. */
mfp.data_dir &= ~1;
/* MFP port I0 interrupt on high->low edge. */
mfp.active_edge &= ~1;
p = parport_register_port((unsigned long)&sound_ym.wd_data,
IRQ_MFP_BUSY, PARPORT_DMA_NONE,
&parport_atari_ops);
if (!p)
return -ENODEV;
if (request_irq(IRQ_MFP_BUSY, parport_atari_interrupt,
IRQ_TYPE_SLOW, p->name, p)) {
parport_put_port (p);
return -ENODEV;
}
this_port = p;
printk(KERN_INFO "%s: Atari built-in port using irq\n", p->name);
parport_announce_port (p);
return 0;
}
return -ENODEV;
}
static void __exit parport_atari_exit(void)
{
parport_remove_port(this_port);
if (this_port->irq != PARPORT_IRQ_NONE)
free_irq(IRQ_MFP_BUSY, this_port);
parport_put_port(this_port);
}
MODULE_AUTHOR("Andreas Schwab");
MODULE_DESCRIPTION("Parport Driver for Atari builtin Port");
MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port");
MODULE_LICENSE("GPL");
module_init(parport_atari_init)
module_exit(parport_atari_exit)