Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Platform dependent support for SGI SN |
| 3 | * |
| 4 | * This file is subject to the terms and conditions of the GNU General Public |
| 5 | * License. See the file "COPYING" in the main directory of this archive |
| 6 | * for more details. |
| 7 | * |
John Keller | ff740fb | 2008-12-08 11:44:11 -0600 | [diff] [blame] | 8 | * Copyright (c) 2000-2008 Silicon Graphics, Inc. All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/irq.h> |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 12 | #include <linux/spinlock.h> |
Jes Sorensen | 2fcc3db | 2006-02-02 05:15:51 -0500 | [diff] [blame] | 13 | #include <linux/init.h> |
Franck Bui-Huu | 8252474 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 14 | #include <linux/rculist.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/sn/addrs.h> |
| 17 | #include <asm/sn/arch.h> |
Prarit Bhargava | c13cf37 | 2005-07-06 15:26:51 -0700 | [diff] [blame] | 18 | #include <asm/sn/intr.h> |
| 19 | #include <asm/sn/pcibr_provider.h> |
Mark Maule | 9b08ebd | 2005-04-25 11:32:16 -0700 | [diff] [blame] | 20 | #include <asm/sn/pcibus_provider_defs.h> |
| 21 | #include <asm/sn/pcidev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <asm/sn/shub_mmr.h> |
| 23 | #include <asm/sn/sn_sal.h> |
John Keller | 6e9de18 | 2007-08-22 19:32:06 -0500 | [diff] [blame] | 24 | #include <asm/sn/sn_feature_sets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
| 26 | static void force_interrupt(int irq); |
| 27 | static void register_intr_pda(struct sn_irq_info *sn_irq_info); |
| 28 | static void unregister_intr_pda(struct sn_irq_info *sn_irq_info); |
| 29 | |
Len Brown | d0d59b9 | 2005-08-25 12:41:22 -0400 | [diff] [blame] | 30 | int sn_force_interrupt_flag = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | extern int sn_ioif_inited; |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 32 | struct list_head **sn_irq_lh; |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 33 | static DEFINE_SPINLOCK(sn_irq_info_lock); /* non-IRQ lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 35 | u64 sn_intr_alloc(nasid_t local_nasid, int local_widget, |
| 36 | struct sn_irq_info *sn_irq_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | int req_irq, nasid_t req_nasid, |
| 38 | int req_slice) |
| 39 | { |
| 40 | struct ia64_sal_retval ret_stuff; |
| 41 | ret_stuff.status = 0; |
| 42 | ret_stuff.v0 = 0; |
| 43 | |
| 44 | SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_INTERRUPT, |
| 45 | (u64) SAL_INTR_ALLOC, (u64) local_nasid, |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 46 | (u64) local_widget, __pa(sn_irq_info), (u64) req_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | (u64) req_nasid, (u64) req_slice); |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | return ret_stuff.status; |
| 50 | } |
| 51 | |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 52 | void sn_intr_free(nasid_t local_nasid, int local_widget, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct sn_irq_info *sn_irq_info) |
| 54 | { |
| 55 | struct ia64_sal_retval ret_stuff; |
| 56 | ret_stuff.status = 0; |
| 57 | ret_stuff.v0 = 0; |
| 58 | |
| 59 | SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_INTERRUPT, |
| 60 | (u64) SAL_INTR_FREE, (u64) local_nasid, |
| 61 | (u64) local_widget, (u64) sn_irq_info->irq_irq, |
| 62 | (u64) sn_irq_info->irq_cookie, 0, 0); |
| 63 | } |
| 64 | |
John Keller | 0e17b56 | 2007-05-02 09:09:18 -0500 | [diff] [blame] | 65 | u64 sn_intr_redirect(nasid_t local_nasid, int local_widget, |
| 66 | struct sn_irq_info *sn_irq_info, |
| 67 | nasid_t req_nasid, int req_slice) |
| 68 | { |
| 69 | struct ia64_sal_retval ret_stuff; |
| 70 | ret_stuff.status = 0; |
| 71 | ret_stuff.v0 = 0; |
| 72 | |
| 73 | SAL_CALL_NOLOCK(ret_stuff, (u64) SN_SAL_IOIF_INTERRUPT, |
| 74 | (u64) SAL_INTR_REDIRECT, (u64) local_nasid, |
| 75 | (u64) local_widget, __pa(sn_irq_info), |
| 76 | (u64) req_nasid, (u64) req_slice, 0); |
| 77 | |
| 78 | return ret_stuff.status; |
| 79 | } |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static unsigned int sn_startup_irq(unsigned int irq) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static void sn_shutdown_irq(unsigned int irq) |
| 87 | { |
| 88 | } |
| 89 | |
Russ Anderson | 1f3b604 | 2007-10-31 11:10:38 -0500 | [diff] [blame] | 90 | extern void ia64_mca_register_cpev(int); |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | static void sn_disable_irq(unsigned int irq) |
| 93 | { |
Russ Anderson | 1f3b604 | 2007-10-31 11:10:38 -0500 | [diff] [blame] | 94 | if (irq == local_vector_to_irq(IA64_CPE_VECTOR)) |
| 95 | ia64_mca_register_cpev(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static void sn_enable_irq(unsigned int irq) |
| 99 | { |
Russ Anderson | 1f3b604 | 2007-10-31 11:10:38 -0500 | [diff] [blame] | 100 | if (irq == local_vector_to_irq(IA64_CPE_VECTOR)) |
| 101 | ia64_mca_register_cpev(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static void sn_ack_irq(unsigned int irq) |
| 105 | { |
Jes Sorensen | 2fcc3db | 2006-02-02 05:15:51 -0500 | [diff] [blame] | 106 | u64 event_occurred, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | irq = irq & 0xff; |
Jes Sorensen | 2fcc3db | 2006-02-02 05:15:51 -0500 | [diff] [blame] | 109 | event_occurred = HUB_L((u64*)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED)); |
Colin Ngam | be539c7 | 2005-04-25 13:06:28 -0700 | [diff] [blame] | 110 | mask = event_occurred & SH_ALL_INT_MASK; |
Jes Sorensen | 2fcc3db | 2006-02-02 05:15:51 -0500 | [diff] [blame] | 111 | HUB_S((u64*)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED_ALIAS), mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | __set_bit(irq, (volatile void *)pda->sn_in_service_ivecs); |
| 113 | |
Mark Maule | 689388b | 2006-01-27 11:55:34 -0600 | [diff] [blame] | 114 | move_native_irq(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | static void sn_end_irq(unsigned int irq) |
| 118 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | int ivec; |
Jack Steiner | 0aa2c72 | 2005-08-11 10:26:00 -0700 | [diff] [blame] | 120 | u64 event_occurred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | ivec = irq & 0xff; |
| 123 | if (ivec == SGI_UART_VECTOR) { |
Jack Steiner | 0aa2c72 | 2005-08-11 10:26:00 -0700 | [diff] [blame] | 124 | event_occurred = HUB_L((u64*)LOCAL_MMR_ADDR (SH_EVENT_OCCURRED)); |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 125 | /* If the UART bit is set here, we may have received an |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | * interrupt from the UART that the driver missed. To |
| 127 | * make sure, we IPI ourselves to force us to look again. |
| 128 | */ |
| 129 | if (event_occurred & SH_EVENT_OCCURRED_UART_INT_MASK) { |
| 130 | platform_send_ipi(smp_processor_id(), SGI_UART_VECTOR, |
| 131 | IA64_IPI_DM_INT, 0); |
| 132 | } |
| 133 | } |
| 134 | __clear_bit(ivec, (volatile void *)pda->sn_in_service_ivecs); |
| 135 | if (sn_force_interrupt_flag) |
| 136 | force_interrupt(irq); |
| 137 | } |
| 138 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 139 | static void sn_irq_info_free(struct rcu_head *head); |
| 140 | |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 141 | struct sn_irq_info *sn_retarget_vector(struct sn_irq_info *sn_irq_info, |
| 142 | nasid_t nasid, int slice) |
| 143 | { |
| 144 | int vector; |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 145 | int cpuid; |
| 146 | #ifdef CONFIG_SMP |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 147 | int cpuphys; |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 148 | #endif |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 149 | int64_t bridge; |
| 150 | int local_widget, status; |
| 151 | nasid_t local_nasid; |
| 152 | struct sn_irq_info *new_irq_info; |
| 153 | struct sn_pcibus_provider *pci_provider; |
| 154 | |
John Keller | 0e17b56 | 2007-05-02 09:09:18 -0500 | [diff] [blame] | 155 | bridge = (u64) sn_irq_info->irq_bridge; |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 156 | if (!bridge) { |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 157 | return NULL; /* irq is not a device interrupt */ |
| 158 | } |
| 159 | |
| 160 | local_nasid = NASID_GET(bridge); |
| 161 | |
| 162 | if (local_nasid & 1) |
| 163 | local_widget = TIO_SWIN_WIDGETNUM(bridge); |
| 164 | else |
| 165 | local_widget = SWIN_WIDGETNUM(bridge); |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 166 | vector = sn_irq_info->irq_irq; |
John Keller | 0e17b56 | 2007-05-02 09:09:18 -0500 | [diff] [blame] | 167 | |
| 168 | /* Make use of SAL_INTR_REDIRECT if PROM supports it */ |
| 169 | status = sn_intr_redirect(local_nasid, local_widget, sn_irq_info, nasid, slice); |
| 170 | if (!status) { |
| 171 | new_irq_info = sn_irq_info; |
| 172 | goto finish_up; |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | * PROM does not support SAL_INTR_REDIRECT, or it failed. |
| 177 | * Revert to old method. |
| 178 | */ |
| 179 | new_irq_info = kmalloc(sizeof(struct sn_irq_info), GFP_ATOMIC); |
| 180 | if (new_irq_info == NULL) |
| 181 | return NULL; |
| 182 | |
| 183 | memcpy(new_irq_info, sn_irq_info, sizeof(struct sn_irq_info)); |
| 184 | |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 185 | /* Free the old PROM new_irq_info structure */ |
| 186 | sn_intr_free(local_nasid, local_widget, new_irq_info); |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 187 | unregister_intr_pda(new_irq_info); |
| 188 | |
| 189 | /* allocate a new PROM new_irq_info struct */ |
| 190 | status = sn_intr_alloc(local_nasid, local_widget, |
| 191 | new_irq_info, vector, |
| 192 | nasid, slice); |
| 193 | |
| 194 | /* SAL call failed */ |
| 195 | if (status) { |
| 196 | kfree(new_irq_info); |
| 197 | return NULL; |
| 198 | } |
| 199 | |
John Keller | 0e17b56 | 2007-05-02 09:09:18 -0500 | [diff] [blame] | 200 | register_intr_pda(new_irq_info); |
| 201 | spin_lock(&sn_irq_info_lock); |
| 202 | list_replace_rcu(&sn_irq_info->list, &new_irq_info->list); |
| 203 | spin_unlock(&sn_irq_info_lock); |
| 204 | call_rcu(&sn_irq_info->rcu, sn_irq_info_free); |
| 205 | |
| 206 | |
| 207 | finish_up: |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 208 | /* Update kernels new_irq_info with new target info */ |
| 209 | cpuid = nasid_slice_to_cpuid(new_irq_info->irq_nasid, |
| 210 | new_irq_info->irq_slice); |
| 211 | new_irq_info->irq_cpuid = cpuid; |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 212 | |
| 213 | pci_provider = sn_pci_provider[new_irq_info->irq_bridge_type]; |
| 214 | |
| 215 | /* |
| 216 | * If this represents a line interrupt, target it. If it's |
| 217 | * an msi (irq_int_bit < 0), it's already targeted. |
| 218 | */ |
| 219 | if (new_irq_info->irq_int_bit >= 0 && |
| 220 | pci_provider && pci_provider->target_interrupt) |
| 221 | (pci_provider->target_interrupt)(new_irq_info); |
| 222 | |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 223 | #ifdef CONFIG_SMP |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 224 | cpuphys = cpu_physical_id(cpuid); |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 225 | set_irq_affinity_info((vector & 0xff), cpuphys, 0); |
| 226 | #endif |
| 227 | |
| 228 | return new_irq_info; |
| 229 | } |
| 230 | |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 231 | static int sn_set_affinity_irq(unsigned int irq, const struct cpumask *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 233 | struct sn_irq_info *sn_irq_info, *sn_irq_info_safe; |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 234 | nasid_t nasid; |
| 235 | int slice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Rusty Russell | 0de2652 | 2008-12-13 21:20:26 +1030 | [diff] [blame] | 237 | nasid = cpuid_to_nasid(cpumask_first(mask)); |
| 238 | slice = cpuid_to_slice(cpumask_first(mask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 240 | list_for_each_entry_safe(sn_irq_info, sn_irq_info_safe, |
Mark Maule | 83821d3 | 2006-04-14 16:03:54 -0500 | [diff] [blame] | 241 | sn_irq_lh[irq], list) |
| 242 | (void)sn_retarget_vector(sn_irq_info, nasid, slice); |
Yinghai Lu | d5dedd4 | 2009-04-27 17:59:21 -0700 | [diff] [blame] | 243 | |
| 244 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
John Keller | 6e9de18 | 2007-08-22 19:32:06 -0500 | [diff] [blame] | 247 | #ifdef CONFIG_SMP |
| 248 | void sn_set_err_irq_affinity(unsigned int irq) |
| 249 | { |
| 250 | /* |
| 251 | * On systems which support CPU disabling (SHub2), all error interrupts |
| 252 | * are targetted at the boot CPU. |
| 253 | */ |
| 254 | if (is_shub2() && sn_prom_feature_available(PRF_CPU_DISABLE_SUPPORT)) |
| 255 | set_irq_affinity_info(irq, cpu_physical_id(0), 0); |
| 256 | } |
| 257 | #else |
| 258 | void sn_set_err_irq_affinity(unsigned int irq) { } |
| 259 | #endif |
| 260 | |
KAMEZAWA Hiroyuki | e253eb0 | 2007-03-07 14:57:35 -0800 | [diff] [blame] | 261 | static void |
| 262 | sn_mask_irq(unsigned int irq) |
| 263 | { |
| 264 | } |
| 265 | |
| 266 | static void |
| 267 | sn_unmask_irq(unsigned int irq) |
| 268 | { |
| 269 | } |
| 270 | |
| 271 | struct irq_chip irq_type_sn = { |
Ingo Molnar | 06344db | 2006-11-16 00:43:02 -0800 | [diff] [blame] | 272 | .name = "SN hub", |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 273 | .startup = sn_startup_irq, |
| 274 | .shutdown = sn_shutdown_irq, |
| 275 | .enable = sn_enable_irq, |
| 276 | .disable = sn_disable_irq, |
| 277 | .ack = sn_ack_irq, |
| 278 | .end = sn_end_irq, |
KAMEZAWA Hiroyuki | e253eb0 | 2007-03-07 14:57:35 -0800 | [diff] [blame] | 279 | .mask = sn_mask_irq, |
| 280 | .unmask = sn_unmask_irq, |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 281 | .set_affinity = sn_set_affinity_irq |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | }; |
| 283 | |
Kenji Kaneshige | 1115200 | 2007-08-13 10:31:26 -0700 | [diff] [blame] | 284 | ia64_vector sn_irq_to_vector(int irq) |
| 285 | { |
| 286 | if (irq >= IA64_NUM_VECTORS) |
| 287 | return 0; |
| 288 | return (ia64_vector)irq; |
| 289 | } |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | unsigned int sn_local_vector_to_irq(u8 vector) |
| 292 | { |
| 293 | return (CPU_VECTOR_TO_IRQ(smp_processor_id(), vector)); |
| 294 | } |
| 295 | |
| 296 | void sn_irq_init(void) |
| 297 | { |
| 298 | int i; |
Thomas Gleixner | 86bc3df | 2009-06-10 12:45:00 -0700 | [diff] [blame] | 299 | struct irq_desc *base_desc = irq_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
Mark Maule | 1008307 | 2006-04-14 16:03:49 -0500 | [diff] [blame] | 301 | ia64_first_device_vector = IA64_SN2_FIRST_DEVICE_VECTOR; |
| 302 | ia64_last_device_vector = IA64_SN2_LAST_DEVICE_VECTOR; |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | for (i = 0; i < NR_IRQS; i++) { |
Thomas Gleixner | 8a7c3cd | 2009-06-10 12:44:59 -0700 | [diff] [blame] | 305 | if (base_desc[i].chip == &no_irq_chip) { |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 306 | base_desc[i].chip = &irq_type_sn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | static void register_intr_pda(struct sn_irq_info *sn_irq_info) |
| 312 | { |
| 313 | int irq = sn_irq_info->irq_irq; |
| 314 | int cpu = sn_irq_info->irq_cpuid; |
| 315 | |
| 316 | if (pdacpu(cpu)->sn_last_irq < irq) { |
| 317 | pdacpu(cpu)->sn_last_irq = irq; |
| 318 | } |
| 319 | |
Jes Sorensen | 2fcc3db | 2006-02-02 05:15:51 -0500 | [diff] [blame] | 320 | if (pdacpu(cpu)->sn_first_irq == 0 || pdacpu(cpu)->sn_first_irq > irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | pdacpu(cpu)->sn_first_irq = irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static void unregister_intr_pda(struct sn_irq_info *sn_irq_info) |
| 325 | { |
| 326 | int irq = sn_irq_info->irq_irq; |
| 327 | int cpu = sn_irq_info->irq_cpuid; |
| 328 | struct sn_irq_info *tmp_irq_info; |
| 329 | int i, foundmatch; |
| 330 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 331 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (pdacpu(cpu)->sn_last_irq == irq) { |
| 333 | foundmatch = 0; |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 334 | for (i = pdacpu(cpu)->sn_last_irq - 1; |
| 335 | i && !foundmatch; i--) { |
| 336 | list_for_each_entry_rcu(tmp_irq_info, |
| 337 | sn_irq_lh[i], |
| 338 | list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | if (tmp_irq_info->irq_cpuid == cpu) { |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 340 | foundmatch = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | break; |
| 342 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | pdacpu(cpu)->sn_last_irq = i; |
| 346 | } |
| 347 | |
| 348 | if (pdacpu(cpu)->sn_first_irq == irq) { |
| 349 | foundmatch = 0; |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 350 | for (i = pdacpu(cpu)->sn_first_irq + 1; |
| 351 | i < NR_IRQS && !foundmatch; i++) { |
| 352 | list_for_each_entry_rcu(tmp_irq_info, |
| 353 | sn_irq_lh[i], |
| 354 | list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | if (tmp_irq_info->irq_cpuid == cpu) { |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 356 | foundmatch = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | break; |
| 358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | pdacpu(cpu)->sn_first_irq = ((i == NR_IRQS) ? 0 : i); |
| 362 | } |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 363 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 366 | static void sn_irq_info_free(struct rcu_head *head) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | { |
| 368 | struct sn_irq_info *sn_irq_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 370 | sn_irq_info = container_of(head, struct sn_irq_info, rcu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | kfree(sn_irq_info); |
| 372 | } |
| 373 | |
| 374 | void sn_irq_fixup(struct pci_dev *pci_dev, struct sn_irq_info *sn_irq_info) |
| 375 | { |
| 376 | nasid_t nasid = sn_irq_info->irq_nasid; |
| 377 | int slice = sn_irq_info->irq_slice; |
| 378 | int cpu = nasid_slice_to_cpuid(nasid, slice); |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 379 | #ifdef CONFIG_SMP |
| 380 | int cpuphys; |
Thomas Gleixner | 86bc3df | 2009-06-10 12:45:00 -0700 | [diff] [blame] | 381 | struct irq_desc *desc; |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 382 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 384 | pci_dev_get(pci_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | sn_irq_info->irq_cpuid = cpu; |
| 386 | sn_irq_info->irq_pciioinfo = SN_PCIDEV_INFO(pci_dev); |
| 387 | |
| 388 | /* link it into the sn_irq[irq] list */ |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 389 | spin_lock(&sn_irq_info_lock); |
| 390 | list_add_rcu(&sn_irq_info->list, sn_irq_lh[sn_irq_info->irq_irq]); |
Mark Maule | 1008307 | 2006-04-14 16:03:49 -0500 | [diff] [blame] | 391 | reserve_irq_vector(sn_irq_info->irq_irq); |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 392 | spin_unlock(&sn_irq_info_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Jes Sorensen | 2fcc3db | 2006-02-02 05:15:51 -0500 | [diff] [blame] | 394 | register_intr_pda(sn_irq_info); |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 395 | #ifdef CONFIG_SMP |
| 396 | cpuphys = cpu_physical_id(cpu); |
| 397 | set_irq_affinity_info(sn_irq_info->irq_irq, cpuphys, 0); |
John Keller | ff740fb | 2008-12-08 11:44:11 -0600 | [diff] [blame] | 398 | desc = irq_to_desc(sn_irq_info->irq_irq); |
| 399 | /* |
| 400 | * Affinity was set by the PROM, prevent it from |
| 401 | * being reset by the request_irq() path. |
| 402 | */ |
| 403 | desc->status |= IRQ_AFFINITY_SET; |
John Keller | c695777 | 2006-11-06 14:10:50 -0600 | [diff] [blame] | 404 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 407 | void sn_irq_unfixup(struct pci_dev *pci_dev) |
| 408 | { |
| 409 | struct sn_irq_info *sn_irq_info; |
| 410 | |
| 411 | /* Only cleanup IRQ stuff if this device has a host bus context */ |
| 412 | if (!SN_PCIDEV_BUSSOFT(pci_dev)) |
| 413 | return; |
| 414 | |
| 415 | sn_irq_info = SN_PCIDEV_INFO(pci_dev)->pdi_sn_irq_info; |
Prarit Bhargava | 8b34ff4 | 2006-02-09 14:12:24 -0800 | [diff] [blame] | 416 | if (!sn_irq_info) |
| 417 | return; |
| 418 | if (!sn_irq_info->irq_irq) { |
Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 419 | kfree(sn_irq_info); |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 420 | return; |
Prarit Bhargava | 6f354b0 | 2005-07-06 15:29:53 -0700 | [diff] [blame] | 421 | } |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 422 | |
| 423 | unregister_intr_pda(sn_irq_info); |
| 424 | spin_lock(&sn_irq_info_lock); |
| 425 | list_del_rcu(&sn_irq_info->list); |
| 426 | spin_unlock(&sn_irq_info_lock); |
Mark Maule | 1008307 | 2006-04-14 16:03:49 -0500 | [diff] [blame] | 427 | if (list_empty(sn_irq_lh[sn_irq_info->irq_irq])) |
| 428 | free_irq_vector(sn_irq_info->irq_irq); |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 429 | call_rcu(&sn_irq_info->rcu, sn_irq_info_free); |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 430 | pci_dev_put(pci_dev); |
Mark Maule | 1008307 | 2006-04-14 16:03:49 -0500 | [diff] [blame] | 431 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Mark Maule | 735e60f | 2005-08-03 14:06:00 -0700 | [diff] [blame] | 434 | static inline void |
| 435 | sn_call_force_intr_provider(struct sn_irq_info *sn_irq_info) |
| 436 | { |
| 437 | struct sn_pcibus_provider *pci_provider; |
| 438 | |
| 439 | pci_provider = sn_pci_provider[sn_irq_info->irq_bridge_type]; |
Mike Habeck | 352b0ef | 2007-08-13 17:13:08 -0500 | [diff] [blame] | 440 | |
| 441 | /* Don't force an interrupt if the irq has been disabled */ |
| 442 | if (!(irq_desc[sn_irq_info->irq_irq].status & IRQ_DISABLED) && |
| 443 | pci_provider && pci_provider->force_interrupt) |
Mark Maule | 735e60f | 2005-08-03 14:06:00 -0700 | [diff] [blame] | 444 | (*pci_provider->force_interrupt)(sn_irq_info); |
| 445 | } |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | static void force_interrupt(int irq) |
| 448 | { |
| 449 | struct sn_irq_info *sn_irq_info; |
| 450 | |
| 451 | if (!sn_ioif_inited) |
| 452 | return; |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 453 | |
| 454 | rcu_read_lock(); |
Mark Maule | 735e60f | 2005-08-03 14:06:00 -0700 | [diff] [blame] | 455 | list_for_each_entry_rcu(sn_irq_info, sn_irq_lh[irq], list) |
| 456 | sn_call_force_intr_provider(sn_irq_info); |
| 457 | |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 458 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* |
| 462 | * Check for lost interrupts. If the PIC int_status reg. says that |
| 463 | * an interrupt has been sent, but not handled, and the interrupt |
| 464 | * is not pending in either the cpu irr regs or in the soft irr regs, |
| 465 | * and the interrupt is not in service, then the interrupt may have |
| 466 | * been lost. Force an interrupt on that pin. It is possible that |
| 467 | * the interrupt is in flight, so we may generate a spurious interrupt, |
| 468 | * but we should never miss a real lost interrupt. |
| 469 | */ |
| 470 | static void sn_check_intr(int irq, struct sn_irq_info *sn_irq_info) |
| 471 | { |
Prarit Bhargava | 53493dc | 2006-01-16 19:54:40 -0800 | [diff] [blame] | 472 | u64 regval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | struct pcidev_info *pcidev_info; |
| 474 | struct pcibus_info *pcibus_info; |
| 475 | |
Mark Maule | 735e60f | 2005-08-03 14:06:00 -0700 | [diff] [blame] | 476 | /* |
| 477 | * Bridge types attached to TIO (anything but PIC) do not need this WAR |
| 478 | * since they do not target Shub II interrupt registers. If that |
| 479 | * ever changes, this check needs to accomodate. |
| 480 | */ |
| 481 | if (sn_irq_info->irq_bridge_type != PCIIO_ASIC_TYPE_PIC) |
| 482 | return; |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | pcidev_info = (struct pcidev_info *)sn_irq_info->irq_pciioinfo; |
| 485 | if (!pcidev_info) |
| 486 | return; |
| 487 | |
| 488 | pcibus_info = |
| 489 | (struct pcibus_info *)pcidev_info->pdi_host_pcidev_info-> |
| 490 | pdi_pcibus_info; |
| 491 | regval = pcireg_intr_status_get(pcibus_info); |
| 492 | |
Bjorn Helgaas | 9a4e554 | 2006-03-21 10:44:07 -0700 | [diff] [blame] | 493 | if (!ia64_get_irr(irq_to_vector(irq))) { |
Mark Maule | 735e60f | 2005-08-03 14:06:00 -0700 | [diff] [blame] | 494 | if (!test_bit(irq, pda->sn_in_service_ivecs)) { |
| 495 | regval &= 0xff; |
| 496 | if (sn_irq_info->irq_int_bit & regval & |
| 497 | sn_irq_info->irq_last_intr) { |
| 498 | regval &= ~(sn_irq_info->irq_int_bit & regval); |
| 499 | sn_call_force_intr_provider(sn_irq_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | } |
| 503 | sn_irq_info->irq_last_intr = regval; |
| 504 | } |
| 505 | |
| 506 | void sn_lb_int_war_check(void) |
| 507 | { |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 508 | struct sn_irq_info *sn_irq_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | int i; |
| 510 | |
| 511 | if (!sn_ioif_inited || pda->sn_first_irq == 0) |
| 512 | return; |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 513 | |
| 514 | rcu_read_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | for (i = pda->sn_first_irq; i <= pda->sn_last_irq; i++) { |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 516 | list_for_each_entry_rcu(sn_irq_info, sn_irq_lh[i], list) { |
Mark Maule | 735e60f | 2005-08-03 14:06:00 -0700 | [diff] [blame] | 517 | sn_check_intr(i, sn_irq_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | } |
| 519 | } |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 520 | rcu_read_unlock(); |
| 521 | } |
| 522 | |
Jes Sorensen | 2fcc3db | 2006-02-02 05:15:51 -0500 | [diff] [blame] | 523 | void __init sn_irq_lh_init(void) |
Prarit Bhargava | cb4cb2c | 2005-07-06 14:59:44 -0700 | [diff] [blame] | 524 | { |
| 525 | int i; |
| 526 | |
| 527 | sn_irq_lh = kmalloc(sizeof(struct list_head *) * NR_IRQS, GFP_KERNEL); |
| 528 | if (!sn_irq_lh) |
| 529 | panic("SN PCI INIT: Failed to allocate memory for PCI init\n"); |
| 530 | |
| 531 | for (i = 0; i < NR_IRQS; i++) { |
| 532 | sn_irq_lh[i] = kmalloc(sizeof(struct list_head), GFP_KERNEL); |
| 533 | if (!sn_irq_lh[i]) |
| 534 | panic("SN PCI INIT: Failed IRQ memory allocation\n"); |
| 535 | |
| 536 | INIT_LIST_HEAD(sn_irq_lh[i]); |
| 537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } |