pmac_pic.c 19 KB

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