imask.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * arch/sh/kernel/cpu/irq/imask.c
  3. *
  4. * Copyright (C) 1999, 2000 Niibe Yutaka
  5. *
  6. * Simple interrupt handling using IMASK of SR register.
  7. *
  8. */
  9. /* NOTE: Will not work on level 15 */
  10. #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>
  18. #include <linux/spinlock.h>
  19. #include <linux/cache.h>
  20. #include <linux/irq.h>
  21. #include <linux/bitmap.h>
  22. #include <asm/irq.h>
  23. /* Bitmap of IRQ masked */
  24. #define IMASK_PRIORITY 15
  25. static DECLARE_BITMAP(imask_mask, IMASK_PRIORITY);
  26. static int interrupt_priority;
  27. static inline void set_interrupt_registers(int ip)
  28. {
  29. unsigned long __dummy;
  30. asm volatile(
  31. #ifdef CONFIG_CPU_HAS_SR_RB
  32. "ldc %2, r6_bank\n\t"
  33. #endif
  34. "stc sr, %0\n\t"
  35. "and #0xf0, %0\n\t"
  36. "shlr2 %0\n\t"
  37. "cmp/eq #0x3c, %0\n\t"
  38. "bt/s 1f ! CLI-ed\n\t"
  39. " stc sr, %0\n\t"
  40. "and %1, %0\n\t"
  41. "or %2, %0\n\t"
  42. "ldc %0, sr\n"
  43. "1:"
  44. : "=&z" (__dummy)
  45. : "r" (~0xf0), "r" (ip << 4)
  46. : "t");
  47. }
  48. static void mask_imask_irq(struct irq_data *data)
  49. {
  50. unsigned int irq = data->irq;
  51. clear_bit(irq, imask_mask);
  52. if (interrupt_priority < IMASK_PRIORITY - irq)
  53. interrupt_priority = IMASK_PRIORITY - irq;
  54. set_interrupt_registers(interrupt_priority);
  55. }
  56. static void unmask_imask_irq(struct irq_data *data)
  57. {
  58. unsigned int irq = data->irq;
  59. set_bit(irq, imask_mask);
  60. interrupt_priority = IMASK_PRIORITY -
  61. find_first_zero_bit(imask_mask, IMASK_PRIORITY);
  62. set_interrupt_registers(interrupt_priority);
  63. }
  64. static struct irq_chip imask_irq_chip = {
  65. .name = "SR.IMASK",
  66. .irq_mask = mask_imask_irq,
  67. .irq_unmask = unmask_imask_irq,
  68. .irq_mask_ack = mask_imask_irq,
  69. };
  70. void make_imask_irq(unsigned int irq)
  71. {
  72. irq_set_chip_and_handler_name(irq, &imask_irq_chip, handle_level_irq,
  73. "level");
  74. }