oss.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Operating System Services (OSS) chip handling
  4. * Written by Joshua M. Thompson (funaho@jurai.org)
  5. *
  6. *
  7. * This chip is used in the IIfx in place of VIA #2. It acts like a fancy
  8. * VIA chip with prorammable interrupt levels.
  9. *
  10. * 990502 (jmt) - Major rewrite for new interrupt architecture as well as some
  11. * recent insights into OSS operational details.
  12. * 990610 (jmt) - Now taking full advantage of the OSS. Interrupts are mapped
  13. * to mostly match the A/UX interrupt scheme supported on the
  14. * VIA side. Also added support for enabling the ISM irq again
  15. * since we now have a functional IOP manager.
  16. */
  17. #include <linux/types.h>
  18. #include <linux/kernel.h>
  19. #include <linux/mm.h>
  20. #include <linux/delay.h>
  21. #include <linux/init.h>
  22. #include <linux/irq.h>
  23. #include <asm/macintosh.h>
  24. #include <asm/macints.h>
  25. #include <asm/mac_via.h>
  26. #include <asm/mac_oss.h>
  27. #include "mac.h"
  28. int oss_present;
  29. volatile struct mac_oss *oss;
  30. /*
  31. * Initialize the OSS
  32. */
  33. void __init oss_init(void)
  34. {
  35. int i;
  36. if (macintosh_config->ident != MAC_MODEL_IIFX)
  37. return;
  38. oss = (struct mac_oss *) OSS_BASE;
  39. pr_debug("OSS detected at %p", oss);
  40. oss_present = 1;
  41. /* Disable all interrupts. Unlike a VIA it looks like we */
  42. /* do this by setting the source's interrupt level to zero. */
  43. for (i = 0; i < OSS_NUM_SOURCES; i++)
  44. oss->irq_level[i] = 0;
  45. }
  46. /*
  47. * Handle OSS interrupts.
  48. * XXX how do you clear a pending IRQ? is it even necessary?
  49. */
  50. static void oss_iopism_irq(struct irq_desc *desc)
  51. {
  52. generic_handle_irq(IRQ_MAC_ADB);
  53. }
  54. static void oss_scsi_irq(struct irq_desc *desc)
  55. {
  56. generic_handle_irq(IRQ_MAC_SCSI);
  57. }
  58. static void oss_nubus_irq(struct irq_desc *desc)
  59. {
  60. u16 events, irq_bit;
  61. int irq_num;
  62. events = oss->irq_pending & OSS_IP_NUBUS;
  63. irq_num = NUBUS_SOURCE_BASE + 5;
  64. irq_bit = OSS_IP_NUBUS5;
  65. do {
  66. if (events & irq_bit) {
  67. events &= ~irq_bit;
  68. generic_handle_irq(irq_num);
  69. }
  70. --irq_num;
  71. irq_bit >>= 1;
  72. } while (events);
  73. }
  74. static void oss_iopscc_irq(struct irq_desc *desc)
  75. {
  76. generic_handle_irq(IRQ_MAC_SCC);
  77. }
  78. /*
  79. * Register the OSS and NuBus interrupt dispatchers.
  80. *
  81. * This IRQ mapping is laid out with two things in mind: first, we try to keep
  82. * things on their own levels to avoid having to do double-dispatches. Second,
  83. * the levels match as closely as possible the alternate IRQ mapping mode (aka
  84. * "A/UX mode") available on some VIA machines.
  85. */
  86. #define OSS_IRQLEV_IOPISM IRQ_AUTO_1
  87. #define OSS_IRQLEV_SCSI IRQ_AUTO_2
  88. #define OSS_IRQLEV_NUBUS IRQ_AUTO_3
  89. #define OSS_IRQLEV_IOPSCC IRQ_AUTO_4
  90. #define OSS_IRQLEV_VIA1 IRQ_AUTO_6
  91. void __init oss_register_interrupts(void)
  92. {
  93. irq_set_chained_handler(OSS_IRQLEV_IOPISM, oss_iopism_irq);
  94. irq_set_chained_handler(OSS_IRQLEV_SCSI, oss_scsi_irq);
  95. irq_set_chained_handler(OSS_IRQLEV_NUBUS, oss_nubus_irq);
  96. irq_set_chained_handler(OSS_IRQLEV_IOPSCC, oss_iopscc_irq);
  97. irq_set_chained_handler(OSS_IRQLEV_VIA1, via1_irq);
  98. /* OSS_VIA1 gets enabled here because it has no machspec interrupt. */
  99. oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
  100. }
  101. /*
  102. * Enable an OSS interrupt
  103. *
  104. * It looks messy but it's rather straightforward. The switch() statement
  105. * just maps the machspec interrupt numbers to the right OSS interrupt
  106. * source (if the OSS handles that interrupt) and then sets the interrupt
  107. * level for that source to nonzero, thus enabling the interrupt.
  108. */
  109. void oss_irq_enable(int irq) {
  110. switch(irq) {
  111. case IRQ_MAC_SCC:
  112. oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
  113. return;
  114. case IRQ_MAC_ADB:
  115. oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
  116. return;
  117. case IRQ_MAC_SCSI:
  118. oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
  119. return;
  120. case IRQ_NUBUS_9:
  121. case IRQ_NUBUS_A:
  122. case IRQ_NUBUS_B:
  123. case IRQ_NUBUS_C:
  124. case IRQ_NUBUS_D:
  125. case IRQ_NUBUS_E:
  126. irq -= NUBUS_SOURCE_BASE;
  127. oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
  128. return;
  129. }
  130. if (IRQ_SRC(irq) == 1)
  131. via_irq_enable(irq);
  132. }
  133. /*
  134. * Disable an OSS interrupt
  135. *
  136. * Same as above except we set the source's interrupt level to zero,
  137. * to disable the interrupt.
  138. */
  139. void oss_irq_disable(int irq) {
  140. switch(irq) {
  141. case IRQ_MAC_SCC:
  142. oss->irq_level[OSS_IOPSCC] = 0;
  143. return;
  144. case IRQ_MAC_ADB:
  145. oss->irq_level[OSS_IOPISM] = 0;
  146. return;
  147. case IRQ_MAC_SCSI:
  148. oss->irq_level[OSS_SCSI] = 0;
  149. return;
  150. case IRQ_NUBUS_9:
  151. case IRQ_NUBUS_A:
  152. case IRQ_NUBUS_B:
  153. case IRQ_NUBUS_C:
  154. case IRQ_NUBUS_D:
  155. case IRQ_NUBUS_E:
  156. irq -= NUBUS_SOURCE_BASE;
  157. oss->irq_level[irq] = 0;
  158. return;
  159. }
  160. if (IRQ_SRC(irq) == 1)
  161. via_irq_disable(irq);
  162. }