open_pic2.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * arch/ppc/kernel/open_pic.c -- OpenPIC Interrupt Handling
  3. *
  4. * Copyright (C) 1997 Geert Uytterhoeven
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file COPYING in the main directory of this archive
  8. * for more details.
  9. *
  10. * This is a duplicate of open_pic.c that deals with U3s MPIC on
  11. * G5 PowerMacs. It's the same file except it's using big endian
  12. * register accesses
  13. */
  14. #include <linux/config.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/sched.h>
  18. #include <linux/init.h>
  19. #include <linux/irq.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/sysdev.h>
  22. #include <linux/errno.h>
  23. #include <asm/ptrace.h>
  24. #include <asm/signal.h>
  25. #include <asm/io.h>
  26. #include <asm/irq.h>
  27. #include <asm/prom.h>
  28. #include <asm/sections.h>
  29. #include <asm/open_pic.h>
  30. #include <asm/i8259.h>
  31. #include "open_pic_defs.h"
  32. void *OpenPIC2_Addr;
  33. static volatile struct OpenPIC *OpenPIC2 = NULL;
  34. /*
  35. * We define OpenPIC_InitSenses table thusly:
  36. * bit 0x1: sense, 0 for edge and 1 for level.
  37. * bit 0x2: polarity, 0 for negative, 1 for positive.
  38. */
  39. extern u_int OpenPIC_NumInitSenses;
  40. extern u_char *OpenPIC_InitSenses;
  41. extern int use_of_interrupt_tree;
  42. static u_int NumProcessors;
  43. static u_int NumSources;
  44. static int open_pic2_irq_offset;
  45. static volatile OpenPIC_Source *ISR[NR_IRQS];
  46. /* Global Operations */
  47. static void openpic2_disable_8259_pass_through(void);
  48. static void openpic2_set_priority(u_int pri);
  49. static void openpic2_set_spurious(u_int vector);
  50. /* Timer Interrupts */
  51. static void openpic2_inittimer(u_int timer, u_int pri, u_int vector);
  52. static void openpic2_maptimer(u_int timer, u_int cpumask);
  53. /* Interrupt Sources */
  54. static void openpic2_enable_irq(u_int irq);
  55. static void openpic2_disable_irq(u_int irq);
  56. static void openpic2_initirq(u_int irq, u_int pri, u_int vector, int polarity,
  57. int is_level);
  58. static void openpic2_mapirq(u_int irq, u_int cpumask, u_int keepmask);
  59. /*
  60. * These functions are not used but the code is kept here
  61. * for completeness and future reference.
  62. */
  63. static void openpic2_reset(void);
  64. #ifdef notused
  65. static void openpic2_enable_8259_pass_through(void);
  66. static u_int openpic2_get_priority(void);
  67. static u_int openpic2_get_spurious(void);
  68. static void openpic2_set_sense(u_int irq, int sense);
  69. #endif /* notused */
  70. /*
  71. * Description of the openpic for the higher-level irq code
  72. */
  73. static void openpic2_end_irq(unsigned int irq_nr);
  74. static void openpic2_ack_irq(unsigned int irq_nr);
  75. struct hw_interrupt_type open_pic2 = {
  76. " OpenPIC2 ",
  77. NULL,
  78. NULL,
  79. openpic2_enable_irq,
  80. openpic2_disable_irq,
  81. openpic2_ack_irq,
  82. openpic2_end_irq,
  83. };
  84. /*
  85. * Accesses to the current processor's openpic registers
  86. * On cascaded controller, this is only CPU 0
  87. */
  88. #define THIS_CPU Processor[0]
  89. #define DECL_THIS_CPU
  90. #define CHECK_THIS_CPU
  91. #if 1
  92. #define check_arg_ipi(ipi) \
  93. if (ipi < 0 || ipi >= OPENPIC_NUM_IPI) \
  94. printk("open_pic.c:%d: illegal ipi %d\n", __LINE__, ipi);
  95. #define check_arg_timer(timer) \
  96. if (timer < 0 || timer >= OPENPIC_NUM_TIMERS) \
  97. printk("open_pic.c:%d: illegal timer %d\n", __LINE__, timer);
  98. #define check_arg_vec(vec) \
  99. if (vec < 0 || vec >= OPENPIC_NUM_VECTORS) \
  100. printk("open_pic.c:%d: illegal vector %d\n", __LINE__, vec);
  101. #define check_arg_pri(pri) \
  102. if (pri < 0 || pri >= OPENPIC_NUM_PRI) \
  103. printk("open_pic.c:%d: illegal priority %d\n", __LINE__, pri);
  104. /*
  105. * Print out a backtrace if it's out of range, since if it's larger than NR_IRQ's
  106. * data has probably been corrupted and we're going to panic or deadlock later
  107. * anyway --Troy
  108. */
  109. extern unsigned long* _get_SP(void);
  110. #define check_arg_irq(irq) \
  111. if (irq < open_pic2_irq_offset || irq >= NumSources+open_pic2_irq_offset \
  112. || ISR[irq - open_pic2_irq_offset] == 0) { \
  113. printk("open_pic.c:%d: illegal irq %d\n", __LINE__, irq); \
  114. /*print_backtrace(_get_SP());*/ }
  115. #define check_arg_cpu(cpu) \
  116. if (cpu < 0 || cpu >= NumProcessors){ \
  117. printk("open_pic2.c:%d: illegal cpu %d\n", __LINE__, cpu); \
  118. /*print_backtrace(_get_SP());*/ }
  119. #else
  120. #define check_arg_ipi(ipi) do {} while (0)
  121. #define check_arg_timer(timer) do {} while (0)
  122. #define check_arg_vec(vec) do {} while (0)
  123. #define check_arg_pri(pri) do {} while (0)
  124. #define check_arg_irq(irq) do {} while (0)
  125. #define check_arg_cpu(cpu) do {} while (0)
  126. #endif
  127. static u_int openpic2_read(volatile u_int *addr)
  128. {
  129. u_int val;
  130. val = in_be32(addr);
  131. return val;
  132. }
  133. static inline void openpic2_write(volatile u_int *addr, u_int val)
  134. {
  135. out_be32(addr, val);
  136. }
  137. static inline u_int openpic2_readfield(volatile u_int *addr, u_int mask)
  138. {
  139. u_int val = openpic2_read(addr);
  140. return val & mask;
  141. }
  142. inline void openpic2_writefield(volatile u_int *addr, u_int mask,
  143. u_int field)
  144. {
  145. u_int val = openpic2_read(addr);
  146. openpic2_write(addr, (val & ~mask) | (field & mask));
  147. }
  148. static inline void openpic2_clearfield(volatile u_int *addr, u_int mask)
  149. {
  150. openpic2_writefield(addr, mask, 0);
  151. }
  152. static inline void openpic2_setfield(volatile u_int *addr, u_int mask)
  153. {
  154. openpic2_writefield(addr, mask, mask);
  155. }
  156. static void openpic2_safe_writefield(volatile u_int *addr, u_int mask,
  157. u_int field)
  158. {
  159. openpic2_setfield(addr, OPENPIC_MASK);
  160. while (openpic2_read(addr) & OPENPIC_ACTIVITY);
  161. openpic2_writefield(addr, mask | OPENPIC_MASK, field | OPENPIC_MASK);
  162. }
  163. static void openpic2_reset(void)
  164. {
  165. openpic2_setfield(&OpenPIC2->Global.Global_Configuration0,
  166. OPENPIC_CONFIG_RESET);
  167. while (openpic2_readfield(&OpenPIC2->Global.Global_Configuration0,
  168. OPENPIC_CONFIG_RESET))
  169. mb();
  170. }
  171. void __init openpic2_set_sources(int first_irq, int num_irqs, void *first_ISR)
  172. {
  173. volatile OpenPIC_Source *src = first_ISR;
  174. int i, last_irq;
  175. last_irq = first_irq + num_irqs;
  176. if (last_irq > NumSources)
  177. NumSources = last_irq;
  178. if (src == 0)
  179. src = &((struct OpenPIC *)OpenPIC2_Addr)->Source[first_irq];
  180. for (i = first_irq; i < last_irq; ++i, ++src)
  181. ISR[i] = src;
  182. }
  183. /*
  184. * The `offset' parameter defines where the interrupts handled by the
  185. * OpenPIC start in the space of interrupt numbers that the kernel knows
  186. * about. In other words, the OpenPIC's IRQ0 is numbered `offset' in the
  187. * kernel's interrupt numbering scheme.
  188. * We assume there is only one OpenPIC.
  189. */
  190. void __init openpic2_init(int offset)
  191. {
  192. u_int t, i;
  193. u_int timerfreq;
  194. const char *version;
  195. if (!OpenPIC2_Addr) {
  196. printk("No OpenPIC2 found !\n");
  197. return;
  198. }
  199. OpenPIC2 = (volatile struct OpenPIC *)OpenPIC2_Addr;
  200. if (ppc_md.progress) ppc_md.progress("openpic: enter", 0x122);
  201. t = openpic2_read(&OpenPIC2->Global.Feature_Reporting0);
  202. switch (t & OPENPIC_FEATURE_VERSION_MASK) {
  203. case 1:
  204. version = "1.0";
  205. break;
  206. case 2:
  207. version = "1.2";
  208. break;
  209. case 3:
  210. version = "1.3";
  211. break;
  212. default:
  213. version = "?";
  214. break;
  215. }
  216. NumProcessors = ((t & OPENPIC_FEATURE_LAST_PROCESSOR_MASK) >>
  217. OPENPIC_FEATURE_LAST_PROCESSOR_SHIFT) + 1;
  218. if (NumSources == 0)
  219. openpic2_set_sources(0,
  220. ((t & OPENPIC_FEATURE_LAST_SOURCE_MASK) >>
  221. OPENPIC_FEATURE_LAST_SOURCE_SHIFT) + 1,
  222. NULL);
  223. printk("OpenPIC (2) Version %s (%d CPUs and %d IRQ sources) at %p\n",
  224. version, NumProcessors, NumSources, OpenPIC2);
  225. timerfreq = openpic2_read(&OpenPIC2->Global.Timer_Frequency);
  226. if (timerfreq)
  227. printk("OpenPIC timer frequency is %d.%06d MHz\n",
  228. timerfreq / 1000000, timerfreq % 1000000);
  229. open_pic2_irq_offset = offset;
  230. /* Initialize timer interrupts */
  231. if ( ppc_md.progress ) ppc_md.progress("openpic2: timer",0x3ba);
  232. for (i = 0; i < OPENPIC_NUM_TIMERS; i++) {
  233. /* Disabled, Priority 0 */
  234. openpic2_inittimer(i, 0, OPENPIC2_VEC_TIMER+i+offset);
  235. /* No processor */
  236. openpic2_maptimer(i, 0);
  237. }
  238. /* Initialize external interrupts */
  239. if (ppc_md.progress) ppc_md.progress("openpic2: external",0x3bc);
  240. openpic2_set_priority(0xf);
  241. /* Init all external sources, including possibly the cascade. */
  242. for (i = 0; i < NumSources; i++) {
  243. int sense;
  244. if (ISR[i] == 0)
  245. continue;
  246. /* the bootloader may have left it enabled (bad !) */
  247. openpic2_disable_irq(i+offset);
  248. sense = (i < OpenPIC_NumInitSenses)? OpenPIC_InitSenses[i]: \
  249. (IRQ_SENSE_LEVEL | IRQ_POLARITY_NEGATIVE);
  250. if (sense & IRQ_SENSE_MASK)
  251. irq_desc[i+offset].status = IRQ_LEVEL;
  252. /* Enabled, Priority 8 */
  253. openpic2_initirq(i, 8, i+offset, (sense & IRQ_POLARITY_MASK),
  254. (sense & IRQ_SENSE_MASK));
  255. /* Processor 0 */
  256. openpic2_mapirq(i, 1<<0, 0);
  257. }
  258. /* Init descriptors */
  259. for (i = offset; i < NumSources + offset; i++)
  260. irq_desc[i].handler = &open_pic2;
  261. /* Initialize the spurious interrupt */
  262. if (ppc_md.progress) ppc_md.progress("openpic2: spurious",0x3bd);
  263. openpic2_set_spurious(OPENPIC2_VEC_SPURIOUS+offset);
  264. openpic2_disable_8259_pass_through();
  265. openpic2_set_priority(0);
  266. if (ppc_md.progress) ppc_md.progress("openpic2: exit",0x222);
  267. }
  268. #ifdef notused
  269. static void openpic2_enable_8259_pass_through(void)
  270. {
  271. openpic2_clearfield(&OpenPIC2->Global.Global_Configuration0,
  272. OPENPIC_CONFIG_8259_PASSTHROUGH_DISABLE);
  273. }
  274. #endif /* notused */
  275. /* This can't be __init, it is used in openpic_sleep_restore_intrs */
  276. static void openpic2_disable_8259_pass_through(void)
  277. {
  278. openpic2_setfield(&OpenPIC2->Global.Global_Configuration0,
  279. OPENPIC_CONFIG_8259_PASSTHROUGH_DISABLE);
  280. }
  281. /*
  282. * Find out the current interrupt
  283. */
  284. u_int openpic2_irq(void)
  285. {
  286. u_int vec;
  287. DECL_THIS_CPU;
  288. CHECK_THIS_CPU;
  289. vec = openpic2_readfield(&OpenPIC2->THIS_CPU.Interrupt_Acknowledge,
  290. OPENPIC_VECTOR_MASK);
  291. return vec;
  292. }
  293. void openpic2_eoi(void)
  294. {
  295. DECL_THIS_CPU;
  296. CHECK_THIS_CPU;
  297. openpic2_write(&OpenPIC2->THIS_CPU.EOI, 0);
  298. /* Handle PCI write posting */
  299. (void)openpic2_read(&OpenPIC2->THIS_CPU.EOI);
  300. }
  301. #ifdef notused
  302. static u_int openpic2_get_priority(void)
  303. {
  304. DECL_THIS_CPU;
  305. CHECK_THIS_CPU;
  306. return openpic2_readfield(&OpenPIC2->THIS_CPU.Current_Task_Priority,
  307. OPENPIC_CURRENT_TASK_PRIORITY_MASK);
  308. }
  309. #endif /* notused */
  310. static void __init openpic2_set_priority(u_int pri)
  311. {
  312. DECL_THIS_CPU;
  313. CHECK_THIS_CPU;
  314. check_arg_pri(pri);
  315. openpic2_writefield(&OpenPIC2->THIS_CPU.Current_Task_Priority,
  316. OPENPIC_CURRENT_TASK_PRIORITY_MASK, pri);
  317. }
  318. /*
  319. * Get/set the spurious vector
  320. */
  321. #ifdef notused
  322. static u_int openpic2_get_spurious(void)
  323. {
  324. return openpic2_readfield(&OpenPIC2->Global.Spurious_Vector,
  325. OPENPIC_VECTOR_MASK);
  326. }
  327. #endif /* notused */
  328. /* This can't be __init, it is used in openpic_sleep_restore_intrs */
  329. static void openpic2_set_spurious(u_int vec)
  330. {
  331. check_arg_vec(vec);
  332. openpic2_writefield(&OpenPIC2->Global.Spurious_Vector, OPENPIC_VECTOR_MASK,
  333. vec);
  334. }
  335. static DEFINE_SPINLOCK(openpic2_setup_lock);
  336. /*
  337. * Initialize a timer interrupt (and disable it)
  338. *
  339. * timer: OpenPIC timer number
  340. * pri: interrupt source priority
  341. * vec: the vector it will produce
  342. */
  343. static void __init openpic2_inittimer(u_int timer, u_int pri, u_int vec)
  344. {
  345. check_arg_timer(timer);
  346. check_arg_pri(pri);
  347. check_arg_vec(vec);
  348. openpic2_safe_writefield(&OpenPIC2->Global.Timer[timer].Vector_Priority,
  349. OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK,
  350. (pri << OPENPIC_PRIORITY_SHIFT) | vec);
  351. }
  352. /*
  353. * Map a timer interrupt to one or more CPUs
  354. */
  355. static void __init openpic2_maptimer(u_int timer, u_int cpumask)
  356. {
  357. check_arg_timer(timer);
  358. openpic2_write(&OpenPIC2->Global.Timer[timer].Destination,
  359. cpumask);
  360. }
  361. /*
  362. * Initalize the interrupt source which will generate an NMI.
  363. * This raises the interrupt's priority from 8 to 9.
  364. *
  365. * irq: The logical IRQ which generates an NMI.
  366. */
  367. void __init
  368. openpic2_init_nmi_irq(u_int irq)
  369. {
  370. check_arg_irq(irq);
  371. openpic2_safe_writefield(&ISR[irq - open_pic2_irq_offset]->Vector_Priority,
  372. OPENPIC_PRIORITY_MASK,
  373. 9 << OPENPIC_PRIORITY_SHIFT);
  374. }
  375. /*
  376. *
  377. * All functions below take an offset'ed irq argument
  378. *
  379. */
  380. /*
  381. * Enable/disable an external interrupt source
  382. *
  383. * Externally called, irq is an offseted system-wide interrupt number
  384. */
  385. static void openpic2_enable_irq(u_int irq)
  386. {
  387. volatile u_int *vpp;
  388. check_arg_irq(irq);
  389. vpp = &ISR[irq - open_pic2_irq_offset]->Vector_Priority;
  390. openpic2_clearfield(vpp, OPENPIC_MASK);
  391. /* make sure mask gets to controller before we return to user */
  392. do {
  393. mb(); /* sync is probably useless here */
  394. } while (openpic2_readfield(vpp, OPENPIC_MASK));
  395. }
  396. static void openpic2_disable_irq(u_int irq)
  397. {
  398. volatile u_int *vpp;
  399. u32 vp;
  400. check_arg_irq(irq);
  401. vpp = &ISR[irq - open_pic2_irq_offset]->Vector_Priority;
  402. openpic2_setfield(vpp, OPENPIC_MASK);
  403. /* make sure mask gets to controller before we return to user */
  404. do {
  405. mb(); /* sync is probably useless here */
  406. vp = openpic2_readfield(vpp, OPENPIC_MASK | OPENPIC_ACTIVITY);
  407. } while((vp & OPENPIC_ACTIVITY) && !(vp & OPENPIC_MASK));
  408. }
  409. /*
  410. * Initialize an interrupt source (and disable it!)
  411. *
  412. * irq: OpenPIC interrupt number
  413. * pri: interrupt source priority
  414. * vec: the vector it will produce
  415. * pol: polarity (1 for positive, 0 for negative)
  416. * sense: 1 for level, 0 for edge
  417. */
  418. static void __init
  419. openpic2_initirq(u_int irq, u_int pri, u_int vec, int pol, int sense)
  420. {
  421. openpic2_safe_writefield(&ISR[irq]->Vector_Priority,
  422. OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK |
  423. OPENPIC_SENSE_MASK | OPENPIC_POLARITY_MASK,
  424. (pri << OPENPIC_PRIORITY_SHIFT) | vec |
  425. (pol ? OPENPIC_POLARITY_POSITIVE :
  426. OPENPIC_POLARITY_NEGATIVE) |
  427. (sense ? OPENPIC_SENSE_LEVEL : OPENPIC_SENSE_EDGE));
  428. }
  429. /*
  430. * Map an interrupt source to one or more CPUs
  431. */
  432. static void openpic2_mapirq(u_int irq, u_int physmask, u_int keepmask)
  433. {
  434. if (ISR[irq] == 0)
  435. return;
  436. if (keepmask != 0)
  437. physmask |= openpic2_read(&ISR[irq]->Destination) & keepmask;
  438. openpic2_write(&ISR[irq]->Destination, physmask);
  439. }
  440. #ifdef notused
  441. /*
  442. * Set the sense for an interrupt source (and disable it!)
  443. *
  444. * sense: 1 for level, 0 for edge
  445. */
  446. static void openpic2_set_sense(u_int irq, int sense)
  447. {
  448. if (ISR[irq] != 0)
  449. openpic2_safe_writefield(&ISR[irq]->Vector_Priority,
  450. OPENPIC_SENSE_LEVEL,
  451. (sense ? OPENPIC_SENSE_LEVEL : 0));
  452. }
  453. #endif /* notused */
  454. /* No spinlocks, should not be necessary with the OpenPIC
  455. * (1 register = 1 interrupt and we have the desc lock).
  456. */
  457. static void openpic2_ack_irq(unsigned int irq_nr)
  458. {
  459. openpic2_disable_irq(irq_nr);
  460. openpic2_eoi();
  461. }
  462. static void openpic2_end_irq(unsigned int irq_nr)
  463. {
  464. if (!(irq_desc[irq_nr].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
  465. openpic2_enable_irq(irq_nr);
  466. }
  467. int
  468. openpic2_get_irq(struct pt_regs *regs)
  469. {
  470. int irq = openpic2_irq();
  471. if (irq == (OPENPIC2_VEC_SPURIOUS + open_pic2_irq_offset))
  472. irq = -1;
  473. return irq;
  474. }
  475. #ifdef CONFIG_PM
  476. /*
  477. * We implement the IRQ controller as a sysdev and put it
  478. * to sleep at powerdown stage (the callback is named suspend,
  479. * but it's old semantics, for the Device Model, it's really
  480. * powerdown). The possible problem is that another sysdev that
  481. * happens to be suspend after this one will have interrupts off,
  482. * that may be an issue... For now, this isn't an issue on pmac
  483. * though...
  484. */
  485. static u32 save_ipi_vp[OPENPIC_NUM_IPI];
  486. static u32 save_irq_src_vp[OPENPIC_MAX_SOURCES];
  487. static u32 save_irq_src_dest[OPENPIC_MAX_SOURCES];
  488. static u32 save_cpu_task_pri[OPENPIC_MAX_PROCESSORS];
  489. static int openpic_suspend_count;
  490. static void openpic2_cached_enable_irq(u_int irq)
  491. {
  492. check_arg_irq(irq);
  493. save_irq_src_vp[irq - open_pic2_irq_offset] &= ~OPENPIC_MASK;
  494. }
  495. static void openpic2_cached_disable_irq(u_int irq)
  496. {
  497. check_arg_irq(irq);
  498. save_irq_src_vp[irq - open_pic2_irq_offset] |= OPENPIC_MASK;
  499. }
  500. /* WARNING: Can be called directly by the cpufreq code with NULL parameter,
  501. * we need something better to deal with that... Maybe switch to S1 for
  502. * cpufreq changes
  503. */
  504. int openpic2_suspend(struct sys_device *sysdev, u32 state)
  505. {
  506. int i;
  507. unsigned long flags;
  508. spin_lock_irqsave(&openpic2_setup_lock, flags);
  509. if (openpic_suspend_count++ > 0) {
  510. spin_unlock_irqrestore(&openpic2_setup_lock, flags);
  511. return 0;
  512. }
  513. open_pic2.enable = openpic2_cached_enable_irq;
  514. open_pic2.disable = openpic2_cached_disable_irq;
  515. for (i=0; i<NumProcessors; i++) {
  516. save_cpu_task_pri[i] = openpic2_read(&OpenPIC2->Processor[i].Current_Task_Priority);
  517. openpic2_writefield(&OpenPIC2->Processor[i].Current_Task_Priority,
  518. OPENPIC_CURRENT_TASK_PRIORITY_MASK, 0xf);
  519. }
  520. for (i=0; i<OPENPIC_NUM_IPI; i++)
  521. save_ipi_vp[i] = openpic2_read(&OpenPIC2->Global.IPI_Vector_Priority(i));
  522. for (i=0; i<NumSources; i++) {
  523. if (ISR[i] == 0)
  524. continue;
  525. save_irq_src_vp[i] = openpic2_read(&ISR[i]->Vector_Priority) & ~OPENPIC_ACTIVITY;
  526. save_irq_src_dest[i] = openpic2_read(&ISR[i]->Destination);
  527. }
  528. spin_unlock_irqrestore(&openpic2_setup_lock, flags);
  529. return 0;
  530. }
  531. /* WARNING: Can be called directly by the cpufreq code with NULL parameter,
  532. * we need something better to deal with that... Maybe switch to S1 for
  533. * cpufreq changes
  534. */
  535. int openpic2_resume(struct sys_device *sysdev)
  536. {
  537. int i;
  538. unsigned long flags;
  539. u32 vppmask = OPENPIC_PRIORITY_MASK | OPENPIC_VECTOR_MASK |
  540. OPENPIC_SENSE_MASK | OPENPIC_POLARITY_MASK |
  541. OPENPIC_MASK;
  542. spin_lock_irqsave(&openpic2_setup_lock, flags);
  543. if ((--openpic_suspend_count) > 0) {
  544. spin_unlock_irqrestore(&openpic2_setup_lock, flags);
  545. return 0;
  546. }
  547. openpic2_reset();
  548. /* OpenPIC sometimes seem to need some time to be fully back up... */
  549. do {
  550. openpic2_set_spurious(OPENPIC2_VEC_SPURIOUS+open_pic2_irq_offset);
  551. } while(openpic2_readfield(&OpenPIC2->Global.Spurious_Vector, OPENPIC_VECTOR_MASK)
  552. != (OPENPIC2_VEC_SPURIOUS + open_pic2_irq_offset));
  553. openpic2_disable_8259_pass_through();
  554. for (i=0; i<OPENPIC_NUM_IPI; i++)
  555. openpic2_write(&OpenPIC2->Global.IPI_Vector_Priority(i),
  556. save_ipi_vp[i]);
  557. for (i=0; i<NumSources; i++) {
  558. if (ISR[i] == 0)
  559. continue;
  560. openpic2_write(&ISR[i]->Destination, save_irq_src_dest[i]);
  561. openpic2_write(&ISR[i]->Vector_Priority, save_irq_src_vp[i]);
  562. /* make sure mask gets to controller before we return to user */
  563. do {
  564. openpic2_write(&ISR[i]->Vector_Priority, save_irq_src_vp[i]);
  565. } while (openpic2_readfield(&ISR[i]->Vector_Priority, vppmask)
  566. != (save_irq_src_vp[i] & vppmask));
  567. }
  568. for (i=0; i<NumProcessors; i++)
  569. openpic2_write(&OpenPIC2->Processor[i].Current_Task_Priority,
  570. save_cpu_task_pri[i]);
  571. open_pic2.enable = openpic2_enable_irq;
  572. open_pic2.disable = openpic2_disable_irq;
  573. spin_unlock_irqrestore(&openpic2_setup_lock, flags);
  574. return 0;
  575. }
  576. #endif /* CONFIG_PM */
  577. /* HACK ALERT */
  578. static struct sysdev_class openpic2_sysclass = {
  579. set_kset_name("openpic2"),
  580. };
  581. static struct sys_device device_openpic2 = {
  582. .id = 0,
  583. .cls = &openpic2_sysclass,
  584. };
  585. static struct sysdev_driver driver_openpic2 = {
  586. #ifdef CONFIG_PM
  587. .suspend = &openpic2_suspend,
  588. .resume = &openpic2_resume,
  589. #endif /* CONFIG_PM */
  590. };
  591. static int __init init_openpic2_sysfs(void)
  592. {
  593. int rc;
  594. if (!OpenPIC2_Addr)
  595. return -ENODEV;
  596. printk(KERN_DEBUG "Registering openpic2 with sysfs...\n");
  597. rc = sysdev_class_register(&openpic2_sysclass);
  598. if (rc) {
  599. printk(KERN_ERR "Failed registering openpic sys class\n");
  600. return -ENODEV;
  601. }
  602. rc = sysdev_register(&device_openpic2);
  603. if (rc) {
  604. printk(KERN_ERR "Failed registering openpic sys device\n");
  605. return -ENODEV;
  606. }
  607. rc = sysdev_driver_register(&openpic2_sysclass, &driver_openpic2);
  608. if (rc) {
  609. printk(KERN_ERR "Failed registering openpic sys driver\n");
  610. return -ENODEV;
  611. }
  612. return 0;
  613. }
  614. subsys_initcall(init_openpic2_sysfs);