oss.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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(unsigned int irq, struct irq_desc *desc)
  54. {
  55. int events = oss->irq_pending &
  56. (OSS_IP_IOPSCC | OSS_IP_SCSI | OSS_IP_IOPISM);
  57. #ifdef DEBUG_IRQS
  58. if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
  59. printk("oss_irq: irq %u events = 0x%04X\n", irq,
  60. (int) oss->irq_pending);
  61. }
  62. #endif
  63. if (events & OSS_IP_IOPSCC) {
  64. oss->irq_pending &= ~OSS_IP_IOPSCC;
  65. generic_handle_irq(IRQ_MAC_SCC);
  66. }
  67. if (events & OSS_IP_SCSI) {
  68. oss->irq_pending &= ~OSS_IP_SCSI;
  69. generic_handle_irq(IRQ_MAC_SCSI);
  70. }
  71. if (events & OSS_IP_IOPISM) {
  72. oss->irq_pending &= ~OSS_IP_IOPISM;
  73. generic_handle_irq(IRQ_MAC_ADB);
  74. }
  75. }
  76. /*
  77. * Nubus IRQ handler, OSS style
  78. *
  79. * Unlike the VIA/RBV this is on its own autovector interrupt level.
  80. */
  81. static void oss_nubus_irq(unsigned int irq, struct irq_desc *desc)
  82. {
  83. int events, irq_bit, i;
  84. events = oss->irq_pending & OSS_IP_NUBUS;
  85. if (!events)
  86. return;
  87. #ifdef DEBUG_NUBUS_INT
  88. if (console_loglevel > 7) {
  89. printk("oss_nubus_irq: events = 0x%04X\n", events);
  90. }
  91. #endif
  92. /* There are only six slots on the OSS, not seven */
  93. i = 6;
  94. irq_bit = 0x40;
  95. do {
  96. --i;
  97. irq_bit >>= 1;
  98. if (events & irq_bit) {
  99. oss->irq_pending &= ~irq_bit;
  100. generic_handle_irq(NUBUS_SOURCE_BASE + i);
  101. }
  102. } while(events & (irq_bit - 1));
  103. }
  104. /*
  105. * Register the OSS and NuBus interrupt dispatchers.
  106. *
  107. * This IRQ mapping is laid out with two things in mind: first, we try to keep
  108. * things on their own levels to avoid having to do double-dispatches. Second,
  109. * the levels match as closely as possible the alternate IRQ mapping mode (aka
  110. * "A/UX mode") available on some VIA machines.
  111. */
  112. #define OSS_IRQLEV_IOPISM IRQ_AUTO_1
  113. #define OSS_IRQLEV_SCSI IRQ_AUTO_2
  114. #define OSS_IRQLEV_NUBUS IRQ_AUTO_3
  115. #define OSS_IRQLEV_IOPSCC IRQ_AUTO_4
  116. #define OSS_IRQLEV_VIA1 IRQ_AUTO_6
  117. void __init oss_register_interrupts(void)
  118. {
  119. irq_set_chained_handler(OSS_IRQLEV_IOPISM, oss_irq);
  120. irq_set_chained_handler(OSS_IRQLEV_SCSI, oss_irq);
  121. irq_set_chained_handler(OSS_IRQLEV_NUBUS, oss_nubus_irq);
  122. irq_set_chained_handler(OSS_IRQLEV_IOPSCC, oss_irq);
  123. irq_set_chained_handler(OSS_IRQLEV_VIA1, via1_irq);
  124. /* OSS_VIA1 gets enabled here because it has no machspec interrupt. */
  125. oss->irq_level[OSS_VIA1] = IRQ_AUTO_6;
  126. }
  127. /*
  128. * Enable an OSS interrupt
  129. *
  130. * It looks messy but it's rather straightforward. The switch() statement
  131. * just maps the machspec interrupt numbers to the right OSS interrupt
  132. * source (if the OSS handles that interrupt) and then sets the interrupt
  133. * level for that source to nonzero, thus enabling the interrupt.
  134. */
  135. void oss_irq_enable(int irq) {
  136. #ifdef DEBUG_IRQUSE
  137. printk("oss_irq_enable(%d)\n", irq);
  138. #endif
  139. switch(irq) {
  140. case IRQ_MAC_SCC:
  141. oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
  142. return;
  143. case IRQ_MAC_ADB:
  144. oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
  145. return;
  146. case IRQ_MAC_SCSI:
  147. oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
  148. return;
  149. case IRQ_NUBUS_9:
  150. case IRQ_NUBUS_A:
  151. case IRQ_NUBUS_B:
  152. case IRQ_NUBUS_C:
  153. case IRQ_NUBUS_D:
  154. case IRQ_NUBUS_E:
  155. irq -= NUBUS_SOURCE_BASE;
  156. oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
  157. return;
  158. }
  159. if (IRQ_SRC(irq) == 1)
  160. via_irq_enable(irq);
  161. }
  162. /*
  163. * Disable an OSS interrupt
  164. *
  165. * Same as above except we set the source's interrupt level to zero,
  166. * to disable the interrupt.
  167. */
  168. void oss_irq_disable(int irq) {
  169. #ifdef DEBUG_IRQUSE
  170. printk("oss_irq_disable(%d)\n", irq);
  171. #endif
  172. switch(irq) {
  173. case IRQ_MAC_SCC:
  174. oss->irq_level[OSS_IOPSCC] = 0;
  175. return;
  176. case IRQ_MAC_ADB:
  177. oss->irq_level[OSS_IOPISM] = 0;
  178. return;
  179. case IRQ_MAC_SCSI:
  180. oss->irq_level[OSS_SCSI] = 0;
  181. return;
  182. case IRQ_NUBUS_9:
  183. case IRQ_NUBUS_A:
  184. case IRQ_NUBUS_B:
  185. case IRQ_NUBUS_C:
  186. case IRQ_NUBUS_D:
  187. case IRQ_NUBUS_E:
  188. irq -= NUBUS_SOURCE_BASE;
  189. oss->irq_level[irq] = 0;
  190. return;
  191. }
  192. if (IRQ_SRC(irq) == 1)
  193. via_irq_disable(irq);
  194. }