2005-06-23 07:43:43 +08:00
|
|
|
/*
|
2005-11-01 09:08:37 +08:00
|
|
|
* Cell Internal Interrupt Controller
|
2005-06-23 07:43:43 +08:00
|
|
|
*
|
|
|
|
* (C) Copyright IBM Deutschland Entwicklung GmbH 2005
|
|
|
|
*
|
|
|
|
* Author: Arnd Bergmann <arndb@de.ibm.com>
|
|
|
|
*
|
|
|
|
* 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, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/irq.h>
|
2006-01-05 22:05:29 +08:00
|
|
|
#include <linux/module.h>
|
2005-06-23 07:43:43 +08:00
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/ptrace.h>
|
|
|
|
|
2005-11-01 09:08:37 +08:00
|
|
|
#include "interrupt.h"
|
2006-06-20 02:33:16 +08:00
|
|
|
#include "cbe_regs.h"
|
2005-06-23 07:43:43 +08:00
|
|
|
|
|
|
|
struct iic {
|
2006-06-20 02:33:16 +08:00
|
|
|
struct cbe_iic_thread_regs __iomem *regs;
|
2006-01-05 22:05:29 +08:00
|
|
|
u8 target_id;
|
2005-06-23 07:43:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static DEFINE_PER_CPU(struct iic, iic);
|
|
|
|
|
|
|
|
void iic_local_enable(void)
|
|
|
|
{
|
2006-03-23 07:00:07 +08:00
|
|
|
struct iic *iic = &__get_cpu_var(iic);
|
|
|
|
u64 tmp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There seems to be a bug that is present in DD2.x CPUs
|
|
|
|
* and still only partially fixed in DD3.1.
|
|
|
|
* This bug causes a value written to the priority register
|
|
|
|
* not to make it there, resulting in a system hang unless we
|
|
|
|
* write it again.
|
|
|
|
* Masking with 0xf0 is done because the Cell BE does not
|
|
|
|
* implement the lower four bits of the interrupt priority,
|
|
|
|
* they always read back as zeroes, although future CPUs
|
|
|
|
* might implement different bits.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
out_be64(&iic->regs->prio, 0xff);
|
|
|
|
tmp = in_be64(&iic->regs->prio);
|
|
|
|
} while ((tmp & 0xf0) != 0xf0);
|
2005-06-23 07:43:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void iic_local_disable(void)
|
|
|
|
{
|
|
|
|
out_be64(&__get_cpu_var(iic).regs->prio, 0x0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int iic_startup(unsigned int irq)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void iic_enable(unsigned int irq)
|
|
|
|
{
|
|
|
|
iic_local_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void iic_disable(unsigned int irq)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void iic_end(unsigned int irq)
|
|
|
|
{
|
|
|
|
iic_local_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct hw_interrupt_type iic_pic = {
|
2005-11-01 09:08:37 +08:00
|
|
|
.typename = " CELL-IIC ",
|
2005-06-23 07:43:43 +08:00
|
|
|
.startup = iic_startup,
|
|
|
|
.enable = iic_enable,
|
|
|
|
.disable = iic_disable,
|
|
|
|
.end = iic_end,
|
|
|
|
};
|
|
|
|
|
2006-06-20 02:33:16 +08:00
|
|
|
static int iic_external_get_irq(struct cbe_iic_pending_bits pending)
|
2005-06-23 07:43:43 +08:00
|
|
|
{
|
|
|
|
int irq;
|
|
|
|
unsigned char node, unit;
|
|
|
|
|
|
|
|
node = pending.source >> 4;
|
|
|
|
unit = pending.source & 0xf;
|
|
|
|
irq = -1;
|
|
|
|
|
|
|
|
/*
|
2005-11-01 09:08:37 +08:00
|
|
|
* This mapping is specific to the Cell Broadband
|
2005-06-23 07:43:43 +08:00
|
|
|
* Engine. We might need to get the numbers
|
|
|
|
* from the device tree to support future CPUs.
|
|
|
|
*/
|
|
|
|
switch (unit) {
|
|
|
|
case 0x00:
|
|
|
|
case 0x0b:
|
|
|
|
/*
|
|
|
|
* One of these units can be connected
|
|
|
|
* to an external interrupt controller.
|
|
|
|
*/
|
2006-06-20 02:33:17 +08:00
|
|
|
if (pending.class != 2)
|
2005-06-23 07:43:43 +08:00
|
|
|
break;
|
|
|
|
irq = IIC_EXT_OFFSET
|
2006-03-23 07:00:06 +08:00
|
|
|
+ spider_get_irq(node)
|
2005-06-23 07:43:43 +08:00
|
|
|
+ node * IIC_NODE_STRIDE;
|
|
|
|
break;
|
|
|
|
case 0x01 ... 0x04:
|
|
|
|
case 0x07 ... 0x0a:
|
|
|
|
/*
|
|
|
|
* These units are connected to the SPEs
|
|
|
|
*/
|
|
|
|
if (pending.class > 2)
|
|
|
|
break;
|
|
|
|
irq = IIC_SPE_OFFSET
|
|
|
|
+ pending.class * IIC_CLASS_STRIDE
|
|
|
|
+ node * IIC_NODE_STRIDE
|
|
|
|
+ unit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (irq == -1)
|
|
|
|
printk(KERN_WARNING "Unexpected interrupt class %02x, "
|
|
|
|
"source %02x, prio %02x, cpu %02x\n", pending.class,
|
|
|
|
pending.source, pending.prio, smp_processor_id());
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get an IRQ number from the pending state register of the IIC */
|
|
|
|
int iic_get_irq(struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
struct iic *iic;
|
|
|
|
int irq;
|
2006-06-20 02:33:16 +08:00
|
|
|
struct cbe_iic_pending_bits pending;
|
2005-06-23 07:43:43 +08:00
|
|
|
|
|
|
|
iic = &__get_cpu_var(iic);
|
|
|
|
*(unsigned long *) &pending =
|
|
|
|
in_be64((unsigned long __iomem *) &iic->regs->pending_destr);
|
|
|
|
|
|
|
|
irq = -1;
|
2006-06-20 02:33:16 +08:00
|
|
|
if (pending.flags & CBE_IIC_IRQ_VALID) {
|
|
|
|
if (pending.flags & CBE_IIC_IRQ_IPI) {
|
2005-06-23 07:43:43 +08:00
|
|
|
irq = IIC_IPI_OFFSET + (pending.prio >> 4);
|
|
|
|
/*
|
|
|
|
if (irq > 0x80)
|
|
|
|
printk(KERN_WARNING "Unexpected IPI prio %02x"
|
|
|
|
"on CPU %02x\n", pending.prio,
|
|
|
|
smp_processor_id());
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
irq = iic_external_get_irq(pending);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
2006-03-23 07:00:06 +08:00
|
|
|
/* hardcoded part to be compatible with older firmware */
|
|
|
|
|
|
|
|
static int setup_iic_hardcoded(void)
|
2005-06-23 07:43:43 +08:00
|
|
|
{
|
|
|
|
struct device_node *np;
|
2006-03-23 07:00:06 +08:00
|
|
|
int nodeid, cpu;
|
2005-06-23 07:43:43 +08:00
|
|
|
unsigned long regs;
|
2006-03-23 07:00:06 +08:00
|
|
|
struct iic *iic;
|
2005-06-23 07:43:43 +08:00
|
|
|
|
2006-06-25 20:46:43 +08:00
|
|
|
for_each_possible_cpu(cpu) {
|
2006-03-23 07:00:06 +08:00
|
|
|
iic = &per_cpu(iic, cpu);
|
|
|
|
nodeid = cpu/2;
|
|
|
|
|
|
|
|
for (np = of_find_node_by_type(NULL, "cpu");
|
|
|
|
np;
|
|
|
|
np = of_find_node_by_type(np, "cpu")) {
|
|
|
|
if (nodeid == *(int *)get_property(np, "node-id", NULL))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!np) {
|
|
|
|
printk(KERN_WARNING "IIC: CPU %d not found\n", cpu);
|
|
|
|
iic->regs = NULL;
|
|
|
|
iic->target_id = 0xff;
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
regs = *(long *)get_property(np, "iic", NULL);
|
|
|
|
|
|
|
|
/* hack until we have decided on the devtree info */
|
|
|
|
regs += 0x400;
|
|
|
|
if (cpu & 1)
|
|
|
|
regs += 0x20;
|
|
|
|
|
|
|
|
printk(KERN_INFO "IIC for CPU %d at %lx\n", cpu, regs);
|
2006-06-20 02:33:16 +08:00
|
|
|
iic->regs = ioremap(regs, sizeof(struct cbe_iic_thread_regs));
|
2006-03-23 07:00:06 +08:00
|
|
|
iic->target_id = (nodeid << 4) + ((cpu & 1) ? 0xf : 0xe);
|
2005-06-23 07:43:43 +08:00
|
|
|
}
|
|
|
|
|
2006-03-23 07:00:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2006-01-05 22:05:29 +08:00
|
|
|
|
2006-03-23 07:00:06 +08:00
|
|
|
static int setup_iic(void)
|
|
|
|
{
|
|
|
|
struct device_node *dn;
|
|
|
|
unsigned long *regs;
|
|
|
|
char *compatible;
|
|
|
|
unsigned *np, found = 0;
|
|
|
|
struct iic *iic = NULL;
|
|
|
|
|
|
|
|
for (dn = NULL; (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
|
|
|
|
compatible = (char *)get_property(dn, "compatible", NULL);
|
|
|
|
|
|
|
|
if (!compatible) {
|
|
|
|
printk(KERN_WARNING "no compatible property found !\n");
|
|
|
|
continue;
|
|
|
|
}
|
2006-01-05 22:05:29 +08:00
|
|
|
|
2006-03-23 07:00:06 +08:00
|
|
|
if (strstr(compatible, "IBM,CBEA-Internal-Interrupt-Controller"))
|
|
|
|
regs = (unsigned long *)get_property(dn,"reg", NULL);
|
|
|
|
else
|
|
|
|
continue;
|
2006-01-05 22:05:29 +08:00
|
|
|
|
2006-03-23 07:00:06 +08:00
|
|
|
if (!regs)
|
|
|
|
printk(KERN_WARNING "IIC: no reg property\n");
|
|
|
|
|
|
|
|
np = (unsigned int *)get_property(dn, "ibm,interrupt-server-ranges", NULL);
|
|
|
|
|
|
|
|
if (!np) {
|
|
|
|
printk(KERN_WARNING "IIC: CPU association not found\n");
|
|
|
|
iic->regs = NULL;
|
|
|
|
iic->target_id = 0xff;
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
iic = &per_cpu(iic, np[0]);
|
2006-06-20 02:33:16 +08:00
|
|
|
iic->regs = ioremap(regs[0], sizeof(struct cbe_iic_thread_regs));
|
2006-03-23 07:00:06 +08:00
|
|
|
iic->target_id = ((np[0] & 2) << 3) + ((np[0] & 1) ? 0xf : 0xe);
|
|
|
|
printk("IIC for CPU %d at %lx mapped to %p\n", np[0], regs[0], iic->regs);
|
|
|
|
|
|
|
|
iic = &per_cpu(iic, np[1]);
|
2006-06-20 02:33:16 +08:00
|
|
|
iic->regs = ioremap(regs[2], sizeof(struct cbe_iic_thread_regs));
|
2006-03-23 07:00:06 +08:00
|
|
|
iic->target_id = ((np[1] & 2) << 3) + ((np[1] & 1) ? 0xf : 0xe);
|
|
|
|
printk("IIC for CPU %d at %lx mapped to %p\n", np[1], regs[2], iic->regs);
|
|
|
|
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return -ENODEV;
|
2005-06-23 07:43:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2005-08-19 01:35:21 +08:00
|
|
|
|
|
|
|
/* Use the highest interrupt priorities for IPI */
|
|
|
|
static inline int iic_ipi_to_irq(int ipi)
|
|
|
|
{
|
|
|
|
return IIC_IPI_OFFSET + IIC_NUM_IPIS - 1 - ipi;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int iic_irq_to_ipi(int irq)
|
|
|
|
{
|
|
|
|
return IIC_NUM_IPIS - 1 - (irq - IIC_IPI_OFFSET);
|
|
|
|
}
|
|
|
|
|
2005-06-23 07:43:43 +08:00
|
|
|
void iic_setup_cpu(void)
|
|
|
|
{
|
|
|
|
out_be64(&__get_cpu_var(iic).regs->prio, 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void iic_cause_IPI(int cpu, int mesg)
|
|
|
|
{
|
2005-08-19 01:35:21 +08:00
|
|
|
out_be64(&per_cpu(iic, cpu).regs->generate, (IIC_NUM_IPIS - 1 - mesg) << 4);
|
2005-06-23 07:43:43 +08:00
|
|
|
}
|
|
|
|
|
2006-01-05 22:05:29 +08:00
|
|
|
u8 iic_get_target_id(int cpu)
|
|
|
|
{
|
|
|
|
return per_cpu(iic, cpu).target_id;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(iic_get_target_id);
|
|
|
|
|
2005-06-23 07:43:43 +08:00
|
|
|
static irqreturn_t iic_ipi_action(int irq, void *dev_id, struct pt_regs *regs)
|
|
|
|
{
|
2005-08-19 01:35:21 +08:00
|
|
|
smp_message_recv(iic_irq_to_ipi(irq), regs);
|
2005-06-23 07:43:43 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2005-08-19 01:35:21 +08:00
|
|
|
static void iic_request_ipi(int ipi, const char *name)
|
2005-06-23 07:43:43 +08:00
|
|
|
{
|
2005-08-19 01:35:21 +08:00
|
|
|
int irq;
|
|
|
|
|
|
|
|
irq = iic_ipi_to_irq(ipi);
|
2005-06-23 07:43:43 +08:00
|
|
|
/* IPIs are marked SA_INTERRUPT as they must run with irqs
|
|
|
|
* disabled */
|
[PATCH] genirq: rename desc->handler to desc->chip
This patch-queue improves the generic IRQ layer to be truly generic, by adding
various abstractions and features to it, without impacting existing
functionality.
While the queue can be best described as "fix and improve everything in the
generic IRQ layer that we could think of", and thus it consists of many
smaller features and lots of cleanups, the one feature that stands out most is
the new 'irq chip' abstraction.
The irq-chip abstraction is about describing and coding and IRQ controller
driver by mapping its raw hardware capabilities [and quirks, if needed] in a
straightforward way, without having to think about "IRQ flow"
(level/edge/etc.) type of details.
This stands in contrast with the current 'irq-type' model of genirq
architectures, which 'mixes' raw hardware capabilities with 'flow' details.
The patchset supports both types of irq controller designs at once, and
converts i386 and x86_64 to the new irq-chip design.
As a bonus side-effect of the irq-chip approach, chained interrupt controllers
(master/slave PIC constructs, etc.) are now supported by design as well.
The end result of this patchset intends to be simpler architecture-level code
and more consolidation between architectures.
We reused many bits of code and many concepts from Russell King's ARM IRQ
layer, the merging of which was one of the motivations for this patchset.
This patch:
rename desc->handler to desc->chip.
Originally i did not want to do this, because it's a big patch. But having
both "desc->handler", "desc->handle_irq" and "action->handler" caused a
large degree of confusion and made the code appear alot less clean than it
truly is.
I have also attempted a dual approach as well by introducing a
desc->chip alias - but that just wasnt robust enough and broke
frequently.
So lets get over with this quickly. The conversion was done automatically
via scripts and converts all the code in the kernel.
This renaming patch is the first one amongst the patches, so that the
remaining patches can stay flexible and can be merged and split up
without having some big monolithic patch act as a merge barrier.
[akpm@osdl.org: build fix]
[akpm@osdl.org: another build fix]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-29 17:24:36 +08:00
|
|
|
get_irq_desc(irq)->chip = &iic_pic;
|
2005-06-23 07:43:43 +08:00
|
|
|
get_irq_desc(irq)->status |= IRQ_PER_CPU;
|
|
|
|
request_irq(irq, iic_ipi_action, SA_INTERRUPT, name, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void iic_request_IPIs(void)
|
|
|
|
{
|
2005-08-19 01:35:21 +08:00
|
|
|
iic_request_ipi(PPC_MSG_CALL_FUNCTION, "IPI-call");
|
|
|
|
iic_request_ipi(PPC_MSG_RESCHEDULE, "IPI-resched");
|
2005-06-23 07:43:43 +08:00
|
|
|
#ifdef CONFIG_DEBUGGER
|
2005-08-19 01:35:21 +08:00
|
|
|
iic_request_ipi(PPC_MSG_DEBUGGER_BREAK, "IPI-debug");
|
2005-06-23 07:43:43 +08:00
|
|
|
#endif /* CONFIG_DEBUGGER */
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SMP */
|
|
|
|
|
|
|
|
static void iic_setup_spe_handlers(void)
|
|
|
|
{
|
|
|
|
int be, isrc;
|
|
|
|
|
|
|
|
/* Assume two threads per BE are present */
|
|
|
|
for (be=0; be < num_present_cpus() / 2; be++) {
|
|
|
|
for (isrc = 0; isrc < IIC_CLASS_STRIDE * 3; isrc++) {
|
|
|
|
int irq = IIC_NODE_STRIDE * be + IIC_SPE_OFFSET + isrc;
|
[PATCH] genirq: rename desc->handler to desc->chip
This patch-queue improves the generic IRQ layer to be truly generic, by adding
various abstractions and features to it, without impacting existing
functionality.
While the queue can be best described as "fix and improve everything in the
generic IRQ layer that we could think of", and thus it consists of many
smaller features and lots of cleanups, the one feature that stands out most is
the new 'irq chip' abstraction.
The irq-chip abstraction is about describing and coding and IRQ controller
driver by mapping its raw hardware capabilities [and quirks, if needed] in a
straightforward way, without having to think about "IRQ flow"
(level/edge/etc.) type of details.
This stands in contrast with the current 'irq-type' model of genirq
architectures, which 'mixes' raw hardware capabilities with 'flow' details.
The patchset supports both types of irq controller designs at once, and
converts i386 and x86_64 to the new irq-chip design.
As a bonus side-effect of the irq-chip approach, chained interrupt controllers
(master/slave PIC constructs, etc.) are now supported by design as well.
The end result of this patchset intends to be simpler architecture-level code
and more consolidation between architectures.
We reused many bits of code and many concepts from Russell King's ARM IRQ
layer, the merging of which was one of the motivations for this patchset.
This patch:
rename desc->handler to desc->chip.
Originally i did not want to do this, because it's a big patch. But having
both "desc->handler", "desc->handle_irq" and "action->handler" caused a
large degree of confusion and made the code appear alot less clean than it
truly is.
I have also attempted a dual approach as well by introducing a
desc->chip alias - but that just wasnt robust enough and broke
frequently.
So lets get over with this quickly. The conversion was done automatically
via scripts and converts all the code in the kernel.
This renaming patch is the first one amongst the patches, so that the
remaining patches can stay flexible and can be merged and split up
without having some big monolithic patch act as a merge barrier.
[akpm@osdl.org: build fix]
[akpm@osdl.org: another build fix]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-06-29 17:24:36 +08:00
|
|
|
get_irq_desc(irq)->chip = &iic_pic;
|
2005-06-23 07:43:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void iic_init_IRQ(void)
|
|
|
|
{
|
|
|
|
int cpu, irq_offset;
|
|
|
|
struct iic *iic;
|
|
|
|
|
2006-03-23 07:00:06 +08:00
|
|
|
if (setup_iic() < 0)
|
|
|
|
setup_iic_hardcoded();
|
|
|
|
|
2005-06-23 07:43:43 +08:00
|
|
|
irq_offset = 0;
|
2006-03-29 06:50:51 +08:00
|
|
|
for_each_possible_cpu(cpu) {
|
2005-06-23 07:43:43 +08:00
|
|
|
iic = &per_cpu(iic, cpu);
|
|
|
|
if (iic->regs)
|
|
|
|
out_be64(&iic->regs->prio, 0xff);
|
|
|
|
}
|
|
|
|
iic_setup_spe_handlers();
|
|
|
|
}
|