]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - arch/powerpc/platforms/iseries/irq.c
Merge ../linux-2.6
[mirror_ubuntu-zesty-kernel.git] / arch / powerpc / platforms / iseries / irq.c
CommitLineData
0c3b4f1a
SR
1/*
2 * This module supports the iSeries PCI bus interrupt handling
3 * Copyright (C) 20yy <Robert L Holtorf> <IBM Corp>
89ef68f0 4 * Copyright (C) 2004-2005 IBM Corporation
0c3b4f1a
SR
5 *
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 */
89ef68f0 26#include <linux/config.h>
1da177e4
LT
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>
1da177e4
LT
35#include <linux/irq.h>
36#include <linux/spinlock.h>
1da177e4 37
1ec65d76 38#include <asm/iseries/hv_types.h>
e45423ea 39#include <asm/iseries/hv_lp_event.h>
8021b8a7 40#include <asm/iseries/hv_call_xm.h>
b08567cb
SR
41
42#include "irq.h"
c6d2ea92 43#include "call_pci.h"
1da177e4
LT
44
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
89ef68f0
SR
52static 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;
106
107 ++Pci_Interrupt_Count;
89ef68f0
SR
108
109 switch (eventParm->hvLpEvent.xSubtype) {
110 case XmPciLpEvent_SlotInterrupt:
111 irq = eventParm->hvLpEvent.xCorrelationToken;
112 /* Dispatch the interrupt handlers for this irq */
113 ppc_irq_dispatch_handler(regsParm, irq);
114 HvCallPci_eoi(eventParm->eventData.slotInterrupt.busNumber,
115 eventParm->eventData.slotInterrupt.subBusNumber,
116 eventParm->eventData.slotInterrupt.deviceId);
117 break;
118 /* Ignore error recovery events for now */
119 case XmPciLpEvent_BusCreated:
7f74e79f 120 printk(KERN_INFO "intReceived: system bus %d created\n",
89ef68f0
SR
121 eventParm->eventData.busCreated.busNumber);
122 break;
123 case XmPciLpEvent_BusError:
124 case XmPciLpEvent_BusFailed:
7f74e79f 125 printk(KERN_INFO "intReceived: system bus %d failed\n",
89ef68f0
SR
126 eventParm->eventData.busFailed.busNumber);
127 break;
128 case XmPciLpEvent_BusRecovered:
129 case XmPciLpEvent_UnQuiesceBus:
7f74e79f 130 printk(KERN_INFO "intReceived: system bus %d recovered\n",
89ef68f0
SR
131 eventParm->eventData.busRecovered.busNumber);
132 break;
133 case XmPciLpEvent_NodeFailed:
134 case XmPciLpEvent_BridgeError:
135 printk(KERN_INFO
7f74e79f 136 "intReceived: multi-adapter bridge %d/%d/%d failed\n",
89ef68f0
SR
137 eventParm->eventData.nodeFailed.busNumber,
138 eventParm->eventData.nodeFailed.subBusNumber,
139 eventParm->eventData.nodeFailed.deviceId);
140 break;
141 case XmPciLpEvent_NodeRecovered:
142 printk(KERN_INFO
7f74e79f 143 "intReceived: multi-adapter bridge %d/%d/%d recovered\n",
89ef68f0
SR
144 eventParm->eventData.nodeRecovered.busNumber,
145 eventParm->eventData.nodeRecovered.subBusNumber,
146 eventParm->eventData.nodeRecovered.deviceId);
147 break;
148 default:
149 printk(KERN_ERR
7f74e79f 150 "intReceived: unrecognized event subtype 0x%x\n",
89ef68f0
SR
151 eventParm->hvLpEvent.xSubtype);
152 break;
153 }
154}
155
156static void XmPciLpEvent_handler(struct HvLpEvent *eventParm,
157 struct pt_regs *regsParm)
158{
159#ifdef CONFIG_PCI
89ef68f0
SR
160 ++Pci_Event_Count;
161
162 if (eventParm && (eventParm->xType == HvLpEvent_Type_PciIo)) {
163 switch (eventParm->xFlags.xFunction) {
164 case HvLpEvent_Function_Int:
165 intReceived((struct XmPciLpEvent *)eventParm, regsParm);
166 break;
167 case HvLpEvent_Function_Ack:
168 printk(KERN_ERR
7f74e79f 169 "XmPciLpEvent_handler: unexpected ack received\n");
89ef68f0
SR
170 break;
171 default:
172 printk(KERN_ERR
7f74e79f 173 "XmPciLpEvent_handler: unexpected event function %d\n",
89ef68f0
SR
174 (int)eventParm->xFlags.xFunction);
175 break;
176 }
177 } else if (eventParm)
178 printk(KERN_ERR
7f74e79f 179 "XmPciLpEvent_handler: Unrecognized PCI event type 0x%x\n",
89ef68f0
SR
180 (int)eventParm->xType);
181 else
7f74e79f 182 printk(KERN_ERR "XmPciLpEvent_handler: NULL event received\n");
89ef68f0
SR
183#endif
184}
185
7f74e79f
SR
186/*
187 * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
188 * It must be called before the bus walk.
189 */
190void __init iSeries_init_IRQ(void)
89ef68f0 191{
7f74e79f 192 /* Register PCI event handler and open an event path */
89ef68f0
SR
193 int xRc;
194
89ef68f0
SR
195 xRc = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
196 &XmPciLpEvent_handler);
197 if (xRc == 0) {
198 xRc = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
199 if (xRc != 0)
7f74e79f 200 printk(KERN_ERR "iSeries_init_IRQ: open event path "
89ef68f0
SR
201 "failed with rc 0x%x\n", xRc);
202 } else
7f74e79f 203 printk(KERN_ERR "iSeries_init_IRQ: register handler "
89ef68f0 204 "failed with rc 0x%x\n", xRc);
1da177e4
LT
205}
206
0c3b4f1a
SR
207#define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
208#define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
209#define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
210
1da177e4 211/*
0c3b4f1a
SR
212 * This will be called by device drivers (via enable_IRQ)
213 * to enable INTA in the bridge interrupt status register.
1da177e4 214 */
0c3b4f1a 215static void iSeries_enable_IRQ(unsigned int irq)
1da177e4 216{
0c3b4f1a
SR
217 u32 bus, deviceId, function, mask;
218 const u32 subBus = 0;
219 unsigned int rirq = virt_irq_to_real_map[irq];
1da177e4 220
0c3b4f1a
SR
221 /* The IRQ has already been locked by the caller */
222 bus = REAL_IRQ_TO_BUS(rirq);
223 function = REAL_IRQ_TO_FUNC(rirq);
224 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
1da177e4 225
0c3b4f1a
SR
226 /* Unmask secondary INTA */
227 mask = 0x80000000;
228 HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
1da177e4
LT
229}
230
1da177e4
LT
231/* This is called by iSeries_activate_IRQs */
232static unsigned int iSeries_startup_IRQ(unsigned int irq)
233{
234 u32 bus, deviceId, function, mask;
235 const u32 subBus = 0;
236 unsigned int rirq = virt_irq_to_real_map[irq];
237
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 /* Link the IRQ number to the bridge */
243 HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
244
245 /* Unmask bridge interrupts in the FISR */
246 mask = 0x01010000 << function;
247 HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
248 iSeries_enable_IRQ(irq);
249 return 0;
250}
251
252/*
253 * This is called out of iSeries_fixup to activate interrupt
254 * generation for usable slots
255 */
256void __init iSeries_activate_IRQs()
257{
258 int irq;
259 unsigned long flags;
260
261 for_each_irq (irq) {
262 irq_desc_t *desc = get_irq_desc(irq);
263
264 if (desc && desc->handler && desc->handler->startup) {
265 spin_lock_irqsave(&desc->lock, flags);
266 desc->handler->startup(irq);
267 spin_unlock_irqrestore(&desc->lock, flags);
268 }
0c3b4f1a 269 }
1da177e4
LT
270}
271
272/* this is not called anywhere currently */
273static void iSeries_shutdown_IRQ(unsigned int irq)
274{
275 u32 bus, deviceId, function, mask;
276 const u32 subBus = 0;
277 unsigned int rirq = virt_irq_to_real_map[irq];
278
279 /* irq should be locked by the caller */
280 bus = REAL_IRQ_TO_BUS(rirq);
281 function = REAL_IRQ_TO_FUNC(rirq);
282 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
283
284 /* Invalidate the IRQ number in the bridge */
285 HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
286
287 /* Mask bridge interrupts in the FISR */
288 mask = 0x01010000 << function;
289 HvCallPci_maskFisr(bus, subBus, deviceId, mask);
290}
291
292/*
293 * This will be called by device drivers (via disable_IRQ)
294 * to disable INTA in the bridge interrupt status register.
295 */
296static void iSeries_disable_IRQ(unsigned int irq)
297{
298 u32 bus, deviceId, function, mask;
299 const u32 subBus = 0;
300 unsigned int rirq = virt_irq_to_real_map[irq];
301
302 /* The IRQ has already been locked by the caller */
303 bus = REAL_IRQ_TO_BUS(rirq);
304 function = REAL_IRQ_TO_FUNC(rirq);
305 deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
306
307 /* Mask secondary INTA */
308 mask = 0x80000000;
309 HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
1da177e4
LT
310}
311
312/*
313 * Need to define this so ppc_irq_dispatch_handler will NOT call
314 * enable_IRQ at the end of interrupt handling. However, this does
315 * nothing because there is not enough information provided to do
316 * the EOI HvCall. This is done by XmPciLpEvent.c
317 */
318static void iSeries_end_IRQ(unsigned int irq)
319{
320}
0c3b4f1a
SR
321
322static hw_irq_controller iSeries_IRQ_handler = {
323 .typename = "iSeries irq controller",
324 .startup = iSeries_startup_IRQ,
325 .shutdown = iSeries_shutdown_IRQ,
326 .enable = iSeries_enable_IRQ,
327 .disable = iSeries_disable_IRQ,
328 .end = iSeries_end_IRQ
329};
330
331/*
332 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
333 * It calculates the irq value for the slot.
334 * Note that subBusNumber is always 0 (at the moment at least).
335 */
336int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
337 HvSubBusNumber subBusNumber, HvAgentId deviceId)
338{
339 unsigned int realirq, virtirq;
340 u8 idsel = (deviceId >> 4);
341 u8 function = deviceId & 7;
342
343 virtirq = next_virtual_irq++;
344 realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function;
345 virt_irq_to_real_map[virtirq] = realirq;
346
347 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
348 return virtirq;
349}
ba293fff
ME
350
351int virt_irq_create_mapping(unsigned int real_irq)
352{
353 BUG(); /* Don't call this on iSeries, yet */
354
355 return 0;
356}
357
358void virt_irq_init(void)
359{
360 return;
361}