pic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Support for the interrupt controllers found on Power Macintosh,
  4. * currently Apple's "Grand Central" interrupt controller in all
  5. * it's incarnations. OpenPIC support used on newer machines is
  6. * in a separate file
  7. *
  8. * Copyright (C) 1997 Paul Mackerras ([email protected])
  9. * Copyright (C) 2005 Benjamin Herrenschmidt ([email protected])
  10. * IBM, Corp.
  11. */
  12. #include <linux/stddef.h>
  13. #include <linux/init.h>
  14. #include <linux/sched.h>
  15. #include <linux/signal.h>
  16. #include <linux/pci.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/syscore_ops.h>
  19. #include <linux/adb.h>
  20. #include <linux/minmax.h>
  21. #include <linux/pmu.h>
  22. #include <linux/irqdomain.h>
  23. #include <linux/of_address.h>
  24. #include <linux/of_irq.h>
  25. #include <asm/sections.h>
  26. #include <asm/io.h>
  27. #include <asm/smp.h>
  28. #include <asm/pci-bridge.h>
  29. #include <asm/time.h>
  30. #include <asm/pmac_feature.h>
  31. #include <asm/mpic.h>
  32. #include <asm/xmon.h>
  33. #include "pmac.h"
  34. #ifdef CONFIG_PPC32
  35. struct pmac_irq_hw {
  36. unsigned int event;
  37. unsigned int enable;
  38. unsigned int ack;
  39. unsigned int level;
  40. };
  41. /* Workaround flags for 32bit powermac machines */
  42. unsigned int of_irq_workarounds;
  43. struct device_node *of_irq_dflt_pic;
  44. /* Default addresses */
  45. static volatile struct pmac_irq_hw __iomem *pmac_irq_hw[4];
  46. static int max_irqs;
  47. static int max_real_irqs;
  48. static DEFINE_RAW_SPINLOCK(pmac_pic_lock);
  49. /* The max irq number this driver deals with is 128; see max_irqs */
  50. static DECLARE_BITMAP(ppc_lost_interrupts, 128);
  51. static DECLARE_BITMAP(ppc_cached_irq_mask, 128);
  52. static int pmac_irq_cascade = -1;
  53. static struct irq_domain *pmac_pic_host;
  54. static void __pmac_retrigger(unsigned int irq_nr)
  55. {
  56. if (irq_nr >= max_real_irqs && pmac_irq_cascade > 0) {
  57. __set_bit(irq_nr, ppc_lost_interrupts);
  58. irq_nr = pmac_irq_cascade;
  59. mb();
  60. }
  61. if (!__test_and_set_bit(irq_nr, ppc_lost_interrupts)) {
  62. atomic_inc(&ppc_n_lost_interrupts);
  63. set_dec(1);
  64. }
  65. }
  66. static void pmac_mask_and_ack_irq(struct irq_data *d)
  67. {
  68. unsigned int src = irqd_to_hwirq(d);
  69. unsigned long bit = 1UL << (src & 0x1f);
  70. int i = src >> 5;
  71. unsigned long flags;
  72. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  73. __clear_bit(src, ppc_cached_irq_mask);
  74. if (__test_and_clear_bit(src, ppc_lost_interrupts))
  75. atomic_dec(&ppc_n_lost_interrupts);
  76. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  77. out_le32(&pmac_irq_hw[i]->ack, bit);
  78. do {
  79. /* make sure ack gets to controller before we enable
  80. interrupts */
  81. mb();
  82. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  83. != (ppc_cached_irq_mask[i] & bit));
  84. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  85. }
  86. static void pmac_ack_irq(struct irq_data *d)
  87. {
  88. unsigned int src = irqd_to_hwirq(d);
  89. unsigned long bit = 1UL << (src & 0x1f);
  90. int i = src >> 5;
  91. unsigned long flags;
  92. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  93. if (__test_and_clear_bit(src, ppc_lost_interrupts))
  94. atomic_dec(&ppc_n_lost_interrupts);
  95. out_le32(&pmac_irq_hw[i]->ack, bit);
  96. (void)in_le32(&pmac_irq_hw[i]->ack);
  97. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  98. }
  99. static void __pmac_set_irq_mask(unsigned int irq_nr, int nokicklost)
  100. {
  101. unsigned long bit = 1UL << (irq_nr & 0x1f);
  102. int i = irq_nr >> 5;
  103. if ((unsigned)irq_nr >= max_irqs)
  104. return;
  105. /* enable unmasked interrupts */
  106. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  107. do {
  108. /* make sure mask gets to controller before we
  109. return to user */
  110. mb();
  111. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  112. != (ppc_cached_irq_mask[i] & bit));
  113. /*
  114. * Unfortunately, setting the bit in the enable register
  115. * when the device interrupt is already on *doesn't* set
  116. * the bit in the flag register or request another interrupt.
  117. */
  118. if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level))
  119. __pmac_retrigger(irq_nr);
  120. }
  121. /* When an irq gets requested for the first client, if it's an
  122. * edge interrupt, we clear any previous one on the controller
  123. */
  124. static unsigned int pmac_startup_irq(struct irq_data *d)
  125. {
  126. unsigned long flags;
  127. unsigned int src = irqd_to_hwirq(d);
  128. unsigned long bit = 1UL << (src & 0x1f);
  129. int i = src >> 5;
  130. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  131. if (!irqd_is_level_type(d))
  132. out_le32(&pmac_irq_hw[i]->ack, bit);
  133. __set_bit(src, ppc_cached_irq_mask);
  134. __pmac_set_irq_mask(src, 0);
  135. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  136. return 0;
  137. }
  138. static void pmac_mask_irq(struct irq_data *d)
  139. {
  140. unsigned long flags;
  141. unsigned int src = irqd_to_hwirq(d);
  142. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  143. __clear_bit(src, ppc_cached_irq_mask);
  144. __pmac_set_irq_mask(src, 1);
  145. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  146. }
  147. static void pmac_unmask_irq(struct irq_data *d)
  148. {
  149. unsigned long flags;
  150. unsigned int src = irqd_to_hwirq(d);
  151. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  152. __set_bit(src, ppc_cached_irq_mask);
  153. __pmac_set_irq_mask(src, 0);
  154. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  155. }
  156. static int pmac_retrigger(struct irq_data *d)
  157. {
  158. unsigned long flags;
  159. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  160. __pmac_retrigger(irqd_to_hwirq(d));
  161. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  162. return 1;
  163. }
  164. static struct irq_chip pmac_pic = {
  165. .name = "PMAC-PIC",
  166. .irq_startup = pmac_startup_irq,
  167. .irq_mask = pmac_mask_irq,
  168. .irq_ack = pmac_ack_irq,
  169. .irq_mask_ack = pmac_mask_and_ack_irq,
  170. .irq_unmask = pmac_unmask_irq,
  171. .irq_retrigger = pmac_retrigger,
  172. };
  173. static irqreturn_t gatwick_action(int cpl, void *dev_id)
  174. {
  175. unsigned long flags;
  176. int irq, bits;
  177. int rc = IRQ_NONE;
  178. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  179. for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) {
  180. int i = irq >> 5;
  181. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  182. bits |= in_le32(&pmac_irq_hw[i]->level);
  183. bits &= ppc_cached_irq_mask[i];
  184. if (bits == 0)
  185. continue;
  186. irq += __ilog2(bits);
  187. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  188. generic_handle_irq(irq);
  189. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  190. rc = IRQ_HANDLED;
  191. }
  192. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  193. return rc;
  194. }
  195. static unsigned int pmac_pic_get_irq(void)
  196. {
  197. int irq;
  198. unsigned long bits = 0;
  199. unsigned long flags;
  200. #ifdef CONFIG_PPC_PMAC32_PSURGE
  201. /* IPI's are a hack on the powersurge -- Cort */
  202. if (smp_processor_id() != 0) {
  203. return psurge_secondary_virq;
  204. }
  205. #endif /* CONFIG_PPC_PMAC32_PSURGE */
  206. raw_spin_lock_irqsave(&pmac_pic_lock, flags);
  207. for (irq = max_real_irqs; (irq -= 32) >= 0; ) {
  208. int i = irq >> 5;
  209. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  210. bits |= in_le32(&pmac_irq_hw[i]->level);
  211. bits &= ppc_cached_irq_mask[i];
  212. if (bits == 0)
  213. continue;
  214. irq += __ilog2(bits);
  215. break;
  216. }
  217. raw_spin_unlock_irqrestore(&pmac_pic_lock, flags);
  218. if (unlikely(irq < 0))
  219. return 0;
  220. return irq_linear_revmap(pmac_pic_host, irq);
  221. }
  222. static int pmac_pic_host_match(struct irq_domain *h, struct device_node *node,
  223. enum irq_domain_bus_token bus_token)
  224. {
  225. /* We match all, we don't always have a node anyway */
  226. return 1;
  227. }
  228. static int pmac_pic_host_map(struct irq_domain *h, unsigned int virq,
  229. irq_hw_number_t hw)
  230. {
  231. if (hw >= max_irqs)
  232. return -EINVAL;
  233. /* Mark level interrupts, set delayed disable for edge ones and set
  234. * handlers
  235. */
  236. irq_set_status_flags(virq, IRQ_LEVEL);
  237. irq_set_chip_and_handler(virq, &pmac_pic, handle_level_irq);
  238. return 0;
  239. }
  240. static const struct irq_domain_ops pmac_pic_host_ops = {
  241. .match = pmac_pic_host_match,
  242. .map = pmac_pic_host_map,
  243. .xlate = irq_domain_xlate_onecell,
  244. };
  245. static void __init pmac_pic_probe_oldstyle(void)
  246. {
  247. int i;
  248. struct device_node *master = NULL;
  249. struct device_node *slave = NULL;
  250. u8 __iomem *addr;
  251. struct resource r;
  252. /* Set our get_irq function */
  253. ppc_md.get_irq = pmac_pic_get_irq;
  254. /*
  255. * Find the interrupt controller type & node
  256. */
  257. if ((master = of_find_node_by_name(NULL, "gc")) != NULL) {
  258. max_irqs = max_real_irqs = 32;
  259. } else if ((master = of_find_node_by_name(NULL, "ohare")) != NULL) {
  260. max_irqs = max_real_irqs = 32;
  261. /* We might have a second cascaded ohare */
  262. slave = of_find_node_by_name(NULL, "pci106b,7");
  263. if (slave)
  264. max_irqs = 64;
  265. } else if ((master = of_find_node_by_name(NULL, "mac-io")) != NULL) {
  266. max_irqs = max_real_irqs = 64;
  267. /* We might have a second cascaded heathrow */
  268. /* Compensate for of_node_put() in of_find_node_by_name() */
  269. of_node_get(master);
  270. slave = of_find_node_by_name(master, "mac-io");
  271. /* Check ordering of master & slave */
  272. if (of_device_is_compatible(master, "gatwick")) {
  273. BUG_ON(slave == NULL);
  274. swap(master, slave);
  275. }
  276. /* We found a slave */
  277. if (slave)
  278. max_irqs = 128;
  279. }
  280. BUG_ON(master == NULL);
  281. /*
  282. * Allocate an irq host
  283. */
  284. pmac_pic_host = irq_domain_add_linear(master, max_irqs,
  285. &pmac_pic_host_ops, NULL);
  286. BUG_ON(pmac_pic_host == NULL);
  287. irq_set_default_host(pmac_pic_host);
  288. /* Get addresses of first controller if we have a node for it */
  289. BUG_ON(of_address_to_resource(master, 0, &r));
  290. /* Map interrupts of primary controller */
  291. addr = (u8 __iomem *) ioremap(r.start, 0x40);
  292. i = 0;
  293. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  294. (addr + 0x20);
  295. if (max_real_irqs > 32)
  296. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  297. (addr + 0x10);
  298. of_node_put(master);
  299. printk(KERN_INFO "irq: Found primary Apple PIC %pOF for %d irqs\n",
  300. master, max_real_irqs);
  301. /* Map interrupts of cascaded controller */
  302. if (slave && !of_address_to_resource(slave, 0, &r)) {
  303. addr = (u8 __iomem *)ioremap(r.start, 0x40);
  304. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  305. (addr + 0x20);
  306. if (max_irqs > 64)
  307. pmac_irq_hw[i++] =
  308. (volatile struct pmac_irq_hw __iomem *)
  309. (addr + 0x10);
  310. pmac_irq_cascade = irq_of_parse_and_map(slave, 0);
  311. printk(KERN_INFO "irq: Found slave Apple PIC %pOF for %d irqs"
  312. " cascade: %d\n", slave,
  313. max_irqs - max_real_irqs, pmac_irq_cascade);
  314. }
  315. of_node_put(slave);
  316. /* Disable all interrupts in all controllers */
  317. for (i = 0; i * 32 < max_irqs; ++i)
  318. out_le32(&pmac_irq_hw[i]->enable, 0);
  319. /* Hookup cascade irq */
  320. if (slave && pmac_irq_cascade) {
  321. if (request_irq(pmac_irq_cascade, gatwick_action,
  322. IRQF_NO_THREAD, "cascade", NULL))
  323. pr_err("Failed to register cascade interrupt\n");
  324. }
  325. printk(KERN_INFO "irq: System has %d possible interrupts\n", max_irqs);
  326. #ifdef CONFIG_XMON
  327. i = irq_create_mapping(NULL, 20);
  328. if (request_irq(i, xmon_irq, IRQF_NO_THREAD, "NMI - XMON", NULL))
  329. pr_err("Failed to register NMI-XMON interrupt\n");
  330. #endif
  331. }
  332. int of_irq_parse_oldworld(const struct device_node *device, int index,
  333. struct of_phandle_args *out_irq)
  334. {
  335. const u32 *ints = NULL;
  336. int intlen;
  337. /*
  338. * Old machines just have a list of interrupt numbers
  339. * and no interrupt-controller nodes. We also have dodgy
  340. * cases where the APPL,interrupts property is completely
  341. * missing behind pci-pci bridges and we have to get it
  342. * from the parent (the bridge itself, as apple just wired
  343. * everything together on these)
  344. */
  345. while (device) {
  346. ints = of_get_property(device, "AAPL,interrupts", &intlen);
  347. if (ints != NULL)
  348. break;
  349. device = device->parent;
  350. if (!of_node_is_type(device, "pci"))
  351. break;
  352. }
  353. if (ints == NULL)
  354. return -EINVAL;
  355. intlen /= sizeof(u32);
  356. if (index >= intlen)
  357. return -EINVAL;
  358. out_irq->np = NULL;
  359. out_irq->args[0] = ints[index];
  360. out_irq->args_count = 1;
  361. return 0;
  362. }
  363. #endif /* CONFIG_PPC32 */
  364. static void __init pmac_pic_setup_mpic_nmi(struct mpic *mpic)
  365. {
  366. #if defined(CONFIG_XMON) && defined(CONFIG_PPC32)
  367. struct device_node* pswitch;
  368. int nmi_irq;
  369. pswitch = of_find_node_by_name(NULL, "programmer-switch");
  370. if (pswitch) {
  371. nmi_irq = irq_of_parse_and_map(pswitch, 0);
  372. if (nmi_irq) {
  373. mpic_irq_set_priority(nmi_irq, 9);
  374. if (request_irq(nmi_irq, xmon_irq, IRQF_NO_THREAD,
  375. "NMI - XMON", NULL))
  376. pr_err("Failed to register NMI-XMON interrupt\n");
  377. }
  378. of_node_put(pswitch);
  379. }
  380. #endif /* defined(CONFIG_XMON) && defined(CONFIG_PPC32) */
  381. }
  382. static struct mpic * __init pmac_setup_one_mpic(struct device_node *np,
  383. int master)
  384. {
  385. const char *name = master ? " MPIC 1 " : " MPIC 2 ";
  386. struct mpic *mpic;
  387. unsigned int flags = master ? 0 : MPIC_SECONDARY;
  388. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, np, 0, 0);
  389. if (of_get_property(np, "big-endian", NULL))
  390. flags |= MPIC_BIG_ENDIAN;
  391. /* Primary Big Endian means HT interrupts. This is quite dodgy
  392. * but works until I find a better way
  393. */
  394. if (master && (flags & MPIC_BIG_ENDIAN))
  395. flags |= MPIC_U3_HT_IRQS;
  396. mpic = mpic_alloc(np, 0, flags, 0, 0, name);
  397. if (mpic == NULL)
  398. return NULL;
  399. mpic_init(mpic);
  400. return mpic;
  401. }
  402. static int __init pmac_pic_probe_mpic(void)
  403. {
  404. struct mpic *mpic1, *mpic2;
  405. struct device_node *np, *master = NULL, *slave = NULL;
  406. /* We can have up to 2 MPICs cascaded */
  407. for_each_node_by_type(np, "open-pic") {
  408. if (master == NULL &&
  409. of_get_property(np, "interrupts", NULL) == NULL)
  410. master = of_node_get(np);
  411. else if (slave == NULL)
  412. slave = of_node_get(np);
  413. if (master && slave) {
  414. of_node_put(np);
  415. break;
  416. }
  417. }
  418. /* Check for bogus setups */
  419. if (master == NULL && slave != NULL) {
  420. master = slave;
  421. slave = NULL;
  422. }
  423. /* Not found, default to good old pmac pic */
  424. if (master == NULL)
  425. return -ENODEV;
  426. /* Set master handler */
  427. ppc_md.get_irq = mpic_get_irq;
  428. /* Setup master */
  429. mpic1 = pmac_setup_one_mpic(master, 1);
  430. BUG_ON(mpic1 == NULL);
  431. /* Install NMI if any */
  432. pmac_pic_setup_mpic_nmi(mpic1);
  433. of_node_put(master);
  434. /* Set up a cascaded controller, if present */
  435. if (slave) {
  436. mpic2 = pmac_setup_one_mpic(slave, 0);
  437. if (mpic2 == NULL)
  438. printk(KERN_ERR "Failed to setup slave MPIC\n");
  439. of_node_put(slave);
  440. }
  441. return 0;
  442. }
  443. void __init pmac_pic_init(void)
  444. {
  445. /* We configure the OF parsing based on our oldworld vs. newworld
  446. * platform type and whether we were booted by BootX.
  447. */
  448. #ifdef CONFIG_PPC32
  449. if (!pmac_newworld)
  450. of_irq_workarounds |= OF_IMAP_OLDWORLD_MAC;
  451. if (of_get_property(of_chosen, "linux,bootx", NULL) != NULL)
  452. of_irq_workarounds |= OF_IMAP_NO_PHANDLE;
  453. /* If we don't have phandles on a newworld, then try to locate a
  454. * default interrupt controller (happens when booting with BootX).
  455. * We do a first match here, hopefully, that only ever happens on
  456. * machines with one controller.
  457. */
  458. if (pmac_newworld && (of_irq_workarounds & OF_IMAP_NO_PHANDLE)) {
  459. struct device_node *np;
  460. for_each_node_with_property(np, "interrupt-controller") {
  461. /* Skip /chosen/interrupt-controller */
  462. if (of_node_name_eq(np, "chosen"))
  463. continue;
  464. /* It seems like at least one person wants
  465. * to use BootX on a machine with an AppleKiwi
  466. * controller which happens to pretend to be an
  467. * interrupt controller too. */
  468. if (of_node_name_eq(np, "AppleKiwi"))
  469. continue;
  470. /* I think we found one ! */
  471. of_irq_dflt_pic = np;
  472. break;
  473. }
  474. }
  475. #endif /* CONFIG_PPC32 */
  476. /* We first try to detect Apple's new Core99 chipset, since mac-io
  477. * is quite different on those machines and contains an IBM MPIC2.
  478. */
  479. if (pmac_pic_probe_mpic() == 0)
  480. return;
  481. #ifdef CONFIG_PPC32
  482. pmac_pic_probe_oldstyle();
  483. #endif
  484. }
  485. #if defined(CONFIG_PM) && defined(CONFIG_PPC32)
  486. /*
  487. * These procedures are used in implementing sleep on the powerbooks.
  488. * sleep_save_intrs() saves the states of all interrupt enables
  489. * and disables all interrupts except for the nominated one.
  490. * sleep_restore_intrs() restores the states of all interrupt enables.
  491. */
  492. unsigned long sleep_save_mask[2];
  493. /* This used to be passed by the PMU driver but that link got
  494. * broken with the new driver model. We use this tweak for now...
  495. * We really want to do things differently though...
  496. */
  497. static int pmacpic_find_viaint(void)
  498. {
  499. int viaint = -1;
  500. #ifdef CONFIG_ADB_PMU
  501. struct device_node *np;
  502. if (pmu_get_model() != PMU_OHARE_BASED)
  503. goto not_found;
  504. np = of_find_node_by_name(NULL, "via-pmu");
  505. if (np == NULL)
  506. goto not_found;
  507. viaint = irq_of_parse_and_map(np, 0);
  508. of_node_put(np);
  509. not_found:
  510. #endif /* CONFIG_ADB_PMU */
  511. return viaint;
  512. }
  513. static int pmacpic_suspend(void)
  514. {
  515. int viaint = pmacpic_find_viaint();
  516. sleep_save_mask[0] = ppc_cached_irq_mask[0];
  517. sleep_save_mask[1] = ppc_cached_irq_mask[1];
  518. ppc_cached_irq_mask[0] = 0;
  519. ppc_cached_irq_mask[1] = 0;
  520. if (viaint > 0)
  521. set_bit(viaint, ppc_cached_irq_mask);
  522. out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]);
  523. if (max_real_irqs > 32)
  524. out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]);
  525. (void)in_le32(&pmac_irq_hw[0]->event);
  526. /* make sure mask gets to controller before we return to caller */
  527. mb();
  528. (void)in_le32(&pmac_irq_hw[0]->enable);
  529. return 0;
  530. }
  531. static void pmacpic_resume(void)
  532. {
  533. int i;
  534. out_le32(&pmac_irq_hw[0]->enable, 0);
  535. if (max_real_irqs > 32)
  536. out_le32(&pmac_irq_hw[1]->enable, 0);
  537. mb();
  538. for (i = 0; i < max_real_irqs; ++i)
  539. if (test_bit(i, sleep_save_mask))
  540. pmac_unmask_irq(irq_get_irq_data(i));
  541. }
  542. static struct syscore_ops pmacpic_syscore_ops = {
  543. .suspend = pmacpic_suspend,
  544. .resume = pmacpic_resume,
  545. };
  546. static int __init init_pmacpic_syscore(void)
  547. {
  548. if (pmac_irq_hw[0])
  549. register_syscore_ops(&pmacpic_syscore_ops);
  550. return 0;
  551. }
  552. machine_subsys_initcall(powermac, init_pmacpic_syscore);
  553. #endif /* CONFIG_PM && CONFIG_PPC32 */