blob: 3d023856405a128b83c5c9309813443552118faf [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 Rothwell60798c6a2005-11-16 17:47:43 +110051enum 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 Rothwell89ef68f2005-06-21 17:15:50 -070061};
62
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110063struct pci_event {
64 struct HvLpEvent event;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070065 union {
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110066 u64 __align; /* Align on an 8-byte boundary */
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070067 struct {
68 u32 fisr;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110069 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 Rothwell89ef68f2005-06-21 17:15:50 -070083};
84
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +110085static DEFINE_SPINLOCK(pending_irqs_lock);
86static int num_pending_irqs;
87static int pending_irqs[NR_IRQS];
88
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110089static void int_received(struct pci_event *event, struct pt_regs *regs)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070090{
91 int irq;
92
Stephen Rothwell60798c6a2005-11-16 17:47:43 +110093 switch (event->event.xSubtype) {
94 case pe_slot_interrupt:
95 irq = event->event.xCorrelationToken;
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +110096 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 Rothwell89ef68f2005-06-21 17:15:50 -0700108 break;
109 /* Ignore error recovery events for now */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100110 case pe_bus_created:
111 printk(KERN_INFO "int_received: system bus %d created\n",
112 event->data.bus.bus_number);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700113 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100114 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 Rothwell89ef68f2005-06-21 17:15:50 -0700118 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100119 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 Rothwell89ef68f2005-06-21 17:15:50 -0700123 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100124 case pe_node_failed:
125 case pe_bridge_error:
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700126 printk(KERN_INFO
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100127 "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 Rothwell89ef68f2005-06-21 17:15:50 -0700131 break;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100132 case pe_node_recovered:
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700133 printk(KERN_INFO
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100134 "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 Rothwell89ef68f2005-06-21 17:15:50 -0700138 break;
139 default:
140 printk(KERN_ERR
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100141 "int_received: unrecognized event subtype 0x%x\n",
142 event->event.xSubtype);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700143 break;
144 }
145}
146
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100147static void pci_event_handler(struct HvLpEvent *event, struct pt_regs *regs)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700148{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100149 if (event && (event->xType == HvLpEvent_Type_PciIo)) {
Stephen Rothwell677f8c02006-01-12 13:47:43 +1100150 if (hvlpevent_is_int(event))
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100151 int_received((struct pci_event *)event, regs);
Stephen Rothwell677f8c02006-01-12 13:47:43 +1100152 else
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700153 printk(KERN_ERR
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100154 "pci_event_handler: unexpected ack received\n");
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100155 } else if (event)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700156 printk(KERN_ERR
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100157 "pci_event_handler: Unrecognized PCI event type 0x%x\n",
158 (int)event->xType);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700159 else
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100160 printk(KERN_ERR "pci_event_handler: NULL event received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700161}
162
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700163/*
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 */
167void __init iSeries_init_IRQ(void)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700168{
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700169 /* Register PCI event handler and open an event path */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100170 int ret;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700171
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100172 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 Rothwell89ef68f2005-06-21 17:15:50 -0700179 } else
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100180 printk(KERN_ERR "iseries_init_IRQ: register handler "
181 "failed with rc 0x%x\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
Stephen Rothwell853f8282005-11-16 18:10:40 +1100184#define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#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 Rothwell0c3b4f12005-06-21 17:15:49 -0700189/*
190 * This will be called by device drivers (via enable_IRQ)
191 * to enable INTA in the bridge interrupt status register.
192 */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100193static void iseries_enable_IRQ(unsigned int irq)
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700194{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100195 u32 bus, dev_id, function, mask;
196 const u32 sub_bus = 0;
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700197 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 Rothwell60798c6a2005-11-16 17:47:43 +1100202 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700203
204 /* Unmask secondary INTA */
205 mask = 0x80000000;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100206 HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask);
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700207}
208
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100209/* This is called by iseries_activate_IRQs */
210static unsigned int iseries_startup_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100212 u32 bus, dev_id, function, mask;
213 const u32 sub_bus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 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 Rothwell60798c6a2005-11-16 17:47:43 +1100218 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /* Link the IRQ number to the bridge */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100221 HvCallXm_connectBusUnit(bus, sub_bus, dev_id, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* Unmask bridge interrupts in the FISR */
224 mask = 0x01010000 << function;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100225 HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask);
226 iseries_enable_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 return 0;
228}
229
230/*
231 * This is called out of iSeries_fixup to activate interrupt
232 * generation for usable slots
233 */
234void __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 Rothwell0c3b4f12005-06-21 17:15:49 -0700247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248}
249
250/* this is not called anywhere currently */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100251static void iseries_shutdown_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100253 u32 bus, dev_id, function, mask;
254 const u32 sub_bus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 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 Rothwell60798c6a2005-11-16 17:47:43 +1100260 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 /* Invalidate the IRQ number in the bridge */
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100263 HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 /* Mask bridge interrupts in the FISR */
266 mask = 0x01010000 << function;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100267 HvCallPci_maskFisr(bus, sub_bus, dev_id, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268}
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 Rothwell60798c6a2005-11-16 17:47:43 +1100274static void iseries_disable_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100276 u32 bus, dev_id, function, mask;
277 const u32 sub_bus = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 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 Rothwell60798c6a2005-11-16 17:47:43 +1100283 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 /* Mask secondary INTA */
286 mask = 0x80000000;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100287 HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100290static void iseries_end_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291{
Stephen Rothwell853f8282005-11-16 18:10:40 +1100292 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 Torvalds1da177e2005-04-16 15:20:36 -0700296}
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700297
298static hw_irq_controller iSeries_IRQ_handler = {
299 .typename = "iSeries irq controller",
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100300 .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 Rothwell0c3b4f12005-06-21 17:15:49 -0700305};
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 Rothwell853f8282005-11-16 18:10:40 +1100310 * Note that sub_bus is always 0 (at the moment at least).
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700311 */
Stephen Rothwell853f8282005-11-16 18:10:40 +1100312int __init iSeries_allocate_IRQ(HvBusNumber bus,
313 HvSubBusNumber sub_bus, HvAgentId dev_id)
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700314{
Stephen Rothwelld9ae2ba2005-11-10 18:11:19 +1100315 int virtirq;
316 unsigned int realirq;
Stephen Rothwell60798c6a2005-11-16 17:47:43 +1100317 u8 idsel = (dev_id >> 4);
318 u8 function = dev_id & 7;
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700319
Stephen Rothwell853f8282005-11-16 18:10:40 +1100320 realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3)
321 + function;
Stephen Rothwelld9ae2ba2005-11-10 18:11:19 +1100322 virtirq = virt_irq_create_mapping(realirq);
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700323
324 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
325 return virtirq;
326}
Stephen Rothwelle1995002005-11-16 18:53:29 +1100327
328/*
329 * Get the next pending IRQ.
330 */
331int iSeries_get_irq(struct pt_regs *regs)
332{
333 struct paca_struct *lpaca;
Stephen Rothwell1d7a6b92005-11-17 18:04:37 +1100334 /* -2 means ignore this interrupt */
335 int irq = -2;
Stephen Rothwelle1995002005-11-16 18:53:29 +1100336
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 Rothwell1d7a6b92005-11-17 18:04:37 +1100347 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 Rothwelle1995002005-11-16 18:53:29 +1100362}