via.c 16 KB

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