irq.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * arch/sh/boards/dreamcast/irq.c
  3. *
  4. * Holly IRQ support for the Sega Dreamcast.
  5. *
  6. * Copyright (c) 2001, 2002 M. R. Brown <mrbrown@0xd6.org>
  7. *
  8. * This file is part of the LinuxDC project (www.linuxdc.org)
  9. * Released under the terms of the GNU GPL v2.0
  10. */
  11. #include <linux/irq.h>
  12. #include <linux/io.h>
  13. #include <asm/irq.h>
  14. #include <mach/sysasic.h>
  15. /*
  16. * Dreamcast System ASIC Hardware Events -
  17. *
  18. * The Dreamcast's System ASIC (a.k.a. Holly) is responsible for receiving
  19. * hardware events from system peripherals and triggering an SH7750 IRQ.
  20. * Hardware events can trigger IRQs 13, 11, or 9 depending on which bits are
  21. * set in the Event Mask Registers (EMRs). When a hardware event is
  22. * triggered, its corresponding bit in the Event Status Registers (ESRs)
  23. * is set, and that bit should be rewritten to the ESR to acknowledge that
  24. * event.
  25. *
  26. * There are three 32-bit ESRs located at 0xa05f6900 - 0xa05f6908. Event
  27. * types can be found in arch/sh/include/mach-dreamcast/mach/sysasic.h.
  28. * There are three groups of EMRs that parallel the ESRs. Each EMR group
  29. * corresponds to an IRQ, so 0xa05f6910 - 0xa05f6918 triggers IRQ 13,
  30. * 0xa05f6920 - 0xa05f6928 triggers IRQ 11, and 0xa05f6930 - 0xa05f6938
  31. * triggers IRQ 9.
  32. *
  33. * In the kernel, these events are mapped to virtual IRQs so that drivers can
  34. * respond to them as they would a normal interrupt. In order to keep this
  35. * mapping simple, the events are mapped as:
  36. *
  37. * 6900/6910 - Events 0-31, IRQ 13
  38. * 6904/6924 - Events 32-63, IRQ 11
  39. * 6908/6938 - Events 64-95, IRQ 9
  40. *
  41. */
  42. #define ESR_BASE 0x005f6900 /* Base event status register */
  43. #define EMR_BASE 0x005f6910 /* Base event mask register */
  44. /*
  45. * Helps us determine the EMR group that this event belongs to: 0 = 0x6910,
  46. * 1 = 0x6920, 2 = 0x6930; also determine the event offset.
  47. */
  48. #define LEVEL(event) (((event) - HW_EVENT_IRQ_BASE) / 32)
  49. /* Return the hardware event's bit position within the EMR/ESR */
  50. #define EVENT_BIT(event) (((event) - HW_EVENT_IRQ_BASE) & 31)
  51. /*
  52. * For each of these *_irq routines, the IRQ passed in is the virtual IRQ
  53. * (logically mapped to the corresponding bit for the hardware event).
  54. */
  55. /* Disable the hardware event by masking its bit in its EMR */
  56. static inline void disable_systemasic_irq(struct irq_data *data)
  57. {
  58. unsigned int irq = data->irq;
  59. __u32 emr = EMR_BASE + (LEVEL(irq) << 4) + (LEVEL(irq) << 2);
  60. __u32 mask;
  61. mask = inl(emr);
  62. mask &= ~(1 << EVENT_BIT(irq));
  63. outl(mask, emr);
  64. }
  65. /* Enable the hardware event by setting its bit in its EMR */
  66. static inline void enable_systemasic_irq(struct irq_data *data)
  67. {
  68. unsigned int irq = data->irq;
  69. __u32 emr = EMR_BASE + (LEVEL(irq) << 4) + (LEVEL(irq) << 2);
  70. __u32 mask;
  71. mask = inl(emr);
  72. mask |= (1 << EVENT_BIT(irq));
  73. outl(mask, emr);
  74. }
  75. /* Acknowledge a hardware event by writing its bit back to its ESR */
  76. static void mask_ack_systemasic_irq(struct irq_data *data)
  77. {
  78. unsigned int irq = data->irq;
  79. __u32 esr = ESR_BASE + (LEVEL(irq) << 2);
  80. disable_systemasic_irq(data);
  81. outl((1 << EVENT_BIT(irq)), esr);
  82. }
  83. struct irq_chip systemasic_int = {
  84. .name = "System ASIC",
  85. .irq_mask = disable_systemasic_irq,
  86. .irq_mask_ack = mask_ack_systemasic_irq,
  87. .irq_unmask = enable_systemasic_irq,
  88. };
  89. /*
  90. * Map the hardware event indicated by the processor IRQ to a virtual IRQ.
  91. */
  92. int systemasic_irq_demux(int irq)
  93. {
  94. __u32 emr, esr, status, level;
  95. __u32 j, bit;
  96. switch (irq) {
  97. case 13:
  98. level = 0;
  99. break;
  100. case 11:
  101. level = 1;
  102. break;
  103. case 9:
  104. level = 2;
  105. break;
  106. default:
  107. return irq;
  108. }
  109. emr = EMR_BASE + (level << 4) + (level << 2);
  110. esr = ESR_BASE + (level << 2);
  111. /* Mask the ESR to filter any spurious, unwanted interrupts */
  112. status = inl(esr);
  113. status &= inl(emr);
  114. /* Now scan and find the first set bit as the event to map */
  115. for (bit = 1, j = 0; j < 32; bit <<= 1, j++) {
  116. if (status & bit) {
  117. irq = HW_EVENT_IRQ_BASE + j + (level << 5);
  118. return irq;
  119. }
  120. }
  121. /* Not reached */
  122. return irq;
  123. }
  124. void systemasic_irq_init(void)
  125. {
  126. int i, nid = cpu_to_node(boot_cpu_data);
  127. /* Assign all virtual IRQs to the System ASIC int. handler */
  128. for (i = HW_EVENT_IRQ_BASE; i < HW_EVENT_IRQ_MAX; i++) {
  129. unsigned int irq;
  130. irq = create_irq_nr(i, nid);
  131. if (unlikely(irq == 0)) {
  132. pr_err("%s: failed hooking irq %d for systemasic\n",
  133. __func__, i);
  134. return;
  135. }
  136. if (unlikely(irq != i)) {
  137. pr_err("%s: got irq %d but wanted %d, bailing.\n",
  138. __func__, irq, i);
  139. destroy_irq(irq);
  140. return;
  141. }
  142. irq_set_chip_and_handler(i, &systemasic_int, handle_level_irq);
  143. }
  144. }