open_pic2.c 19 KB

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