pic.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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/sysdev.h>
  24. #include <linux/adb.h>
  25. #include <linux/pmu.h>
  26. #include <linux/module.h>
  27. #include <asm/sections.h>
  28. #include <asm/io.h>
  29. #include <asm/smp.h>
  30. #include <asm/prom.h>
  31. #include <asm/pci-bridge.h>
  32. #include <asm/time.h>
  33. #include <asm/pmac_feature.h>
  34. #include <asm/mpic.h>
  35. #include <asm/xmon.h>
  36. #include "pmac.h"
  37. #ifdef CONFIG_PPC32
  38. struct pmac_irq_hw {
  39. unsigned int event;
  40. unsigned int enable;
  41. unsigned int ack;
  42. unsigned int level;
  43. };
  44. /* Default addresses */
  45. static volatile struct pmac_irq_hw __iomem *pmac_irq_hw[4];
  46. #define GC_LEVEL_MASK 0x3ff00000
  47. #define OHARE_LEVEL_MASK 0x1ff00000
  48. #define HEATHROW_LEVEL_MASK 0x1ff00000
  49. static int max_irqs;
  50. static int max_real_irqs;
  51. static u32 level_mask[4];
  52. static DEFINE_SPINLOCK(pmac_pic_lock);
  53. #define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
  54. static unsigned long ppc_lost_interrupts[NR_MASK_WORDS];
  55. static unsigned long ppc_cached_irq_mask[NR_MASK_WORDS];
  56. static int pmac_irq_cascade = -1;
  57. static struct irq_host *pmac_pic_host;
  58. static void __pmac_retrigger(unsigned int irq_nr)
  59. {
  60. if (irq_nr >= max_real_irqs && pmac_irq_cascade > 0) {
  61. __set_bit(irq_nr, ppc_lost_interrupts);
  62. irq_nr = pmac_irq_cascade;
  63. mb();
  64. }
  65. if (!__test_and_set_bit(irq_nr, ppc_lost_interrupts)) {
  66. atomic_inc(&ppc_n_lost_interrupts);
  67. set_dec(1);
  68. }
  69. }
  70. static void pmac_mask_and_ack_irq(unsigned int virq)
  71. {
  72. unsigned int src = irq_map[virq].hwirq;
  73. unsigned long bit = 1UL << (src & 0x1f);
  74. int i = src >> 5;
  75. unsigned long flags;
  76. spin_lock_irqsave(&pmac_pic_lock, flags);
  77. __clear_bit(src, ppc_cached_irq_mask);
  78. if (__test_and_clear_bit(src, ppc_lost_interrupts))
  79. atomic_dec(&ppc_n_lost_interrupts);
  80. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  81. out_le32(&pmac_irq_hw[i]->ack, bit);
  82. do {
  83. /* make sure ack gets to controller before we enable
  84. interrupts */
  85. mb();
  86. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  87. != (ppc_cached_irq_mask[i] & bit));
  88. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  89. }
  90. static void pmac_ack_irq(unsigned int virq)
  91. {
  92. unsigned int src = irq_map[virq].hwirq;
  93. unsigned long bit = 1UL << (src & 0x1f);
  94. int i = src >> 5;
  95. unsigned long flags;
  96. spin_lock_irqsave(&pmac_pic_lock, flags);
  97. if (__test_and_clear_bit(src, ppc_lost_interrupts))
  98. atomic_dec(&ppc_n_lost_interrupts);
  99. out_le32(&pmac_irq_hw[i]->ack, bit);
  100. (void)in_le32(&pmac_irq_hw[i]->ack);
  101. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  102. }
  103. static void __pmac_set_irq_mask(unsigned int irq_nr, int nokicklost)
  104. {
  105. unsigned long bit = 1UL << (irq_nr & 0x1f);
  106. int i = irq_nr >> 5;
  107. if ((unsigned)irq_nr >= max_irqs)
  108. return;
  109. /* enable unmasked interrupts */
  110. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  111. do {
  112. /* make sure mask gets to controller before we
  113. return to user */
  114. mb();
  115. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  116. != (ppc_cached_irq_mask[i] & bit));
  117. /*
  118. * Unfortunately, setting the bit in the enable register
  119. * when the device interrupt is already on *doesn't* set
  120. * the bit in the flag register or request another interrupt.
  121. */
  122. if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level))
  123. __pmac_retrigger(irq_nr);
  124. }
  125. /* When an irq gets requested for the first client, if it's an
  126. * edge interrupt, we clear any previous one on the controller
  127. */
  128. static unsigned int pmac_startup_irq(unsigned int virq)
  129. {
  130. unsigned long flags;
  131. unsigned int src = irq_map[virq].hwirq;
  132. unsigned long bit = 1UL << (src & 0x1f);
  133. int i = src >> 5;
  134. spin_lock_irqsave(&pmac_pic_lock, flags);
  135. if ((irq_desc[virq].status & IRQ_LEVEL) == 0)
  136. out_le32(&pmac_irq_hw[i]->ack, bit);
  137. __set_bit(src, ppc_cached_irq_mask);
  138. __pmac_set_irq_mask(src, 0);
  139. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  140. return 0;
  141. }
  142. static void pmac_mask_irq(unsigned int virq)
  143. {
  144. unsigned long flags;
  145. unsigned int src = irq_map[virq].hwirq;
  146. spin_lock_irqsave(&pmac_pic_lock, flags);
  147. __clear_bit(src, ppc_cached_irq_mask);
  148. __pmac_set_irq_mask(src, 1);
  149. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  150. }
  151. static void pmac_unmask_irq(unsigned int virq)
  152. {
  153. unsigned long flags;
  154. unsigned int src = irq_map[virq].hwirq;
  155. spin_lock_irqsave(&pmac_pic_lock, flags);
  156. __set_bit(src, ppc_cached_irq_mask);
  157. __pmac_set_irq_mask(src, 0);
  158. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  159. }
  160. static int pmac_retrigger(unsigned int virq)
  161. {
  162. unsigned long flags;
  163. spin_lock_irqsave(&pmac_pic_lock, flags);
  164. __pmac_retrigger(irq_map[virq].hwirq);
  165. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  166. return 1;
  167. }
  168. static struct irq_chip pmac_pic = {
  169. .typename = " PMAC-PIC ",
  170. .startup = pmac_startup_irq,
  171. .mask = pmac_mask_irq,
  172. .ack = pmac_ack_irq,
  173. .mask_ack = pmac_mask_and_ack_irq,
  174. .unmask = pmac_unmask_irq,
  175. .retrigger = pmac_retrigger,
  176. };
  177. static irqreturn_t gatwick_action(int cpl, void *dev_id)
  178. {
  179. unsigned long flags;
  180. int irq, bits;
  181. int rc = IRQ_NONE;
  182. spin_lock_irqsave(&pmac_pic_lock, flags);
  183. for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) {
  184. int i = irq >> 5;
  185. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  186. /* We must read level interrupts from the level register */
  187. bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
  188. bits &= ppc_cached_irq_mask[i];
  189. if (bits == 0)
  190. continue;
  191. irq += __ilog2(bits);
  192. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  193. __do_IRQ(irq);
  194. spin_lock_irqsave(&pmac_pic_lock, flags);
  195. rc = IRQ_HANDLED;
  196. }
  197. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  198. return rc;
  199. }
  200. static unsigned int pmac_pic_get_irq(void)
  201. {
  202. int irq;
  203. unsigned long bits = 0;
  204. unsigned long flags;
  205. #ifdef CONFIG_SMP
  206. void psurge_smp_message_recv(void);
  207. /* IPI's are a hack on the powersurge -- Cort */
  208. if ( smp_processor_id() != 0 ) {
  209. psurge_smp_message_recv();
  210. return NO_IRQ_IGNORE; /* ignore, already handled */
  211. }
  212. #endif /* CONFIG_SMP */
  213. spin_lock_irqsave(&pmac_pic_lock, flags);
  214. for (irq = max_real_irqs; (irq -= 32) >= 0; ) {
  215. int i = irq >> 5;
  216. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  217. /* We must read level interrupts from the level register */
  218. bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
  219. bits &= ppc_cached_irq_mask[i];
  220. if (bits == 0)
  221. continue;
  222. irq += __ilog2(bits);
  223. break;
  224. }
  225. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  226. if (unlikely(irq < 0))
  227. return NO_IRQ;
  228. return irq_linear_revmap(pmac_pic_host, irq);
  229. }
  230. #ifdef CONFIG_XMON
  231. static struct irqaction xmon_action = {
  232. .handler = xmon_irq,
  233. .flags = 0,
  234. .mask = CPU_MASK_NONE,
  235. .name = "NMI - XMON"
  236. };
  237. #endif
  238. static struct irqaction gatwick_cascade_action = {
  239. .handler = gatwick_action,
  240. .flags = IRQF_DISABLED,
  241. .mask = CPU_MASK_NONE,
  242. .name = "cascade",
  243. };
  244. static int pmac_pic_host_match(struct irq_host *h, struct device_node *node)
  245. {
  246. /* We match all, we don't always have a node anyway */
  247. return 1;
  248. }
  249. static int pmac_pic_host_map(struct irq_host *h, unsigned int virq,
  250. irq_hw_number_t hw)
  251. {
  252. struct irq_desc *desc = get_irq_desc(virq);
  253. int level;
  254. if (hw >= max_irqs)
  255. return -EINVAL;
  256. /* Mark level interrupts, set delayed disable for edge ones and set
  257. * handlers
  258. */
  259. level = !!(level_mask[hw >> 5] & (1UL << (hw & 0x1f)));
  260. if (level)
  261. desc->status |= IRQ_LEVEL;
  262. set_irq_chip_and_handler(virq, &pmac_pic, level ?
  263. handle_level_irq : handle_edge_irq);
  264. return 0;
  265. }
  266. static int pmac_pic_host_xlate(struct irq_host *h, struct device_node *ct,
  267. u32 *intspec, unsigned int intsize,
  268. irq_hw_number_t *out_hwirq,
  269. unsigned int *out_flags)
  270. {
  271. *out_flags = IRQ_TYPE_NONE;
  272. *out_hwirq = *intspec;
  273. return 0;
  274. }
  275. static struct irq_host_ops pmac_pic_host_ops = {
  276. .match = pmac_pic_host_match,
  277. .map = pmac_pic_host_map,
  278. .xlate = pmac_pic_host_xlate,
  279. };
  280. static void __init pmac_pic_probe_oldstyle(void)
  281. {
  282. int i;
  283. struct device_node *master = NULL;
  284. struct device_node *slave = NULL;
  285. u8 __iomem *addr;
  286. struct resource r;
  287. /* Set our get_irq function */
  288. ppc_md.get_irq = pmac_pic_get_irq;
  289. /*
  290. * Find the interrupt controller type & node
  291. */
  292. if ((master = of_find_node_by_name(NULL, "gc")) != NULL) {
  293. max_irqs = max_real_irqs = 32;
  294. level_mask[0] = GC_LEVEL_MASK;
  295. } else if ((master = of_find_node_by_name(NULL, "ohare")) != NULL) {
  296. max_irqs = max_real_irqs = 32;
  297. level_mask[0] = OHARE_LEVEL_MASK;
  298. /* We might have a second cascaded ohare */
  299. slave = of_find_node_by_name(NULL, "pci106b,7");
  300. if (slave) {
  301. max_irqs = 64;
  302. level_mask[1] = OHARE_LEVEL_MASK;
  303. }
  304. } else if ((master = of_find_node_by_name(NULL, "mac-io")) != NULL) {
  305. max_irqs = max_real_irqs = 64;
  306. level_mask[0] = HEATHROW_LEVEL_MASK;
  307. level_mask[1] = 0;
  308. /* We might have a second cascaded heathrow */
  309. slave = of_find_node_by_name(master, "mac-io");
  310. /* Check ordering of master & slave */
  311. if (of_device_is_compatible(master, "gatwick")) {
  312. struct device_node *tmp;
  313. BUG_ON(slave == NULL);
  314. tmp = master;
  315. master = slave;
  316. slave = tmp;
  317. }
  318. /* We found a slave */
  319. if (slave) {
  320. max_irqs = 128;
  321. level_mask[2] = HEATHROW_LEVEL_MASK;
  322. level_mask[3] = 0;
  323. }
  324. }
  325. BUG_ON(master == NULL);
  326. /*
  327. * Allocate an irq host
  328. */
  329. pmac_pic_host = irq_alloc_host(master, IRQ_HOST_MAP_LINEAR, max_irqs,
  330. &pmac_pic_host_ops,
  331. max_irqs);
  332. BUG_ON(pmac_pic_host == NULL);
  333. irq_set_default_host(pmac_pic_host);
  334. /* Get addresses of first controller if we have a node for it */
  335. BUG_ON(of_address_to_resource(master, 0, &r));
  336. /* Map interrupts of primary controller */
  337. addr = (u8 __iomem *) ioremap(r.start, 0x40);
  338. i = 0;
  339. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  340. (addr + 0x20);
  341. if (max_real_irqs > 32)
  342. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  343. (addr + 0x10);
  344. of_node_put(master);
  345. printk(KERN_INFO "irq: Found primary Apple PIC %s for %d irqs\n",
  346. master->full_name, max_real_irqs);
  347. /* Map interrupts of cascaded controller */
  348. if (slave && !of_address_to_resource(slave, 0, &r)) {
  349. addr = (u8 __iomem *)ioremap(r.start, 0x40);
  350. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  351. (addr + 0x20);
  352. if (max_irqs > 64)
  353. pmac_irq_hw[i++] =
  354. (volatile struct pmac_irq_hw __iomem *)
  355. (addr + 0x10);
  356. pmac_irq_cascade = irq_of_parse_and_map(slave, 0);
  357. printk(KERN_INFO "irq: Found slave Apple PIC %s for %d irqs"
  358. " cascade: %d\n", slave->full_name,
  359. max_irqs - max_real_irqs, pmac_irq_cascade);
  360. }
  361. of_node_put(slave);
  362. /* Disable all interrupts in all controllers */
  363. for (i = 0; i * 32 < max_irqs; ++i)
  364. out_le32(&pmac_irq_hw[i]->enable, 0);
  365. /* Hookup cascade irq */
  366. if (slave && pmac_irq_cascade != NO_IRQ)
  367. setup_irq(pmac_irq_cascade, &gatwick_cascade_action);
  368. printk(KERN_INFO "irq: System has %d possible interrupts\n", max_irqs);
  369. #ifdef CONFIG_XMON
  370. setup_irq(irq_create_mapping(NULL, 20), &xmon_action);
  371. #endif
  372. }
  373. #endif /* CONFIG_PPC32 */
  374. static void pmac_u3_cascade(unsigned int irq, struct irq_desc *desc)
  375. {
  376. struct mpic *mpic = desc->handler_data;
  377. unsigned int cascade_irq = mpic_get_one_irq(mpic);
  378. if (cascade_irq != NO_IRQ)
  379. generic_handle_irq(cascade_irq);
  380. desc->chip->eoi(irq);
  381. }
  382. static void __init pmac_pic_setup_mpic_nmi(struct mpic *mpic)
  383. {
  384. #if defined(CONFIG_XMON) && defined(CONFIG_PPC32)
  385. struct device_node* pswitch;
  386. int nmi_irq;
  387. pswitch = of_find_node_by_name(NULL, "programmer-switch");
  388. if (pswitch) {
  389. nmi_irq = irq_of_parse_and_map(pswitch, 0);
  390. if (nmi_irq != NO_IRQ) {
  391. mpic_irq_set_priority(nmi_irq, 9);
  392. setup_irq(nmi_irq, &xmon_action);
  393. }
  394. of_node_put(pswitch);
  395. }
  396. #endif /* defined(CONFIG_XMON) && defined(CONFIG_PPC32) */
  397. }
  398. static struct mpic * __init pmac_setup_one_mpic(struct device_node *np,
  399. int master)
  400. {
  401. const char *name = master ? " MPIC 1 " : " MPIC 2 ";
  402. struct resource r;
  403. struct mpic *mpic;
  404. unsigned int flags = master ? MPIC_PRIMARY : 0;
  405. int rc;
  406. rc = of_address_to_resource(np, 0, &r);
  407. if (rc)
  408. return NULL;
  409. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, np, 0, 0);
  410. flags |= MPIC_WANTS_RESET;
  411. if (of_get_property(np, "big-endian", NULL))
  412. flags |= MPIC_BIG_ENDIAN;
  413. /* Primary Big Endian means HT interrupts. This is quite dodgy
  414. * but works until I find a better way
  415. */
  416. if (master && (flags & MPIC_BIG_ENDIAN))
  417. flags |= MPIC_U3_HT_IRQS;
  418. mpic = mpic_alloc(np, r.start, flags, 0, 0, name);
  419. if (mpic == NULL)
  420. return NULL;
  421. mpic_init(mpic);
  422. return mpic;
  423. }
  424. static int __init pmac_pic_probe_mpic(void)
  425. {
  426. struct mpic *mpic1, *mpic2;
  427. struct device_node *np, *master = NULL, *slave = NULL;
  428. unsigned int cascade;
  429. /* We can have up to 2 MPICs cascaded */
  430. for (np = NULL; (np = of_find_node_by_type(np, "open-pic"))
  431. != NULL;) {
  432. if (master == NULL &&
  433. of_get_property(np, "interrupts", NULL) == NULL)
  434. master = of_node_get(np);
  435. else if (slave == NULL)
  436. slave = of_node_get(np);
  437. if (master && slave)
  438. break;
  439. }
  440. /* Check for bogus setups */
  441. if (master == NULL && slave != NULL) {
  442. master = slave;
  443. slave = NULL;
  444. }
  445. /* Not found, default to good old pmac pic */
  446. if (master == NULL)
  447. return -ENODEV;
  448. /* Set master handler */
  449. ppc_md.get_irq = mpic_get_irq;
  450. /* Setup master */
  451. mpic1 = pmac_setup_one_mpic(master, 1);
  452. BUG_ON(mpic1 == NULL);
  453. /* Install NMI if any */
  454. pmac_pic_setup_mpic_nmi(mpic1);
  455. of_node_put(master);
  456. /* No slave, let's go out */
  457. if (slave == NULL)
  458. return 0;
  459. /* Get/Map slave interrupt */
  460. cascade = irq_of_parse_and_map(slave, 0);
  461. if (cascade == NO_IRQ) {
  462. printk(KERN_ERR "Failed to map cascade IRQ\n");
  463. return 0;
  464. }
  465. mpic2 = pmac_setup_one_mpic(slave, 0);
  466. if (mpic2 == NULL) {
  467. printk(KERN_ERR "Failed to setup slave MPIC\n");
  468. of_node_put(slave);
  469. return 0;
  470. }
  471. set_irq_data(cascade, mpic2);
  472. set_irq_chained_handler(cascade, pmac_u3_cascade);
  473. of_node_put(slave);
  474. return 0;
  475. }
  476. void __init pmac_pic_init(void)
  477. {
  478. unsigned int flags = 0;
  479. /* We configure the OF parsing based on our oldworld vs. newworld
  480. * platform type and wether we were booted by BootX.
  481. */
  482. #ifdef CONFIG_PPC32
  483. if (!pmac_newworld)
  484. flags |= OF_IMAP_OLDWORLD_MAC;
  485. if (of_get_property(of_chosen, "linux,bootx", NULL) != NULL)
  486. flags |= OF_IMAP_NO_PHANDLE;
  487. #endif /* CONFIG_PPC_32 */
  488. of_irq_map_init(flags);
  489. /* We first try to detect Apple's new Core99 chipset, since mac-io
  490. * is quite different on those machines and contains an IBM MPIC2.
  491. */
  492. if (pmac_pic_probe_mpic() == 0)
  493. return;
  494. #ifdef CONFIG_PPC32
  495. pmac_pic_probe_oldstyle();
  496. #endif
  497. }
  498. #if defined(CONFIG_PM) && defined(CONFIG_PPC32)
  499. /*
  500. * These procedures are used in implementing sleep on the powerbooks.
  501. * sleep_save_intrs() saves the states of all interrupt enables
  502. * and disables all interrupts except for the nominated one.
  503. * sleep_restore_intrs() restores the states of all interrupt enables.
  504. */
  505. unsigned long sleep_save_mask[2];
  506. /* This used to be passed by the PMU driver but that link got
  507. * broken with the new driver model. We use this tweak for now...
  508. * We really want to do things differently though...
  509. */
  510. static int pmacpic_find_viaint(void)
  511. {
  512. int viaint = -1;
  513. #ifdef CONFIG_ADB_PMU
  514. struct device_node *np;
  515. if (pmu_get_model() != PMU_OHARE_BASED)
  516. goto not_found;
  517. np = of_find_node_by_name(NULL, "via-pmu");
  518. if (np == NULL)
  519. goto not_found;
  520. viaint = irq_of_parse_and_map(np, 0);;
  521. not_found:
  522. #endif /* CONFIG_ADB_PMU */
  523. return viaint;
  524. }
  525. static int pmacpic_suspend(struct sys_device *sysdev, pm_message_t state)
  526. {
  527. int viaint = pmacpic_find_viaint();
  528. sleep_save_mask[0] = ppc_cached_irq_mask[0];
  529. sleep_save_mask[1] = ppc_cached_irq_mask[1];
  530. ppc_cached_irq_mask[0] = 0;
  531. ppc_cached_irq_mask[1] = 0;
  532. if (viaint > 0)
  533. set_bit(viaint, ppc_cached_irq_mask);
  534. out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]);
  535. if (max_real_irqs > 32)
  536. out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]);
  537. (void)in_le32(&pmac_irq_hw[0]->event);
  538. /* make sure mask gets to controller before we return to caller */
  539. mb();
  540. (void)in_le32(&pmac_irq_hw[0]->enable);
  541. return 0;
  542. }
  543. static int pmacpic_resume(struct sys_device *sysdev)
  544. {
  545. int i;
  546. out_le32(&pmac_irq_hw[0]->enable, 0);
  547. if (max_real_irqs > 32)
  548. out_le32(&pmac_irq_hw[1]->enable, 0);
  549. mb();
  550. for (i = 0; i < max_real_irqs; ++i)
  551. if (test_bit(i, sleep_save_mask))
  552. pmac_unmask_irq(i);
  553. return 0;
  554. }
  555. #endif /* CONFIG_PM && CONFIG_PPC32 */
  556. static struct sysdev_class pmacpic_sysclass = {
  557. .name = "pmac_pic",
  558. };
  559. static struct sys_device device_pmacpic = {
  560. .id = 0,
  561. .cls = &pmacpic_sysclass,
  562. };
  563. static struct sysdev_driver driver_pmacpic = {
  564. #if defined(CONFIG_PM) && defined(CONFIG_PPC32)
  565. .suspend = &pmacpic_suspend,
  566. .resume = &pmacpic_resume,
  567. #endif /* CONFIG_PM && CONFIG_PPC32 */
  568. };
  569. static int __init init_pmacpic_sysfs(void)
  570. {
  571. #ifdef CONFIG_PPC32
  572. if (max_irqs == 0)
  573. return -ENODEV;
  574. #endif
  575. printk(KERN_DEBUG "Registering pmac pic with sysfs...\n");
  576. sysdev_class_register(&pmacpic_sysclass);
  577. sysdev_register(&device_pmacpic);
  578. sysdev_driver_register(&pmacpic_sysclass, &driver_pmacpic);
  579. return 0;
  580. }
  581. machine_subsys_initcall(powermac, init_pmacpic_sysfs);