blob: 83442ea77476a88e31985b5ae331eb71edabc076 [file] [log] [blame]
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -07001/*
2 * This module supports the iSeries PCI bus interrupt handling
3 * Copyright (C) 20yy <Robert L Holtorf> <IBM Corp>
Stephen Rothwell89ef68f2005-06-21 17:15:50 -07004 * Copyright (C) 2004-2005 IBM Corporation
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -07005 *
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 Rothwell89ef68f2005-06-21 17:15:50 -070026#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#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 Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/irq.h>
36#include <linux/spinlock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Stephen Rothwelle1995002005-11-16 18:53:29 +110038#include <asm/paca.h>
Kelly Daly1ec65d72005-11-02 13:46:07 +110039#include <asm/iseries/hv_types.h>
Kelly Dalye45423e2005-11-02 12:08:31 +110040#include <asm/iseries/hv_lp_event.h>
Kelly Daly8021b8a2005-11-02 11:41:12 +110041#include <asm/iseries/hv_call_xm.h>
Stephen Rothwelle1995002005-11-16 18:53:29 +110042#include <asm/iseries/it_lp_queue.h>
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100043
44#include "irq.h"
Stephen Rothwellc6d2ea92005-10-14 17:16:17 +100045#include "call_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Stephen Rothwelle1995002005-11-16 18:53:29 +110047#if defined(CONFIG_SMP)
48extern void iSeries_smp_message_recv(struct pt_regs *);
49#endif
50
Stephen Rothwellee2cdec2006-01-12 13:54:20 +110051#ifdef CONFIG_PCI
52
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110053enum pci_event_type {
54 pe_bus_created = 0, /* PHB has been created */
55 pe_bus_error = 1, /* PHB has failed */
56 pe_bus_failed = 2, /* Msg to Secondary, Primary failed bus */
57 pe_node_failed = 4, /* Multi-adapter bridge has failed */
58 pe_node_recovered = 5, /* Multi-adapter bridge has recovered */
59 pe_bus_recovered = 12, /* PHB has been recovered */
60 pe_unquiese_bus = 18, /* Secondary bus unqiescing */
61 pe_bridge_error = 21, /* Bridge Error */
62 pe_slot_interrupt = 22 /* Slot interrupt */
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070063};
64
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110065struct pci_event {
66 struct HvLpEvent event;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070067 union {
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110068 u64 __align; /* Align on an 8-byte boundary */
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070069 struct {
70 u32 fisr;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110071 HvBusNumber bus_number;
72 HvSubBusNumber sub_bus_number;
73 HvAgentId dev_id;
74 } slot;
75 struct {
76 HvBusNumber bus_number;
77 HvSubBusNumber sub_bus_number;
78 } bus;
79 struct {
80 HvBusNumber bus_number;
81 HvSubBusNumber sub_bus_number;
82 HvAgentId dev_id;
83 } node;
84 } data;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070085};
86
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +110087static DEFINE_SPINLOCK(pending_irqs_lock);
88static int num_pending_irqs;
89static int pending_irqs[NR_IRQS];
90
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110091static void int_received(struct pci_event *event, struct pt_regs *regs)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070092{
93 int irq;
94
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110095 switch (event->event.xSubtype) {
96 case pe_slot_interrupt:
97 irq = event->event.xCorrelationToken;
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +110098 if (irq < NR_IRQS) {
99 spin_lock(&pending_irqs_lock);
100 pending_irqs[irq]++;
101 num_pending_irqs++;
102 spin_unlock(&pending_irqs_lock);
103 } else {
104 printk(KERN_WARNING "int_received: bad irq number %d\n",
105 irq);
106 HvCallPci_eoi(event->data.slot.bus_number,
107 event->data.slot.sub_bus_number,
108 event->data.slot.dev_id);
109 }
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700110 break;
111 /* Ignore error recovery events for now */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100112 case pe_bus_created:
113 printk(KERN_INFO "int_received: system bus %d created\n",
114 event->data.bus.bus_number);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700115 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100116 case pe_bus_error:
117 case pe_bus_failed:
118 printk(KERN_INFO "int_received: system bus %d failed\n",
119 event->data.bus.bus_number);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700120 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100121 case pe_bus_recovered:
122 case pe_unquiese_bus:
123 printk(KERN_INFO "int_received: system bus %d recovered\n",
124 event->data.bus.bus_number);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700125 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100126 case pe_node_failed:
127 case pe_bridge_error:
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700128 printk(KERN_INFO
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100129 "int_received: multi-adapter bridge %d/%d/%d failed\n",
130 event->data.node.bus_number,
131 event->data.node.sub_bus_number,
132 event->data.node.dev_id);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700133 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100134 case pe_node_recovered:
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700135 printk(KERN_INFO
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100136 "int_received: multi-adapter bridge %d/%d/%d recovered\n",
137 event->data.node.bus_number,
138 event->data.node.sub_bus_number,
139 event->data.node.dev_id);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700140 break;
141 default:
142 printk(KERN_ERR
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100143 "int_received: unrecognized event subtype 0x%x\n",
144 event->event.xSubtype);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700145 break;
146 }
147}
148
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100149static void pci_event_handler(struct HvLpEvent *event, struct pt_regs *regs)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700150{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100151 if (event && (event->xType == HvLpEvent_Type_PciIo)) {
Stephen Rothwell677f8c02006-01-12 13:47:43 +1100152 if (hvlpevent_is_int(event))
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100153 int_received((struct pci_event *)event, regs);
Stephen Rothwell677f8c02006-01-12 13:47:43 +1100154 else
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700155 printk(KERN_ERR
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100156 "pci_event_handler: unexpected ack received\n");
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100157 } else if (event)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700158 printk(KERN_ERR
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100159 "pci_event_handler: Unrecognized PCI event type 0x%x\n",
160 (int)event->xType);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700161 else
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100162 printk(KERN_ERR "pci_event_handler: NULL event received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700163}
164
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700165/*
166 * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
167 * It must be called before the bus walk.
168 */
169void __init iSeries_init_IRQ(void)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700170{
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700171 /* Register PCI event handler and open an event path */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100172 int ret;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700173
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100174 ret = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
175 &pci_event_handler);
176 if (ret == 0) {
177 ret = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
178 if (ret != 0)
179 printk(KERN_ERR "iseries_init_IRQ: open event path "
180 "failed with rc 0x%x\n", ret);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700181 } else
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100182 printk(KERN_ERR "iseries_init_IRQ: register handler "
183 "failed with rc 0x%x\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
Stephen Rothwell853f8282005-11-16 18:10:40 +1100186#define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
188#define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
189#define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
190
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700191/*
192 * This will be called by device drivers (via enable_IRQ)
193 * to enable INTA in the bridge interrupt status register.
194 */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100195static void iseries_enable_IRQ(unsigned int irq)
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700196{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100197 u32 bus, dev_id, function, mask;
198 const u32 sub_bus = 0;
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700199 unsigned int rirq = virt_irq_to_real_map[irq];
200
201 /* The IRQ has already been locked by the caller */
202 bus = REAL_IRQ_TO_BUS(rirq);
203 function = REAL_IRQ_TO_FUNC(rirq);
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100204 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700205
206 /* Unmask secondary INTA */
207 mask = 0x80000000;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100208 HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask);
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700209}
210
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100211/* This is called by iseries_activate_IRQs */
212static unsigned int iseries_startup_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100214 u32 bus, dev_id, function, mask;
215 const u32 sub_bus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 unsigned int rirq = virt_irq_to_real_map[irq];
217
218 bus = REAL_IRQ_TO_BUS(rirq);
219 function = REAL_IRQ_TO_FUNC(rirq);
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100220 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* Link the IRQ number to the bridge */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100223 HvCallXm_connectBusUnit(bus, sub_bus, dev_id, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 /* Unmask bridge interrupts in the FISR */
226 mask = 0x01010000 << function;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100227 HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask);
228 iseries_enable_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 return 0;
230}
231
232/*
233 * This is called out of iSeries_fixup to activate interrupt
234 * generation for usable slots
235 */
236void __init iSeries_activate_IRQs()
237{
238 int irq;
239 unsigned long flags;
240
241 for_each_irq (irq) {
242 irq_desc_t *desc = get_irq_desc(irq);
243
244 if (desc && desc->handler && desc->handler->startup) {
245 spin_lock_irqsave(&desc->lock, flags);
246 desc->handler->startup(irq);
247 spin_unlock_irqrestore(&desc->lock, flags);
248 }
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252/* this is not called anywhere currently */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100253static void iseries_shutdown_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100255 u32 bus, dev_id, function, mask;
256 const u32 sub_bus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 unsigned int rirq = virt_irq_to_real_map[irq];
258
259 /* irq should be locked by the caller */
260 bus = REAL_IRQ_TO_BUS(rirq);
261 function = REAL_IRQ_TO_FUNC(rirq);
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100262 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 /* Invalidate the IRQ number in the bridge */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100265 HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 /* Mask bridge interrupts in the FISR */
268 mask = 0x01010000 << function;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100269 HvCallPci_maskFisr(bus, sub_bus, dev_id, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
272/*
273 * This will be called by device drivers (via disable_IRQ)
274 * to disable INTA in the bridge interrupt status register.
275 */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100276static void iseries_disable_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100278 u32 bus, dev_id, function, mask;
279 const u32 sub_bus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 unsigned int rirq = virt_irq_to_real_map[irq];
281
282 /* The IRQ has already been locked by the caller */
283 bus = REAL_IRQ_TO_BUS(rirq);
284 function = REAL_IRQ_TO_FUNC(rirq);
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100285 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 /* Mask secondary INTA */
288 mask = 0x80000000;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100289 HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290}
291
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100292static void iseries_end_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Stephen Rothwell853f8282005-11-16 18:10:40 +1100294 unsigned int rirq = virt_irq_to_real_map[irq];
295
296 HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq), REAL_IRQ_TO_SUBBUS(rirq),
297 (REAL_IRQ_TO_IDSEL(rirq) << 4) + REAL_IRQ_TO_FUNC(rirq));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700299
300static hw_irq_controller iSeries_IRQ_handler = {
301 .typename = "iSeries irq controller",
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100302 .startup = iseries_startup_IRQ,
303 .shutdown = iseries_shutdown_IRQ,
304 .enable = iseries_enable_IRQ,
305 .disable = iseries_disable_IRQ,
306 .end = iseries_end_IRQ
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700307};
308
309/*
310 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
311 * It calculates the irq value for the slot.
Stephen Rothwell853f8282005-11-16 18:10:40 +1100312 * Note that sub_bus is always 0 (at the moment at least).
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700313 */
Stephen Rothwell853f8282005-11-16 18:10:40 +1100314int __init iSeries_allocate_IRQ(HvBusNumber bus,
315 HvSubBusNumber sub_bus, HvAgentId dev_id)
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700316{
Stephen Rothwelld9ae2ba2005-11-10 18:11:19 +1100317 int virtirq;
318 unsigned int realirq;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100319 u8 idsel = (dev_id >> 4);
320 u8 function = dev_id & 7;
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700321
Stephen Rothwell853f8282005-11-16 18:10:40 +1100322 realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3)
323 + function;
Stephen Rothwelld9ae2ba2005-11-10 18:11:19 +1100324 virtirq = virt_irq_create_mapping(realirq);
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700325
326 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
327 return virtirq;
328}
Stephen Rothwelle1995002005-11-16 18:53:29 +1100329
Stephen Rothwellee2cdec2006-01-12 13:54:20 +1100330#endif /* CONFIG_PCI */
331
Stephen Rothwelle1995002005-11-16 18:53:29 +1100332/*
333 * Get the next pending IRQ.
334 */
335int iSeries_get_irq(struct pt_regs *regs)
336{
337 struct paca_struct *lpaca;
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +1100338 /* -2 means ignore this interrupt */
339 int irq = -2;
Stephen Rothwelle1995002005-11-16 18:53:29 +1100340
341 lpaca = get_paca();
342#ifdef CONFIG_SMP
343 if (lpaca->lppaca.int_dword.fields.ipi_cnt) {
344 lpaca->lppaca.int_dword.fields.ipi_cnt = 0;
345 iSeries_smp_message_recv(regs);
346 }
347#endif /* CONFIG_SMP */
348 if (hvlpevent_is_pending())
349 process_hvlpevents(regs);
350
Stephen Rothwellee2cdec2006-01-12 13:54:20 +1100351#ifdef CONFIG_PCI
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +1100352 if (num_pending_irqs) {
353 spin_lock(&pending_irqs_lock);
354 for (irq = 0; irq < NR_IRQS; irq++) {
355 if (pending_irqs[irq]) {
356 pending_irqs[irq]--;
357 num_pending_irqs--;
358 break;
359 }
360 }
361 spin_unlock(&pending_irqs_lock);
362 if (irq >= NR_IRQS)
363 irq = -2;
364 }
Stephen Rothwellee2cdec2006-01-12 13:54:20 +1100365#endif
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +1100366
367 return irq;
Stephen Rothwelle1995002005-11-16 18:53:29 +1100368}