pic.c 20 KB

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