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>
39 #include <asm/iseries/hv_types.h>
40 #include <asm/iseries/hv_lp_event.h>
41 #include <asm/iseries/hv_call_xm.h>
42 #include <asm/iseries/it_lp_queue.h>
47 #if defined(CONFIG_SMP)
48 extern void iSeries_smp_message_recv(struct pt_regs *);
52 pe_bus_created = 0, /* PHB has been created */
53 pe_bus_error = 1, /* PHB has failed */
54 pe_bus_failed = 2, /* Msg to Secondary, Primary failed bus */
55 pe_node_failed = 4, /* Multi-adapter bridge has failed */
56 pe_node_recovered = 5, /* Multi-adapter bridge has recovered */
57 pe_bus_recovered = 12, /* PHB has been recovered */
58 pe_unquiese_bus = 18, /* Secondary bus unqiescing */
59 pe_bridge_error = 21, /* Bridge Error */
60 pe_slot_interrupt = 22 /* Slot interrupt */
64 struct HvLpEvent event;
66 u64 __align; /* Align on an 8-byte boundary */
69 HvBusNumber bus_number;
70 HvSubBusNumber sub_bus_number;
74 HvBusNumber bus_number;
75 HvSubBusNumber sub_bus_number;
78 HvBusNumber bus_number;
79 HvSubBusNumber sub_bus_number;
85 static void int_received(struct pci_event *event, struct pt_regs *regs)
88 #ifdef CONFIG_IRQSTACKS
89 struct thread_info *curtp, *irqtp;
92 switch (event->event.xSubtype) {
93 case pe_slot_interrupt:
94 irq = event->event.xCorrelationToken;
95 /* Dispatch the interrupt handlers for this irq */
96 #ifdef CONFIG_IRQSTACKS
97 /* Switch to the irq stack to handle this */
98 curtp = current_thread_info();
99 irqtp = hardirq_ctx[smp_processor_id()];
100 if (curtp != irqtp) {
101 irqtp->task = curtp->task;
103 call___do_IRQ(irq, regs, irqtp);
106 set_bits(irqtp->flags, &curtp->flags);
111 /* Ignore error recovery events for now */
113 printk(KERN_INFO "int_received: system bus %d created\n",
114 event->data.bus.bus_number);
118 printk(KERN_INFO "int_received: system bus %d failed\n",
119 event->data.bus.bus_number);
121 case pe_bus_recovered:
122 case pe_unquiese_bus:
123 printk(KERN_INFO "int_received: system bus %d recovered\n",
124 event->data.bus.bus_number);
127 case pe_bridge_error:
129 "int_received: multi-adapter bridge %d/%d/%d failed\n",
130 event->data.node.bus_number,
131 event->data.node.sub_bus_number,
132 event->data.node.dev_id);
134 case pe_node_recovered:
136 "int_received: multi-adapter bridge %d/%d/%d recovered\n",
137 event->data.node.bus_number,
138 event->data.node.sub_bus_number,
139 event->data.node.dev_id);
143 "int_received: unrecognized event subtype 0x%x\n",
144 event->event.xSubtype);
149 static void pci_event_handler(struct HvLpEvent *event, struct pt_regs *regs)
151 if (event && (event->xType == HvLpEvent_Type_PciIo)) {
152 switch (event->xFlags.xFunction) {
153 case HvLpEvent_Function_Int:
154 int_received((struct pci_event *)event, regs);
156 case HvLpEvent_Function_Ack:
158 "pci_event_handler: unexpected ack received\n");
162 "pci_event_handler: unexpected event function %d\n",
163 (int)event->xFlags.xFunction);
168 "pci_event_handler: Unrecognized PCI event type 0x%x\n",
171 printk(KERN_ERR "pci_event_handler: NULL event received\n");
175 * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
176 * It must be called before the bus walk.
178 void __init iSeries_init_IRQ(void)
180 /* Register PCI event handler and open an event path */
183 ret = HvLpEvent_registerHandler(HvLpEvent_Type_PciIo,
186 ret = HvLpEvent_openPath(HvLpEvent_Type_PciIo, 0);
188 printk(KERN_ERR "iseries_init_IRQ: open event path "
189 "failed with rc 0x%x\n", ret);
191 printk(KERN_ERR "iseries_init_IRQ: register handler "
192 "failed with rc 0x%x\n", ret);
195 #define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff)
196 #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
197 #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
198 #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
201 * This will be called by device drivers (via enable_IRQ)
202 * to enable INTA in the bridge interrupt status register.
204 static void iseries_enable_IRQ(unsigned int irq)
206 u32 bus, dev_id, function, mask;
207 const u32 sub_bus = 0;
208 unsigned int rirq = virt_irq_to_real_map[irq];
210 /* The IRQ has already been locked by the caller */
211 bus = REAL_IRQ_TO_BUS(rirq);
212 function = REAL_IRQ_TO_FUNC(rirq);
213 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
215 /* Unmask secondary INTA */
217 HvCallPci_unmaskInterrupts(bus, sub_bus, dev_id, mask);
220 /* This is called by iseries_activate_IRQs */
221 static unsigned int iseries_startup_IRQ(unsigned int irq)
223 u32 bus, dev_id, function, mask;
224 const u32 sub_bus = 0;
225 unsigned int rirq = virt_irq_to_real_map[irq];
227 bus = REAL_IRQ_TO_BUS(rirq);
228 function = REAL_IRQ_TO_FUNC(rirq);
229 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
231 /* Link the IRQ number to the bridge */
232 HvCallXm_connectBusUnit(bus, sub_bus, dev_id, irq);
234 /* Unmask bridge interrupts in the FISR */
235 mask = 0x01010000 << function;
236 HvCallPci_unmaskFisr(bus, sub_bus, dev_id, mask);
237 iseries_enable_IRQ(irq);
242 * This is called out of iSeries_fixup to activate interrupt
243 * generation for usable slots
245 void __init iSeries_activate_IRQs()
251 irq_desc_t *desc = get_irq_desc(irq);
253 if (desc && desc->handler && desc->handler->startup) {
254 spin_lock_irqsave(&desc->lock, flags);
255 desc->handler->startup(irq);
256 spin_unlock_irqrestore(&desc->lock, flags);
261 /* this is not called anywhere currently */
262 static void iseries_shutdown_IRQ(unsigned int irq)
264 u32 bus, dev_id, function, mask;
265 const u32 sub_bus = 0;
266 unsigned int rirq = virt_irq_to_real_map[irq];
268 /* irq should be locked by the caller */
269 bus = REAL_IRQ_TO_BUS(rirq);
270 function = REAL_IRQ_TO_FUNC(rirq);
271 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
273 /* Invalidate the IRQ number in the bridge */
274 HvCallXm_connectBusUnit(bus, sub_bus, dev_id, 0);
276 /* Mask bridge interrupts in the FISR */
277 mask = 0x01010000 << function;
278 HvCallPci_maskFisr(bus, sub_bus, dev_id, mask);
282 * This will be called by device drivers (via disable_IRQ)
283 * to disable INTA in the bridge interrupt status register.
285 static void iseries_disable_IRQ(unsigned int irq)
287 u32 bus, dev_id, function, mask;
288 const u32 sub_bus = 0;
289 unsigned int rirq = virt_irq_to_real_map[irq];
291 /* The IRQ has already been locked by the caller */
292 bus = REAL_IRQ_TO_BUS(rirq);
293 function = REAL_IRQ_TO_FUNC(rirq);
294 dev_id = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function;
296 /* Mask secondary INTA */
298 HvCallPci_maskInterrupts(bus, sub_bus, dev_id, mask);
301 static void iseries_end_IRQ(unsigned int irq)
303 unsigned int rirq = virt_irq_to_real_map[irq];
305 HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq), REAL_IRQ_TO_SUBBUS(rirq),
306 (REAL_IRQ_TO_IDSEL(rirq) << 4) + REAL_IRQ_TO_FUNC(rirq));
309 static hw_irq_controller iSeries_IRQ_handler = {
310 .typename = "iSeries irq controller",
311 .startup = iseries_startup_IRQ,
312 .shutdown = iseries_shutdown_IRQ,
313 .enable = iseries_enable_IRQ,
314 .disable = iseries_disable_IRQ,
315 .end = iseries_end_IRQ
319 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
320 * It calculates the irq value for the slot.
321 * Note that sub_bus is always 0 (at the moment at least).
323 int __init iSeries_allocate_IRQ(HvBusNumber bus,
324 HvSubBusNumber sub_bus, HvAgentId dev_id)
327 unsigned int realirq;
328 u8 idsel = (dev_id >> 4);
329 u8 function = dev_id & 7;
331 realirq = (((((sub_bus << 8) + (bus - 1)) << 3) + (idsel - 1)) << 3)
333 virtirq = virt_irq_create_mapping(realirq);
335 irq_desc[virtirq].handler = &iSeries_IRQ_handler;
340 * Get the next pending IRQ.
342 int iSeries_get_irq(struct pt_regs *regs)
344 struct paca_struct *lpaca;
348 if (lpaca->lppaca.int_dword.fields.ipi_cnt) {
349 lpaca->lppaca.int_dword.fields.ipi_cnt = 0;
350 iSeries_smp_message_recv(regs);
352 #endif /* CONFIG_SMP */
353 if (hvlpevent_is_pending())
354 process_hvlpevents(regs);
356 /* -2 means ignore this interrupt */