pic.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. .name = "cascade",
  240. };
  241. static int pmac_pic_host_match(struct irq_host *h, struct device_node *node)
  242. {
  243. /* We match all, we don't always have a node anyway */
  244. return 1;
  245. }
  246. static int pmac_pic_host_map(struct irq_host *h, unsigned int virq,
  247. irq_hw_number_t hw)
  248. {
  249. int level;
  250. if (hw >= max_irqs)
  251. return -EINVAL;
  252. /* Mark level interrupts, set delayed disable for edge ones and set
  253. * handlers
  254. */
  255. level = !!(level_mask[hw >> 5] & (1UL << (hw & 0x1f)));
  256. if (level)
  257. irq_set_status_flags(virq, IRQ_LEVEL);
  258. irq_set_chip_and_handler(virq, &pmac_pic,
  259. level ? handle_level_irq : handle_edge_irq);
  260. return 0;
  261. }
  262. static int pmac_pic_host_xlate(struct irq_host *h, struct device_node *ct,
  263. const u32 *intspec, unsigned int intsize,
  264. irq_hw_number_t *out_hwirq,
  265. unsigned int *out_flags)
  266. {
  267. *out_flags = IRQ_TYPE_NONE;
  268. *out_hwirq = *intspec;
  269. return 0;
  270. }
  271. static struct irq_host_ops pmac_pic_host_ops = {
  272. .match = pmac_pic_host_match,
  273. .map = pmac_pic_host_map,
  274. .xlate = pmac_pic_host_xlate,
  275. };
  276. static void __init pmac_pic_probe_oldstyle(void)
  277. {
  278. int i;
  279. struct device_node *master = NULL;
  280. struct device_node *slave = NULL;
  281. u8 __iomem *addr;
  282. struct resource r;
  283. /* Set our get_irq function */
  284. ppc_md.get_irq = pmac_pic_get_irq;
  285. /*
  286. * Find the interrupt controller type & node
  287. */
  288. if ((master = of_find_node_by_name(NULL, "gc")) != NULL) {
  289. max_irqs = max_real_irqs = 32;
  290. level_mask[0] = GC_LEVEL_MASK;
  291. } else if ((master = of_find_node_by_name(NULL, "ohare")) != NULL) {
  292. max_irqs = max_real_irqs = 32;
  293. level_mask[0] = OHARE_LEVEL_MASK;
  294. /* We might have a second cascaded ohare */
  295. slave = of_find_node_by_name(NULL, "pci106b,7");
  296. if (slave) {
  297. max_irqs = 64;
  298. level_mask[1] = OHARE_LEVEL_MASK;
  299. }
  300. } else if ((master = of_find_node_by_name(NULL, "mac-io")) != NULL) {
  301. max_irqs = max_real_irqs = 64;
  302. level_mask[0] = HEATHROW_LEVEL_MASK;
  303. level_mask[1] = 0;
  304. /* We might have a second cascaded heathrow */
  305. slave = of_find_node_by_name(master, "mac-io");
  306. /* Check ordering of master & slave */
  307. if (of_device_is_compatible(master, "gatwick")) {
  308. struct device_node *tmp;
  309. BUG_ON(slave == NULL);
  310. tmp = master;
  311. master = slave;
  312. slave = tmp;
  313. }
  314. /* We found a slave */
  315. if (slave) {
  316. max_irqs = 128;
  317. level_mask[2] = HEATHROW_LEVEL_MASK;
  318. level_mask[3] = 0;
  319. }
  320. }
  321. BUG_ON(master == NULL);
  322. /*
  323. * Allocate an irq host
  324. */
  325. pmac_pic_host = irq_alloc_host(master, IRQ_HOST_MAP_LINEAR, max_irqs,
  326. &pmac_pic_host_ops,
  327. max_irqs);
  328. BUG_ON(pmac_pic_host == NULL);
  329. irq_set_default_host(pmac_pic_host);
  330. /* Get addresses of first controller if we have a node for it */
  331. BUG_ON(of_address_to_resource(master, 0, &r));
  332. /* Map interrupts of primary controller */
  333. addr = (u8 __iomem *) ioremap(r.start, 0x40);
  334. i = 0;
  335. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  336. (addr + 0x20);
  337. if (max_real_irqs > 32)
  338. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  339. (addr + 0x10);
  340. of_node_put(master);
  341. printk(KERN_INFO "irq: Found primary Apple PIC %s for %d irqs\n",
  342. master->full_name, max_real_irqs);
  343. /* Map interrupts of cascaded controller */
  344. if (slave && !of_address_to_resource(slave, 0, &r)) {
  345. addr = (u8 __iomem *)ioremap(r.start, 0x40);
  346. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  347. (addr + 0x20);
  348. if (max_irqs > 64)
  349. pmac_irq_hw[i++] =
  350. (volatile struct pmac_irq_hw __iomem *)
  351. (addr + 0x10);
  352. pmac_irq_cascade = irq_of_parse_and_map(slave, 0);
  353. printk(KERN_INFO "irq: Found slave Apple PIC %s for %d irqs"
  354. " cascade: %d\n", slave->full_name,
  355. max_irqs - max_real_irqs, pmac_irq_cascade);
  356. }
  357. of_node_put(slave);
  358. /* Disable all interrupts in all controllers */
  359. for (i = 0; i * 32 < max_irqs; ++i)
  360. out_le32(&pmac_irq_hw[i]->enable, 0);
  361. /* Hookup cascade irq */
  362. if (slave && pmac_irq_cascade != NO_IRQ)
  363. setup_irq(pmac_irq_cascade, &gatwick_cascade_action);
  364. printk(KERN_INFO "irq: System has %d possible interrupts\n", max_irqs);
  365. #ifdef CONFIG_XMON
  366. setup_irq(irq_create_mapping(NULL, 20), &xmon_action);
  367. #endif
  368. }
  369. int of_irq_map_oldworld(struct device_node *device, int index,
  370. struct of_irq *out_irq)
  371. {
  372. const u32 *ints = NULL;
  373. int intlen;
  374. /*
  375. * Old machines just have a list of interrupt numbers
  376. * and no interrupt-controller nodes. We also have dodgy
  377. * cases where the APPL,interrupts property is completely
  378. * missing behind pci-pci bridges and we have to get it
  379. * from the parent (the bridge itself, as apple just wired
  380. * everything together on these)
  381. */
  382. while (device) {
  383. ints = of_get_property(device, "AAPL,interrupts", &intlen);
  384. if (ints != NULL)
  385. break;
  386. device = device->parent;
  387. if (device && strcmp(device->type, "pci") != 0)
  388. break;
  389. }
  390. if (ints == NULL)
  391. return -EINVAL;
  392. intlen /= sizeof(u32);
  393. if (index >= intlen)
  394. return -EINVAL;
  395. out_irq->controller = NULL;
  396. out_irq->specifier[0] = ints[index];
  397. out_irq->size = 1;
  398. return 0;
  399. }
  400. #endif /* CONFIG_PPC32 */
  401. static void pmac_u3_cascade(unsigned int irq, struct irq_desc *desc)
  402. {
  403. struct irq_chip *chip = irq_desc_get_chip(desc);
  404. struct mpic *mpic = irq_desc_get_handler_data(desc);
  405. unsigned int cascade_irq = mpic_get_one_irq(mpic);
  406. if (cascade_irq != NO_IRQ)
  407. generic_handle_irq(cascade_irq);
  408. chip->irq_eoi(&desc->irq_data);
  409. }
  410. static void __init pmac_pic_setup_mpic_nmi(struct mpic *mpic)
  411. {
  412. #if defined(CONFIG_XMON) && defined(CONFIG_PPC32)
  413. struct device_node* pswitch;
  414. int nmi_irq;
  415. pswitch = of_find_node_by_name(NULL, "programmer-switch");
  416. if (pswitch) {
  417. nmi_irq = irq_of_parse_and_map(pswitch, 0);
  418. if (nmi_irq != NO_IRQ) {
  419. mpic_irq_set_priority(nmi_irq, 9);
  420. setup_irq(nmi_irq, &xmon_action);
  421. }
  422. of_node_put(pswitch);
  423. }
  424. #endif /* defined(CONFIG_XMON) && defined(CONFIG_PPC32) */
  425. }
  426. static struct mpic * __init pmac_setup_one_mpic(struct device_node *np,
  427. int master)
  428. {
  429. const char *name = master ? " MPIC 1 " : " MPIC 2 ";
  430. struct resource r;
  431. struct mpic *mpic;
  432. unsigned int flags = master ? MPIC_PRIMARY : 0;
  433. int rc;
  434. rc = of_address_to_resource(np, 0, &r);
  435. if (rc)
  436. return NULL;
  437. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, np, 0, 0);
  438. flags |= MPIC_WANTS_RESET;
  439. if (of_get_property(np, "big-endian", NULL))
  440. flags |= MPIC_BIG_ENDIAN;
  441. /* Primary Big Endian means HT interrupts. This is quite dodgy
  442. * but works until I find a better way
  443. */
  444. if (master && (flags & MPIC_BIG_ENDIAN))
  445. flags |= MPIC_U3_HT_IRQS;
  446. mpic = mpic_alloc(np, r.start, flags, 0, 0, name);
  447. if (mpic == NULL)
  448. return NULL;
  449. mpic_init(mpic);
  450. return mpic;
  451. }
  452. static int __init pmac_pic_probe_mpic(void)
  453. {
  454. struct mpic *mpic1, *mpic2;
  455. struct device_node *np, *master = NULL, *slave = NULL;
  456. unsigned int cascade;
  457. /* We can have up to 2 MPICs cascaded */
  458. for (np = NULL; (np = of_find_node_by_type(np, "open-pic"))
  459. != NULL;) {
  460. if (master == NULL &&
  461. of_get_property(np, "interrupts", NULL) == NULL)
  462. master = of_node_get(np);
  463. else if (slave == NULL)
  464. slave = of_node_get(np);
  465. if (master && slave)
  466. break;
  467. }
  468. /* Check for bogus setups */
  469. if (master == NULL && slave != NULL) {
  470. master = slave;
  471. slave = NULL;
  472. }
  473. /* Not found, default to good old pmac pic */
  474. if (master == NULL)
  475. return -ENODEV;
  476. /* Set master handler */
  477. ppc_md.get_irq = mpic_get_irq;
  478. /* Setup master */
  479. mpic1 = pmac_setup_one_mpic(master, 1);
  480. BUG_ON(mpic1 == NULL);
  481. /* Install NMI if any */
  482. pmac_pic_setup_mpic_nmi(mpic1);
  483. of_node_put(master);
  484. /* No slave, let's go out */
  485. if (slave == NULL)
  486. return 0;
  487. /* Get/Map slave interrupt */
  488. cascade = irq_of_parse_and_map(slave, 0);
  489. if (cascade == NO_IRQ) {
  490. printk(KERN_ERR "Failed to map cascade IRQ\n");
  491. return 0;
  492. }
  493. mpic2 = pmac_setup_one_mpic(slave, 0);
  494. if (mpic2 == NULL) {
  495. printk(KERN_ERR "Failed to setup slave MPIC\n");
  496. of_node_put(slave);
  497. return 0;
  498. }
  499. irq_set_handler_data(cascade, mpic2);
  500. irq_set_chained_handler(cascade, pmac_u3_cascade);
  501. of_node_put(slave);
  502. return 0;
  503. }
  504. void __init pmac_pic_init(void)
  505. {
  506. /* We configure the OF parsing based on our oldworld vs. newworld
  507. * platform type and wether we were booted by BootX.
  508. */
  509. #ifdef CONFIG_PPC32
  510. if (!pmac_newworld)
  511. of_irq_workarounds |= OF_IMAP_OLDWORLD_MAC;
  512. if (of_get_property(of_chosen, "linux,bootx", NULL) != NULL)
  513. of_irq_workarounds |= OF_IMAP_NO_PHANDLE;
  514. /* If we don't have phandles on a newworld, then try to locate a
  515. * default interrupt controller (happens when booting with BootX).
  516. * We do a first match here, hopefully, that only ever happens on
  517. * machines with one controller.
  518. */
  519. if (pmac_newworld && (of_irq_workarounds & OF_IMAP_NO_PHANDLE)) {
  520. struct device_node *np;
  521. for_each_node_with_property(np, "interrupt-controller") {
  522. /* Skip /chosen/interrupt-controller */
  523. if (strcmp(np->name, "chosen") == 0)
  524. continue;
  525. /* It seems like at least one person wants
  526. * to use BootX on a machine with an AppleKiwi
  527. * controller which happens to pretend to be an
  528. * interrupt controller too. */
  529. if (strcmp(np->name, "AppleKiwi") == 0)
  530. continue;
  531. /* I think we found one ! */
  532. of_irq_dflt_pic = np;
  533. break;
  534. }
  535. }
  536. #endif /* CONFIG_PPC32 */
  537. /* We first try to detect Apple's new Core99 chipset, since mac-io
  538. * is quite different on those machines and contains an IBM MPIC2.
  539. */
  540. if (pmac_pic_probe_mpic() == 0)
  541. return;
  542. #ifdef CONFIG_PPC32
  543. pmac_pic_probe_oldstyle();
  544. #endif
  545. }
  546. #if defined(CONFIG_PM) && defined(CONFIG_PPC32)
  547. /*
  548. * These procedures are used in implementing sleep on the powerbooks.
  549. * sleep_save_intrs() saves the states of all interrupt enables
  550. * and disables all interrupts except for the nominated one.
  551. * sleep_restore_intrs() restores the states of all interrupt enables.
  552. */
  553. unsigned long sleep_save_mask[2];
  554. /* This used to be passed by the PMU driver but that link got
  555. * broken with the new driver model. We use this tweak for now...
  556. * We really want to do things differently though...
  557. */
  558. static int pmacpic_find_viaint(void)
  559. {
  560. int viaint = -1;
  561. #ifdef CONFIG_ADB_PMU
  562. struct device_node *np;
  563. if (pmu_get_model() != PMU_OHARE_BASED)
  564. goto not_found;
  565. np = of_find_node_by_name(NULL, "via-pmu");
  566. if (np == NULL)
  567. goto not_found;
  568. viaint = irq_of_parse_and_map(np, 0);
  569. not_found:
  570. #endif /* CONFIG_ADB_PMU */
  571. return viaint;
  572. }
  573. static int pmacpic_suspend(void)
  574. {
  575. int viaint = pmacpic_find_viaint();
  576. sleep_save_mask[0] = ppc_cached_irq_mask[0];
  577. sleep_save_mask[1] = ppc_cached_irq_mask[1];
  578. ppc_cached_irq_mask[0] = 0;
  579. ppc_cached_irq_mask[1] = 0;
  580. if (viaint > 0)
  581. set_bit(viaint, ppc_cached_irq_mask);
  582. out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]);
  583. if (max_real_irqs > 32)
  584. out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]);
  585. (void)in_le32(&pmac_irq_hw[0]->event);
  586. /* make sure mask gets to controller before we return to caller */
  587. mb();
  588. (void)in_le32(&pmac_irq_hw[0]->enable);
  589. return 0;
  590. }
  591. static void pmacpic_resume(void)
  592. {
  593. int i;
  594. out_le32(&pmac_irq_hw[0]->enable, 0);
  595. if (max_real_irqs > 32)
  596. out_le32(&pmac_irq_hw[1]->enable, 0);
  597. mb();
  598. for (i = 0; i < max_real_irqs; ++i)
  599. if (test_bit(i, sleep_save_mask))
  600. pmac_unmask_irq(irq_get_irq_data(i));
  601. }
  602. static struct syscore_ops pmacpic_syscore_ops = {
  603. .suspend = pmacpic_suspend,
  604. .resume = pmacpic_resume,
  605. };
  606. static int __init init_pmacpic_syscore(void)
  607. {
  608. if (pmac_irq_hw[0])
  609. register_syscore_ops(&pmacpic_syscore_ops);
  610. return 0;
  611. }
  612. machine_subsys_initcall(powermac, init_pmacpic_syscore);
  613. #endif /* CONFIG_PM && CONFIG_PPC32 */