blob: 55ecc8d3e73fb956df4f78502db27e1ab028a81f [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 Rothwell89ef68f2005-06-21 17:15:50 -070038#include <asm/ppcdebug.h>
39#include <asm/iSeries/HvTypes.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 Rothwellb08567cb2005-09-28 23:37:01 +100042
43#include "irq.h"
Stephen Rothwellc6d2ea92005-10-14 17:16:17 +100044#include "call_pci.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
46/* This maps virtual irq numbers to real irqs */
47unsigned int virt_irq_to_real_map[NR_IRQS];
48
49/* The next available virtual irq number */
50/* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */
51static int next_virtual_irq = 2;
52
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070053static long Pci_Interrupt_Count;
54static long Pci_Event_Count;
55
56enum 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
66};
67
68struct XmPciLpEvent_BusInterrupt {
69 HvBusNumber busNumber;
70 HvSubBusNumber subBusNumber;
71};
72
73struct XmPciLpEvent_NodeInterrupt {
74 HvBusNumber busNumber;
75 HvSubBusNumber subBusNumber;
76 HvAgentId deviceId;
77};
78
79struct XmPciLpEvent {
80 struct HvLpEvent hvLpEvent;
81
82 union {
83 u64 alignData; // Align on an 8-byte boundary
84
85 struct {
86 u32 fisr;
87 HvBusNumber busNumber;
88 HvSubBusNumber subBusNumber;
89 HvAgentId deviceId;
90 } slotInterrupt;
91
92 struct XmPciLpEvent_BusInterrupt busFailed;
93 struct XmPciLpEvent_BusInterrupt busRecovered;
94 struct XmPciLpEvent_BusInterrupt busCreated;
95
96 struct XmPciLpEvent_NodeInterrupt nodeFailed;
97 struct XmPciLpEvent_NodeInterrupt nodeRecovered;
98
99 } eventData;
100
101};
102
103static void intReceived(struct XmPciLpEvent *eventParm,
104 struct pt_regs *regsParm)
105{
106 int irq;
107
108 ++Pci_Interrupt_Count;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700109
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);
118 break;
119 /* Ignore error recovery events for now */
120 case XmPciLpEvent_BusCreated:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700121 printk(KERN_INFO "intReceived: system bus %d created\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700122 eventParm->eventData.busCreated.busNumber);
123 break;
124 case XmPciLpEvent_BusError:
125 case XmPciLpEvent_BusFailed:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700126 printk(KERN_INFO "intReceived: system bus %d failed\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700127 eventParm->eventData.busFailed.busNumber);
128 break;
129 case XmPciLpEvent_BusRecovered:
130 case XmPciLpEvent_UnQuiesceBus:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700131 printk(KERN_INFO "intReceived: system bus %d recovered\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700132 eventParm->eventData.busRecovered.busNumber);
133 break;
134 case XmPciLpEvent_NodeFailed:
135 case XmPciLpEvent_BridgeError:
136 printk(KERN_INFO
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700137 "intReceived: multi-adapter bridge %d/%d/%d failed\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700138 eventParm->eventData.nodeFailed.busNumber,
139 eventParm->eventData.nodeFailed.subBusNumber,
140 eventParm->eventData.nodeFailed.deviceId);
141 break;
142 case XmPciLpEvent_NodeRecovered:
143 printk(KERN_INFO
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700144 "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700145 eventParm->eventData.nodeRecovered.busNumber,
146 eventParm->eventData.nodeRecovered.subBusNumber,
147 eventParm->eventData.nodeRecovered.deviceId);
148 break;
149 default:
150 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700151 "intReceived: unrecognized event subtype 0x%x\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700152 eventParm->hvLpEvent.xSubtype);
153 break;
154 }
155}
156
157static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
158 struct pt_regs *regsParm)
159{
160#ifdef CONFIG_PCI
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700161 ++Pci_Event_Count;
162
163 if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
164 switch (eventParm->xFlags.xFunction) {
165 case HvLpEvent_Function_Int:
166 intReceived((struct XmPciLpEvent *)eventParm, regsParm);
167 break;
168 case HvLpEvent_Function_Ack:
169 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700170 "XmPciLpEvent_handler: unexpected ack received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700171 break;
172 default:
173 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700174 "XmPciLpEvent_handler: unexpected event function %d\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700175 (int)eventParm->xFlags.xFunction);
176 break;
177 }
178 } else if (eventParm)
179 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700180 "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700181 (int)eventParm->xType);
182 else
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700183 printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700184#endif
185}
186
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700187/*
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.
190 */
191void __init iSeries_init_IRQ(void)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700192{
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700193 /* Register PCI event handler and open an event path */
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700194 int xRc;
195
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700196 xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
197 &XmPciLpEvent_handler);
198 if (xRc == 0) {
199 xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
200 if (xRc != 0)
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700201 printk(KERN_ERR "iSeries_init_IRQ: open event path "
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700202 "failed with rc 0x%x\n", xRc);
203 } else
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700204 printk(KERN_ERR "iSeries_init_IRQ: register handler "
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700205 "failed with rc 0x%x\n", xRc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206}
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#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)
211
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700212/*
213 * This will be called by device drivers (via enable_IRQ)
214 * to enable INTA in the bridge interrupt status register.
215 */
216static void iSeries_enable_IRQ(unsigned int irq)
217{
218 u32 bus, deviceId, function, mask;
219 const u32 subBus = 0;
220 unsigned int rirq = virt_irq_to_real_map[irq];
221
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;
226
227 /* Unmask secondary INTA */
228 mask = 0x80000000;
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);
232}
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234/* This is called by iSeries_activate_IRQs */
235static unsigned int iSeries_startup_IRQ(unsigned int irq)
236{
237 u32 bus, deviceId, function, mask;
238 const u32 subBus = 0;
239 unsigned int rirq = virt_irq_to_real_map[irq];
240
241 bus = REAL_IRQ_TO_BUS(rirq);
242 function = REAL_IRQ_TO_FUNC(rirq);
243 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
244
245 /* Link the IRQ number to the bridge */
246 HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
247
248 /* Unmask bridge interrupts in the FISR */
249 mask = 0x01010000 << function;
250 HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
251 iSeries_enable_IRQ(irq);
252 return 0;
253}
254
255/*
256 * This is called out of iSeries_fixup to activate interrupt
257 * generation for usable slots
258 */
259void __init iSeries_activate_IRQs()
260{
261 int irq;
262 unsigned long flags;
263
264 for_each_irq (irq) {
265 irq_desc_t *desc = get_irq_desc(irq);
266
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);
271 }
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
275/* this is not called anywhere currently */
276static void iSeries_shutdown_IRQ(unsigned int irq)
277{
278 u32 bus, deviceId, function, mask;
279 const u32 subBus = 0;
280 unsigned int rirq = virt_irq_to_real_map[irq];
281
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;
286
287 /* Invalidate the IRQ number in the bridge */
288 HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
289
290 /* Mask bridge interrupts in the FISR */
291 mask = 0x01010000 << function;
292 HvCallPci_maskFisr(bus, subBus, deviceId, mask);
293}
294
295/*
296 * This will be called by device drivers (via disable_IRQ)
297 * to disable INTA in the bridge interrupt status register.
298 */
299static void iSeries_disable_IRQ(unsigned int irq)
300{
301 u32 bus, deviceId, function, mask;
302 const u32 subBus = 0;
303 unsigned int rirq = virt_irq_to_real_map[irq];
304
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;
309
310 /* Mask secondary INTA */
311 mask = 0x80000000;
312 HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
313 PPCDBG(PPCDBG_BUSWALK, "iSeries_disable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700314 bus, subBus, deviceId, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317/*
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
322 */
323static void iSeries_end_IRQ(unsigned int irq)
324{
325}
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700326
327static 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
334};
335
336/*
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).
340 */
341int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
342 HvSubBusNumber subBusNumber, HvAgentId deviceId)
343{
344 unsigned int realirq, virtirq;
345 u8 idsel = (deviceId >> 4);
346 u8 function = deviceId & 7;
347
348 virtirq = next_virtual_irq++;
349 realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
350 virt_irq_to_real_map[virtirq] = realirq;
351
352 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
353 return virtirq;
354}
Michael Ellermanba293ff2005-09-23 14:43:22 +1000355
356int virt_irq_create_mapping(unsigned int real_irq)
357{
358 BUG(); /* Don't call this on iSeries, yet */
359
360 return 0;
361}
362
363void virt_irq_init(void)
364{
365 return;
366}