octeon-irq.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2004-2012 Cavium, Inc.
  7. */
  8. #include <linux/interrupt.h>
  9. #include <linux/irqdomain.h>
  10. #include <linux/bitops.h>
  11. #include <linux/percpu.h>
  12. #include <linux/slab.h>
  13. #include <linux/irq.h>
  14. #include <linux/smp.h>
  15. #include <linux/of.h>
  16. #include <asm/octeon/octeon.h>
  17. static DEFINE_RAW_SPINLOCK(octeon_irq_ciu0_lock);
  18. static DEFINE_RAW_SPINLOCK(octeon_irq_ciu1_lock);
  19. static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu0_en_mirror);
  20. static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu1_en_mirror);
  21. static __read_mostly u8 octeon_irq_ciu_to_irq[8][64];
  22. union octeon_ciu_chip_data {
  23. void *p;
  24. unsigned long l;
  25. struct {
  26. unsigned int line:6;
  27. unsigned int bit:6;
  28. } s;
  29. };
  30. struct octeon_core_chip_data {
  31. struct mutex core_irq_mutex;
  32. bool current_en;
  33. bool desired_en;
  34. u8 bit;
  35. };
  36. #define MIPS_CORE_IRQ_LINES 8
  37. static struct octeon_core_chip_data octeon_irq_core_chip_data[MIPS_CORE_IRQ_LINES];
  38. static void octeon_irq_set_ciu_mapping(int irq, int line, int bit,
  39. struct irq_chip *chip,
  40. irq_flow_handler_t handler)
  41. {
  42. union octeon_ciu_chip_data cd;
  43. irq_set_chip_and_handler(irq, chip, handler);
  44. cd.l = 0;
  45. cd.s.line = line;
  46. cd.s.bit = bit;
  47. irq_set_chip_data(irq, cd.p);
  48. octeon_irq_ciu_to_irq[line][bit] = irq;
  49. }
  50. static int octeon_coreid_for_cpu(int cpu)
  51. {
  52. #ifdef CONFIG_SMP
  53. return cpu_logical_map(cpu);
  54. #else
  55. return cvmx_get_core_num();
  56. #endif
  57. }
  58. static int octeon_cpu_for_coreid(int coreid)
  59. {
  60. #ifdef CONFIG_SMP
  61. return cpu_number_map(coreid);
  62. #else
  63. return smp_processor_id();
  64. #endif
  65. }
  66. static void octeon_irq_core_ack(struct irq_data *data)
  67. {
  68. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  69. unsigned int bit = cd->bit;
  70. /*
  71. * We don't need to disable IRQs to make these atomic since
  72. * they are already disabled earlier in the low level
  73. * interrupt code.
  74. */
  75. clear_c0_status(0x100 << bit);
  76. /* The two user interrupts must be cleared manually. */
  77. if (bit < 2)
  78. clear_c0_cause(0x100 << bit);
  79. }
  80. static void octeon_irq_core_eoi(struct irq_data *data)
  81. {
  82. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  83. /*
  84. * We don't need to disable IRQs to make these atomic since
  85. * they are already disabled earlier in the low level
  86. * interrupt code.
  87. */
  88. set_c0_status(0x100 << cd->bit);
  89. }
  90. static void octeon_irq_core_set_enable_local(void *arg)
  91. {
  92. struct irq_data *data = arg;
  93. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  94. unsigned int mask = 0x100 << cd->bit;
  95. /*
  96. * Interrupts are already disabled, so these are atomic.
  97. */
  98. if (cd->desired_en)
  99. set_c0_status(mask);
  100. else
  101. clear_c0_status(mask);
  102. }
  103. static void octeon_irq_core_disable(struct irq_data *data)
  104. {
  105. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  106. cd->desired_en = false;
  107. }
  108. static void octeon_irq_core_enable(struct irq_data *data)
  109. {
  110. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  111. cd->desired_en = true;
  112. }
  113. static void octeon_irq_core_bus_lock(struct irq_data *data)
  114. {
  115. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  116. mutex_lock(&cd->core_irq_mutex);
  117. }
  118. static void octeon_irq_core_bus_sync_unlock(struct irq_data *data)
  119. {
  120. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  121. if (cd->desired_en != cd->current_en) {
  122. on_each_cpu(octeon_irq_core_set_enable_local, data, 1);
  123. cd->current_en = cd->desired_en;
  124. }
  125. mutex_unlock(&cd->core_irq_mutex);
  126. }
  127. static struct irq_chip octeon_irq_chip_core = {
  128. .name = "Core",
  129. .irq_enable = octeon_irq_core_enable,
  130. .irq_disable = octeon_irq_core_disable,
  131. .irq_ack = octeon_irq_core_ack,
  132. .irq_eoi = octeon_irq_core_eoi,
  133. .irq_bus_lock = octeon_irq_core_bus_lock,
  134. .irq_bus_sync_unlock = octeon_irq_core_bus_sync_unlock,
  135. .irq_cpu_online = octeon_irq_core_eoi,
  136. .irq_cpu_offline = octeon_irq_core_ack,
  137. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  138. };
  139. static void __init octeon_irq_init_core(void)
  140. {
  141. int i;
  142. int irq;
  143. struct octeon_core_chip_data *cd;
  144. for (i = 0; i < MIPS_CORE_IRQ_LINES; i++) {
  145. cd = &octeon_irq_core_chip_data[i];
  146. cd->current_en = false;
  147. cd->desired_en = false;
  148. cd->bit = i;
  149. mutex_init(&cd->core_irq_mutex);
  150. irq = OCTEON_IRQ_SW0 + i;
  151. switch (irq) {
  152. case OCTEON_IRQ_TIMER:
  153. case OCTEON_IRQ_SW0:
  154. case OCTEON_IRQ_SW1:
  155. case OCTEON_IRQ_5:
  156. case OCTEON_IRQ_PERF:
  157. irq_set_chip_data(irq, cd);
  158. irq_set_chip_and_handler(irq, &octeon_irq_chip_core,
  159. handle_percpu_irq);
  160. break;
  161. default:
  162. break;
  163. }
  164. }
  165. }
  166. static int next_cpu_for_irq(struct irq_data *data)
  167. {
  168. #ifdef CONFIG_SMP
  169. int cpu;
  170. int weight = cpumask_weight(data->affinity);
  171. if (weight > 1) {
  172. cpu = smp_processor_id();
  173. for (;;) {
  174. cpu = cpumask_next(cpu, data->affinity);
  175. if (cpu >= nr_cpu_ids) {
  176. cpu = -1;
  177. continue;
  178. } else if (cpumask_test_cpu(cpu, cpu_online_mask)) {
  179. break;
  180. }
  181. }
  182. } else if (weight == 1) {
  183. cpu = cpumask_first(data->affinity);
  184. } else {
  185. cpu = smp_processor_id();
  186. }
  187. return cpu;
  188. #else
  189. return smp_processor_id();
  190. #endif
  191. }
  192. static void octeon_irq_ciu_enable(struct irq_data *data)
  193. {
  194. int cpu = next_cpu_for_irq(data);
  195. int coreid = octeon_coreid_for_cpu(cpu);
  196. unsigned long *pen;
  197. unsigned long flags;
  198. union octeon_ciu_chip_data cd;
  199. cd.p = irq_data_get_irq_chip_data(data);
  200. if (cd.s.line == 0) {
  201. raw_spin_lock_irqsave(&octeon_irq_ciu0_lock, flags);
  202. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  203. set_bit(cd.s.bit, pen);
  204. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  205. raw_spin_unlock_irqrestore(&octeon_irq_ciu0_lock, flags);
  206. } else {
  207. raw_spin_lock_irqsave(&octeon_irq_ciu1_lock, flags);
  208. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  209. set_bit(cd.s.bit, pen);
  210. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  211. raw_spin_unlock_irqrestore(&octeon_irq_ciu1_lock, flags);
  212. }
  213. }
  214. static void octeon_irq_ciu_enable_local(struct irq_data *data)
  215. {
  216. unsigned long *pen;
  217. unsigned long flags;
  218. union octeon_ciu_chip_data cd;
  219. cd.p = irq_data_get_irq_chip_data(data);
  220. if (cd.s.line == 0) {
  221. raw_spin_lock_irqsave(&octeon_irq_ciu0_lock, flags);
  222. pen = &__get_cpu_var(octeon_irq_ciu0_en_mirror);
  223. set_bit(cd.s.bit, pen);
  224. cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
  225. raw_spin_unlock_irqrestore(&octeon_irq_ciu0_lock, flags);
  226. } else {
  227. raw_spin_lock_irqsave(&octeon_irq_ciu1_lock, flags);
  228. pen = &__get_cpu_var(octeon_irq_ciu1_en_mirror);
  229. set_bit(cd.s.bit, pen);
  230. cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
  231. raw_spin_unlock_irqrestore(&octeon_irq_ciu1_lock, flags);
  232. }
  233. }
  234. static void octeon_irq_ciu_disable_local(struct irq_data *data)
  235. {
  236. unsigned long *pen;
  237. unsigned long flags;
  238. union octeon_ciu_chip_data cd;
  239. cd.p = irq_data_get_irq_chip_data(data);
  240. if (cd.s.line == 0) {
  241. raw_spin_lock_irqsave(&octeon_irq_ciu0_lock, flags);
  242. pen = &__get_cpu_var(octeon_irq_ciu0_en_mirror);
  243. clear_bit(cd.s.bit, pen);
  244. cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
  245. raw_spin_unlock_irqrestore(&octeon_irq_ciu0_lock, flags);
  246. } else {
  247. raw_spin_lock_irqsave(&octeon_irq_ciu1_lock, flags);
  248. pen = &__get_cpu_var(octeon_irq_ciu1_en_mirror);
  249. clear_bit(cd.s.bit, pen);
  250. cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
  251. raw_spin_unlock_irqrestore(&octeon_irq_ciu1_lock, flags);
  252. }
  253. }
  254. static void octeon_irq_ciu_disable_all(struct irq_data *data)
  255. {
  256. unsigned long flags;
  257. unsigned long *pen;
  258. int cpu;
  259. union octeon_ciu_chip_data cd;
  260. wmb(); /* Make sure flag changes arrive before register updates. */
  261. cd.p = irq_data_get_irq_chip_data(data);
  262. if (cd.s.line == 0) {
  263. raw_spin_lock_irqsave(&octeon_irq_ciu0_lock, flags);
  264. for_each_online_cpu(cpu) {
  265. int coreid = octeon_coreid_for_cpu(cpu);
  266. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  267. clear_bit(cd.s.bit, pen);
  268. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  269. }
  270. raw_spin_unlock_irqrestore(&octeon_irq_ciu0_lock, flags);
  271. } else {
  272. raw_spin_lock_irqsave(&octeon_irq_ciu1_lock, flags);
  273. for_each_online_cpu(cpu) {
  274. int coreid = octeon_coreid_for_cpu(cpu);
  275. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  276. clear_bit(cd.s.bit, pen);
  277. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  278. }
  279. raw_spin_unlock_irqrestore(&octeon_irq_ciu1_lock, flags);
  280. }
  281. }
  282. static void octeon_irq_ciu_enable_all(struct irq_data *data)
  283. {
  284. unsigned long flags;
  285. unsigned long *pen;
  286. int cpu;
  287. union octeon_ciu_chip_data cd;
  288. cd.p = irq_data_get_irq_chip_data(data);
  289. if (cd.s.line == 0) {
  290. raw_spin_lock_irqsave(&octeon_irq_ciu0_lock, flags);
  291. for_each_online_cpu(cpu) {
  292. int coreid = octeon_coreid_for_cpu(cpu);
  293. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  294. set_bit(cd.s.bit, pen);
  295. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  296. }
  297. raw_spin_unlock_irqrestore(&octeon_irq_ciu0_lock, flags);
  298. } else {
  299. raw_spin_lock_irqsave(&octeon_irq_ciu1_lock, flags);
  300. for_each_online_cpu(cpu) {
  301. int coreid = octeon_coreid_for_cpu(cpu);
  302. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  303. set_bit(cd.s.bit, pen);
  304. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  305. }
  306. raw_spin_unlock_irqrestore(&octeon_irq_ciu1_lock, flags);
  307. }
  308. }
  309. /*
  310. * Enable the irq on the next core in the affinity set for chips that
  311. * have the EN*_W1{S,C} registers.
  312. */
  313. static void octeon_irq_ciu_enable_v2(struct irq_data *data)
  314. {
  315. u64 mask;
  316. int cpu = next_cpu_for_irq(data);
  317. union octeon_ciu_chip_data cd;
  318. cd.p = irq_data_get_irq_chip_data(data);
  319. mask = 1ull << (cd.s.bit);
  320. /*
  321. * Called under the desc lock, so these should never get out
  322. * of sync.
  323. */
  324. if (cd.s.line == 0) {
  325. int index = octeon_coreid_for_cpu(cpu) * 2;
  326. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  327. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  328. } else {
  329. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  330. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  331. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  332. }
  333. }
  334. /*
  335. * Enable the irq on the current CPU for chips that
  336. * have the EN*_W1{S,C} registers.
  337. */
  338. static void octeon_irq_ciu_enable_local_v2(struct irq_data *data)
  339. {
  340. u64 mask;
  341. union octeon_ciu_chip_data cd;
  342. cd.p = irq_data_get_irq_chip_data(data);
  343. mask = 1ull << (cd.s.bit);
  344. if (cd.s.line == 0) {
  345. int index = cvmx_get_core_num() * 2;
  346. set_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu0_en_mirror));
  347. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  348. } else {
  349. int index = cvmx_get_core_num() * 2 + 1;
  350. set_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu1_en_mirror));
  351. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  352. }
  353. }
  354. static void octeon_irq_ciu_disable_local_v2(struct irq_data *data)
  355. {
  356. u64 mask;
  357. union octeon_ciu_chip_data cd;
  358. cd.p = irq_data_get_irq_chip_data(data);
  359. mask = 1ull << (cd.s.bit);
  360. if (cd.s.line == 0) {
  361. int index = cvmx_get_core_num() * 2;
  362. clear_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu0_en_mirror));
  363. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  364. } else {
  365. int index = cvmx_get_core_num() * 2 + 1;
  366. clear_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu1_en_mirror));
  367. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  368. }
  369. }
  370. /*
  371. * Write to the W1C bit in CVMX_CIU_INTX_SUM0 to clear the irq.
  372. */
  373. static void octeon_irq_ciu_ack(struct irq_data *data)
  374. {
  375. u64 mask;
  376. union octeon_ciu_chip_data cd;
  377. cd.p = data->chip_data;
  378. mask = 1ull << (cd.s.bit);
  379. if (cd.s.line == 0) {
  380. int index = cvmx_get_core_num() * 2;
  381. cvmx_write_csr(CVMX_CIU_INTX_SUM0(index), mask);
  382. } else {
  383. cvmx_write_csr(CVMX_CIU_INT_SUM1, mask);
  384. }
  385. }
  386. /*
  387. * Disable the irq on the all cores for chips that have the EN*_W1{S,C}
  388. * registers.
  389. */
  390. static void octeon_irq_ciu_disable_all_v2(struct irq_data *data)
  391. {
  392. int cpu;
  393. u64 mask;
  394. union octeon_ciu_chip_data cd;
  395. wmb(); /* Make sure flag changes arrive before register updates. */
  396. cd.p = data->chip_data;
  397. mask = 1ull << (cd.s.bit);
  398. if (cd.s.line == 0) {
  399. for_each_online_cpu(cpu) {
  400. int index = octeon_coreid_for_cpu(cpu) * 2;
  401. clear_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  402. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  403. }
  404. } else {
  405. for_each_online_cpu(cpu) {
  406. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  407. clear_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  408. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  409. }
  410. }
  411. }
  412. /*
  413. * Enable the irq on the all cores for chips that have the EN*_W1{S,C}
  414. * registers.
  415. */
  416. static void octeon_irq_ciu_enable_all_v2(struct irq_data *data)
  417. {
  418. int cpu;
  419. u64 mask;
  420. union octeon_ciu_chip_data cd;
  421. cd.p = data->chip_data;
  422. mask = 1ull << (cd.s.bit);
  423. if (cd.s.line == 0) {
  424. for_each_online_cpu(cpu) {
  425. int index = octeon_coreid_for_cpu(cpu) * 2;
  426. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  427. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  428. }
  429. } else {
  430. for_each_online_cpu(cpu) {
  431. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  432. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  433. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  434. }
  435. }
  436. }
  437. static void octeon_irq_gpio_setup(struct irq_data *data)
  438. {
  439. union cvmx_gpio_bit_cfgx cfg;
  440. union octeon_ciu_chip_data cd;
  441. u32 t = irqd_get_trigger_type(data);
  442. cd.p = irq_data_get_irq_chip_data(data);
  443. cfg.u64 = 0;
  444. cfg.s.int_en = 1;
  445. cfg.s.int_type = (t & IRQ_TYPE_EDGE_BOTH) != 0;
  446. cfg.s.rx_xor = (t & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) != 0;
  447. /* 140 nS glitch filter*/
  448. cfg.s.fil_cnt = 7;
  449. cfg.s.fil_sel = 3;
  450. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.bit - 16), cfg.u64);
  451. }
  452. static void octeon_irq_ciu_enable_gpio_v2(struct irq_data *data)
  453. {
  454. octeon_irq_gpio_setup(data);
  455. octeon_irq_ciu_enable_v2(data);
  456. }
  457. static void octeon_irq_ciu_enable_gpio(struct irq_data *data)
  458. {
  459. octeon_irq_gpio_setup(data);
  460. octeon_irq_ciu_enable(data);
  461. }
  462. static int octeon_irq_ciu_gpio_set_type(struct irq_data *data, unsigned int t)
  463. {
  464. irqd_set_trigger_type(data, t);
  465. octeon_irq_gpio_setup(data);
  466. return IRQ_SET_MASK_OK;
  467. }
  468. static void octeon_irq_ciu_disable_gpio_v2(struct irq_data *data)
  469. {
  470. union octeon_ciu_chip_data cd;
  471. cd.p = irq_data_get_irq_chip_data(data);
  472. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.bit - 16), 0);
  473. octeon_irq_ciu_disable_all_v2(data);
  474. }
  475. static void octeon_irq_ciu_disable_gpio(struct irq_data *data)
  476. {
  477. union octeon_ciu_chip_data cd;
  478. cd.p = irq_data_get_irq_chip_data(data);
  479. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.bit - 16), 0);
  480. octeon_irq_ciu_disable_all(data);
  481. }
  482. static void octeon_irq_ciu_gpio_ack(struct irq_data *data)
  483. {
  484. union octeon_ciu_chip_data cd;
  485. u64 mask;
  486. cd.p = irq_data_get_irq_chip_data(data);
  487. mask = 1ull << (cd.s.bit - 16);
  488. cvmx_write_csr(CVMX_GPIO_INT_CLR, mask);
  489. }
  490. static void octeon_irq_handle_gpio(unsigned int irq, struct irq_desc *desc)
  491. {
  492. if (irqd_get_trigger_type(irq_desc_get_irq_data(desc)) & IRQ_TYPE_EDGE_BOTH)
  493. handle_edge_irq(irq, desc);
  494. else
  495. handle_level_irq(irq, desc);
  496. }
  497. #ifdef CONFIG_SMP
  498. static void octeon_irq_cpu_offline_ciu(struct irq_data *data)
  499. {
  500. int cpu = smp_processor_id();
  501. cpumask_t new_affinity;
  502. if (!cpumask_test_cpu(cpu, data->affinity))
  503. return;
  504. if (cpumask_weight(data->affinity) > 1) {
  505. /*
  506. * It has multi CPU affinity, just remove this CPU
  507. * from the affinity set.
  508. */
  509. cpumask_copy(&new_affinity, data->affinity);
  510. cpumask_clear_cpu(cpu, &new_affinity);
  511. } else {
  512. /* Otherwise, put it on lowest numbered online CPU. */
  513. cpumask_clear(&new_affinity);
  514. cpumask_set_cpu(cpumask_first(cpu_online_mask), &new_affinity);
  515. }
  516. __irq_set_affinity_locked(data, &new_affinity);
  517. }
  518. static int octeon_irq_ciu_set_affinity(struct irq_data *data,
  519. const struct cpumask *dest, bool force)
  520. {
  521. int cpu;
  522. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  523. unsigned long flags;
  524. union octeon_ciu_chip_data cd;
  525. cd.p = data->chip_data;
  526. /*
  527. * For non-v2 CIU, we will allow only single CPU affinity.
  528. * This removes the need to do locking in the .ack/.eoi
  529. * functions.
  530. */
  531. if (cpumask_weight(dest) != 1)
  532. return -EINVAL;
  533. if (!enable_one)
  534. return 0;
  535. if (cd.s.line == 0) {
  536. raw_spin_lock_irqsave(&octeon_irq_ciu0_lock, flags);
  537. for_each_online_cpu(cpu) {
  538. int coreid = octeon_coreid_for_cpu(cpu);
  539. unsigned long *pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  540. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  541. enable_one = false;
  542. set_bit(cd.s.bit, pen);
  543. } else {
  544. clear_bit(cd.s.bit, pen);
  545. }
  546. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  547. }
  548. raw_spin_unlock_irqrestore(&octeon_irq_ciu0_lock, flags);
  549. } else {
  550. raw_spin_lock_irqsave(&octeon_irq_ciu1_lock, flags);
  551. for_each_online_cpu(cpu) {
  552. int coreid = octeon_coreid_for_cpu(cpu);
  553. unsigned long *pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  554. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  555. enable_one = false;
  556. set_bit(cd.s.bit, pen);
  557. } else {
  558. clear_bit(cd.s.bit, pen);
  559. }
  560. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  561. }
  562. raw_spin_unlock_irqrestore(&octeon_irq_ciu1_lock, flags);
  563. }
  564. return 0;
  565. }
  566. /*
  567. * Set affinity for the irq for chips that have the EN*_W1{S,C}
  568. * registers.
  569. */
  570. static int octeon_irq_ciu_set_affinity_v2(struct irq_data *data,
  571. const struct cpumask *dest,
  572. bool force)
  573. {
  574. int cpu;
  575. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  576. u64 mask;
  577. union octeon_ciu_chip_data cd;
  578. if (!enable_one)
  579. return 0;
  580. cd.p = data->chip_data;
  581. mask = 1ull << cd.s.bit;
  582. if (cd.s.line == 0) {
  583. for_each_online_cpu(cpu) {
  584. unsigned long *pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  585. int index = octeon_coreid_for_cpu(cpu) * 2;
  586. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  587. enable_one = false;
  588. set_bit(cd.s.bit, pen);
  589. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  590. } else {
  591. clear_bit(cd.s.bit, pen);
  592. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  593. }
  594. }
  595. } else {
  596. for_each_online_cpu(cpu) {
  597. unsigned long *pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  598. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  599. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  600. enable_one = false;
  601. set_bit(cd.s.bit, pen);
  602. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  603. } else {
  604. clear_bit(cd.s.bit, pen);
  605. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  606. }
  607. }
  608. }
  609. return 0;
  610. }
  611. #endif
  612. /*
  613. * The v1 CIU code already masks things, so supply a dummy version to
  614. * the core chip code.
  615. */
  616. static void octeon_irq_dummy_mask(struct irq_data *data)
  617. {
  618. }
  619. /*
  620. * Newer octeon chips have support for lockless CIU operation.
  621. */
  622. static struct irq_chip octeon_irq_chip_ciu_v2 = {
  623. .name = "CIU",
  624. .irq_enable = octeon_irq_ciu_enable_v2,
  625. .irq_disable = octeon_irq_ciu_disable_all_v2,
  626. .irq_ack = octeon_irq_ciu_ack,
  627. .irq_mask = octeon_irq_ciu_disable_local_v2,
  628. .irq_unmask = octeon_irq_ciu_enable_v2,
  629. #ifdef CONFIG_SMP
  630. .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
  631. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  632. #endif
  633. };
  634. static struct irq_chip octeon_irq_chip_ciu = {
  635. .name = "CIU",
  636. .irq_enable = octeon_irq_ciu_enable,
  637. .irq_disable = octeon_irq_ciu_disable_all,
  638. .irq_ack = octeon_irq_ciu_ack,
  639. .irq_mask = octeon_irq_dummy_mask,
  640. #ifdef CONFIG_SMP
  641. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  642. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  643. #endif
  644. };
  645. /* The mbox versions don't do any affinity or round-robin. */
  646. static struct irq_chip octeon_irq_chip_ciu_mbox_v2 = {
  647. .name = "CIU-M",
  648. .irq_enable = octeon_irq_ciu_enable_all_v2,
  649. .irq_disable = octeon_irq_ciu_disable_all_v2,
  650. .irq_ack = octeon_irq_ciu_disable_local_v2,
  651. .irq_eoi = octeon_irq_ciu_enable_local_v2,
  652. .irq_cpu_online = octeon_irq_ciu_enable_local_v2,
  653. .irq_cpu_offline = octeon_irq_ciu_disable_local_v2,
  654. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  655. };
  656. static struct irq_chip octeon_irq_chip_ciu_mbox = {
  657. .name = "CIU-M",
  658. .irq_enable = octeon_irq_ciu_enable_all,
  659. .irq_disable = octeon_irq_ciu_disable_all,
  660. .irq_cpu_online = octeon_irq_ciu_enable_local,
  661. .irq_cpu_offline = octeon_irq_ciu_disable_local,
  662. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  663. };
  664. static struct irq_chip octeon_irq_chip_ciu_gpio_v2 = {
  665. .name = "CIU-GPIO",
  666. .irq_enable = octeon_irq_ciu_enable_gpio_v2,
  667. .irq_disable = octeon_irq_ciu_disable_gpio_v2,
  668. .irq_ack = octeon_irq_ciu_gpio_ack,
  669. .irq_mask = octeon_irq_ciu_disable_local_v2,
  670. .irq_unmask = octeon_irq_ciu_enable_v2,
  671. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  672. #ifdef CONFIG_SMP
  673. .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
  674. #endif
  675. .flags = IRQCHIP_SET_TYPE_MASKED,
  676. };
  677. static struct irq_chip octeon_irq_chip_ciu_gpio = {
  678. .name = "CIU-GPIO",
  679. .irq_enable = octeon_irq_ciu_enable_gpio,
  680. .irq_disable = octeon_irq_ciu_disable_gpio,
  681. .irq_mask = octeon_irq_dummy_mask,
  682. .irq_ack = octeon_irq_ciu_gpio_ack,
  683. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  684. #ifdef CONFIG_SMP
  685. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  686. #endif
  687. .flags = IRQCHIP_SET_TYPE_MASKED,
  688. };
  689. /*
  690. * Watchdog interrupts are special. They are associated with a single
  691. * core, so we hardwire the affinity to that core.
  692. */
  693. static void octeon_irq_ciu_wd_enable(struct irq_data *data)
  694. {
  695. unsigned long flags;
  696. unsigned long *pen;
  697. int coreid = data->irq - OCTEON_IRQ_WDOG0; /* Bit 0-63 of EN1 */
  698. int cpu = octeon_cpu_for_coreid(coreid);
  699. raw_spin_lock_irqsave(&octeon_irq_ciu1_lock, flags);
  700. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  701. set_bit(coreid, pen);
  702. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  703. raw_spin_unlock_irqrestore(&octeon_irq_ciu1_lock, flags);
  704. }
  705. /*
  706. * Watchdog interrupts are special. They are associated with a single
  707. * core, so we hardwire the affinity to that core.
  708. */
  709. static void octeon_irq_ciu1_wd_enable_v2(struct irq_data *data)
  710. {
  711. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  712. int cpu = octeon_cpu_for_coreid(coreid);
  713. set_bit(coreid, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  714. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(coreid * 2 + 1), 1ull << coreid);
  715. }
  716. static struct irq_chip octeon_irq_chip_ciu_wd_v2 = {
  717. .name = "CIU-W",
  718. .irq_enable = octeon_irq_ciu1_wd_enable_v2,
  719. .irq_disable = octeon_irq_ciu_disable_all_v2,
  720. .irq_mask = octeon_irq_ciu_disable_local_v2,
  721. .irq_unmask = octeon_irq_ciu_enable_local_v2,
  722. };
  723. static struct irq_chip octeon_irq_chip_ciu_wd = {
  724. .name = "CIU-W",
  725. .irq_enable = octeon_irq_ciu_wd_enable,
  726. .irq_disable = octeon_irq_ciu_disable_all,
  727. .irq_mask = octeon_irq_dummy_mask,
  728. };
  729. static bool octeon_irq_ciu_is_edge(unsigned int line, unsigned int bit)
  730. {
  731. bool edge = false;
  732. if (line == 0)
  733. switch (bit) {
  734. case 48 ... 49: /* GMX DRP */
  735. case 50: /* IPD_DRP */
  736. case 52 ... 55: /* Timers */
  737. case 58: /* MPI */
  738. edge = true;
  739. break;
  740. default:
  741. break;
  742. }
  743. else /* line == 1 */
  744. switch (bit) {
  745. case 47: /* PTP */
  746. edge = true;
  747. break;
  748. default:
  749. break;
  750. }
  751. return edge;
  752. }
  753. struct octeon_irq_gpio_domain_data {
  754. unsigned int base_hwirq;
  755. };
  756. static int octeon_irq_gpio_xlat(struct irq_domain *d,
  757. struct device_node *node,
  758. const u32 *intspec,
  759. unsigned int intsize,
  760. unsigned long *out_hwirq,
  761. unsigned int *out_type)
  762. {
  763. unsigned int type;
  764. unsigned int pin;
  765. unsigned int trigger;
  766. struct octeon_irq_gpio_domain_data *gpiod;
  767. if (d->of_node != node)
  768. return -EINVAL;
  769. if (intsize < 2)
  770. return -EINVAL;
  771. pin = intspec[0];
  772. if (pin >= 16)
  773. return -EINVAL;
  774. trigger = intspec[1];
  775. switch (trigger) {
  776. case 1:
  777. type = IRQ_TYPE_EDGE_RISING;
  778. break;
  779. case 2:
  780. type = IRQ_TYPE_EDGE_FALLING;
  781. break;
  782. case 4:
  783. type = IRQ_TYPE_LEVEL_HIGH;
  784. break;
  785. case 8:
  786. type = IRQ_TYPE_LEVEL_LOW;
  787. break;
  788. default:
  789. pr_err("Error: (%s) Invalid irq trigger specification: %x\n",
  790. node->name,
  791. trigger);
  792. type = IRQ_TYPE_LEVEL_LOW;
  793. break;
  794. }
  795. *out_type = type;
  796. gpiod = d->host_data;
  797. *out_hwirq = gpiod->base_hwirq + pin;
  798. return 0;
  799. }
  800. static int octeon_irq_ciu_xlat(struct irq_domain *d,
  801. struct device_node *node,
  802. const u32 *intspec,
  803. unsigned int intsize,
  804. unsigned long *out_hwirq,
  805. unsigned int *out_type)
  806. {
  807. unsigned int ciu, bit;
  808. ciu = intspec[0];
  809. bit = intspec[1];
  810. if (ciu > 1 || bit > 63)
  811. return -EINVAL;
  812. /* These are the GPIO lines */
  813. if (ciu == 0 && bit >= 16 && bit < 32)
  814. return -EINVAL;
  815. *out_hwirq = (ciu << 6) | bit;
  816. *out_type = 0;
  817. return 0;
  818. }
  819. static struct irq_chip *octeon_irq_ciu_chip;
  820. static struct irq_chip *octeon_irq_gpio_chip;
  821. static bool octeon_irq_virq_in_range(unsigned int virq)
  822. {
  823. /* We cannot let it overflow the mapping array. */
  824. if (virq < (1ul << 8 * sizeof(octeon_irq_ciu_to_irq[0][0])))
  825. return true;
  826. WARN_ONCE(true, "virq out of range %u.\n", virq);
  827. return false;
  828. }
  829. static int octeon_irq_ciu_map(struct irq_domain *d,
  830. unsigned int virq, irq_hw_number_t hw)
  831. {
  832. unsigned int line = hw >> 6;
  833. unsigned int bit = hw & 63;
  834. if (!octeon_irq_virq_in_range(virq))
  835. return -EINVAL;
  836. if (line > 1 || octeon_irq_ciu_to_irq[line][bit] != 0)
  837. return -EINVAL;
  838. if (octeon_irq_ciu_is_edge(line, bit))
  839. octeon_irq_set_ciu_mapping(virq, line, bit,
  840. octeon_irq_ciu_chip,
  841. handle_edge_irq);
  842. else
  843. octeon_irq_set_ciu_mapping(virq, line, bit,
  844. octeon_irq_ciu_chip,
  845. handle_level_irq);
  846. return 0;
  847. }
  848. static int octeon_irq_gpio_map(struct irq_domain *d,
  849. unsigned int virq, irq_hw_number_t hw)
  850. {
  851. unsigned int line = hw >> 6;
  852. unsigned int bit = hw & 63;
  853. if (!octeon_irq_virq_in_range(virq))
  854. return -EINVAL;
  855. if (line > 1 || octeon_irq_ciu_to_irq[line][bit] != 0)
  856. return -EINVAL;
  857. octeon_irq_set_ciu_mapping(virq, line, bit,
  858. octeon_irq_gpio_chip,
  859. octeon_irq_handle_gpio);
  860. return 0;
  861. }
  862. static struct irq_domain_ops octeon_irq_domain_ciu_ops = {
  863. .map = octeon_irq_ciu_map,
  864. .xlate = octeon_irq_ciu_xlat,
  865. };
  866. static struct irq_domain_ops octeon_irq_domain_gpio_ops = {
  867. .map = octeon_irq_gpio_map,
  868. .xlate = octeon_irq_gpio_xlat,
  869. };
  870. static void octeon_irq_ip2_v1(void)
  871. {
  872. const unsigned long core_id = cvmx_get_core_num();
  873. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(core_id * 2));
  874. ciu_sum &= __get_cpu_var(octeon_irq_ciu0_en_mirror);
  875. clear_c0_status(STATUSF_IP2);
  876. if (likely(ciu_sum)) {
  877. int bit = fls64(ciu_sum) - 1;
  878. int irq = octeon_irq_ciu_to_irq[0][bit];
  879. if (likely(irq))
  880. do_IRQ(irq);
  881. else
  882. spurious_interrupt();
  883. } else {
  884. spurious_interrupt();
  885. }
  886. set_c0_status(STATUSF_IP2);
  887. }
  888. static void octeon_irq_ip2_v2(void)
  889. {
  890. const unsigned long core_id = cvmx_get_core_num();
  891. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(core_id * 2));
  892. ciu_sum &= __get_cpu_var(octeon_irq_ciu0_en_mirror);
  893. if (likely(ciu_sum)) {
  894. int bit = fls64(ciu_sum) - 1;
  895. int irq = octeon_irq_ciu_to_irq[0][bit];
  896. if (likely(irq))
  897. do_IRQ(irq);
  898. else
  899. spurious_interrupt();
  900. } else {
  901. spurious_interrupt();
  902. }
  903. }
  904. static void octeon_irq_ip3_v1(void)
  905. {
  906. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
  907. ciu_sum &= __get_cpu_var(octeon_irq_ciu1_en_mirror);
  908. clear_c0_status(STATUSF_IP3);
  909. if (likely(ciu_sum)) {
  910. int bit = fls64(ciu_sum) - 1;
  911. int irq = octeon_irq_ciu_to_irq[1][bit];
  912. if (likely(irq))
  913. do_IRQ(irq);
  914. else
  915. spurious_interrupt();
  916. } else {
  917. spurious_interrupt();
  918. }
  919. set_c0_status(STATUSF_IP3);
  920. }
  921. static void octeon_irq_ip3_v2(void)
  922. {
  923. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
  924. ciu_sum &= __get_cpu_var(octeon_irq_ciu1_en_mirror);
  925. if (likely(ciu_sum)) {
  926. int bit = fls64(ciu_sum) - 1;
  927. int irq = octeon_irq_ciu_to_irq[1][bit];
  928. if (likely(irq))
  929. do_IRQ(irq);
  930. else
  931. spurious_interrupt();
  932. } else {
  933. spurious_interrupt();
  934. }
  935. }
  936. static void octeon_irq_ip4_mask(void)
  937. {
  938. clear_c0_status(STATUSF_IP4);
  939. spurious_interrupt();
  940. }
  941. static void (*octeon_irq_ip2)(void);
  942. static void (*octeon_irq_ip3)(void);
  943. static void (*octeon_irq_ip4)(void);
  944. void __cpuinitdata (*octeon_irq_setup_secondary)(void);
  945. static void __cpuinit octeon_irq_percpu_enable(void)
  946. {
  947. irq_cpu_online();
  948. }
  949. static void __cpuinit octeon_irq_init_ciu_percpu(void)
  950. {
  951. int coreid = cvmx_get_core_num();
  952. /*
  953. * Disable All CIU Interrupts. The ones we need will be
  954. * enabled later. Read the SUM register so we know the write
  955. * completed.
  956. */
  957. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2)), 0);
  958. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2 + 1)), 0);
  959. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2)), 0);
  960. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2 + 1)), 0);
  961. cvmx_read_csr(CVMX_CIU_INTX_SUM0((coreid * 2)));
  962. }
  963. static void __cpuinit octeon_irq_setup_secondary_ciu(void)
  964. {
  965. __get_cpu_var(octeon_irq_ciu0_en_mirror) = 0;
  966. __get_cpu_var(octeon_irq_ciu1_en_mirror) = 0;
  967. octeon_irq_init_ciu_percpu();
  968. octeon_irq_percpu_enable();
  969. /* Enable the CIU lines */
  970. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  971. clear_c0_status(STATUSF_IP4);
  972. }
  973. static void __init octeon_irq_init_ciu(void)
  974. {
  975. unsigned int i;
  976. struct irq_chip *chip;
  977. struct irq_chip *chip_mbox;
  978. struct irq_chip *chip_wd;
  979. struct device_node *gpio_node;
  980. struct device_node *ciu_node;
  981. octeon_irq_init_ciu_percpu();
  982. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu;
  983. if (OCTEON_IS_MODEL(OCTEON_CN58XX_PASS2_X) ||
  984. OCTEON_IS_MODEL(OCTEON_CN56XX_PASS2_X) ||
  985. OCTEON_IS_MODEL(OCTEON_CN52XX_PASS2_X) ||
  986. OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
  987. octeon_irq_ip2 = octeon_irq_ip2_v2;
  988. octeon_irq_ip3 = octeon_irq_ip3_v2;
  989. chip = &octeon_irq_chip_ciu_v2;
  990. chip_mbox = &octeon_irq_chip_ciu_mbox_v2;
  991. chip_wd = &octeon_irq_chip_ciu_wd_v2;
  992. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio_v2;
  993. } else {
  994. octeon_irq_ip2 = octeon_irq_ip2_v1;
  995. octeon_irq_ip3 = octeon_irq_ip3_v1;
  996. chip = &octeon_irq_chip_ciu;
  997. chip_mbox = &octeon_irq_chip_ciu_mbox;
  998. chip_wd = &octeon_irq_chip_ciu_wd;
  999. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio;
  1000. }
  1001. octeon_irq_ciu_chip = chip;
  1002. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1003. /* Mips internal */
  1004. octeon_irq_init_core();
  1005. /* CIU_0 */
  1006. for (i = 0; i < 16; i++)
  1007. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WORKQ0, 0, i + 0, chip, handle_level_irq);
  1008. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX0, 0, 32, chip_mbox, handle_percpu_irq);
  1009. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX1, 0, 33, chip_mbox, handle_percpu_irq);
  1010. for (i = 0; i < 4; i++)
  1011. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_PCI_INT0, 0, i + 36, chip, handle_level_irq);
  1012. for (i = 0; i < 4; i++)
  1013. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_PCI_MSI0, 0, i + 40, chip, handle_level_irq);
  1014. octeon_irq_set_ciu_mapping(OCTEON_IRQ_RML, 0, 46, chip, handle_level_irq);
  1015. for (i = 0; i < 4; i++)
  1016. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_TIMER0, 0, i + 52, chip, handle_edge_irq);
  1017. octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB0, 0, 56, chip, handle_level_irq);
  1018. octeon_irq_set_ciu_mapping(OCTEON_IRQ_BOOTDMA, 0, 63, chip, handle_level_irq);
  1019. /* CIU_1 */
  1020. for (i = 0; i < 16; i++)
  1021. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i + 0, chip_wd, handle_level_irq);
  1022. octeon_irq_set_ciu_mapping(OCTEON_IRQ_USB1, 1, 17, chip, handle_level_irq);
  1023. gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
  1024. if (gpio_node) {
  1025. struct octeon_irq_gpio_domain_data *gpiod;
  1026. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1027. if (gpiod) {
  1028. /* gpio domain host_data is the base hwirq number. */
  1029. gpiod->base_hwirq = 16;
  1030. irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_gpio_ops, gpiod);
  1031. of_node_put(gpio_node);
  1032. } else
  1033. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1034. } else
  1035. pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
  1036. ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-ciu");
  1037. if (ciu_node) {
  1038. irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu_ops, NULL);
  1039. of_node_put(ciu_node);
  1040. } else
  1041. pr_warn("Cannot find device node for cavium,octeon-3860-ciu.\n");
  1042. /* Enable the CIU lines */
  1043. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1044. clear_c0_status(STATUSF_IP4);
  1045. }
  1046. void __init arch_init_irq(void)
  1047. {
  1048. #ifdef CONFIG_SMP
  1049. /* Set the default affinity to the boot cpu. */
  1050. cpumask_clear(irq_default_affinity);
  1051. cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
  1052. #endif
  1053. octeon_irq_init_ciu();
  1054. }
  1055. asmlinkage void plat_irq_dispatch(void)
  1056. {
  1057. unsigned long cop0_cause;
  1058. unsigned long cop0_status;
  1059. while (1) {
  1060. cop0_cause = read_c0_cause();
  1061. cop0_status = read_c0_status();
  1062. cop0_cause &= cop0_status;
  1063. cop0_cause &= ST0_IM;
  1064. if (unlikely(cop0_cause & STATUSF_IP2))
  1065. octeon_irq_ip2();
  1066. else if (unlikely(cop0_cause & STATUSF_IP3))
  1067. octeon_irq_ip3();
  1068. else if (unlikely(cop0_cause & STATUSF_IP4))
  1069. octeon_irq_ip4();
  1070. else if (likely(cop0_cause))
  1071. do_IRQ(fls(cop0_cause) - 9 + MIPS_CPU_IRQ_BASE);
  1072. else
  1073. break;
  1074. }
  1075. }
  1076. #ifdef CONFIG_HOTPLUG_CPU
  1077. void fixup_irqs(void)
  1078. {
  1079. irq_cpu_offline();
  1080. }
  1081. #endif /* CONFIG_HOTPLUG_CPU */