handle.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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[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 __init intc_ack_data(struct intc_desc *desc,
  144. struct intc_desc_int *d,
  145. intc_enum enum_id)
  146. {
  147. struct intc_mask_reg *mr = desc->hw.ack_regs;
  148. unsigned int i, j, fn, mode;
  149. unsigned long reg_e, reg_d;
  150. for (i = 0; mr && enum_id && i < desc->hw.nr_ack_regs; i++) {
  151. mr = desc->hw.ack_regs + i;
  152. for (j = 0; j < ARRAY_SIZE(mr->enum_ids); j++) {
  153. if (mr->enum_ids[j] != enum_id)
  154. continue;
  155. fn = REG_FN_MODIFY_BASE;
  156. mode = MODE_ENABLE_REG;
  157. reg_e = mr->set_reg;
  158. reg_d = mr->set_reg;
  159. fn += (mr->reg_width >> 3) - 1;
  160. return _INTC_MK(fn, mode,
  161. intc_get_reg(d, reg_e),
  162. intc_get_reg(d, reg_d),
  163. 1,
  164. (mr->reg_width - 1) - j);
  165. }
  166. }
  167. return 0;
  168. }
  169. static void intc_enable_disable(struct intc_desc_int *d,
  170. unsigned long handle, int do_enable)
  171. {
  172. unsigned long addr;
  173. unsigned int cpu;
  174. unsigned long (*fn)(unsigned long, unsigned long,
  175. unsigned long (*)(unsigned long, unsigned long,
  176. unsigned long),
  177. unsigned int);
  178. if (do_enable) {
  179. for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_E(handle)); cpu++) {
  180. addr = INTC_REG(d, _INTC_ADDR_E(handle), cpu);
  181. fn = intc_enable_noprio_fns[_INTC_MODE(handle)];
  182. fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
  183. }
  184. } else {
  185. for (cpu = 0; cpu < SMP_NR(d, _INTC_ADDR_D(handle)); cpu++) {
  186. addr = INTC_REG(d, _INTC_ADDR_D(handle), cpu);
  187. fn = intc_disable_fns[_INTC_MODE(handle)];
  188. fn(addr, handle, intc_reg_fns[_INTC_FN(handle)], 0);
  189. }
  190. }
  191. }
  192. void __init intc_enable_disable_enum(struct intc_desc *desc,
  193. struct intc_desc_int *d,
  194. intc_enum enum_id, int enable)
  195. {
  196. unsigned int i, j, data;
  197. /* go through and enable/disable all mask bits */
  198. i = j = 0;
  199. do {
  200. data = _intc_mask_data(desc, d, enum_id, &i, &j);
  201. if (data)
  202. intc_enable_disable(d, data, enable);
  203. j++;
  204. } while (data);
  205. /* go through and enable/disable all priority fields */
  206. i = j = 0;
  207. do {
  208. data = _intc_prio_data(desc, d, enum_id, &i, &j);
  209. if (data)
  210. intc_enable_disable(d, data, enable);
  211. j++;
  212. } while (data);
  213. }
  214. unsigned int __init
  215. intc_get_sense_handle(struct intc_desc *desc, struct intc_desc_int *d,
  216. intc_enum enum_id)
  217. {
  218. struct intc_sense_reg *sr = desc->hw.sense_regs;
  219. unsigned int i, j, fn, bit;
  220. for (i = 0; sr && enum_id && i < desc->hw.nr_sense_regs; i++) {
  221. sr = desc->hw.sense_regs + i;
  222. for (j = 0; j < ARRAY_SIZE(sr->enum_ids); j++) {
  223. if (sr->enum_ids[j] != enum_id)
  224. continue;
  225. fn = REG_FN_MODIFY_BASE;
  226. fn += (sr->reg_width >> 3) - 1;
  227. BUG_ON((j + 1) * sr->field_width > sr->reg_width);
  228. bit = sr->reg_width - ((j + 1) * sr->field_width);
  229. return _INTC_MK(fn, 0, intc_get_reg(d, sr->reg),
  230. 0, sr->field_width, bit);
  231. }
  232. }
  233. return 0;
  234. }
  235. void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
  236. struct intc_desc_int *d, intc_enum id)
  237. {
  238. unsigned long flags;
  239. /*
  240. * Nothing to do for this IRQ.
  241. */
  242. if (!desc->hw.ack_regs)
  243. return;
  244. raw_spin_lock_irqsave(&intc_big_lock, flags);
  245. ack_handle[irq] = intc_ack_data(desc, d, id);
  246. raw_spin_unlock_irqrestore(&intc_big_lock, flags);
  247. }
  248. unsigned long intc_get_ack_handle(unsigned int irq)
  249. {
  250. return ack_handle[irq];
  251. }