2005-10-26 06:47:42 +00:00
|
|
|
/*
|
|
|
|
* i8259 interrupt controller driver.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
2006-07-03 11:36:01 +00:00
|
|
|
#undef DEBUG
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/interrupt.h>
|
2006-07-03 11:36:01 +00:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/delay.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/i8259.h>
|
2006-07-03 11:36:01 +00:00
|
|
|
#include <asm/prom.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-26 06:47:42 +00:00
|
|
|
static volatile void __iomem *pci_intack; /* RO, gives us the irq vector */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-26 06:47:42 +00:00
|
|
|
static unsigned char cached_8259[2] = { 0xff, 0xff };
|
2005-04-16 22:20:36 +00:00
|
|
|
#define cached_A1 (cached_8259[0])
|
|
|
|
#define cached_21 (cached_8259[1])
|
|
|
|
|
2010-02-18 02:23:11 +00:00
|
|
|
static DEFINE_RAW_SPINLOCK(i8259_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-02-14 21:06:50 +00:00
|
|
|
static struct irq_domain *i8259_host;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Acknowledge the IRQ using either the PCI host bridge's interrupt
|
|
|
|
* acknowledge feature or poll. How i8259_init() is called determines
|
|
|
|
* which is called. It should be noted that polling is broken on some
|
|
|
|
* IBM and Motorola PReP boxes so we must use the int-ack feature on them.
|
|
|
|
*/
|
2006-10-07 12:08:26 +00:00
|
|
|
unsigned int i8259_irq(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int irq;
|
2006-07-03 11:36:01 +00:00
|
|
|
int lock = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Either int-ack or poll for the IRQ */
|
|
|
|
if (pci_intack)
|
2005-10-26 06:47:42 +00:00
|
|
|
irq = readb(pci_intack);
|
2005-04-16 22:20:36 +00:00
|
|
|
else {
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_lock(&i8259_lock);
|
2006-07-03 11:36:01 +00:00
|
|
|
lock = 1;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Perform an interrupt acknowledge cycle on controller 1. */
|
|
|
|
outb(0x0C, 0x20); /* prepare for poll */
|
|
|
|
irq = inb(0x20) & 7;
|
|
|
|
if (irq == 2 ) {
|
|
|
|
/*
|
|
|
|
* Interrupt is cascaded so perform interrupt
|
|
|
|
* acknowledge on controller 2.
|
|
|
|
*/
|
|
|
|
outb(0x0C, 0xA0); /* prepare for poll */
|
|
|
|
irq = (inb(0xA0) & 7) + 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (irq == 7) {
|
|
|
|
/*
|
|
|
|
* This may be a spurious interrupt.
|
|
|
|
*
|
|
|
|
* Read the interrupt status register (ISR). If the most
|
|
|
|
* significant bit is not set then there is no valid
|
|
|
|
* interrupt.
|
|
|
|
*/
|
|
|
|
if (!pci_intack)
|
|
|
|
outb(0x0B, 0x20); /* ISR register */
|
|
|
|
if(~inb(0x20) & 0x80)
|
2006-07-03 11:36:01 +00:00
|
|
|
irq = NO_IRQ;
|
|
|
|
} else if (irq == 0xff)
|
|
|
|
irq = NO_IRQ;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-03 11:36:01 +00:00
|
|
|
if (lock)
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_unlock(&i8259_lock);
|
2006-07-03 11:36:01 +00:00
|
|
|
return irq;
|
2005-10-26 06:47:42 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 13:59:56 +00:00
|
|
|
static void i8259_mask_and_ack_irq(struct irq_data *d)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_lock_irqsave(&i8259_lock, flags);
|
2011-03-07 13:59:56 +00:00
|
|
|
if (d->irq > 7) {
|
|
|
|
cached_A1 |= 1 << (d->irq-8);
|
2005-10-26 06:47:42 +00:00
|
|
|
inb(0xA1); /* DUMMY */
|
|
|
|
outb(cached_A1, 0xA1);
|
|
|
|
outb(0x20, 0xA0); /* Non-specific EOI */
|
|
|
|
outb(0x20, 0x20); /* Non-specific EOI to cascade */
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2011-03-07 13:59:56 +00:00
|
|
|
cached_21 |= 1 << d->irq;
|
2005-10-26 06:47:42 +00:00
|
|
|
inb(0x21); /* DUMMY */
|
|
|
|
outb(cached_21, 0x21);
|
|
|
|
outb(0x20, 0x20); /* Non-specific EOI */
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_unlock_irqrestore(&i8259_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void i8259_set_irq_mask(int irq_nr)
|
|
|
|
{
|
|
|
|
outb(cached_A1,0xA1);
|
|
|
|
outb(cached_21,0x21);
|
|
|
|
}
|
|
|
|
|
2011-03-07 13:59:56 +00:00
|
|
|
static void i8259_mask_irq(struct irq_data *d)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-03-07 13:59:56 +00:00
|
|
|
pr_debug("i8259_mask_irq(%d)\n", d->irq);
|
2006-07-03 11:36:01 +00:00
|
|
|
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_lock_irqsave(&i8259_lock, flags);
|
2011-03-07 13:59:56 +00:00
|
|
|
if (d->irq < 8)
|
|
|
|
cached_21 |= 1 << d->irq;
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2011-03-07 13:59:56 +00:00
|
|
|
cached_A1 |= 1 << (d->irq-8);
|
|
|
|
i8259_set_irq_mask(d->irq);
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_unlock_irqrestore(&i8259_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2011-03-07 13:59:56 +00:00
|
|
|
static void i8259_unmask_irq(struct irq_data *d)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2011-03-07 13:59:56 +00:00
|
|
|
pr_debug("i8259_unmask_irq(%d)\n", d->irq);
|
2006-07-03 11:36:01 +00:00
|
|
|
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_lock_irqsave(&i8259_lock, flags);
|
2011-03-07 13:59:56 +00:00
|
|
|
if (d->irq < 8)
|
|
|
|
cached_21 &= ~(1 << d->irq);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2011-03-07 13:59:56 +00:00
|
|
|
cached_A1 &= ~(1 << (d->irq-8));
|
|
|
|
i8259_set_irq_mask(d->irq);
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_unlock_irqrestore(&i8259_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-07-03 09:32:51 +00:00
|
|
|
static struct irq_chip i8259_pic = {
|
2010-01-31 20:33:41 +00:00
|
|
|
.name = "i8259",
|
2011-03-07 13:59:56 +00:00
|
|
|
.irq_mask = i8259_mask_irq,
|
|
|
|
.irq_disable = i8259_mask_irq,
|
|
|
|
.irq_unmask = i8259_unmask_irq,
|
|
|
|
.irq_mask_ack = i8259_mask_and_ack_irq,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource pic1_iores = {
|
|
|
|
.name = "8259 (master)",
|
|
|
|
.start = 0x20,
|
|
|
|
.end = 0x21,
|
|
|
|
.flags = IORESOURCE_BUSY,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource pic2_iores = {
|
|
|
|
.name = "8259 (slave)",
|
|
|
|
.start = 0xa0,
|
|
|
|
.end = 0xa1,
|
|
|
|
.flags = IORESOURCE_BUSY,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource pic_edgectrl_iores = {
|
|
|
|
.name = "8259 edge control",
|
|
|
|
.start = 0x4d0,
|
|
|
|
.end = 0x4d1,
|
|
|
|
.flags = IORESOURCE_BUSY,
|
|
|
|
};
|
|
|
|
|
2012-02-14 21:06:50 +00:00
|
|
|
static int i8259_host_match(struct irq_domain *h, struct device_node *node)
|
2006-07-03 11:36:01 +00:00
|
|
|
{
|
2007-08-28 08:47:54 +00:00
|
|
|
return h->of_node == NULL || h->of_node == node;
|
2006-07-03 11:36:01 +00:00
|
|
|
}
|
|
|
|
|
2012-02-14 21:06:50 +00:00
|
|
|
static int i8259_host_map(struct irq_domain *h, unsigned int virq,
|
[PATCH] powerpc: fix trigger handling in the new irq code
This patch slightly reworks the new irq code to fix a small design error. I
removed the passing of the trigger to the map() calls entirely, it was not a
good idea to have one call do two different things. It also fixes a couple of
corner cases.
Mapping a linux virtual irq to a physical irq now does only that. Setting the
trigger is a different action which has a different call.
The main changes are:
- I no longer call host->ops->map() for an already mapped irq, I just return
the virtual number that was already mapped. It was called before to give an
opportunity to change the trigger, but that was causing issues as that could
happen while the interrupt was in use by a device, and because of the
trigger change, map would potentially muck around with things in a racy way.
That was causing much burden on a given's controller implementation of
map() to get it right. This is much simpler now. map() is only called on
the initial mapping of an irq, meaning that you know that this irq is _not_
being used. You can initialize the hardware if you want (though you don't
have to).
- Controllers that can handle different type of triggers (level/edge/etc...)
now implement the standard irq_chip->set_type() call as defined by the
generic code. That means that you can use the standard set_irq_type() to
configure an irq line manually if you wish or (though I don't like that
interface), pass explicit trigger flags to request_irq() as defined by the
generic kernel interfaces. Also, using those interfaces guarantees that
your controller set_type callback is called with the descriptor lock held,
thus providing locking against activity on the same interrupt (including
mask/unmask/etc...) automatically. A result is that, for example, MPIC's
own map() implementation calls irq_set_type(NONE) to configure the hardware
to the default triggers.
- To allow the above, the irq_map array entry for the new mapped interrupt
is now set before map() callback is called for the controller.
- The irq_create_of_mapping() (also used by irq_of_parse_and_map()) function
for mapping interrupts from the device-tree now also call the separate
set_irq_type(), and only does so if there is a change in the trigger type.
- While I was at it, I changed pci_read_irq_line() (which is the helper I
would expect most archs to use in their pcibios_fixup() to get the PCI
interrupt routing from the device tree) to also handle a fallback when the
DT mapping fails consisting of reading the PCI_INTERRUPT_PIN to know wether
the device has an interrupt at all, and the the PCI_INTERRUPT_LINE to get an
interrupt number from the device. That number is then mapped using the
default controller, and the trigger is set to level low. That default
behaviour works for several platforms that don't have a proper interrupt
tree like Pegasos. If it doesn't work for your platform, then either
provide a proper interrupt tree from the firmware so that fallback isn't
needed, or don't call pci_read_irq_line()
- Add back a bit that got dropped by my main rework patch for properly
clearing pending IPIs on pSeries when using a kexec
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-07-10 11:44:42 +00:00
|
|
|
irq_hw_number_t hw)
|
2006-07-03 11:36:01 +00:00
|
|
|
{
|
|
|
|
pr_debug("i8259_host_map(%d, 0x%lx)\n", virq, hw);
|
|
|
|
|
|
|
|
/* We block the internal cascade */
|
|
|
|
if (hw == 2)
|
2011-03-25 14:43:57 +00:00
|
|
|
irq_set_status_flags(virq, IRQ_NOREQUEST);
|
2006-07-03 11:36:01 +00:00
|
|
|
|
[PATCH] powerpc: fix trigger handling in the new irq code
This patch slightly reworks the new irq code to fix a small design error. I
removed the passing of the trigger to the map() calls entirely, it was not a
good idea to have one call do two different things. It also fixes a couple of
corner cases.
Mapping a linux virtual irq to a physical irq now does only that. Setting the
trigger is a different action which has a different call.
The main changes are:
- I no longer call host->ops->map() for an already mapped irq, I just return
the virtual number that was already mapped. It was called before to give an
opportunity to change the trigger, but that was causing issues as that could
happen while the interrupt was in use by a device, and because of the
trigger change, map would potentially muck around with things in a racy way.
That was causing much burden on a given's controller implementation of
map() to get it right. This is much simpler now. map() is only called on
the initial mapping of an irq, meaning that you know that this irq is _not_
being used. You can initialize the hardware if you want (though you don't
have to).
- Controllers that can handle different type of triggers (level/edge/etc...)
now implement the standard irq_chip->set_type() call as defined by the
generic code. That means that you can use the standard set_irq_type() to
configure an irq line manually if you wish or (though I don't like that
interface), pass explicit trigger flags to request_irq() as defined by the
generic kernel interfaces. Also, using those interfaces guarantees that
your controller set_type callback is called with the descriptor lock held,
thus providing locking against activity on the same interrupt (including
mask/unmask/etc...) automatically. A result is that, for example, MPIC's
own map() implementation calls irq_set_type(NONE) to configure the hardware
to the default triggers.
- To allow the above, the irq_map array entry for the new mapped interrupt
is now set before map() callback is called for the controller.
- The irq_create_of_mapping() (also used by irq_of_parse_and_map()) function
for mapping interrupts from the device-tree now also call the separate
set_irq_type(), and only does so if there is a change in the trigger type.
- While I was at it, I changed pci_read_irq_line() (which is the helper I
would expect most archs to use in their pcibios_fixup() to get the PCI
interrupt routing from the device tree) to also handle a fallback when the
DT mapping fails consisting of reading the PCI_INTERRUPT_PIN to know wether
the device has an interrupt at all, and the the PCI_INTERRUPT_LINE to get an
interrupt number from the device. That number is then mapped using the
default controller, and the trigger is set to level low. That default
behaviour works for several platforms that don't have a proper interrupt
tree like Pegasos. If it doesn't work for your platform, then either
provide a proper interrupt tree from the firmware so that fallback isn't
needed, or don't call pci_read_irq_line()
- Add back a bit that got dropped by my main rework patch for properly
clearing pending IPIs on pSeries when using a kexec
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-07-10 11:44:42 +00:00
|
|
|
/* We use the level handler only for now, we might want to
|
2006-07-03 11:36:01 +00:00
|
|
|
* be more cautious here but that works for now
|
|
|
|
*/
|
2011-03-25 14:43:57 +00:00
|
|
|
irq_set_status_flags(virq, IRQ_LEVEL);
|
2011-03-25 15:45:20 +00:00
|
|
|
irq_set_chip_and_handler(virq, &i8259_pic, handle_level_irq);
|
2006-07-03 11:36:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-14 21:06:50 +00:00
|
|
|
static int i8259_host_xlate(struct irq_domain *h, struct device_node *ct,
|
2009-12-08 02:39:50 +00:00
|
|
|
const u32 *intspec, unsigned int intsize,
|
2006-07-03 11:36:01 +00:00
|
|
|
irq_hw_number_t *out_hwirq, unsigned int *out_flags)
|
|
|
|
{
|
|
|
|
static unsigned char map_isa_senses[4] = {
|
|
|
|
IRQ_TYPE_LEVEL_LOW,
|
|
|
|
IRQ_TYPE_LEVEL_HIGH,
|
|
|
|
IRQ_TYPE_EDGE_FALLING,
|
|
|
|
IRQ_TYPE_EDGE_RISING,
|
|
|
|
};
|
|
|
|
|
|
|
|
*out_hwirq = intspec[0];
|
|
|
|
if (intsize > 1 && intspec[1] < 4)
|
|
|
|
*out_flags = map_isa_senses[intspec[1]];
|
|
|
|
else
|
|
|
|
*out_flags = IRQ_TYPE_NONE;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-14 21:06:50 +00:00
|
|
|
static struct irq_domain_ops i8259_host_ops = {
|
2006-07-03 11:36:01 +00:00
|
|
|
.match = i8259_host_match,
|
|
|
|
.map = i8259_host_map,
|
|
|
|
.xlate = i8259_host_xlate,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2012-02-14 21:06:50 +00:00
|
|
|
struct irq_domain *i8259_get_host(void)
|
2006-10-25 03:22:27 +00:00
|
|
|
{
|
|
|
|
return i8259_host;
|
|
|
|
}
|
|
|
|
|
2006-08-02 01:13:50 +00:00
|
|
|
/**
|
2006-07-03 11:36:01 +00:00
|
|
|
* i8259_init - Initialize the legacy controller
|
|
|
|
* @node: device node of the legacy PIC (can be NULL, but then, it will match
|
|
|
|
* all interrupts, so beware)
|
|
|
|
* @intack_addr: PCI interrupt acknowledge (real) address which will return
|
|
|
|
* the active irq from the 8259
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
2006-07-03 11:36:01 +00:00
|
|
|
void i8259_init(struct device_node *node, unsigned long intack_addr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2006-07-03 11:36:01 +00:00
|
|
|
/* initialize the controller */
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_lock_irqsave(&i8259_lock, flags);
|
2006-07-03 11:36:01 +00:00
|
|
|
|
|
|
|
/* Mask all first */
|
|
|
|
outb(0xff, 0xA1);
|
|
|
|
outb(0xff, 0x21);
|
2005-10-26 06:47:42 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* init master interrupt controller */
|
|
|
|
outb(0x11, 0x20); /* Start init sequence */
|
|
|
|
outb(0x00, 0x21); /* Vector base */
|
|
|
|
outb(0x04, 0x21); /* edge tiggered, Cascade (slave) on IRQ2 */
|
|
|
|
outb(0x01, 0x21); /* Select 8086 mode */
|
|
|
|
|
|
|
|
/* init slave interrupt controller */
|
|
|
|
outb(0x11, 0xA0); /* Start init sequence */
|
|
|
|
outb(0x08, 0xA1); /* Vector base */
|
|
|
|
outb(0x02, 0xA1); /* edge triggered, Cascade (slave) on IRQ2 */
|
|
|
|
outb(0x01, 0xA1); /* Select 8086 mode */
|
|
|
|
|
2006-07-03 11:36:01 +00:00
|
|
|
/* That thing is slow */
|
|
|
|
udelay(100);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* always read ISR */
|
|
|
|
outb(0x0B, 0x20);
|
|
|
|
outb(0x0B, 0xA0);
|
|
|
|
|
2006-07-03 11:36:01 +00:00
|
|
|
/* Unmask the internal cascade */
|
|
|
|
cached_21 &= ~(1 << 2);
|
|
|
|
|
|
|
|
/* Set interrupt masks */
|
2005-04-16 22:20:36 +00:00
|
|
|
outb(cached_A1, 0xA1);
|
|
|
|
outb(cached_21, 0x21);
|
|
|
|
|
2010-02-18 02:23:11 +00:00
|
|
|
raw_spin_unlock_irqrestore(&i8259_lock, flags);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-07-03 11:36:01 +00:00
|
|
|
/* create a legacy host */
|
2012-02-14 21:06:55 +00:00
|
|
|
i8259_host = irq_domain_add_legacy_isa(node, &i8259_host_ops, NULL);
|
2006-07-03 11:36:01 +00:00
|
|
|
if (i8259_host == NULL) {
|
|
|
|
printk(KERN_ERR "i8259: failed to allocate irq host !\n");
|
|
|
|
return;
|
2006-07-03 09:32:51 +00:00
|
|
|
}
|
2005-11-05 17:54:22 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* reserve our resources */
|
2006-07-03 11:36:01 +00:00
|
|
|
/* XXX should we continue doing that ? it seems to cause problems
|
|
|
|
* with further requesting of PCI IO resources for that range...
|
|
|
|
* need to look into it.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
request_resource(&ioport_resource, &pic1_iores);
|
|
|
|
request_resource(&ioport_resource, &pic2_iores);
|
|
|
|
request_resource(&ioport_resource, &pic_edgectrl_iores);
|
|
|
|
|
|
|
|
if (intack_addr != 0)
|
|
|
|
pci_intack = ioremap(intack_addr, 1);
|
2005-10-26 06:47:42 +00:00
|
|
|
|
2006-07-03 11:36:01 +00:00
|
|
|
printk(KERN_INFO "i8259 legacy interrupt controller initialized\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|