pmac_pic.c 19 KB

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