octeon-irq.c 32 KB

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