1 /************************************************************************/
2 /* This module supports the iSeries PCI bus interrupt handling */
3 /* Copyright (C) 20yy <Robert L Holtorf> <IBM Corp> */
5 /* This program is free software; you can redistribute it and/or modify */
6 /* it under the terms of the GNU General Public License as published by */
7 /* the Free Software Foundation; either version 2 of the License, or */
8 /* (at your option) any later version. */
10 /* This program is distributed in the hope that it will be useful, */
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13 /* GNU General Public License for more details. */
15 /* You should have received a copy of the GNU General Public License */
16 /* along with this program; if not, write to the: */
17 /* Free Software Foundation, Inc., */
18 /* 59 Temple Place, Suite 330, */
19 /* Boston, MA 02111-1307 USA */
20 /************************************************************************/
21 /* Change Activity: */
22 /* Created, December 13, 2000 by Wayne Holm */
23 /* End Change Activity */
24 /************************************************************************/
25 #include <linux/pci.h>
26 #include <linux/init.h>
27 #include <linux/threads.h>
28 #include <linux/smp.h>
29 #include <linux/param.h>
30 #include <linux/string.h>
31 #include <linux/bootmem.h>
32 #include <linux/ide.h>
34 #include <linux/irq.h>
35 #include <linux/spinlock.h>
36 #include <asm/ppcdebug.h>
38 #include <asm/iSeries/HvCallPci.h>
39 #include <asm/iSeries/HvCallXm.h>
40 #include <asm/iSeries/iSeries_irq.h>
41 #include <asm/iSeries/XmPciLpEvent.h>
43 static unsigned int iSeries_startup_IRQ(unsigned int irq);
44 static void iSeries_shutdown_IRQ(unsigned int irq);
45 static void iSeries_enable_IRQ(unsigned int irq);
46 static void iSeries_disable_IRQ(unsigned int irq);
47 static void iSeries_end_IRQ(unsigned int irq);
49 static hw_irq_controller iSeries_IRQ_handler = {
50 .typename = "iSeries irq controller",
51 .startup = iSeries_startup_IRQ,
52 .shutdown = iSeries_shutdown_IRQ,
53 .enable = iSeries_enable_IRQ,
54 .disable = iSeries_disable_IRQ,
55 .end = iSeries_end_IRQ
58 void iSeries_init_irq_desc(irq_desc_t *desc)
60 desc->handler = &iSeries_IRQ_handler;
63 /* This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c */
64 void __init iSeries_init_IRQ(void)
66 /* Register PCI event handler and open an event path */
67 PPCDBG(PPCDBG_BUSWALK,
68 "Register PCI event handler and open an event path\n");
74 * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot
75 * It calculates the irq value for the slot.
76 * Note that subBusNumber is always 0 (at the moment at least).
78 int __init iSeries_allocate_IRQ(HvBusNumber busNumber,
79 HvSubBusNumber subBusNumber, HvAgentId deviceId)
81 u8 idsel = (deviceId >> 4);
82 u8 function = deviceId & 7;
84 return ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function + 1;
87 #define IRQ_TO_BUS(irq) (((((irq) - 1) >> 6) & 0xff) + 1)
88 #define IRQ_TO_IDSEL(irq) (((((irq) - 1) >> 3) & 7) + 1)
89 #define IRQ_TO_FUNC(irq) (((irq) - 1) & 7)
92 /* This is called by iSeries_activate_IRQs */
93 static unsigned int iSeries_startup_IRQ(unsigned int irq)
95 u32 bus, deviceId, function, mask;
98 bus = IRQ_TO_BUS(irq);
99 function = IRQ_TO_FUNC(irq);
100 deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
102 /* Link the IRQ number to the bridge */
103 HvCallXm_connectBusUnit(bus, subBus, deviceId, irq);
105 /* Unmask bridge interrupts in the FISR */
106 mask = 0x01010000 << function;
107 HvCallPci_unmaskFisr(bus, subBus, deviceId, mask);
108 PPCDBG(PPCDBG_BUSWALK, "iSeries_activate_IRQ 0x%02X.%02X.%02X Irq:0x%02X\n",
109 bus, subBus, deviceId, irq);
114 * This is called out of iSeries_fixup to activate interrupt
115 * generation for usable slots
117 void __init iSeries_activate_IRQs()
123 irq_desc_t *desc = get_irq_desc(irq);
125 if (desc && desc->handler && desc->handler->startup) {
126 spin_lock_irqsave(&desc->lock, flags);
127 desc->handler->startup(irq);
128 spin_unlock_irqrestore(&desc->lock, flags);
133 /* this is not called anywhere currently */
134 static void iSeries_shutdown_IRQ(unsigned int irq)
136 u32 bus, deviceId, function, mask;
137 const u32 subBus = 0;
139 /* irq should be locked by the caller */
140 bus = IRQ_TO_BUS(irq);
141 function = IRQ_TO_FUNC(irq);
142 deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
144 /* Invalidate the IRQ number in the bridge */
145 HvCallXm_connectBusUnit(bus, subBus, deviceId, 0);
147 /* Mask bridge interrupts in the FISR */
148 mask = 0x01010000 << function;
149 HvCallPci_maskFisr(bus, subBus, deviceId, mask);
153 * This will be called by device drivers (via disable_IRQ)
154 * to disable INTA in the bridge interrupt status register.
156 static void iSeries_disable_IRQ(unsigned int irq)
158 u32 bus, deviceId, function, mask;
159 const u32 subBus = 0;
161 /* The IRQ has already been locked by the caller */
162 bus = IRQ_TO_BUS(irq);
163 function = IRQ_TO_FUNC(irq);
164 deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
166 /* Mask secondary INTA */
168 HvCallPci_maskInterrupts(bus, subBus, deviceId, mask);
169 PPCDBG(PPCDBG_BUSWALK, "iSeries_disable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
170 bus, subBus, deviceId, irq);
174 * This will be called by device drivers (via enable_IRQ)
175 * to enable INTA in the bridge interrupt status register.
177 static void iSeries_enable_IRQ(unsigned int irq)
179 u32 bus, deviceId, function, mask;
180 const u32 subBus = 0;
182 /* The IRQ has already been locked by the caller */
183 bus = IRQ_TO_BUS(irq);
184 function = IRQ_TO_FUNC(irq);
185 deviceId = (IRQ_TO_IDSEL(irq) << 4) + function;
187 /* Unmask secondary INTA */
189 HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask);
190 PPCDBG(PPCDBG_BUSWALK, "iSeries_enable_IRQ 0x%02X.%02X.%02X 0x%04X\n",
191 bus, subBus, deviceId, irq);
195 * Need to define this so ppc_irq_dispatch_handler will NOT call
196 * enable_IRQ at the end of interrupt handling. However, this does
197 * nothing because there is not enough information provided to do
198 * the EOI HvCall. This is done by XmPciLpEvent.c
200 static void iSeries_end_IRQ(unsigned int irq)