oss.c 5.3 KB

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