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/ppcdebug.h>
39 #include <asm/iSeries/HvTypes.h>
40 #include <asm/iSeries/HvLpEvent.h>
41 #include <asm/iseries/hv_call_xm.h>
46 /* This maps virtual irq numbers to real irqs */
47 unsigned int virt_irq_to_real_map[NR_IRQS];
49 /* The next available virtual irq number */
50 /* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */
51 static int next_virtual_irq = 2;
53 static long Pci_Interrupt_Count;
54 static long Pci_Event_Count;
56 enum XmPciLpEvent_Subtype {
57 XmPciLpEvent_BusCreated = 0, // PHB has been created
58 XmPciLpEvent_BusError = 1, // PHB has failed
59 XmPciLpEvent_BusFailed = 2, // Msg to Secondary, Primary failed bus
60 XmPciLpEvent_NodeFailed = 4, // Multi-adapter bridge has failed
61 XmPciLpEvent_NodeRecovered = 5, // Multi-adapter bridge has recovered
62 XmPciLpEvent_BusRecovered = 12, // PHB has been recovered
63 XmPciLpEvent_UnQuiesceBus = 18, // Secondary bus unqiescing
64 XmPciLpEvent_BridgeError = 21, // Bridge Error
65 XmPciLpEvent_SlotInterrupt = 22 // Slot interrupt
68 struct XmPciLpEvent_BusInterrupt {
69 HvBusNumber busNumber;
70 HvSubBusNumber subBusNumber;
73 struct XmPciLpEvent_NodeInterrupt {
74 HvBusNumber busNumber;
75 HvSubBusNumber subBusNumber;
80 struct HvLpEvent hvLpEvent;
83 u64 alignData; // Align on an 8-byte boundary
87 HvBusNumber busNumber;
88 HvSubBusNumber subBusNumber;
92 struct XmPciLpEvent_BusInterrupt busFailed;
93 struct XmPciLpEvent_BusInterrupt busRecovered;
94 struct XmPciLpEvent_BusInterrupt busCreated;
96 struct XmPciLpEvent_NodeInterrupt nodeFailed;
97 struct XmPciLpEvent_NodeInterrupt nodeRecovered;
103 static void intReceived(struct XmPciLpEvent *eventParm,
104 struct pt_regs *regsParm)
108 ++Pci_Interrupt_Count;
110 switch (eventParm->hvLpEvent.xSubtype) {
111 case XmPciLpEvent_SlotInterrupt:
112 irq = eventParm->hvLpEvent.xCorrelationToken;
113 /* Dispatch the interrupt handlers for this irq */
114 ppc_irq_dispatch_handler(regsParm, irq);
115 HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
116 eventParm->eventData.slotInterrupt.subBusNumber,
117 eventParm->eventData.slotInterrupt.deviceId);
119 /* Ignore error recovery events for now */
120 case XmPciLpEvent_BusCreated:
121 printk(KERN_INFO "intReceived: system bus %d created\n",
122 eventParm->eventData.busCreated.busNumber);
124 case XmPciLpEvent_BusError:
125 case XmPciLpEvent_BusFailed:
126 printk(KERN_INFO "intReceived: system bus %d failed\n",
127 eventParm->eventData.busFailed.busNumber);
129 case XmPciLpEvent_BusRecovered:
130 case XmPciLpEvent_UnQuiesceBus:
131 printk(KERN_INFO "intReceived: system bus %d recovered\n",
132 eventParm->eventData.busRecovered.busNumber);
134 case XmPciLpEvent_NodeFailed:
135 case XmPciLpEvent_BridgeError:
137 "intReceived: multi-adapter bridge %d/%d/%d failed\n",
138 eventParm->eventData.nodeFailed.busNumber,
139 eventParm->eventData.nodeFailed.subBusNumber,
140 eventParm->eventData.nodeFailed.deviceId);
142 case XmPciLpEvent_NodeRecovered:
144 "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
145 eventParm->eventData.nodeRecovered.busNumber,
146 eventParm->eventData.nodeRecovered.subBusNumber,
147 eventParm->eventData.nodeRecovered.deviceId);
151 "intReceived: unrecognized event subtype 0x%x\n",
152 eventParm->hvLpEvent.xSubtype);
157 static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
158 struct pt_regs *regsParm)
163 if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
164 switch (eventParm->xFlags.xFunction) {
165 case HvLpEvent_Function_Int:
166 intReceived((struct XmPciLpEvent *)eventParm, regsParm);
168 case HvLpEvent_Function_Ack:
170 "XmPciLpEvent_handler: unexpected ack received\n");
174 "XmPciLpEvent_handler: unexpected event function %d\n",
175 (int)eventParm->xFlags.xFunction);
178 } else if (eventParm)
180 "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
181 (int)eventParm->xType);
183 printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
188 * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
189 * It must be called before the bus walk.
191 void __init iSeries_init_IRQ(void)
193 /* Register PCI event handler and open an event path */
196 xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
197 &XmPciLpEvent_handler);
199 xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
201 printk(KERN_ERR "iSeries_init_IRQ: open event path "
202 "failed with rc 0x%x\n", xRc);
204 printk(KERN_ERR "iSeries_init_IRQ: register handler "
205 "failed with rc 0x%x\n", xRc);
208 #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
209 #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
210 #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
213 * This will be called by device drivers (via enable_IRQ)
214 * to enable INTA in the bridge interrupt status register.
216 static void iSeries_enable_IRQ(unsigned int irq)
218 u32 bus, deviceId, function, mask;
219 const u32 subBus = 0;
220 unsigned int rirq = virt_irq_to_real_map[irq];
222 /* The IRQ has already been locked by the caller */
223 bus = REAL_IRQ_TO_BUS(rirq);
224 function = REAL_IRQ_TO_FUNC(rirq);
225 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
227 /* Unmask secondary INTA */
229 HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
230 PPCDBG(PPCDBG_BUSWALK, "iSeries_enable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
231 bus, subBus, deviceId, irq);
234 /* This is called by iSeries_activate_IRQs */
235 static unsigned int iSeries_startup_IRQ(unsigned int irq)
237 u32 bus, deviceId, function, mask;
238 const u32 subBus = 0;
239 unsigned int rirq = virt_irq_to_real_map[irq];
241 bus = REAL_IRQ_TO_BUS(rirq);
242 function = REAL_IRQ_TO_FUNC(rirq);
243 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
245 /* Link the IRQ number to the bridge */
246 HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
248 /* Unmask bridge interrupts in the FISR */
249 mask = 0x01010000 << function;
250 HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
251 iSeries_enable_IRQ(irq);
256 * This is called out of iSeries_fixup to activate interrupt
257 * generation for usable slots
259 void __init iSeries_activate_IRQs()
265 irq_desc_t *desc = get_irq_desc(irq);
267 if (desc && desc->handler && desc->handler->startup) {
268 spin_lock_irqsave(&desc->lock, flags);
269 desc->handler->startup(irq);
270 spin_unlock_irqrestore(&desc->lock, flags);
275 /* this is not called anywhere currently */
276 static void iSeries_shutdown_IRQ(unsigned int irq)
278 u32 bus, deviceId, function, mask;
279 const u32 subBus = 0;
280 unsigned int rirq = virt_irq_to_real_map[irq];
282 /* irq should be locked by the caller */
283 bus = REAL_IRQ_TO_BUS(rirq);
284 function = REAL_IRQ_TO_FUNC(rirq);
285 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
287 /* Invalidate the IRQ number in the bridge */
288 HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
290 /* Mask bridge interrupts in the FISR */
291 mask = 0x01010000 << function;
292 HvCallPci_maskFisr(bus, subBus, deviceId, mask);
296 * This will be called by device drivers (via disable_IRQ)
297 * to disable INTA in the bridge interrupt status register.
299 static void iSeries_disable_IRQ(unsigned int irq)
301 u32 bus, deviceId, function, mask;
302 const u32 subBus = 0;
303 unsigned int rirq = virt_irq_to_real_map[irq];
305 /* The IRQ has already been locked by the caller */
306 bus = REAL_IRQ_TO_BUS(rirq);
307 function = REAL_IRQ_TO_FUNC(rirq);
308 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
310 /* Mask secondary INTA */
312 HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
313 PPCDBG(PPCDBG_BUSWALK, "iSeries_disable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
314 bus, subBus, deviceId, irq);
318 * Need to define this so ppc_irq_dispatch_handler will NOT call
319 * enable_IRQ at the end of interrupt handling. However, this does
320 * nothing because there is not enough information provided to do
321 * the EOI HvCall. This is done by XmPciLpEvent.c
323 static void iSeries_end_IRQ(unsigned int irq)
327 static hw_irq_controller iSeries_IRQ_handler = {
328 .typename = "iSeries irq controller",
329 .startup = iSeries_startup_IRQ,
330 .shutdown = iSeries_shutdown_IRQ,
331 .enable = iSeries_enable_IRQ,
332 .disable = iSeries_disable_IRQ,
333 .end = iSeries_end_IRQ
337 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
338 * It calculates the irq value for the slot.
339 * Note that subBusNumber is always 0 (at the moment at least).
341 int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
342 HvSubBusNumber subBusNumber, HvAgentId deviceId)
344 unsigned int realirq, virtirq;
345 u8 idsel = (deviceId >> 4);
346 u8 function = deviceId & 7;
348 virtirq = next_virtual_irq++;
349 realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
350 virt_irq_to_real_map[virtirq] = realirq;
352 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
356 int virt_irq_create_mapping(unsigned int real_irq)
358 BUG(); /* Don't call this on iSeries, yet */
363 void virt_irq_init(void)