oss.c 7.0 KB

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