oss.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * OSS 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. extern void via1_irq(unsigned int irq, struct irq_desc *desc);
  30. /*
  31. * Initialize the OSS
  32. *
  33. * The OSS "detection" code is actually in via_init() which is always called
  34. * before us. Thus we can count on oss_present being valid on entry.
  35. */
  36. void __init oss_init(void)
  37. {
  38. int i;
  39. if (!oss_present) return;
  40. oss = (struct mac_oss *) OSS_BASE;
  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] = OSS_IRQLEV_DISABLED;
  45. }
  46. /* If we disable VIA1 here, we never really handle it... */
  47. oss->irq_level[OSS_VIA1] = OSS_IRQLEV_VIA1;
  48. }
  49. /*
  50. * Initialize OSS for Nubus access
  51. */
  52. void __init oss_nubus_init(void)
  53. {
  54. }
  55. /*
  56. * Handle miscellaneous OSS interrupts. Right now that's just sound
  57. * and SCSI; everything else is routed to its own autovector IRQ.
  58. */
  59. static void oss_irq(unsigned int irq, struct irq_desc *desc)
  60. {
  61. int events;
  62. events = oss->irq_pending & (OSS_IP_SOUND|OSS_IP_SCSI);
  63. if (!events)
  64. return;
  65. #ifdef DEBUG_IRQS
  66. if ((console_loglevel == 10) && !(events & OSS_IP_SCSI)) {
  67. printk("oss_irq: irq %u events = 0x%04X\n", irq,
  68. (int) oss->irq_pending);
  69. }
  70. #endif
  71. /* FIXME: how do you clear a pending IRQ? */
  72. if (events & OSS_IP_SOUND) {
  73. oss->irq_pending &= ~OSS_IP_SOUND;
  74. /* FIXME: call sound handler */
  75. } else if (events & OSS_IP_SCSI) {
  76. oss->irq_pending &= ~OSS_IP_SCSI;
  77. generic_handle_irq(IRQ_MAC_SCSI);
  78. } else {
  79. /* FIXME: error check here? */
  80. }
  81. }
  82. /*
  83. * Nubus IRQ handler, OSS style
  84. *
  85. * Unlike the VIA/RBV this is on its own autovector interrupt level.
  86. */
  87. static void oss_nubus_irq(unsigned int irq, struct irq_desc *desc)
  88. {
  89. int events, irq_bit, i;
  90. events = oss->irq_pending & OSS_IP_NUBUS;
  91. if (!events)
  92. return;
  93. #ifdef DEBUG_NUBUS_INT
  94. if (console_loglevel > 7) {
  95. printk("oss_nubus_irq: events = 0x%04X\n", events);
  96. }
  97. #endif
  98. /* There are only six slots on the OSS, not seven */
  99. i = 6;
  100. irq_bit = 0x40;
  101. do {
  102. --i;
  103. irq_bit >>= 1;
  104. if (events & irq_bit) {
  105. oss->irq_pending &= ~irq_bit;
  106. generic_handle_irq(NUBUS_SOURCE_BASE + i);
  107. }
  108. } while(events & (irq_bit - 1));
  109. }
  110. /*
  111. * Register the OSS and NuBus interrupt dispatchers.
  112. */
  113. void __init oss_register_interrupts(void)
  114. {
  115. irq_set_chained_handler(OSS_IRQLEV_SCSI, oss_irq);
  116. irq_set_chained_handler(OSS_IRQLEV_NUBUS, oss_nubus_irq);
  117. irq_set_chained_handler(OSS_IRQLEV_SOUND, oss_irq);
  118. irq_set_chained_handler(OSS_IRQLEV_VIA1, via1_irq);
  119. }
  120. /*
  121. * Enable an OSS interrupt
  122. *
  123. * It looks messy but it's rather straightforward. The switch() statement
  124. * just maps the machspec interrupt numbers to the right OSS interrupt
  125. * source (if the OSS handles that interrupt) and then sets the interrupt
  126. * level for that source to nonzero, thus enabling the interrupt.
  127. */
  128. void oss_irq_enable(int irq) {
  129. #ifdef DEBUG_IRQUSE
  130. printk("oss_irq_enable(%d)\n", irq);
  131. #endif
  132. switch(irq) {
  133. case IRQ_MAC_SCC:
  134. oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
  135. break;
  136. case IRQ_MAC_ADB:
  137. oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
  138. break;
  139. case IRQ_MAC_SCSI:
  140. oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
  141. break;
  142. case IRQ_NUBUS_9:
  143. case IRQ_NUBUS_A:
  144. case IRQ_NUBUS_B:
  145. case IRQ_NUBUS_C:
  146. case IRQ_NUBUS_D:
  147. case IRQ_NUBUS_E:
  148. irq -= NUBUS_SOURCE_BASE;
  149. oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
  150. break;
  151. #ifdef DEBUG_IRQUSE
  152. default:
  153. printk("%s unknown irq %d\n", __func__, irq);
  154. break;
  155. #endif
  156. }
  157. }
  158. /*
  159. * Disable an OSS interrupt
  160. *
  161. * Same as above except we set the source's interrupt level to zero,
  162. * to disable the interrupt.
  163. */
  164. void oss_irq_disable(int irq) {
  165. #ifdef DEBUG_IRQUSE
  166. printk("oss_irq_disable(%d)\n", irq);
  167. #endif
  168. switch(irq) {
  169. case IRQ_MAC_SCC:
  170. oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED;
  171. break;
  172. case IRQ_MAC_ADB:
  173. oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED;
  174. break;
  175. case IRQ_MAC_SCSI:
  176. oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
  177. break;
  178. case IRQ_NUBUS_9:
  179. case IRQ_NUBUS_A:
  180. case IRQ_NUBUS_B:
  181. case IRQ_NUBUS_C:
  182. case IRQ_NUBUS_D:
  183. case IRQ_NUBUS_E:
  184. irq -= NUBUS_SOURCE_BASE;
  185. oss->irq_level[irq] = OSS_IRQLEV_DISABLED;
  186. break;
  187. #ifdef DEBUG_IRQUSE
  188. default:
  189. printk("%s unknown irq %d\n", __func__, irq);
  190. break;
  191. #endif
  192. }
  193. }
  194. /*
  195. * Clear an OSS interrupt
  196. *
  197. * Not sure if this works or not but it's the only method I could
  198. * think of based on the contents of the mac_oss structure.
  199. */
  200. void oss_irq_clear(int irq) {
  201. /* FIXME: how to do this on OSS? */
  202. switch(irq) {
  203. case IRQ_MAC_SCC:
  204. oss->irq_pending &= ~OSS_IP_IOPSCC;
  205. break;
  206. case IRQ_MAC_ADB:
  207. oss->irq_pending &= ~OSS_IP_IOPISM;
  208. break;
  209. case IRQ_MAC_SCSI:
  210. oss->irq_pending &= ~OSS_IP_SCSI;
  211. break;
  212. case IRQ_NUBUS_9:
  213. case IRQ_NUBUS_A:
  214. case IRQ_NUBUS_B:
  215. case IRQ_NUBUS_C:
  216. case IRQ_NUBUS_D:
  217. case IRQ_NUBUS_E:
  218. irq -= NUBUS_SOURCE_BASE;
  219. oss->irq_pending &= ~(1 << irq);
  220. break;
  221. }
  222. }
  223. /*
  224. * Check to see if a specific OSS interrupt is pending
  225. */
  226. int oss_irq_pending(int irq)
  227. {
  228. switch(irq) {
  229. case IRQ_MAC_SCC:
  230. return oss->irq_pending & OSS_IP_IOPSCC;
  231. break;
  232. case IRQ_MAC_ADB:
  233. return oss->irq_pending & OSS_IP_IOPISM;
  234. break;
  235. case IRQ_MAC_SCSI:
  236. return oss->irq_pending & OSS_IP_SCSI;
  237. break;
  238. case IRQ_NUBUS_9:
  239. case IRQ_NUBUS_A:
  240. case IRQ_NUBUS_B:
  241. case IRQ_NUBUS_C:
  242. case IRQ_NUBUS_D:
  243. case IRQ_NUBUS_E:
  244. irq -= NUBUS_SOURCE_BASE;
  245. return oss->irq_pending & (1 << irq);
  246. break;
  247. }
  248. return 0;
  249. }