pic.c 18 KB

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