oss.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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, IRQ_FLG_LOCK,
  56. "scsi", (void *) oss))
  57. pr_err("Couldn't register %s interrupt\n", "scsi");
  58. if (request_irq(OSS_IRQLEV_NUBUS, oss_nubus_irq, IRQ_FLG_LOCK,
  59. "nubus", (void *) oss))
  60. pr_err("Couldn't register %s interrupt\n", "nubus");
  61. if (request_irq(OSS_IRQLEV_SOUND, oss_irq, IRQ_FLG_LOCK,
  62. "sound", (void *) oss))
  63. pr_err("Couldn't register %s interrupt\n", "sound");
  64. if (request_irq(OSS_IRQLEV_VIA1, via1_irq, IRQ_FLG_LOCK,
  65. "via1", (void *) via1))
  66. pr_err("Couldn't register %s interrupt\n", "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. static irqreturn_t oss_irq(int irq, void *dev_id)
  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. oss->irq_pending &= ~OSS_IP_SOUND;
  93. /* FIXME: call sound handler */
  94. } else if (events & OSS_IP_SCSI) {
  95. oss->irq_pending &= ~OSS_IP_SCSI;
  96. m68k_handle_int(IRQ_MAC_SCSI);
  97. } else {
  98. /* FIXME: error check here? */
  99. }
  100. return IRQ_HANDLED;
  101. }
  102. /*
  103. * Nubus IRQ handler, OSS style
  104. *
  105. * Unlike the VIA/RBV this is on its own autovector interrupt level.
  106. */
  107. static irqreturn_t oss_nubus_irq(int irq, void *dev_id)
  108. {
  109. int events, irq_bit, i;
  110. events = oss->irq_pending & OSS_IP_NUBUS;
  111. if (!events)
  112. return IRQ_NONE;
  113. #ifdef DEBUG_NUBUS_INT
  114. if (console_loglevel > 7) {
  115. printk("oss_nubus_irq: events = 0x%04X\n", events);
  116. }
  117. #endif
  118. /* There are only six slots on the OSS, not seven */
  119. i = 6;
  120. irq_bit = 0x40;
  121. do {
  122. --i;
  123. irq_bit >>= 1;
  124. if (events & irq_bit) {
  125. oss->irq_pending &= ~irq_bit;
  126. m68k_handle_int(NUBUS_SOURCE_BASE + i);
  127. }
  128. } while(events & (irq_bit - 1));
  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_MAC_SCC:
  145. oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_IOPSCC;
  146. break;
  147. case IRQ_MAC_ADB:
  148. oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_IOPISM;
  149. break;
  150. case IRQ_MAC_SCSI:
  151. oss->irq_level[OSS_SCSI] = OSS_IRQLEV_SCSI;
  152. break;
  153. case IRQ_NUBUS_9:
  154. case IRQ_NUBUS_A:
  155. case IRQ_NUBUS_B:
  156. case IRQ_NUBUS_C:
  157. case IRQ_NUBUS_D:
  158. case IRQ_NUBUS_E:
  159. irq -= NUBUS_SOURCE_BASE;
  160. oss->irq_level[irq] = OSS_IRQLEV_NUBUS;
  161. break;
  162. #ifdef DEBUG_IRQUSE
  163. default:
  164. printk("%s unknown irq %d\n", __func__, irq);
  165. break;
  166. #endif
  167. }
  168. }
  169. /*
  170. * Disable an OSS interrupt
  171. *
  172. * Same as above except we set the source's interrupt level to zero,
  173. * to disable the interrupt.
  174. */
  175. void oss_irq_disable(int irq) {
  176. #ifdef DEBUG_IRQUSE
  177. printk("oss_irq_disable(%d)\n", irq);
  178. #endif
  179. switch(irq) {
  180. case IRQ_MAC_SCC:
  181. oss->irq_level[OSS_IOPSCC] = OSS_IRQLEV_DISABLED;
  182. break;
  183. case IRQ_MAC_ADB:
  184. oss->irq_level[OSS_IOPISM] = OSS_IRQLEV_DISABLED;
  185. break;
  186. case IRQ_MAC_SCSI:
  187. oss->irq_level[OSS_SCSI] = OSS_IRQLEV_DISABLED;
  188. break;
  189. case IRQ_NUBUS_9:
  190. case IRQ_NUBUS_A:
  191. case IRQ_NUBUS_B:
  192. case IRQ_NUBUS_C:
  193. case IRQ_NUBUS_D:
  194. case IRQ_NUBUS_E:
  195. irq -= NUBUS_SOURCE_BASE;
  196. oss->irq_level[irq] = OSS_IRQLEV_DISABLED;
  197. break;
  198. #ifdef DEBUG_IRQUSE
  199. default:
  200. printk("%s unknown irq %d\n", __func__, irq);
  201. break;
  202. #endif
  203. }
  204. }
  205. /*
  206. * Clear an OSS interrupt
  207. *
  208. * Not sure if this works or not but it's the only method I could
  209. * think of based on the contents of the mac_oss structure.
  210. */
  211. void oss_irq_clear(int irq) {
  212. /* FIXME: how to do this on OSS? */
  213. switch(irq) {
  214. case IRQ_MAC_SCC:
  215. oss->irq_pending &= ~OSS_IP_IOPSCC;
  216. break;
  217. case IRQ_MAC_ADB:
  218. oss->irq_pending &= ~OSS_IP_IOPISM;
  219. break;
  220. case IRQ_MAC_SCSI:
  221. oss->irq_pending &= ~OSS_IP_SCSI;
  222. break;
  223. case IRQ_NUBUS_9:
  224. case IRQ_NUBUS_A:
  225. case IRQ_NUBUS_B:
  226. case IRQ_NUBUS_C:
  227. case IRQ_NUBUS_D:
  228. case IRQ_NUBUS_E:
  229. irq -= NUBUS_SOURCE_BASE;
  230. oss->irq_pending &= ~(1 << irq);
  231. break;
  232. }
  233. }
  234. /*
  235. * Check to see if a specific OSS interrupt is pending
  236. */
  237. int oss_irq_pending(int irq)
  238. {
  239. switch(irq) {
  240. case IRQ_MAC_SCC:
  241. return oss->irq_pending & OSS_IP_IOPSCC;
  242. break;
  243. case IRQ_MAC_ADB:
  244. return oss->irq_pending & OSS_IP_IOPISM;
  245. break;
  246. case IRQ_MAC_SCSI:
  247. return oss->irq_pending & OSS_IP_SCSI;
  248. break;
  249. case IRQ_NUBUS_9:
  250. case IRQ_NUBUS_A:
  251. case IRQ_NUBUS_B:
  252. case IRQ_NUBUS_C:
  253. case IRQ_NUBUS_D:
  254. case IRQ_NUBUS_E:
  255. irq -= NUBUS_SOURCE_BASE;
  256. return oss->irq_pending & (1 << irq);
  257. break;
  258. }
  259. return 0;
  260. }