Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 1 | /* |
Arnd Bergmann | f3f66f5 | 2005-10-31 20:08:37 -0500 | [diff] [blame] | 2 | * Cell Internal Interrupt Controller |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 3 | * |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 4 | * Copyright (C) 2006 Benjamin Herrenschmidt (benh@kernel.crashing.org) |
| 5 | * IBM, Corp. |
| 6 | * |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 7 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 8 | * |
| 9 | * Author: Arnd Bergmann <arndb@de.ibm.com> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 24 | * |
| 25 | * TODO: |
| 26 | * - Fix various assumptions related to HW CPU numbers vs. linux CPU numbers |
| 27 | * vs node numbers in the setup code |
| 28 | * - Implement proper handling of maxcpus=1/2 (that is, routing of irqs from |
| 29 | * a non-active node to the active node) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 30 | */ |
| 31 | |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 32 | #include <linux/interrupt.h> |
| 33 | #include <linux/irq.h> |
Arnd Bergmann | 2fb9d20 | 2006-01-05 14:05:29 +0000 | [diff] [blame] | 34 | #include <linux/module.h> |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 35 | #include <linux/percpu.h> |
| 36 | #include <linux/types.h> |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 37 | #include <linux/ioport.h> |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 38 | #include <linux/kernel_stat.h> |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 39 | |
| 40 | #include <asm/io.h> |
| 41 | #include <asm/pgtable.h> |
| 42 | #include <asm/prom.h> |
| 43 | #include <asm/ptrace.h> |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 44 | #include <asm/machdep.h> |
Benjamin Herrenschmidt | eef686a0 | 2007-10-04 15:40:42 +1000 | [diff] [blame] | 45 | #include <asm/cell-regs.h> |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 46 | |
Arnd Bergmann | f3f66f5 | 2005-10-31 20:08:37 -0500 | [diff] [blame] | 47 | #include "interrupt.h" |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 48 | |
| 49 | struct iic { |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 50 | struct cbe_iic_thread_regs __iomem *regs; |
Arnd Bergmann | 2fb9d20 | 2006-01-05 14:05:29 +0000 | [diff] [blame] | 51 | u8 target_id; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 52 | u8 eoi_stack[16]; |
| 53 | int eoi_ptr; |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 54 | struct device_node *node; |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 55 | }; |
| 56 | |
Tejun Heo | 6b7487f | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 57 | static DEFINE_PER_CPU(struct iic, cpu_iic); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 58 | #define IIC_NODE_COUNT 2 |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 59 | static struct irq_host *iic_host; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 60 | |
| 61 | /* Convert between "pending" bits and hw irq number */ |
| 62 | static irq_hw_number_t iic_pending_to_hwnum(struct cbe_iic_pending_bits bits) |
| 63 | { |
| 64 | unsigned char unit = bits.source & 0xf; |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 65 | unsigned char node = bits.source >> 4; |
| 66 | unsigned char class = bits.class & 3; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 67 | |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 68 | /* Decode IPIs */ |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 69 | if (bits.flags & CBE_IIC_IRQ_IPI) |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 70 | return IIC_IRQ_TYPE_IPI | (bits.prio >> 4); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 71 | else |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 72 | return (node << IIC_IRQ_NODE_SHIFT) | (class << 4) | unit; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 73 | } |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 74 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 75 | static void iic_mask(struct irq_data *d) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 76 | { |
| 77 | } |
| 78 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 79 | static void iic_unmask(struct irq_data *d) |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 80 | { |
| 81 | } |
| 82 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 83 | static void iic_eoi(struct irq_data *d) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 84 | { |
Tejun Heo | 6b7487f | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 85 | struct iic *iic = &__get_cpu_var(cpu_iic); |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 86 | out_be64(&iic->regs->prio, iic->eoi_stack[--iic->eoi_ptr]); |
| 87 | BUG_ON(iic->eoi_ptr < 0); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 88 | } |
| 89 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 90 | static struct irq_chip iic_chip = { |
Anton Blanchard | fc380c0 | 2010-01-31 20:33:41 +0000 | [diff] [blame] | 91 | .name = "CELL-IIC", |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 92 | .irq_mask = iic_mask, |
| 93 | .irq_unmask = iic_unmask, |
| 94 | .irq_eoi = iic_eoi, |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 95 | }; |
| 96 | |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 97 | |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 98 | static void iic_ioexc_eoi(struct irq_data *d) |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 99 | { |
| 100 | } |
| 101 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 102 | static void iic_ioexc_cascade(unsigned int irq, struct irq_desc *desc) |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 103 | { |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 104 | struct irq_chip *chip = get_irq_desc_chip(desc); |
| 105 | struct cbe_iic_regs __iomem *node_iic = |
| 106 | (void __iomem *)get_irq_desc_data(desc); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 107 | unsigned int base = (irq & 0xffffff00) | IIC_IRQ_TYPE_IOEXC; |
| 108 | unsigned long bits, ack; |
| 109 | int cascade; |
| 110 | |
| 111 | for (;;) { |
| 112 | bits = in_be64(&node_iic->iic_is); |
| 113 | if (bits == 0) |
| 114 | break; |
| 115 | /* pre-ack edge interrupts */ |
| 116 | ack = bits & IIC_ISR_EDGE_MASK; |
| 117 | if (ack) |
| 118 | out_be64(&node_iic->iic_is, ack); |
| 119 | /* handle them */ |
| 120 | for (cascade = 63; cascade >= 0; cascade--) |
| 121 | if (bits & (0x8000000000000000UL >> cascade)) { |
| 122 | unsigned int cirq = |
| 123 | irq_linear_revmap(iic_host, |
| 124 | base | cascade); |
| 125 | if (cirq != NO_IRQ) |
Olof Johansson | 49f19ce | 2006-10-05 20:31:10 -0500 | [diff] [blame] | 126 | generic_handle_irq(cirq); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 127 | } |
| 128 | /* post-ack level interrupts */ |
| 129 | ack = bits & ~IIC_ISR_EDGE_MASK; |
| 130 | if (ack) |
| 131 | out_be64(&node_iic->iic_is, ack); |
| 132 | } |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 133 | chip->irq_eoi(&desc->irq_data); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | |
| 137 | static struct irq_chip iic_ioexc_chip = { |
Anton Blanchard | fc380c0 | 2010-01-31 20:33:41 +0000 | [diff] [blame] | 138 | .name = "CELL-IOEX", |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 139 | .irq_mask = iic_mask, |
| 140 | .irq_unmask = iic_unmask, |
| 141 | .irq_eoi = iic_ioexc_eoi, |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 142 | }; |
| 143 | |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 144 | /* Get an IRQ number from the pending state register of the IIC */ |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 145 | static unsigned int iic_get_irq(void) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 146 | { |
Geoff Levand | 9e6ee34 | 2006-08-09 15:28:13 -0700 | [diff] [blame] | 147 | struct cbe_iic_pending_bits pending; |
| 148 | struct iic *iic; |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 149 | unsigned int virq; |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 150 | |
Tejun Heo | 6b7487f | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 151 | iic = &__get_cpu_var(cpu_iic); |
Geoff Levand | 9e6ee34 | 2006-08-09 15:28:13 -0700 | [diff] [blame] | 152 | *(unsigned long *) &pending = |
Ingo Molnar | b36ac9e | 2009-01-06 14:03:44 +0000 | [diff] [blame] | 153 | in_be64((u64 __iomem *) &iic->regs->pending_destr); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 154 | if (!(pending.flags & CBE_IIC_IRQ_VALID)) |
| 155 | return NO_IRQ; |
| 156 | virq = irq_linear_revmap(iic_host, iic_pending_to_hwnum(pending)); |
| 157 | if (virq == NO_IRQ) |
| 158 | return NO_IRQ; |
Geoff Levand | 9e6ee34 | 2006-08-09 15:28:13 -0700 | [diff] [blame] | 159 | iic->eoi_stack[++iic->eoi_ptr] = pending.prio; |
| 160 | BUG_ON(iic->eoi_ptr > 15); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 161 | return virq; |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Olof Johansson | 4bfac36 | 2007-10-28 04:28:51 +1100 | [diff] [blame] | 164 | void iic_setup_cpu(void) |
| 165 | { |
Tejun Heo | 6b7487f | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 166 | out_be64(&__get_cpu_var(cpu_iic).regs->prio, 0xff); |
Olof Johansson | 4bfac36 | 2007-10-28 04:28:51 +1100 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | u8 iic_get_target_id(int cpu) |
| 170 | { |
Tejun Heo | 6b7487f | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 171 | return per_cpu(cpu_iic, cpu).target_id; |
Olof Johansson | 4bfac36 | 2007-10-28 04:28:51 +1100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | EXPORT_SYMBOL_GPL(iic_get_target_id); |
| 175 | |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 176 | #ifdef CONFIG_SMP |
Arnd Bergmann | a84195f | 2005-08-18 19:35:21 +0200 | [diff] [blame] | 177 | |
| 178 | /* Use the highest interrupt priorities for IPI */ |
| 179 | static inline int iic_ipi_to_irq(int ipi) |
| 180 | { |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 181 | return IIC_IRQ_TYPE_IPI + 0xf - ipi; |
Arnd Bergmann | a84195f | 2005-08-18 19:35:21 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 184 | void iic_cause_IPI(int cpu, int mesg) |
| 185 | { |
Tejun Heo | 6b7487f | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 186 | out_be64(&per_cpu(cpu_iic, cpu).regs->generate, (0xf - mesg) << 4); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 187 | } |
| 188 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 189 | struct irq_host *iic_get_irq_host(int node) |
| 190 | { |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 191 | return iic_host; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 192 | } |
| 193 | EXPORT_SYMBOL_GPL(iic_get_irq_host); |
| 194 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 195 | static irqreturn_t iic_ipi_action(int irq, void *dev_id) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 196 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 197 | int ipi = (int)(long)dev_id; |
| 198 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 199 | smp_message_recv(ipi); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 200 | |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 201 | return IRQ_HANDLED; |
| 202 | } |
Arnd Bergmann | a84195f | 2005-08-18 19:35:21 +0200 | [diff] [blame] | 203 | static void iic_request_ipi(int ipi, const char *name) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 204 | { |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 205 | int virq; |
Arnd Bergmann | a84195f | 2005-08-18 19:35:21 +0200 | [diff] [blame] | 206 | |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 207 | virq = irq_create_mapping(iic_host, iic_ipi_to_irq(ipi)); |
| 208 | if (virq == NO_IRQ) { |
| 209 | printk(KERN_ERR |
| 210 | "iic: failed to map IPI %s\n", name); |
| 211 | return; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 212 | } |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 213 | if (request_irq(virq, iic_ipi_action, IRQF_DISABLED, name, |
| 214 | (void *)(long)ipi)) |
| 215 | printk(KERN_ERR |
| 216 | "iic: failed to request IPI %s\n", name); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void iic_request_IPIs(void) |
| 220 | { |
Arnd Bergmann | a84195f | 2005-08-18 19:35:21 +0200 | [diff] [blame] | 221 | iic_request_ipi(PPC_MSG_CALL_FUNCTION, "IPI-call"); |
| 222 | iic_request_ipi(PPC_MSG_RESCHEDULE, "IPI-resched"); |
Jens Axboe | b7d7a24 | 2008-06-26 11:22:13 +0200 | [diff] [blame] | 223 | iic_request_ipi(PPC_MSG_CALL_FUNC_SINGLE, "IPI-call-single"); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 224 | #ifdef CONFIG_DEBUGGER |
Arnd Bergmann | a84195f | 2005-08-18 19:35:21 +0200 | [diff] [blame] | 225 | iic_request_ipi(PPC_MSG_DEBUGGER_BREAK, "IPI-debug"); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 226 | #endif /* CONFIG_DEBUGGER */ |
| 227 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 228 | |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 229 | #endif /* CONFIG_SMP */ |
| 230 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 231 | |
| 232 | static int iic_host_match(struct irq_host *h, struct device_node *node) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 233 | { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 234 | return of_device_is_compatible(node, |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 235 | "IBM,CBEA-Internal-Interrupt-Controller"); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 236 | } |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 237 | |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 238 | extern int noirqdebug; |
| 239 | |
| 240 | static void handle_iic_irq(unsigned int irq, struct irq_desc *desc) |
| 241 | { |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 242 | struct irq_chip *chip = get_irq_desc_chip(desc); |
| 243 | |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 244 | raw_spin_lock(&desc->lock); |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 245 | |
| 246 | desc->status &= ~(IRQ_REPLAY | IRQ_WAITING); |
| 247 | |
| 248 | /* |
| 249 | * If we're currently running this IRQ, or its disabled, |
| 250 | * we shouldn't process the IRQ. Mark it pending, handle |
| 251 | * the necessary masking and go out |
| 252 | */ |
| 253 | if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) || |
| 254 | !desc->action)) { |
| 255 | desc->status |= IRQ_PENDING; |
| 256 | goto out_eoi; |
| 257 | } |
| 258 | |
Yinghai Lu | dee4102 | 2009-01-11 00:29:15 -0800 | [diff] [blame] | 259 | kstat_incr_irqs_this_cpu(irq, desc); |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 260 | |
| 261 | /* Mark the IRQ currently in progress.*/ |
| 262 | desc->status |= IRQ_INPROGRESS; |
| 263 | |
| 264 | do { |
| 265 | struct irqaction *action = desc->action; |
| 266 | irqreturn_t action_ret; |
| 267 | |
| 268 | if (unlikely(!action)) |
| 269 | goto out_eoi; |
| 270 | |
| 271 | desc->status &= ~IRQ_PENDING; |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 272 | raw_spin_unlock(&desc->lock); |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 273 | action_ret = handle_IRQ_event(irq, action); |
| 274 | if (!noirqdebug) |
| 275 | note_interrupt(irq, desc, action_ret); |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 276 | raw_spin_lock(&desc->lock); |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 277 | |
| 278 | } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING); |
| 279 | |
| 280 | desc->status &= ~IRQ_INPROGRESS; |
| 281 | out_eoi: |
Lennert Buytenhek | d1ae63d | 2011-03-07 13:59:28 +0000 | [diff] [blame^] | 282 | chip->irq_eoi(&desc->irq_data); |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 283 | raw_spin_unlock(&desc->lock); |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 284 | } |
| 285 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 286 | static int iic_host_map(struct irq_host *h, unsigned int virq, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 287 | irq_hw_number_t hw) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 288 | { |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 289 | switch (hw & IIC_IRQ_TYPE_MASK) { |
| 290 | case IIC_IRQ_TYPE_IPI: |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 291 | set_irq_chip_and_handler(virq, &iic_chip, handle_percpu_irq); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 292 | break; |
| 293 | case IIC_IRQ_TYPE_IOEXC: |
| 294 | set_irq_chip_and_handler(virq, &iic_ioexc_chip, |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 295 | handle_iic_irq); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 296 | break; |
| 297 | default: |
Jeremy Kerr | 5711fe9 | 2008-04-04 17:55:28 +1100 | [diff] [blame] | 298 | set_irq_chip_and_handler(virq, &iic_chip, handle_iic_irq); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 299 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 300 | return 0; |
| 301 | } |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 302 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 303 | static int iic_host_xlate(struct irq_host *h, struct device_node *ct, |
Roman Fietze | 40d50cf | 2009-12-08 02:39:50 +0000 | [diff] [blame] | 304 | const u32 *intspec, unsigned int intsize, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 305 | irq_hw_number_t *out_hwirq, unsigned int *out_flags) |
| 306 | |
| 307 | { |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 308 | unsigned int node, ext, unit, class; |
| 309 | const u32 *val; |
| 310 | |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 311 | if (!of_device_is_compatible(ct, |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 312 | "IBM,CBEA-Internal-Interrupt-Controller")) |
| 313 | return -ENODEV; |
| 314 | if (intsize != 1) |
| 315 | return -ENODEV; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 316 | val = of_get_property(ct, "#interrupt-cells", NULL); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 317 | if (val == NULL || *val != 1) |
| 318 | return -ENODEV; |
| 319 | |
| 320 | node = intspec[0] >> 24; |
| 321 | ext = (intspec[0] >> 16) & 0xff; |
| 322 | class = (intspec[0] >> 8) & 0xff; |
| 323 | unit = intspec[0] & 0xff; |
| 324 | |
| 325 | /* Check if node is in supported range */ |
| 326 | if (node > 1) |
| 327 | return -EINVAL; |
| 328 | |
| 329 | /* Build up interrupt number, special case for IO exceptions */ |
| 330 | *out_hwirq = (node << IIC_IRQ_NODE_SHIFT); |
| 331 | if (unit == IIC_UNIT_IIC && class == 1) |
| 332 | *out_hwirq |= IIC_IRQ_TYPE_IOEXC | ext; |
| 333 | else |
| 334 | *out_hwirq |= IIC_IRQ_TYPE_NORMAL | |
| 335 | (class << IIC_IRQ_CLASS_SHIFT) | unit; |
| 336 | |
| 337 | /* Dummy flags, ignored by iic code */ |
| 338 | *out_flags = IRQ_TYPE_EDGE_RISING; |
| 339 | |
| 340 | return 0; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static struct irq_host_ops iic_host_ops = { |
| 344 | .match = iic_host_match, |
| 345 | .map = iic_host_map, |
| 346 | .xlate = iic_host_xlate, |
| 347 | }; |
| 348 | |
| 349 | static void __init init_one_iic(unsigned int hw_cpu, unsigned long addr, |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 350 | struct device_node *node) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 351 | { |
| 352 | /* XXX FIXME: should locate the linux CPU number from the HW cpu |
| 353 | * number properly. We are lucky for now |
| 354 | */ |
Tejun Heo | 6b7487f | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 355 | struct iic *iic = &per_cpu(cpu_iic, hw_cpu); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 356 | |
| 357 | iic->regs = ioremap(addr, sizeof(struct cbe_iic_thread_regs)); |
| 358 | BUG_ON(iic->regs == NULL); |
| 359 | |
| 360 | iic->target_id = ((hw_cpu & 2) << 3) | ((hw_cpu & 1) ? 0xf : 0xe); |
| 361 | iic->eoi_stack[0] = 0xff; |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 362 | iic->node = of_node_get(node); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 363 | out_be64(&iic->regs->prio, 0); |
| 364 | |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 365 | printk(KERN_INFO "IIC for CPU %d target id 0x%x : %s\n", |
| 366 | hw_cpu, iic->target_id, node->full_name); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | static int __init setup_iic(void) |
| 370 | { |
| 371 | struct device_node *dn; |
| 372 | struct resource r0, r1; |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 373 | unsigned int node, cascade, found = 0; |
Arnd Bergmann | 43b4f40 | 2006-10-04 17:26:24 +0200 | [diff] [blame] | 374 | struct cbe_iic_regs __iomem *node_iic; |
Geoff Levand | 9e6ee34 | 2006-08-09 15:28:13 -0700 | [diff] [blame] | 375 | const u32 *np; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 376 | |
| 377 | for (dn = NULL; |
| 378 | (dn = of_find_node_by_name(dn,"interrupt-controller")) != NULL;) { |
Stephen Rothwell | 55b61fe | 2007-05-03 17:26:52 +1000 | [diff] [blame] | 379 | if (!of_device_is_compatible(dn, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 380 | "IBM,CBEA-Internal-Interrupt-Controller")) |
| 381 | continue; |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 382 | np = of_get_property(dn, "ibm,interrupt-server-ranges", NULL); |
Geoff Levand | 9e6ee34 | 2006-08-09 15:28:13 -0700 | [diff] [blame] | 383 | if (np == NULL) { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 384 | printk(KERN_WARNING "IIC: CPU association not found\n"); |
| 385 | of_node_put(dn); |
| 386 | return -ENODEV; |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 387 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 388 | if (of_address_to_resource(dn, 0, &r0) || |
| 389 | of_address_to_resource(dn, 1, &r1)) { |
| 390 | printk(KERN_WARNING "IIC: Can't resolve addresses\n"); |
| 391 | of_node_put(dn); |
| 392 | return -ENODEV; |
| 393 | } |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 394 | found++; |
| 395 | init_one_iic(np[0], r0.start, dn); |
| 396 | init_one_iic(np[1], r1.start, dn); |
| 397 | |
| 398 | /* Setup cascade for IO exceptions. XXX cleanup tricks to get |
| 399 | * node vs CPU etc... |
| 400 | * Note that we configure the IIC_IRR here with a hard coded |
| 401 | * priority of 1. We might want to improve that later. |
| 402 | */ |
| 403 | node = np[0] >> 1; |
| 404 | node_iic = cbe_get_cpu_iic_regs(np[0]); |
| 405 | cascade = node << IIC_IRQ_NODE_SHIFT; |
| 406 | cascade |= 1 << IIC_IRQ_CLASS_SHIFT; |
| 407 | cascade |= IIC_UNIT_IIC; |
| 408 | cascade = irq_create_mapping(iic_host, cascade); |
| 409 | if (cascade == NO_IRQ) |
| 410 | continue; |
Arnd Bergmann | 43b4f40 | 2006-10-04 17:26:24 +0200 | [diff] [blame] | 411 | /* |
| 412 | * irq_data is a generic pointer that gets passed back |
| 413 | * to us later, so the forced cast is fine. |
| 414 | */ |
| 415 | set_irq_data(cascade, (void __force *)node_iic); |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 416 | set_irq_chained_handler(cascade , iic_ioexc_cascade); |
| 417 | out_be64(&node_iic->iic_ir, |
| 418 | (1 << 12) /* priority */ | |
| 419 | (node << 4) /* dest node */ | |
| 420 | IIC_UNIT_THREAD_0 /* route them to thread 0 */); |
| 421 | /* Flush pending (make sure it triggers if there is |
| 422 | * anything pending |
| 423 | */ |
| 424 | out_be64(&node_iic->iic_is, 0xfffffffffffffffful); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 425 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 426 | |
| 427 | if (found) |
| 428 | return 0; |
| 429 | else |
| 430 | return -ENODEV; |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 431 | } |
| 432 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 433 | void __init iic_init_IRQ(void) |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 434 | { |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 435 | /* Setup an irq host data structure */ |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 436 | iic_host = irq_alloc_host(NULL, IRQ_HOST_MAP_LINEAR, IIC_SOURCE_COUNT, |
Benjamin Herrenschmidt | 2e19458 | 2006-09-29 15:00:29 +1000 | [diff] [blame] | 437 | &iic_host_ops, IIC_IRQ_INVALID); |
| 438 | BUG_ON(iic_host == NULL); |
| 439 | irq_set_default_host(iic_host); |
| 440 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 441 | /* Discover and initialize iics */ |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 442 | if (setup_iic() < 0) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 443 | panic("IIC: Failed to initialize !\n"); |
Jens Osterkamp | d0e57c6 | 2006-03-23 00:00:06 +0100 | [diff] [blame] | 444 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 445 | /* Set master interrupt handling function */ |
| 446 | ppc_md.get_irq = iic_get_irq; |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 447 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 448 | /* Enable on current CPU */ |
| 449 | iic_setup_cpu(); |
Arnd Bergmann | cebf589 | 2005-06-23 09:43:43 +1000 | [diff] [blame] | 450 | } |
Kevin Corry | 0443bbd | 2006-11-20 18:45:15 +0100 | [diff] [blame] | 451 | |
| 452 | void iic_set_interrupt_routing(int cpu, int thread, int priority) |
| 453 | { |
| 454 | struct cbe_iic_regs __iomem *iic_regs = cbe_get_cpu_iic_regs(cpu); |
| 455 | u64 iic_ir = 0; |
| 456 | int node = cpu >> 1; |
| 457 | |
| 458 | /* Set which node and thread will handle the next interrupt */ |
| 459 | iic_ir |= CBE_IIC_IR_PRIO(priority) | |
| 460 | CBE_IIC_IR_DEST_NODE(node); |
| 461 | if (thread == 0) |
| 462 | iic_ir |= CBE_IIC_IR_DEST_UNIT(CBE_IIC_IR_PT_0); |
| 463 | else |
| 464 | iic_ir |= CBE_IIC_IR_DEST_UNIT(CBE_IIC_IR_PT_1); |
| 465 | out_be64(&iic_regs->iic_ir, iic_ir); |
| 466 | } |