open_pic2.c 19 KB

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