pic.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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/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 *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_XMON
  339. static struct irqaction xmon_action = {
  340. .handler = xmon_irq,
  341. .flags = 0,
  342. .mask = CPU_MASK_NONE,
  343. .name = "NMI - XMON"
  344. };
  345. #endif
  346. static struct irqaction gatwick_cascade_action = {
  347. .handler = gatwick_action,
  348. .flags = SA_INTERRUPT,
  349. .mask = CPU_MASK_NONE,
  350. .name = "cascade",
  351. };
  352. #endif /* CONFIG_PPC32 */
  353. static int pmac_u3_cascade(struct pt_regs *regs, void *data)
  354. {
  355. return mpic_get_one_irq((struct mpic *)data, regs);
  356. }
  357. void __init pmac_pic_init(void)
  358. {
  359. struct device_node *irqctrler = NULL;
  360. struct device_node *irqctrler2 = NULL;
  361. struct device_node *np;
  362. #ifdef CONFIG_PPC32
  363. int i;
  364. unsigned long addr;
  365. int irq_cascade = -1;
  366. #endif
  367. struct mpic *mpic1, *mpic2;
  368. /* We first try to detect Apple's new Core99 chipset, since mac-io
  369. * is quite different on those machines and contains an IBM MPIC2.
  370. */
  371. np = find_type_devices("open-pic");
  372. while (np) {
  373. if (np->parent && !strcmp(np->parent->name, "u3"))
  374. irqctrler2 = np;
  375. else
  376. irqctrler = np;
  377. np = np->next;
  378. }
  379. if (irqctrler != NULL && irqctrler->n_addrs > 0) {
  380. unsigned char senses[128];
  381. printk(KERN_INFO "PowerMac using OpenPIC irq controller at 0x%08x\n",
  382. (unsigned int)irqctrler->addrs[0].address);
  383. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler, 0, 0);
  384. prom_get_irq_senses(senses, 0, 128);
  385. mpic1 = mpic_alloc(irqctrler->addrs[0].address,
  386. MPIC_PRIMARY | MPIC_WANTS_RESET,
  387. 0, 0, 128, 252, senses, 128, " OpenPIC ");
  388. BUG_ON(mpic1 == NULL);
  389. mpic_init(mpic1);
  390. if (irqctrler2 != NULL && irqctrler2->n_intrs > 0 &&
  391. irqctrler2->n_addrs > 0) {
  392. printk(KERN_INFO "Slave OpenPIC at 0x%08x hooked on IRQ %d\n",
  393. (u32)irqctrler2->addrs[0].address,
  394. irqctrler2->intrs[0].line);
  395. pmac_call_feature(PMAC_FTR_ENABLE_MPIC, irqctrler2, 0, 0);
  396. prom_get_irq_senses(senses, 128, 128 + 124);
  397. /* We don't need to set MPIC_BROKEN_U3 here since we don't have
  398. * hypertransport interrupts routed to it
  399. */
  400. mpic2 = mpic_alloc(irqctrler2->addrs[0].address,
  401. MPIC_BIG_ENDIAN | MPIC_WANTS_RESET,
  402. 0, 128, 124, 0, senses, 124,
  403. " U3-MPIC ");
  404. BUG_ON(mpic2 == NULL);
  405. mpic_init(mpic2);
  406. mpic_setup_cascade(irqctrler2->intrs[0].line,
  407. pmac_u3_cascade, mpic2);
  408. }
  409. #if defined(CONFIG_XMON) && defined(CONFIG_PPC32)
  410. {
  411. struct device_node* pswitch;
  412. int nmi_irq;
  413. pswitch = find_devices("programmer-switch");
  414. if (pswitch && pswitch->n_intrs) {
  415. nmi_irq = pswitch->intrs[0].line;
  416. mpic_irq_set_priority(nmi_irq, 9);
  417. setup_irq(nmi_irq, &xmon_action);
  418. }
  419. }
  420. #endif /* CONFIG_XMON */
  421. return;
  422. }
  423. irqctrler = NULL;
  424. #ifdef CONFIG_PPC32
  425. /* Get the level/edge settings, assume if it's not
  426. * a Grand Central nor an OHare, then it's an Heathrow
  427. * (or Paddington).
  428. */
  429. ppc_md.get_irq = pmac_get_irq;
  430. if (find_devices("gc"))
  431. level_mask[0] = GC_LEVEL_MASK;
  432. else if (find_devices("ohare")) {
  433. level_mask[0] = OHARE_LEVEL_MASK;
  434. /* We might have a second cascaded ohare */
  435. level_mask[1] = OHARE_LEVEL_MASK;
  436. } else {
  437. level_mask[0] = HEATHROW_LEVEL_MASK;
  438. level_mask[1] = 0;
  439. /* We might have a second cascaded heathrow */
  440. level_mask[2] = HEATHROW_LEVEL_MASK;
  441. level_mask[3] = 0;
  442. }
  443. /*
  444. * G3 powermacs and 1999 G3 PowerBooks have 64 interrupts,
  445. * 1998 G3 Series PowerBooks have 128,
  446. * other powermacs have 32.
  447. * The combo ethernet/modem card for the Powerstar powerbooks
  448. * (2400/3400/3500, ohare based) has a second ohare chip
  449. * effectively making a total of 64.
  450. */
  451. max_irqs = max_real_irqs = 32;
  452. irqctrler = find_devices("mac-io");
  453. if (irqctrler)
  454. {
  455. max_real_irqs = 64;
  456. if (irqctrler->next)
  457. max_irqs = 128;
  458. else
  459. max_irqs = 64;
  460. }
  461. for ( i = 0; i < max_real_irqs ; i++ )
  462. irq_desc[i].handler = &pmac_pic;
  463. /* get addresses of first controller */
  464. if (irqctrler) {
  465. if (irqctrler->n_addrs > 0) {
  466. addr = (unsigned long)
  467. ioremap(irqctrler->addrs[0].address, 0x40);
  468. for (i = 0; i < 2; ++i)
  469. pmac_irq_hw[i] = (volatile struct pmac_irq_hw*)
  470. (addr + (2 - i) * 0x10);
  471. }
  472. /* get addresses of second controller */
  473. irqctrler = irqctrler->next;
  474. if (irqctrler && irqctrler->n_addrs > 0) {
  475. addr = (unsigned long)
  476. ioremap(irqctrler->addrs[0].address, 0x40);
  477. for (i = 2; i < 4; ++i)
  478. pmac_irq_hw[i] = (volatile struct pmac_irq_hw*)
  479. (addr + (4 - i) * 0x10);
  480. irq_cascade = irqctrler->intrs[0].line;
  481. if (device_is_compatible(irqctrler, "gatwick"))
  482. pmac_fix_gatwick_interrupts(irqctrler, max_real_irqs);
  483. }
  484. } else {
  485. /* older powermacs have a GC (grand central) or ohare at
  486. f3000000, with interrupt control registers at f3000020. */
  487. addr = (unsigned long) ioremap(0xf3000000, 0x40);
  488. pmac_irq_hw[0] = (volatile struct pmac_irq_hw *) (addr + 0x20);
  489. }
  490. /* PowerBooks 3400 and 3500 can have a second controller in a second
  491. ohare chip, on the combo ethernet/modem card */
  492. if (machine_is_compatible("AAPL,3400/2400")
  493. || machine_is_compatible("AAPL,3500"))
  494. irq_cascade = enable_second_ohare();
  495. /* disable all interrupts in all controllers */
  496. for (i = 0; i * 32 < max_irqs; ++i)
  497. out_le32(&pmac_irq_hw[i]->enable, 0);
  498. /* mark level interrupts */
  499. for (i = 0; i < max_irqs; i++)
  500. if (level_mask[i >> 5] & (1UL << (i & 0x1f)))
  501. irq_desc[i].status = IRQ_LEVEL;
  502. /* get interrupt line of secondary interrupt controller */
  503. if (irq_cascade >= 0) {
  504. printk(KERN_INFO "irq: secondary controller on irq %d\n",
  505. (int)irq_cascade);
  506. for ( i = max_real_irqs ; i < max_irqs ; i++ )
  507. irq_desc[i].handler = &gatwick_pic;
  508. setup_irq(irq_cascade, &gatwick_cascade_action);
  509. }
  510. printk("System has %d possible interrupts\n", max_irqs);
  511. if (max_irqs != max_real_irqs)
  512. printk(KERN_DEBUG "%d interrupts on main controller\n",
  513. max_real_irqs);
  514. #ifdef CONFIG_XMON
  515. setup_irq(20, &xmon_action);
  516. #endif /* CONFIG_XMON */
  517. #endif /* CONFIG_PPC32 */
  518. }
  519. #if defined(CONFIG_PM) && defined(CONFIG_PPC32)
  520. /*
  521. * These procedures are used in implementing sleep on the powerbooks.
  522. * sleep_save_intrs() saves the states of all interrupt enables
  523. * and disables all interrupts except for the nominated one.
  524. * sleep_restore_intrs() restores the states of all interrupt enables.
  525. */
  526. unsigned long sleep_save_mask[2];
  527. /* This used to be passed by the PMU driver but that link got
  528. * broken with the new driver model. We use this tweak for now...
  529. */
  530. static int pmacpic_find_viaint(void)
  531. {
  532. int viaint = -1;
  533. #ifdef CONFIG_ADB_PMU
  534. struct device_node *np;
  535. if (pmu_get_model() != PMU_OHARE_BASED)
  536. goto not_found;
  537. np = of_find_node_by_name(NULL, "via-pmu");
  538. if (np == NULL)
  539. goto not_found;
  540. viaint = np->intrs[0].line;
  541. #endif /* CONFIG_ADB_PMU */
  542. not_found:
  543. return viaint;
  544. }
  545. static int pmacpic_suspend(struct sys_device *sysdev, pm_message_t state)
  546. {
  547. int viaint = pmacpic_find_viaint();
  548. sleep_save_mask[0] = ppc_cached_irq_mask[0];
  549. sleep_save_mask[1] = ppc_cached_irq_mask[1];
  550. ppc_cached_irq_mask[0] = 0;
  551. ppc_cached_irq_mask[1] = 0;
  552. if (viaint > 0)
  553. set_bit(viaint, ppc_cached_irq_mask);
  554. out_le32(&pmac_irq_hw[0]->enable, ppc_cached_irq_mask[0]);
  555. if (max_real_irqs > 32)
  556. out_le32(&pmac_irq_hw[1]->enable, ppc_cached_irq_mask[1]);
  557. (void)in_le32(&pmac_irq_hw[0]->event);
  558. /* make sure mask gets to controller before we return to caller */
  559. mb();
  560. (void)in_le32(&pmac_irq_hw[0]->enable);
  561. return 0;
  562. }
  563. static int pmacpic_resume(struct sys_device *sysdev)
  564. {
  565. int i;
  566. out_le32(&pmac_irq_hw[0]->enable, 0);
  567. if (max_real_irqs > 32)
  568. out_le32(&pmac_irq_hw[1]->enable, 0);
  569. mb();
  570. for (i = 0; i < max_real_irqs; ++i)
  571. if (test_bit(i, sleep_save_mask))
  572. pmac_unmask_irq(i);
  573. return 0;
  574. }
  575. #endif /* CONFIG_PM && CONFIG_PPC32 */
  576. static struct sysdev_class pmacpic_sysclass = {
  577. set_kset_name("pmac_pic"),
  578. };
  579. static struct sys_device device_pmacpic = {
  580. .id = 0,
  581. .cls = &pmacpic_sysclass,
  582. };
  583. static struct sysdev_driver driver_pmacpic = {
  584. #if defined(CONFIG_PM) && defined(CONFIG_PPC32)
  585. .suspend = &pmacpic_suspend,
  586. .resume = &pmacpic_resume,
  587. #endif /* CONFIG_PM && CONFIG_PPC32 */
  588. };
  589. static int __init init_pmacpic_sysfs(void)
  590. {
  591. #ifdef CONFIG_PPC32
  592. if (max_irqs == 0)
  593. return -ENODEV;
  594. #endif
  595. printk(KERN_DEBUG "Registering pmac pic with sysfs...\n");
  596. sysdev_class_register(&pmacpic_sysclass);
  597. sysdev_register(&device_pmacpic);
  598. sysdev_driver_register(&pmacpic_sysclass, &driver_pmacpic);
  599. return 0;
  600. }
  601. subsys_initcall(init_pmacpic_sysfs);