via.c 16 KB

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