oss.c 4.9 KB

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