21 #include <linux/types.h>
22 #include <linux/kernel.h>
29 #include <linux/pci.h>
30 #include <linux/slab.h>
34 #include <asm/ptrace.h>
35 #include <asm/signal.h>
37 #include <asm/pgtable.h>
39 #include <asm/machdep.h>
46 #define DBG(fmt...) printk(fmt)
51 static struct mpic *mpics;
52 static struct mpic *mpic_primary;
56 #ifdef CONFIG_IRQ_ALL_CPUS
57 #define distribute_irqs (1)
59 #define distribute_irqs (0)
63 #ifdef CONFIG_MPIC_WEIRD
64 static u32 mpic_infos[][MPIC_IDX_END] = {
68 MPIC_GREG_GLOBAL_CONF_0,
70 MPIC_GREG_IPI_VECTOR_PRI_0,
77 MPIC_TIMER_CURRENT_CNT,
79 MPIC_TIMER_VECTOR_PRI,
80 MPIC_TIMER_DESTINATION,
84 MPIC_CPU_IPI_DISPATCH_0,
85 MPIC_CPU_IPI_DISPATCH_STRIDE,
86 MPIC_CPU_CURRENT_TASK_PRI,
95 MPIC_VECPRI_VECTOR_MASK,
96 MPIC_VECPRI_POLARITY_POSITIVE,
97 MPIC_VECPRI_POLARITY_NEGATIVE,
98 MPIC_VECPRI_SENSE_LEVEL,
99 MPIC_VECPRI_SENSE_EDGE,
100 MPIC_VECPRI_POLARITY_MASK,
101 MPIC_VECPRI_SENSE_MASK,
106 TSI108_GREG_FEATURE_0,
107 TSI108_GREG_GLOBAL_CONF_0,
108 TSI108_GREG_VENDOR_ID,
109 TSI108_GREG_IPI_VECTOR_PRI_0,
110 TSI108_GREG_IPI_STRIDE,
111 TSI108_GREG_SPURIOUS,
112 TSI108_GREG_TIMER_FREQ,
116 TSI108_TIMER_CURRENT_CNT,
117 TSI108_TIMER_BASE_CNT,
118 TSI108_TIMER_VECTOR_PRI,
119 TSI108_TIMER_DESTINATION,
123 TSI108_CPU_IPI_DISPATCH_0,
124 TSI108_CPU_IPI_DISPATCH_STRIDE,
125 TSI108_CPU_CURRENT_TASK_PRI,
133 TSI108_IRQ_VECTOR_PRI,
134 TSI108_VECPRI_VECTOR_MASK,
135 TSI108_VECPRI_POLARITY_POSITIVE,
136 TSI108_VECPRI_POLARITY_NEGATIVE,
137 TSI108_VECPRI_SENSE_LEVEL,
138 TSI108_VECPRI_SENSE_EDGE,
139 TSI108_VECPRI_POLARITY_MASK,
140 TSI108_VECPRI_SENSE_MASK,
141 TSI108_IRQ_DESTINATION
145 #define MPIC_INFO(name) mpic->hw_set[MPIC_IDX_##name]
149 #define MPIC_INFO(name) MPIC_##name
153 static inline unsigned int mpic_processor_id(
struct mpic *mpic)
155 unsigned int cpu = 0;
157 if (!(mpic->flags & MPIC_SECONDARY))
168 static inline u32 _mpic_read(
enum mpic_reg_type
type,
169 struct mpic_reg_bank *
rb,
173 #ifdef CONFIG_PPC_DCR
174 case mpic_access_dcr:
175 return dcr_read(rb->dhost, reg);
177 case mpic_access_mmio_be:
178 return in_be32(rb->base + (reg >> 2));
179 case mpic_access_mmio_le:
181 return in_le32(rb->base + (reg >> 2));
185 static inline void _mpic_write(
enum mpic_reg_type type,
186 struct mpic_reg_bank *rb,
190 #ifdef CONFIG_PPC_DCR
191 case mpic_access_dcr:
192 dcr_write(rb->dhost, reg, value);
195 case mpic_access_mmio_be:
196 out_be32(rb->base + (reg >> 2), value);
198 case mpic_access_mmio_le:
200 out_le32(rb->base + (reg >> 2), value);
205 static inline u32 _mpic_ipi_read(
struct mpic *mpic,
unsigned int ipi)
207 enum mpic_reg_type type = mpic->reg_type;
211 if ((mpic->flags & MPIC_BROKEN_IPI) && type == mpic_access_mmio_le)
212 type = mpic_access_mmio_be;
213 return _mpic_read(type, &mpic->gregs, offset);
216 static inline void _mpic_ipi_write(
struct mpic *mpic,
unsigned int ipi,
u32 value)
218 unsigned int offset =
MPIC_INFO(GREG_IPI_VECTOR_PRI_0) +
221 _mpic_write(mpic->reg_type, &mpic->gregs, offset, value);
224 static inline unsigned int mpic_tm_offset(
struct mpic *mpic,
unsigned int tm)
226 return (tm >> 2) * MPIC_TIMER_GROUP_STRIDE +
230 static inline u32 _mpic_tm_read(
struct mpic *mpic,
unsigned int tm)
232 unsigned int offset = mpic_tm_offset(mpic, tm) +
235 return _mpic_read(mpic->reg_type, &mpic->tmregs, offset);
238 static inline void _mpic_tm_write(
struct mpic *mpic,
unsigned int tm,
u32 value)
240 unsigned int offset = mpic_tm_offset(mpic, tm) +
243 _mpic_write(mpic->reg_type, &mpic->tmregs, offset, value);
246 static inline u32 _mpic_cpu_read(
struct mpic *mpic,
unsigned int reg)
248 unsigned int cpu = mpic_processor_id(mpic);
250 return _mpic_read(mpic->reg_type, &mpic->cpuregs[cpu], reg);
253 static inline void _mpic_cpu_write(
struct mpic *mpic,
unsigned int reg,
u32 value)
255 unsigned int cpu = mpic_processor_id(mpic);
257 _mpic_write(mpic->reg_type, &mpic->cpuregs[cpu], reg, value);
260 static inline u32 _mpic_irq_read(
struct mpic *mpic,
unsigned int src_no,
unsigned int reg)
262 unsigned int isu = src_no >> mpic->isu_shift;
263 unsigned int idx = src_no & mpic->isu_mask;
266 val = _mpic_read(mpic->reg_type, &mpic->isus[isu],
268 #ifdef CONFIG_MPIC_BROKEN_REGREAD
270 val = (val & (MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY)) |
271 mpic->isu_reg0_shadow[src_no];
276 static inline void _mpic_irq_write(
struct mpic *mpic,
unsigned int src_no,
277 unsigned int reg,
u32 value)
279 unsigned int isu = src_no >> mpic->isu_shift;
280 unsigned int idx = src_no & mpic->isu_mask;
282 _mpic_write(mpic->reg_type, &mpic->isus[isu],
283 reg + (idx *
MPIC_INFO(IRQ_STRIDE)), value);
285 #ifdef CONFIG_MPIC_BROKEN_REGREAD
287 mpic->isu_reg0_shadow[src_no] =
288 value & ~(MPIC_VECPRI_MASK | MPIC_VECPRI_ACTIVITY);
292 #define mpic_read(b,r) _mpic_read(mpic->reg_type,&(b),(r))
293 #define mpic_write(b,r,v) _mpic_write(mpic->reg_type,&(b),(r),(v))
294 #define mpic_ipi_read(i) _mpic_ipi_read(mpic,(i))
295 #define mpic_ipi_write(i,v) _mpic_ipi_write(mpic,(i),(v))
296 #define mpic_tm_read(i) _mpic_tm_read(mpic,(i))
297 #define mpic_tm_write(i,v) _mpic_tm_write(mpic,(i),(v))
298 #define mpic_cpu_read(i) _mpic_cpu_read(mpic,(i))
299 #define mpic_cpu_write(i,v) _mpic_cpu_write(mpic,(i),(v))
300 #define mpic_irq_read(s,r) _mpic_irq_read(mpic,(s),(r))
301 #define mpic_irq_write(s,r,v) _mpic_irq_write(mpic,(s),(r),(v))
310 struct mpic_reg_bank *rb,
unsigned int offset,
313 rb->base =
ioremap(phys_addr + offset, size);
317 #ifdef CONFIG_PPC_DCR
318 static void _mpic_map_dcr(
struct mpic *mpic,
struct mpic_reg_bank *rb,
319 unsigned int offset,
unsigned int size)
322 rb->dhost = dcr_map(mpic->node, phys_addr + offset, size);
323 BUG_ON(!DCR_MAP_OK(rb->dhost));
326 static inline void mpic_map(
struct mpic *mpic,
328 unsigned int offset,
unsigned int size)
330 if (mpic->flags & MPIC_USES_DCR)
331 _mpic_map_dcr(mpic, rb, offset, size);
333 _mpic_map_mmio(mpic, phys_addr, rb, offset, size);
336 #define mpic_map(m,p,b,o,s) _mpic_map_mmio(m,p,b,o,s)
344 static void __init mpic_test_broken_ipi(
struct mpic *mpic)
353 mpic->flags |= MPIC_BROKEN_IPI;
357 #ifdef CONFIG_MPIC_U3_HT_IRQS
362 static inline int mpic_is_ht_interrupt(
struct mpic *mpic,
unsigned int source)
364 if (source >= 128 || !mpic->fixups)
370 static inline void mpic_ht_end_irq(
struct mpic *mpic,
unsigned int source)
372 struct mpic_irq_fixup *
fixup = &mpic->fixups[
source];
374 if (fixup->applebase) {
375 unsigned int soff = (fixup->index >> 3) & ~3;
376 unsigned int mask = 1
U << (fixup->index & 0x1f);
377 writel(mask, fixup->applebase + soff);
380 writeb(0x11 + 2 * fixup->index, fixup->base + 2);
381 writel(fixup->data, fixup->base + 4);
386 static void mpic_startup_ht_interrupt(
struct mpic *mpic,
unsigned int source,
389 struct mpic_irq_fixup *fixup = &mpic->fixups[
source];
393 if (fixup->base ==
NULL)
396 DBG(
"startup_ht_interrupt(0x%x) index: %d\n",
397 source, fixup->index);
400 writeb(0x10 + 2 * fixup->index, fixup->base + 2);
401 tmp =
readl(fixup->base + 4);
405 writel(tmp, fixup->base + 4);
411 mpic->save_data[
source].fixup_data = tmp | 1;
415 static void mpic_shutdown_ht_interrupt(
struct mpic *mpic,
unsigned int source)
417 struct mpic_irq_fixup *fixup = &mpic->fixups[
source];
421 if (fixup->base ==
NULL)
424 DBG(
"shutdown_ht_interrupt(0x%x)\n", source);
428 writeb(0x10 + 2 * fixup->index, fixup->base + 2);
429 tmp =
readl(fixup->base + 4);
431 writel(tmp, fixup->base + 4);
437 mpic->save_data[
source].fixup_data = tmp & ~1;
441 #ifdef CONFIG_PCI_MSI
442 static void __init mpic_scan_ht_msi(
struct mpic *mpic,
u8 __iomem *devbase,
453 id =
readb(devbase + pos + 3);
462 base = devbase +
pos;
478 static void __init mpic_scan_ht_msi(
struct mpic *mpic,
u8 __iomem *devbase,
485 static void __init mpic_scan_ht_pic(
struct mpic *mpic,
u8 __iomem *devbase,
486 unsigned int devfn,
u32 vdid)
497 id =
readb(devbase + pos + 3);
505 base = devbase +
pos;
507 n = (
readl(base + 4) >> 16) & 0xff;
511 devfn >> 3, devfn & 0x7, pos, vdid & 0xffff, vdid >> 16, n + 1);
513 for (i = 0; i <=
n; i++) {
514 writeb(0x10 + 2 * i, base + 2);
515 tmp =
readl(base + 4);
516 irq = (tmp >> 16) & 0xff;
517 DBG(
"HT PIC index 0x%x, irq 0x%x, tmp: %08x\n", i, irq, tmp);
521 mpic->fixups[irq].index =
i;
522 mpic->fixups[irq].base = base;
524 if ((vdid & 0xffff) == 0x106b)
525 mpic->fixups[irq].applebase = devbase + 0x60;
527 mpic->fixups[irq].applebase =
NULL;
528 writeb(0x11 + 2 * i, base + 2);
529 mpic->fixups[irq].data =
readl(base + 4) | 0x80000000;
534 static void __init mpic_scan_ht_pics(
struct mpic *mpic)
542 mpic->fixups = kzalloc(128 *
sizeof(*mpic->fixups),
GFP_KERNEL);
551 cfgspace =
ioremap(0xf2000000, 0x10000);
557 for (devfn = 0; devfn < 0x100; devfn++) {
558 u8 __iomem *devbase = cfgspace + (devfn << 8);
563 DBG(
"devfn %x, l: %x\n", devfn, l);
566 if (l == 0xffffffff || l == 0x00000000 ||
567 l == 0x0000ffff || l == 0xffff0000)
574 mpic_scan_ht_pic(mpic, devbase, devfn, l);
575 mpic_scan_ht_msi(mpic, devbase, devfn);
579 if (
PCI_FUNC(devfn) == 0 && (hdr_type & 0x80) == 0)
586 static inline int mpic_is_ht_interrupt(
struct mpic *mpic,
unsigned int source)
591 static void __init mpic_scan_ht_pics(
struct mpic *mpic)
598 static struct mpic *mpic_find(
unsigned int irq)
603 return irq_get_chip_data(irq);
607 static unsigned int mpic_is_ipi(
struct mpic *mpic,
unsigned int src)
609 return (src >= mpic->ipi_vecs[0] &&
src <= mpic->ipi_vecs[3]);
613 static unsigned int mpic_is_tm(
struct mpic *mpic,
unsigned int src)
615 return (src >= mpic->timer_vecs[0] &&
src <= mpic->timer_vecs[7]);
624 for (i = 0; i < min(32, NR_CPUS); ++i, cpumask >>= 1)
625 mask |= (cpumask & 1) << get_hard_smp_processor_id(i);
631 static inline struct mpic * mpic_from_ipi(
struct irq_data *
d)
633 return irq_data_get_irq_chip_data(d);
638 static inline struct mpic * mpic_from_irq(
unsigned int irq)
640 return irq_get_chip_data(irq);
644 static inline struct mpic * mpic_from_irq_data(
struct irq_data *
d)
646 return irq_data_get_irq_chip_data(d);
650 static inline void mpic_eoi(
struct mpic *mpic)
663 unsigned int loops = 100000;
664 struct mpic *mpic = mpic_from_irq_data(d);
665 unsigned int src = irqd_to_hwirq(d);
667 DBG(
"%p: %s: enable_irq: %d (src %d)\n", mpic, mpic->name, d->
irq, src);
684 unsigned int loops = 100000;
685 struct mpic *mpic = mpic_from_irq_data(d);
686 unsigned int src = irqd_to_hwirq(d);
688 DBG(
"%s: disable_irq: %d (src %d)\n", mpic->name, d->
irq, src);
706 struct mpic *mpic = mpic_from_irq_data(d);
709 DBG(
"%s: end_irq: %d\n", mpic->name, d->
irq);
719 #ifdef CONFIG_MPIC_U3_HT_IRQS
721 static void mpic_unmask_ht_irq(
struct irq_data *
d)
723 struct mpic *mpic = mpic_from_irq_data(d);
724 unsigned int src = irqd_to_hwirq(d);
728 if (irqd_is_level_type(d))
729 mpic_ht_end_irq(mpic, src);
732 static unsigned int mpic_startup_ht_irq(
struct irq_data *d)
734 struct mpic *mpic = mpic_from_irq_data(d);
735 unsigned int src = irqd_to_hwirq(d);
738 mpic_startup_ht_interrupt(mpic, src, irqd_is_level_type(d));
743 static void mpic_shutdown_ht_irq(
struct irq_data *d)
745 struct mpic *mpic = mpic_from_irq_data(d);
746 unsigned int src = irqd_to_hwirq(d);
748 mpic_shutdown_ht_interrupt(mpic, src);
752 static void mpic_end_ht_irq(
struct irq_data *d)
754 struct mpic *mpic = mpic_from_irq_data(d);
755 unsigned int src = irqd_to_hwirq(d);
758 DBG(
"%s: end_irq: %d\n", mpic->name, d->
irq);
765 if (irqd_is_level_type(d))
766 mpic_ht_end_irq(mpic, src);
773 static void mpic_unmask_ipi(
struct irq_data *d)
775 struct mpic *mpic = mpic_from_ipi(d);
778 DBG(
"%s: enable_ipi: %d (ipi %d)\n", mpic->name, d->
irq, src);
782 static void mpic_mask_ipi(
struct irq_data *d)
787 static void mpic_end_ipi(
struct irq_data *d)
789 struct mpic *mpic = mpic_from_ipi(d);
801 static void mpic_unmask_tm(
struct irq_data *d)
803 struct mpic *mpic = mpic_from_irq_data(d);
806 DBG(
"%s: enable_tm: %d (tm %d)\n", mpic->name, d->
irq, src);
811 static void mpic_mask_tm(
struct irq_data *d)
813 struct mpic *mpic = mpic_from_irq_data(d);
823 struct mpic *mpic = mpic_from_irq_data(d);
824 unsigned int src = irqd_to_hwirq(d);
826 if (mpic->flags & MPIC_SINGLE_DEST_CPU) {
836 mpic_physmask(mask));
842 static unsigned int mpic_type_to_vecpri(
struct mpic *mpic,
unsigned int type)
865 struct mpic *mpic = mpic_from_irq_data(d);
866 unsigned int src = irqd_to_hwirq(d);
867 unsigned int vecpri, vold, vnew;
869 DBG(
"mpic: set_irq_type(mpic:@%p,virq:%d,src:0x%x,type:0x%x)\n",
870 mpic, d->
irq, src, flow_type);
872 if (src >= mpic->num_sources)
883 switch(vold & (
MPIC_INFO(VECPRI_POLARITY_MASK) |
905 irqd_set_trigger_type(d, flow_type);
908 if (mpic_is_ht_interrupt(mpic, src))
909 vecpri = MPIC_VECPRI_POLARITY_POSITIVE |
910 MPIC_VECPRI_SENSE_EDGE;
912 vecpri = mpic_type_to_vecpri(mpic, flow_type);
914 vnew = vold & ~(
MPIC_INFO(VECPRI_POLARITY_MASK) |
925 struct mpic *mpic = mpic_from_irq(virq);
929 DBG(
"mpic: set_vector(mpic:@%p,virq:%d,src:%d,vector:0x%x)\n",
930 mpic, virq, src, vector);
932 if (src >= mpic->num_sources)
936 vecpri = vecpri & ~
MPIC_INFO(VECPRI_VECTOR_MASK);
943 struct mpic *mpic = mpic_from_irq(virq);
946 DBG(
"mpic: set_destination(mpic:@%p,virq:%d,src:%d,cpuid:0x%x)\n",
947 mpic, virq, src, cpuid);
949 if (src >= mpic->num_sources)
955 static struct irq_chip mpic_irq_chip = {
963 static struct irq_chip mpic_ipi_chip = {
965 .irq_unmask = mpic_unmask_ipi,
966 .irq_eoi = mpic_end_ipi,
970 static struct irq_chip mpic_tm_chip = {
971 .irq_mask = mpic_mask_tm,
972 .irq_unmask = mpic_unmask_tm,
976 #ifdef CONFIG_MPIC_U3_HT_IRQS
977 static struct irq_chip mpic_irq_ht_chip = {
979 .irq_shutdown = mpic_shutdown_ht_irq,
981 .irq_unmask = mpic_unmask_ht_irq,
982 .irq_eoi = mpic_end_ht_irq,
994 static int mpic_host_map(
struct irq_domain *
h,
unsigned int virq,
1000 DBG(
"mpic: map virq %d, hwirq 0x%lx\n", virq, hw);
1002 if (hw == mpic->spurious_vec)
1004 if (mpic->protected &&
test_bit(hw, mpic->protected))
1008 else if (hw >= mpic->ipi_vecs[0]) {
1009 WARN_ON(mpic->flags & MPIC_SECONDARY);
1011 DBG(
"mpic: mapping as IPI\n");
1013 irq_set_chip_and_handler(virq, &mpic->hc_ipi,
1019 if (hw >= mpic->timer_vecs[0] &&
hw <= mpic->timer_vecs[7]) {
1020 WARN_ON(mpic->flags & MPIC_SECONDARY);
1022 DBG(
"mpic: mapping as timer\n");
1024 irq_set_chip_and_handler(virq, &mpic->hc_tm,
1032 if (hw >= mpic->num_sources)
1038 chip = &mpic->hc_irq;
1040 #ifdef CONFIG_MPIC_U3_HT_IRQS
1042 if (mpic_is_ht_interrupt(mpic, hw))
1043 chip = &mpic->hc_ht_irq;
1046 DBG(
"mpic: mapping to irq chip @%p\n", chip);
1058 if (!mpic_is_ipi(mpic, hw) && (mpic->flags & MPIC_NO_RESET)) {
1068 const u32 *intspec,
unsigned int intsize,
1073 static unsigned char map_mpic_senses[4] = {
1080 *out_hwirq = intspec[0];
1081 if (intsize >= 4 && (mpic->flags & MPIC_FSL)) {
1089 switch (intspec[2]) {
1093 if (!(mpic->flags & MPIC_FSL_HAS_EIMR))
1096 if (intspec[3] >=
ARRAY_SIZE(mpic->err_int_vecs))
1099 *out_hwirq = mpic->err_int_vecs[intspec[3]];
1103 if (intspec[0] >=
ARRAY_SIZE(mpic->ipi_vecs))
1106 *out_hwirq = mpic->ipi_vecs[intspec[0]];
1109 if (intspec[0] >=
ARRAY_SIZE(mpic->timer_vecs))
1112 *out_hwirq = mpic->timer_vecs[intspec[0]];
1115 pr_debug(
"%s: unknown irq type %u\n",
1116 __func__, intspec[2]);
1120 *out_flags = map_mpic_senses[intspec[1] & 3];
1121 }
else if (intsize > 1) {
1134 if (machine_is(powermac))
1136 *out_flags = map_mpic_senses[intspec[1] &
mask];
1140 DBG(
"mpic: xlate (%d cells: 0x%08x 0x%08x) to line 0x%lx sense 0x%x\n",
1141 intsize, intspec[0], intspec[1], *out_hwirq, *out_flags);
1147 static void mpic_cascade(
unsigned int irq,
struct irq_desc *
desc)
1149 struct irq_chip *chip = irq_desc_get_chip(desc);
1150 struct mpic *mpic = irq_desc_get_handler_data(desc);
1153 BUG_ON(!(mpic->flags & MPIC_SECONDARY));
1163 .match = mpic_host_match,
1164 .map = mpic_host_map,
1165 .xlate = mpic_host_xlate,
1175 unsigned int isu_size,
1179 int i, psize, intvec_top;
1187 static const struct of_device_id __initconst mpic_device_id[] = {
1188 { .
type =
"open-pic", },
1189 { .compatible =
"open-pic", },
1198 node = of_node_get(node);
1209 flags |= MPIC_USES_DCR;
1213 goto err_of_node_put;
1214 phys_addr = r.
start;
1220 flags |= MPIC_BIG_ENDIAN;
1222 flags |= MPIC_NO_RESET;
1224 flags |= MPIC_SINGLE_DEST_CPU;
1226 flags |= MPIC_FSL | MPIC_LARGE_VECTORS;
1228 mpic = kzalloc(
sizeof(
struct mpic),
GFP_KERNEL);
1230 goto err_of_node_put;
1235 mpic->flags =
flags;
1237 mpic->hc_irq = mpic_irq_chip;
1239 if (!(mpic->flags & MPIC_SECONDARY))
1241 #ifdef CONFIG_MPIC_U3_HT_IRQS
1242 mpic->hc_ht_irq = mpic_irq_ht_chip;
1244 if (!(mpic->flags & MPIC_SECONDARY))
1249 mpic->hc_ipi = mpic_ipi_chip;
1253 mpic->hc_tm = mpic_tm_chip;
1256 mpic->num_sources = 0;
1258 if (mpic->flags & MPIC_LARGE_VECTORS)
1263 mpic->timer_vecs[0] = intvec_top - 12;
1264 mpic->timer_vecs[1] = intvec_top - 11;
1265 mpic->timer_vecs[2] = intvec_top - 10;
1266 mpic->timer_vecs[3] = intvec_top - 9;
1267 mpic->timer_vecs[4] = intvec_top - 8;
1268 mpic->timer_vecs[5] = intvec_top - 7;
1269 mpic->timer_vecs[6] = intvec_top - 6;
1270 mpic->timer_vecs[7] = intvec_top - 5;
1271 mpic->ipi_vecs[0] = intvec_top - 4;
1272 mpic->ipi_vecs[1] = intvec_top - 3;
1273 mpic->ipi_vecs[2] = intvec_top - 2;
1274 mpic->ipi_vecs[3] = intvec_top - 1;
1275 mpic->spurious_vec = intvec_top;
1282 mpic->protected = kzalloc(mapsize*
sizeof(
long),
GFP_KERNEL);
1284 for (i = 0; i < psize/
sizeof(
u32); i++) {
1285 if (psrc[i] > intvec_top)
1291 #ifdef CONFIG_MPIC_WEIRD
1292 mpic->hw_set = mpic_infos[MPIC_GET_REGSET(mpic->flags)];
1296 if (mpic->flags & MPIC_BIG_ENDIAN)
1297 mpic->reg_type = mpic_access_mmio_be;
1299 mpic->reg_type = mpic_access_mmio_le;
1305 #ifdef CONFIG_PPC_DCR
1306 if (mpic->flags & MPIC_USES_DCR)
1307 mpic->reg_type = mpic_access_dcr;
1309 BUG_ON(mpic->flags & MPIC_USES_DCR);
1316 if (mpic->flags & MPIC_FSL) {
1325 mpic_map(mpic, mpic->paddr, &mpic->thiscpuregs,
1326 MPIC_CPU_THISBASE, 0x1000);
1328 brr1 = _mpic_read(mpic->reg_type, &mpic->thiscpuregs,
1330 version = brr1 & MPIC_FSL_BRR1_VER;
1345 if (version >= 0x401) {
1357 if (!(mpic->flags & MPIC_NO_RESET)) {
1361 | MPIC_GREG_GCONF_RESET);
1363 & MPIC_GREG_GCONF_RESET)
1368 if (mpic->flags & MPIC_ENABLE_COREINT)
1371 | MPIC_GREG_GCONF_COREINT);
1373 if (mpic->flags & MPIC_ENABLE_MCK)
1376 | MPIC_GREG_GCONF_MCK);
1386 unsigned int cpu = get_hard_smp_processor_id(i);
1388 mpic_map(mpic, mpic->paddr, &mpic->cpuregs[cpu],
1405 last_irq = (greg_feature & MPIC_GREG_FEATURE_LAST_SRC_MASK)
1406 >> MPIC_GREG_FEATURE_LAST_SRC_SHIFT;
1408 last_irq = isu_size * MPIC_MAX_ISU - 1;
1409 of_property_read_u32(mpic->node,
"last-interrupt-source", &last_irq);
1411 last_irq = irq_count - 1;
1415 isu_size = last_irq + 1;
1416 mpic->num_sources = isu_size;
1417 mpic_map(mpic, mpic->paddr, &mpic->isus[0],
1422 mpic->isu_size = isu_size;
1423 mpic->isu_shift = 1 + __ilog2(mpic->isu_size - 1);
1424 mpic->isu_mask = (1 << mpic->isu_shift) - 1;
1428 &mpic_host_ops, mpic);
1434 if (mpic->irqhost ==
NULL)
1438 switch (greg_feature & MPIC_GREG_FEATURE_VERSION_MASK) {
1456 mpic->isu_size, mpic->isu_shift, mpic->isu_mask);
1461 if (!(mpic->flags & MPIC_SECONDARY)) {
1462 mpic_primary = mpic;
1476 unsigned int isu_first = isu_num * mpic->isu_size;
1478 BUG_ON(isu_num >= MPIC_MAX_ISU);
1481 paddr, &mpic->isus[isu_num], 0,
1482 MPIC_INFO(IRQ_STRIDE) * mpic->isu_size);
1484 if ((isu_first + mpic->isu_size) > mpic->num_sources)
1485 mpic->num_sources = isu_first + mpic->isu_size;
1493 BUG_ON(mpic->num_sources == 0);
1495 printk(
KERN_INFO "mpic: Initializing for %d sources\n", mpic->num_sources);
1500 if (mpic->flags & MPIC_FSL) {
1501 u32 brr1 = _mpic_read(mpic->reg_type, &mpic->thiscpuregs,
1511 if (version >= 0x0301)
1516 if (mpic->flags & MPIC_FSL_HAS_EIMR)
1520 for (i = 0; i < num_timers; i++) {
1521 unsigned int offset = mpic_tm_offset(mpic, i);
1529 (9 << MPIC_VECPRI_PRIORITY_SHIFT) |
1530 (mpic->timer_vecs[0] + i));
1534 mpic_test_broken_ipi(mpic);
1535 for (i = 0; i < 4; i++) {
1538 (10 << MPIC_VECPRI_PRIORITY_SHIFT) |
1539 (mpic->ipi_vecs[0] + i));
1543 DBG(
"MPIC flags: %x\n", mpic->flags);
1544 if ((mpic->flags & MPIC_U3_HT_IRQS) && !(mpic->flags & MPIC_SECONDARY)) {
1545 mpic_scan_ht_pics(mpic);
1551 cpu = mpic_processor_id(mpic);
1553 if (!(mpic->flags & MPIC_NO_RESET)) {
1554 for (i = 0; i < mpic->num_sources; i++) {
1556 u32 vecpri = MPIC_VECPRI_MASK | i |
1557 (8 << MPIC_VECPRI_PRIORITY_SHIFT);
1560 if (mpic->protected &&
test_bit(i, mpic->protected))
1572 if (!(mpic->flags & MPIC_NO_PTHROU_DIS))
1575 | MPIC_GREG_GCONF_8259_PTHROU_DIS);
1577 if (mpic->flags & MPIC_NO_BIAS)
1580 | MPIC_GREG_GCONF_NO_BIAS);
1587 mpic->save_data =
kmalloc(mpic->num_sources *
sizeof(*mpic->save_data),
1593 if (mpic->flags & MPIC_SECONDARY) {
1597 mpic->node->full_name, virq);
1599 irq_set_chained_handler(virq, &mpic_cascade);
1608 v =
mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
1609 v &= ~MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO_MASK;
1610 v |= MPIC_GREG_GLOBAL_CONF_1_CLK_RATIO(clock_ratio);
1611 mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
1616 unsigned long flags;
1620 v =
mpic_read(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1);
1622 v |= MPIC_GREG_GLOBAL_CONF_1_SIE;
1624 v &= ~MPIC_GREG_GLOBAL_CONF_1_SIE;
1625 mpic_write(mpic->gregs, MPIC_GREG_GLOBAL_CONF_1, v);
1631 struct mpic *mpic = mpic_find(irq);
1633 unsigned long flags;
1640 if (mpic_is_ipi(mpic, src)) {
1642 ~MPIC_VECPRI_PRIORITY_MASK;
1644 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1645 }
else if (mpic_is_tm(mpic, src)) {
1647 ~MPIC_VECPRI_PRIORITY_MASK;
1649 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1652 & ~MPIC_VECPRI_PRIORITY_MASK;
1654 reg | (pri << MPIC_VECPRI_PRIORITY_SHIFT));
1662 struct mpic *mpic = mpic_primary;
1663 unsigned long flags;
1678 if (distribute_irqs) {
1679 for (i = 0; i < mpic->num_sources ; i++)
1693 struct mpic *mpic = mpic_primary;
1700 struct mpic *mpic = mpic_primary;
1702 prio &= MPIC_CPU_TASKPRI_MASK;
1708 struct mpic *mpic = mpic_primary;
1709 unsigned long flags;
1719 for (i = 0; i < mpic->num_sources ; i++)
1734 static unsigned int _mpic_get_one_irq(
struct mpic *mpic,
int reg)
1740 DBG(
"%s: get_one_irq(reg 0x%x): %d\n", mpic->name, reg, src);
1742 if (
unlikely(src == mpic->spurious_vec)) {
1743 if (mpic->flags & MPIC_SPV_EOI)
1749 mpic->name, (
int)src);
1759 return _mpic_get_one_irq(mpic,
MPIC_INFO(CPU_INTACK));
1764 struct mpic *mpic = mpic_primary;
1774 struct mpic *mpic = mpic_primary;
1779 src =
mfspr(SPRN_EPR);
1781 if (
unlikely(src == mpic->spurious_vec)) {
1782 if (mpic->flags & MPIC_SPV_EOI)
1788 mpic->name, (
int)src);
1800 struct mpic *mpic = mpic_primary;
1804 return _mpic_get_one_irq(mpic,
MPIC_INFO(CPU_MCACK));
1808 void mpic_request_ipis(
void)
1810 struct mpic *mpic = mpic_primary;
1816 for (i = 0; i < 4; i++) {
1818 mpic->ipi_vecs[0] + i);
1827 void smp_mpic_message_pass(
int cpu,
int msg)
1829 struct mpic *mpic = mpic_primary;
1835 if ((
unsigned int)msg > 3) {
1836 printk(
"SMP %d: smp_message_pass: unknown msg %d\n",
1842 DBG(
"%s: send_ipi(ipi_no: %d)\n", mpic->name, msg);
1845 physmask = 1 << get_hard_smp_processor_id(cpu);
1848 msg *
MPIC_INFO(CPU_IPI_DISPATCH_STRIDE), physmask);
1851 int __init smp_mpic_probe(
void)
1855 DBG(
"smp_mpic_probe()...\n");
1857 nr_cpus = cpumask_weight(cpu_possible_mask);
1859 DBG(
"nr_cpus: %d\n", nr_cpus);
1862 mpic_request_ipis();
1867 void __devinit smp_mpic_setup_cpu(
int cpu)
1874 struct mpic *mpic = mpic_primary;
1876 int cpuid = get_hard_smp_processor_id(cpu);
1881 pir |= (1 <<
cpuid);
1886 pir &= ~(1 <<
cpuid);
1892 if (mpic->flags & MPIC_FSL) {
1893 for (i = 0; i < 15; i++) {
1894 _mpic_write(mpic->reg_type, &mpic->cpuregs[cpuid],
1902 static void mpic_suspend_one(
struct mpic *mpic)
1906 for (i = 0; i < mpic->num_sources; i++) {
1907 mpic->save_data[
i].vecprio =
1909 mpic->save_data[
i].dest =
1914 static int mpic_suspend(
void)
1916 struct mpic *mpic = mpics;
1919 mpic_suspend_one(mpic);
1926 static void mpic_resume_one(
struct mpic *mpic)
1930 for (i = 0; i < mpic->num_sources; i++) {
1932 mpic->save_data[i].vecprio);
1934 mpic->save_data[i].dest);
1936 #ifdef CONFIG_MPIC_U3_HT_IRQS
1938 struct mpic_irq_fixup *fixup = &mpic->fixups[
i];
1942 if ((mpic->save_data[i].fixup_data & 1) == 0)
1946 writeb(0x10 + 2 * fixup->index, fixup->base + 2);
1948 writel(mpic->save_data[i].fixup_data & ~1,
1956 static void mpic_resume(
void)
1958 struct mpic *mpic = mpics;
1961 mpic_resume_one(mpic);
1968 .suspend = mpic_suspend,
1971 static int mpic_init_sys(
void)