via.c 16 KB

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