via.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /*
  2. * 6522 Versatile Interface Adapter (VIA)
  3. *
  4. * There are two of these on the Mac II. Some IRQs are vectored
  5. * via them as are assorted bits and bobs - eg RTC, ADB.
  6. *
  7. * CSA: Motorola seems to have removed documentation on the 6522 from
  8. * their web site; try
  9. * http://nerini.drf.com/vectrex/other/text/chips/6522/
  10. * http://www.zymurgy.net/classic/vic20/vicdet1.htm
  11. * and
  12. * http://193.23.168.87/mikro_laborversuche/via_iobaustein/via6522_1.html
  13. * for info. A full-text web search on 6522 AND VIA will probably also
  14. * net some usefulness. <cananian@alumni.princeton.edu> 20apr1999
  15. *
  16. * Additional data is here (the SY6522 was used in the Mac II etc):
  17. * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522.pdf
  18. * http://www.6502.org/documents/datasheets/synertek/synertek_sy6522_programming_reference.pdf
  19. *
  20. * PRAM/RTC access algorithms are from the NetBSD RTC toolkit version 1.08b
  21. * by Erik Vogan and adapted to Linux by Joshua M. Thompson (funaho@jurai.org)
  22. *
  23. */
  24. #include <linux/types.h>
  25. #include <linux/kernel.h>
  26. #include <linux/mm.h>
  27. #include <linux/delay.h>
  28. #include <linux/init.h>
  29. #include <linux/ide.h>
  30. #include <linux/module.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/macintosh.h>
  33. #include <asm/macints.h>
  34. #include <asm/machw.h>
  35. #include <asm/mac_via.h>
  36. #include <asm/mac_psc.h>
  37. volatile __u8 *via1, *via2;
  38. #if 0
  39. /* See note in mac_via.h about how this is possibly not useful */
  40. volatile long *via_memory_bogon=(long *)&via_memory_bogon;
  41. #endif
  42. int rbv_present;
  43. int via_alt_mapping;
  44. EXPORT_SYMBOL(via_alt_mapping);
  45. __u8 rbv_clear;
  46. /*
  47. * Globals for accessing the VIA chip registers without having to
  48. * check if we're hitting a real VIA or an RBV. Normally you could
  49. * just hit the combined register (ie, vIER|rIER) but that seems to
  50. * break on AV Macs...probably because they actually decode more than
  51. * eight address bits. Why can't Apple engineers at least be
  52. * _consistently_ lazy? - 1999-05-21 (jmt)
  53. */
  54. static int gIER,gIFR,gBufA,gBufB;
  55. /*
  56. * Timer defs.
  57. */
  58. #define TICK_SIZE 10000
  59. #define MAC_CLOCK_TICK (783300/HZ) /* ticks per HZ */
  60. #define MAC_CLOCK_LOW (MAC_CLOCK_TICK&0xFF)
  61. #define MAC_CLOCK_HIGH (MAC_CLOCK_TICK>>8)
  62. /* To disable a NuBus slot on Quadras we make the slot IRQ lines outputs, set
  63. * high. On RBV we just use the slot interrupt enable register. On Macs with
  64. * genuine VIA chips we must use nubus_disabled to keep track of disabled slot
  65. * interrupts. When any slot IRQ is disabled we mask the (edge triggered) CA1
  66. * or "SLOTS" interrupt. When no slot is disabled, we unmask the CA1 interrupt.
  67. * So, on genuine VIAs, having more than one NuBus IRQ can mean trouble,
  68. * because closing one of those drivers can mask all of the NuBus interrupts.
  69. * Also, since we can't mask the unregistered slot IRQs on genuine VIAs, it's
  70. * possible to get interrupts from cards that MacOS or the ROM has configured
  71. * but we have not. FWIW, "Designing Cards and Drivers for Macintosh II and
  72. * Macintosh SE", page 9-8, says, a slot IRQ with no driver would crash MacOS.
  73. */
  74. static u8 nubus_disabled;
  75. void via_debug_dump(void);
  76. irqreturn_t via1_irq(int, void *);
  77. irqreturn_t via2_irq(int, void *);
  78. irqreturn_t via_nubus_irq(int, void *);
  79. void via_irq_enable(int irq);
  80. void via_irq_disable(int irq);
  81. void via_irq_clear(int irq);
  82. extern irqreturn_t mac_scc_dispatch(int, void *);
  83. extern int oss_present;
  84. /*
  85. * Initialize the VIAs
  86. *
  87. * First we figure out where they actually _are_ as well as what type of
  88. * VIA we have for VIA2 (it could be a real VIA or an RBV or even an OSS.)
  89. * Then we pretty much clear them out and disable all IRQ sources.
  90. *
  91. * Note: the OSS is actually "detected" here and not in oss_init(). It just
  92. * seems more logical to do it here since via_init() needs to know
  93. * these things anyways.
  94. */
  95. void __init via_init(void)
  96. {
  97. switch(macintosh_config->via_type) {
  98. /* IIci, IIsi, IIvx, IIvi (P6xx), LC series */
  99. case MAC_VIA_IIci:
  100. via1 = (void *) VIA1_BASE;
  101. if (macintosh_config->ident == MAC_MODEL_IIFX) {
  102. via2 = NULL;
  103. rbv_present = 0;
  104. oss_present = 1;
  105. } else {
  106. via2 = (void *) RBV_BASE;
  107. rbv_present = 1;
  108. oss_present = 0;
  109. }
  110. if (macintosh_config->ident == MAC_MODEL_LCIII) {
  111. rbv_clear = 0x00;
  112. } else {
  113. /* on most RBVs (& unlike the VIAs), you */
  114. /* need to set bit 7 when you write to IFR */
  115. /* in order for your clear to occur. */
  116. rbv_clear = 0x80;
  117. }
  118. gIER = rIER;
  119. gIFR = rIFR;
  120. gBufA = rSIFR;
  121. gBufB = rBufB;
  122. break;
  123. /* Quadra and early MacIIs agree on the VIA locations */
  124. case MAC_VIA_QUADRA:
  125. case MAC_VIA_II:
  126. via1 = (void *) VIA1_BASE;
  127. via2 = (void *) VIA2_BASE;
  128. rbv_present = 0;
  129. oss_present = 0;
  130. rbv_clear = 0x00;
  131. gIER = vIER;
  132. gIFR = vIFR;
  133. gBufA = vBufA;
  134. gBufB = vBufB;
  135. break;
  136. default:
  137. panic("UNKNOWN VIA TYPE");
  138. }
  139. printk(KERN_INFO "VIA1 at %p is a 6522 or clone\n", via1);
  140. printk(KERN_INFO "VIA2 at %p is ", via2);
  141. if (rbv_present) {
  142. printk("an RBV\n");
  143. } else if (oss_present) {
  144. printk("an OSS\n");
  145. } else {
  146. printk("a 6522 or clone\n");
  147. }
  148. #ifdef DEBUG_VIA
  149. via_debug_dump();
  150. #endif
  151. /*
  152. * Shut down all IRQ sources, reset the timers, and
  153. * kill the timer latch on VIA1.
  154. */
  155. via1[vIER] = 0x7F;
  156. via1[vIFR] = 0x7F;
  157. via1[vT1LL] = 0;
  158. via1[vT1LH] = 0;
  159. via1[vT1CL] = 0;
  160. via1[vT1CH] = 0;
  161. via1[vT2CL] = 0;
  162. via1[vT2CH] = 0;
  163. via1[vACR] &= 0x3F;
  164. via1[vACR] &= ~0x03; /* disable port A & B latches */
  165. /*
  166. * SE/30: disable video IRQ
  167. * XXX: testing for SE/30 VBL
  168. */
  169. if (macintosh_config->ident == MAC_MODEL_SE30) {
  170. via1[vDirB] |= 0x40;
  171. via1[vBufB] |= 0x40;
  172. }
  173. /*
  174. * Set the RTC bits to a known state: all lines to outputs and
  175. * RTC disabled (yes that's 0 to enable and 1 to disable).
  176. */
  177. via1[vDirB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk | VIA1B_vRTCData);
  178. via1[vBufB] |= (VIA1B_vRTCEnb | VIA1B_vRTCClk);
  179. /* Everything below this point is VIA2/RBV only... */
  180. if (oss_present) return;
  181. #if 1
  182. /* Some machines support an alternate IRQ mapping that spreads */
  183. /* Ethernet and Sound out to their own autolevel IRQs and moves */
  184. /* VIA1 to level 6. A/UX uses this mapping and we do too. Note */
  185. /* that the IIfx emulates this alternate mapping using the OSS. */
  186. switch(macintosh_config->ident) {
  187. case MAC_MODEL_P475:
  188. case MAC_MODEL_P475F:
  189. case MAC_MODEL_P575:
  190. case MAC_MODEL_Q605:
  191. case MAC_MODEL_Q605_ACC:
  192. case MAC_MODEL_C610:
  193. case MAC_MODEL_Q610:
  194. case MAC_MODEL_Q630:
  195. case MAC_MODEL_C650:
  196. case MAC_MODEL_Q650:
  197. case MAC_MODEL_Q700:
  198. case MAC_MODEL_Q800:
  199. case MAC_MODEL_Q900:
  200. case MAC_MODEL_Q950:
  201. via_alt_mapping = 1;
  202. via1[vDirB] |= 0x40;
  203. via1[vBufB] &= ~0x40;
  204. break;
  205. default:
  206. via_alt_mapping = 0;
  207. break;
  208. }
  209. #else
  210. via_alt_mapping = 0;
  211. #endif
  212. /*
  213. * Now initialize VIA2. For RBV we just kill all interrupts;
  214. * for a regular VIA we also reset the timers and stuff.
  215. */
  216. via2[gIER] = 0x7F;
  217. via2[gIFR] = 0x7F | rbv_clear;
  218. if (!rbv_present) {
  219. via2[vT1LL] = 0;
  220. via2[vT1LH] = 0;
  221. via2[vT1CL] = 0;
  222. via2[vT1CH] = 0;
  223. via2[vT2CL] = 0;
  224. via2[vT2CH] = 0;
  225. via2[vACR] &= 0x3F;
  226. via2[vACR] &= ~0x03; /* disable port A & B latches */
  227. }
  228. /*
  229. * Set vPCR for SCSI interrupts (but not on RBV)
  230. */
  231. if (!rbv_present) {
  232. if (macintosh_config->scsi_type == MAC_SCSI_OLD) {
  233. /* CB2 (IRQ) indep. input, positive edge */
  234. /* CA2 (DRQ) indep. input, positive edge */
  235. via2[vPCR] = 0x66;
  236. } else {
  237. /* CB2 (IRQ) indep. input, negative edge */
  238. /* CA2 (DRQ) indep. input, negative edge */
  239. via2[vPCR] = 0x22;
  240. }
  241. }
  242. }
  243. /*
  244. * Start the 100 Hz clock
  245. */
  246. void __init via_init_clock(irq_handler_t func)
  247. {
  248. via1[vACR] |= 0x40;
  249. via1[vT1LL] = MAC_CLOCK_LOW;
  250. via1[vT1LH] = MAC_CLOCK_HIGH;
  251. via1[vT1CL] = MAC_CLOCK_LOW;
  252. via1[vT1CH] = MAC_CLOCK_HIGH;
  253. request_irq(IRQ_MAC_TIMER_1, func, IRQ_FLG_LOCK, "timer", func);
  254. }
  255. /*
  256. * Register the interrupt dispatchers for VIA or RBV machines only.
  257. */
  258. void __init via_register_interrupts(void)
  259. {
  260. if (via_alt_mapping) {
  261. request_irq(IRQ_AUTO_1, via1_irq,
  262. IRQ_FLG_LOCK|IRQ_FLG_FAST, "software",
  263. (void *) via1);
  264. request_irq(IRQ_AUTO_6, via1_irq,
  265. IRQ_FLG_LOCK|IRQ_FLG_FAST, "via1",
  266. (void *) via1);
  267. } else {
  268. request_irq(IRQ_AUTO_1, via1_irq,
  269. IRQ_FLG_LOCK|IRQ_FLG_FAST, "via1",
  270. (void *) via1);
  271. }
  272. request_irq(IRQ_AUTO_2, via2_irq, IRQ_FLG_LOCK|IRQ_FLG_FAST,
  273. "via2", (void *) via2);
  274. if (!psc_present) {
  275. request_irq(IRQ_AUTO_4, mac_scc_dispatch, IRQ_FLG_LOCK,
  276. "scc", mac_scc_dispatch);
  277. }
  278. request_irq(IRQ_MAC_NUBUS, via_nubus_irq, IRQ_FLG_LOCK|IRQ_FLG_FAST,
  279. "nubus", (void *) via2);
  280. }
  281. /*
  282. * Debugging dump, used in various places to see what's going on.
  283. */
  284. void via_debug_dump(void)
  285. {
  286. printk(KERN_DEBUG "VIA1: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  287. (uint) via1[vDirA], (uint) via1[vDirB], (uint) via1[vACR]);
  288. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  289. (uint) via1[vPCR], (uint) via1[vIFR], (uint) via1[vIER]);
  290. if (oss_present) {
  291. printk(KERN_DEBUG "VIA2: <OSS>\n");
  292. } else if (rbv_present) {
  293. printk(KERN_DEBUG "VIA2: IFR = 0x%02X IER = 0x%02X\n",
  294. (uint) via2[rIFR], (uint) via2[rIER]);
  295. printk(KERN_DEBUG " SIFR = 0x%02X SIER = 0x%02X\n",
  296. (uint) via2[rSIFR], (uint) via2[rSIER]);
  297. } else {
  298. printk(KERN_DEBUG "VIA2: DDRA = 0x%02X DDRB = 0x%02X ACR = 0x%02X\n",
  299. (uint) via2[vDirA], (uint) via2[vDirB],
  300. (uint) via2[vACR]);
  301. printk(KERN_DEBUG " PCR = 0x%02X IFR = 0x%02X IER = 0x%02X\n",
  302. (uint) via2[vPCR],
  303. (uint) via2[vIFR], (uint) via2[vIER]);
  304. }
  305. }
  306. /*
  307. * This is always executed with interrupts disabled.
  308. *
  309. * TBI: get time offset between scheduling timer ticks
  310. */
  311. unsigned long mac_gettimeoffset (void)
  312. {
  313. unsigned long ticks, offset = 0;
  314. /* read VIA1 timer 2 current value */
  315. ticks = via1[vT1CL] | (via1[vT1CH] << 8);
  316. /* The probability of underflow is less than 2% */
  317. if (ticks > MAC_CLOCK_TICK - MAC_CLOCK_TICK / 50)
  318. /* Check for pending timer interrupt in VIA1 IFR */
  319. if (via1[vIFR] & 0x40) offset = TICK_SIZE;
  320. ticks = MAC_CLOCK_TICK - ticks;
  321. ticks = ticks * 10000L / MAC_CLOCK_TICK;
  322. return ticks + offset;
  323. }
  324. /*
  325. * Flush the L2 cache on Macs that have it by flipping
  326. * the system into 24-bit mode for an instant.
  327. */
  328. void via_flush_cache(void)
  329. {
  330. via2[gBufB] &= ~VIA2B_vMode32;
  331. via2[gBufB] |= VIA2B_vMode32;
  332. }
  333. /*
  334. * Return the status of the L2 cache on a IIci
  335. */
  336. int via_get_cache_disable(void)
  337. {
  338. /* Safeguard against being called accidentally */
  339. if (!via2) {
  340. printk(KERN_ERR "via_get_cache_disable called on a non-VIA machine!\n");
  341. return 1;
  342. }
  343. return (int) via2[gBufB] & VIA2B_vCDis;
  344. }
  345. /*
  346. * Initialize VIA2 for Nubus access
  347. */
  348. void __init via_nubus_init(void)
  349. {
  350. /* unlock nubus transactions */
  351. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  352. (macintosh_config->adb_type != MAC_ADB_PB2)) {
  353. /* set the line to be an output on non-RBV machines */
  354. if (!rbv_present)
  355. via2[vDirB] |= 0x02;
  356. /* this seems to be an ADB bit on PMU machines */
  357. /* according to MkLinux. -- jmt */
  358. via2[gBufB] |= 0x02;
  359. }
  360. /* Disable all the slot interrupts (where possible). */
  361. switch (macintosh_config->via_type) {
  362. case MAC_VIA_II:
  363. /* Just make the port A lines inputs. */
  364. switch(macintosh_config->ident) {
  365. case MAC_MODEL_II:
  366. case MAC_MODEL_IIX:
  367. case MAC_MODEL_IICX:
  368. case MAC_MODEL_SE30:
  369. /* The top two bits are RAM size outputs. */
  370. via2[vDirA] &= 0xC0;
  371. break;
  372. default:
  373. via2[vDirA] &= 0x80;
  374. }
  375. break;
  376. case MAC_VIA_IIci:
  377. /* RBV. Disable all the slot interrupts. SIER works like IER. */
  378. via2[rSIER] = 0x7F;
  379. break;
  380. case MAC_VIA_QUADRA:
  381. /* Disable the inactive slot interrupts by making those lines outputs. */
  382. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  383. (macintosh_config->adb_type != MAC_ADB_PB2)) {
  384. via2[vBufA] |= 0x7F;
  385. via2[vDirA] |= 0x7F;
  386. }
  387. break;
  388. }
  389. }
  390. /*
  391. * The generic VIA interrupt routines (shamelessly stolen from Alan Cox's
  392. * via6522.c :-), disable/pending masks added.
  393. */
  394. irqreturn_t via1_irq(int irq, void *dev_id)
  395. {
  396. int irq_num;
  397. unsigned char irq_bit, events;
  398. events = via1[vIFR] & via1[vIER] & 0x7F;
  399. if (!events)
  400. return IRQ_NONE;
  401. irq_num = VIA1_SOURCE_BASE;
  402. irq_bit = 1;
  403. do {
  404. if (events & irq_bit) {
  405. via1[vIFR] = irq_bit;
  406. m68k_handle_int(irq_num);
  407. }
  408. ++irq_num;
  409. irq_bit <<= 1;
  410. } while (events >= irq_bit);
  411. #if 0 /* freakin' pmu is doing weird stuff */
  412. if (!oss_present) {
  413. /* This (still) seems to be necessary to get IDE
  414. working. However, if you enable VBL interrupts,
  415. you're screwed... */
  416. /* FIXME: should we check the SLOTIRQ bit before
  417. pulling this stunt? */
  418. /* No, it won't be set. that's why we're doing this. */
  419. via_irq_disable(IRQ_MAC_NUBUS);
  420. via_irq_clear(IRQ_MAC_NUBUS);
  421. m68k_handle_int(IRQ_MAC_NUBUS);
  422. via_irq_enable(IRQ_MAC_NUBUS);
  423. }
  424. #endif
  425. return IRQ_HANDLED;
  426. }
  427. irqreturn_t via2_irq(int irq, void *dev_id)
  428. {
  429. int irq_num;
  430. unsigned char irq_bit, events;
  431. events = via2[gIFR] & via2[gIER] & 0x7F;
  432. if (!events)
  433. return IRQ_NONE;
  434. irq_num = VIA2_SOURCE_BASE;
  435. irq_bit = 1;
  436. do {
  437. if (events & irq_bit) {
  438. via2[gIFR] = irq_bit | rbv_clear;
  439. m68k_handle_int(irq_num);
  440. }
  441. ++irq_num;
  442. irq_bit <<= 1;
  443. } while (events >= irq_bit);
  444. return IRQ_HANDLED;
  445. }
  446. /*
  447. * Dispatch Nubus interrupts. We are called as a secondary dispatch by the
  448. * VIA2 dispatcher as a fast interrupt handler.
  449. */
  450. irqreturn_t via_nubus_irq(int irq, void *dev_id)
  451. {
  452. int slot_irq;
  453. unsigned char slot_bit, events;
  454. events = ~via2[gBufA] & 0x7F;
  455. if (rbv_present)
  456. events &= via2[rSIER];
  457. else
  458. events &= ~via2[vDirA];
  459. if (!events)
  460. return IRQ_NONE;
  461. do {
  462. slot_irq = IRQ_NUBUS_F;
  463. slot_bit = 0x40;
  464. do {
  465. if (events & slot_bit) {
  466. events &= ~slot_bit;
  467. m68k_handle_int(slot_irq);
  468. }
  469. --slot_irq;
  470. slot_bit >>= 1;
  471. } while (events);
  472. /* clear the CA1 interrupt and make certain there's no more. */
  473. via2[gIFR] = 0x02 | rbv_clear;
  474. events = ~via2[gBufA] & 0x7F;
  475. if (rbv_present)
  476. events &= via2[rSIER];
  477. else
  478. events &= ~via2[vDirA];
  479. } while (events);
  480. return IRQ_HANDLED;
  481. }
  482. void via_irq_enable(int irq) {
  483. int irq_src = IRQ_SRC(irq);
  484. int irq_idx = IRQ_IDX(irq);
  485. #ifdef DEBUG_IRQUSE
  486. printk(KERN_DEBUG "via_irq_enable(%d)\n", irq);
  487. #endif
  488. if (irq_src == 1) {
  489. via1[vIER] = IER_SET_BIT(irq_idx);
  490. } else if (irq_src == 2) {
  491. if (irq != IRQ_MAC_NUBUS || nubus_disabled == 0)
  492. via2[gIER] = IER_SET_BIT(irq_idx);
  493. } else if (irq_src == 7) {
  494. switch (macintosh_config->via_type) {
  495. case MAC_VIA_II:
  496. nubus_disabled &= ~(1 << irq_idx);
  497. /* Enable the CA1 interrupt when no slot is disabled. */
  498. if (!nubus_disabled)
  499. via2[gIER] = IER_SET_BIT(1);
  500. break;
  501. case MAC_VIA_IIci:
  502. /* On RBV, enable the slot interrupt.
  503. * SIER works like IER.
  504. */
  505. via2[rSIER] = IER_SET_BIT(irq_idx);
  506. break;
  507. case MAC_VIA_QUADRA:
  508. /* Make the port A line an input to enable the slot irq.
  509. * But not on PowerBooks, that's ADB.
  510. */
  511. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  512. (macintosh_config->adb_type != MAC_ADB_PB2))
  513. via2[vDirA] &= ~(1 << irq_idx);
  514. break;
  515. }
  516. }
  517. }
  518. void via_irq_disable(int irq) {
  519. int irq_src = IRQ_SRC(irq);
  520. int irq_idx = IRQ_IDX(irq);
  521. #ifdef DEBUG_IRQUSE
  522. printk(KERN_DEBUG "via_irq_disable(%d)\n", irq);
  523. #endif
  524. if (irq_src == 1) {
  525. via1[vIER] = IER_CLR_BIT(irq_idx);
  526. } else if (irq_src == 2) {
  527. via2[gIER] = IER_CLR_BIT(irq_idx);
  528. } else if (irq_src == 7) {
  529. switch (macintosh_config->via_type) {
  530. case MAC_VIA_II:
  531. nubus_disabled |= 1 << irq_idx;
  532. if (nubus_disabled)
  533. via2[gIER] = IER_CLR_BIT(1);
  534. break;
  535. case MAC_VIA_IIci:
  536. via2[rSIER] = IER_CLR_BIT(irq_idx);
  537. break;
  538. case MAC_VIA_QUADRA:
  539. if ((macintosh_config->adb_type != MAC_ADB_PB1) &&
  540. (macintosh_config->adb_type != MAC_ADB_PB2))
  541. via2[vDirA] |= 1 << irq_idx;
  542. break;
  543. }
  544. }
  545. }
  546. void via_irq_clear(int irq) {
  547. int irq_src = IRQ_SRC(irq);
  548. int irq_idx = IRQ_IDX(irq);
  549. int irq_bit = 1 << irq_idx;
  550. if (irq_src == 1) {
  551. via1[vIFR] = irq_bit;
  552. } else if (irq_src == 2) {
  553. via2[gIFR] = irq_bit | rbv_clear;
  554. } else if (irq_src == 7) {
  555. /* FIXME: There is no way to clear an individual nubus slot
  556. * IRQ flag, other than getting the device to do it.
  557. */
  558. }
  559. }
  560. /*
  561. * Returns nonzero if an interrupt is pending on the given
  562. * VIA/IRQ combination.
  563. */
  564. int via_irq_pending(int irq)
  565. {
  566. int irq_src = IRQ_SRC(irq);
  567. int irq_idx = IRQ_IDX(irq);
  568. int irq_bit = 1 << irq_idx;
  569. if (irq_src == 1) {
  570. return via1[vIFR] & irq_bit;
  571. } else if (irq_src == 2) {
  572. return via2[gIFR] & irq_bit;
  573. } else if (irq_src == 7) {
  574. /* Always 0 for MAC_VIA_QUADRA if the slot irq is disabled. */
  575. return ~via2[gBufA] & irq_bit;
  576. }
  577. return 0;
  578. }