blob: 01090e9ce0cfb74bc30eaa1068d7e0b883883786 [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
Kelly Daly1ec65d72005-11-02 13:46:07 +110038#include <asm/iseries/hv_types.h>
Kelly Dalye45423e2005-11-02 12:08:31 +110039#include <asm/iseries/hv_lp_event.h>
Kelly Daly8021b8a2005-11-02 11:41:12 +110040#include <asm/iseries/hv_call_xm.h>
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100041
42#include "irq.h"
Stephen Rothwellc6d2ea92005-10-14 17:16:17 +100043#include "call_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/* This maps virtual irq numbers to real irqs */
46unsigned int virt_irq_to_real_map[NR_IRQS];
47
48/* The next available virtual irq number */
49/* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */
50static int next_virtual_irq = 2;
51
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070052static long Pci_Interrupt_Count;
53static long Pci_Event_Count;
54
55enum XmPciLpEvent_Subtype {
56 XmPciLpEvent_BusCreated = 0, // PHB has been created
57 XmPciLpEvent_BusError = 1, // PHB has failed
58 XmPciLpEvent_BusFailed = 2, // Msg to Secondary, Primary failed bus
59 XmPciLpEvent_NodeFailed = 4, // Multi-adapter bridge has failed
60 XmPciLpEvent_NodeRecovered = 5, // Multi-adapter bridge has recovered
61 XmPciLpEvent_BusRecovered = 12, // PHB has been recovered
62 XmPciLpEvent_UnQuiesceBus = 18, // Secondary bus unqiescing
63 XmPciLpEvent_BridgeError = 21, // Bridge Error
64 XmPciLpEvent_SlotInterrupt = 22 // Slot interrupt
65};
66
67struct XmPciLpEvent_BusInterrupt {
68 HvBusNumber busNumber;
69 HvSubBusNumber subBusNumber;
70};
71
72struct XmPciLpEvent_NodeInterrupt {
73 HvBusNumber busNumber;
74 HvSubBusNumber subBusNumber;
75 HvAgentId deviceId;
76};
77
78struct XmPciLpEvent {
79 struct HvLpEvent hvLpEvent;
80
81 union {
82 u64 alignData; // Align on an 8-byte boundary
83
84 struct {
85 u32 fisr;
86 HvBusNumber busNumber;
87 HvSubBusNumber subBusNumber;
88 HvAgentId deviceId;
89 } slotInterrupt;
90
91 struct XmPciLpEvent_BusInterrupt busFailed;
92 struct XmPciLpEvent_BusInterrupt busRecovered;
93 struct XmPciLpEvent_BusInterrupt busCreated;
94
95 struct XmPciLpEvent_NodeInterrupt nodeFailed;
96 struct XmPciLpEvent_NodeInterrupt nodeRecovered;
97
98 } eventData;
99
100};
101
102static void intReceived(struct XmPciLpEvent *eventParm,
103 struct pt_regs *regsParm)
104{
105 int irq;
Stephen Rothwell5a7b3ff2005-11-09 15:07:16 +1100106#ifdef CONFIG_IRQSTACKS
107 struct thread_info *curtp, *irqtp;
108#endif
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700109
110 ++Pci_Interrupt_Count;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700111
112 switch (eventParm->hvLpEvent.xSubtype) {
113 case XmPciLpEvent_SlotInterrupt:
114 irq = eventParm->hvLpEvent.xCorrelationToken;
115 /* Dispatch the interrupt handlers for this irq */
Stephen Rothwell5a7b3ff2005-11-09 15:07:16 +1100116#ifdef CONFIG_IRQSTACKS
117 /* Switch to the irq stack to handle this */
118 curtp = current_thread_info();
119 irqtp = hardirq_ctx[smp_processor_id()];
120 if (curtp != irqtp) {
121 irqtp->task = curtp->task;
122 irqtp->flags = 0;
Stephen Rothwelld4be4f32005-11-09 16:19:53 +1100123 call___do_IRQ(irq, regsParm, irqtp);
Stephen Rothwell5a7b3ff2005-11-09 15:07:16 +1100124 irqtp->task = NULL;
125 if (irqtp->flags)
126 set_bits(irqtp->flags, &curtp->flags);
127 } else
128#endif
Stephen Rothwelld4be4f32005-11-09 16:19:53 +1100129 __do_IRQ(irq, regsParm);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700130 HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
131 eventParm->eventData.slotInterrupt.subBusNumber,
132 eventParm->eventData.slotInterrupt.deviceId);
133 break;
134 /* Ignore error recovery events for now */
135 case XmPciLpEvent_BusCreated:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700136 printk(KERN_INFO "intReceived: system bus %d created\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700137 eventParm->eventData.busCreated.busNumber);
138 break;
139 case XmPciLpEvent_BusError:
140 case XmPciLpEvent_BusFailed:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700141 printk(KERN_INFO "intReceived: system bus %d failed\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700142 eventParm->eventData.busFailed.busNumber);
143 break;
144 case XmPciLpEvent_BusRecovered:
145 case XmPciLpEvent_UnQuiesceBus:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700146 printk(KERN_INFO "intReceived: system bus %d recovered\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700147 eventParm->eventData.busRecovered.busNumber);
148 break;
149 case XmPciLpEvent_NodeFailed:
150 case XmPciLpEvent_BridgeError:
151 printk(KERN_INFO
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700152 "intReceived: multi-adapter bridge %d/%d/%d failed\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700153 eventParm->eventData.nodeFailed.busNumber,
154 eventParm->eventData.nodeFailed.subBusNumber,
155 eventParm->eventData.nodeFailed.deviceId);
156 break;
157 case XmPciLpEvent_NodeRecovered:
158 printk(KERN_INFO
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700159 "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700160 eventParm->eventData.nodeRecovered.busNumber,
161 eventParm->eventData.nodeRecovered.subBusNumber,
162 eventParm->eventData.nodeRecovered.deviceId);
163 break;
164 default:
165 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700166 "intReceived: unrecognized event subtype 0x%x\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700167 eventParm->hvLpEvent.xSubtype);
168 break;
169 }
170}
171
172static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
173 struct pt_regs *regsParm)
174{
175#ifdef CONFIG_PCI
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700176 ++Pci_Event_Count;
177
178 if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
179 switch (eventParm->xFlags.xFunction) {
180 case HvLpEvent_Function_Int:
181 intReceived((struct XmPciLpEvent *)eventParm, regsParm);
182 break;
183 case HvLpEvent_Function_Ack:
184 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700185 "XmPciLpEvent_handler: unexpected ack received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700186 break;
187 default:
188 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700189 "XmPciLpEvent_handler: unexpected event function %d\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700190 (int)eventParm->xFlags.xFunction);
191 break;
192 }
193 } else if (eventParm)
194 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700195 "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700196 (int)eventParm->xType);
197 else
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700198 printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700199#endif
200}
201
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700202/*
203 * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
204 * It must be called before the bus walk.
205 */
206void __init iSeries_init_IRQ(void)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700207{
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700208 /* Register PCI event handler and open an event path */
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700209 int xRc;
210
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700211 xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
212 &XmPciLpEvent_handler);
213 if (xRc == 0) {
214 xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
215 if (xRc != 0)
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700216 printk(KERN_ERR "iSeries_init_IRQ: open event path "
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700217 "failed with rc 0x%x\n", xRc);
218 } else
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700219 printk(KERN_ERR "iSeries_init_IRQ: register handler "
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700220 "failed with rc 0x%x\n", xRc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223#define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
224#define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
225#define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
226
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700227/*
228 * This will be called by device drivers (via enable_IRQ)
229 * to enable INTA in the bridge interrupt status register.
230 */
231static void iSeries_enable_IRQ(unsigned int irq)
232{
233 u32 bus, deviceId, function, mask;
234 const u32 subBus = 0;
235 unsigned int rirq = virt_irq_to_real_map[irq];
236
237 /* The IRQ has already been locked by the caller */
238 bus = REAL_IRQ_TO_BUS(rirq);
239 function = REAL_IRQ_TO_FUNC(rirq);
240 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
241
242 /* Unmask secondary INTA */
243 mask = 0x80000000;
244 HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/* This is called by iSeries_activate_IRQs */
248static unsigned int iSeries_startup_IRQ(unsigned int irq)
249{
250 u32 bus, deviceId, function, mask;
251 const u32 subBus = 0;
252 unsigned int rirq = virt_irq_to_real_map[irq];
253
254 bus = REAL_IRQ_TO_BUS(rirq);
255 function = REAL_IRQ_TO_FUNC(rirq);
256 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
257
258 /* Link the IRQ number to the bridge */
259 HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
260
261 /* Unmask bridge interrupts in the FISR */
262 mask = 0x01010000 << function;
263 HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
264 iSeries_enable_IRQ(irq);
265 return 0;
266}
267
268/*
269 * This is called out of iSeries_fixup to activate interrupt
270 * generation for usable slots
271 */
272void __init iSeries_activate_IRQs()
273{
274 int irq;
275 unsigned long flags;
276
277 for_each_irq (irq) {
278 irq_desc_t *desc = get_irq_desc(irq);
279
280 if (desc && desc->handler && desc->handler->startup) {
281 spin_lock_irqsave(&desc->lock, flags);
282 desc->handler->startup(irq);
283 spin_unlock_irqrestore(&desc->lock, flags);
284 }
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286}
287
288/* this is not called anywhere currently */
289static void iSeries_shutdown_IRQ(unsigned int irq)
290{
291 u32 bus, deviceId, function, mask;
292 const u32 subBus = 0;
293 unsigned int rirq = virt_irq_to_real_map[irq];
294
295 /* irq should be locked by the caller */
296 bus = REAL_IRQ_TO_BUS(rirq);
297 function = REAL_IRQ_TO_FUNC(rirq);
298 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
299
300 /* Invalidate the IRQ number in the bridge */
301 HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
302
303 /* Mask bridge interrupts in the FISR */
304 mask = 0x01010000 << function;
305 HvCallPci_maskFisr(bus, subBus, deviceId, mask);
306}
307
308/*
309 * This will be called by device drivers (via disable_IRQ)
310 * to disable INTA in the bridge interrupt status register.
311 */
312static void iSeries_disable_IRQ(unsigned int irq)
313{
314 u32 bus, deviceId, function, mask;
315 const u32 subBus = 0;
316 unsigned int rirq = virt_irq_to_real_map[irq];
317
318 /* The IRQ has already been locked by the caller */
319 bus = REAL_IRQ_TO_BUS(rirq);
320 function = REAL_IRQ_TO_FUNC(rirq);
321 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
322
323 /* Mask secondary INTA */
324 mask = 0x80000000;
325 HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326}
327
328/*
Stephen Rothwelld4be4f32005-11-09 16:19:53 +1100329 * This does nothing because there is not enough information
330 * provided to do the EOI HvCall. This is done by XmPciLpEvent.c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 */
332static void iSeries_end_IRQ(unsigned int irq)
333{
334}
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700335
336static hw_irq_controller iSeries_IRQ_handler = {
337 .typename = "iSeries irq controller",
338 .startup = iSeries_startup_IRQ,
339 .shutdown = iSeries_shutdown_IRQ,
340 .enable = iSeries_enable_IRQ,
341 .disable = iSeries_disable_IRQ,
342 .end = iSeries_end_IRQ
343};
344
345/*
346 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
347 * It calculates the irq value for the slot.
348 * Note that subBusNumber is always 0 (at the moment at least).
349 */
350int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
351 HvSubBusNumber subBusNumber, HvAgentId deviceId)
352{
353 unsigned int realirq, virtirq;
354 u8 idsel = (deviceId >> 4);
355 u8 function = deviceId & 7;
356
357 virtirq = next_virtual_irq++;
358 realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
359 virt_irq_to_real_map[virtirq] = realirq;
360
361 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
362 return virtirq;
363}
Michael Ellermanba293ff2005-09-23 14:43:22 +1000364
365int virt_irq_create_mapping(unsigned int real_irq)
366{
367 BUG(); /* Don't call this on iSeries, yet */
368
369 return 0;
370}
371
372void virt_irq_init(void)
373{
374 return;
375}