pic.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 *, struct pt_regs *);
  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 GATWICK_IRQ_POOL_SIZE 10
  59. static struct interrupt_info gatwick_int_pool[GATWICK_IRQ_POOL_SIZE];
  60. #define NR_MASK_WORDS ((NR_IRQS + 31) / 32)
  61. static unsigned long ppc_lost_interrupts[NR_MASK_WORDS];
  62. /*
  63. * Mark an irq as "lost". This is only used on the pmac
  64. * since it can lose interrupts (see pmac_set_irq_mask).
  65. * -- Cort
  66. */
  67. void __set_lost(unsigned long irq_nr, int nokick)
  68. {
  69. if (!test_and_set_bit(irq_nr, ppc_lost_interrupts)) {
  70. atomic_inc(&ppc_n_lost_interrupts);
  71. if (!nokick)
  72. set_dec(1);
  73. }
  74. }
  75. static void pmac_mask_and_ack_irq(unsigned int irq_nr)
  76. {
  77. unsigned long bit = 1UL << (irq_nr & 0x1f);
  78. int i = irq_nr >> 5;
  79. unsigned long flags;
  80. if ((unsigned)irq_nr >= max_irqs)
  81. return;
  82. clear_bit(irq_nr, ppc_cached_irq_mask);
  83. if (test_and_clear_bit(irq_nr, ppc_lost_interrupts))
  84. atomic_dec(&ppc_n_lost_interrupts);
  85. spin_lock_irqsave(&pmac_pic_lock, flags);
  86. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  87. out_le32(&pmac_irq_hw[i]->ack, bit);
  88. do {
  89. /* make sure ack gets to controller before we enable
  90. interrupts */
  91. mb();
  92. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  93. != (ppc_cached_irq_mask[i] & bit));
  94. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  95. }
  96. static void pmac_set_irq_mask(unsigned int irq_nr, int nokicklost)
  97. {
  98. unsigned long bit = 1UL << (irq_nr & 0x1f);
  99. int i = irq_nr >> 5;
  100. unsigned long flags;
  101. if ((unsigned)irq_nr >= max_irqs)
  102. return;
  103. spin_lock_irqsave(&pmac_pic_lock, flags);
  104. /* enable unmasked interrupts */
  105. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  106. do {
  107. /* make sure mask gets to controller before we
  108. return to user */
  109. mb();
  110. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  111. != (ppc_cached_irq_mask[i] & bit));
  112. /*
  113. * Unfortunately, setting the bit in the enable register
  114. * when the device interrupt is already on *doesn't* set
  115. * the bit in the flag register or request another interrupt.
  116. */
  117. if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level))
  118. __set_lost((ulong)irq_nr, nokicklost);
  119. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  120. }
  121. /* When an irq gets requested for the first client, if it's an
  122. * edge interrupt, we clear any previous one on the controller
  123. */
  124. static unsigned int pmac_startup_irq(unsigned int irq_nr)
  125. {
  126. unsigned long bit = 1UL << (irq_nr & 0x1f);
  127. int i = irq_nr >> 5;
  128. if ((irq_desc[irq_nr].status & IRQ_LEVEL) == 0)
  129. out_le32(&pmac_irq_hw[i]->ack, bit);
  130. set_bit(irq_nr, ppc_cached_irq_mask);
  131. pmac_set_irq_mask(irq_nr, 0);
  132. return 0;
  133. }
  134. static void pmac_mask_irq(unsigned int irq_nr)
  135. {
  136. clear_bit(irq_nr, ppc_cached_irq_mask);
  137. pmac_set_irq_mask(irq_nr, 0);
  138. mb();
  139. }
  140. static void pmac_unmask_irq(unsigned int irq_nr)
  141. {
  142. set_bit(irq_nr, ppc_cached_irq_mask);
  143. pmac_set_irq_mask(irq_nr, 0);
  144. }
  145. static void pmac_end_irq(unsigned int irq_nr)
  146. {
  147. if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))
  148. && irq_desc[irq_nr].action) {
  149. set_bit(irq_nr, ppc_cached_irq_mask);
  150. pmac_set_irq_mask(irq_nr, 1);
  151. }
  152. }
  153. struct hw_interrupt_type pmac_pic = {
  154. .typename = " PMAC-PIC ",
  155. .startup = pmac_startup_irq,
  156. .enable = pmac_unmask_irq,
  157. .disable = pmac_mask_irq,
  158. .ack = pmac_mask_and_ack_irq,
  159. .end = pmac_end_irq,
  160. };
  161. struct hw_interrupt_type gatwick_pic = {
  162. .typename = " GATWICK ",
  163. .startup = pmac_startup_irq,
  164. .enable = pmac_unmask_irq,
  165. .disable = pmac_mask_irq,
  166. .ack = pmac_mask_and_ack_irq,
  167. .end = pmac_end_irq,
  168. };
  169. static irqreturn_t gatwick_action(int cpl, void *dev_id, struct pt_regs *regs)
  170. {
  171. int irq, bits;
  172. for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) {
  173. int i = irq >> 5;
  174. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  175. /* We must read level interrupts from the level register */
  176. bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
  177. bits &= ppc_cached_irq_mask[i];
  178. if (bits == 0)
  179. continue;
  180. irq += __ilog2(bits);
  181. __do_IRQ(irq, regs);
  182. return IRQ_HANDLED;
  183. }
  184. printk("gatwick irq not from gatwick pic\n");
  185. return IRQ_NONE;
  186. }
  187. static int pmac_get_irq(struct pt_regs *regs)
  188. {
  189. int irq;
  190. unsigned long bits = 0;
  191. #ifdef CONFIG_SMP
  192. void psurge_smp_message_recv(struct pt_regs *);
  193. /* IPI's are a hack on the powersurge -- Cort */
  194. if ( smp_processor_id() != 0 ) {
  195. psurge_smp_message_recv(regs);
  196. return -2; /* ignore, already handled */
  197. }
  198. #endif /* CONFIG_SMP */
  199. for (irq = max_real_irqs; (irq -= 32) >= 0; ) {
  200. int i = irq >> 5;
  201. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  202. /* We must read level interrupts from the level register */
  203. bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
  204. bits &= ppc_cached_irq_mask[i];
  205. if (bits == 0)
  206. continue;
  207. irq += __ilog2(bits);
  208. break;
  209. }
  210. return irq;
  211. }
  212. /* This routine will fix some missing interrupt values in the device tree
  213. * on the gatwick mac-io controller used by some PowerBooks
  214. *
  215. * Walking of OF nodes could use a bit more fixing up here, but it's not
  216. * very important as this is all boot time code on static portions of the
  217. * device-tree.
  218. *
  219. * However, the modifications done to "intrs" will have to be removed and
  220. * replaced with proper updates of the "interrupts" properties or
  221. * AAPL,interrupts, yet to be decided, once the dynamic parsing is there.
  222. */
  223. static void __init pmac_fix_gatwick_interrupts(struct device_node *gw,
  224. int irq_base)
  225. {
  226. struct device_node *node;
  227. int count;
  228. memset(gatwick_int_pool, 0, sizeof(gatwick_int_pool));
  229. count = 0;
  230. for (node = NULL; (node = of_get_next_child(gw, node)) != NULL;) {
  231. /* Fix SCC */
  232. if ((strcasecmp(node->name, "escc") == 0) && node->child) {
  233. if (node->child->n_intrs < 3) {
  234. node->child->intrs = &gatwick_int_pool[count];
  235. count += 3;
  236. }
  237. node->child->n_intrs = 3;
  238. node->child->intrs[0].line = 15+irq_base;
  239. node->child->intrs[1].line = 4+irq_base;
  240. node->child->intrs[2].line = 5+irq_base;
  241. printk(KERN_INFO "irq: fixed SCC on gatwick"
  242. " (%d,%d,%d)\n",
  243. node->child->intrs[0].line,
  244. node->child->intrs[1].line,
  245. node->child->intrs[2].line);
  246. }
  247. /* Fix media-bay & left SWIM */
  248. if (strcasecmp(node->name, "media-bay") == 0) {
  249. struct device_node* ya_node;
  250. if (node->n_intrs == 0)
  251. node->intrs = &gatwick_int_pool[count++];
  252. node->n_intrs = 1;
  253. node->intrs[0].line = 29+irq_base;
  254. printk(KERN_INFO "irq: fixed media-bay on gatwick"
  255. " (%d)\n", node->intrs[0].line);
  256. ya_node = node->child;
  257. while(ya_node) {
  258. if (strcasecmp(ya_node->name, "floppy") == 0) {
  259. if (ya_node->n_intrs < 2) {
  260. ya_node->intrs = &gatwick_int_pool[count];
  261. count += 2;
  262. }
  263. ya_node->n_intrs = 2;
  264. ya_node->intrs[0].line = 19+irq_base;
  265. ya_node->intrs[1].line = 1+irq_base;
  266. printk(KERN_INFO "irq: fixed floppy on second controller (%d,%d)\n",
  267. ya_node->intrs[0].line, ya_node->intrs[1].line);
  268. }
  269. if (strcasecmp(ya_node->name, "ata4") == 0) {
  270. if (ya_node->n_intrs < 2) {
  271. ya_node->intrs = &gatwick_int_pool[count];
  272. count += 2;
  273. }
  274. ya_node->n_intrs = 2;
  275. ya_node->intrs[0].line = 14+irq_base;
  276. ya_node->intrs[1].line = 3+irq_base;
  277. printk(KERN_INFO "irq: fixed ide on second controller (%d,%d)\n",
  278. ya_node->intrs[0].line, ya_node->intrs[1].line);
  279. }
  280. ya_node = ya_node->sibling;
  281. }
  282. }
  283. }
  284. if (count > 10) {
  285. printk("WARNING !! Gatwick interrupt pool overflow\n");
  286. printk(" GATWICK_IRQ_POOL_SIZE = %d\n", GATWICK_IRQ_POOL_SIZE);
  287. printk(" requested = %d\n", count);
  288. }
  289. }
  290. /*
  291. * The PowerBook 3400/2400/3500 can have a combo ethernet/modem
  292. * card which includes an ohare chip that acts as a second interrupt
  293. * controller. If we find this second ohare, set it up and fix the
  294. * interrupt value in the device tree for the ethernet chip.
  295. */
  296. static void __init enable_second_ohare(struct device_node *np)
  297. {
  298. unsigned char bus, devfn;
  299. unsigned short cmd;
  300. struct device_node *ether;
  301. /* This code doesn't strictly belong here, it could be part of
  302. * either the PCI initialisation or the feature code. It's kept
  303. * here for historical reasons.
  304. */
  305. if (pci_device_from_OF_node(np, &bus, &devfn) == 0) {
  306. struct pci_controller* hose =
  307. pci_find_hose_for_OF_device(np);
  308. if (!hose) {
  309. printk(KERN_ERR "Can't find PCI hose for OHare2 !\n");
  310. return;
  311. }
  312. early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd);
  313. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  314. cmd &= ~PCI_COMMAND_IO;
  315. early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd);
  316. }
  317. /* Fix interrupt for the modem/ethernet combo controller. The number
  318. * in the device tree (27) is bogus (correct for the ethernet-only
  319. * board but not the combo ethernet/modem board).
  320. * The real interrupt is 28 on the second controller -> 28+32 = 60.
  321. */
  322. ether = of_find_node_by_name(NULL, "pci1011,14");
  323. if (ether && ether->n_intrs > 0) {
  324. ether->intrs[0].line = 60;
  325. printk(KERN_INFO "irq: Fixed ethernet IRQ to %d\n",
  326. ether->intrs[0].line);
  327. }
  328. of_node_put(ether);
  329. }
  330. #ifdef CONFIG_XMON
  331. static struct irqaction xmon_action = {
  332. .handler = xmon_irq,
  333. .flags = 0,
  334. .mask = CPU_MASK_NONE,
  335. .name = "NMI - XMON"
  336. };
  337. #endif
  338. static struct irqaction gatwick_cascade_action = {
  339. .handler = gatwick_action,
  340. .flags = IRQF_DISABLED,
  341. .mask = CPU_MASK_NONE,
  342. .name = "cascade",
  343. };
  344. static void __init pmac_pic_probe_oldstyle(void)
  345. {
  346. int i;
  347. int irq_cascade = -1;
  348. struct device_node *master = NULL;
  349. struct device_node *slave = NULL;
  350. u8 __iomem *addr;
  351. struct resource r;
  352. /* Set our get_irq function */
  353. ppc_md.get_irq = pmac_get_irq;
  354. /*
  355. * Find the interrupt controller type & node
  356. */
  357. if ((master = of_find_node_by_name(NULL, "gc")) != NULL) {
  358. max_irqs = max_real_irqs = 32;
  359. level_mask[0] = GC_LEVEL_MASK;
  360. } else if ((master = of_find_node_by_name(NULL, "ohare")) != NULL) {
  361. max_irqs = max_real_irqs = 32;
  362. level_mask[0] = OHARE_LEVEL_MASK;
  363. /* We might have a second cascaded ohare */
  364. slave = of_find_node_by_name(NULL, "pci106b,7");
  365. if (slave) {
  366. max_irqs = 64;
  367. level_mask[1] = OHARE_LEVEL_MASK;
  368. enable_second_ohare(slave);
  369. }
  370. } else if ((master = of_find_node_by_name(NULL, "mac-io")) != NULL) {
  371. max_irqs = max_real_irqs = 64;
  372. level_mask[0] = HEATHROW_LEVEL_MASK;
  373. level_mask[1] = 0;
  374. /* We might have a second cascaded heathrow */
  375. slave = of_find_node_by_name(master, "mac-io");
  376. /* Check ordering of master & slave */
  377. if (device_is_compatible(master, "gatwick")) {
  378. struct device_node *tmp;
  379. BUG_ON(slave == NULL);
  380. tmp = master;
  381. master = slave;
  382. slave = tmp;
  383. }
  384. /* We found a slave */
  385. if (slave) {
  386. max_irqs = 128;
  387. level_mask[2] = HEATHROW_LEVEL_MASK;
  388. level_mask[3] = 0;
  389. pmac_fix_gatwick_interrupts(slave, max_real_irqs);
  390. }
  391. }
  392. BUG_ON(master == NULL);
  393. /* Set the handler for the main PIC */
  394. for ( i = 0; i < max_real_irqs ; i++ )
  395. irq_desc[i].chip = &pmac_pic;
  396. /* Get addresses of first controller if we have a node for it */
  397. BUG_ON(of_address_to_resource(master, 0, &r));
  398. /* Map interrupts of primary controller */
  399. addr = (u8 __iomem *) ioremap(r.start, 0x40);
  400. i = 0;
  401. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  402. (addr + 0x20);
  403. if (max_real_irqs > 32)
  404. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  405. (addr + 0x10);
  406. of_node_put(master);
  407. printk(KERN_INFO "irq: Found primary Apple PIC %s for %d irqs\n",
  408. master->full_name, max_real_irqs);
  409. /* Map interrupts of cascaded controller */
  410. if (slave && !of_address_to_resource(slave, 0, &r)) {
  411. addr = (u8 __iomem *)ioremap(r.start, 0x40);
  412. pmac_irq_hw[i++] = (volatile struct pmac_irq_hw __iomem *)
  413. (addr + 0x20);
  414. if (max_irqs > 64)
  415. pmac_irq_hw[i++] =
  416. (volatile struct pmac_irq_hw __iomem *)
  417. (addr + 0x10);
  418. irq_cascade = slave->intrs[0].line;
  419. printk(KERN_INFO "irq: Found slave Apple PIC %s for %d irqs"
  420. " cascade: %d\n", slave->full_name,
  421. max_irqs - max_real_irqs, irq_cascade);
  422. }
  423. of_node_put(slave);
  424. /* disable all interrupts in all controllers */
  425. for (i = 0; i * 32 < max_irqs; ++i)
  426. out_le32(&pmac_irq_hw[i]->enable, 0);
  427. /* mark level interrupts */
  428. for (i = 0; i < max_irqs; i++)
  429. if (level_mask[i >> 5] & (1UL << (i & 0x1f)))
  430. irq_desc[i].status = IRQ_LEVEL;
  431. /* Setup handlers for secondary controller and hook cascade irq*/
  432. if (slave) {
  433. for ( i = max_real_irqs ; i < max_irqs ; i++ )
  434. irq_desc[i].chip = &gatwick_pic;
  435. setup_irq(irq_cascade, &gatwick_cascade_action);
  436. }
  437. printk(KERN_INFO "irq: System has %d possible interrupts\n", max_irqs);
  438. #ifdef CONFIG_XMON
  439. setup_irq(20, &xmon_action);
  440. #endif
  441. }
  442. #endif /* CONFIG_PPC32 */
  443. static int pmac_u3_cascade(struct pt_regs *regs, void *data)
  444. {
  445. return mpic_get_one_irq((struct mpic *)data, regs);
  446. }
  447. static void __init pmac_pic_setup_mpic_nmi(struct mpic *mpic)
  448. {
  449. #if defined(CONFIG_XMON) && defined(CONFIG_PPC32)
  450. struct device_node* pswitch;
  451. int nmi_irq;
  452. pswitch = of_find_node_by_name(NULL, "programmer-switch");
  453. if (pswitch && pswitch->n_intrs) {
  454. nmi_irq = pswitch->intrs[0].line;
  455. mpic_irq_set_priority(nmi_irq, 9);
  456. setup_irq(nmi_irq, &xmon_action);
  457. }
  458. of_node_put(pswitch);
  459. #endif /* defined(CONFIG_XMON) && defined(CONFIG_PPC32) */
  460. }
  461. static struct mpic * __init pmac_setup_one_mpic(struct device_node *np,
  462. int master)
  463. {
  464. unsigned char senses[128];
  465. int offset = master ? 0 : 128;
  466. int count = master ? 128 : 124;
  467. const char *name = master ? " MPIC 1 " : " MPIC 2 ";
  468. struct resource r;
  469. struct mpic *mpic;
  470. unsigned int flags = master ? MPIC_PRIMARY : 0;
  471. int rc;
  472. rc = of_address_to_resource(np, 0, &r);
  473. if (rc)
  474. return NULL;
  475. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, np, 0, 0);
  476. prom_get_irq_senses(senses, offset, offset + count);
  477. flags |= MPIC_WANTS_RESET;
  478. if (get_property(np, "big-endian", NULL))
  479. flags |= MPIC_BIG_ENDIAN;
  480. /* Primary Big Endian means HT interrupts. This is quite dodgy
  481. * but works until I find a better way
  482. */
  483. if (master && (flags & MPIC_BIG_ENDIAN))
  484. flags |= MPIC_BROKEN_U3;
  485. mpic = mpic_alloc(r.start, flags, 0, offset, count, master ? 252 : 0,
  486. senses, count, name);
  487. if (mpic == NULL)
  488. return NULL;
  489. mpic_init(mpic);
  490. return mpic;
  491. }
  492. static int __init pmac_pic_probe_mpic(void)
  493. {
  494. struct mpic *mpic1, *mpic2;
  495. struct device_node *np, *master = NULL, *slave = NULL;
  496. /* We can have up to 2 MPICs cascaded */
  497. for (np = NULL; (np = of_find_node_by_type(np, "open-pic"))
  498. != NULL;) {
  499. if (master == NULL &&
  500. get_property(np, "interrupts", NULL) == NULL)
  501. master = of_node_get(np);
  502. else if (slave == NULL)
  503. slave = of_node_get(np);
  504. if (master && slave)
  505. break;
  506. }
  507. /* Check for bogus setups */
  508. if (master == NULL && slave != NULL) {
  509. master = slave;
  510. slave = NULL;
  511. }
  512. /* Not found, default to good old pmac pic */
  513. if (master == NULL)
  514. return -ENODEV;
  515. /* Set master handler */
  516. ppc_md.get_irq = mpic_get_irq;
  517. /* Setup master */
  518. mpic1 = pmac_setup_one_mpic(master, 1);
  519. BUG_ON(mpic1 == NULL);
  520. /* Install NMI if any */
  521. pmac_pic_setup_mpic_nmi(mpic1);
  522. of_node_put(master);
  523. /* No slave, let's go out */
  524. if (slave == NULL || slave->n_intrs < 1)
  525. return 0;
  526. mpic2 = pmac_setup_one_mpic(slave, 0);
  527. if (mpic2 == NULL) {
  528. printk(KERN_ERR "Failed to setup slave MPIC\n");
  529. of_node_put(slave);
  530. return 0;
  531. }
  532. mpic_setup_cascade(slave->intrs[0].line, pmac_u3_cascade, mpic2);
  533. of_node_put(slave);
  534. return 0;
  535. }
  536. void __init pmac_pic_init(void)
  537. {
  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. */
  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 = np->intrs[0].line;
  569. #endif /* CONFIG_ADB_PMU */
  570. not_found:
  571. return viaint;
  572. }
  573. static int pmacpic_suspend(struct sys_device *sysdev, pm_message_t state)
  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 int pmacpic_resume(struct sys_device *sysdev)
  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(i);
  601. return 0;
  602. }
  603. #endif /* CONFIG_PM && CONFIG_PPC32 */
  604. static struct sysdev_class pmacpic_sysclass = {
  605. set_kset_name("pmac_pic"),
  606. };
  607. static struct sys_device device_pmacpic = {
  608. .id = 0,
  609. .cls = &pmacpic_sysclass,
  610. };
  611. static struct sysdev_driver driver_pmacpic = {
  612. #if defined(CONFIG_PM) && defined(CONFIG_PPC32)
  613. .suspend = &pmacpic_suspend,
  614. .resume = &pmacpic_resume,
  615. #endif /* CONFIG_PM && CONFIG_PPC32 */
  616. };
  617. static int __init init_pmacpic_sysfs(void)
  618. {
  619. #ifdef CONFIG_PPC32
  620. if (max_irqs == 0)
  621. return -ENODEV;
  622. #endif
  623. printk(KERN_DEBUG "Registering pmac pic with sysfs...\n");
  624. sysdev_class_register(&pmacpic_sysclass);
  625. sysdev_register(&device_pmacpic);
  626. sysdev_driver_register(&pmacpic_sysclass, &driver_pmacpic);
  627. return 0;
  628. }
  629. subsys_initcall(init_pmacpic_sysfs);