2 * This module supports the iSeries PCI bus interrupt handling
3 * Copyright (C) 20yy <Robert L Holtorf> <IBM Corp>
4 * Copyright (C) 2004-2005 IBM Corporation
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.
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.
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
23 * Created, December 13, 2000 by Wayne Holm
26 #include <linux/config.h>
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>
35 #include <linux/irq.h>
36 #include <linux/spinlock.h>
38 #include <asm/iseries/hv_types.h>
39 #include <asm/iseries/hv_lp_event.h>
40 #include <asm/iseries/hv_call_xm.h>
45 static long Pci_Interrupt_Count;
46 static long Pci_Event_Count;
48 enum XmPciLpEvent_Subtype {
49 XmPciLpEvent_BusCreated = 0, // PHB has been created
50 XmPciLpEvent_BusError = 1, // PHB has failed
51 XmPciLpEvent_BusFailed = 2, // Msg to Secondary, Primary failed bus
52 XmPciLpEvent_NodeFailed = 4, // Multi-adapter bridge has failed
53 XmPciLpEvent_NodeRecovered = 5, // Multi-adapter bridge has recovered
54 XmPciLpEvent_BusRecovered = 12, // PHB has been recovered
55 XmPciLpEvent_UnQuiesceBus = 18, // Secondary bus unqiescing
56 XmPciLpEvent_BridgeError = 21, // Bridge Error
57 XmPciLpEvent_SlotInterrupt = 22 // Slot interrupt
60 struct XmPciLpEvent_BusInterrupt {
61 HvBusNumber busNumber;
62 HvSubBusNumber subBusNumber;
65 struct XmPciLpEvent_NodeInterrupt {
66 HvBusNumber busNumber;
67 HvSubBusNumber subBusNumber;
72 struct HvLpEvent hvLpEvent;
75 u64 alignData; // Align on an 8-byte boundary
79 HvBusNumber busNumber;
80 HvSubBusNumber subBusNumber;
84 struct XmPciLpEvent_BusInterrupt busFailed;
85 struct XmPciLpEvent_BusInterrupt busRecovered;
86 struct XmPciLpEvent_BusInterrupt busCreated;
88 struct XmPciLpEvent_NodeInterrupt nodeFailed;
89 struct XmPciLpEvent_NodeInterrupt nodeRecovered;
95 static void intReceived(struct XmPciLpEvent *eventParm,
96 struct pt_regs *regsParm)
99 #ifdef CONFIG_IRQSTACKS
100 struct thread_info *curtp, *irqtp;
103 ++Pci_Interrupt_Count;
105 switch (eventParm->hvLpEvent.xSubtype) {
106 case XmPciLpEvent_SlotInterrupt:
107 irq = eventParm->hvLpEvent.xCorrelationToken;
108 /* Dispatch the interrupt handlers for this irq */
109 #ifdef CONFIG_IRQSTACKS
110 /* Switch to the irq stack to handle this */
111 curtp = current_thread_info();
112 irqtp = hardirq_ctx[smp_processor_id()];
113 if (curtp != irqtp) {
114 irqtp->task = curtp->task;
116 call___do_IRQ(irq, regsParm, irqtp);
119 set_bits(irqtp->flags, &curtp->flags);
122 __do_IRQ(irq, regsParm);
123 HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
124 eventParm->eventData.slotInterrupt.subBusNumber,
125 eventParm->eventData.slotInterrupt.deviceId);
127 /* Ignore error recovery events for now */
128 case XmPciLpEvent_BusCreated:
129 printk(KERN_INFO "intReceived: system bus %d created\n",
130 eventParm->eventData.busCreated.busNumber);
132 case XmPciLpEvent_BusError:
133 case XmPciLpEvent_BusFailed:
134 printk(KERN_INFO "intReceived: system bus %d failed\n",
135 eventParm->eventData.busFailed.busNumber);
137 case XmPciLpEvent_BusRecovered:
138 case XmPciLpEvent_UnQuiesceBus:
139 printk(KERN_INFO "intReceived: system bus %d recovered\n",
140 eventParm->eventData.busRecovered.busNumber);
142 case XmPciLpEvent_NodeFailed:
143 case XmPciLpEvent_BridgeError:
145 "intReceived: multi-adapter bridge %d/%d/%d failed\n",
146 eventParm->eventData.nodeFailed.busNumber,
147 eventParm->eventData.nodeFailed.subBusNumber,
148 eventParm->eventData.nodeFailed.deviceId);
150 case XmPciLpEvent_NodeRecovered:
152 "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
153 eventParm->eventData.nodeRecovered.busNumber,
154 eventParm->eventData.nodeRecovered.subBusNumber,
155 eventParm->eventData.nodeRecovered.deviceId);
159 "intReceived: unrecognized event subtype 0x%x\n",
160 eventParm->hvLpEvent.xSubtype);
165 static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
166 struct pt_regs *regsParm)
171 if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
172 switch (eventParm->xFlags.xFunction) {
173 case HvLpEvent_Function_Int:
174 intReceived((struct XmPciLpEvent *)eventParm, regsParm);
176 case HvLpEvent_Function_Ack:
178 "XmPciLpEvent_handler: unexpected ack received\n");
182 "XmPciLpEvent_handler: unexpected event function %d\n",
183 (int)eventParm->xFlags.xFunction);
186 } else if (eventParm)
188 "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
189 (int)eventParm->xType);
191 printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
196 * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
197 * It must be called before the bus walk.
199 void __init iSeries_init_IRQ(void)
201 /* Register PCI event handler and open an event path */
204 xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
205 &XmPciLpEvent_handler);
207 xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
209 printk(KERN_ERR "iSeries_init_IRQ: open event path "
210 "failed with rc 0x%x\n", xRc);
212 printk(KERN_ERR "iSeries_init_IRQ: register handler "
213 "failed with rc 0x%x\n", xRc);
216 #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
217 #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
218 #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
221 * This will be called by device drivers (via enable_IRQ)
222 * to enable INTA in the bridge interrupt status register.
224 static void iSeries_enable_IRQ(unsigned int irq)
226 u32 bus, deviceId, function, mask;
227 const u32 subBus = 0;
228 unsigned int rirq = virt_irq_to_real_map[irq];
230 /* The IRQ has already been locked by the caller */
231 bus = REAL_IRQ_TO_BUS(rirq);
232 function = REAL_IRQ_TO_FUNC(rirq);
233 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
235 /* Unmask secondary INTA */
237 HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
240 /* This is called by iSeries_activate_IRQs */
241 static unsigned int iSeries_startup_IRQ(unsigned int irq)
243 u32 bus, deviceId, function, mask;
244 const u32 subBus = 0;
245 unsigned int rirq = virt_irq_to_real_map[irq];
247 bus = REAL_IRQ_TO_BUS(rirq);
248 function = REAL_IRQ_TO_FUNC(rirq);
249 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
251 /* Link the IRQ number to the bridge */
252 HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
254 /* Unmask bridge interrupts in the FISR */
255 mask = 0x01010000 << function;
256 HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
257 iSeries_enable_IRQ(irq);
262 * This is called out of iSeries_fixup to activate interrupt
263 * generation for usable slots
265 void __init iSeries_activate_IRQs()
271 irq_desc_t *desc = get_irq_desc(irq);
273 if (desc && desc->handler && desc->handler->startup) {
274 spin_lock_irqsave(&desc->lock, flags);
275 desc->handler->startup(irq);
276 spin_unlock_irqrestore(&desc->lock, flags);
281 /* this is not called anywhere currently */
282 static void iSeries_shutdown_IRQ(unsigned int irq)
284 u32 bus, deviceId, function, mask;
285 const u32 subBus = 0;
286 unsigned int rirq = virt_irq_to_real_map[irq];
288 /* irq should be locked by the caller */
289 bus = REAL_IRQ_TO_BUS(rirq);
290 function = REAL_IRQ_TO_FUNC(rirq);
291 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
293 /* Invalidate the IRQ number in the bridge */
294 HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
296 /* Mask bridge interrupts in the FISR */
297 mask = 0x01010000 << function;
298 HvCallPci_maskFisr(bus, subBus, deviceId, mask);
302 * This will be called by device drivers (via disable_IRQ)
303 * to disable INTA in the bridge interrupt status register.
305 static void iSeries_disable_IRQ(unsigned int irq)
307 u32 bus, deviceId, function, mask;
308 const u32 subBus = 0;
309 unsigned int rirq = virt_irq_to_real_map[irq];
311 /* The IRQ has already been locked by the caller */
312 bus = REAL_IRQ_TO_BUS(rirq);
313 function = REAL_IRQ_TO_FUNC(rirq);
314 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
316 /* Mask secondary INTA */
318 HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
322 * This does nothing because there is not enough information
323 * provided to do the EOI HvCall. This is done by XmPciLpEvent.c
325 static void iSeries_end_IRQ(unsigned int irq)
329 static hw_irq_controller iSeries_IRQ_handler = {
330 .typename = "iSeries irq controller",
331 .startup = iSeries_startup_IRQ,
332 .shutdown = iSeries_shutdown_IRQ,
333 .enable = iSeries_enable_IRQ,
334 .disable = iSeries_disable_IRQ,
335 .end = iSeries_end_IRQ
339 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
340 * It calculates the irq value for the slot.
341 * Note that subBusNumber is always 0 (at the moment at least).
343 int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
344 HvSubBusNumber subBusNumber, HvAgentId deviceId)
347 unsigned int realirq;
348 u8 idsel = (deviceId >> 4);
349 u8 function = deviceId & 7;
351 realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
352 virtirq = virt_irq_create_mapping(realirq);
354 irq_desc[virtirq].handler = &iSeries_IRQ_handler;