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