pic.c 18 KB

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