handle.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Shared interrupt handling code for IPR and INTC2 types of IRQs.
  3. *
  4. * Copyright (C) 2007, 2008 Magnus Damm
  5. * Copyright (C) 2009, 2010 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/irq.h>
  13. #include <linux/spinlock.h>
  14. #include "internals.h"
  15. static unsigned long ack_handle[INTC_NR_IRQS];
  16. static intc_enum __init intc_grp_id(struct intc_desc *desc,
  17. intc_enum enum_id)
  18. {
  19. struct intc_group *g = desc->hw.groups;
  20. unsigned int i, j;
  21. for (i = 0; g && enum_id && i < desc->hw.nr_groups; i++) {
  22. g = desc->hw.groups + i;
  23. for (j = 0; g->enum_ids[j]; j++) {
  24. if (g->enum_ids[j] != enum_id)
  25. continue;
  26. return g->enum_id;
  27. }
  28. }
  29. return 0;
  30. }
  31. static unsigned int __init _intc_mask_data(struct intc_desc *desc,
  32. struct intc_desc_int *d,
  33. intc_enum enum_id,
  34. unsigned int *reg_idx,
  35. unsigned int *fld_idx)
  36. {
  37. struct intc_mask_reg *mr = desc->hw.mask_regs;
  38. unsigned int fn, mode;
  39. unsigned long reg_e, reg_d;
  40. while (mr && enum_id && *reg_idx < desc->hw.nr_mask_regs) {
  41. mr = desc->hw.mask_regs + *reg_idx;
  42. for (; *fld_idx < ARRAY_SIZE(mr->enum_ids); (*fld_idx)++) {
  43. if (mr->enum_ids[*fld_idx] != enum_id)
  44. continue;
  45. if (mr->set_reg && mr->clr_reg) {
  46. fn = REG_FN_WRITE_BASE;
  47. mode = MODE_DUAL_REG;
  48. reg_e = mr->clr_reg;
  49. reg_d = mr->set_reg;
  50. } else {
  51. fn = REG_FN_MODIFY_BASE;
  52. if (mr->set_reg) {
  53. mode = MODE_ENABLE_REG;
  54. reg_e = mr->set_reg;
  55. reg_d = mr->set_reg;
  56. } else {
  57. mode = MODE_MASK_REG;
  58. reg_e = mr->clr_reg;
  59. reg_d = mr->clr_reg;
  60. }
  61. }
  62. fn += (mr->reg_width >> 3) - 1;
  63. return _INTC_MK(fn, mode,
  64. intc_get_reg(d, reg_e),
  65. intc_get_reg(d, reg_d),
  66. 1,
  67. (mr->reg_width - 1) - *fld_idx);
  68. }
  69. *fld_idx = 0;
  70. (*reg_idx)++;
  71. }
  72. return 0;
  73. }
  74. unsigned int __init
  75. intc_get_mask_handle(struct intc_desc *desc, struct intc_desc_int *d,
  76. intc_enum enum_id, int do_grps)
  77. {
  78. unsigned int i = 0;
  79. unsigned int j = 0;
  80. unsigned int ret;
  81. ret = _intc_mask_data(desc, d, enum_id, &i, &j);
  82. if (ret)
  83. return ret;
  84. if (do_grps)
  85. return intc_get_mask_handle(desc, d, intc_grp_id(desc, enum_id), 0);
  86. return 0;
  87. }
  88. static unsigned int __init _intc_prio_data(struct intc_desc *desc,
  89. struct intc_desc_int *d,
  90. intc_enum enum_id,
  91. unsigned int *reg_idx,
  92. unsigned int *fld_idx)
  93. {
  94. struct intc_prio_reg *pr = desc->hw.prio_regs;
  95. unsigned int fn, n, mode, bit;
  96. unsigned long reg_e, reg_d;
  97. while (pr && enum_id && *reg_idx < desc->hw.nr_prio_regs) {
  98. pr = desc->hw.prio_regs + *reg_idx;
  99. for (; *fld_idx < ARRAY_SIZE(pr->enum_ids); (*fld_idx)++) {
  100. if (pr->enum_ids[*fld_idx] != enum_id)
  101. continue;
  102. if (pr->set_reg && pr->clr_reg) {
  103. fn = REG_FN_WRITE_BASE;
  104. mode = MODE_PCLR_REG;
  105. reg_e = pr->set_reg;
  106. reg_d = pr->clr_reg;
  107. } else {
  108. fn = REG_FN_MODIFY_BASE;
  109. mode = MODE_PRIO_REG;
  110. if (!pr->set_reg)
  111. BUG();
  112. reg_e = pr->set_reg;
  113. reg_d = pr->set_reg;
  114. }
  115. fn += (pr->reg_width >> 3) - 1;
  116. n = *fld_idx + 1;
  117. BUG_ON(n * pr->field_width > pr->reg_width);
  118. bit = pr->reg_width - (n * pr->field_width);
  119. return _INTC_MK(fn, mode,
  120. intc_get_reg(d, reg_e),
  121. intc_get_reg(d, reg_d),
  122. pr->field_width, bit);
  123. }
  124. *fld_idx = 0;
  125. (*reg_idx)++;
  126. }
  127. return 0;
  128. }
  129. unsigned int __init
  130. intc_get_prio_handle(struct intc_desc *desc, struct intc_desc_int *d,
  131. intc_enum enum_id, int do_grps)
  132. {
  133. unsigned int i = 0;
  134. unsigned int j = 0;
  135. unsigned int ret;
  136. ret = _intc_prio_data(desc, d, enum_id, &i, &j);
  137. if (ret)
  138. return ret;
  139. if (do_grps)
  140. return intc_get_prio_handle(desc, d, intc_grp_id(desc, enum_id), 0);
  141. return 0;
  142. }
  143. static unsigned int intc_ack_data(struct intc_desc *desc,
  144. struct intc_desc_int *d, intc_enum enum_id)
  145. {
  146. struct intc_mask_reg *mr = desc->hw.ack_regs;
  147. unsigned int i, j, fn, mode;
  148. unsigned long reg_e, reg_d;
  149. for (i = 0; mr && enum_id && i < desc->hw.nr_ack_regs; i++) {
  150. mr = desc->hw.ack_regs + i;
  151. for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) {
  152. if (mr->enum_ids[j] != enum_id)
  153. continue;
  154. fn = REG_FN_MODIFY_BASE;
  155. mode = MODE_ENABLE_REG;
  156. reg_e = mr->set_reg;
  157. reg_d = mr->set_reg;
  158. fn += (mr->reg_width >> 3) - 1;
  159. return _INTC_MK(fn, mode,
  160. intc_get_reg(d, reg_e),
  161. intc_get_reg(d, reg_d),
  162. 1,
  163. (mr->reg_width - 1) - j);
  164. }
  165. }
  166. return 0;
  167. }
  168. static void intc_enable_disable(struct intc_desc_int *d,
  169. unsigned long handle, int do_enable)
  170. {
  171. unsigned long addr;
  172. unsigned int cpu;
  173. unsigned long (*fn)(unsigned long, unsigned long,
  174. unsigned long (*)(unsigned long, unsigned long,
  175. unsigned long),
  176. unsigned int);
  177. if (do_enable) {
  178. for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {
  179. addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);
  180. fn = intc_enable_noprio_fns[_INTC_MODE(handle)];
  181. fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
  182. }
  183. } else {
  184. for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
  185. addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);
  186. fn = intc_disable_fns[_INTC_MODE(handle)];
  187. fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
  188. }
  189. }
  190. }
  191. void __init intc_enable_disable_enum(struct intc_desc *desc,
  192. struct intc_desc_int *d,
  193. intc_enum enum_id, int enable)
  194. {
  195. unsigned int i, j, data;
  196. /* go through and enable/disable all mask bits */
  197. i = j = 0;
  198. do {
  199. data = _intc_mask_data(desc, d, enum_id, &i, &j);
  200. if (data)
  201. intc_enable_disable(d, data, enable);
  202. j++;
  203. } while (data);
  204. /* go through and enable/disable all priority fields */
  205. i = j = 0;
  206. do {
  207. data = _intc_prio_data(desc, d, enum_id, &i, &j);
  208. if (data)
  209. intc_enable_disable(d, data, enable);
  210. j++;
  211. } while (data);
  212. }
  213. unsigned int __init
  214. intc_get_sense_handle(struct intc_desc *desc, struct intc_desc_int *d,
  215. intc_enum enum_id)
  216. {
  217. struct intc_sense_reg *sr = desc->hw.sense_regs;
  218. unsigned int i, j, fn, bit;
  219. for (i = 0; sr && enum_id && i < desc->hw.nr_sense_regs; i++) {
  220. sr = desc->hw.sense_regs + i;
  221. for (j = 0; j < ARRAY_SIZE(sr->enum_ids); j++) {
  222. if (sr->enum_ids[j] != enum_id)
  223. continue;
  224. fn = REG_FN_MODIFY_BASE;
  225. fn += (sr->reg_width >> 3) - 1;
  226. BUG_ON((j + 1) * sr->field_width > sr->reg_width);
  227. bit = sr->reg_width - ((j + 1) * sr->field_width);
  228. return _INTC_MK(fn, 0, intc_get_reg(d, sr->reg),
  229. 0, sr->field_width, bit);
  230. }
  231. }
  232. return 0;
  233. }
  234. void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
  235. struct intc_desc_int *d, intc_enum id)
  236. {
  237. unsigned long flags;
  238. /*
  239. * Nothing to do for this IRQ.
  240. */
  241. if (!desc->hw.ack_regs)
  242. return;
  243. raw_spin_lock_irqsave(&intc_big_lock, flags);
  244. ack_handle[irq] = intc_ack_data(desc, d, id);
  245. raw_spin_unlock_irqrestore(&intc_big_lock, flags);
  246. }
  247. unsigned long intc_get_ack_handle(unsigned int irq)
  248. {
  249. return ack_handle[irq];
  250. }