pic.c 19 KB

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