Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This module supports the iSeries PCI bus interrupt handling |
| 3 | * Copyright (C) 20yy <Robert L Holtorf> <IBM Corp> |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 4 | * Copyright (C) 2004-2005 IBM Corporation |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the: |
| 18 | * Free Software Foundation, Inc., |
| 19 | * 59 Temple Place, Suite 330, |
| 20 | * Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * Change Activity: |
| 23 | * Created, December 13, 2000 by Wayne Holm |
| 24 | * End Change Activity |
| 25 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/pci.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/threads.h> |
| 29 | #include <linux/smp.h> |
| 30 | #include <linux/param.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/irq.h> |
| 34 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 36 | #include <asm/paca.h> |
Kelly Daly | 1ec65d7 | 2005-11-02 13:46:07 +1100 | [diff] [blame] | 37 | #include <asm/iseries/hv_types.h> |
Kelly Daly | e45423e | 2005-11-02 12:08:31 +1100 | [diff] [blame] | 38 | #include <asm/iseries/hv_lp_event.h> |
Kelly Daly | 8021b8a | 2005-11-02 11:41:12 +1100 | [diff] [blame] | 39 | #include <asm/iseries/hv_call_xm.h> |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 40 | #include <asm/iseries/it_lp_queue.h> |
Stephen Rothwell | b08567cb | 2005-09-28 23:37:01 +1000 | [diff] [blame] | 41 | |
| 42 | #include "irq.h" |
Stephen Rothwell | 0d177df | 2006-05-19 16:46:28 +1000 | [diff] [blame] | 43 | #include "pci.h" |
Stephen Rothwell | c6d2ea9 | 2005-10-14 17:16:17 +1000 | [diff] [blame] | 44 | #include "call_pci.h" |
Stephen Rothwell | 1224f37 | 2006-10-06 13:55:26 +1000 | [diff] [blame] | 45 | #include "smp.h" |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 46 | |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 47 | #ifdef CONFIG_PCI |
| 48 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 49 | enum pci_event_type { |
| 50 | pe_bus_created = 0, /* PHB has been created */ |
| 51 | pe_bus_error = 1, /* PHB has failed */ |
| 52 | pe_bus_failed = 2, /* Msg to Secondary, Primary failed bus */ |
| 53 | pe_node_failed = 4, /* Multi-adapter bridge has failed */ |
| 54 | pe_node_recovered = 5, /* Multi-adapter bridge has recovered */ |
| 55 | pe_bus_recovered = 12, /* PHB has been recovered */ |
| 56 | pe_unquiese_bus = 18, /* Secondary bus unqiescing */ |
| 57 | pe_bridge_error = 21, /* Bridge Error */ |
| 58 | pe_slot_interrupt = 22 /* Slot interrupt */ |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 61 | struct pci_event { |
| 62 | struct HvLpEvent event; |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 63 | union { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 64 | u64 __align; /* Align on an 8-byte boundary */ |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 65 | struct { |
| 66 | u32 fisr; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 67 | HvBusNumber bus_number; |
| 68 | HvSubBusNumber sub_bus_number; |
| 69 | HvAgentId dev_id; |
| 70 | } slot; |
| 71 | struct { |
| 72 | HvBusNumber bus_number; |
| 73 | HvSubBusNumber sub_bus_number; |
| 74 | } bus; |
| 75 | struct { |
| 76 | HvBusNumber bus_number; |
| 77 | HvSubBusNumber sub_bus_number; |
| 78 | HvAgentId dev_id; |
| 79 | } node; |
| 80 | } data; |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 81 | }; |
| 82 | |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 83 | static DEFINE_SPINLOCK(pending_irqs_lock); |
| 84 | static int num_pending_irqs; |
| 85 | static int pending_irqs[NR_IRQS]; |
| 86 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 87 | static void int_received(struct pci_event *event) |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 88 | { |
| 89 | int irq; |
| 90 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 91 | switch (event->event.xSubtype) { |
| 92 | case pe_slot_interrupt: |
| 93 | irq = event->event.xCorrelationToken; |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 94 | if (irq < NR_IRQS) { |
| 95 | spin_lock(&pending_irqs_lock); |
| 96 | pending_irqs[irq]++; |
| 97 | num_pending_irqs++; |
| 98 | spin_unlock(&pending_irqs_lock); |
| 99 | } else { |
| 100 | printk(KERN_WARNING "int_received: bad irq number %d\n", |
| 101 | irq); |
| 102 | HvCallPci_eoi(event->data.slot.bus_number, |
| 103 | event->data.slot.sub_bus_number, |
| 104 | event->data.slot.dev_id); |
| 105 | } |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 106 | break; |
| 107 | /* Ignore error recovery events for now */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 108 | case pe_bus_created: |
| 109 | printk(KERN_INFO "int_received: system bus %d created\n", |
| 110 | event->data.bus.bus_number); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 111 | break; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 112 | case pe_bus_error: |
| 113 | case pe_bus_failed: |
| 114 | printk(KERN_INFO "int_received: system bus %d failed\n", |
| 115 | event->data.bus.bus_number); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 116 | break; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 117 | case pe_bus_recovered: |
| 118 | case pe_unquiese_bus: |
| 119 | printk(KERN_INFO "int_received: system bus %d recovered\n", |
| 120 | event->data.bus.bus_number); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 121 | break; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 122 | case pe_node_failed: |
| 123 | case pe_bridge_error: |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 124 | printk(KERN_INFO |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 125 | "int_received: multi-adapter bridge %d/%d/%d failed\n", |
| 126 | event->data.node.bus_number, |
| 127 | event->data.node.sub_bus_number, |
| 128 | event->data.node.dev_id); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 129 | break; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 130 | case pe_node_recovered: |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 131 | printk(KERN_INFO |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 132 | "int_received: multi-adapter bridge %d/%d/%d recovered\n", |
| 133 | event->data.node.bus_number, |
| 134 | event->data.node.sub_bus_number, |
| 135 | event->data.node.dev_id); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 136 | break; |
| 137 | default: |
| 138 | printk(KERN_ERR |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 139 | "int_received: unrecognized event subtype 0x%x\n", |
| 140 | event->event.xSubtype); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 141 | break; |
| 142 | } |
| 143 | } |
| 144 | |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 145 | static void pci_event_handler(struct HvLpEvent *event) |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 146 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 147 | if (event && (event->xType == HvLpEvent_Type_PciIo)) { |
Stephen Rothwell | 677f8c0 | 2006-01-12 13:47:43 +1100 | [diff] [blame] | 148 | if (hvlpevent_is_int(event)) |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 149 | int_received((struct pci_event *)event); |
Stephen Rothwell | 677f8c0 | 2006-01-12 13:47:43 +1100 | [diff] [blame] | 150 | else |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 151 | printk(KERN_ERR |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 152 | "pci_event_handler: unexpected ack received\n"); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 153 | } else if (event) |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 154 | printk(KERN_ERR |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 155 | "pci_event_handler: Unrecognized PCI event type 0x%x\n", |
| 156 | (int)event->xType); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 157 | else |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 158 | printk(KERN_ERR "pci_event_handler: NULL event received\n"); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 161 | #define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1) |
| 163 | #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1) |
| 164 | #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7) |
| 165 | |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 166 | /* |
| 167 | * This will be called by device drivers (via enable_IRQ) |
| 168 | * to enable INTA in the bridge interrupt status register. |
| 169 | */ |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 170 | static void iseries_enable_IRQ(struct irq_data *d) |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 171 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 172 | u32 bus, dev_id, function, mask; |
| 173 | const u32 sub_bus = 0; |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 174 | unsigned int rirq = (unsigned int)irq_map[d->irq].hwirq; |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 175 | |
| 176 | /* The IRQ has already been locked by the caller */ |
| 177 | bus = REAL_IRQ_TO_BUS(rirq); |
| 178 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 179 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 180 | |
| 181 | /* Unmask secondary INTA */ |
| 182 | mask = 0x80000000; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 183 | HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask); |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 186 | /* This is called by iseries_activate_IRQs */ |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 187 | static unsigned int iseries_startup_IRQ(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 189 | u32 bus, dev_id, function, mask; |
| 190 | const u32 sub_bus = 0; |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 191 | unsigned int rirq = (unsigned int)irq_map[d->irq].hwirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | bus = REAL_IRQ_TO_BUS(rirq); |
| 194 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 195 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | /* Link the IRQ number to the bridge */ |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 198 | HvCallXm_connectBusUnit(bus, sub_bus, dev_id, d->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | /* Unmask bridge interrupts in the FISR */ |
| 201 | mask = 0x01010000 << function; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 202 | HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask); |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 203 | iseries_enable_IRQ(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * This is called out of iSeries_fixup to activate interrupt |
| 209 | * generation for usable slots |
| 210 | */ |
| 211 | void __init iSeries_activate_IRQs() |
| 212 | { |
| 213 | int irq; |
| 214 | unsigned long flags; |
| 215 | |
| 216 | for_each_irq (irq) { |
Michael Ellerman | 6cff46f | 2009-10-13 19:44:51 +0000 | [diff] [blame] | 217 | struct irq_desc *desc = irq_to_desc(irq); |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 218 | struct irq_chip *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 220 | if (!desc) |
| 221 | continue; |
| 222 | |
| 223 | chip = get_irq_desc_chip(desc); |
| 224 | if (chip && chip->irq_startup) { |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 225 | raw_spin_lock_irqsave(&desc->lock, flags); |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 226 | chip->irq_startup(&desc->irq_data); |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 227 | raw_spin_unlock_irqrestore(&desc->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 229 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /* this is not called anywhere currently */ |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 233 | static void iseries_shutdown_IRQ(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 235 | u32 bus, dev_id, function, mask; |
| 236 | const u32 sub_bus = 0; |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 237 | unsigned int rirq = (unsigned int)irq_map[d->irq].hwirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | /* irq should be locked by the caller */ |
| 240 | bus = REAL_IRQ_TO_BUS(rirq); |
| 241 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 242 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | /* Invalidate the IRQ number in the bridge */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 245 | HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | /* Mask bridge interrupts in the FISR */ |
| 248 | mask = 0x01010000 << function; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 249 | HvCallPci_maskFisr(bus, sub_bus, dev_id, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /* |
| 253 | * This will be called by device drivers (via disable_IRQ) |
| 254 | * to disable INTA in the bridge interrupt status register. |
| 255 | */ |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 256 | static void iseries_disable_IRQ(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 258 | u32 bus, dev_id, function, mask; |
| 259 | const u32 sub_bus = 0; |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 260 | unsigned int rirq = (unsigned int)irq_map[d->irq].hwirq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | /* The IRQ has already been locked by the caller */ |
| 263 | bus = REAL_IRQ_TO_BUS(rirq); |
| 264 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 265 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | /* Mask secondary INTA */ |
| 268 | mask = 0x80000000; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 269 | HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 272 | static void iseries_end_IRQ(struct irq_data *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | { |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 274 | unsigned int rirq = (unsigned int)irq_map[d->irq].hwirq; |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 275 | |
| 276 | HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq), REAL_IRQ_TO_SUBBUS(rirq), |
| 277 | (REAL_IRQ_TO_IDSEL(rirq) << 4) + REAL_IRQ_TO_FUNC(rirq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | } |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 279 | |
Benjamin Herrenschmidt | b9e5b4e | 2006-07-03 19:32:51 +1000 | [diff] [blame] | 280 | static struct irq_chip iseries_pic = { |
Anton Blanchard | fc380c0 | 2010-01-31 20:33:41 +0000 | [diff] [blame] | 281 | .name = "iSeries", |
Lennert Buytenhek | 8f312ec | 2011-03-07 13:59:36 +0000 | [diff] [blame] | 282 | .irq_startup = iseries_startup_IRQ, |
| 283 | .irq_shutdown = iseries_shutdown_IRQ, |
| 284 | .irq_unmask = iseries_enable_IRQ, |
| 285 | .irq_mask = iseries_disable_IRQ, |
| 286 | .irq_eoi = iseries_end_IRQ |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
| 289 | /* |
| 290 | * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot |
| 291 | * It calculates the irq value for the slot. |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 292 | * Note that sub_bus is always 0 (at the moment at least). |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 293 | */ |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 294 | int __init iSeries_allocate_IRQ(HvBusNumber bus, |
Stephen Rothwell | 0d177df | 2006-05-19 16:46:28 +1000 | [diff] [blame] | 295 | HvSubBusNumber sub_bus, u32 bsubbus) |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 296 | { |
Stephen Rothwell | d9ae2ba | 2005-11-10 18:11:19 +1100 | [diff] [blame] | 297 | unsigned int realirq; |
Stephen Rothwell | 0d177df | 2006-05-19 16:46:28 +1000 | [diff] [blame] | 298 | u8 idsel = ISERIES_GET_DEVICE_FROM_SUBBUS(bsubbus); |
| 299 | u8 function = ISERIES_GET_FUNCTION_FROM_SUBBUS(bsubbus); |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 300 | |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 301 | realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3) |
| 302 | + function; |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 303 | |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 304 | return irq_create_mapping(NULL, realirq); |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 305 | } |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 306 | |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 307 | #endif /* CONFIG_PCI */ |
| 308 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 309 | /* |
| 310 | * Get the next pending IRQ. |
| 311 | */ |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 312 | unsigned int iSeries_get_irq(void) |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 313 | { |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 314 | int irq = NO_IRQ_IGNORE; |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 315 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 316 | #ifdef CONFIG_SMP |
David Gibson | 3356bb9f7 | 2006-01-13 10:26:42 +1100 | [diff] [blame] | 317 | if (get_lppaca()->int_dword.fields.ipi_cnt) { |
| 318 | get_lppaca()->int_dword.fields.ipi_cnt = 0; |
Stephen Rothwell | 1224f37 | 2006-10-06 13:55:26 +1000 | [diff] [blame] | 319 | iSeries_smp_message_recv(); |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 320 | } |
| 321 | #endif /* CONFIG_SMP */ |
| 322 | if (hvlpevent_is_pending()) |
Olaf Hering | 35a84c2 | 2006-10-07 22:08:26 +1000 | [diff] [blame] | 323 | process_hvlpevents(); |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 324 | |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 325 | #ifdef CONFIG_PCI |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 326 | if (num_pending_irqs) { |
| 327 | spin_lock(&pending_irqs_lock); |
| 328 | for (irq = 0; irq < NR_IRQS; irq++) { |
| 329 | if (pending_irqs[irq]) { |
| 330 | pending_irqs[irq]--; |
| 331 | num_pending_irqs--; |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | spin_unlock(&pending_irqs_lock); |
| 336 | if (irq >= NR_IRQS) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 337 | irq = NO_IRQ_IGNORE; |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 338 | } |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 339 | #endif |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 340 | |
| 341 | return irq; |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 342 | } |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 343 | |
Stephen Rothwell | be9e95b | 2007-03-04 17:03:48 +1100 | [diff] [blame] | 344 | #ifdef CONFIG_PCI |
| 345 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 346 | static int iseries_irq_host_map(struct irq_host *h, unsigned int virq, |
Benjamin Herrenschmidt | 6e99e45 | 2006-07-10 04:44:42 -0700 | [diff] [blame] | 347 | irq_hw_number_t hw) |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 348 | { |
| 349 | set_irq_chip_and_handler(virq, &iseries_pic, handle_fasteoi_irq); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
Michael Ellerman | 8528ab8 | 2007-08-28 18:47:55 +1000 | [diff] [blame] | 354 | static int iseries_irq_host_match(struct irq_host *h, struct device_node *np) |
| 355 | { |
| 356 | /* Match all */ |
| 357 | return 1; |
| 358 | } |
| 359 | |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 360 | static struct irq_host_ops iseries_irq_host_ops = { |
| 361 | .map = iseries_irq_host_map, |
Michael Ellerman | 8528ab8 | 2007-08-28 18:47:55 +1000 | [diff] [blame] | 362 | .match = iseries_irq_host_match, |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | /* |
| 366 | * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c |
| 367 | * It must be called before the bus walk. |
| 368 | */ |
| 369 | void __init iSeries_init_IRQ(void) |
| 370 | { |
| 371 | /* Register PCI event handler and open an event path */ |
| 372 | struct irq_host *host; |
| 373 | int ret; |
| 374 | |
| 375 | /* |
| 376 | * The Hypervisor only allows us up to 256 interrupt |
| 377 | * sources (the irq number is passed in a u8). |
| 378 | */ |
| 379 | irq_set_virq_count(256); |
| 380 | |
| 381 | /* Create irq host. No need for a revmap since HV will give us |
| 382 | * back our virtual irq number |
| 383 | */ |
Michael Ellerman | 52964f8 | 2007-08-28 18:47:54 +1000 | [diff] [blame] | 384 | host = irq_alloc_host(NULL, IRQ_HOST_MAP_NOMAP, 0, |
| 385 | &iseries_irq_host_ops, 0); |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 386 | BUG_ON(host == NULL); |
| 387 | irq_set_default_host(host); |
| 388 | |
| 389 | ret = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo, |
| 390 | &pci_event_handler); |
| 391 | if (ret == 0) { |
| 392 | ret = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0); |
| 393 | if (ret != 0) |
| 394 | printk(KERN_ERR "iseries_init_IRQ: open event path " |
| 395 | "failed with rc 0x%x\n", ret); |
| 396 | } else |
| 397 | printk(KERN_ERR "iseries_init_IRQ: register handler " |
| 398 | "failed with rc 0x%x\n", ret); |
| 399 | } |
| 400 | |
Stephen Rothwell | be9e95b | 2007-03-04 17:03:48 +1100 | [diff] [blame] | 401 | #endif /* CONFIG_PCI */ |