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/pci.h>
27 #include <linux/init.h>
28 #include <linux/threads.h>
29 #include <linux/smp.h>
30 #include <linux/param.h>
31 #include <linux/string.h>
32 #include <linux/bootmem.h>
33 #include <linux/irq.h>
34 #include <linux/spinlock.h>
37 #include <asm/iseries/hv_types.h>
38 #include <asm/iseries/hv_lp_event.h>
39 #include <asm/iseries/hv_call_xm.h>
40 #include <asm/iseries/it_lp_queue.h>
50 pe_bus_created
= 0, /* PHB has been created */
51 pe_bus_error
= 1, /* PHB has failed */
52 pe_bus_failed
= 2, /* Msg to Secondary, Primary failed bus */
53 pe_node_failed
= 4, /* Multi-adapter bridge has failed */
54 pe_node_recovered
= 5, /* Multi-adapter bridge has recovered */
55 pe_bus_recovered
= 12, /* PHB has been recovered */
56 pe_unquiese_bus
= 18, /* Secondary bus unqiescing */
57 pe_bridge_error
= 21, /* Bridge Error */
58 pe_slot_interrupt
= 22 /* Slot interrupt */
62 struct HvLpEvent event
;
64 u64 __align
; /* Align on an 8-byte boundary */
67 HvBusNumber bus_number
;
68 HvSubBusNumber sub_bus_number
;
72 HvBusNumber bus_number
;
73 HvSubBusNumber sub_bus_number
;
76 HvBusNumber bus_number
;
77 HvSubBusNumber sub_bus_number
;
83 static DEFINE_SPINLOCK(pending_irqs_lock
);
84 static int num_pending_irqs
;
85 static int pending_irqs
[NR_IRQS
];
87 static void int_received(struct pci_event
*event
)
91 switch (event
->event
.xSubtype
) {
92 case pe_slot_interrupt
:
93 irq
= event
->event
.xCorrelationToken
;
95 spin_lock(&pending_irqs_lock
);
98 spin_unlock(&pending_irqs_lock
);
100 printk(KERN_WARNING
"int_received: bad irq number %d\n",
102 HvCallPci_eoi(event
->data
.slot
.bus_number
,
103 event
->data
.slot
.sub_bus_number
,
104 event
->data
.slot
.dev_id
);
107 /* Ignore error recovery events for now */
109 printk(KERN_INFO
"int_received: system bus %d created\n",
110 event
->data
.bus
.bus_number
);
114 printk(KERN_INFO
"int_received: system bus %d failed\n",
115 event
->data
.bus
.bus_number
);
117 case pe_bus_recovered
:
118 case pe_unquiese_bus
:
119 printk(KERN_INFO
"int_received: system bus %d recovered\n",
120 event
->data
.bus
.bus_number
);
123 case pe_bridge_error
:
125 "int_received: multi-adapter bridge %d/%d/%d failed\n",
126 event
->data
.node
.bus_number
,
127 event
->data
.node
.sub_bus_number
,
128 event
->data
.node
.dev_id
);
130 case pe_node_recovered
:
132 "int_received: multi-adapter bridge %d/%d/%d recovered\n",
133 event
->data
.node
.bus_number
,
134 event
->data
.node
.sub_bus_number
,
135 event
->data
.node
.dev_id
);
139 "int_received: unrecognized event subtype 0x%x\n",
140 event
->event
.xSubtype
);
145 static void pci_event_handler(struct HvLpEvent
*event
)
147 if (event
&& (event
->xType
== HvLpEvent_Type_PciIo
)) {
148 if (hvlpevent_is_int(event
))
149 int_received((struct pci_event
*)event
);
152 "pci_event_handler: unexpected ack received\n");
155 "pci_event_handler: Unrecognized PCI event type 0x%x\n",
158 printk(KERN_ERR
"pci_event_handler: NULL event received\n");
161 #define REAL_IRQ_TO_SUBBUS(irq) (((irq) >> 14) & 0xff)
162 #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1)
163 #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1)
164 #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7)
167 * This will be called by device drivers (via enable_IRQ)
168 * to enable INTA in the bridge interrupt status register.
170 static void iseries_enable_IRQ(unsigned int irq
)
172 u32 bus
, dev_id
, function
, mask
;
173 const u32 sub_bus
= 0;
174 unsigned int rirq
= (unsigned int)irq_map
[irq
].hwirq
;
176 /* The IRQ has already been locked by the caller */
177 bus
= REAL_IRQ_TO_BUS(rirq
);
178 function
= REAL_IRQ_TO_FUNC(rirq
);
179 dev_id
= (REAL_IRQ_TO_IDSEL(rirq
) << 4) + function
;
181 /* Unmask secondary INTA */
183 HvCallPci_unmaskInterrupts(bus
, sub_bus
, dev_id
, mask
);
186 /* This is called by iseries_activate_IRQs */
187 static unsigned int iseries_startup_IRQ(unsigned int irq
)
189 u32 bus
, dev_id
, function
, mask
;
190 const u32 sub_bus
= 0;
191 unsigned int rirq
= (unsigned int)irq_map
[irq
].hwirq
;
193 bus
= REAL_IRQ_TO_BUS(rirq
);
194 function
= REAL_IRQ_TO_FUNC(rirq
);
195 dev_id
= (REAL_IRQ_TO_IDSEL(rirq
) << 4) + function
;
197 /* Link the IRQ number to the bridge */
198 HvCallXm_connectBusUnit(bus
, sub_bus
, dev_id
, irq
);
200 /* Unmask bridge interrupts in the FISR */
201 mask
= 0x01010000 << function
;
202 HvCallPci_unmaskFisr(bus
, sub_bus
, dev_id
, mask
);
203 iseries_enable_IRQ(irq
);
208 * This is called out of iSeries_fixup to activate interrupt
209 * generation for usable slots
211 void __init
iSeries_activate_IRQs()
217 irq_desc_t
*desc
= get_irq_desc(irq
);
219 if (desc
&& desc
->chip
&& desc
->chip
->startup
) {
220 spin_lock_irqsave(&desc
->lock
, flags
);
221 desc
->chip
->startup(irq
);
222 spin_unlock_irqrestore(&desc
->lock
, flags
);
227 /* this is not called anywhere currently */
228 static void iseries_shutdown_IRQ(unsigned int irq
)
230 u32 bus
, dev_id
, function
, mask
;
231 const u32 sub_bus
= 0;
232 unsigned int rirq
= (unsigned int)irq_map
[irq
].hwirq
;
234 /* irq should be locked by the caller */
235 bus
= REAL_IRQ_TO_BUS(rirq
);
236 function
= REAL_IRQ_TO_FUNC(rirq
);
237 dev_id
= (REAL_IRQ_TO_IDSEL(rirq
) << 4) + function
;
239 /* Invalidate the IRQ number in the bridge */
240 HvCallXm_connectBusUnit(bus
, sub_bus
, dev_id
, 0);
242 /* Mask bridge interrupts in the FISR */
243 mask
= 0x01010000 << function
;
244 HvCallPci_maskFisr(bus
, sub_bus
, dev_id
, mask
);
248 * This will be called by device drivers (via disable_IRQ)
249 * to disable INTA in the bridge interrupt status register.
251 static void iseries_disable_IRQ(unsigned int irq
)
253 u32 bus
, dev_id
, function
, mask
;
254 const u32 sub_bus
= 0;
255 unsigned int rirq
= (unsigned int)irq_map
[irq
].hwirq
;
257 /* The IRQ has already been locked by the caller */
258 bus
= REAL_IRQ_TO_BUS(rirq
);
259 function
= REAL_IRQ_TO_FUNC(rirq
);
260 dev_id
= (REAL_IRQ_TO_IDSEL(rirq
) << 4) + function
;
262 /* Mask secondary INTA */
264 HvCallPci_maskInterrupts(bus
, sub_bus
, dev_id
, mask
);
267 static void iseries_end_IRQ(unsigned int irq
)
269 unsigned int rirq
= (unsigned int)irq_map
[irq
].hwirq
;
271 HvCallPci_eoi(REAL_IRQ_TO_BUS(rirq
), REAL_IRQ_TO_SUBBUS(rirq
),
272 (REAL_IRQ_TO_IDSEL(rirq
) << 4) + REAL_IRQ_TO_FUNC(rirq
));
275 static struct irq_chip iseries_pic
= {
276 .typename
= "iSeries irq controller",
277 .startup
= iseries_startup_IRQ
,
278 .shutdown
= iseries_shutdown_IRQ
,
279 .unmask
= iseries_enable_IRQ
,
280 .mask
= iseries_disable_IRQ
,
281 .eoi
= iseries_end_IRQ
285 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
286 * It calculates the irq value for the slot.
287 * Note that sub_bus is always 0 (at the moment at least).
289 int __init
iSeries_allocate_IRQ(HvBusNumber bus
,
290 HvSubBusNumber sub_bus
, u32 bsubbus
)
292 unsigned int realirq
;
293 u8 idsel
= ISERIES_GET_DEVICE_FROM_SUBBUS(bsubbus
);
294 u8 function
= ISERIES_GET_FUNCTION_FROM_SUBBUS(bsubbus
);
296 realirq
= (((((sub_bus
<< 8) + (bus
- 1)) << 3) + (idsel
- 1)) << 3)
299 return irq_create_mapping(NULL
, realirq
);
302 #endif /* CONFIG_PCI */
305 * Get the next pending IRQ.
307 unsigned int iSeries_get_irq(void)
309 int irq
= NO_IRQ_IGNORE
;
312 if (get_lppaca()->int_dword
.fields
.ipi_cnt
) {
313 get_lppaca()->int_dword
.fields
.ipi_cnt
= 0;
314 iSeries_smp_message_recv();
316 #endif /* CONFIG_SMP */
317 if (hvlpevent_is_pending())
318 process_hvlpevents();
321 if (num_pending_irqs
) {
322 spin_lock(&pending_irqs_lock
);
323 for (irq
= 0; irq
< NR_IRQS
; irq
++) {
324 if (pending_irqs
[irq
]) {
330 spin_unlock(&pending_irqs_lock
);
341 static int iseries_irq_host_map(struct irq_host
*h
, unsigned int virq
,
344 set_irq_chip_and_handler(virq
, &iseries_pic
, handle_fasteoi_irq
);
349 static int iseries_irq_host_match(struct irq_host
*h
, struct device_node
*np
)
355 static struct irq_host_ops iseries_irq_host_ops
= {
356 .map
= iseries_irq_host_map
,
357 .match
= iseries_irq_host_match
,
361 * This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c
362 * It must be called before the bus walk.
364 void __init
iSeries_init_IRQ(void)
366 /* Register PCI event handler and open an event path */
367 struct irq_host
*host
;
371 * The Hypervisor only allows us up to 256 interrupt
372 * sources (the irq number is passed in a u8).
374 irq_set_virq_count(256);
376 /* Create irq host. No need for a revmap since HV will give us
377 * back our virtual irq number
379 host
= irq_alloc_host(NULL
, IRQ_HOST_MAP_NOMAP
, 0,
380 &iseries_irq_host_ops
, 0);
381 BUG_ON(host
== NULL
);
382 irq_set_default_host(host
);
384 ret
= HvLpEvent_registerHandler(HvLpEvent_Type_PciIo
,
387 ret
= HvLpEvent_openPath(HvLpEvent_Type_PciIo
, 0);
389 printk(KERN_ERR
"iseries_init_IRQ: open event path "
390 "failed with rc 0x%x\n", ret
);
392 printk(KERN_ERR
"iseries_init_IRQ: register handler "
393 "failed with rc 0x%x\n", ret
);
396 #endif /* CONFIG_PCI */