···11+/*22+ * linux/arch/arm/common/gic.c33+ *44+ * Copyright (C) 2002 ARM Limited, All Rights Reserved.55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 as88+ * published by the Free Software Foundation.99+ *1010+ * Interrupt architecture for the GIC:1111+ *1212+ * o There is one Interrupt Distributor, which receives interrupts1313+ * from system devices and sends them to the Interrupt Controllers.1414+ *1515+ * o There is one CPU Interface per CPU, which sends interrupts sent1616+ * by the Distributor, and interrupts generated locally, to the1717+ * associated CPU.1818+ *1919+ * Note that IRQs 0-31 are special - they are local to each CPU.2020+ * As such, the enable set/clear, pending set/clear and active bit2121+ * registers are banked per-cpu for these sources.2222+ */2323+#include <linux/init.h>2424+#include <linux/kernel.h>2525+#include <linux/list.h>2626+#include <linux/smp.h>2727+2828+#include <asm/irq.h>2929+#include <asm/io.h>3030+#include <asm/mach/irq.h>3131+#include <asm/hardware/gic.h>3232+3333+static void __iomem *gic_dist_base;3434+static void __iomem *gic_cpu_base;3535+3636+/*3737+ * Routines to acknowledge, disable and enable interrupts3838+ *3939+ * Linux assumes that when we're done with an interrupt we need to4040+ * unmask it, in the same way we need to unmask an interrupt when4141+ * we first enable it.4242+ *4343+ * The GIC has a seperate notion of "end of interrupt" to re-enable4444+ * an interrupt after handling, in order to support hardware4545+ * prioritisation.4646+ *4747+ * We can make the GIC behave in the way that Linux expects by making4848+ * our "acknowledge" routine disable the interrupt, then mark it as4949+ * complete.5050+ */5151+static void gic_ack_irq(unsigned int irq)5252+{5353+ u32 mask = 1 << (irq % 32);5454+ writel(mask, gic_dist_base + GIC_DIST_ENABLE_CLEAR + (irq / 32) * 4);5555+ writel(irq, gic_cpu_base + GIC_CPU_EOI);5656+}5757+5858+static void gic_mask_irq(unsigned int irq)5959+{6060+ u32 mask = 1 << (irq % 32);6161+ writel(mask, gic_dist_base + GIC_DIST_ENABLE_CLEAR + (irq / 32) * 4);6262+}6363+6464+static void gic_unmask_irq(unsigned int irq)6565+{6666+ u32 mask = 1 << (irq % 32);6767+ writel(mask, gic_dist_base + GIC_DIST_ENABLE_SET + (irq / 32) * 4);6868+}6969+7070+static void gic_set_cpu(struct irqdesc *desc, unsigned int irq, unsigned int cpu)7171+{7272+ void __iomem *reg = gic_dist_base + GIC_DIST_TARGET + (irq & ~3);7373+ unsigned int shift = (irq % 4) * 8;7474+ u32 val;7575+7676+ val = readl(reg) & ~(0xff << shift);7777+ val |= 1 << (cpu + shift);7878+ writel(val, reg);7979+}8080+8181+static struct irqchip gic_chip = {8282+ .ack = gic_ack_irq,8383+ .mask = gic_mask_irq,8484+ .unmask = gic_unmask_irq,8585+#ifdef CONFIG_SMP8686+ .set_cpu = gic_set_cpu,8787+#endif8888+};8989+9090+void __init gic_dist_init(void __iomem *base)9191+{9292+ unsigned int max_irq, i;9393+ u32 cpumask = 1 << smp_processor_id();9494+9595+ cpumask |= cpumask << 8;9696+ cpumask |= cpumask << 16;9797+9898+ gic_dist_base = base;9999+100100+ writel(0, base + GIC_DIST_CTRL);101101+102102+ /*103103+ * Find out how many interrupts are supported.104104+ */105105+ max_irq = readl(base + GIC_DIST_CTR) & 0x1f;106106+ max_irq = (max_irq + 1) * 32;107107+108108+ /*109109+ * The GIC only supports up to 1020 interrupt sources.110110+ * Limit this to either the architected maximum, or the111111+ * platform maximum.112112+ */113113+ if (max_irq > max(1020, NR_IRQS))114114+ max_irq = max(1020, NR_IRQS);115115+116116+ /*117117+ * Set all global interrupts to be level triggered, active low.118118+ */119119+ for (i = 32; i < max_irq; i += 16)120120+ writel(0, base + GIC_DIST_CONFIG + i * 4 / 16);121121+122122+ /*123123+ * Set all global interrupts to this CPU only.124124+ */125125+ for (i = 32; i < max_irq; i += 4)126126+ writel(cpumask, base + GIC_DIST_TARGET + i * 4 / 4);127127+128128+ /*129129+ * Set priority on all interrupts.130130+ */131131+ for (i = 0; i < max_irq; i += 4)132132+ writel(0xa0a0a0a0, base + GIC_DIST_PRI + i * 4 / 4);133133+134134+ /*135135+ * Disable all interrupts.136136+ */137137+ for (i = 0; i < max_irq; i += 32)138138+ writel(0xffffffff, base + GIC_DIST_ENABLE_CLEAR + i * 4 / 32);139139+140140+ /*141141+ * Setup the Linux IRQ subsystem.142142+ */143143+ for (i = 29; i < max_irq; i++) {144144+ set_irq_chip(i, &gic_chip);145145+ set_irq_handler(i, do_level_IRQ);146146+ set_irq_flags(i, IRQF_VALID | IRQF_PROBE);147147+ }148148+149149+ writel(1, base + GIC_DIST_CTRL);150150+}151151+152152+void __cpuinit gic_cpu_init(void __iomem *base)153153+{154154+ gic_cpu_base = base;155155+ writel(0xf0, base + GIC_CPU_PRIMASK);156156+ writel(1, base + GIC_CPU_CTRL);157157+}158158+159159+#ifdef CONFIG_SMP160160+void gic_raise_softirq(cpumask_t cpumask, unsigned int irq)161161+{162162+ unsigned long map = *cpus_addr(cpumask);163163+164164+ writel(map << 16 | irq, gic_dist_base + GIC_DIST_SOFTINT);165165+}166166+#endif
+41
include/asm-arm/hardware/gic.h
···11+/*22+ * linux/include/asm-arm/hardware/gic.h33+ *44+ * Copyright (C) 2002 ARM Limited, All Rights Reserved.55+ *66+ * This program is free software; you can redistribute it and/or modify77+ * it under the terms of the GNU General Public License version 2 as88+ * published by the Free Software Foundation.99+ */1010+#ifndef __ASM_ARM_HARDWARE_GIC_H1111+#define __ASM_ARM_HARDWARE_GIC_H1212+1313+#include <linux/compiler.h>1414+1515+#define GIC_CPU_CTRL 0x001616+#define GIC_CPU_PRIMASK 0x041717+#define GIC_CPU_BINPOINT 0x081818+#define GIC_CPU_INTACK 0x0c1919+#define GIC_CPU_EOI 0x102020+#define GIC_CPU_RUNNINGPRI 0x142121+#define GIC_CPU_HIGHPRI 0x182222+2323+#define GIC_DIST_CTRL 0x0002424+#define GIC_DIST_CTR 0x0042525+#define GIC_DIST_ENABLE_SET 0x1002626+#define GIC_DIST_ENABLE_CLEAR 0x1802727+#define GIC_DIST_PENDING_SET 0x2002828+#define GIC_DIST_PENDING_CLEAR 0x2802929+#define GIC_DIST_ACTIVE_BIT 0x3003030+#define GIC_DIST_PRI 0x4003131+#define GIC_DIST_TARGET 0x8003232+#define GIC_DIST_CONFIG 0xc003333+#define GIC_DIST_SOFTINT 0xf003434+3535+#ifndef __ASSEMBLY__3636+void gic_dist_init(void __iomem *base);3737+void gic_cpu_init(void __iomem *base);3838+void gic_raise_softirq(cpumask_t cpumask, unsigned int irq);3939+#endif4040+4141+#endif