b830914e32d306263616894fb7cf324f51fb73e0
2 * SS1000/SC2000 interrupt handling.
4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Heavily based on arch/sparc/kernel/irq.c.
8 #include <linux/kernel_stat.h>
9 #include <linux/seq_file.h>
11 #include <asm/timer.h>
12 #include <asm/traps.h>
16 #include <asm/cacheflush.h>
17 #include <asm/setup.h>
22 /* Sun4d interrupts fall roughly into two categories. SBUS and
23 * cpu local. CPU local interrupts cover the timer interrupts
24 * and whatnot, and we encode those as normal PILs between
26 * SBUS interrupts are encodes as a combination of board, level and slot.
29 struct sun4d_handler_data
{
30 unsigned int cpuid
; /* target cpu */
31 unsigned int real_irq
; /* interrupt level */
35 static unsigned int sun4d_encode_irq(int board
, int lvl
, int slot
)
37 return (board
+ 1) << 5 | (lvl
<< 2) | slot
;
40 struct sun4d_timer_regs
{
43 u32 l10_limit_noclear
;
48 static struct sun4d_timer_regs __iomem
*sun4d_timers
;
50 #define SUN4D_TIMER_IRQ 10
52 /* Specify which cpu handle interrupts from which board.
53 * Index is board - value is cpu.
55 static unsigned char board_to_cpu
[32];
57 static int pil_to_sbus
[] = {
76 /* Exported for sun4d_smp.c */
77 DEFINE_SPINLOCK(sun4d_imsk_lock
);
79 /* SBUS interrupts are encoded integers including the board number
80 * (plus one), the SBUS level, and the SBUS slot number. Sun4D
81 * IRQ dispatch is done by:
83 * 1) Reading the BW local interrupt table in order to get the bus
86 * This table is indexed by SBUS interrupt level which can be
87 * derived from the PIL we got interrupted on.
89 * 2) For each bus showing interrupt pending from #1, read the
90 * SBI interrupt state register. This will indicate which slots
91 * have interrupts pending for that SBUS interrupt level.
93 * 3) Call the genreric IRQ support.
95 static void sun4d_sbus_handler_irq(int sbusl
)
97 unsigned int bus_mask
;
98 unsigned int sbino
, slot
;
101 bus_mask
= bw_get_intr_mask(sbusl
) & 0x3ffff;
102 bw_clear_intr_mask(sbusl
, bus_mask
);
105 /* Loop for each pending SBI */
106 for (sbino
= 0; bus_mask
; sbino
++) {
107 unsigned int idx
, mask
;
112 /* XXX This seems to ACK the irq twice. acquire_sbi()
113 * XXX uses swap, therefore this writes 0xf << sbil,
114 * XXX then later release_sbi() will write the individual
115 * XXX bits which were set again.
117 mask
= acquire_sbi(SBI2DEVID(sbino
), 0xf << sbil
);
118 mask
&= (0xf << sbil
);
120 /* Loop for each pending SBI slot */
125 struct irq_bucket
*p
;
133 pil
= sun4d_encode_irq(sbino
, sbil
, idx
);
137 struct irq_bucket
*next
;
140 generic_handle_irq(p
->irq
);
143 release_sbi(SBI2DEVID(sbino
), slot
);
148 void sun4d_handler_irq(int pil
, struct pt_regs
*regs
)
150 struct pt_regs
*old_regs
;
151 /* SBUS IRQ level (1 - 7) */
152 int sbusl
= pil_to_sbus
[pil
];
154 /* FIXME: Is this necessary?? */
157 cc_set_iclr(1 << pil
);
159 old_regs
= set_irq_regs(regs
);
163 struct irq_bucket
*p
;
167 struct irq_bucket
*next
;
170 generic_handle_irq(p
->irq
);
175 sun4d_sbus_handler_irq(sbusl
);
178 set_irq_regs(old_regs
);
182 static void sun4d_mask_irq(struct irq_data
*data
)
184 struct sun4d_handler_data
*handler_data
= data
->handler_data
;
185 unsigned int real_irq
;
187 int cpuid
= handler_data
->cpuid
;
190 real_irq
= handler_data
->real_irq
;
192 spin_lock_irqsave(&sun4d_imsk_lock
, flags
);
193 cc_set_imsk_other(cpuid
, cc_get_imsk_other(cpuid
) | (1 << real_irq
));
194 spin_unlock_irqrestore(&sun4d_imsk_lock
, flags
);
196 cc_set_imsk(cc_get_imsk() | (1 << real_irq
));
200 static void sun4d_unmask_irq(struct irq_data
*data
)
202 struct sun4d_handler_data
*handler_data
= data
->handler_data
;
203 unsigned int real_irq
;
205 int cpuid
= handler_data
->cpuid
;
208 real_irq
= handler_data
->real_irq
;
211 spin_lock_irqsave(&sun4d_imsk_lock
, flags
);
212 cc_set_imsk_other(cpuid
, cc_get_imsk_other(cpuid
) | ~(1 << real_irq
));
213 spin_unlock_irqrestore(&sun4d_imsk_lock
, flags
);
215 cc_set_imsk(cc_get_imsk() | ~(1 << real_irq
));
219 static unsigned int sun4d_startup_irq(struct irq_data
*data
)
222 sun4d_unmask_irq(data
);
226 static void sun4d_shutdown_irq(struct irq_data
*data
)
228 sun4d_mask_irq(data
);
229 irq_unlink(data
->irq
);
232 struct irq_chip sun4d_irq
= {
234 .irq_startup
= sun4d_startup_irq
,
235 .irq_shutdown
= sun4d_shutdown_irq
,
236 .irq_unmask
= sun4d_unmask_irq
,
237 .irq_mask
= sun4d_mask_irq
,
241 static void sun4d_set_cpu_int(int cpu
, int level
)
243 sun4d_send_ipi(cpu
, level
);
246 static void sun4d_clear_ipi(int cpu
, int level
)
250 static void sun4d_set_udt(int cpu
)
254 /* Setup IRQ distribution scheme. */
255 void __init
sun4d_distribute_irqs(void)
257 struct device_node
*dp
;
259 int cpuid
= cpu_logical_map(1);
262 cpuid
= cpu_logical_map(0);
263 for_each_node_by_name(dp
, "sbi") {
264 int devid
= of_getintprop_default(dp
, "device-id", 0);
265 int board
= of_getintprop_default(dp
, "board#", 0);
266 board_to_cpu
[board
] = cpuid
;
267 set_sbi_tid(devid
, cpuid
<< 3);
269 printk(KERN_ERR
"All sbus IRQs directed to CPU%d\n", cpuid
);
273 static void sun4d_clear_clock_irq(void)
275 sbus_readl(&sun4d_timers
->l10_timer_limit
);
278 static void sun4d_load_profile_irq(int cpu
, unsigned int limit
)
280 bw_set_prof_limit(cpu
, limit
);
283 static void __init
sun4d_load_profile_irqs(void)
287 while (!cpu_find_by_instance(cpu
, NULL
, &mid
)) {
288 sun4d_load_profile_irq(mid
>> 3, 0);
293 unsigned int sun4d_build_device_irq(struct platform_device
*op
,
294 unsigned int real_irq
)
296 struct device_node
*dp
= op
->dev
.of_node
;
297 struct device_node
*io_unit
, *sbi
= dp
->parent
;
298 const struct linux_prom_registers
*regs
;
299 struct sun4d_handler_data
*handler_data
;
307 if (!strcmp(sbi
->name
, "sbi"))
315 regs
= of_get_property(dp
, "reg", NULL
);
319 slot
= regs
->which_io
;
322 * If SBI's parent is not io-unit or the io-unit lacks
323 * a "board#" property, something is very wrong.
325 if (!sbi
->parent
|| strcmp(sbi
->parent
->name
, "io-unit")) {
326 printk("%s: Error, parent is not io-unit.\n", sbi
->full_name
);
329 io_unit
= sbi
->parent
;
330 board
= of_getintprop_default(io_unit
, "board#", -1);
332 printk("%s: Error, lacks board# property.\n", io_unit
->full_name
);
336 sbusl
= pil_to_sbus
[real_irq
];
338 pil
= sun4d_encode_irq(board
, sbusl
, slot
);
342 irq
= irq_alloc(real_irq
, pil
);
346 handler_data
= irq_get_handler_data(irq
);
347 if (unlikely(handler_data
))
350 handler_data
= kzalloc(sizeof(struct sun4d_handler_data
), GFP_ATOMIC
);
351 if (unlikely(!handler_data
)) {
352 prom_printf("IRQ: kzalloc(sun4d_handler_data) failed.\n");
355 handler_data
->cpuid
= board_to_cpu
[board
];
356 handler_data
->real_irq
= real_irq
;
357 irq_set_chip_and_handler_name(irq
, &sun4d_irq
,
358 handle_level_irq
, "level");
359 irq_set_handler_data(irq
, handler_data
);
365 static void __init
sun4d_fixup_trap_table(void)
369 struct tt_entry
*trap_table
= &sparc_ttable
[SP_TRAP_IRQ1
+ (14 - 1)];
371 /* Adjust so that we jump directly to smp4d_ticker */
372 lvl14_save
[2] += smp4d_ticker
- real_irq_entry
;
374 /* For SMP we use the level 14 ticker, however the bootup code
375 * has copied the firmware's level 14 vector into the boot cpu's
376 * trap table, we must fix this now or we get squashed.
378 local_irq_save(flags
);
379 patchme_maybe_smp_msg
[0] = 0x01000000; /* NOP out the branch */
380 trap_table
->inst_one
= lvl14_save
[0];
381 trap_table
->inst_two
= lvl14_save
[1];
382 trap_table
->inst_three
= lvl14_save
[2];
383 trap_table
->inst_four
= lvl14_save
[3];
384 local_flush_cache_all();
385 local_irq_restore(flags
);
389 static void __init
sun4d_init_timers(irq_handler_t counter_fn
)
391 struct device_node
*dp
;
397 dp
= of_find_node_by_name(NULL
, "cpu-unit");
399 prom_printf("sun4d_init_timers: Unable to find cpu-unit\n");
403 /* Which cpu-unit we use is arbitrary, we can view the bootbus timer
404 * registers via any cpu's mapping. The first 'reg' property is the
407 reg
= of_get_property(dp
, "reg", NULL
);
410 prom_printf("sun4d_init_timers: No reg property\n");
415 res
.end
= reg
[2] - 1;
416 res
.flags
= reg
[0] & 0xff;
417 sun4d_timers
= of_ioremap(&res
, BW_TIMER_LIMIT
,
418 sizeof(struct sun4d_timer_regs
), "user timer");
420 prom_printf("sun4d_init_timers: Can't map timer regs\n");
424 sbus_writel((((1000000/HZ
) + 1) << 10), &sun4d_timers
->l10_timer_limit
);
426 master_l10_counter
= &sun4d_timers
->l10_cur_count
;
428 irq
= sun4d_build_device_irq(NULL
, SUN4D_TIMER_IRQ
);
429 err
= request_irq(irq
, counter_fn
, IRQF_TIMER
, "timer", NULL
);
431 prom_printf("sun4d_init_timers: request_irq() failed with %d\n",
435 sun4d_load_profile_irqs();
436 sun4d_fixup_trap_table();
439 void __init
sun4d_init_sbi_irq(void)
441 struct device_node
*dp
;
444 target_cpu
= boot_cpu_id
;
445 for_each_node_by_name(dp
, "sbi") {
446 int devid
= of_getintprop_default(dp
, "device-id", 0);
447 int board
= of_getintprop_default(dp
, "board#", 0);
450 set_sbi_tid(devid
, target_cpu
<< 3);
451 board_to_cpu
[board
] = target_cpu
;
453 /* Get rid of pending irqs from PROM */
454 mask
= acquire_sbi(devid
, 0xffffffff);
456 printk(KERN_ERR
"Clearing pending IRQs %08x on SBI %d\n",
458 release_sbi(devid
, mask
);
463 void __init
sun4d_init_IRQ(void)
467 BTFIXUPSET_CALL(clear_clock_irq
, sun4d_clear_clock_irq
, BTFIXUPCALL_NORM
);
468 BTFIXUPSET_CALL(load_profile_irq
, sun4d_load_profile_irq
, BTFIXUPCALL_NORM
);
470 sparc_irq_config
.init_timers
= sun4d_init_timers
;
471 sparc_irq_config
.build_device_irq
= sun4d_build_device_irq
;
474 BTFIXUPSET_CALL(set_cpu_int
, sun4d_set_cpu_int
, BTFIXUPCALL_NORM
);
475 BTFIXUPSET_CALL(clear_cpu_int
, sun4d_clear_ipi
, BTFIXUPCALL_NOP
);
476 BTFIXUPSET_CALL(set_irq_udt
, sun4d_set_udt
, BTFIXUPCALL_NOP
);
478 /* Cannot enable interrupts until OBP ticker is disabled. */
This page took 0.044621 seconds and 4 git commands to generate.