Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * This module supports the iSeries PCI bus interrupt handling |
| 3 | * Copyright (C) 20yy <Robert L Holtorf> <IBM Corp> |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| 33 | |
| 34 | #include <linux/irq.h> |
| 35 | #include <linux/spinlock.h> |
| 36 | #include <asm/ppcdebug.h> |
| 37 | |
| 38 | #include <asm/iSeries/HvCallPci.h> |
| 39 | #include <asm/iSeries/HvCallXm.h> |
| 40 | #include <asm/iSeries/iSeries_irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* This maps virtual irq numbers to real irqs */ |
| 43 | unsigned int virt_irq_to_real_map[NR_IRQS]; |
| 44 | |
| 45 | /* The next available virtual irq number */ |
| 46 | /* Note: the pcnet32 driver assumes irq numbers < 2 aren't valid. :( */ |
| 47 | static int next_virtual_irq = 2; |
| 48 | |
| 49 | /* This is called by init_IRQ. set in ppc_md.init_IRQ by iSeries_setup.c */ |
| 50 | void __init iSeries_init_IRQ(void) |
| 51 | { |
| 52 | /* Register PCI event handler and open an event path */ |
| 53 | XmPciLpEvent_init(); |
| 54 | } |
| 55 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #define REAL_IRQ_TO_BUS(irq) ((((irq) >> 6) & 0xff) + 1) |
| 57 | #define REAL_IRQ_TO_IDSEL(irq) ((((irq) >> 3) & 7) + 1) |
| 58 | #define REAL_IRQ_TO_FUNC(irq) ((irq) & 7) |
| 59 | |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame^] | 60 | /* |
| 61 | * This will be called by device drivers (via enable_IRQ) |
| 62 | * to enable INTA in the bridge interrupt status register. |
| 63 | */ |
| 64 | static void iSeries_enable_IRQ(unsigned int irq) |
| 65 | { |
| 66 | u32 bus, deviceId, function, mask; |
| 67 | const u32 subBus = 0; |
| 68 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 69 | |
| 70 | /* The IRQ has already been locked by the caller */ |
| 71 | bus = REAL_IRQ_TO_BUS(rirq); |
| 72 | function = REAL_IRQ_TO_FUNC(rirq); |
| 73 | deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
| 74 | |
| 75 | /* Unmask secondary INTA */ |
| 76 | mask = 0x80000000; |
| 77 | HvCallPci_unmaskInterrupts(bus, subBus, deviceId, mask); |
| 78 | PPCDBG(PPCDBG_BUSWALK, "iSeries_enable_IRQ 0x%02X.%02X.%02X 0x%04X\n", |
| 79 | bus, subBus, deviceId, irq); |
| 80 | } |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* This is called by iSeries_activate_IRQs */ |
| 83 | static unsigned int iSeries_startup_IRQ(unsigned int irq) |
| 84 | { |
| 85 | u32 bus, deviceId, function, mask; |
| 86 | const u32 subBus = 0; |
| 87 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 88 | |
| 89 | bus = REAL_IRQ_TO_BUS(rirq); |
| 90 | function = REAL_IRQ_TO_FUNC(rirq); |
| 91 | deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
| 92 | |
| 93 | /* Link the IRQ number to the bridge */ |
| 94 | HvCallXm_connectBusUnit(bus, subBus, deviceId, irq); |
| 95 | |
| 96 | /* Unmask bridge interrupts in the FISR */ |
| 97 | mask = 0x01010000 << function; |
| 98 | HvCallPci_unmaskFisr(bus, subBus, deviceId, mask); |
| 99 | iSeries_enable_IRQ(irq); |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * This is called out of iSeries_fixup to activate interrupt |
| 105 | * generation for usable slots |
| 106 | */ |
| 107 | void __init iSeries_activate_IRQs() |
| 108 | { |
| 109 | int irq; |
| 110 | unsigned long flags; |
| 111 | |
| 112 | for_each_irq (irq) { |
| 113 | irq_desc_t *desc = get_irq_desc(irq); |
| 114 | |
| 115 | if (desc && desc->handler && desc->handler->startup) { |
| 116 | spin_lock_irqsave(&desc->lock, flags); |
| 117 | desc->handler->startup(irq); |
| 118 | spin_unlock_irqrestore(&desc->lock, flags); |
| 119 | } |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame^] | 120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /* this is not called anywhere currently */ |
| 124 | static void iSeries_shutdown_IRQ(unsigned int irq) |
| 125 | { |
| 126 | u32 bus, deviceId, function, mask; |
| 127 | const u32 subBus = 0; |
| 128 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 129 | |
| 130 | /* irq should be locked by the caller */ |
| 131 | bus = REAL_IRQ_TO_BUS(rirq); |
| 132 | function = REAL_IRQ_TO_FUNC(rirq); |
| 133 | deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
| 134 | |
| 135 | /* Invalidate the IRQ number in the bridge */ |
| 136 | HvCallXm_connectBusUnit(bus, subBus, deviceId, 0); |
| 137 | |
| 138 | /* Mask bridge interrupts in the FISR */ |
| 139 | mask = 0x01010000 << function; |
| 140 | HvCallPci_maskFisr(bus, subBus, deviceId, mask); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * This will be called by device drivers (via disable_IRQ) |
| 145 | * to disable INTA in the bridge interrupt status register. |
| 146 | */ |
| 147 | static void iSeries_disable_IRQ(unsigned int irq) |
| 148 | { |
| 149 | u32 bus, deviceId, function, mask; |
| 150 | const u32 subBus = 0; |
| 151 | unsigned int rirq = virt_irq_to_real_map[irq]; |
| 152 | |
| 153 | /* The IRQ has already been locked by the caller */ |
| 154 | bus = REAL_IRQ_TO_BUS(rirq); |
| 155 | function = REAL_IRQ_TO_FUNC(rirq); |
| 156 | deviceId = (REAL_IRQ_TO_IDSEL(rirq) << 4) + function; |
| 157 | |
| 158 | /* Mask secondary INTA */ |
| 159 | mask = 0x80000000; |
| 160 | HvCallPci_maskInterrupts(bus, subBus, deviceId, mask); |
| 161 | PPCDBG(PPCDBG_BUSWALK, "iSeries_disable_IRQ 0x%02X.%02X.%02X 0x%04X\n", |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame^] | 162 | bus, subBus, deviceId, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Need to define this so ppc_irq_dispatch_handler will NOT call |
| 167 | * enable_IRQ at the end of interrupt handling. However, this does |
| 168 | * nothing because there is not enough information provided to do |
| 169 | * the EOI HvCall. This is done by XmPciLpEvent.c |
| 170 | */ |
| 171 | static void iSeries_end_IRQ(unsigned int irq) |
| 172 | { |
| 173 | } |
Stephen Rothwell | 0c3b4f1 | 2005-06-21 17:15:49 -0700 | [diff] [blame^] | 174 | |
| 175 | static hw_irq_controller iSeries_IRQ_handler = { |
| 176 | .typename = "iSeries irq controller", |
| 177 | .startup = iSeries_startup_IRQ, |
| 178 | .shutdown = iSeries_shutdown_IRQ, |
| 179 | .enable = iSeries_enable_IRQ, |
| 180 | .disable = iSeries_disable_IRQ, |
| 181 | .end = iSeries_end_IRQ |
| 182 | }; |
| 183 | |
| 184 | /* |
| 185 | * This is called out of iSeries_scan_slot to allocate an IRQ for an EADS slot |
| 186 | * It calculates the irq value for the slot. |
| 187 | * Note that subBusNumber is always 0 (at the moment at least). |
| 188 | */ |
| 189 | int __init iSeries_allocate_IRQ(HvBusNumber busNumber, |
| 190 | HvSubBusNumber subBusNumber, HvAgentId deviceId) |
| 191 | { |
| 192 | unsigned int realirq, virtirq; |
| 193 | u8 idsel = (deviceId >> 4); |
| 194 | u8 function = deviceId & 7; |
| 195 | |
| 196 | virtirq = next_virtual_irq++; |
| 197 | realirq = ((busNumber - 1) << 6) + ((idsel - 1) << 3) + function; |
| 198 | virt_irq_to_real_map[virtirq] = realirq; |
| 199 | |
| 200 | irq_desc[virtirq].handler = &iSeries_IRQ_handler; |
| 201 | return virtirq; |
| 202 | } |