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