ppc4xx_pic.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * arch/ppc/syslib/ppc4xx_pic.c
  3. *
  4. * Interrupt controller driver for PowerPC 4xx-based processors.
  5. *
  6. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  7. * Copyright (c) 2004, 2005 Zultys Technologies
  8. *
  9. * Based on original code by
  10. * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
  11. * Armin Custer <akuster@mvista.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/config.h>
  19. #include <linux/init.h>
  20. #include <linux/sched.h>
  21. #include <linux/signal.h>
  22. #include <linux/stddef.h>
  23. #include <asm/processor.h>
  24. #include <asm/system.h>
  25. #include <asm/irq.h>
  26. #include <asm/ppc4xx_pic.h>
  27. /* See comment in include/arch-ppc/ppc4xx_pic.h
  28. * for more info about these two variables
  29. */
  30. extern struct ppc4xx_uic_settings ppc4xx_core_uic_cfg[NR_UICS]
  31. __attribute__ ((weak));
  32. extern unsigned char ppc4xx_uic_ext_irq_cfg[] __attribute__ ((weak));
  33. #define IRQ_MASK_UIC0(irq) (1 << (31 - (irq)))
  34. #define IRQ_MASK_UICx(irq) (1 << (31 - ((irq) & 0x1f)))
  35. #define IRQ_MASK_UIC1(irq) IRQ_MASK_UICx(irq)
  36. #define IRQ_MASK_UIC2(irq) IRQ_MASK_UICx(irq)
  37. #define UIC_HANDLERS(n) \
  38. static void ppc4xx_uic##n##_enable(unsigned int irq) \
  39. { \
  40. u32 mask = IRQ_MASK_UIC##n(irq); \
  41. if (irq_desc[irq].status & IRQ_LEVEL) \
  42. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  43. ppc_cached_irq_mask[n] |= mask; \
  44. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  45. } \
  46. \
  47. static void ppc4xx_uic##n##_disable(unsigned int irq) \
  48. { \
  49. ppc_cached_irq_mask[n] &= ~IRQ_MASK_UIC##n(irq); \
  50. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  51. ACK_UIC##n##_PARENT \
  52. } \
  53. \
  54. static void ppc4xx_uic##n##_ack(unsigned int irq) \
  55. { \
  56. u32 mask = IRQ_MASK_UIC##n(irq); \
  57. ppc_cached_irq_mask[n] &= ~mask; \
  58. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  59. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  60. ACK_UIC##n##_PARENT \
  61. } \
  62. \
  63. static void ppc4xx_uic##n##_end(unsigned int irq) \
  64. { \
  65. unsigned int status = irq_desc[irq].status; \
  66. u32 mask = IRQ_MASK_UIC##n(irq); \
  67. if (status & IRQ_LEVEL) { \
  68. mtdcr(DCRN_UIC_SR(UIC##n), mask); \
  69. ACK_UIC##n##_PARENT \
  70. } \
  71. if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) { \
  72. ppc_cached_irq_mask[n] |= mask; \
  73. mtdcr(DCRN_UIC_ER(UIC##n), ppc_cached_irq_mask[n]); \
  74. } \
  75. }
  76. #define DECLARE_UIC(n) \
  77. { \
  78. .typename = "UIC"#n, \
  79. .enable = ppc4xx_uic##n##_enable, \
  80. .disable = ppc4xx_uic##n##_disable, \
  81. .ack = ppc4xx_uic##n##_ack, \
  82. .end = ppc4xx_uic##n##_end, \
  83. } \
  84. #if NR_UICS == 3
  85. #define ACK_UIC0_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC0NC);
  86. #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC1NC);
  87. #define ACK_UIC2_PARENT mtdcr(DCRN_UIC_SR(UICB), UICB_UIC2NC);
  88. UIC_HANDLERS(0);
  89. UIC_HANDLERS(1);
  90. UIC_HANDLERS(2);
  91. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  92. {
  93. u32 uicb = mfdcr(DCRN_UIC_MSR(UICB));
  94. if (uicb & UICB_UIC0NC)
  95. return 32 - ffs(mfdcr(DCRN_UIC_MSR(UIC0)));
  96. else if (uicb & UICB_UIC1NC)
  97. return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
  98. else if (uicb & UICB_UIC2NC)
  99. return 96 - ffs(mfdcr(DCRN_UIC_MSR(UIC2)));
  100. else
  101. return -1;
  102. }
  103. static void __init ppc4xx_pic_impl_init(void)
  104. {
  105. /* Configure Base UIC */
  106. mtdcr(DCRN_UIC_CR(UICB), 0);
  107. mtdcr(DCRN_UIC_TR(UICB), 0);
  108. mtdcr(DCRN_UIC_PR(UICB), 0xffffffff);
  109. mtdcr(DCRN_UIC_SR(UICB), 0xffffffff);
  110. mtdcr(DCRN_UIC_ER(UICB), UICB_UIC0NC | UICB_UIC1NC | UICB_UIC2NC);
  111. }
  112. #elif NR_UICS == 2
  113. #define ACK_UIC0_PARENT
  114. #define ACK_UIC1_PARENT mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
  115. UIC_HANDLERS(0);
  116. UIC_HANDLERS(1);
  117. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  118. {
  119. u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
  120. if (uic0 & UIC0_UIC1NC)
  121. return 64 - ffs(mfdcr(DCRN_UIC_MSR(UIC1)));
  122. else
  123. return uic0 ? 32 - ffs(uic0) : -1;
  124. }
  125. static void __init ppc4xx_pic_impl_init(void)
  126. {
  127. /* Enable cascade interrupt in UIC0 */
  128. ppc_cached_irq_mask[0] |= UIC0_UIC1NC;
  129. mtdcr(DCRN_UIC_SR(UIC0), UIC0_UIC1NC);
  130. mtdcr(DCRN_UIC_ER(UIC0), ppc_cached_irq_mask[0]);
  131. }
  132. #elif NR_UICS == 1
  133. #define ACK_UIC0_PARENT
  134. UIC_HANDLERS(0);
  135. static int ppc4xx_pic_get_irq(struct pt_regs *regs)
  136. {
  137. u32 uic0 = mfdcr(DCRN_UIC_MSR(UIC0));
  138. return uic0 ? 32 - ffs(uic0) : -1;
  139. }
  140. static inline void ppc4xx_pic_impl_init(void)
  141. {
  142. }
  143. #endif
  144. static struct ppc4xx_uic_impl {
  145. struct hw_interrupt_type decl;
  146. int base; /* Base DCR number */
  147. } __uic[] = {
  148. { .decl = DECLARE_UIC(0), .base = UIC0 },
  149. #if NR_UICS > 1
  150. { .decl = DECLARE_UIC(1), .base = UIC1 },
  151. #if NR_UICS > 2
  152. { .decl = DECLARE_UIC(2), .base = UIC2 },
  153. #endif
  154. #endif
  155. };
  156. static inline int is_level_sensitive(int irq)
  157. {
  158. u32 tr = mfdcr(DCRN_UIC_TR(__uic[irq >> 5].base));
  159. return (tr & IRQ_MASK_UICx(irq)) == 0;
  160. }
  161. void __init ppc4xx_pic_init(void)
  162. {
  163. int i;
  164. unsigned char *eirqs = ppc4xx_uic_ext_irq_cfg;
  165. for (i = 0; i < NR_UICS; ++i) {
  166. int base = __uic[i].base;
  167. /* Disable everything by default */
  168. ppc_cached_irq_mask[i] = 0;
  169. mtdcr(DCRN_UIC_ER(base), 0);
  170. /* We don't use critical interrupts */
  171. mtdcr(DCRN_UIC_CR(base), 0);
  172. /* Configure polarity and triggering */
  173. if (ppc4xx_core_uic_cfg) {
  174. struct ppc4xx_uic_settings *p = ppc4xx_core_uic_cfg + i;
  175. u32 mask = p->ext_irq_mask;
  176. u32 pr = mfdcr(DCRN_UIC_PR(base)) & mask;
  177. u32 tr = mfdcr(DCRN_UIC_TR(base)) & mask;
  178. /* "Fixed" interrupts (on-chip devices) */
  179. pr |= p->polarity & ~mask;
  180. tr |= p->triggering & ~mask;
  181. /* Merge external IRQs settings if board port
  182. * provided them
  183. */
  184. if (eirqs && mask) {
  185. pr &= ~mask;
  186. tr &= ~mask;
  187. while (mask) {
  188. /* Extract current external IRQ mask */
  189. u32 eirq_mask = 1 << __ilog2(mask);
  190. if (!(*eirqs & IRQ_SENSE_LEVEL))
  191. tr |= eirq_mask;
  192. if (*eirqs & IRQ_POLARITY_POSITIVE)
  193. pr |= eirq_mask;
  194. mask &= ~eirq_mask;
  195. ++eirqs;
  196. }
  197. }
  198. mtdcr(DCRN_UIC_PR(base), pr);
  199. mtdcr(DCRN_UIC_TR(base), tr);
  200. }
  201. /* ACK any pending interrupts to prevent false
  202. * triggering after first enable
  203. */
  204. mtdcr(DCRN_UIC_SR(base), 0xffffffff);
  205. }
  206. /* Perform optional implementation specific setup
  207. * (e.g. enable cascade interrupts for multi-UIC configurations)
  208. */
  209. ppc4xx_pic_impl_init();
  210. /* Attach low-level handlers */
  211. for (i = 0; i < (NR_UICS << 5); ++i) {
  212. irq_desc[i].handler = &__uic[i >> 5].decl;
  213. if (is_level_sensitive(i))
  214. irq_desc[i].status |= IRQ_LEVEL;
  215. }
  216. ppc_md.get_irq = ppc4xx_pic_get_irq;
  217. }