oss.c 6.7 KB

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