pic.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. *
  9. * Maintained by Benjamin Herrenschmidt (benh@kernel.crashing.org)
  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/xmon.h>
  35. #include <asm/pmac_feature.h>
  36. #include <asm/mpic.h>
  37. #include "pmac.h"
  38. /*
  39. * XXX this should be in xmon.h, but putting it there means xmon.h
  40. * has to include <linux/interrupt.h> (to get irqreturn_t), which
  41. * causes all sorts of problems. -- paulus
  42. */
  43. extern irqreturn_t xmon_irq(int, void *, struct pt_regs *);
  44. #ifdef CONFIG_PPC32
  45. struct pmac_irq_hw {
  46. unsigned int event;
  47. unsigned int enable;
  48. unsigned int ack;
  49. unsigned int level;
  50. };
  51. /* Default addresses */
  52. static volatile struct pmac_irq_hw *pmac_irq_hw[4] = {
  53. (struct pmac_irq_hw *) 0xf3000020,
  54. (struct pmac_irq_hw *) 0xf3000010,
  55. (struct pmac_irq_hw *) 0xf4000020,
  56. (struct pmac_irq_hw *) 0xf4000010,
  57. };
  58. #define GC_LEVEL_MASK 0x3ff00000
  59. #define OHARE_LEVEL_MASK 0x1ff00000
  60. #define HEATHROW_LEVEL_MASK 0x1ff00000
  61. static int max_irqs;
  62. static int max_real_irqs;
  63. static u32 level_mask[4];
  64. static DEFINE_SPINLOCK(pmac_pic_lock);
  65. /* XXX here for now, should move to arch/powerpc/kernel/irq.c */
  66. int ppc_do_canonicalize_irqs;
  67. EXPORT_SYMBOL(ppc_do_canonicalize_irqs);
  68. #define GATWICK_IRQ_POOL_SIZE 10
  69. static struct interrupt_info gatwick_int_pool[GATWICK_IRQ_POOL_SIZE];
  70. /*
  71. * Mark an irq as "lost". This is only used on the pmac
  72. * since it can lose interrupts (see pmac_set_irq_mask).
  73. * -- Cort
  74. */
  75. void
  76. __set_lost(unsigned long irq_nr, int nokick)
  77. {
  78. if (!test_and_set_bit(irq_nr, ppc_lost_interrupts)) {
  79. atomic_inc(&ppc_n_lost_interrupts);
  80. if (!nokick)
  81. set_dec(1);
  82. }
  83. }
  84. static void
  85. pmac_mask_and_ack_irq(unsigned int irq_nr)
  86. {
  87. unsigned long bit = 1UL << (irq_nr & 0x1f);
  88. int i = irq_nr >> 5;
  89. unsigned long flags;
  90. if ((unsigned)irq_nr >= max_irqs)
  91. return;
  92. clear_bit(irq_nr, ppc_cached_irq_mask);
  93. if (test_and_clear_bit(irq_nr, ppc_lost_interrupts))
  94. atomic_dec(&ppc_n_lost_interrupts);
  95. spin_lock_irqsave(&pmac_pic_lock, flags);
  96. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  97. out_le32(&pmac_irq_hw[i]->ack, bit);
  98. do {
  99. /* make sure ack gets to controller before we enable
  100. interrupts */
  101. mb();
  102. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  103. != (ppc_cached_irq_mask[i] & bit));
  104. 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. unsigned long flags;
  111. if ((unsigned)irq_nr >= max_irqs)
  112. return;
  113. spin_lock_irqsave(&pmac_pic_lock, flags);
  114. /* enable unmasked interrupts */
  115. out_le32(&pmac_irq_hw[i]->enable, ppc_cached_irq_mask[i]);
  116. do {
  117. /* make sure mask gets to controller before we
  118. return to user */
  119. mb();
  120. } while((in_le32(&pmac_irq_hw[i]->enable) & bit)
  121. != (ppc_cached_irq_mask[i] & bit));
  122. /*
  123. * Unfortunately, setting the bit in the enable register
  124. * when the device interrupt is already on *doesn't* set
  125. * the bit in the flag register or request another interrupt.
  126. */
  127. if (bit & ppc_cached_irq_mask[i] & in_le32(&pmac_irq_hw[i]->level))
  128. __set_lost((ulong)irq_nr, nokicklost);
  129. spin_unlock_irqrestore(&pmac_pic_lock, flags);
  130. }
  131. /* When an irq gets requested for the first client, if it's an
  132. * edge interrupt, we clear any previous one on the controller
  133. */
  134. static unsigned int pmac_startup_irq(unsigned int irq_nr)
  135. {
  136. unsigned long bit = 1UL << (irq_nr & 0x1f);
  137. int i = irq_nr >> 5;
  138. if ((irq_desc[irq_nr].status & IRQ_LEVEL) == 0)
  139. out_le32(&pmac_irq_hw[i]->ack, bit);
  140. set_bit(irq_nr, ppc_cached_irq_mask);
  141. pmac_set_irq_mask(irq_nr, 0);
  142. return 0;
  143. }
  144. static void pmac_mask_irq(unsigned int irq_nr)
  145. {
  146. clear_bit(irq_nr, ppc_cached_irq_mask);
  147. pmac_set_irq_mask(irq_nr, 0);
  148. mb();
  149. }
  150. static void pmac_unmask_irq(unsigned int irq_nr)
  151. {
  152. set_bit(irq_nr, ppc_cached_irq_mask);
  153. pmac_set_irq_mask(irq_nr, 0);
  154. }
  155. static void pmac_end_irq(unsigned int irq_nr)
  156. {
  157. if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS))
  158. && irq_desc[irq_nr].action) {
  159. set_bit(irq_nr, ppc_cached_irq_mask);
  160. pmac_set_irq_mask(irq_nr, 1);
  161. }
  162. }
  163. struct hw_interrupt_type pmac_pic = {
  164. .typename = " PMAC-PIC ",
  165. .startup = pmac_startup_irq,
  166. .enable = pmac_unmask_irq,
  167. .disable = pmac_mask_irq,
  168. .ack = pmac_mask_and_ack_irq,
  169. .end = pmac_end_irq,
  170. };
  171. struct hw_interrupt_type gatwick_pic = {
  172. .typename = " GATWICK ",
  173. .startup = pmac_startup_irq,
  174. .enable = pmac_unmask_irq,
  175. .disable = pmac_mask_irq,
  176. .ack = pmac_mask_and_ack_irq,
  177. .end = pmac_end_irq,
  178. };
  179. static irqreturn_t gatwick_action(int cpl, void *dev_id, struct pt_regs *regs)
  180. {
  181. int irq, bits;
  182. for (irq = max_irqs; (irq -= 32) >= max_real_irqs; ) {
  183. int i = irq >> 5;
  184. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  185. /* We must read level interrupts from the level register */
  186. bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
  187. bits &= ppc_cached_irq_mask[i];
  188. if (bits == 0)
  189. continue;
  190. irq += __ilog2(bits);
  191. __do_IRQ(irq, regs);
  192. return IRQ_HANDLED;
  193. }
  194. printk("gatwick irq not from gatwick pic\n");
  195. return IRQ_NONE;
  196. }
  197. int
  198. pmac_get_irq(struct pt_regs *regs)
  199. {
  200. int irq;
  201. unsigned long bits = 0;
  202. #ifdef CONFIG_SMP
  203. void psurge_smp_message_recv(struct pt_regs *);
  204. /* IPI's are a hack on the powersurge -- Cort */
  205. if ( smp_processor_id() != 0 ) {
  206. psurge_smp_message_recv(regs);
  207. return -2; /* ignore, already handled */
  208. }
  209. #endif /* CONFIG_SMP */
  210. for (irq = max_real_irqs; (irq -= 32) >= 0; ) {
  211. int i = irq >> 5;
  212. bits = in_le32(&pmac_irq_hw[i]->event) | ppc_lost_interrupts[i];
  213. /* We must read level interrupts from the level register */
  214. bits |= (in_le32(&pmac_irq_hw[i]->level) & level_mask[i]);
  215. bits &= ppc_cached_irq_mask[i];
  216. if (bits == 0)
  217. continue;
  218. irq += __ilog2(bits);
  219. break;
  220. }
  221. return irq;
  222. }
  223. /* This routine will fix some missing interrupt values in the device tree
  224. * on the gatwick mac-io controller used by some PowerBooks
  225. */
  226. static void __init
  227. pmac_fix_gatwick_interrupts(struct device_node *gw, int irq_base)
  228. {
  229. struct device_node *node;
  230. int count;
  231. memset(gatwick_int_pool, 0, sizeof(gatwick_int_pool));
  232. node = gw->child;
  233. count = 0;
  234. while(node)
  235. {
  236. /* Fix SCC */
  237. if (strcasecmp(node->name, "escc") == 0)
  238. if (node->child) {
  239. if (node->child->n_intrs < 3) {
  240. node->child->intrs = &gatwick_int_pool[count];
  241. count += 3;
  242. }
  243. node->child->n_intrs = 3;
  244. node->child->intrs[0].line = 15+irq_base;
  245. node->child->intrs[1].line = 4+irq_base;
  246. node->child->intrs[2].line = 5+irq_base;
  247. printk(KERN_INFO "irq: fixed SCC on second controller (%d,%d,%d)\n",
  248. node->child->intrs[0].line,
  249. node->child->intrs[1].line,
  250. node->child->intrs[2].line);
  251. }
  252. /* Fix media-bay & left SWIM */
  253. if (strcasecmp(node->name, "media-bay") == 0) {
  254. struct device_node* ya_node;
  255. if (node->n_intrs == 0)
  256. node->intrs = &gatwick_int_pool[count++];
  257. node->n_intrs = 1;
  258. node->intrs[0].line = 29+irq_base;
  259. printk(KERN_INFO "irq: fixed media-bay on second controller (%d)\n",
  260. node->intrs[0].line);
  261. ya_node = node->child;
  262. while(ya_node)
  263. {
  264. if (strcasecmp(ya_node->name, "floppy") == 0) {
  265. if (ya_node->n_intrs < 2) {
  266. ya_node->intrs = &gatwick_int_pool[count];
  267. count += 2;
  268. }
  269. ya_node->n_intrs = 2;
  270. ya_node->intrs[0].line = 19+irq_base;
  271. ya_node->intrs[1].line = 1+irq_base;
  272. printk(KERN_INFO "irq: fixed floppy on second controller (%d,%d)\n",
  273. ya_node->intrs[0].line, ya_node->intrs[1].line);
  274. }
  275. if (strcasecmp(ya_node->name, "ata4") == 0) {
  276. if (ya_node->n_intrs < 2) {
  277. ya_node->intrs = &gatwick_int_pool[count];
  278. count += 2;
  279. }
  280. ya_node->n_intrs = 2;
  281. ya_node->intrs[0].line = 14+irq_base;
  282. ya_node->intrs[1].line = 3+irq_base;
  283. printk(KERN_INFO "irq: fixed ide on second controller (%d,%d)\n",
  284. ya_node->intrs[0].line, ya_node->intrs[1].line);
  285. }
  286. ya_node = ya_node->sibling;
  287. }
  288. }
  289. node = node->sibling;
  290. }
  291. if (count > 10) {
  292. printk("WARNING !! Gatwick interrupt pool overflow\n");
  293. printk(" GATWICK_IRQ_POOL_SIZE = %d\n", GATWICK_IRQ_POOL_SIZE);
  294. printk(" requested = %d\n", count);
  295. }
  296. }
  297. /*
  298. * The PowerBook 3400/2400/3500 can have a combo ethernet/modem
  299. * card which includes an ohare chip that acts as a second interrupt
  300. * controller. If we find this second ohare, set it up and fix the
  301. * interrupt value in the device tree for the ethernet chip.
  302. */
  303. static int __init enable_second_ohare(void)
  304. {
  305. unsigned char bus, devfn;
  306. unsigned short cmd;
  307. unsigned long addr;
  308. struct device_node *irqctrler = find_devices("pci106b,7");
  309. struct device_node *ether;
  310. if (irqctrler == NULL || irqctrler->n_addrs <= 0)
  311. return -1;
  312. addr = (unsigned long) ioremap(irqctrler->addrs[0].address, 0x40);
  313. pmac_irq_hw[1] = (volatile struct pmac_irq_hw *)(addr + 0x20);
  314. max_irqs = 64;
  315. if (pci_device_from_OF_node(irqctrler, &bus, &devfn) == 0) {
  316. struct pci_controller* hose = pci_find_hose_for_OF_device(irqctrler);
  317. if (!hose)
  318. printk(KERN_ERR "Can't find PCI hose for OHare2 !\n");
  319. else {
  320. early_read_config_word(hose, bus, devfn, PCI_COMMAND, &cmd);
  321. cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  322. cmd &= ~PCI_COMMAND_IO;
  323. early_write_config_word(hose, bus, devfn, PCI_COMMAND, cmd);
  324. }
  325. }
  326. /* Fix interrupt for the modem/ethernet combo controller. The number
  327. in the device tree (27) is bogus (correct for the ethernet-only
  328. board but not the combo ethernet/modem board).
  329. The real interrupt is 28 on the second controller -> 28+32 = 60.
  330. */
  331. ether = find_devices("pci1011,14");
  332. if (ether && ether->n_intrs > 0) {
  333. ether->intrs[0].line = 60;
  334. printk(KERN_INFO "irq: Fixed ethernet IRQ to %d\n",
  335. ether->intrs[0].line);
  336. }
  337. /* Return the interrupt number of the cascade */
  338. return irqctrler->intrs[0].line;
  339. }
  340. #ifdef CONFIG_XMON
  341. static struct irqaction xmon_action = {
  342. .handler = xmon_irq,
  343. .flags = 0,
  344. .mask = CPU_MASK_NONE,
  345. .name = "NMI - XMON"
  346. };
  347. #endif
  348. static struct irqaction gatwick_cascade_action = {
  349. .handler = gatwick_action,
  350. .flags = SA_INTERRUPT,
  351. .mask = CPU_MASK_NONE,
  352. .name = "cascade",
  353. };
  354. #endif /* CONFIG_PPC32 */
  355. static int pmac_u3_cascade(struct pt_regs *regs, void *data)
  356. {
  357. return mpic_get_one_irq((struct mpic *)data, regs);
  358. }
  359. void __init pmac_pic_init(void)
  360. {
  361. struct device_node *irqctrler = NULL;
  362. struct device_node *irqctrler2 = NULL;
  363. struct device_node *np;
  364. #ifdef CONFIG_PPC32
  365. int i;
  366. unsigned long addr;
  367. int irq_cascade = -1;
  368. #endif
  369. struct mpic *mpic1, *mpic2;
  370. /* We first try to detect Apple's new Core99 chipset, since mac-io
  371. * is quite different on those machines and contains an IBM MPIC2.
  372. */
  373. np = find_type_devices("open-pic");
  374. while (np) {
  375. if (np->parent && !strcmp(np->parent->name, "u3"))
  376. irqctrler2 = np;
  377. else
  378. irqctrler = np;
  379. np = np->next;
  380. }
  381. if (irqctrler != NULL && irqctrler->n_addrs > 0) {
  382. unsigned char senses[128];
  383. printk(KERN_INFO "PowerMac using OpenPIC irq controller at 0x%08x\n",
  384. (unsigned int)irqctrler->addrs[0].address);
  385. ppc_md.get_irq = mpic_get_irq;
  386. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler, 0, 0);
  387. prom_get_irq_senses(senses, 0, 128);
  388. mpic1 = mpic_alloc(irqctrler->addrs[0].address,
  389. MPIC_PRIMARY | MPIC_WANTS_RESET,
  390. 0, 0, 128, 252, senses, 128, " OpenPIC ");
  391. BUG_ON(mpic1 == NULL);
  392. mpic_init(mpic1);
  393. if (irqctrler2 != NULL && irqctrler2->n_intrs > 0 &&
  394. irqctrler2->n_addrs > 0) {
  395. printk(KERN_INFO "Slave OpenPIC at 0x%08x hooked on IRQ %d\n",
  396. (u32)irqctrler2->addrs[0].address,
  397. irqctrler2->intrs[0].line);
  398. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler2, 0, 0);
  399. prom_get_irq_senses(senses, 128, 128 + 124);
  400. /* We don't need to set MPIC_BROKEN_U3 here since we don't have
  401. * hypertransport interrupts routed to it
  402. */
  403. mpic2 = mpic_alloc(irqctrler2->addrs[0].address,
  404. MPIC_BIG_ENDIAN | MPIC_WANTS_RESET,
  405. 0, 128, 124, 0, senses, 124,
  406. " U3-MPIC ");
  407. BUG_ON(mpic2 == NULL);
  408. mpic_init(mpic2);
  409. mpic_setup_cascade(irqctrler2->intrs[0].line,
  410. pmac_u3_cascade, mpic2);
  411. }
  412. #if defined(CONFIG_XMON) && defined(CONFIG_PPC32)
  413. {
  414. struct device_node* pswitch;
  415. int nmi_irq;
  416. pswitch = find_devices("programmer-switch");
  417. if (pswitch && pswitch->n_intrs) {
  418. nmi_irq = pswitch->intrs[0].line;
  419. mpic_irq_set_priority(nmi_irq, 9);
  420. setup_irq(nmi_irq, &xmon_action);
  421. }
  422. }
  423. #endif /* CONFIG_XMON */
  424. return;
  425. }
  426. irqctrler = NULL;
  427. #ifdef CONFIG_PPC32
  428. /* Get the level/edge settings, assume if it's not
  429. * a Grand Central nor an OHare, then it's an Heathrow
  430. * (or Paddington).
  431. */
  432. if (find_devices("gc"))
  433. level_mask[0] = GC_LEVEL_MASK;
  434. else if (find_devices("ohare")) {
  435. level_mask[0] = OHARE_LEVEL_MASK;
  436. /* We might have a second cascaded ohare */
  437. level_mask[1] = OHARE_LEVEL_MASK;
  438. } else {
  439. level_mask[0] = HEATHROW_LEVEL_MASK;
  440. level_mask[1] = 0;
  441. /* We might have a second cascaded heathrow */
  442. level_mask[2] = HEATHROW_LEVEL_MASK;
  443. level_mask[3] = 0;
  444. }
  445. /*
  446. * G3 powermacs and 1999 G3 PowerBooks have 64 interrupts,
  447. * 1998 G3 Series PowerBooks have 128,
  448. * other powermacs have 32.
  449. * The combo ethernet/modem card for the Powerstar powerbooks
  450. * (2400/3400/3500, ohare based) has a second ohare chip
  451. * effectively making a total of 64.
  452. */
  453. max_irqs = max_real_irqs = 32;
  454. irqctrler = find_devices("mac-io");
  455. if (irqctrler)
  456. {
  457. max_real_irqs = 64;
  458. if (irqctrler->next)
  459. max_irqs = 128;
  460. else
  461. max_irqs = 64;
  462. }
  463. for ( i = 0; i < max_real_irqs ; i++ )
  464. irq_desc[i].handler = &pmac_pic;
  465. /* get addresses of first controller */
  466. if (irqctrler) {
  467. if (irqctrler->n_addrs > 0) {
  468. addr = (unsigned long)
  469. ioremap(irqctrler->addrs[0].address, 0x40);
  470. for (i = 0; i < 2; ++i)
  471. pmac_irq_hw[i] = (volatile struct pmac_irq_hw*)
  472. (addr + (2 - i) * 0x10);
  473. }
  474. /* get addresses of second controller */
  475. irqctrler = irqctrler->next;
  476. if (irqctrler && irqctrler->n_addrs > 0) {
  477. addr = (unsigned long)
  478. ioremap(irqctrler->addrs[0].address, 0x40);
  479. for (i = 2; i < 4; ++i)
  480. pmac_irq_hw[i] = (volatile struct pmac_irq_hw*)
  481. (addr + (4 - i) * 0x10);
  482. irq_cascade = irqctrler->intrs[0].line;
  483. if (device_is_compatible(irqctrler, "gatwick"))
  484. pmac_fix_gatwick_interrupts(irqctrler, max_real_irqs);
  485. }
  486. } else {
  487. /* older powermacs have a GC (grand central) or ohare at
  488. f3000000, with interrupt control registers at f3000020. */
  489. addr = (unsigned long) ioremap(0xf3000000, 0x40);
  490. pmac_irq_hw[0] = (volatile struct pmac_irq_hw *) (addr + 0x20);
  491. }
  492. /* PowerBooks 3400 and 3500 can have a second controller in a second
  493. ohare chip, on the combo ethernet/modem card */
  494. if (machine_is_compatible("AAPL,3400/2400")
  495. || machine_is_compatible("AAPL,3500"))
  496. irq_cascade = enable_second_ohare();
  497. /* disable all interrupts in all controllers */
  498. for (i = 0; i * 32 < max_irqs; ++i)
  499. out_le32(&pmac_irq_hw[i]->enable, 0);
  500. /* mark level interrupts */
  501. for (i = 0; i < max_irqs; i++)
  502. if (level_mask[i >> 5] & (1UL << (i & 0x1f)))
  503. irq_desc[i].status = IRQ_LEVEL;
  504. /* get interrupt line of secondary interrupt controller */
  505. if (irq_cascade >= 0) {
  506. printk(KERN_INFO "irq: secondary controller on irq %d\n",
  507. (int)irq_cascade);
  508. for ( i = max_real_irqs ; i < max_irqs ; i++ )
  509. irq_desc[i].handler = &gatwick_pic;
  510. setup_irq(irq_cascade, &gatwick_cascade_action);
  511. }
  512. printk("System has %d possible interrupts\n", max_irqs);
  513. if (max_irqs != max_real_irqs)
  514. printk(KERN_DEBUG "%d interrupts on main controller\n",
  515. max_real_irqs);
  516. #ifdef CONFIG_XMON
  517. setup_irq(20, &xmon_action);
  518. #endif /* CONFIG_XMON */
  519. #endif /* CONFIG_PPC32 */
  520. }
  521. #ifdef CONFIG_PM
  522. /*
  523. * These procedures are used in implementing sleep on the powerbooks.
  524. * sleep_save_intrs() saves the states of all interrupt enables
  525. * and disables all interrupts except for the nominated one.
  526. * sleep_restore_intrs() restores the states of all interrupt enables.
  527. */
  528. unsigned long sleep_save_mask[2];
  529. /* This used to be passed by the PMU driver but that link got
  530. * broken with the new driver model. We use this tweak for now...
  531. */
  532. static int pmacpic_find_viaint(void)
  533. {
  534. int viaint = -1;
  535. #ifdef CONFIG_ADB_PMU
  536. struct device_node *np;
  537. if (pmu_get_model() != PMU_OHARE_BASED)
  538. goto not_found;
  539. np = of_find_node_by_name(NULL, "via-pmu");
  540. if (np == NULL)
  541. goto not_found;
  542. viaint = np->intrs[0].line;
  543. #endif /* CONFIG_ADB_PMU */
  544. not_found:
  545. return viaint;
  546. }
  547. static int pmacpic_suspend(struct sys_device *sysdev, pm_message_t state)
  548. {
  549. int viaint = pmacpic_find_viaint();
  550. sleep_save_mask[0] = ppc_cached_irq_mask[0];
  551. sleep_save_mask[1] = ppc_cached_irq_mask[1];
  552. ppc_cached_irq_mask[0] = 0;
  553. ppc_cached_irq_mask[1] = 0;
  554. if (viaint > 0)
  555. set_bit(viaint, ppc_cached_irq_mask);
  556. out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]);
  557. if (max_real_irqs > 32)
  558. out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]);
  559. (void)in_le32(&pmac_irq_hw[0]->event);
  560. /* make sure mask gets to controller before we return to caller */
  561. mb();
  562. (void)in_le32(&pmac_irq_hw[0]->enable);
  563. return 0;
  564. }
  565. static int pmacpic_resume(struct sys_device *sysdev)
  566. {
  567. int i;
  568. out_le32(&pmac_irq_hw[0]->enable, 0);
  569. if (max_real_irqs > 32)
  570. out_le32(&pmac_irq_hw[1]->enable, 0);
  571. mb();
  572. for (i = 0; i < max_real_irqs; ++i)
  573. if (test_bit(i, sleep_save_mask))
  574. pmac_unmask_irq(i);
  575. return 0;
  576. }
  577. #endif /* CONFIG_PM */
  578. static struct sysdev_class pmacpic_sysclass = {
  579. set_kset_name("pmac_pic"),
  580. };
  581. static struct sys_device device_pmacpic = {
  582. .id = 0,
  583. .cls = &pmacpic_sysclass,
  584. };
  585. static struct sysdev_driver driver_pmacpic = {
  586. #ifdef CONFIG_PM
  587. .suspend = &pmacpic_suspend,
  588. .resume = &pmacpic_resume,
  589. #endif /* CONFIG_PM */
  590. };
  591. static int __init init_pmacpic_sysfs(void)
  592. {
  593. #ifdef CONFIG_PPC32
  594. if (max_irqs == 0)
  595. return -ENODEV;
  596. #endif
  597. printk(KERN_DEBUG "Registering pmac pic with sysfs...\n");
  598. sysdev_class_register(&pmacpic_sysclass);
  599. sysdev_register(&device_pmacpic);
  600. sysdev_driver_register(&pmacpic_sysclass, &driver_pmacpic);
  601. return 0;
  602. }
  603. subsys_initcall(init_pmacpic_sysfs);