pmac_pic.c 19 KB

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