pic.c 19 KB

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