blob: a58daa153686db64ca16a9fb4bc6b4f84a19ae7b [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
Stephen Rothwell89ef68f2005-06-21 17:15:50 -070045static long Pci_Interrupt_Count;
46static long Pci_Event_Count;
47
48enum 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
58};
59
60struct XmPciLpEvent_BusInterrupt {
61 HvBusNumber busNumber;
62 HvSubBusNumber subBusNumber;
63};
64
65struct XmPciLpEvent_NodeInterrupt {
66 HvBusNumber busNumber;
67 HvSubBusNumber subBusNumber;
68 HvAgentId deviceId;
69};
70
71struct XmPciLpEvent {
72 struct HvLpEvent hvLpEvent;
73
74 union {
75 u64 alignData; // Align on an 8-byte boundary
76
77 struct {
78 u32 fisr;
79 HvBusNumber busNumber;
80 HvSubBusNumber subBusNumber;
81 HvAgentId deviceId;
82 } slotInterrupt;
83
84 struct XmPciLpEvent_BusInterrupt busFailed;
85 struct XmPciLpEvent_BusInterrupt busRecovered;
86 struct XmPciLpEvent_BusInterrupt busCreated;
87
88 struct XmPciLpEvent_NodeInterrupt nodeFailed;
89 struct XmPciLpEvent_NodeInterrupt nodeRecovered;
90
91 } eventData;
92
93};
94
95static void intReceived(struct XmPciLpEvent *eventParm,
96 struct pt_regs *regsParm)
97{
98 int irq;
Stephen Rothwell5a7b3ff2005-11-09 15:07:16 +110099#ifdef CONFIG_IRQSTACKS
100 struct thread_info *curtp, *irqtp;
101#endif
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700102
103 ++Pci_Interrupt_Count;
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700104
105 switch (eventParm->hvLpEvent.xSubtype) {
106 case XmPciLpEvent_SlotInterrupt:
107 irq = eventParm->hvLpEvent.xCorrelationToken;
108 /* Dispatch the interrupt handlers for this irq */
Stephen Rothwell5a7b3ff2005-11-09 15:07:16 +1100109#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;
115 irqtp->flags = 0;
Stephen Rothwelld4be4f32005-11-09 16:19:53 +1100116 call___do_IRQ(irq, regsParm, irqtp);
Stephen Rothwell5a7b3ff2005-11-09 15:07:16 +1100117 irqtp->task = NULL;
118 if (irqtp->flags)
119 set_bits(irqtp->flags, &curtp->flags);
120 } else
121#endif
Stephen Rothwelld4be4f32005-11-09 16:19:53 +1100122 __do_IRQ(irq, regsParm);
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700123 HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
124 eventParm->eventData.slotInterrupt.subBusNumber,
125 eventParm->eventData.slotInterrupt.deviceId);
126 break;
127 /* Ignore error recovery events for now */
128 case XmPciLpEvent_BusCreated:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700129 printk(KERN_INFO "intReceived: system bus %d created\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700130 eventParm->eventData.busCreated.busNumber);
131 break;
132 case XmPciLpEvent_BusError:
133 case XmPciLpEvent_BusFailed:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700134 printk(KERN_INFO "intReceived: system bus %d failed\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700135 eventParm->eventData.busFailed.busNumber);
136 break;
137 case XmPciLpEvent_BusRecovered:
138 case XmPciLpEvent_UnQuiesceBus:
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700139 printk(KERN_INFO "intReceived: system bus %d recovered\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700140 eventParm->eventData.busRecovered.busNumber);
141 break;
142 case XmPciLpEvent_NodeFailed:
143 case XmPciLpEvent_BridgeError:
144 printk(KERN_INFO
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700145 "intReceived: multi-adapter bridge %d/%d/%d failed\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700146 eventParm->eventData.nodeFailed.busNumber,
147 eventParm->eventData.nodeFailed.subBusNumber,
148 eventParm->eventData.nodeFailed.deviceId);
149 break;
150 case XmPciLpEvent_NodeRecovered:
151 printk(KERN_INFO
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700152 "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700153 eventParm->eventData.nodeRecovered.busNumber,
154 eventParm->eventData.nodeRecovered.subBusNumber,
155 eventParm->eventData.nodeRecovered.deviceId);
156 break;
157 default:
158 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700159 "intReceived: unrecognized event subtype 0x%x\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700160 eventParm->hvLpEvent.xSubtype);
161 break;
162 }
163}
164
165static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
166 struct pt_regs *regsParm)
167{
168#ifdef CONFIG_PCI
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700169 ++Pci_Event_Count;
170
171 if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
172 switch (eventParm->xFlags.xFunction) {
173 case HvLpEvent_Function_Int:
174 intReceived((struct XmPciLpEvent *)eventParm, regsParm);
175 break;
176 case HvLpEvent_Function_Ack:
177 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700178 "XmPciLpEvent_handler: unexpected ack received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700179 break;
180 default:
181 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700182 "XmPciLpEvent_handler: unexpected event function %d\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700183 (int)eventParm->xFlags.xFunction);
184 break;
185 }
186 } else if (eventParm)
187 printk(KERN_ERR
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700188 "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700189 (int)eventParm->xType);
190 else
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700191 printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700192#endif
193}
194
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700195/*
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.
198 */
199void __init iSeries_init_IRQ(void)
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700200{
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700201 /* Register PCI event handler and open an event path */
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700202 int xRc;
203
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700204 xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
205 &XmPciLpEvent_handler);
206 if (xRc == 0) {
207 xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
208 if (xRc != 0)
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700209 printk(KERN_ERR "iSeries_init_IRQ: open event path "
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700210 "failed with rc 0x%x\n", xRc);
211 } else
Stephen Rothwell7f74e792005-06-21 17:15:51 -0700212 printk(KERN_ERR "iSeries_init_IRQ: register handler "
Stephen Rothwell89ef68f2005-06-21 17:15:50 -0700213 "failed with rc 0x%x\n", xRc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#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)
219
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700220/*
221 * This will be called by device drivers (via enable_IRQ)
222 * to enable INTA in the bridge interrupt status register.
223 */
224static void iSeries_enable_IRQ(unsigned int irq)
225{
226 u32 bus, deviceId, function, mask;
227 const u32 subBus = 0;
228 unsigned int rirq = virt_irq_to_real_map[irq];
229
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;
234
235 /* Unmask secondary INTA */
236 mask = 0x80000000;
237 HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700238}
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/* This is called by iSeries_activate_IRQs */
241static unsigned int iSeries_startup_IRQ(unsigned int irq)
242{
243 u32 bus, deviceId, function, mask;
244 const u32 subBus = 0;
245 unsigned int rirq = virt_irq_to_real_map[irq];
246
247 bus = REAL_IRQ_TO_BUS(rirq);
248 function = REAL_IRQ_TO_FUNC(rirq);
249 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
250
251 /* Link the IRQ number to the bridge */
252 HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
253
254 /* Unmask bridge interrupts in the FISR */
255 mask = 0x01010000 << function;
256 HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
257 iSeries_enable_IRQ(irq);
258 return 0;
259}
260
261/*
262 * This is called out of iSeries_fixup to activate interrupt
263 * generation for usable slots
264 */
265void __init iSeries_activate_IRQs()
266{
267 int irq;
268 unsigned long flags;
269
270 for_each_irq (irq) {
271 irq_desc_t *desc = get_irq_desc(irq);
272
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);
277 }
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}
280
281/* this is not called anywhere currently */
282static void iSeries_shutdown_IRQ(unsigned int irq)
283{
284 u32 bus, deviceId, function, mask;
285 const u32 subBus = 0;
286 unsigned int rirq = virt_irq_to_real_map[irq];
287
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;
292
293 /* Invalidate the IRQ number in the bridge */
294 HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
295
296 /* Mask bridge interrupts in the FISR */
297 mask = 0x01010000 << function;
298 HvCallPci_maskFisr(bus, subBus, deviceId, mask);
299}
300
301/*
302 * This will be called by device drivers (via disable_IRQ)
303 * to disable INTA in the bridge interrupt status register.
304 */
305static void iSeries_disable_IRQ(unsigned int irq)
306{
307 u32 bus, deviceId, function, mask;
308 const u32 subBus = 0;
309 unsigned int rirq = virt_irq_to_real_map[irq];
310
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;
315
316 /* Mask secondary INTA */
317 mask = 0x80000000;
318 HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
321/*
Stephen Rothwelld4be4f32005-11-09 16:19:53 +1100322 * This does nothing because there is not enough information
323 * provided to do the EOI HvCall. This is done by XmPciLpEvent.c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 */
325static void iSeries_end_IRQ(unsigned int irq)
326{
327}
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700328
329static 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
336};
337
338/*
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).
342 */
343int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
344 HvSubBusNumber subBusNumber, HvAgentId deviceId)
345{
Stephen Rothwelld9ae2ba2005-11-10 18:11:19 +1100346 int virtirq;
347 unsigned int realirq;
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700348 u8 idsel = (deviceId >> 4);
349 u8 function = deviceId & 7;
350
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700351 realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
Stephen Rothwelld9ae2ba2005-11-10 18:11:19 +1100352 virtirq = virt_irq_create_mapping(realirq);
Stephen Rothwell0c3b4f12005-06-21 17:15:49 -0700353
354 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
355 return virtirq;
356}