]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/powerpc/sysdev/mpic.c
powerpc/mpic: add the mpic global timer support
[mirror_ubuntu-bionic-kernel.git] / arch / powerpc / sysdev / mpic.c
1 /*
2 * arch/powerpc/kernel/mpic.c
3 *
4 * Driver for interrupt controllers following the OpenPIC standard, the
5 * common implementation beeing IBM's MPIC. This driver also can deal
6 * with various broken implementations of this HW.
7 *
8 * Copyright (C) 2004 Benjamin Herrenschmidt, IBM Corp.
9 * Copyright 2010-2011 Freescale Semiconductor, Inc.
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive
13 * for more details.
14 */
15
16 #undef DEBUG
17 #undef DEBUG_IPI
18 #undef DEBUG_IRQ
19 #undef DEBUG_LOW
20
21 #include <linux/types.h>
22 #include <linux/kernel.h>
23 #include <linux/init.h>
24 #include <linux/irq.h>
25 #include <linux/smp.h>
26 #include <linux/interrupt.h>
27 #include <linux/bootmem.h>
28 #include <linux/spinlock.h>
29 #include <linux/pci.h>
30 #include <linux/slab.h>
31
32 #include <asm/ptrace.h>
33 #include <asm/signal.h>
34 #include <asm/io.h>
35 #include <asm/pgtable.h>
36 #include <asm/irq.h>
37 #include <asm/machdep.h>
38 #include <asm/mpic.h>
39 #include <asm/smp.h>
40
41 #include "mpic.h"
42
43 #ifdef DEBUG
44 #define DBG(fmt...) printk(fmt)
45 #else
46 #define DBG(fmt...)
47 #endif
48
49 static struct mpic *mpics;
50 static struct mpic *mpic_primary;
51 static DEFINE_RAW_SPINLOCK(mpic_lock);
52
53 #ifdef CONFIG_PPC32 /* XXX for now */
54 #ifdef CONFIG_IRQ_ALL_CPUS
55 #define distribute_irqs (1)
56 #else
57 #define distribute_irqs (0)
58 #endif
59 #endif
60
61 #ifdef CONFIG_MPIC_WEIRD
62 static u32 mpic_infos[][MPIC_IDX_END] = {
63 [0] = { /* Original OpenPIC compatible MPIC */
64 MPIC_GREG_BASE,
65 MPIC_GREG_FEATURE_0,
66 MPIC_GREG_GLOBAL_CONF_0,
67 MPIC_GREG_VENDOR_ID,
68 MPIC_GREG_IPI_VECTOR_PRI_0,
69 MPIC_GREG_IPI_STRIDE,
70 MPIC_GREG_SPURIOUS,
71 MPIC_GREG_TIMER_FREQ,
72
73 MPIC_TIMER_BASE,
74 MPIC_TIMER_STRIDE,
75 MPIC_TIMER_CURRENT_CNT,
76 MPIC_TIMER_BASE_CNT,
77 MPIC_TIMER_VECTOR_PRI,
78 MPIC_TIMER_DESTINATION,
79
80 MPIC_CPU_BASE,
81 MPIC_CPU_STRIDE,
82 MPIC_CPU_IPI_DISPATCH_0,
83 MPIC_CPU_IPI_DISPATCH_STRIDE,
84 MPIC_CPU_CURRENT_TASK_PRI,
85 MPIC_CPU_WHOAMI,
86 MPIC_CPU_INTACK,
87 MPIC_CPU_EOI,
88 MPIC_CPU_MCACK,
89
90 MPIC_IRQ_BASE,
91 MPIC_IRQ_STRIDE,
92 MPIC_IRQ_VECTOR_PRI,
93 MPIC_VECPRI_VECTOR_MASK,
94 MPIC_VECPRI_POLARITY_POSITIVE,
95 MPIC_VECPRI_POLARITY_NEGATIVE,
96 MPIC_VECPRI_SENSE_LEVEL,
97 MPIC_VECPRI_SENSE_EDGE,
98 MPIC_VECPRI_POLARITY_MASK,
99 MPIC_VECPRI_SENSE_MASK,
100 MPIC_IRQ_DESTINATION
101 },
102 [1] = { /* Tsi108/109 PIC */
103 TSI108_GREG_BASE,
104 TSI108_GREG_FEATURE_0,
105 TSI108_GREG_GLOBAL_CONF_0,
106 TSI108_GREG_VENDOR_ID,
107 TSI108_GREG_IPI_VECTOR_PRI_0,
108 TSI108_GREG_IPI_STRIDE,
109 TSI108_GREG_SPURIOUS,
110 TSI108_GREG_TIMER_FREQ,
111
112 TSI108_TIMER_BASE,
113 TSI108_TIMER_STRIDE,
114 TSI108_TIMER_CURRENT_CNT,
115 TSI108_TIMER_BASE_CNT,
116 TSI108_TIMER_VECTOR_PRI,
117 TSI108_TIMER_DESTINATION,
118
119 TSI108_CPU_BASE,
120 TSI108_CPU_STRIDE,
121 TSI108_CPU_IPI_DISPATCH_0,
122 TSI108_CPU_IPI_DISPATCH_STRIDE,
123 TSI108_CPU_CURRENT_TASK_PRI,
124 TSI108_CPU_WHOAMI,
125 TSI108_CPU_INTACK,
126 TSI108_CPU_EOI,
127 TSI108_CPU_MCACK,
128
129 TSI108_IRQ_BASE,
130 TSI108_IRQ_STRIDE,
131 TSI108_IRQ_VECTOR_PRI,
132 TSI108_VECPRI_VECTOR_MASK,
133 TSI108_VECPRI_POLARITY_POSITIVE,
134 TSI108_VECPRI_POLARITY_NEGATIVE,
135 TSI108_VECPRI_SENSE_LEVEL,
136 TSI108_VECPRI_SENSE_EDGE,
137 TSI108_VECPRI_POLARITY_MASK,
138 TSI108_VECPRI_SENSE_MASK,
139 TSI108_IRQ_DESTINATION
140 },
141 };
142
143 #define MPIC_INFO(name) mpic->hw_set[MPIC_IDX_##name]
144
145 #else /* CONFIG_MPIC_WEIRD */
146
147 #define MPIC_INFO(name) MPIC_##name
148
149 #endif /* CONFIG_MPIC_WEIRD */
150
151 static inline unsigned int mpic_processor_id(struct mpic *mpic)
152 {
153 unsigned int cpu = 0;
154
155 if (mpic->flags & MPIC_PRIMARY)
156 cpu = hard_smp_processor_id();
157
158 return cpu;
159 }
160
161 /*
162 * Register accessor functions
163 */
164
165
166 static inline u32 _mpic_read(enum mpic_reg_type type,
167 struct mpic_reg_bank *rb,
168 unsigned int reg)
169 {
170 switch(type) {
171 #ifdef CONFIG_PPC_DCR
172 case mpic_access_dcr:
173 return dcr_read(rb->dhost, reg);
174 #endif
175 case mpic_access_mmio_be:
176 return in_be32(rb->base + (reg >> 2));
177 case mpic_access_mmio_le:
178 default:
179 return in_le32(rb->base + (reg >> 2));
180 }
181 }
182
183 static inline void _mpic_write(enum mpic_reg_type type,
184 struct mpic_reg_bank *rb,
185 unsigned int reg, u32 value)
186 {
187 switch(type) {
188 #ifdef CONFIG_PPC_DCR
189 case mpic_access_dcr:
190 dcr_write(rb->dhost, reg, value);
191 break;
192 #endif
193 case mpic_access_mmio_be:
194 out_be32(rb->base + (reg >> 2), value);
195 break;
196 case mpic_access_mmio_le:
197 default:
198 out_le32(rb->base + (reg >> 2), value);
199 break;
200 }
201 }
202
203 static inline u32 _mpic_ipi_read(struct mpic *mpic, unsigned int ipi)
204 {
205 enum mpic_reg_type type = mpic->reg_type;
206 unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
207 (ipi * MPIC_INFO(GREG_IPI_STRIDE));
208
209 if ((mpic->flags & MPIC_BROKEN_IPI) && type == mpic_access_mmio_le)
210 type = mpic_access_mmio_be;
211 return _mpic_read(type, &mpic->gregs, offset);
212 }
213
214 static inline void _mpic_ipi_write(struct mpic *mpic, unsigned int ipi, u32 value)
215 {
216 unsigned int offset = MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
217 (ipi * MPIC_INFO(GREG_IPI_STRIDE));
218
219 _mpic_write(mpic->reg_type, &mpic->gregs, offset, value);
220 }
221
222 static inline u32 _mpic_tm_read(struct mpic *mpic, unsigned int tm)
223 {
224 unsigned int offset = MPIC_INFO(TIMER_VECTOR_PRI) +
225 ((tm & 3) * MPIC_INFO(TIMER_STRIDE));
226
227 if (tm >= 4)
228 offset += 0x1000 / 4;
229
230 return _mpic_read(mpic->reg_type, &mpic->tmregs, offset);
231 }
232
233 static inline void _mpic_tm_write(struct mpic *mpic, unsigned int tm, u32 value)
234 {
235 unsigned int offset = MPIC_INFO(TIMER_VECTOR_PRI) +
236 ((tm & 3) * MPIC_INFO(TIMER_STRIDE));
237
238 if (tm >= 4)
239 offset += 0x1000 / 4;
240
241 _mpic_write(mpic->reg_type, &mpic->tmregs, offset, value);
242 }
243
244 static inline u32 _mpic_cpu_read(struct mpic *mpic, unsigned int reg)
245 {
246 unsigned int cpu = mpic_processor_id(mpic);
247
248 return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg);
249 }
250
251 static inline void _mpic_cpu_write(struct mpic *mpic, unsigned int reg, u32 value)
252 {
253 unsigned int cpu = mpic_processor_id(mpic);
254
255 _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value);
256 }
257
258 static inline u32 _mpic_irq_read(struct mpic *mpic, unsigned int src_no, unsigned int reg)
259 {
260 unsigned int isu = src_no >> mpic->isu_shift;
261 unsigned int idx = src_no & mpic->isu_mask;
262 unsigned int val;
263
264 val = _mpic_read(mpic->reg_type, &mpic->isus[isu],
265 reg + (idx * MPIC_INFO(IRQ_STRIDE)));
266 #ifdef CONFIG_MPIC_BROKEN_REGREAD
267 if (reg == 0)
268 val = (val & (MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY)) |
269 mpic->isu_reg0_shadow[src_no];
270 #endif
271 return val;
272 }
273
274 static inline void _mpic_irq_write(struct mpic *mpic, unsigned int src_no,
275 unsigned int reg, u32 value)
276 {
277 unsigned int isu = src_no >> mpic->isu_shift;
278 unsigned int idx = src_no & mpic->isu_mask;
279
280 _mpic_write(mpic->reg_type, &mpic->isus[isu],
281 reg + (idx * MPIC_INFO(IRQ_STRIDE)), value);
282
283 #ifdef CONFIG_MPIC_BROKEN_REGREAD
284 if (reg == 0)
285 mpic->isu_reg0_shadow[src_no] =
286 value & ~(MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY);
287 #endif
288 }
289
290 #define mpic_read(b,r) _mpic_read(mpic->reg_type,&(b),(r))
291 #define mpic_write(b,r,v) _mpic_write(mpic->reg_type,&(b),(r),(v))
292 #define mpic_ipi_read(i) _mpic_ipi_read(mpic,(i))
293 #define mpic_ipi_write(i,v) _mpic_ipi_write(mpic,(i),(v))
294 #define mpic_tm_read(i) _mpic_tm_read(mpic,(i))
295 #define mpic_tm_write(i,v) _mpic_tm_write(mpic,(i),(v))
296 #define mpic_cpu_read(i) _mpic_cpu_read(mpic,(i))
297 #define mpic_cpu_write(i,v) _mpic_cpu_write(mpic,(i),(v))
298 #define mpic_irq_read(s,r) _mpic_irq_read(mpic,(s),(r))
299 #define mpic_irq_write(s,r,v) _mpic_irq_write(mpic,(s),(r),(v))
300
301
302 /*
303 * Low level utility functions
304 */
305
306
307 static void _mpic_map_mmio(struct mpic *mpic, phys_addr_t phys_addr,
308 struct mpic_reg_bank *rb, unsigned int offset,
309 unsigned int size)
310 {
311 rb->base = ioremap(phys_addr + offset, size);
312 BUG_ON(rb->base == NULL);
313 }
314
315 #ifdef CONFIG_PPC_DCR
316 static void _mpic_map_dcr(struct mpic *mpic, struct device_node *node,
317 struct mpic_reg_bank *rb,
318 unsigned int offset, unsigned int size)
319 {
320 const u32 *dbasep;
321
322 dbasep = of_get_property(node, "dcr-reg", NULL);
323
324 rb->dhost = dcr_map(node, *dbasep + offset, size);
325 BUG_ON(!DCR_MAP_OK(rb->dhost));
326 }
327
328 static inline void mpic_map(struct mpic *mpic, struct device_node *node,
329 phys_addr_t phys_addr, struct mpic_reg_bank *rb,
330 unsigned int offset, unsigned int size)
331 {
332 if (mpic->flags & MPIC_USES_DCR)
333 _mpic_map_dcr(mpic, node, rb, offset, size);
334 else
335 _mpic_map_mmio(mpic, phys_addr, rb, offset, size);
336 }
337 #else /* CONFIG_PPC_DCR */
338 #define mpic_map(m,n,p,b,o,s) _mpic_map_mmio(m,p,b,o,s)
339 #endif /* !CONFIG_PPC_DCR */
340
341
342
343 /* Check if we have one of those nice broken MPICs with a flipped endian on
344 * reads from IPI registers
345 */
346 static void __init mpic_test_broken_ipi(struct mpic *mpic)
347 {
348 u32 r;
349
350 mpic_write(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0), MPIC_VECPRI_MASK);
351 r = mpic_read(mpic->gregs, MPIC_INFO(GREG_IPI_VECTOR_PRI_0));
352
353 if (r == le32_to_cpu(MPIC_VECPRI_MASK)) {
354 printk(KERN_INFO "mpic: Detected reversed IPI registers\n");
355 mpic->flags |= MPIC_BROKEN_IPI;
356 }
357 }
358
359 #ifdef CONFIG_MPIC_U3_HT_IRQS
360
361 /* Test if an interrupt is sourced from HyperTransport (used on broken U3s)
362 * to force the edge setting on the MPIC and do the ack workaround.
363 */
364 static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
365 {
366 if (source >= 128 || !mpic->fixups)
367 return 0;
368 return mpic->fixups[source].base != NULL;
369 }
370
371
372 static inline void mpic_ht_end_irq(struct mpic *mpic, unsigned int source)
373 {
374 struct mpic_irq_fixup *fixup = &mpic->fixups[source];
375
376 if (fixup->applebase) {
377 unsigned int soff = (fixup->index >> 3) & ~3;
378 unsigned int mask = 1U << (fixup->index & 0x1f);
379 writel(mask, fixup->applebase + soff);
380 } else {
381 raw_spin_lock(&mpic->fixup_lock);
382 writeb(0x11 + 2 * fixup->index, fixup->base + 2);
383 writel(fixup->data, fixup->base + 4);
384 raw_spin_unlock(&mpic->fixup_lock);
385 }
386 }
387
388 static void mpic_startup_ht_interrupt(struct mpic *mpic, unsigned int source,
389 bool level)
390 {
391 struct mpic_irq_fixup *fixup = &mpic->fixups[source];
392 unsigned long flags;
393 u32 tmp;
394
395 if (fixup->base == NULL)
396 return;
397
398 DBG("startup_ht_interrupt(0x%x) index: %d\n",
399 source, fixup->index);
400 raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
401 /* Enable and configure */
402 writeb(0x10 + 2 * fixup->index, fixup->base + 2);
403 tmp = readl(fixup->base + 4);
404 tmp &= ~(0x23U);
405 if (level)
406 tmp |= 0x22;
407 writel(tmp, fixup->base + 4);
408 raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
409
410 #ifdef CONFIG_PM
411 /* use the lowest bit inverted to the actual HW,
412 * set if this fixup was enabled, clear otherwise */
413 mpic->save_data[source].fixup_data = tmp | 1;
414 #endif
415 }
416
417 static void mpic_shutdown_ht_interrupt(struct mpic *mpic, unsigned int source)
418 {
419 struct mpic_irq_fixup *fixup = &mpic->fixups[source];
420 unsigned long flags;
421 u32 tmp;
422
423 if (fixup->base == NULL)
424 return;
425
426 DBG("shutdown_ht_interrupt(0x%x)\n", source);
427
428 /* Disable */
429 raw_spin_lock_irqsave(&mpic->fixup_lock, flags);
430 writeb(0x10 + 2 * fixup->index, fixup->base + 2);
431 tmp = readl(fixup->base + 4);
432 tmp |= 1;
433 writel(tmp, fixup->base + 4);
434 raw_spin_unlock_irqrestore(&mpic->fixup_lock, flags);
435
436 #ifdef CONFIG_PM
437 /* use the lowest bit inverted to the actual HW,
438 * set if this fixup was enabled, clear otherwise */
439 mpic->save_data[source].fixup_data = tmp & ~1;
440 #endif
441 }
442
443 #ifdef CONFIG_PCI_MSI
444 static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase,
445 unsigned int devfn)
446 {
447 u8 __iomem *base;
448 u8 pos, flags;
449 u64 addr = 0;
450
451 for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0;
452 pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) {
453 u8 id = readb(devbase + pos + PCI_CAP_LIST_ID);
454 if (id == PCI_CAP_ID_HT) {
455 id = readb(devbase + pos + 3);
456 if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_MSI_MAPPING)
457 break;
458 }
459 }
460
461 if (pos == 0)
462 return;
463
464 base = devbase + pos;
465
466 flags = readb(base + HT_MSI_FLAGS);
467 if (!(flags & HT_MSI_FLAGS_FIXED)) {
468 addr = readl(base + HT_MSI_ADDR_LO) & HT_MSI_ADDR_LO_MASK;
469 addr = addr | ((u64)readl(base + HT_MSI_ADDR_HI) << 32);
470 }
471
472 printk(KERN_DEBUG "mpic: - HT:%02x.%x %s MSI mapping found @ 0x%llx\n",
473 PCI_SLOT(devfn), PCI_FUNC(devfn),
474 flags & HT_MSI_FLAGS_ENABLE ? "enabled" : "disabled", addr);
475
476 if (!(flags & HT_MSI_FLAGS_ENABLE))
477 writeb(flags | HT_MSI_FLAGS_ENABLE, base + HT_MSI_FLAGS);
478 }
479 #else
480 static void __init mpic_scan_ht_msi(struct mpic *mpic, u8 __iomem *devbase,
481 unsigned int devfn)
482 {
483 return;
484 }
485 #endif
486
487 static void __init mpic_scan_ht_pic(struct mpic *mpic, u8 __iomem *devbase,
488 unsigned int devfn, u32 vdid)
489 {
490 int i, irq, n;
491 u8 __iomem *base;
492 u32 tmp;
493 u8 pos;
494
495 for (pos = readb(devbase + PCI_CAPABILITY_LIST); pos != 0;
496 pos = readb(devbase + pos + PCI_CAP_LIST_NEXT)) {
497 u8 id = readb(devbase + pos + PCI_CAP_LIST_ID);
498 if (id == PCI_CAP_ID_HT) {
499 id = readb(devbase + pos + 3);
500 if ((id & HT_5BIT_CAP_MASK) == HT_CAPTYPE_IRQ)
501 break;
502 }
503 }
504 if (pos == 0)
505 return;
506
507 base = devbase + pos;
508 writeb(0x01, base + 2);
509 n = (readl(base + 4) >> 16) & 0xff;
510
511 printk(KERN_INFO "mpic: - HT:%02x.%x [0x%02x] vendor %04x device %04x"
512 " has %d irqs\n",
513 devfn >> 3, devfn & 0x7, pos, vdid & 0xffff, vdid >> 16, n + 1);
514
515 for (i = 0; i <= n; i++) {
516 writeb(0x10 + 2 * i, base + 2);
517 tmp = readl(base + 4);
518 irq = (tmp >> 16) & 0xff;
519 DBG("HT PIC index 0x%x, irq 0x%x, tmp: %08x\n", i, irq, tmp);
520 /* mask it , will be unmasked later */
521 tmp |= 0x1;
522 writel(tmp, base + 4);
523 mpic->fixups[irq].index = i;
524 mpic->fixups[irq].base = base;
525 /* Apple HT PIC has a non-standard way of doing EOIs */
526 if ((vdid & 0xffff) == 0x106b)
527 mpic->fixups[irq].applebase = devbase + 0x60;
528 else
529 mpic->fixups[irq].applebase = NULL;
530 writeb(0x11 + 2 * i, base + 2);
531 mpic->fixups[irq].data = readl(base + 4) | 0x80000000;
532 }
533 }
534
535
536 static void __init mpic_scan_ht_pics(struct mpic *mpic)
537 {
538 unsigned int devfn;
539 u8 __iomem *cfgspace;
540
541 printk(KERN_INFO "mpic: Setting up HT PICs workarounds for U3/U4\n");
542
543 /* Allocate fixups array */
544 mpic->fixups = kzalloc(128 * sizeof(*mpic->fixups), GFP_KERNEL);
545 BUG_ON(mpic->fixups == NULL);
546
547 /* Init spinlock */
548 raw_spin_lock_init(&mpic->fixup_lock);
549
550 /* Map U3 config space. We assume all IO-APICs are on the primary bus
551 * so we only need to map 64kB.
552 */
553 cfgspace = ioremap(0xf2000000, 0x10000);
554 BUG_ON(cfgspace == NULL);
555
556 /* Now we scan all slots. We do a very quick scan, we read the header
557 * type, vendor ID and device ID only, that's plenty enough
558 */
559 for (devfn = 0; devfn < 0x100; devfn++) {
560 u8 __iomem *devbase = cfgspace + (devfn << 8);
561 u8 hdr_type = readb(devbase + PCI_HEADER_TYPE);
562 u32 l = readl(devbase + PCI_VENDOR_ID);
563 u16 s;
564
565 DBG("devfn %x, l: %x\n", devfn, l);
566
567 /* If no device, skip */
568 if (l == 0xffffffff || l == 0x00000000 ||
569 l == 0x0000ffff || l == 0xffff0000)
570 goto next;
571 /* Check if is supports capability lists */
572 s = readw(devbase + PCI_STATUS);
573 if (!(s & PCI_STATUS_CAP_LIST))
574 goto next;
575
576 mpic_scan_ht_pic(mpic, devbase, devfn, l);
577 mpic_scan_ht_msi(mpic, devbase, devfn);
578
579 next:
580 /* next device, if function 0 */
581 if (PCI_FUNC(devfn) == 0 && (hdr_type & 0x80) == 0)
582 devfn += 7;
583 }
584 }
585
586 #else /* CONFIG_MPIC_U3_HT_IRQS */
587
588 static inline int mpic_is_ht_interrupt(struct mpic *mpic, unsigned int source)
589 {
590 return 0;
591 }
592
593 static void __init mpic_scan_ht_pics(struct mpic *mpic)
594 {
595 }
596
597 #endif /* CONFIG_MPIC_U3_HT_IRQS */
598
599 #ifdef CONFIG_SMP
600 static int irq_choose_cpu(const struct cpumask *mask)
601 {
602 int cpuid;
603
604 if (cpumask_equal(mask, cpu_all_mask)) {
605 static int irq_rover = 0;
606 static DEFINE_RAW_SPINLOCK(irq_rover_lock);
607 unsigned long flags;
608
609 /* Round-robin distribution... */
610 do_round_robin:
611 raw_spin_lock_irqsave(&irq_rover_lock, flags);
612
613 irq_rover = cpumask_next(irq_rover, cpu_online_mask);
614 if (irq_rover >= nr_cpu_ids)
615 irq_rover = cpumask_first(cpu_online_mask);
616
617 cpuid = irq_rover;
618
619 raw_spin_unlock_irqrestore(&irq_rover_lock, flags);
620 } else {
621 cpuid = cpumask_first_and(mask, cpu_online_mask);
622 if (cpuid >= nr_cpu_ids)
623 goto do_round_robin;
624 }
625
626 return get_hard_smp_processor_id(cpuid);
627 }
628 #else
629 static int irq_choose_cpu(const struct cpumask *mask)
630 {
631 return hard_smp_processor_id();
632 }
633 #endif
634
635 /* Find an mpic associated with a given linux interrupt */
636 static struct mpic *mpic_find(unsigned int irq)
637 {
638 if (irq < NUM_ISA_INTERRUPTS)
639 return NULL;
640
641 return irq_get_chip_data(irq);
642 }
643
644 /* Determine if the linux irq is an IPI */
645 static unsigned int mpic_is_ipi(struct mpic *mpic, unsigned int irq)
646 {
647 unsigned int src = virq_to_hw(irq);
648
649 return (src >= mpic->ipi_vecs[0] && src <= mpic->ipi_vecs[3]);
650 }
651
652 /* Determine if the linux irq is a timer */
653 static unsigned int mpic_is_tm(struct mpic *mpic, unsigned int irq)
654 {
655 unsigned int src = virq_to_hw(irq);
656
657 return (src >= mpic->timer_vecs[0] && src <= mpic->timer_vecs[7]);
658 }
659
660 /* Convert a cpu mask from logical to physical cpu numbers. */
661 static inline u32 mpic_physmask(u32 cpumask)
662 {
663 int i;
664 u32 mask = 0;
665
666 for (i = 0; i < NR_CPUS; ++i, cpumask >>= 1)
667 mask |= (cpumask & 1) << get_hard_smp_processor_id(i);
668 return mask;
669 }
670
671 #ifdef CONFIG_SMP
672 /* Get the mpic structure from the IPI number */
673 static inline struct mpic * mpic_from_ipi(struct irq_data *d)
674 {
675 return irq_data_get_irq_chip_data(d);
676 }
677 #endif
678
679 /* Get the mpic structure from the irq number */
680 static inline struct mpic * mpic_from_irq(unsigned int irq)
681 {
682 return irq_get_chip_data(irq);
683 }
684
685 /* Get the mpic structure from the irq data */
686 static inline struct mpic * mpic_from_irq_data(struct irq_data *d)
687 {
688 return irq_data_get_irq_chip_data(d);
689 }
690
691 /* Send an EOI */
692 static inline void mpic_eoi(struct mpic *mpic)
693 {
694 mpic_cpu_write(MPIC_INFO(CPU_EOI), 0);
695 (void)mpic_cpu_read(MPIC_INFO(CPU_WHOAMI));
696 }
697
698 /*
699 * Linux descriptor level callbacks
700 */
701
702
703 void mpic_unmask_irq(struct irq_data *d)
704 {
705 unsigned int loops = 100000;
706 struct mpic *mpic = mpic_from_irq_data(d);
707 unsigned int src = irqd_to_hwirq(d);
708
709 DBG("%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, d->irq, src);
710
711 mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
712 mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) &
713 ~MPIC_VECPRI_MASK);
714 /* make sure mask gets to controller before we return to user */
715 do {
716 if (!loops--) {
717 printk(KERN_ERR "%s: timeout on hwirq %u\n",
718 __func__, src);
719 break;
720 }
721 } while(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK);
722 }
723
724 void mpic_mask_irq(struct irq_data *d)
725 {
726 unsigned int loops = 100000;
727 struct mpic *mpic = mpic_from_irq_data(d);
728 unsigned int src = irqd_to_hwirq(d);
729
730 DBG("%s: disable_irq: %d (src %d)\n", mpic->name, d->irq, src);
731
732 mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
733 mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) |
734 MPIC_VECPRI_MASK);
735
736 /* make sure mask gets to controller before we return to user */
737 do {
738 if (!loops--) {
739 printk(KERN_ERR "%s: timeout on hwirq %u\n",
740 __func__, src);
741 break;
742 }
743 } while(!(mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI)) & MPIC_VECPRI_MASK));
744 }
745
746 void mpic_end_irq(struct irq_data *d)
747 {
748 struct mpic *mpic = mpic_from_irq_data(d);
749
750 #ifdef DEBUG_IRQ
751 DBG("%s: end_irq: %d\n", mpic->name, d->irq);
752 #endif
753 /* We always EOI on end_irq() even for edge interrupts since that
754 * should only lower the priority, the MPIC should have properly
755 * latched another edge interrupt coming in anyway
756 */
757
758 mpic_eoi(mpic);
759 }
760
761 #ifdef CONFIG_MPIC_U3_HT_IRQS
762
763 static void mpic_unmask_ht_irq(struct irq_data *d)
764 {
765 struct mpic *mpic = mpic_from_irq_data(d);
766 unsigned int src = irqd_to_hwirq(d);
767
768 mpic_unmask_irq(d);
769
770 if (irqd_is_level_type(d))
771 mpic_ht_end_irq(mpic, src);
772 }
773
774 static unsigned int mpic_startup_ht_irq(struct irq_data *d)
775 {
776 struct mpic *mpic = mpic_from_irq_data(d);
777 unsigned int src = irqd_to_hwirq(d);
778
779 mpic_unmask_irq(d);
780 mpic_startup_ht_interrupt(mpic, src, irqd_is_level_type(d));
781
782 return 0;
783 }
784
785 static void mpic_shutdown_ht_irq(struct irq_data *d)
786 {
787 struct mpic *mpic = mpic_from_irq_data(d);
788 unsigned int src = irqd_to_hwirq(d);
789
790 mpic_shutdown_ht_interrupt(mpic, src);
791 mpic_mask_irq(d);
792 }
793
794 static void mpic_end_ht_irq(struct irq_data *d)
795 {
796 struct mpic *mpic = mpic_from_irq_data(d);
797 unsigned int src = irqd_to_hwirq(d);
798
799 #ifdef DEBUG_IRQ
800 DBG("%s: end_irq: %d\n", mpic->name, d->irq);
801 #endif
802 /* We always EOI on end_irq() even for edge interrupts since that
803 * should only lower the priority, the MPIC should have properly
804 * latched another edge interrupt coming in anyway
805 */
806
807 if (irqd_is_level_type(d))
808 mpic_ht_end_irq(mpic, src);
809 mpic_eoi(mpic);
810 }
811 #endif /* !CONFIG_MPIC_U3_HT_IRQS */
812
813 #ifdef CONFIG_SMP
814
815 static void mpic_unmask_ipi(struct irq_data *d)
816 {
817 struct mpic *mpic = mpic_from_ipi(d);
818 unsigned int src = virq_to_hw(d->irq) - mpic->ipi_vecs[0];
819
820 DBG("%s: enable_ipi: %d (ipi %d)\n", mpic->name, d->irq, src);
821 mpic_ipi_write(src, mpic_ipi_read(src) & ~MPIC_VECPRI_MASK);
822 }
823
824 static void mpic_mask_ipi(struct irq_data *d)
825 {
826 /* NEVER disable an IPI... that's just plain wrong! */
827 }
828
829 static void mpic_end_ipi(struct irq_data *d)
830 {
831 struct mpic *mpic = mpic_from_ipi(d);
832
833 /*
834 * IPIs are marked IRQ_PER_CPU. This has the side effect of
835 * preventing the IRQ_PENDING/IRQ_INPROGRESS logic from
836 * applying to them. We EOI them late to avoid re-entering.
837 * We mark IPI's with IRQF_DISABLED as they must run with
838 * irqs disabled.
839 */
840 mpic_eoi(mpic);
841 }
842
843 #endif /* CONFIG_SMP */
844
845 static void mpic_unmask_tm(struct irq_data *d)
846 {
847 struct mpic *mpic = mpic_from_irq_data(d);
848 unsigned int src = virq_to_hw(d->irq) - mpic->timer_vecs[0];
849
850 DBG("%s: enable_tm: %d (tm %d)\n", mpic->name, irq, src);
851 mpic_tm_write(src, mpic_tm_read(src) & ~MPIC_VECPRI_MASK);
852 mpic_tm_read(src);
853 }
854
855 static void mpic_mask_tm(struct irq_data *d)
856 {
857 struct mpic *mpic = mpic_from_irq_data(d);
858 unsigned int src = virq_to_hw(d->irq) - mpic->timer_vecs[0];
859
860 mpic_tm_write(src, mpic_tm_read(src) | MPIC_VECPRI_MASK);
861 mpic_tm_read(src);
862 }
863
864 int mpic_set_affinity(struct irq_data *d, const struct cpumask *cpumask,
865 bool force)
866 {
867 struct mpic *mpic = mpic_from_irq_data(d);
868 unsigned int src = irqd_to_hwirq(d);
869
870 if (mpic->flags & MPIC_SINGLE_DEST_CPU) {
871 int cpuid = irq_choose_cpu(cpumask);
872
873 mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
874 } else {
875 cpumask_var_t tmp;
876
877 alloc_cpumask_var(&tmp, GFP_KERNEL);
878
879 cpumask_and(tmp, cpumask, cpu_online_mask);
880
881 mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION),
882 mpic_physmask(cpumask_bits(tmp)[0]));
883
884 free_cpumask_var(tmp);
885 }
886
887 return 0;
888 }
889
890 static unsigned int mpic_type_to_vecpri(struct mpic *mpic, unsigned int type)
891 {
892 /* Now convert sense value */
893 switch(type & IRQ_TYPE_SENSE_MASK) {
894 case IRQ_TYPE_EDGE_RISING:
895 return MPIC_INFO(VECPRI_SENSE_EDGE) |
896 MPIC_INFO(VECPRI_POLARITY_POSITIVE);
897 case IRQ_TYPE_EDGE_FALLING:
898 case IRQ_TYPE_EDGE_BOTH:
899 return MPIC_INFO(VECPRI_SENSE_EDGE) |
900 MPIC_INFO(VECPRI_POLARITY_NEGATIVE);
901 case IRQ_TYPE_LEVEL_HIGH:
902 return MPIC_INFO(VECPRI_SENSE_LEVEL) |
903 MPIC_INFO(VECPRI_POLARITY_POSITIVE);
904 case IRQ_TYPE_LEVEL_LOW:
905 default:
906 return MPIC_INFO(VECPRI_SENSE_LEVEL) |
907 MPIC_INFO(VECPRI_POLARITY_NEGATIVE);
908 }
909 }
910
911 int mpic_set_irq_type(struct irq_data *d, unsigned int flow_type)
912 {
913 struct mpic *mpic = mpic_from_irq_data(d);
914 unsigned int src = irqd_to_hwirq(d);
915 unsigned int vecpri, vold, vnew;
916
917 DBG("mpic: set_irq_type(mpic:@%p,virq:%d,src:0x%x,type:0x%x)\n",
918 mpic, d->irq, src, flow_type);
919
920 if (src >= mpic->irq_count)
921 return -EINVAL;
922
923 if (flow_type == IRQ_TYPE_NONE)
924 if (mpic->senses && src < mpic->senses_count)
925 flow_type = mpic->senses[src];
926 if (flow_type == IRQ_TYPE_NONE)
927 flow_type = IRQ_TYPE_LEVEL_LOW;
928
929 irqd_set_trigger_type(d, flow_type);
930
931 if (mpic_is_ht_interrupt(mpic, src))
932 vecpri = MPIC_VECPRI_POLARITY_POSITIVE |
933 MPIC_VECPRI_SENSE_EDGE;
934 else
935 vecpri = mpic_type_to_vecpri(mpic, flow_type);
936
937 vold = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
938 vnew = vold & ~(MPIC_INFO(VECPRI_POLARITY_MASK) |
939 MPIC_INFO(VECPRI_SENSE_MASK));
940 vnew |= vecpri;
941 if (vold != vnew)
942 mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vnew);
943
944 return IRQ_SET_MASK_OK_NOCOPY;;
945 }
946
947 void mpic_set_vector(unsigned int virq, unsigned int vector)
948 {
949 struct mpic *mpic = mpic_from_irq(virq);
950 unsigned int src = virq_to_hw(virq);
951 unsigned int vecpri;
952
953 DBG("mpic: set_vector(mpic:@%p,virq:%d,src:%d,vector:0x%x)\n",
954 mpic, virq, src, vector);
955
956 if (src >= mpic->irq_count)
957 return;
958
959 vecpri = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI));
960 vecpri = vecpri & ~MPIC_INFO(VECPRI_VECTOR_MASK);
961 vecpri |= vector;
962 mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
963 }
964
965 void mpic_set_destination(unsigned int virq, unsigned int cpuid)
966 {
967 struct mpic *mpic = mpic_from_irq(virq);
968 unsigned int src = virq_to_hw(virq);
969
970 DBG("mpic: set_destination(mpic:@%p,virq:%d,src:%d,cpuid:0x%x)\n",
971 mpic, virq, src, cpuid);
972
973 if (src >= mpic->irq_count)
974 return;
975
976 mpic_irq_write(src, MPIC_INFO(IRQ_DESTINATION), 1 << cpuid);
977 }
978
979 static struct irq_chip mpic_irq_chip = {
980 .irq_mask = mpic_mask_irq,
981 .irq_unmask = mpic_unmask_irq,
982 .irq_eoi = mpic_end_irq,
983 .irq_set_type = mpic_set_irq_type,
984 };
985
986 #ifdef CONFIG_SMP
987 static struct irq_chip mpic_ipi_chip = {
988 .irq_mask = mpic_mask_ipi,
989 .irq_unmask = mpic_unmask_ipi,
990 .irq_eoi = mpic_end_ipi,
991 };
992 #endif /* CONFIG_SMP */
993
994 static struct irq_chip mpic_tm_chip = {
995 .irq_mask = mpic_mask_tm,
996 .irq_unmask = mpic_unmask_tm,
997 .irq_eoi = mpic_end_irq,
998 };
999
1000 #ifdef CONFIG_MPIC_U3_HT_IRQS
1001 static struct irq_chip mpic_irq_ht_chip = {
1002 .irq_startup = mpic_startup_ht_irq,
1003 .irq_shutdown = mpic_shutdown_ht_irq,
1004 .irq_mask = mpic_mask_irq,
1005 .irq_unmask = mpic_unmask_ht_irq,
1006 .irq_eoi = mpic_end_ht_irq,
1007 .irq_set_type = mpic_set_irq_type,
1008 };
1009 #endif /* CONFIG_MPIC_U3_HT_IRQS */
1010
1011
1012 static int mpic_host_match(struct irq_host *h, struct device_node *node)
1013 {
1014 /* Exact match, unless mpic node is NULL */
1015 return h->of_node == NULL || h->of_node == node;
1016 }
1017
1018 static int mpic_host_map(struct irq_host *h, unsigned int virq,
1019 irq_hw_number_t hw)
1020 {
1021 struct mpic *mpic = h->host_data;
1022 struct irq_chip *chip;
1023
1024 DBG("mpic: map virq %d, hwirq 0x%lx\n", virq, hw);
1025
1026 if (hw == mpic->spurious_vec)
1027 return -EINVAL;
1028 if (mpic->protected && test_bit(hw, mpic->protected))
1029 return -EINVAL;
1030
1031 #ifdef CONFIG_SMP
1032 else if (hw >= mpic->ipi_vecs[0]) {
1033 WARN_ON(!(mpic->flags & MPIC_PRIMARY));
1034
1035 DBG("mpic: mapping as IPI\n");
1036 irq_set_chip_data(virq, mpic);
1037 irq_set_chip_and_handler(virq, &mpic->hc_ipi,
1038 handle_percpu_irq);
1039 return 0;
1040 }
1041 #endif /* CONFIG_SMP */
1042
1043 if (hw >= mpic->timer_vecs[0] && hw <= mpic->timer_vecs[7]) {
1044 WARN_ON(!(mpic->flags & MPIC_PRIMARY));
1045
1046 DBG("mpic: mapping as timer\n");
1047 irq_set_chip_data(virq, mpic);
1048 irq_set_chip_and_handler(virq, &mpic->hc_tm,
1049 handle_fasteoi_irq);
1050 return 0;
1051 }
1052
1053 if (hw >= mpic->irq_count)
1054 return -EINVAL;
1055
1056 mpic_msi_reserve_hwirq(mpic, hw);
1057
1058 /* Default chip */
1059 chip = &mpic->hc_irq;
1060
1061 #ifdef CONFIG_MPIC_U3_HT_IRQS
1062 /* Check for HT interrupts, override vecpri */
1063 if (mpic_is_ht_interrupt(mpic, hw))
1064 chip = &mpic->hc_ht_irq;
1065 #endif /* CONFIG_MPIC_U3_HT_IRQS */
1066
1067 DBG("mpic: mapping to irq chip @%p\n", chip);
1068
1069 irq_set_chip_data(virq, mpic);
1070 irq_set_chip_and_handler(virq, chip, handle_fasteoi_irq);
1071
1072 /* Set default irq type */
1073 irq_set_irq_type(virq, IRQ_TYPE_NONE);
1074
1075 /* If the MPIC was reset, then all vectors have already been
1076 * initialized. Otherwise, a per source lazy initialization
1077 * is done here.
1078 */
1079 if (!mpic_is_ipi(mpic, hw) && (mpic->flags & MPIC_NO_RESET)) {
1080 mpic_set_vector(virq, hw);
1081 mpic_set_destination(virq, mpic_processor_id(mpic));
1082 mpic_irq_set_priority(virq, 8);
1083 }
1084
1085 return 0;
1086 }
1087
1088 static int mpic_host_xlate(struct irq_host *h, struct device_node *ct,
1089 const u32 *intspec, unsigned int intsize,
1090 irq_hw_number_t *out_hwirq, unsigned int *out_flags)
1091
1092 {
1093 struct mpic *mpic = h->host_data;
1094 static unsigned char map_mpic_senses[4] = {
1095 IRQ_TYPE_EDGE_RISING,
1096 IRQ_TYPE_LEVEL_LOW,
1097 IRQ_TYPE_LEVEL_HIGH,
1098 IRQ_TYPE_EDGE_FALLING,
1099 };
1100
1101 *out_hwirq = intspec[0];
1102 if (intsize >= 4 && (mpic->flags & MPIC_FSL)) {
1103 /*
1104 * Freescale MPIC with extended intspec:
1105 * First two cells are as usual. Third specifies
1106 * an "interrupt type". Fourth is type-specific data.
1107 *
1108 * See Documentation/devicetree/bindings/powerpc/fsl/mpic.txt
1109 */
1110 switch (intspec[2]) {
1111 case 0:
1112 case 1: /* no EISR/EIMR support for now, treat as shared IRQ */
1113 break;
1114 case 2:
1115 if (intspec[0] >= ARRAY_SIZE(mpic->ipi_vecs))
1116 return -EINVAL;
1117
1118 *out_hwirq = mpic->ipi_vecs[intspec[0]];
1119 break;
1120 case 3:
1121 if (intspec[0] >= ARRAY_SIZE(mpic->timer_vecs))
1122 return -EINVAL;
1123
1124 *out_hwirq = mpic->timer_vecs[intspec[0]];
1125 break;
1126 default:
1127 pr_debug("%s: unknown irq type %u\n",
1128 __func__, intspec[2]);
1129 return -EINVAL;
1130 }
1131
1132 *out_flags = map_mpic_senses[intspec[1] & 3];
1133 } else if (intsize > 1) {
1134 u32 mask = 0x3;
1135
1136 /* Apple invented a new race of encoding on machines with
1137 * an HT APIC. They encode, among others, the index within
1138 * the HT APIC. We don't care about it here since thankfully,
1139 * it appears that they have the APIC already properly
1140 * configured, and thus our current fixup code that reads the
1141 * APIC config works fine. However, we still need to mask out
1142 * bits in the specifier to make sure we only get bit 0 which
1143 * is the level/edge bit (the only sense bit exposed by Apple),
1144 * as their bit 1 means something else.
1145 */
1146 if (machine_is(powermac))
1147 mask = 0x1;
1148 *out_flags = map_mpic_senses[intspec[1] & mask];
1149 } else
1150 *out_flags = IRQ_TYPE_NONE;
1151
1152 DBG("mpic: xlate (%d cells: 0x%08x 0x%08x) to line 0x%lx sense 0x%x\n",
1153 intsize, intspec[0], intspec[1], *out_hwirq, *out_flags);
1154
1155 return 0;
1156 }
1157
1158 static struct irq_host_ops mpic_host_ops = {
1159 .match = mpic_host_match,
1160 .map = mpic_host_map,
1161 .xlate = mpic_host_xlate,
1162 };
1163
1164 static int mpic_reset_prohibited(struct device_node *node)
1165 {
1166 return node && of_get_property(node, "pic-no-reset", NULL);
1167 }
1168
1169 /*
1170 * Exported functions
1171 */
1172
1173 struct mpic * __init mpic_alloc(struct device_node *node,
1174 phys_addr_t phys_addr,
1175 unsigned int flags,
1176 unsigned int isu_size,
1177 unsigned int irq_count,
1178 const char *name)
1179 {
1180 struct mpic *mpic;
1181 u32 greg_feature;
1182 const char *vers;
1183 int i;
1184 int intvec_top;
1185 u64 paddr = phys_addr;
1186
1187 mpic = kzalloc(sizeof(struct mpic), GFP_KERNEL);
1188 if (mpic == NULL)
1189 return NULL;
1190
1191 mpic->name = name;
1192
1193 mpic->hc_irq = mpic_irq_chip;
1194 mpic->hc_irq.name = name;
1195 if (flags & MPIC_PRIMARY)
1196 mpic->hc_irq.irq_set_affinity = mpic_set_affinity;
1197 #ifdef CONFIG_MPIC_U3_HT_IRQS
1198 mpic->hc_ht_irq = mpic_irq_ht_chip;
1199 mpic->hc_ht_irq.name = name;
1200 if (flags & MPIC_PRIMARY)
1201 mpic->hc_ht_irq.irq_set_affinity = mpic_set_affinity;
1202 #endif /* CONFIG_MPIC_U3_HT_IRQS */
1203
1204 #ifdef CONFIG_SMP
1205 mpic->hc_ipi = mpic_ipi_chip;
1206 mpic->hc_ipi.name = name;
1207 #endif /* CONFIG_SMP */
1208
1209 mpic->hc_tm = mpic_tm_chip;
1210 mpic->hc_tm.name = name;
1211
1212 mpic->flags = flags;
1213 mpic->isu_size = isu_size;
1214 mpic->irq_count = irq_count;
1215 mpic->num_sources = 0; /* so far */
1216
1217 if (flags & MPIC_LARGE_VECTORS)
1218 intvec_top = 2047;
1219 else
1220 intvec_top = 255;
1221
1222 mpic->timer_vecs[0] = intvec_top - 12;
1223 mpic->timer_vecs[1] = intvec_top - 11;
1224 mpic->timer_vecs[2] = intvec_top - 10;
1225 mpic->timer_vecs[3] = intvec_top - 9;
1226 mpic->timer_vecs[4] = intvec_top - 8;
1227 mpic->timer_vecs[5] = intvec_top - 7;
1228 mpic->timer_vecs[6] = intvec_top - 6;
1229 mpic->timer_vecs[7] = intvec_top - 5;
1230 mpic->ipi_vecs[0] = intvec_top - 4;
1231 mpic->ipi_vecs[1] = intvec_top - 3;
1232 mpic->ipi_vecs[2] = intvec_top - 2;
1233 mpic->ipi_vecs[3] = intvec_top - 1;
1234 mpic->spurious_vec = intvec_top;
1235
1236 /* Check for "big-endian" in device-tree */
1237 if (node && of_get_property(node, "big-endian", NULL) != NULL)
1238 mpic->flags |= MPIC_BIG_ENDIAN;
1239 if (node && of_device_is_compatible(node, "fsl,mpic"))
1240 mpic->flags |= MPIC_FSL;
1241
1242 /* Look for protected sources */
1243 if (node) {
1244 int psize;
1245 unsigned int bits, mapsize;
1246 const u32 *psrc =
1247 of_get_property(node, "protected-sources", &psize);
1248 if (psrc) {
1249 psize /= 4;
1250 bits = intvec_top + 1;
1251 mapsize = BITS_TO_LONGS(bits) * sizeof(unsigned long);
1252 mpic->protected = kzalloc(mapsize, GFP_KERNEL);
1253 BUG_ON(mpic->protected == NULL);
1254 for (i = 0; i < psize; i++) {
1255 if (psrc[i] > intvec_top)
1256 continue;
1257 __set_bit(psrc[i], mpic->protected);
1258 }
1259 }
1260 }
1261
1262 #ifdef CONFIG_MPIC_WEIRD
1263 mpic->hw_set = mpic_infos[MPIC_GET_REGSET(flags)];
1264 #endif
1265
1266 /* default register type */
1267 mpic->reg_type = (flags & MPIC_BIG_ENDIAN) ?
1268 mpic_access_mmio_be : mpic_access_mmio_le;
1269
1270 /* If no physical address is passed in, a device-node is mandatory */
1271 BUG_ON(paddr == 0 && node == NULL);
1272
1273 /* If no physical address passed in, check if it's dcr based */
1274 if (paddr == 0 && of_get_property(node, "dcr-reg", NULL) != NULL) {
1275 #ifdef CONFIG_PPC_DCR
1276 mpic->flags |= MPIC_USES_DCR;
1277 mpic->reg_type = mpic_access_dcr;
1278 #else
1279 BUG();
1280 #endif /* CONFIG_PPC_DCR */
1281 }
1282
1283 /* If the MPIC is not DCR based, and no physical address was passed
1284 * in, try to obtain one
1285 */
1286 if (paddr == 0 && !(mpic->flags & MPIC_USES_DCR)) {
1287 const u32 *reg = of_get_property(node, "reg", NULL);
1288 BUG_ON(reg == NULL);
1289 paddr = of_translate_address(node, reg);
1290 BUG_ON(paddr == OF_BAD_ADDR);
1291 }
1292
1293 /* Map the global registers */
1294 mpic_map(mpic, node, paddr, &mpic->gregs, MPIC_INFO(GREG_BASE), 0x1000);
1295 mpic_map(mpic, node, paddr, &mpic->tmregs, MPIC_INFO(TIMER_BASE), 0x1000);
1296
1297 /* Reset */
1298
1299 /* When using a device-node, reset requests are only honored if the MPIC
1300 * is allowed to reset.
1301 */
1302 if (mpic_reset_prohibited(node))
1303 mpic->flags |= MPIC_NO_RESET;
1304
1305 if ((flags & MPIC_WANTS_RESET) && !(mpic->flags & MPIC_NO_RESET)) {
1306 printk(KERN_DEBUG "mpic: Resetting\n");
1307 mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
1308 mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1309 | MPIC_GREG_GCONF_RESET);
1310 while( mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1311 & MPIC_GREG_GCONF_RESET)
1312 mb();
1313 }
1314
1315 /* CoreInt */
1316 if (flags & MPIC_ENABLE_COREINT)
1317 mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
1318 mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1319 | MPIC_GREG_GCONF_COREINT);
1320
1321 if (flags & MPIC_ENABLE_MCK)
1322 mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
1323 mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1324 | MPIC_GREG_GCONF_MCK);
1325
1326 /* Read feature register, calculate num CPUs and, for non-ISU
1327 * MPICs, num sources as well. On ISU MPICs, sources are counted
1328 * as ISUs are added
1329 */
1330 greg_feature = mpic_read(mpic->gregs, MPIC_INFO(GREG_FEATURE_0));
1331 mpic->num_cpus = ((greg_feature & MPIC_GREG_FEATURE_LAST_CPU_MASK)
1332 >> MPIC_GREG_FEATURE_LAST_CPU_SHIFT) + 1;
1333 if (isu_size == 0) {
1334 if (flags & MPIC_BROKEN_FRR_NIRQS)
1335 mpic->num_sources = mpic->irq_count;
1336 else
1337 mpic->num_sources =
1338 ((greg_feature & MPIC_GREG_FEATURE_LAST_SRC_MASK)
1339 >> MPIC_GREG_FEATURE_LAST_SRC_SHIFT) + 1;
1340 }
1341
1342 /* Map the per-CPU registers */
1343 for (i = 0; i < mpic->num_cpus; i++) {
1344 mpic_map(mpic, node, paddr, &mpic->cpuregs[i],
1345 MPIC_INFO(CPU_BASE) + i * MPIC_INFO(CPU_STRIDE),
1346 0x1000);
1347 }
1348
1349 /* Initialize main ISU if none provided */
1350 if (mpic->isu_size == 0) {
1351 mpic->isu_size = mpic->num_sources;
1352 mpic_map(mpic, node, paddr, &mpic->isus[0],
1353 MPIC_INFO(IRQ_BASE), MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
1354 }
1355 mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1);
1356 mpic->isu_mask = (1 << mpic->isu_shift) - 1;
1357
1358 mpic->irqhost = irq_alloc_host(node, IRQ_HOST_MAP_LINEAR,
1359 isu_size ? isu_size : mpic->num_sources,
1360 &mpic_host_ops,
1361 flags & MPIC_LARGE_VECTORS ? 2048 : 256);
1362 if (mpic->irqhost == NULL)
1363 return NULL;
1364
1365 mpic->irqhost->host_data = mpic;
1366
1367 /* Display version */
1368 switch (greg_feature & MPIC_GREG_FEATURE_VERSION_MASK) {
1369 case 1:
1370 vers = "1.0";
1371 break;
1372 case 2:
1373 vers = "1.2";
1374 break;
1375 case 3:
1376 vers = "1.3";
1377 break;
1378 default:
1379 vers = "<unknown>";
1380 break;
1381 }
1382 printk(KERN_INFO "mpic: Setting up MPIC \"%s\" version %s at %llx,"
1383 " max %d CPUs\n",
1384 name, vers, (unsigned long long)paddr, mpic->num_cpus);
1385 printk(KERN_INFO "mpic: ISU size: %d, shift: %d, mask: %x\n",
1386 mpic->isu_size, mpic->isu_shift, mpic->isu_mask);
1387
1388 mpic->next = mpics;
1389 mpics = mpic;
1390
1391 if (flags & MPIC_PRIMARY) {
1392 mpic_primary = mpic;
1393 irq_set_default_host(mpic->irqhost);
1394 }
1395
1396 return mpic;
1397 }
1398
1399 void __init mpic_assign_isu(struct mpic *mpic, unsigned int isu_num,
1400 phys_addr_t paddr)
1401 {
1402 unsigned int isu_first = isu_num * mpic->isu_size;
1403
1404 BUG_ON(isu_num >= MPIC_MAX_ISU);
1405
1406 mpic_map(mpic, mpic->irqhost->of_node,
1407 paddr, &mpic->isus[isu_num], 0,
1408 MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
1409
1410 if ((isu_first + mpic->isu_size) > mpic->num_sources)
1411 mpic->num_sources = isu_first + mpic->isu_size;
1412 }
1413
1414 void __init mpic_set_default_senses(struct mpic *mpic, u8 *senses, int count)
1415 {
1416 mpic->senses = senses;
1417 mpic->senses_count = count;
1418 }
1419
1420 void __init mpic_init(struct mpic *mpic)
1421 {
1422 int i;
1423 int cpu;
1424
1425 BUG_ON(mpic->num_sources == 0);
1426
1427 printk(KERN_INFO "mpic: Initializing for %d sources\n", mpic->num_sources);
1428
1429 /* Set current processor priority to max */
1430 mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
1431
1432 /* Initialize timers to our reserved vectors and mask them for now */
1433 for (i = 0; i < 4; i++) {
1434 mpic_write(mpic->tmregs,
1435 i * MPIC_INFO(TIMER_STRIDE) +
1436 MPIC_INFO(TIMER_DESTINATION),
1437 1 << hard_smp_processor_id());
1438 mpic_write(mpic->tmregs,
1439 i * MPIC_INFO(TIMER_STRIDE) +
1440 MPIC_INFO(TIMER_VECTOR_PRI),
1441 MPIC_VECPRI_MASK |
1442 (9 << MPIC_VECPRI_PRIORITY_SHIFT) |
1443 (mpic->timer_vecs[0] + i));
1444 }
1445
1446 /* Initialize IPIs to our reserved vectors and mark them disabled for now */
1447 mpic_test_broken_ipi(mpic);
1448 for (i = 0; i < 4; i++) {
1449 mpic_ipi_write(i,
1450 MPIC_VECPRI_MASK |
1451 (10 << MPIC_VECPRI_PRIORITY_SHIFT) |
1452 (mpic->ipi_vecs[0] + i));
1453 }
1454
1455 /* Initialize interrupt sources */
1456 if (mpic->irq_count == 0)
1457 mpic->irq_count = mpic->num_sources;
1458
1459 /* Do the HT PIC fixups on U3 broken mpic */
1460 DBG("MPIC flags: %x\n", mpic->flags);
1461 if ((mpic->flags & MPIC_U3_HT_IRQS) && (mpic->flags & MPIC_PRIMARY)) {
1462 mpic_scan_ht_pics(mpic);
1463 mpic_u3msi_init(mpic);
1464 }
1465
1466 mpic_pasemi_msi_init(mpic);
1467
1468 cpu = mpic_processor_id(mpic);
1469
1470 if (!(mpic->flags & MPIC_NO_RESET)) {
1471 for (i = 0; i < mpic->num_sources; i++) {
1472 /* start with vector = source number, and masked */
1473 u32 vecpri = MPIC_VECPRI_MASK | i |
1474 (8 << MPIC_VECPRI_PRIORITY_SHIFT);
1475
1476 /* check if protected */
1477 if (mpic->protected && test_bit(i, mpic->protected))
1478 continue;
1479 /* init hw */
1480 mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI), vecpri);
1481 mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION), 1 << cpu);
1482 }
1483 }
1484
1485 /* Init spurious vector */
1486 mpic_write(mpic->gregs, MPIC_INFO(GREG_SPURIOUS), mpic->spurious_vec);
1487
1488 /* Disable 8259 passthrough, if supported */
1489 if (!(mpic->flags & MPIC_NO_PTHROU_DIS))
1490 mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
1491 mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1492 | MPIC_GREG_GCONF_8259_PTHROU_DIS);
1493
1494 if (mpic->flags & MPIC_NO_BIAS)
1495 mpic_write(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0),
1496 mpic_read(mpic->gregs, MPIC_INFO(GREG_GLOBAL_CONF_0))
1497 | MPIC_GREG_GCONF_NO_BIAS);
1498
1499 /* Set current processor priority to 0 */
1500 mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
1501
1502 #ifdef CONFIG_PM
1503 /* allocate memory to save mpic state */
1504 mpic->save_data = kmalloc(mpic->num_sources * sizeof(*mpic->save_data),
1505 GFP_KERNEL);
1506 BUG_ON(mpic->save_data == NULL);
1507 #endif
1508 }
1509
1510 void __init mpic_set_clk_ratio(struct mpic *mpic, u32 clock_ratio)
1511 {
1512 u32 v;
1513
1514 v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
1515 v &= ~MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK;
1516 v |= MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(clock_ratio);
1517 mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
1518 }
1519
1520 void __init mpic_set_serial_int(struct mpic *mpic, int enable)
1521 {
1522 unsigned long flags;
1523 u32 v;
1524
1525 raw_spin_lock_irqsave(&mpic_lock, flags);
1526 v = mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
1527 if (enable)
1528 v |= MPIC_GREG_GLOBAL_CONF_1_SIE;
1529 else
1530 v &= ~MPIC_GREG_GLOBAL_CONF_1_SIE;
1531 mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
1532 raw_spin_unlock_irqrestore(&mpic_lock, flags);
1533 }
1534
1535 void mpic_irq_set_priority(unsigned int irq, unsigned int pri)
1536 {
1537 struct mpic *mpic = mpic_find(irq);
1538 unsigned int src = virq_to_hw(irq);
1539 unsigned long flags;
1540 u32 reg;
1541
1542 if (!mpic)
1543 return;
1544
1545 raw_spin_lock_irqsave(&mpic_lock, flags);
1546 if (mpic_is_ipi(mpic, irq)) {
1547 reg = mpic_ipi_read(src - mpic->ipi_vecs[0]) &
1548 ~MPIC_VECPRI_PRIORITY_MASK;
1549 mpic_ipi_write(src - mpic->ipi_vecs[0],
1550 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1551 } else if (mpic_is_tm(mpic, irq)) {
1552 reg = mpic_tm_read(src - mpic->timer_vecs[0]) &
1553 ~MPIC_VECPRI_PRIORITY_MASK;
1554 mpic_tm_write(src - mpic->timer_vecs[0],
1555 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1556 } else {
1557 reg = mpic_irq_read(src, MPIC_INFO(IRQ_VECTOR_PRI))
1558 & ~MPIC_VECPRI_PRIORITY_MASK;
1559 mpic_irq_write(src, MPIC_INFO(IRQ_VECTOR_PRI),
1560 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1561 }
1562 raw_spin_unlock_irqrestore(&mpic_lock, flags);
1563 }
1564
1565 void mpic_setup_this_cpu(void)
1566 {
1567 #ifdef CONFIG_SMP
1568 struct mpic *mpic = mpic_primary;
1569 unsigned long flags;
1570 u32 msk = 1 << hard_smp_processor_id();
1571 unsigned int i;
1572
1573 BUG_ON(mpic == NULL);
1574
1575 DBG("%s: setup_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
1576
1577 raw_spin_lock_irqsave(&mpic_lock, flags);
1578
1579 /* let the mpic know we want intrs. default affinity is 0xffffffff
1580 * until changed via /proc. That's how it's done on x86. If we want
1581 * it differently, then we should make sure we also change the default
1582 * values of irq_desc[].affinity in irq.c.
1583 */
1584 if (distribute_irqs) {
1585 for (i = 0; i < mpic->num_sources ; i++)
1586 mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
1587 mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) | msk);
1588 }
1589
1590 /* Set current processor priority to 0 */
1591 mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0);
1592
1593 raw_spin_unlock_irqrestore(&mpic_lock, flags);
1594 #endif /* CONFIG_SMP */
1595 }
1596
1597 int mpic_cpu_get_priority(void)
1598 {
1599 struct mpic *mpic = mpic_primary;
1600
1601 return mpic_cpu_read(MPIC_INFO(CPU_CURRENT_TASK_PRI));
1602 }
1603
1604 void mpic_cpu_set_priority(int prio)
1605 {
1606 struct mpic *mpic = mpic_primary;
1607
1608 prio &= MPIC_CPU_TASKPRI_MASK;
1609 mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), prio);
1610 }
1611
1612 void mpic_teardown_this_cpu(int secondary)
1613 {
1614 struct mpic *mpic = mpic_primary;
1615 unsigned long flags;
1616 u32 msk = 1 << hard_smp_processor_id();
1617 unsigned int i;
1618
1619 BUG_ON(mpic == NULL);
1620
1621 DBG("%s: teardown_this_cpu(%d)\n", mpic->name, hard_smp_processor_id());
1622 raw_spin_lock_irqsave(&mpic_lock, flags);
1623
1624 /* let the mpic know we don't want intrs. */
1625 for (i = 0; i < mpic->num_sources ; i++)
1626 mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
1627 mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION)) & ~msk);
1628
1629 /* Set current processor priority to max */
1630 mpic_cpu_write(MPIC_INFO(CPU_CURRENT_TASK_PRI), 0xf);
1631 /* We need to EOI the IPI since not all platforms reset the MPIC
1632 * on boot and new interrupts wouldn't get delivered otherwise.
1633 */
1634 mpic_eoi(mpic);
1635
1636 raw_spin_unlock_irqrestore(&mpic_lock, flags);
1637 }
1638
1639
1640 static unsigned int _mpic_get_one_irq(struct mpic *mpic, int reg)
1641 {
1642 u32 src;
1643
1644 src = mpic_cpu_read(reg) & MPIC_INFO(VECPRI_VECTOR_MASK);
1645 #ifdef DEBUG_LOW
1646 DBG("%s: get_one_irq(reg 0x%x): %d\n", mpic->name, reg, src);
1647 #endif
1648 if (unlikely(src == mpic->spurious_vec)) {
1649 if (mpic->flags & MPIC_SPV_EOI)
1650 mpic_eoi(mpic);
1651 return NO_IRQ;
1652 }
1653 if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
1654 if (printk_ratelimit())
1655 printk(KERN_WARNING "%s: Got protected source %d !\n",
1656 mpic->name, (int)src);
1657 mpic_eoi(mpic);
1658 return NO_IRQ;
1659 }
1660
1661 return irq_linear_revmap(mpic->irqhost, src);
1662 }
1663
1664 unsigned int mpic_get_one_irq(struct mpic *mpic)
1665 {
1666 return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_INTACK));
1667 }
1668
1669 unsigned int mpic_get_irq(void)
1670 {
1671 struct mpic *mpic = mpic_primary;
1672
1673 BUG_ON(mpic == NULL);
1674
1675 return mpic_get_one_irq(mpic);
1676 }
1677
1678 unsigned int mpic_get_coreint_irq(void)
1679 {
1680 #ifdef CONFIG_BOOKE
1681 struct mpic *mpic = mpic_primary;
1682 u32 src;
1683
1684 BUG_ON(mpic == NULL);
1685
1686 src = mfspr(SPRN_EPR);
1687
1688 if (unlikely(src == mpic->spurious_vec)) {
1689 if (mpic->flags & MPIC_SPV_EOI)
1690 mpic_eoi(mpic);
1691 return NO_IRQ;
1692 }
1693 if (unlikely(mpic->protected && test_bit(src, mpic->protected))) {
1694 if (printk_ratelimit())
1695 printk(KERN_WARNING "%s: Got protected source %d !\n",
1696 mpic->name, (int)src);
1697 return NO_IRQ;
1698 }
1699
1700 return irq_linear_revmap(mpic->irqhost, src);
1701 #else
1702 return NO_IRQ;
1703 #endif
1704 }
1705
1706 unsigned int mpic_get_mcirq(void)
1707 {
1708 struct mpic *mpic = mpic_primary;
1709
1710 BUG_ON(mpic == NULL);
1711
1712 return _mpic_get_one_irq(mpic, MPIC_INFO(CPU_MCACK));
1713 }
1714
1715 #ifdef CONFIG_SMP
1716 void mpic_request_ipis(void)
1717 {
1718 struct mpic *mpic = mpic_primary;
1719 int i;
1720 BUG_ON(mpic == NULL);
1721
1722 printk(KERN_INFO "mpic: requesting IPIs...\n");
1723
1724 for (i = 0; i < 4; i++) {
1725 unsigned int vipi = irq_create_mapping(mpic->irqhost,
1726 mpic->ipi_vecs[0] + i);
1727 if (vipi == NO_IRQ) {
1728 printk(KERN_ERR "Failed to map %s\n", smp_ipi_name[i]);
1729 continue;
1730 }
1731 smp_request_message_ipi(vipi, i);
1732 }
1733 }
1734
1735 static void mpic_send_ipi(unsigned int ipi_no, const struct cpumask *cpu_mask)
1736 {
1737 struct mpic *mpic = mpic_primary;
1738
1739 BUG_ON(mpic == NULL);
1740
1741 #ifdef DEBUG_IPI
1742 DBG("%s: send_ipi(ipi_no: %d)\n", mpic->name, ipi_no);
1743 #endif
1744
1745 mpic_cpu_write(MPIC_INFO(CPU_IPI_DISPATCH_0) +
1746 ipi_no * MPIC_INFO(CPU_IPI_DISPATCH_STRIDE),
1747 mpic_physmask(cpumask_bits(cpu_mask)[0]));
1748 }
1749
1750 void smp_mpic_message_pass(int target, int msg)
1751 {
1752 cpumask_var_t tmp;
1753
1754 /* make sure we're sending something that translates to an IPI */
1755 if ((unsigned int)msg > 3) {
1756 printk("SMP %d: smp_message_pass: unknown msg %d\n",
1757 smp_processor_id(), msg);
1758 return;
1759 }
1760 switch (target) {
1761 case MSG_ALL:
1762 mpic_send_ipi(msg, cpu_online_mask);
1763 break;
1764 case MSG_ALL_BUT_SELF:
1765 alloc_cpumask_var(&tmp, GFP_NOWAIT);
1766 cpumask_andnot(tmp, cpu_online_mask,
1767 cpumask_of(smp_processor_id()));
1768 mpic_send_ipi(msg, tmp);
1769 free_cpumask_var(tmp);
1770 break;
1771 default:
1772 mpic_send_ipi(msg, cpumask_of(target));
1773 break;
1774 }
1775 }
1776
1777 int __init smp_mpic_probe(void)
1778 {
1779 int nr_cpus;
1780
1781 DBG("smp_mpic_probe()...\n");
1782
1783 nr_cpus = cpumask_weight(cpu_possible_mask);
1784
1785 DBG("nr_cpus: %d\n", nr_cpus);
1786
1787 if (nr_cpus > 1)
1788 mpic_request_ipis();
1789
1790 return nr_cpus;
1791 }
1792
1793 void __devinit smp_mpic_setup_cpu(int cpu)
1794 {
1795 mpic_setup_this_cpu();
1796 }
1797
1798 void mpic_reset_core(int cpu)
1799 {
1800 struct mpic *mpic = mpic_primary;
1801 u32 pir;
1802 int cpuid = get_hard_smp_processor_id(cpu);
1803
1804 /* Set target bit for core reset */
1805 pir = mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
1806 pir |= (1 << cpuid);
1807 mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
1808 mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
1809
1810 /* Restore target bit after reset complete */
1811 pir &= ~(1 << cpuid);
1812 mpic_write(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT), pir);
1813 mpic_read(mpic->gregs, MPIC_INFO(GREG_PROCESSOR_INIT));
1814 }
1815 #endif /* CONFIG_SMP */
1816
1817 #ifdef CONFIG_PM
1818 static int mpic_suspend(struct sys_device *dev, pm_message_t state)
1819 {
1820 struct mpic *mpic = container_of(dev, struct mpic, sysdev);
1821 int i;
1822
1823 for (i = 0; i < mpic->num_sources; i++) {
1824 mpic->save_data[i].vecprio =
1825 mpic_irq_read(i, MPIC_INFO(IRQ_VECTOR_PRI));
1826 mpic->save_data[i].dest =
1827 mpic_irq_read(i, MPIC_INFO(IRQ_DESTINATION));
1828 }
1829
1830 return 0;
1831 }
1832
1833 static int mpic_resume(struct sys_device *dev)
1834 {
1835 struct mpic *mpic = container_of(dev, struct mpic, sysdev);
1836 int i;
1837
1838 for (i = 0; i < mpic->num_sources; i++) {
1839 mpic_irq_write(i, MPIC_INFO(IRQ_VECTOR_PRI),
1840 mpic->save_data[i].vecprio);
1841 mpic_irq_write(i, MPIC_INFO(IRQ_DESTINATION),
1842 mpic->save_data[i].dest);
1843
1844 #ifdef CONFIG_MPIC_U3_HT_IRQS
1845 if (mpic->fixups) {
1846 struct mpic_irq_fixup *fixup = &mpic->fixups[i];
1847
1848 if (fixup->base) {
1849 /* we use the lowest bit in an inverted meaning */
1850 if ((mpic->save_data[i].fixup_data & 1) == 0)
1851 continue;
1852
1853 /* Enable and configure */
1854 writeb(0x10 + 2 * fixup->index, fixup->base + 2);
1855
1856 writel(mpic->save_data[i].fixup_data & ~1,
1857 fixup->base + 4);
1858 }
1859 }
1860 #endif
1861 } /* end for loop */
1862
1863 return 0;
1864 }
1865 #endif
1866
1867 static struct sysdev_class mpic_sysclass = {
1868 #ifdef CONFIG_PM
1869 .resume = mpic_resume,
1870 .suspend = mpic_suspend,
1871 #endif
1872 .name = "mpic",
1873 };
1874
1875 static int mpic_init_sys(void)
1876 {
1877 struct mpic *mpic = mpics;
1878 int error, id = 0;
1879
1880 error = sysdev_class_register(&mpic_sysclass);
1881
1882 while (mpic && !error) {
1883 mpic->sysdev.cls = &mpic_sysclass;
1884 mpic->sysdev.id = id++;
1885 error = sysdev_register(&mpic->sysdev);
1886 mpic = mpic->next;
1887 }
1888 return error;
1889 }
1890
1891 device_initcall(mpic_init_sys);