26 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/list.h>
40 #include <linux/slab.h>
43 #include <asm/exception.h>
65 #ifdef CONFIG_GIC_NON_BANKED
80 .irq_retrigger =
NULL,
91 #ifdef CONFIG_GIC_NON_BANKED
109 return data->get_base(&data->
cpu_base);
118 #define gic_data_dist_base(d) ((d)->dist_base.common_base)
119 #define gic_data_cpu_base(d) ((d)->cpu_base.common_base)
120 #define gic_set_base_accessor(d,f)
125 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
131 struct gic_chip_data *gic_data = irq_data_get_irq_chip_data(d);
135 static inline unsigned int gic_irq(
struct irq_data *
d)
143 static void gic_mask_irq(
struct irq_data *
d)
145 u32 mask = 1 << (gic_irq(d) % 32);
154 static void gic_unmask_irq(
struct irq_data *d)
156 u32 mask = 1 << (gic_irq(d) % 32);
165 static void gic_eoi_irq(
struct irq_data *d)
173 writel_relaxed(gic_irq(d), gic_cpu_base(d) +
GIC_CPU_EOI);
176 static int gic_set_type(
struct irq_data *d,
unsigned int type)
179 unsigned int gicirq = gic_irq(d);
180 u32 enablemask = 1 << (gicirq % 32);
181 u32 enableoff = (gicirq / 32) * 4;
182 u32 confmask = 0x2 << ((gicirq % 16) * 2);
183 u32 confoff = (gicirq / 16) * 4;
224 static int gic_retrigger(
struct irq_data *d)
233 static int gic_set_affinity(
struct irq_data *d,
const struct cpumask *mask_val,
237 unsigned int shift = (gic_irq(d) % 4) * 8;
241 if (cpu >= 8 || cpu >= nr_cpu_ids)
244 mask = 0xff << shift;
249 writel_relaxed(val | bit, reg);
268 #define gic_set_wake NULL
279 irqnr = irqstat & ~0x1c00;
281 if (
likely(irqnr > 15 && irqnr < 1021)) {
297 static void gic_handle_cascade_irq(
unsigned int irq,
struct irq_desc *
desc)
304 chained_irq_enter(chip, desc);
310 gic_irq = (status & 0x3ff);
315 if (
unlikely(gic_irq < 32 || gic_irq > 1020))
321 chained_irq_exit(chip, desc);
326 .irq_mask = gic_mask_irq,
327 .irq_unmask = gic_unmask_irq,
328 .irq_eoi = gic_eoi_irq,
329 .irq_set_type = gic_set_type,
330 .irq_retrigger = gic_retrigger,
332 .irq_set_affinity = gic_set_affinity,
343 irq_set_chained_handler(irq, gic_handle_cascade_irq);
350 unsigned int gic_irqs = gic->
gic_irqs;
355 cpumask |= cpumask << 8;
356 cpumask |= cpumask << 16;
363 for (i = 32; i < gic_irqs; i += 16)
369 for (i = 32; i < gic_irqs; i += 4)
375 for (i = 32; i < gic_irqs; i += 4)
376 writel_relaxed(0xa0a0a0a0, base +
GIC_DIST_PRI + i * 4 / 4);
382 for (i = 32; i < gic_irqs; i += 32)
404 for (i = 0; i < 32; i += 4)
405 writel_relaxed(0xa0a0a0a0, dist_base +
GIC_DIST_PRI + i * 4 / 4);
418 static void gic_dist_save(
unsigned int gic_nr)
420 unsigned int gic_irqs;
427 gic_irqs = gic_data[gic_nr].gic_irqs;
434 gic_data[gic_nr].saved_spi_conf[i] =
438 gic_data[gic_nr].saved_spi_target[i] =
442 gic_data[gic_nr].saved_spi_enable[i] =
453 static void gic_dist_restore(
unsigned int gic_nr)
455 unsigned int gic_irqs;
462 gic_irqs = gic_data[gic_nr].gic_irqs;
471 writel_relaxed(gic_data[gic_nr].saved_spi_conf[i],
475 writel_relaxed(0xa0a0a0a0,
479 writel_relaxed(gic_data[gic_nr].saved_spi_target[i],
483 writel_relaxed(gic_data[gic_nr].saved_spi_enable[i],
489 static void gic_cpu_save(
unsigned int gic_nr)
502 if (!dist_base || !cpu_base)
515 static void gic_cpu_restore(
unsigned int gic_nr)
528 if (!dist_base || !cpu_base)
540 writel_relaxed(0xa0a0a0a0, dist_base +
GIC_DIST_PRI + i * 4);
551 #ifdef CONFIG_GIC_NON_BANKED
553 if (!gic_data[i].get_base)
585 BUG_ON(!gic->saved_ppi_enable);
589 BUG_ON(!gic->saved_ppi_conf);
591 if (gic == &gic_data[0])
600 static int gic_irq_domain_map(
struct irq_domain *d,
unsigned int irq,
605 irq_set_chip_and_handler(irq, &gic_chip,
609 irq_set_chip_and_handler(irq, &gic_chip,
617 static int gic_irq_domain_xlate(
struct irq_domain *d,
619 const u32 *intspec,
unsigned int intsize,
620 unsigned long *out_hwirq,
unsigned int *out_type)
628 *out_hwirq = intspec[1] + 16;
639 .map = gic_irq_domain_map,
640 .xlate = gic_irq_domain_xlate,
651 BUG_ON(gic_nr >= MAX_GIC_NR);
653 gic = &gic_data[gic_nr];
654 #ifdef CONFIG_GIC_NON_BANKED
678 "GIC_NON_BANKED not enabled, ignoring %08x offset!",
689 if (gic_nr == 0 && (irq_start & 31) > 0) {
692 irq_start = (irq_start & ~31) + 16;
702 gic_irqs = (gic_irqs + 1) * 32;
707 gic_irqs -= hwirq_base;
708 irq_base = irq_alloc_descs(irq_start, 16, gic_irqs,
numa_node_id());
710 WARN(1,
"Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
712 irq_base = irq_start;
715 hwirq_base, &gic_irq_domain_ops, gic);
727 BUG_ON(gic_nr >= MAX_GIC_NR);
729 gic_cpu_init(&gic_data[gic_nr]);
736 unsigned long map = 0;
767 WARN(!dist_base,
"unable to map gic dist registers\n");
770 WARN(!cpu_base,
"unable to map gic cpu registers\n");
772 if (of_property_read_u32(node,
"cpu-offset", &percpu_offset))
775 gic_init_bases(gic_cnt, -1, dist_base, cpu_base, percpu_offset, node);