oss.c 7.0 KB

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