open_pic2.c 19 KB

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