pic.c 20 KB

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