oss.c 6.6 KB

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