blob: 13c15d968098d90b91beedb38855e331c73e616d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Kellerff740fb2008-12-08 11:44:11 -06008 * Copyright (c) 2000-2008 Silicon Graphics, Inc. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
10
11#include <linux/irq.h>
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -070012#include <linux/spinlock.h>
Jes Sorensen2fcc3db2006-02-02 05:15:51 -050013#include <linux/init.h>
Franck Bui-Huu82524742008-05-12 21:21:05 +020014#include <linux/rculist.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/sn/addrs.h>
17#include <asm/sn/arch.h>
Prarit Bhargavac13cf372005-07-06 15:26:51 -070018#include <asm/sn/intr.h>
19#include <asm/sn/pcibr_provider.h>
Mark Maule9b08ebd2005-04-25 11:32:16 -070020#include <asm/sn/pcibus_provider_defs.h>
21#include <asm/sn/pcidev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <asm/sn/shub_mmr.h>
23#include <asm/sn/sn_sal.h>
John Keller6e9de182007-08-22 19:32:06 -050024#include <asm/sn/sn_feature_sets.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26static void force_interrupt(int irq);
27static void register_intr_pda(struct sn_irq_info *sn_irq_info);
28static void unregister_intr_pda(struct sn_irq_info *sn_irq_info);
29
Len Brownd0d59b92005-08-25 12:41:22 -040030int sn_force_interrupt_flag = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031extern int sn_ioif_inited;
Mark Maule83821d32006-04-14 16:03:54 -050032struct list_head **sn_irq_lh;
Ingo Molnar34af9462006-06-27 02:53:55 -070033static DEFINE_SPINLOCK(sn_irq_info_lock); /* non-IRQ lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Mark Maule83821d32006-04-14 16:03:54 -050035u64 sn_intr_alloc(nasid_t local_nasid, int local_widget,
36 struct sn_irq_info *sn_irq_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 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 Maule83821d32006-04-14 16:03:54 -050046 (u64) local_widget, __pa(sn_irq_info), (u64) req_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 (u64) req_nasid, (u64) req_slice);
Mark Maule83821d32006-04-14 16:03:54 -050048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 return ret_stuff.status;
50}
51
Mark Maule83821d32006-04-14 16:03:54 -050052void sn_intr_free(nasid_t local_nasid, int local_widget,
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 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 Keller0e17b562007-05-02 09:09:18 -050065u64 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 Torvalds1da177e2005-04-16 15:20:36 -070081static unsigned int sn_startup_irq(unsigned int irq)
82{
83 return 0;
84}
85
86static void sn_shutdown_irq(unsigned int irq)
87{
88}
89
Russ Anderson1f3b6042007-10-31 11:10:38 -050090extern void ia64_mca_register_cpev(int);
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092static void sn_disable_irq(unsigned int irq)
93{
Russ Anderson1f3b6042007-10-31 11:10:38 -050094 if (irq == local_vector_to_irq(IA64_CPE_VECTOR))
95 ia64_mca_register_cpev(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
98static void sn_enable_irq(unsigned int irq)
99{
Russ Anderson1f3b6042007-10-31 11:10:38 -0500100 if (irq == local_vector_to_irq(IA64_CPE_VECTOR))
101 ia64_mca_register_cpev(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102}
103
104static void sn_ack_irq(unsigned int irq)
105{
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500106 u64 event_occurred, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 irq = irq & 0xff;
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500109 event_occurred = HUB_L((u64*)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED));
Colin Ngambe539c72005-04-25 13:06:28 -0700110 mask = event_occurred & SH_ALL_INT_MASK;
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500111 HUB_S((u64*)LOCAL_MMR_ADDR(SH_EVENT_OCCURRED_ALIAS), mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 __set_bit(irq, (volatile void *)pda->sn_in_service_ivecs);
113
Mark Maule689388b2006-01-27 11:55:34 -0600114 move_native_irq(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115}
116
117static void sn_end_irq(unsigned int irq)
118{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 int ivec;
Jack Steiner0aa2c722005-08-11 10:26:00 -0700120 u64 event_occurred;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 ivec = irq & 0xff;
123 if (ivec == SGI_UART_VECTOR) {
Jack Steiner0aa2c722005-08-11 10:26:00 -0700124 event_occurred = HUB_L((u64*)LOCAL_MMR_ADDR (SH_EVENT_OCCURRED));
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700125 /* If the UART bit is set here, we may have received an
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 * 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 Bhargavacb4cb2c2005-07-06 14:59:44 -0700139static void sn_irq_info_free(struct rcu_head *head);
140
Mark Maule83821d32006-04-14 16:03:54 -0500141struct sn_irq_info *sn_retarget_vector(struct sn_irq_info *sn_irq_info,
142 nasid_t nasid, int slice)
143{
144 int vector;
John Kellerc6957772006-11-06 14:10:50 -0600145 int cpuid;
146#ifdef CONFIG_SMP
Mark Maule83821d32006-04-14 16:03:54 -0500147 int cpuphys;
John Kellerc6957772006-11-06 14:10:50 -0600148#endif
Mark Maule83821d32006-04-14 16:03:54 -0500149 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 Keller0e17b562007-05-02 09:09:18 -0500155 bridge = (u64) sn_irq_info->irq_bridge;
Mark Maule83821d32006-04-14 16:03:54 -0500156 if (!bridge) {
Mark Maule83821d32006-04-14 16:03:54 -0500157 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 Maule83821d32006-04-14 16:03:54 -0500166 vector = sn_irq_info->irq_irq;
John Keller0e17b562007-05-02 09:09:18 -0500167
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 Maule83821d32006-04-14 16:03:54 -0500185 /* Free the old PROM new_irq_info structure */
186 sn_intr_free(local_nasid, local_widget, new_irq_info);
Mark Maule83821d32006-04-14 16:03:54 -0500187 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 Keller0e17b562007-05-02 09:09:18 -0500200 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
207finish_up:
John Kellerc6957772006-11-06 14:10:50 -0600208 /* 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 Maule83821d32006-04-14 16:03:54 -0500212
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 Maule83821d32006-04-14 16:03:54 -0500223#ifdef CONFIG_SMP
John Kellerc6957772006-11-06 14:10:50 -0600224 cpuphys = cpu_physical_id(cpuid);
Mark Maule83821d32006-04-14 16:03:54 -0500225 set_irq_affinity_info((vector & 0xff), cpuphys, 0);
226#endif
227
228 return new_irq_info;
229}
230
Yinghai Lud5dedd42009-04-27 17:59:21 -0700231static int sn_set_affinity_irq(unsigned int irq, const struct cpumask *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700233 struct sn_irq_info *sn_irq_info, *sn_irq_info_safe;
Mark Maule83821d32006-04-14 16:03:54 -0500234 nasid_t nasid;
235 int slice;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Rusty Russell0de26522008-12-13 21:20:26 +1030237 nasid = cpuid_to_nasid(cpumask_first(mask));
238 slice = cpuid_to_slice(cpumask_first(mask));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700240 list_for_each_entry_safe(sn_irq_info, sn_irq_info_safe,
Mark Maule83821d32006-04-14 16:03:54 -0500241 sn_irq_lh[irq], list)
242 (void)sn_retarget_vector(sn_irq_info, nasid, slice);
Yinghai Lud5dedd42009-04-27 17:59:21 -0700243
244 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}
246
John Keller6e9de182007-08-22 19:32:06 -0500247#ifdef CONFIG_SMP
248void 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
258void sn_set_err_irq_affinity(unsigned int irq) { }
259#endif
260
KAMEZAWA Hiroyukie253eb02007-03-07 14:57:35 -0800261static void
262sn_mask_irq(unsigned int irq)
263{
264}
265
266static void
267sn_unmask_irq(unsigned int irq)
268{
269}
270
271struct irq_chip irq_type_sn = {
Ingo Molnar06344db2006-11-16 00:43:02 -0800272 .name = "SN hub",
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700273 .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 Hiroyukie253eb02007-03-07 14:57:35 -0800279 .mask = sn_mask_irq,
280 .unmask = sn_unmask_irq,
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700281 .set_affinity = sn_set_affinity_irq
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282};
283
Kenji Kaneshige11152002007-08-13 10:31:26 -0700284ia64_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 Torvalds1da177e2005-04-16 15:20:36 -0700291unsigned int sn_local_vector_to_irq(u8 vector)
292{
293 return (CPU_VECTOR_TO_IRQ(smp_processor_id(), vector));
294}
295
296void sn_irq_init(void)
297{
298 int i;
Thomas Gleixner86bc3df2009-06-10 12:45:00 -0700299 struct irq_desc *base_desc = irq_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Mark Maule10083072006-04-14 16:03:49 -0500301 ia64_first_device_vector = IA64_SN2_FIRST_DEVICE_VECTOR;
302 ia64_last_device_vector = IA64_SN2_LAST_DEVICE_VECTOR;
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 for (i = 0; i < NR_IRQS; i++) {
Thomas Gleixner8a7c3cd2009-06-10 12:44:59 -0700305 if (base_desc[i].chip == &no_irq_chip) {
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700306 base_desc[i].chip = &irq_type_sn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
308 }
309}
310
311static 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 Sorensen2fcc3db2006-02-02 05:15:51 -0500320 if (pdacpu(cpu)->sn_first_irq == 0 || pdacpu(cpu)->sn_first_irq > irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 pdacpu(cpu)->sn_first_irq = irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
324static 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 Bhargavacb4cb2c2005-07-06 14:59:44 -0700331 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (pdacpu(cpu)->sn_last_irq == irq) {
333 foundmatch = 0;
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700334 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 Torvalds1da177e2005-04-16 15:20:36 -0700339 if (tmp_irq_info->irq_cpuid == cpu) {
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700340 foundmatch = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 break;
342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344 }
345 pdacpu(cpu)->sn_last_irq = i;
346 }
347
348 if (pdacpu(cpu)->sn_first_irq == irq) {
349 foundmatch = 0;
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700350 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 Torvalds1da177e2005-04-16 15:20:36 -0700355 if (tmp_irq_info->irq_cpuid == cpu) {
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700356 foundmatch = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 break;
358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
360 }
361 pdacpu(cpu)->sn_first_irq = ((i == NR_IRQS) ? 0 : i);
362 }
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700363 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700366static void sn_irq_info_free(struct rcu_head *head)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
368 struct sn_irq_info *sn_irq_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700370 sn_irq_info = container_of(head, struct sn_irq_info, rcu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 kfree(sn_irq_info);
372}
373
374void 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 Kellerc6957772006-11-06 14:10:50 -0600379#ifdef CONFIG_SMP
380 int cpuphys;
Thomas Gleixner86bc3df2009-06-10 12:45:00 -0700381 struct irq_desc *desc;
John Kellerc6957772006-11-06 14:10:50 -0600382#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700384 pci_dev_get(pci_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 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 Bhargavacb4cb2c2005-07-06 14:59:44 -0700389 spin_lock(&sn_irq_info_lock);
390 list_add_rcu(&sn_irq_info->list, sn_irq_lh[sn_irq_info->irq_irq]);
Mark Maule10083072006-04-14 16:03:49 -0500391 reserve_irq_vector(sn_irq_info->irq_irq);
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700392 spin_unlock(&sn_irq_info_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500394 register_intr_pda(sn_irq_info);
John Kellerc6957772006-11-06 14:10:50 -0600395#ifdef CONFIG_SMP
396 cpuphys = cpu_physical_id(cpu);
397 set_irq_affinity_info(sn_irq_info->irq_irq, cpuphys, 0);
John Kellerff740fb2008-12-08 11:44:11 -0600398 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 Kellerc6957772006-11-06 14:10:50 -0600404#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700407void 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 Bhargava8b34ff42006-02-09 14:12:24 -0800416 if (!sn_irq_info)
417 return;
418 if (!sn_irq_info->irq_irq) {
Prarit Bhargava6f354b02005-07-06 15:29:53 -0700419 kfree(sn_irq_info);
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700420 return;
Prarit Bhargava6f354b02005-07-06 15:29:53 -0700421 }
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700422
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 Maule10083072006-04-14 16:03:49 -0500427 if (list_empty(sn_irq_lh[sn_irq_info->irq_irq]))
428 free_irq_vector(sn_irq_info->irq_irq);
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700429 call_rcu(&sn_irq_info->rcu, sn_irq_info_free);
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700430 pci_dev_put(pci_dev);
Mark Maule10083072006-04-14 16:03:49 -0500431
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700432}
433
Mark Maule735e60f2005-08-03 14:06:00 -0700434static inline void
435sn_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 Habeck352b0ef2007-08-13 17:13:08 -0500440
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 Maule735e60f2005-08-03 14:06:00 -0700444 (*pci_provider->force_interrupt)(sn_irq_info);
445}
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447static void force_interrupt(int irq)
448{
449 struct sn_irq_info *sn_irq_info;
450
451 if (!sn_ioif_inited)
452 return;
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700453
454 rcu_read_lock();
Mark Maule735e60f2005-08-03 14:06:00 -0700455 list_for_each_entry_rcu(sn_irq_info, sn_irq_lh[irq], list)
456 sn_call_force_intr_provider(sn_irq_info);
457
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700458 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
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 */
470static void sn_check_intr(int irq, struct sn_irq_info *sn_irq_info)
471{
Prarit Bhargava53493dc2006-01-16 19:54:40 -0800472 u64 regval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 struct pcidev_info *pcidev_info;
474 struct pcibus_info *pcibus_info;
475
Mark Maule735e60f2005-08-03 14:06:00 -0700476 /*
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 Torvalds1da177e2005-04-16 15:20:36 -0700484 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 Helgaas9a4e5542006-03-21 10:44:07 -0700493 if (!ia64_get_irr(irq_to_vector(irq))) {
Mark Maule735e60f2005-08-03 14:06:00 -0700494 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 Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501 }
502 }
503 sn_irq_info->irq_last_intr = regval;
504}
505
506void sn_lb_int_war_check(void)
507{
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700508 struct sn_irq_info *sn_irq_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 int i;
510
511 if (!sn_ioif_inited || pda->sn_first_irq == 0)
512 return;
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700513
514 rcu_read_lock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 for (i = pda->sn_first_irq; i <= pda->sn_last_irq; i++) {
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700516 list_for_each_entry_rcu(sn_irq_info, sn_irq_lh[i], list) {
Mark Maule735e60f2005-08-03 14:06:00 -0700517 sn_check_intr(i, sn_irq_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 }
519 }
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700520 rcu_read_unlock();
521}
522
Jes Sorensen2fcc3db2006-02-02 05:15:51 -0500523void __init sn_irq_lh_init(void)
Prarit Bhargavacb4cb2c2005-07-06 14:59:44 -0700524{
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 Torvalds1da177e2005-04-16 15:20:36 -0700538}