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 | */ |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 26 | #include <linux/config.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/pci.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/threads.h> |
| 30 | #include <linux/smp.h> |
| 31 | #include <linux/param.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/bootmem.h> |
| 34 | #include <linux/ide.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <linux/irq.h> |
| 36 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 38 | #include <asm/paca.h> |
Kelly Daly | 1ec65d7 | 2005-11-02 13:46:07 +1100 | [diff] [blame] | 39 | #include <asm/iseries/hv_types.h> |
Kelly Daly | e45423e | 2005-11-02 12:08:31 +1100 | [diff] [blame] | 40 | #include <asm/iseries/hv_lp_event.h> |
Kelly Daly | 8021b8a | 2005-11-02 11:41:12 +1100 | [diff] [blame] | 41 | #include <asm/iseries/hv_call_xm.h> |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 42 | #include <asm/iseries/it_lp_queue.h> |
Stephen Rothwell | b08567cb | 2005-09-28 23:37:01 +1000 | [diff] [blame] | 43 | |
| 44 | #include "irq.h" |
Stephen Rothwell | 0d177df | 2006-05-19 16:46:28 +1000 | [diff] [blame] | 45 | #include "pci.h" |
Stephen Rothwell | c6d2ea9 | 2005-10-14 17:16:17 +1000 | [diff] [blame] | 46 | #include "call_pci.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 48 | #if defined(CONFIG_SMP) |
| 49 | extern void iSeries_smp_message_recv(struct pt_regs *); |
| 50 | #endif |
| 51 | |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 52 | #ifdef CONFIG_PCI |
| 53 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 54 | enum pci_event_type { |
| 55 | pe_bus_created = 0, /* PHB has been created */ |
| 56 | pe_bus_error = 1, /* PHB has failed */ |
| 57 | pe_bus_failed = 2, /* Msg to Secondary, Primary failed bus */ |
| 58 | pe_node_failed = 4, /* Multi-adapter bridge has failed */ |
| 59 | pe_node_recovered = 5, /* Multi-adapter bridge has recovered */ |
| 60 | pe_bus_recovered = 12, /* PHB has been recovered */ |
| 61 | pe_unquiese_bus = 18, /* Secondary bus unqiescing */ |
| 62 | pe_bridge_error = 21, /* Bridge Error */ |
| 63 | pe_slot_interrupt = 22 /* Slot interrupt */ |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 66 | struct pci_event { |
| 67 | struct HvLpEvent event; |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 68 | union { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 69 | u64 __align; /* Align on an 8-byte boundary */ |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 70 | struct { |
| 71 | u32 fisr; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 72 | HvBusNumber bus_number; |
| 73 | HvSubBusNumber sub_bus_number; |
| 74 | HvAgentId dev_id; |
| 75 | } slot; |
| 76 | struct { |
| 77 | HvBusNumber bus_number; |
| 78 | HvSubBusNumber sub_bus_number; |
| 79 | } bus; |
| 80 | struct { |
| 81 | HvBusNumber bus_number; |
| 82 | HvSubBusNumber sub_bus_number; |
| 83 | HvAgentId dev_id; |
| 84 | } node; |
| 85 | } data; |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 88 | static DEFINE_SPINLOCK(pending_irqs_lock); |
| 89 | static int num_pending_irqs; |
| 90 | static int pending_irqs[NR_IRQS]; |
| 91 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 92 | static void int_received(struct pci_event *event, struct pt_regs *regs) |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 93 | { |
| 94 | int irq; |
| 95 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 96 | switch (event->event.xSubtype) { |
| 97 | case pe_slot_interrupt: |
| 98 | irq = event->event.xCorrelationToken; |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 99 | if (irq < NR_IRQS) { |
| 100 | spin_lock(&pending_irqs_lock); |
| 101 | pending_irqs[irq]++; |
| 102 | num_pending_irqs++; |
| 103 | spin_unlock(&pending_irqs_lock); |
| 104 | } else { |
| 105 | printk(KERN_WARNING "int_received: bad irq number %d\n", |
| 106 | irq); |
| 107 | HvCallPci_eoi(event->data.slot.bus_number, |
| 108 | event->data.slot.sub_bus_number, |
| 109 | event->data.slot.dev_id); |
| 110 | } |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 111 | break; |
| 112 | /* Ignore error recovery events for now */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 113 | case pe_bus_created: |
| 114 | printk(KERN_INFO "int_received: system bus %d created\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_error: |
| 118 | case pe_bus_failed: |
| 119 | printk(KERN_INFO "int_received: system bus %d failed\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_bus_recovered: |
| 123 | case pe_unquiese_bus: |
| 124 | printk(KERN_INFO "int_received: system bus %d recovered\n", |
| 125 | event->data.bus.bus_number); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 126 | break; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 127 | case pe_node_failed: |
| 128 | case pe_bridge_error: |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 129 | printk(KERN_INFO |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 130 | "int_received: multi-adapter bridge %d/%d/%d failed\n", |
| 131 | event->data.node.bus_number, |
| 132 | event->data.node.sub_bus_number, |
| 133 | event->data.node.dev_id); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 134 | break; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 135 | case pe_node_recovered: |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 136 | printk(KERN_INFO |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 137 | "int_received: multi-adapter bridge %d/%d/%d recovered\n", |
| 138 | event->data.node.bus_number, |
| 139 | event->data.node.sub_bus_number, |
| 140 | event->data.node.dev_id); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 141 | break; |
| 142 | default: |
| 143 | printk(KERN_ERR |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 144 | "int_received: unrecognized event subtype 0x%x\n", |
| 145 | event->event.xSubtype); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 146 | break; |
| 147 | } |
| 148 | } |
| 149 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 150 | static void pci_event_handler(struct HvLpEvent *event, struct pt_regs *regs) |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 151 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 152 | if (event && (event->xType == HvLpEvent_Type_PciIo)) { |
Stephen Rothwell | 677f8c0 | 2006-01-12 13:47:43 +1100 | [diff] [blame] | 153 | if (hvlpevent_is_int(event)) |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 154 | int_received((struct pci_event *)event, regs); |
Stephen Rothwell | 677f8c0 | 2006-01-12 13:47:43 +1100 | [diff] [blame] | 155 | else |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 156 | printk(KERN_ERR |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 157 | "pci_event_handler: unexpected ack received\n"); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 158 | } else if (event) |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 159 | printk(KERN_ERR |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 160 | "pci_event_handler: Unrecognized PCI event type 0x%x\n", |
| 161 | (int)event->xType); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 162 | else |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 163 | printk(KERN_ERR "pci_event_handler: NULL event received\n"); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Stephen Rothwell | 7f74e79 | 2005-06-21 17:15:51 -0700 | [diff] [blame] | 166 | /* |
| 167 | * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c |
| 168 | * It must be called before the bus walk. |
| 169 | */ |
| 170 | void __init iSeries_init_IRQ(void) |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 171 | { |
Stephen Rothwell | 7f74e79 | 2005-06-21 17:15:51 -0700 | [diff] [blame] | 172 | /* Register PCI event handler and open an event path */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 173 | int ret; |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 174 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 175 | ret = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo, |
| 176 | &pci_event_handler); |
| 177 | if (ret == 0) { |
| 178 | ret = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0); |
| 179 | if (ret != 0) |
| 180 | printk(KERN_ERR "iseries_init_IRQ: open event path " |
| 181 | "failed with rc 0x%x\n", ret); |
Stephen Rothwell | 89ef68f | 2005-06-21 17:15:50 -0700 | [diff] [blame] | 182 | } else |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 183 | printk(KERN_ERR "iseries_init_IRQ: register handler " |
| 184 | "failed with rc 0x%x\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 187 | #define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1) |
| 189 | #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1) |
| 190 | #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7) |
| 191 | |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 192 | /* |
| 193 | * This will be called by device drivers (via enable_IRQ) |
| 194 | * to enable INTA in the bridge interrupt status register. |
| 195 | */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 196 | static void iseries_enable_IRQ(unsigned int irq) |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 197 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 198 | u32 bus, dev_id, function, mask; |
| 199 | const u32 sub_bus = 0; |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 200 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 201 | |
| 202 | /* The IRQ has already been locked by the caller */ |
| 203 | bus = REAL_IRQ_TO_BUS(rirq); |
| 204 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 205 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 206 | |
| 207 | /* Unmask secondary INTA */ |
| 208 | mask = 0x80000000; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 209 | HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask); |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 212 | /* This is called by iseries_activate_IRQs */ |
| 213 | static unsigned int iseries_startup_IRQ(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 215 | u32 bus, dev_id, function, mask; |
| 216 | const u32 sub_bus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 218 | |
| 219 | bus = REAL_IRQ_TO_BUS(rirq); |
| 220 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 221 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | |
| 223 | /* Link the IRQ number to the bridge */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 224 | HvCallXm_connectBusUnit(bus, sub_bus, dev_id, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* Unmask bridge interrupts in the FISR */ |
| 227 | mask = 0x01010000 << function; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 228 | HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask); |
| 229 | iseries_enable_IRQ(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * This is called out of iSeries_fixup to activate interrupt |
| 235 | * generation for usable slots |
| 236 | */ |
| 237 | void __init iSeries_activate_IRQs() |
| 238 | { |
| 239 | int irq; |
| 240 | unsigned long flags; |
| 241 | |
| 242 | for_each_irq (irq) { |
| 243 | irq_desc_t *desc = get_irq_desc(irq); |
| 244 | |
| 245 | if (desc && desc->handler && desc->handler->startup) { |
| 246 | spin_lock_irqsave(&desc->lock, flags); |
| 247 | desc->handler->startup(irq); |
| 248 | spin_unlock_irqrestore(&desc->lock, flags); |
| 249 | } |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 250 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* this is not called anywhere currently */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 254 | static void iseries_shutdown_IRQ(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 256 | u32 bus, dev_id, function, mask; |
| 257 | const u32 sub_bus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 259 | |
| 260 | /* irq should be locked by the caller */ |
| 261 | bus = REAL_IRQ_TO_BUS(rirq); |
| 262 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 263 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
| 265 | /* Invalidate the IRQ number in the bridge */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 266 | HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | /* Mask bridge interrupts in the FISR */ |
| 269 | mask = 0x01010000 << function; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 270 | HvCallPci_maskFisr(bus, sub_bus, dev_id, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /* |
| 274 | * This will be called by device drivers (via disable_IRQ) |
| 275 | * to disable INTA in the bridge interrupt status register. |
| 276 | */ |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 277 | static void iseries_disable_IRQ(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 279 | u32 bus, dev_id, function, mask; |
| 280 | const u32 sub_bus = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 282 | |
| 283 | /* The IRQ has already been locked by the caller */ |
| 284 | bus = REAL_IRQ_TO_BUS(rirq); |
| 285 | function = REAL_IRQ_TO_FUNC(rirq); |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 286 | dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | /* Mask secondary INTA */ |
| 289 | mask = 0x80000000; |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 290 | HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 293 | static void iseries_end_IRQ(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 295 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 296 | |
| 297 | HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq), REAL_IRQ_TO_SUBBUS(rirq), |
| 298 | (REAL_IRQ_TO_IDSEL(rirq) << 4) + REAL_IRQ_TO_FUNC(rirq)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 300 | |
| 301 | static hw_irq_controller iSeries_IRQ_handler = { |
| 302 | .typename = "iSeries irq controller", |
Stephen Rothwell | 60798c6a | 2005-11-16 17:47:43 +1100 | [diff] [blame] | 303 | .startup = iseries_startup_IRQ, |
| 304 | .shutdown = iseries_shutdown_IRQ, |
| 305 | .enable = iseries_enable_IRQ, |
| 306 | .disable = iseries_disable_IRQ, |
| 307 | .end = iseries_end_IRQ |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 308 | }; |
| 309 | |
| 310 | /* |
| 311 | * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot |
| 312 | * It calculates the irq value for the slot. |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 313 | * Note that sub_bus is always 0 (at the moment at least). |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 314 | */ |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 315 | int __init iSeries_allocate_IRQ(HvBusNumber bus, |
Stephen Rothwell | 0d177df | 2006-05-19 16:46:28 +1000 | [diff] [blame] | 316 | HvSubBusNumber sub_bus, u32 bsubbus) |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 317 | { |
Stephen Rothwell | d9ae2ba | 2005-11-10 18:11:19 +1100 | [diff] [blame] | 318 | int virtirq; |
| 319 | unsigned int realirq; |
Stephen Rothwell | 0d177df | 2006-05-19 16:46:28 +1000 | [diff] [blame] | 320 | u8 idsel = ISERIES_GET_DEVICE_FROM_SUBBUS(bsubbus); |
| 321 | u8 function = ISERIES_GET_FUNCTION_FROM_SUBBUS(bsubbus); |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 322 | |
Stephen Rothwell | 853f828 | 2005-11-16 18:10:40 +1100 | [diff] [blame] | 323 | realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3) |
| 324 | + function; |
Stephen Rothwell | d9ae2ba | 2005-11-10 18:11:19 +1100 | [diff] [blame] | 325 | virtirq = virt_irq_create_mapping(realirq); |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame] | 326 | |
| 327 | irq_desc[virtirq].handler = &iSeries_IRQ_handler; |
| 328 | return virtirq; |
| 329 | } |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 330 | |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 331 | #endif /* CONFIG_PCI */ |
| 332 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 333 | /* |
| 334 | * Get the next pending IRQ. |
| 335 | */ |
| 336 | int iSeries_get_irq(struct pt_regs *regs) |
| 337 | { |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 338 | /* -2 means ignore this interrupt */ |
| 339 | int irq = -2; |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 340 | |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 341 | #ifdef CONFIG_SMP |
David Gibson | 3356bb9f7 | 2006-01-13 10:26:42 +1100 | [diff] [blame] | 342 | if (get_lppaca()->int_dword.fields.ipi_cnt) { |
| 343 | get_lppaca()->int_dword.fields.ipi_cnt = 0; |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 344 | iSeries_smp_message_recv(regs); |
| 345 | } |
| 346 | #endif /* CONFIG_SMP */ |
| 347 | if (hvlpevent_is_pending()) |
| 348 | process_hvlpevents(regs); |
| 349 | |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 350 | #ifdef CONFIG_PCI |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 351 | if (num_pending_irqs) { |
| 352 | spin_lock(&pending_irqs_lock); |
| 353 | for (irq = 0; irq < NR_IRQS; irq++) { |
| 354 | if (pending_irqs[irq]) { |
| 355 | pending_irqs[irq]--; |
| 356 | num_pending_irqs--; |
| 357 | break; |
| 358 | } |
| 359 | } |
| 360 | spin_unlock(&pending_irqs_lock); |
| 361 | if (irq >= NR_IRQS) |
| 362 | irq = -2; |
| 363 | } |
Stephen Rothwell | ee2cdec | 2006-01-12 13:54:20 +1100 | [diff] [blame] | 364 | #endif |
Stephen Rothwell | 1d7a6b9 | 2005-11-17 18:04:37 +1100 | [diff] [blame] | 365 | |
| 366 | return irq; |
Stephen Rothwell | e199500 | 2005-11-16 18:53:29 +1100 | [diff] [blame] | 367 | } |