blob: a862d13fc85748303b84497848046c1ad22a3e1e [file] [log] [blame]
David S. Miller4a907de2007-06-13 00:01:04 -07001/* irq.c: UltraSparc IRQ handling/init/registry.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
David S. Miller4a907de2007-06-13 00:01:04 -07003 * Copyright (C) 1997, 2007 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
5 * Copyright (C) 1998 Jakub Jelinek (jj@ultra.linux.cz)
6 */
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/module.h>
9#include <linux/sched.h>
10#include <linux/ptrace.h>
11#include <linux/errno.h>
12#include <linux/kernel_stat.h>
13#include <linux/signal.h>
14#include <linux/mm.h>
15#include <linux/interrupt.h>
16#include <linux/slab.h>
17#include <linux/random.h>
18#include <linux/init.h>
19#include <linux/delay.h>
20#include <linux/proc_fs.h>
21#include <linux/seq_file.h>
David S. Millerb5a37e92006-02-11 23:07:13 -080022#include <linux/bootmem.h>
David S. Millere18e2a02006-06-20 01:23:32 -070023#include <linux/irq.h>
David S. Miller35a17eb2007-02-10 17:41:02 -080024#include <linux/msi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#include <asm/ptrace.h>
27#include <asm/processor.h>
28#include <asm/atomic.h>
29#include <asm/system.h>
30#include <asm/irq.h>
Sven Hartge2e457ef2005-10-08 21:12:04 -070031#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/sbus.h>
33#include <asm/iommu.h>
34#include <asm/upa.h>
35#include <asm/oplib.h>
David S. Miller25c75812006-06-22 20:21:22 -070036#include <asm/prom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include <asm/timer.h>
38#include <asm/smp.h>
39#include <asm/starfire.h>
40#include <asm/uaccess.h>
41#include <asm/cache.h>
42#include <asm/cpudata.h>
David S. Miller63b61452005-06-27 17:04:45 -070043#include <asm/auxio.h>
David S. Miller92704a12006-02-26 23:27:19 -080044#include <asm/head.h>
David S. Miller4a907de2007-06-13 00:01:04 -070045#include <asm/hypervisor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047/* UPA nodes send interrupt packet to UltraSparc with first data reg
48 * value low 5 (7 on Starfire) bits holding the IRQ identifier being
49 * delivered. We must translate this into a non-vector IRQ so we can
50 * set the softint on this cpu.
51 *
52 * To make processing these packets efficient and race free we use
53 * an array of irq buckets below. The interrupt vector handler in
54 * entry.S feeds incoming packets into per-cpu pil-indexed lists.
55 * The IVEC handler does not need to act atomically, the PIL dispatch
56 * code uses CAS to get an atomic snapshot of the list and clear it
57 * at the same time.
David S. Millere18e2a02006-06-20 01:23:32 -070058 *
59 * If you make changes to ino_bucket, please update hand coded assembler
60 * of the vectored interrupt trap handler(s) in entry.S and sun4v_ivec.S
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 */
David S. Millere18e2a02006-06-20 01:23:32 -070062struct ino_bucket {
63 /* Next handler in per-CPU IRQ worklist. We know that
64 * bucket pointers have the high 32-bits clear, so to
65 * save space we only store the bits we need.
66 */
67/*0x00*/unsigned int irq_chain;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
David S. Millere18e2a02006-06-20 01:23:32 -070069 /* Virtual interrupt number assigned to this INO. */
70/*0x04*/unsigned int virt_irq;
71};
72
73#define NUM_IVECS (IMAP_INR + 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES)));
75
David S. Millere18e2a02006-06-20 01:23:32 -070076#define __irq_ino(irq) \
77 (((struct ino_bucket *)(unsigned long)(irq)) - &ivector_table[0])
78#define __bucket(irq) ((struct ino_bucket *)(unsigned long)(irq))
79#define __irq(bucket) ((unsigned int)(unsigned long)(bucket))
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/* This has to be in the main kernel image, it cannot be
82 * turned into per-cpu data. The reason is that the main
83 * kernel image is locked into the TLB and this structure
84 * is accessed from the vectored interrupt trap handler. If
85 * access to this structure takes a TLB miss it could cause
86 * the 5-level sparc v9 trap stack to overflow.
87 */
David S. Millerfd0504c32006-06-20 01:20:00 -070088#define irq_work(__cpu) &(trap_block[(__cpu)].irq_worklist)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
David S. Miller8047e242006-06-20 01:22:35 -070090static unsigned int virt_to_real_irq_table[NR_IRQS];
David S. Miller8047e242006-06-20 01:22:35 -070091
92static unsigned char virt_irq_alloc(unsigned int real_irq)
93{
94 unsigned char ent;
95
96 BUILD_BUG_ON(NR_IRQS >= 256);
97
David S. Miller35a17eb2007-02-10 17:41:02 -080098 for (ent = 1; ent < NR_IRQS; ent++) {
99 if (!virt_to_real_irq_table[ent])
100 break;
101 }
David S. Miller8047e242006-06-20 01:22:35 -0700102 if (ent >= NR_IRQS) {
103 printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
104 return 0;
105 }
106
David S. Miller8047e242006-06-20 01:22:35 -0700107 virt_to_real_irq_table[ent] = real_irq;
108
109 return ent;
110}
111
David S. Miller5746c992007-02-20 01:26:48 -0800112#ifdef CONFIG_PCI_MSI
David S. Miller35a17eb2007-02-10 17:41:02 -0800113static void virt_irq_free(unsigned int virt_irq)
David S. Miller8047e242006-06-20 01:22:35 -0700114{
David S. Miller35a17eb2007-02-10 17:41:02 -0800115 unsigned int real_irq;
David S. Miller8047e242006-06-20 01:22:35 -0700116
David S. Miller35a17eb2007-02-10 17:41:02 -0800117 if (virt_irq >= NR_IRQS)
118 return;
119
120 real_irq = virt_to_real_irq_table[virt_irq];
121 virt_to_real_irq_table[virt_irq] = 0;
122
123 __bucket(real_irq)->virt_irq = 0;
David S. Miller8047e242006-06-20 01:22:35 -0700124}
David S. Miller5746c992007-02-20 01:26:48 -0800125#endif
David S. Miller8047e242006-06-20 01:22:35 -0700126
127static unsigned int virt_to_real_irq(unsigned char virt_irq)
128{
129 return virt_to_real_irq_table[virt_irq];
130}
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/*
David S. Millere18e2a02006-06-20 01:23:32 -0700133 * /proc/interrupts printing:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136int show_interrupts(struct seq_file *p, void *v)
137{
David S. Millere18e2a02006-06-20 01:23:32 -0700138 int i = *(loff_t *) v, j;
139 struct irqaction * action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
David S. Millere18e2a02006-06-20 01:23:32 -0700142 if (i == 0) {
143 seq_printf(p, " ");
144 for_each_online_cpu(j)
145 seq_printf(p, "CPU%d ",j);
146 seq_putc(p, '\n');
147 }
148
149 if (i < NR_IRQS) {
150 spin_lock_irqsave(&irq_desc[i].lock, flags);
151 action = irq_desc[i].action;
152 if (!action)
153 goto skip;
154 seq_printf(p, "%3d: ",i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155#ifndef CONFIG_SMP
156 seq_printf(p, "%10u ", kstat_irqs(i));
157#else
David S. Millere18e2a02006-06-20 01:23:32 -0700158 for_each_online_cpu(j)
159 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#endif
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700161 seq_printf(p, " %9s", irq_desc[i].chip->typename);
David S. Millere18e2a02006-06-20 01:23:32 -0700162 seq_printf(p, " %s", action->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
David S. Millere18e2a02006-06-20 01:23:32 -0700164 for (action=action->next; action; action = action->next)
165 seq_printf(p, ", %s", action->name);
166
167 seq_putc(p, '\n');
168skip:
169 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
170 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 return 0;
172}
173
David S. Millerebd8c562006-02-17 08:38:06 -0800174static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
175{
176 unsigned int tid;
177
178 if (this_is_starfire) {
179 tid = starfire_translate(imap, cpuid);
180 tid <<= IMAP_TID_SHIFT;
181 tid &= IMAP_TID_UPA;
182 } else {
183 if (tlb_type == cheetah || tlb_type == cheetah_plus) {
184 unsigned long ver;
185
186 __asm__ ("rdpr %%ver, %0" : "=r" (ver));
187 if ((ver >> 32UL) == __JALAPENO_ID ||
188 (ver >> 32UL) == __SERRANO_ID) {
189 tid = cpuid << IMAP_TID_SHIFT;
190 tid &= IMAP_TID_JBUS;
191 } else {
192 unsigned int a = cpuid & 0x1f;
193 unsigned int n = (cpuid >> 5) & 0x1f;
194
195 tid = ((a << IMAP_AID_SHIFT) |
196 (n << IMAP_NID_SHIFT));
197 tid &= (IMAP_AID_SAFARI |
198 IMAP_NID_SAFARI);;
199 }
200 } else {
201 tid = cpuid << IMAP_TID_SHIFT;
202 tid &= IMAP_TID_UPA;
203 }
204 }
205
206 return tid;
207}
208
David S. Millere18e2a02006-06-20 01:23:32 -0700209struct irq_handler_data {
210 unsigned long iclr;
211 unsigned long imap;
212
213 void (*pre_handler)(unsigned int, void *, void *);
214 void *pre_handler_arg1;
215 void *pre_handler_arg2;
216};
217
218static inline struct ino_bucket *virt_irq_to_bucket(unsigned int virt_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
David S. Miller8047e242006-06-20 01:22:35 -0700220 unsigned int real_irq = virt_to_real_irq(virt_irq);
David S. Millere18e2a02006-06-20 01:23:32 -0700221 struct ino_bucket *bucket = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
David S. Millere18e2a02006-06-20 01:23:32 -0700223 if (likely(real_irq))
224 bucket = __bucket(real_irq);
David S. Miller8047e242006-06-20 01:22:35 -0700225
David S. Millere18e2a02006-06-20 01:23:32 -0700226 return bucket;
227}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
David S. Millere18e2a02006-06-20 01:23:32 -0700229#ifdef CONFIG_SMP
230static int irq_choose_cpu(unsigned int virt_irq)
231{
Ingo Molnara53da522006-06-29 02:24:38 -0700232 cpumask_t mask = irq_desc[virt_irq].affinity;
David S. Millere18e2a02006-06-20 01:23:32 -0700233 int cpuid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
David S. Millere18e2a02006-06-20 01:23:32 -0700235 if (cpus_equal(mask, CPU_MASK_ALL)) {
236 static int irq_rover;
237 static DEFINE_SPINLOCK(irq_rover_lock);
238 unsigned long flags;
David S. Millerebd8c562006-02-17 08:38:06 -0800239
David S. Millere18e2a02006-06-20 01:23:32 -0700240 /* Round-robin distribution... */
241 do_round_robin:
242 spin_lock_irqsave(&irq_rover_lock, flags);
243
244 while (!cpu_online(irq_rover)) {
245 if (++irq_rover >= NR_CPUS)
246 irq_rover = 0;
247 }
248 cpuid = irq_rover;
249 do {
250 if (++irq_rover >= NR_CPUS)
251 irq_rover = 0;
252 } while (!cpu_online(irq_rover));
253
254 spin_unlock_irqrestore(&irq_rover_lock, flags);
255 } else {
256 cpumask_t tmp;
257
258 cpus_and(tmp, cpu_online_map, mask);
259
260 if (cpus_empty(tmp))
261 goto do_round_robin;
262
263 cpuid = first_cpu(tmp);
264 }
265
266 return cpuid;
267}
268#else
269static int irq_choose_cpu(unsigned int virt_irq)
270{
271 return real_hard_smp_processor_id();
272}
273#endif
274
275static void sun4u_irq_enable(unsigned int virt_irq)
276{
David S. Miller68c92182007-01-29 12:12:28 -0800277 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
David S. Millere18e2a02006-06-20 01:23:32 -0700278
279 if (likely(data)) {
David S. Miller861fe902007-05-02 17:31:36 -0700280 unsigned long cpuid, imap, val;
David S. Millere18e2a02006-06-20 01:23:32 -0700281 unsigned int tid;
282
283 cpuid = irq_choose_cpu(virt_irq);
284 imap = data->imap;
285
286 tid = sun4u_compute_tid(imap, cpuid);
287
David S. Miller861fe902007-05-02 17:31:36 -0700288 val = upa_readq(imap);
289 val &= ~(IMAP_TID_UPA | IMAP_TID_JBUS |
290 IMAP_AID_SAFARI | IMAP_NID_SAFARI);
291 val |= tid | IMAP_VALID;
292 upa_writeq(val, imap);
David S. Millere18e2a02006-06-20 01:23:32 -0700293 }
294}
295
296static void sun4u_irq_disable(unsigned int virt_irq)
297{
David S. Miller68c92182007-01-29 12:12:28 -0800298 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
David S. Millere18e2a02006-06-20 01:23:32 -0700299
300 if (likely(data)) {
301 unsigned long imap = data->imap;
David S. Miller861fe902007-05-02 17:31:36 -0700302 u32 tmp = upa_readq(imap);
David S. Millere18e2a02006-06-20 01:23:32 -0700303
304 tmp &= ~IMAP_VALID;
David S. Miller861fe902007-05-02 17:31:36 -0700305 upa_writeq(tmp, imap);
David S. Millere18e2a02006-06-20 01:23:32 -0700306 }
307}
308
309static void sun4u_irq_end(unsigned int virt_irq)
310{
David S. Miller68c92182007-01-29 12:12:28 -0800311 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
David S. Millere18e2a02006-06-20 01:23:32 -0700312
313 if (likely(data))
David S. Miller861fe902007-05-02 17:31:36 -0700314 upa_writeq(ICLR_IDLE, data->iclr);
David S. Millere18e2a02006-06-20 01:23:32 -0700315}
316
317static void sun4v_irq_enable(unsigned int virt_irq)
318{
319 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
320 unsigned int ino = bucket - &ivector_table[0];
321
322 if (likely(bucket)) {
323 unsigned long cpuid;
David S. Millerc4bea282006-02-13 22:56:27 -0800324 int err;
David S. Miller10951ee2006-02-13 18:22:57 -0800325
David S. Millere18e2a02006-06-20 01:23:32 -0700326 cpuid = irq_choose_cpu(virt_irq);
327
David S. Millerebd8c562006-02-17 08:38:06 -0800328 err = sun4v_intr_settarget(ino, cpuid);
David S. Millerc4bea282006-02-13 22:56:27 -0800329 if (err != HV_EOK)
David S. Millerebd8c562006-02-17 08:38:06 -0800330 printk("sun4v_intr_settarget(%x,%lu): err(%d)\n",
331 ino, cpuid, err);
David S. Millerabd92b22006-02-14 22:20:13 -0800332 err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
David S. Millerc4bea282006-02-13 22:56:27 -0800333 if (err != HV_EOK)
334 printk("sun4v_intr_setenabled(%x): err(%d)\n",
335 ino, err);
David S. Millerd82ace72006-02-09 02:52:44 -0800336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
David S. Millere18e2a02006-06-20 01:23:32 -0700339static void sun4v_irq_disable(unsigned int virt_irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
David S. Millere18e2a02006-06-20 01:23:32 -0700341 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
342 unsigned int ino = bucket - &ivector_table[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
David S. Millere18e2a02006-06-20 01:23:32 -0700344 if (likely(bucket)) {
David S. Miller8047e242006-06-20 01:22:35 -0700345 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
David S. Miller8047e242006-06-20 01:22:35 -0700347 err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
348 if (err != HV_EOK)
349 printk("sun4v_intr_setenabled(%x): "
350 "err(%d)\n", ino, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352}
353
David S. Miller35a17eb2007-02-10 17:41:02 -0800354#ifdef CONFIG_PCI_MSI
355static void sun4v_msi_enable(unsigned int virt_irq)
356{
357 sun4v_irq_enable(virt_irq);
358 unmask_msi_irq(virt_irq);
359}
360
361static void sun4v_msi_disable(unsigned int virt_irq)
362{
363 mask_msi_irq(virt_irq);
364 sun4v_irq_disable(virt_irq);
365}
366#endif
367
David S. Millere18e2a02006-06-20 01:23:32 -0700368static void sun4v_irq_end(unsigned int virt_irq)
David S. Miller088dd1f2005-07-04 13:24:38 -0700369{
David S. Millere18e2a02006-06-20 01:23:32 -0700370 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
371 unsigned int ino = bucket - &ivector_table[0];
372
373 if (likely(bucket)) {
374 int err;
375
376 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
377 if (err != HV_EOK)
378 printk("sun4v_intr_setstate(%x): "
379 "err(%d)\n", ino, err);
380 }
David S. Miller088dd1f2005-07-04 13:24:38 -0700381}
382
David S. Miller4a907de2007-06-13 00:01:04 -0700383static void sun4v_virq_enable(unsigned int virt_irq)
384{
385 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
386 unsigned int ino = bucket - &ivector_table[0];
387
388 if (likely(bucket)) {
389 unsigned long cpuid, dev_handle, dev_ino;
390 int err;
391
392 cpuid = irq_choose_cpu(virt_irq);
393
394 dev_handle = ino & IMAP_IGN;
395 dev_ino = ino & IMAP_INO;
396
397 err = sun4v_vintr_set_target(dev_handle, dev_ino, cpuid);
398 if (err != HV_EOK)
399 printk("sun4v_vintr_set_target(%lx,%lx,%lu): "
400 "err(%d)\n",
401 dev_handle, dev_ino, cpuid, err);
402 err = sun4v_vintr_set_state(dev_handle, dev_ino,
David S. Miller12450882007-06-26 00:13:09 -0700403 HV_INTR_STATE_IDLE);
404 if (err != HV_EOK)
405 printk("sun4v_vintr_set_state(%lx,%lx,"
406 "HV_INTR_STATE_IDLE): err(%d)\n",
407 dev_handle, dev_ino, err);
408 err = sun4v_vintr_set_valid(dev_handle, dev_ino,
David S. Miller4a907de2007-06-13 00:01:04 -0700409 HV_INTR_ENABLED);
410 if (err != HV_EOK)
411 printk("sun4v_vintr_set_state(%lx,%lx,"
412 "HV_INTR_ENABLED): err(%d)\n",
413 dev_handle, dev_ino, err);
414 }
415}
416
417static void sun4v_virq_disable(unsigned int virt_irq)
418{
419 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
420 unsigned int ino = bucket - &ivector_table[0];
421
422 if (likely(bucket)) {
423 unsigned long dev_handle, dev_ino;
424 int err;
425
426 dev_handle = ino & IMAP_IGN;
427 dev_ino = ino & IMAP_INO;
428
David S. Miller12450882007-06-26 00:13:09 -0700429 err = sun4v_vintr_set_valid(dev_handle, dev_ino,
David S. Miller4a907de2007-06-13 00:01:04 -0700430 HV_INTR_DISABLED);
431 if (err != HV_EOK)
432 printk("sun4v_vintr_set_state(%lx,%lx,"
433 "HV_INTR_DISABLED): err(%d)\n",
434 dev_handle, dev_ino, err);
435 }
436}
437
438static void sun4v_virq_end(unsigned int virt_irq)
439{
440 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
441 unsigned int ino = bucket - &ivector_table[0];
442
443 if (likely(bucket)) {
444 unsigned long dev_handle, dev_ino;
445 int err;
446
447 dev_handle = ino & IMAP_IGN;
448 dev_ino = ino & IMAP_INO;
449
450 err = sun4v_vintr_set_state(dev_handle, dev_ino,
451 HV_INTR_STATE_IDLE);
452 if (err != HV_EOK)
453 printk("sun4v_vintr_set_state(%lx,%lx,"
454 "HV_INTR_STATE_IDLE): err(%d)\n",
455 dev_handle, dev_ino, err);
456 }
457}
458
David S. Millere18e2a02006-06-20 01:23:32 -0700459static void run_pre_handler(unsigned int virt_irq)
460{
461 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
David S. Miller68c92182007-01-29 12:12:28 -0800462 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
David S. Millere18e2a02006-06-20 01:23:32 -0700463
464 if (likely(data->pre_handler)) {
465 data->pre_handler(__irq_ino(__irq(bucket)),
466 data->pre_handler_arg1,
467 data->pre_handler_arg2);
468 }
469}
470
David S. Miller729e7d72006-12-12 00:59:12 -0800471static struct irq_chip sun4u_irq = {
David S. Millere18e2a02006-06-20 01:23:32 -0700472 .typename = "sun4u",
473 .enable = sun4u_irq_enable,
474 .disable = sun4u_irq_disable,
475 .end = sun4u_irq_end,
476};
477
David S. Miller729e7d72006-12-12 00:59:12 -0800478static struct irq_chip sun4u_irq_ack = {
David S. Millere18e2a02006-06-20 01:23:32 -0700479 .typename = "sun4u+ack",
480 .enable = sun4u_irq_enable,
481 .disable = sun4u_irq_disable,
482 .ack = run_pre_handler,
483 .end = sun4u_irq_end,
484};
485
David S. Miller729e7d72006-12-12 00:59:12 -0800486static struct irq_chip sun4v_irq = {
David S. Millere18e2a02006-06-20 01:23:32 -0700487 .typename = "sun4v",
488 .enable = sun4v_irq_enable,
489 .disable = sun4v_irq_disable,
490 .end = sun4v_irq_end,
491};
492
David S. Miller729e7d72006-12-12 00:59:12 -0800493static struct irq_chip sun4v_irq_ack = {
David S. Millere18e2a02006-06-20 01:23:32 -0700494 .typename = "sun4v+ack",
495 .enable = sun4v_irq_enable,
496 .disable = sun4v_irq_disable,
497 .ack = run_pre_handler,
498 .end = sun4v_irq_end,
499};
500
David S. Miller35a17eb2007-02-10 17:41:02 -0800501#ifdef CONFIG_PCI_MSI
502static struct irq_chip sun4v_msi = {
503 .typename = "sun4v+msi",
504 .mask = mask_msi_irq,
505 .unmask = unmask_msi_irq,
506 .enable = sun4v_msi_enable,
507 .disable = sun4v_msi_disable,
508 .ack = run_pre_handler,
509 .end = sun4v_irq_end,
510};
511#endif
512
David S. Miller4a907de2007-06-13 00:01:04 -0700513static struct irq_chip sun4v_virq = {
514 .typename = "vsun4v",
515 .enable = sun4v_virq_enable,
516 .disable = sun4v_virq_disable,
517 .end = sun4v_virq_end,
518};
519
520static struct irq_chip sun4v_virq_ack = {
521 .typename = "vsun4v+ack",
522 .enable = sun4v_virq_enable,
523 .disable = sun4v_virq_disable,
524 .ack = run_pre_handler,
525 .end = sun4v_virq_end,
526};
527
David S. Millere18e2a02006-06-20 01:23:32 -0700528void irq_install_pre_handler(int virt_irq,
529 void (*func)(unsigned int, void *, void *),
530 void *arg1, void *arg2)
531{
David S. Miller68c92182007-01-29 12:12:28 -0800532 struct irq_handler_data *data = get_irq_chip_data(virt_irq);
533 struct irq_chip *chip;
David S. Millere18e2a02006-06-20 01:23:32 -0700534
535 data->pre_handler = func;
536 data->pre_handler_arg1 = arg1;
537 data->pre_handler_arg2 = arg2;
538
David S. Miller68c92182007-01-29 12:12:28 -0800539 chip = get_irq_chip(virt_irq);
540 if (chip == &sun4u_irq_ack ||
David S. Miller4a907de2007-06-13 00:01:04 -0700541 chip == &sun4v_irq_ack ||
542 chip == &sun4v_virq_ack
David S. Miller35a17eb2007-02-10 17:41:02 -0800543#ifdef CONFIG_PCI_MSI
544 || chip == &sun4v_msi
545#endif
546 )
David S. Miller24ac26d2006-06-29 14:38:21 -0700547 return;
548
David S. Miller68c92182007-01-29 12:12:28 -0800549 chip = (chip == &sun4u_irq ?
David S. Miller4a907de2007-06-13 00:01:04 -0700550 &sun4u_irq_ack :
551 (chip == &sun4v_irq ?
552 &sun4v_irq_ack : &sun4v_virq_ack));
David S. Miller68c92182007-01-29 12:12:28 -0800553 set_irq_chip(virt_irq, chip);
David S. Millere18e2a02006-06-20 01:23:32 -0700554}
555
556unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
558 struct ino_bucket *bucket;
David S. Millere18e2a02006-06-20 01:23:32 -0700559 struct irq_handler_data *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 int ino;
561
David S. Miller10951ee2006-02-13 18:22:57 -0800562 BUG_ON(tlb_type == hypervisor);
563
David S. Miller861fe902007-05-02 17:31:36 -0700564 ino = (upa_readq(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
David S. Miller088dd1f2005-07-04 13:24:38 -0700565 bucket = &ivector_table[ino];
David S. Millere18e2a02006-06-20 01:23:32 -0700566 if (!bucket->virt_irq) {
567 bucket->virt_irq = virt_irq_alloc(__irq(bucket));
David S. Miller68c92182007-01-29 12:12:28 -0800568 set_irq_chip(bucket->virt_irq, &sun4u_irq);
David S. Miller088dd1f2005-07-04 13:24:38 -0700569 }
570
David S. Miller68c92182007-01-29 12:12:28 -0800571 data = get_irq_chip_data(bucket->virt_irq);
572 if (unlikely(data))
David S. Millere18e2a02006-06-20 01:23:32 -0700573 goto out;
574
575 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
576 if (unlikely(!data)) {
577 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
David S. Miller088dd1f2005-07-04 13:24:38 -0700578 prom_halt();
579 }
David S. Miller68c92182007-01-29 12:12:28 -0800580 set_irq_chip_data(bucket->virt_irq, data);
David S. Miller088dd1f2005-07-04 13:24:38 -0700581
David S. Millere18e2a02006-06-20 01:23:32 -0700582 data->imap = imap;
583 data->iclr = iclr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
David S. Miller088dd1f2005-07-04 13:24:38 -0700585out:
David S. Miller8047e242006-06-20 01:22:35 -0700586 return bucket->virt_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
David S. Miller4a907de2007-06-13 00:01:04 -0700589static unsigned int sun4v_build_common(unsigned long sysino,
590 struct irq_chip *chip)
David S. Millere3999572006-02-13 18:16:10 -0800591{
592 struct ino_bucket *bucket;
David S. Millere18e2a02006-06-20 01:23:32 -0700593 struct irq_handler_data *data;
David S. Millere18e2a02006-06-20 01:23:32 -0700594
595 BUG_ON(tlb_type != hypervisor);
David S. Millere3999572006-02-13 18:16:10 -0800596
David S. Millere3999572006-02-13 18:16:10 -0800597 bucket = &ivector_table[sysino];
David S. Millere18e2a02006-06-20 01:23:32 -0700598 if (!bucket->virt_irq) {
599 bucket->virt_irq = virt_irq_alloc(__irq(bucket));
David S. Miller4a907de2007-06-13 00:01:04 -0700600 set_irq_chip(bucket->virt_irq, chip);
David S. Millere18e2a02006-06-20 01:23:32 -0700601 }
602
David S. Miller68c92182007-01-29 12:12:28 -0800603 data = get_irq_chip_data(bucket->virt_irq);
604 if (unlikely(data))
David S. Millere18e2a02006-06-20 01:23:32 -0700605 goto out;
606
607 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
608 if (unlikely(!data)) {
609 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
610 prom_halt();
611 }
David S. Miller68c92182007-01-29 12:12:28 -0800612 set_irq_chip_data(bucket->virt_irq, data);
David S. Millere3999572006-02-13 18:16:10 -0800613
614 /* Catch accidental accesses to these things. IMAP/ICLR handling
615 * is done by hypervisor calls on sun4v platforms, not by direct
616 * register accesses.
617 */
David S. Millere18e2a02006-06-20 01:23:32 -0700618 data->imap = ~0UL;
619 data->iclr = ~0UL;
David S. Millere3999572006-02-13 18:16:10 -0800620
David S. Millere18e2a02006-06-20 01:23:32 -0700621out:
David S. Miller8047e242006-06-20 01:22:35 -0700622 return bucket->virt_irq;
David S. Millere3999572006-02-13 18:16:10 -0800623}
624
David S. Miller4a907de2007-06-13 00:01:04 -0700625unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
626{
627 unsigned long sysino = sun4v_devino_to_sysino(devhandle, devino);
628
629 return sun4v_build_common(sysino, &sun4v_irq);
630}
631
632unsigned int sun4v_build_virq(u32 devhandle, unsigned int devino)
633{
634 unsigned long sysino, hv_err;
635
636 BUG_ON(devhandle & ~IMAP_IGN);
637 BUG_ON(devino & ~IMAP_INO);
638
639 sysino = devhandle | devino;
640
641 hv_err = sun4v_vintr_set_cookie(devhandle, devino, sysino);
642 if (hv_err) {
643 prom_printf("IRQ: Fatal, cannot set cookie for [%x:%x] "
644 "err=%lu\n", devhandle, devino, hv_err);
645 prom_halt();
646 }
647
648 return sun4v_build_common(sysino, &sun4v_virq);
649}
650
David S. Miller35a17eb2007-02-10 17:41:02 -0800651#ifdef CONFIG_PCI_MSI
652unsigned int sun4v_build_msi(u32 devhandle, unsigned int *virt_irq_p,
653 unsigned int msi_start, unsigned int msi_end)
654{
655 struct ino_bucket *bucket;
656 struct irq_handler_data *data;
657 unsigned long sysino;
658 unsigned int devino;
659
660 BUG_ON(tlb_type != hypervisor);
661
662 /* Find a free devino in the given range. */
663 for (devino = msi_start; devino < msi_end; devino++) {
664 sysino = sun4v_devino_to_sysino(devhandle, devino);
665 bucket = &ivector_table[sysino];
666 if (!bucket->virt_irq)
667 break;
668 }
669 if (devino >= msi_end)
670 return 0;
671
672 sysino = sun4v_devino_to_sysino(devhandle, devino);
673 bucket = &ivector_table[sysino];
674 bucket->virt_irq = virt_irq_alloc(__irq(bucket));
675 *virt_irq_p = bucket->virt_irq;
676 set_irq_chip(bucket->virt_irq, &sun4v_msi);
677
678 data = get_irq_chip_data(bucket->virt_irq);
679 if (unlikely(data))
680 return devino;
681
682 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
683 if (unlikely(!data)) {
684 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
685 prom_halt();
686 }
687 set_irq_chip_data(bucket->virt_irq, data);
688
689 data->imap = ~0UL;
690 data->iclr = ~0UL;
691
692 return devino;
693}
694
695void sun4v_destroy_msi(unsigned int virt_irq)
696{
697 virt_irq_free(virt_irq);
698}
699#endif
700
David S. Millere18e2a02006-06-20 01:23:32 -0700701void ack_bad_irq(unsigned int virt_irq)
David S. Miller088dd1f2005-07-04 13:24:38 -0700702{
David S. Millere18e2a02006-06-20 01:23:32 -0700703 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
704 unsigned int ino = 0xdeadbeef;
David S. Miller088dd1f2005-07-04 13:24:38 -0700705
David S. Millere18e2a02006-06-20 01:23:32 -0700706 if (bucket)
707 ino = bucket - &ivector_table[0];
David S. Miller088dd1f2005-07-04 13:24:38 -0700708
David S. Millere18e2a02006-06-20 01:23:32 -0700709 printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
710 ino, virt_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711}
712
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713void handler_irq(int irq, struct pt_regs *regs)
714{
David S. Millere18e2a02006-06-20 01:23:32 -0700715 struct ino_bucket *bucket;
Al Viro6d24c8d2006-10-08 08:23:28 -0400716 struct pt_regs *old_regs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 clear_softint(1 << irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
Al Viro6d24c8d2006-10-08 08:23:28 -0400720 old_regs = set_irq_regs(regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 irq_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722
723 /* Sliiiick... */
David S. Millere18e2a02006-06-20 01:23:32 -0700724 bucket = __bucket(xchg32(irq_work(smp_processor_id()), 0));
725 while (bucket) {
726 struct ino_bucket *next = __bucket(bucket->irq_chain);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727
David S. Millere18e2a02006-06-20 01:23:32 -0700728 bucket->irq_chain = 0;
Al Viro6d24c8d2006-10-08 08:23:28 -0400729 __do_IRQ(bucket->virt_irq);
David S. Millerfd0504c32006-06-20 01:20:00 -0700730
David S. Millere18e2a02006-06-20 01:23:32 -0700731 bucket = next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 }
David S. Millere18e2a02006-06-20 01:23:32 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 irq_exit();
Al Viro6d24c8d2006-10-08 08:23:28 -0400735 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736}
737
David S. Millercdd51862005-07-24 19:36:13 -0700738struct sun5_timer {
739 u64 count0;
740 u64 limit0;
741 u64 count1;
742 u64 limit1;
743};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
David S. Millercdd51862005-07-24 19:36:13 -0700745static struct sun5_timer *prom_timers;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746static u64 prom_limit0, prom_limit1;
747
748static void map_prom_timers(void)
749{
David S. Miller25c75812006-06-22 20:21:22 -0700750 struct device_node *dp;
Stephen Rothwell6a23acf2007-04-23 15:53:27 -0700751 const unsigned int *addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /* PROM timer node hangs out in the top level of device siblings... */
David S. Miller25c75812006-06-22 20:21:22 -0700754 dp = of_find_node_by_path("/");
755 dp = dp->child;
756 while (dp) {
757 if (!strcmp(dp->name, "counter-timer"))
758 break;
759 dp = dp->sibling;
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762 /* Assume if node is not present, PROM uses different tick mechanism
763 * which we should not care about.
764 */
David S. Miller25c75812006-06-22 20:21:22 -0700765 if (!dp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 prom_timers = (struct sun5_timer *) 0;
767 return;
768 }
769
770 /* If PROM is really using this, it must be mapped by him. */
David S. Miller25c75812006-06-22 20:21:22 -0700771 addr = of_get_property(dp, "address", NULL);
772 if (!addr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 prom_printf("PROM does not have timer mapped, trying to continue.\n");
774 prom_timers = (struct sun5_timer *) 0;
775 return;
776 }
777 prom_timers = (struct sun5_timer *) ((unsigned long)addr[0]);
778}
779
780static void kill_prom_timer(void)
781{
782 if (!prom_timers)
783 return;
784
785 /* Save them away for later. */
786 prom_limit0 = prom_timers->limit0;
787 prom_limit1 = prom_timers->limit1;
788
789 /* Just as in sun4c/sun4m PROM uses timer which ticks at IRQ 14.
790 * We turn both off here just to be paranoid.
791 */
792 prom_timers->limit0 = 0;
793 prom_timers->limit1 = 0;
794
795 /* Wheee, eat the interrupt packet too... */
796 __asm__ __volatile__(
797" mov 0x40, %%g2\n"
798" ldxa [%%g0] %0, %%g1\n"
799" ldxa [%%g2] %1, %%g1\n"
800" stxa %%g0, [%%g0] %0\n"
801" membar #Sync\n"
802 : /* no outputs */
803 : "i" (ASI_INTR_RECEIVE), "i" (ASI_INTR_R)
804 : "g1", "g2");
805}
806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807void init_irqwork_curcpu(void)
808{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 int cpu = hard_smp_processor_id();
810
David S. Millerfd0504c32006-06-20 01:20:00 -0700811 trap_block[cpu].irq_worklist = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812}
813
David S. Miller5cbc3072007-05-25 15:49:59 -0700814/* Please be very careful with register_one_mondo() and
815 * sun4v_register_mondo_queues().
816 *
817 * On SMP this gets invoked from the CPU trampoline before
818 * the cpu has fully taken over the trap table from OBP,
819 * and it's kernel stack + %g6 thread register state is
820 * not fully cooked yet.
821 *
822 * Therefore you cannot make any OBP calls, not even prom_printf,
823 * from these two routines.
824 */
825static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type, unsigned long qmask)
David S. Millerac29c112006-02-08 00:08:23 -0800826{
David S. Miller5cbc3072007-05-25 15:49:59 -0700827 unsigned long num_entries = (qmask + 1) / 64;
David S. Miller94f87622006-02-16 14:26:53 -0800828 unsigned long status;
David S. Millerac29c112006-02-08 00:08:23 -0800829
David S. Miller94f87622006-02-16 14:26:53 -0800830 status = sun4v_cpu_qconf(type, paddr, num_entries);
831 if (status != HV_EOK) {
832 prom_printf("SUN4V: sun4v_cpu_qconf(%lu:%lx:%lu) failed, "
833 "err %lu\n", type, paddr, num_entries, status);
David S. Millerac29c112006-02-08 00:08:23 -0800834 prom_halt();
835 }
836}
837
David S. Millerb5a37e92006-02-11 23:07:13 -0800838static void __cpuinit sun4v_register_mondo_queues(int this_cpu)
David S. Miller5b0c0572006-02-08 02:53:50 -0800839{
David S. Millerb5a37e92006-02-11 23:07:13 -0800840 struct trap_per_cpu *tb = &trap_block[this_cpu];
841
David S. Miller5cbc3072007-05-25 15:49:59 -0700842 register_one_mondo(tb->cpu_mondo_pa, HV_CPU_QUEUE_CPU_MONDO,
843 tb->cpu_mondo_qmask);
844 register_one_mondo(tb->dev_mondo_pa, HV_CPU_QUEUE_DEVICE_MONDO,
845 tb->dev_mondo_qmask);
846 register_one_mondo(tb->resum_mondo_pa, HV_CPU_QUEUE_RES_ERROR,
847 tb->resum_qmask);
848 register_one_mondo(tb->nonresum_mondo_pa, HV_CPU_QUEUE_NONRES_ERROR,
849 tb->nonresum_qmask);
David S. Millerb5a37e92006-02-11 23:07:13 -0800850}
851
David S. Miller5cbc3072007-05-25 15:49:59 -0700852static void __cpuinit alloc_one_mondo(unsigned long *pa_ptr, unsigned long qmask, int use_bootmem)
David S. Millerb5a37e92006-02-11 23:07:13 -0800853{
David S. Miller5cbc3072007-05-25 15:49:59 -0700854 unsigned long size = PAGE_ALIGN(qmask + 1);
855 unsigned long order = get_order(size);
856 void *p = NULL;
David S. Millerb5a37e92006-02-11 23:07:13 -0800857
David S. Miller5cbc3072007-05-25 15:49:59 -0700858 if (use_bootmem) {
859 p = __alloc_bootmem_low(size, size, 0);
860 } else {
861 struct page *page = alloc_pages(GFP_ATOMIC | __GFP_ZERO, order);
862 if (page)
863 p = page_address(page);
864 }
David S. Millerb5a37e92006-02-11 23:07:13 -0800865
David S. Miller5cbc3072007-05-25 15:49:59 -0700866 if (!p) {
David S. Millerb5a37e92006-02-11 23:07:13 -0800867 prom_printf("SUN4V: Error, cannot allocate mondo queue.\n");
868 prom_halt();
869 }
870
David S. Miller5cbc3072007-05-25 15:49:59 -0700871 *pa_ptr = __pa(p);
David S. Millerb5a37e92006-02-11 23:07:13 -0800872}
873
David S. Miller5cbc3072007-05-25 15:49:59 -0700874static void __cpuinit alloc_one_kbuf(unsigned long *pa_ptr, unsigned long qmask, int use_bootmem)
David S. Millerb5a37e92006-02-11 23:07:13 -0800875{
David S. Miller5cbc3072007-05-25 15:49:59 -0700876 unsigned long size = PAGE_ALIGN(qmask + 1);
877 unsigned long order = get_order(size);
878 void *p = NULL;
David S. Millerb5a37e92006-02-11 23:07:13 -0800879
David S. Miller5cbc3072007-05-25 15:49:59 -0700880 if (use_bootmem) {
881 p = __alloc_bootmem_low(size, size, 0);
882 } else {
883 struct page *page = alloc_pages(GFP_ATOMIC | __GFP_ZERO, order);
884 if (page)
885 p = page_address(page);
886 }
David S. Miller5b0c0572006-02-08 02:53:50 -0800887
David S. Miller5cbc3072007-05-25 15:49:59 -0700888 if (!p) {
David S. Miller5b0c0572006-02-08 02:53:50 -0800889 prom_printf("SUN4V: Error, cannot allocate kbuf page.\n");
890 prom_halt();
891 }
892
David S. Miller5cbc3072007-05-25 15:49:59 -0700893 *pa_ptr = __pa(p);
David S. Miller5b0c0572006-02-08 02:53:50 -0800894}
895
David S. Millerb5a37e92006-02-11 23:07:13 -0800896static void __cpuinit init_cpu_send_mondo_info(struct trap_per_cpu *tb, int use_bootmem)
David S. Miller1d2f1f92006-02-08 16:41:20 -0800897{
898#ifdef CONFIG_SMP
David S. Millerb5a37e92006-02-11 23:07:13 -0800899 void *page;
David S. Miller1d2f1f92006-02-08 16:41:20 -0800900
901 BUILD_BUG_ON((NR_CPUS * sizeof(u16)) > (PAGE_SIZE - 64));
902
David S. Millerb5a37e92006-02-11 23:07:13 -0800903 if (use_bootmem)
904 page = alloc_bootmem_low_pages(PAGE_SIZE);
905 else
906 page = (void *) get_zeroed_page(GFP_ATOMIC);
907
David S. Miller1d2f1f92006-02-08 16:41:20 -0800908 if (!page) {
909 prom_printf("SUN4V: Error, cannot allocate cpu mondo page.\n");
910 prom_halt();
911 }
912
913 tb->cpu_mondo_block_pa = __pa(page);
914 tb->cpu_list_pa = __pa(page + 64);
915#endif
916}
917
David S. Millerb5a37e92006-02-11 23:07:13 -0800918/* Allocate and register the mondo and error queues for this cpu. */
David S. Miller72aff532006-02-17 01:29:17 -0800919void __cpuinit sun4v_init_mondo_queues(int use_bootmem, int cpu, int alloc, int load)
David S. Millerac29c112006-02-08 00:08:23 -0800920{
David S. Millerac29c112006-02-08 00:08:23 -0800921 struct trap_per_cpu *tb = &trap_block[cpu];
922
David S. Miller72aff532006-02-17 01:29:17 -0800923 if (alloc) {
David S. Miller5cbc3072007-05-25 15:49:59 -0700924 alloc_one_mondo(&tb->cpu_mondo_pa, tb->cpu_mondo_qmask, use_bootmem);
925 alloc_one_mondo(&tb->dev_mondo_pa, tb->dev_mondo_qmask, use_bootmem);
926 alloc_one_mondo(&tb->resum_mondo_pa, tb->resum_qmask, use_bootmem);
927 alloc_one_kbuf(&tb->resum_kernel_buf_pa, tb->resum_qmask, use_bootmem);
928 alloc_one_mondo(&tb->nonresum_mondo_pa, tb->nonresum_qmask, use_bootmem);
929 alloc_one_kbuf(&tb->nonresum_kernel_buf_pa, tb->nonresum_qmask, use_bootmem);
David S. Miller1d2f1f92006-02-08 16:41:20 -0800930
David S. Miller72aff532006-02-17 01:29:17 -0800931 init_cpu_send_mondo_info(tb, use_bootmem);
932 }
David S. Miller1d2f1f92006-02-08 16:41:20 -0800933
David S. Miller72aff532006-02-17 01:29:17 -0800934 if (load) {
935 if (cpu != hard_smp_processor_id()) {
936 prom_printf("SUN4V: init mondo on cpu %d not %d\n",
937 cpu, hard_smp_processor_id());
938 prom_halt();
939 }
940 sun4v_register_mondo_queues(cpu);
941 }
David S. Millerac29c112006-02-08 00:08:23 -0800942}
943
David S. Millere18e2a02006-06-20 01:23:32 -0700944static struct irqaction timer_irq_action = {
945 .name = "timer",
946};
947
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948/* Only invoked on boot processor. */
949void __init init_IRQ(void)
950{
951 map_prom_timers();
952 kill_prom_timer();
953 memset(&ivector_table[0], 0, sizeof(ivector_table));
954
David S. Millerac29c112006-02-08 00:08:23 -0800955 if (tlb_type == hypervisor)
David S. Miller72aff532006-02-17 01:29:17 -0800956 sun4v_init_mondo_queues(1, hard_smp_processor_id(), 1, 1);
David S. Millerac29c112006-02-08 00:08:23 -0800957
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 /* We need to clear any IRQ's pending in the soft interrupt
959 * registers, a spurious one could be left around from the
960 * PROM timer which we just disabled.
961 */
962 clear_softint(get_softint());
963
964 /* Now that ivector table is initialized, it is safe
965 * to receive IRQ vector traps. We will normally take
966 * one or two right now, in case some device PROM used
967 * to boot us wants to speak to us. We just ignore them.
968 */
969 __asm__ __volatile__("rdpr %%pstate, %%g1\n\t"
970 "or %%g1, %0, %%g1\n\t"
971 "wrpr %%g1, 0x0, %%pstate"
972 : /* No outputs */
973 : "i" (PSTATE_IE)
974 : "g1");
David S. Millere18e2a02006-06-20 01:23:32 -0700975
976 irq_desc[0].action = &timer_irq_action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977}