blob: e7f1745bd12120055977da02c095840d50487802 [file] [log] [blame]
Paul Mundtbf3a00f2006-01-16 22:14:14 -08001/*
2 * arch/sh/kernel/cpu/irq/imask.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1999, 2000 Niibe Yutaka
5 *
6 * Simple interrupt handling using IMASK of SR register.
7 *
8 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07009/* NOTE: Will not work on level 15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/ptrace.h>
11#include <linux/errno.h>
12#include <linux/kernel_stat.h>
13#include <linux/signal.h>
14#include <linux/sched.h>
15#include <linux/interrupt.h>
16#include <linux/init.h>
17#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/spinlock.h>
19#include <linux/cache.h>
20#include <linux/irq.h>
Paul Mundt55620c82009-05-22 01:16:17 +090021#include <linux/bitmap.h>
Paul Mundtbf3a00f2006-01-16 22:14:14 -080022#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/* Bitmap of IRQ masked */
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#define IMASK_PRIORITY 15
26
Paul Mundt55620c82009-05-22 01:16:17 +090027static DECLARE_BITMAP(imask_mask, IMASK_PRIORITY);
28static int interrupt_priority;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Paul Mundt55620c82009-05-22 01:16:17 +090030static inline void set_interrupt_registers(int ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 unsigned long __dummy;
33
Yoshinori Sato9d4436a2006-11-05 15:40:13 +090034 asm volatile(
35#ifdef CONFIG_CPU_HAS_SR_RB
36 "ldc %2, r6_bank\n\t"
37#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 "stc sr, %0\n\t"
39 "and #0xf0, %0\n\t"
40 "shlr2 %0\n\t"
41 "cmp/eq #0x3c, %0\n\t"
42 "bt/s 1f ! CLI-ed\n\t"
43 " stc sr, %0\n\t"
44 "and %1, %0\n\t"
45 "or %2, %0\n\t"
46 "ldc %0, sr\n"
47 "1:"
48 : "=&z" (__dummy)
49 : "r" (~0xf0), "r" (ip << 4)
50 : "t");
51}
52
Paul Mundt949bf162010-10-27 14:54:50 +090053static void mask_imask_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054{
Paul Mundt949bf162010-10-27 14:54:50 +090055 unsigned int irq = data->irq;
56
Paul Mundt3709ab82009-05-26 13:52:28 +090057 clear_bit(irq, imask_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 if (interrupt_priority < IMASK_PRIORITY - irq)
59 interrupt_priority = IMASK_PRIORITY - irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 set_interrupt_registers(interrupt_priority);
61}
62
Paul Mundt949bf162010-10-27 14:54:50 +090063static void unmask_imask_irq(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Paul Mundt949bf162010-10-27 14:54:50 +090065 unsigned int irq = data->irq;
66
Paul Mundt3709ab82009-05-26 13:52:28 +090067 set_bit(irq, imask_mask);
Paul Mundt55620c82009-05-22 01:16:17 +090068 interrupt_priority = IMASK_PRIORITY -
69 find_first_zero_bit(imask_mask, IMASK_PRIORITY);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 set_interrupt_registers(interrupt_priority);
71}
72
Paul Mundt55620c82009-05-22 01:16:17 +090073static struct irq_chip imask_irq_chip = {
Thomas Gleixner648f1532009-11-17 22:50:45 +000074 .name = "SR.IMASK",
Paul Mundt949bf162010-10-27 14:54:50 +090075 .irq_mask = mask_imask_irq,
76 .irq_unmask = unmask_imask_irq,
77 .irq_mask_ack = mask_imask_irq,
Paul Mundt55620c82009-05-22 01:16:17 +090078};
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80void make_imask_irq(unsigned int irq)
81{
Thomas Gleixnerfcb89182011-03-24 16:31:17 +010082 irq_set_chip_and_handler_name(irq, &imask_irq_chip, handle_level_irq,
83 "level");
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}