3 #include <linux/bitmap.h>
4 #include <linux/init.h>
9 #include <asm/gcmpregs.h>
10 #include <asm/mips-boards/maltaint.h>
12 #include <linux/hardirq.h>
13 #include <asm-generic/bitops/find.h>
16 static unsigned long _gic_base
;
17 static unsigned int _irqbase
;
18 static unsigned int gic_irq_flags
[GIC_NUM_INTRS
];
19 #define GIC_IRQ_FLAG_EDGE 0x0001
21 struct gic_pcpu_mask pcpu_masks
[NR_CPUS
];
22 static struct gic_pending_regs pending_regs
[NR_CPUS
];
23 static struct gic_intrmask_regs intrmask_regs
[NR_CPUS
];
25 void gic_send_ipi(unsigned int intr
)
27 pr_debug("CPU%d: %s status %08x\n", smp_processor_id(), __func__
,
29 GICWRITE(GIC_REG(SHARED
, GIC_SH_WEDGE
), 0x80000000 | intr
);
32 /* This is Malta specific and needs to be exported */
33 static void __init
vpe_local_setup(unsigned int numvpes
)
36 unsigned long timer_interrupt
= 5, perf_interrupt
= 5;
40 * Setup the default performance counter timer interrupts
43 for (i
= 0; i
< numvpes
; i
++) {
44 GICWRITE(GIC_REG(VPE_LOCAL
, GIC_VPE_OTHER_ADDR
), i
);
46 /* Are Interrupts locally routable? */
47 GICREAD(GIC_REG(VPE_OTHER
, GIC_VPE_CTL
), vpe_ctl
);
48 if (vpe_ctl
& GIC_VPE_CTL_TIMER_RTBL_MSK
)
49 GICWRITE(GIC_REG(VPE_OTHER
, GIC_VPE_TIMER_MAP
),
50 GIC_MAP_TO_PIN_MSK
| timer_interrupt
);
52 if (vpe_ctl
& GIC_VPE_CTL_PERFCNT_RTBL_MSK
)
53 GICWRITE(GIC_REG(VPE_OTHER
, GIC_VPE_PERFCTR_MAP
),
54 GIC_MAP_TO_PIN_MSK
| perf_interrupt
);
58 unsigned int gic_get_int(void)
61 unsigned long *pending
, *intrmask
, *pcpu_mask
;
62 unsigned long *pending_abs
, *intrmask_abs
;
64 /* Get per-cpu bitmaps */
65 pending
= pending_regs
[smp_processor_id()].pending
;
66 intrmask
= intrmask_regs
[smp_processor_id()].intrmask
;
67 pcpu_mask
= pcpu_masks
[smp_processor_id()].pcpu_mask
;
69 pending_abs
= (unsigned long *) GIC_REG_ABS_ADDR(SHARED
,
70 GIC_SH_PEND_31_0_OFS
);
71 intrmask_abs
= (unsigned long *) GIC_REG_ABS_ADDR(SHARED
,
72 GIC_SH_MASK_31_0_OFS
);
74 for (i
= 0; i
< BITS_TO_LONGS(GIC_NUM_INTRS
); i
++) {
75 GICREAD(*pending_abs
, pending
[i
]);
76 GICREAD(*intrmask_abs
, intrmask
[i
]);
81 bitmap_and(pending
, pending
, intrmask
, GIC_NUM_INTRS
);
82 bitmap_and(pending
, pending
, pcpu_mask
, GIC_NUM_INTRS
);
84 i
= find_first_bit(pending
, GIC_NUM_INTRS
);
86 pr_debug("CPU%d: %s pend=%d\n", smp_processor_id(), __func__
, i
);
91 static unsigned int gic_irq_startup(unsigned int irq
)
94 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__
, irq
);
95 GIC_SET_INTR_MASK(irq
);
99 static void gic_irq_ack(unsigned int irq
)
102 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__
, irq
);
103 GIC_CLR_INTR_MASK(irq
);
105 if (gic_irq_flags
[irq
] & GIC_IRQ_FLAG_EDGE
)
106 GICWRITE(GIC_REG(SHARED
, GIC_SH_WEDGE
), irq
);
109 static void gic_mask_irq(unsigned int irq
)
112 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__
, irq
);
113 GIC_CLR_INTR_MASK(irq
);
116 static void gic_unmask_irq(unsigned int irq
)
119 pr_debug("CPU%d: %s: irq%d\n", smp_processor_id(), __func__
, irq
);
120 GIC_SET_INTR_MASK(irq
);
125 static DEFINE_SPINLOCK(gic_lock
);
127 static int gic_set_affinity(unsigned int irq
, const struct cpumask
*cpumask
)
129 cpumask_t tmp
= CPU_MASK_NONE
;
134 pr_debug(KERN_DEBUG
"%s(%d) called\n", __func__
, irq
);
135 cpumask_and(&tmp
, cpumask
, cpu_online_mask
);
139 /* Assumption : cpumask refers to a single CPU */
140 spin_lock_irqsave(&gic_lock
, flags
);
142 /* Re-route this IRQ */
143 GIC_SH_MAP_TO_VPE_SMASK(irq
, first_cpu(tmp
));
145 /* Update the pcpu_masks */
146 for (i
= 0; i
< NR_CPUS
; i
++)
147 clear_bit(irq
, pcpu_masks
[i
].pcpu_mask
);
148 set_bit(irq
, pcpu_masks
[first_cpu(tmp
)].pcpu_mask
);
151 cpumask_copy(irq_desc
[irq
].affinity
, cpumask
);
152 spin_unlock_irqrestore(&gic_lock
, flags
);
158 static struct irq_chip gic_irq_controller
= {
160 .startup
= gic_irq_startup
,
162 .mask
= gic_mask_irq
,
163 .mask_ack
= gic_mask_irq
,
164 .unmask
= gic_unmask_irq
,
165 .eoi
= gic_unmask_irq
,
167 .set_affinity
= gic_set_affinity
,
171 static void __init
gic_setup_intr(unsigned int intr
, unsigned int cpu
,
172 unsigned int pin
, unsigned int polarity
, unsigned int trigtype
,
175 /* Setup Intr to Pin mapping */
176 if (pin
& GIC_MAP_TO_NMI_MSK
) {
177 GICWRITE(GIC_REG_ADDR(SHARED
, GIC_SH_MAP_TO_PIN(intr
)), pin
);
178 /* FIXME: hack to route NMI to all cpu's */
179 for (cpu
= 0; cpu
< NR_CPUS
; cpu
+= 32) {
180 GICWRITE(GIC_REG_ADDR(SHARED
,
181 GIC_SH_MAP_TO_VPE_REG_OFF(intr
, cpu
)),
185 GICWRITE(GIC_REG_ADDR(SHARED
, GIC_SH_MAP_TO_PIN(intr
)),
186 GIC_MAP_TO_PIN_MSK
| pin
);
187 /* Setup Intr to CPU mapping */
188 GIC_SH_MAP_TO_VPE_SMASK(intr
, cpu
);
191 /* Setup Intr Polarity */
192 GIC_SET_POLARITY(intr
, polarity
);
194 /* Setup Intr Trigger Type */
195 GIC_SET_TRIGGER(intr
, trigtype
);
197 /* Init Intr Masks */
198 GIC_CLR_INTR_MASK(intr
);
199 /* Initialise per-cpu Interrupt software masks */
200 if (flags
& GIC_FLAG_IPI
)
201 set_bit(intr
, pcpu_masks
[cpu
].pcpu_mask
);
202 if (flags
& GIC_FLAG_TRANSPARENT
)
203 GIC_SET_INTR_MASK(intr
);
204 if (trigtype
== GIC_TRIG_EDGE
)
205 gic_irq_flags
[intr
] |= GIC_IRQ_FLAG_EDGE
;
208 static void __init
gic_basic_init(int numintrs
, int numvpes
,
209 struct gic_intr_map
*intrmap
, int mapsize
)
214 for (i
= 0; i
< numintrs
; i
++) {
215 GIC_SET_POLARITY(i
, GIC_POL_POS
);
216 GIC_SET_TRIGGER(i
, GIC_TRIG_LEVEL
);
217 GIC_CLR_INTR_MASK(i
);
218 if (i
< GIC_NUM_INTRS
)
219 gic_irq_flags
[i
] = 0;
222 /* Setup specifics */
223 for (i
= 0; i
< mapsize
; i
++) {
224 cpu
= intrmap
[i
].cpunum
;
227 if (cpu
== 0 && i
!= 0 && intrmap
[i
].flags
== 0)
237 vpe_local_setup(numvpes
);
239 for (i
= _irqbase
; i
< (_irqbase
+ numintrs
); i
++)
240 set_irq_chip(i
, &gic_irq_controller
);
243 void __init
gic_init(unsigned long gic_base_addr
,
244 unsigned long gic_addrspace_size
,
245 struct gic_intr_map
*intr_map
, unsigned int intr_map_size
,
246 unsigned int irqbase
)
248 unsigned int gicconfig
;
249 int numvpes
, numintrs
;
251 _gic_base
= (unsigned long) ioremap_nocache(gic_base_addr
,
255 GICREAD(GIC_REG(SHARED
, GIC_SH_CONFIG
), gicconfig
);
256 numintrs
= (gicconfig
& GIC_SH_CONFIG_NUMINTRS_MSK
) >>
257 GIC_SH_CONFIG_NUMINTRS_SHF
;
258 numintrs
= ((numintrs
+ 1) * 8);
260 numvpes
= (gicconfig
& GIC_SH_CONFIG_NUMVPES_MSK
) >>
261 GIC_SH_CONFIG_NUMVPES_SHF
;
263 pr_debug("%s called\n", __func__
);
265 gic_basic_init(numintrs
, numvpes
, intr_map
, intr_map_size
);