octeon-irq.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  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. #include <asm/octeon/cvmx-ciu2-defs.h>
  18. static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu0_en_mirror);
  19. static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu1_en_mirror);
  20. static DEFINE_PER_CPU(raw_spinlock_t, octeon_irq_ciu_spinlock);
  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 long line:6;
  27. unsigned long bit:6;
  28. unsigned long gpio_line:6;
  29. } s;
  30. };
  31. struct octeon_core_chip_data {
  32. struct mutex core_irq_mutex;
  33. bool current_en;
  34. bool desired_en;
  35. u8 bit;
  36. };
  37. #define MIPS_CORE_IRQ_LINES 8
  38. static struct octeon_core_chip_data octeon_irq_core_chip_data[MIPS_CORE_IRQ_LINES];
  39. static void octeon_irq_set_ciu_mapping(int irq, int line, int bit, int gpio_line,
  40. struct irq_chip *chip,
  41. irq_flow_handler_t handler)
  42. {
  43. union octeon_ciu_chip_data cd;
  44. irq_set_chip_and_handler(irq, chip, handler);
  45. cd.l = 0;
  46. cd.s.line = line;
  47. cd.s.bit = bit;
  48. cd.s.gpio_line = gpio_line;
  49. irq_set_chip_data(irq, cd.p);
  50. octeon_irq_ciu_to_irq[line][bit] = irq;
  51. }
  52. static void octeon_irq_force_ciu_mapping(struct irq_domain *domain,
  53. int irq, int line, int bit)
  54. {
  55. irq_domain_associate(domain, irq, line << 6 | bit);
  56. }
  57. static int octeon_coreid_for_cpu(int cpu)
  58. {
  59. #ifdef CONFIG_SMP
  60. return cpu_logical_map(cpu);
  61. #else
  62. return cvmx_get_core_num();
  63. #endif
  64. }
  65. static int octeon_cpu_for_coreid(int coreid)
  66. {
  67. #ifdef CONFIG_SMP
  68. return cpu_number_map(coreid);
  69. #else
  70. return smp_processor_id();
  71. #endif
  72. }
  73. static void octeon_irq_core_ack(struct irq_data *data)
  74. {
  75. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  76. unsigned int bit = cd->bit;
  77. /*
  78. * We don't need to disable IRQs to make these atomic since
  79. * they are already disabled earlier in the low level
  80. * interrupt code.
  81. */
  82. clear_c0_status(0x100 << bit);
  83. /* The two user interrupts must be cleared manually. */
  84. if (bit < 2)
  85. clear_c0_cause(0x100 << bit);
  86. }
  87. static void octeon_irq_core_eoi(struct irq_data *data)
  88. {
  89. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  90. /*
  91. * We don't need to disable IRQs to make these atomic since
  92. * they are already disabled earlier in the low level
  93. * interrupt code.
  94. */
  95. set_c0_status(0x100 << cd->bit);
  96. }
  97. static void octeon_irq_core_set_enable_local(void *arg)
  98. {
  99. struct irq_data *data = arg;
  100. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  101. unsigned int mask = 0x100 << cd->bit;
  102. /*
  103. * Interrupts are already disabled, so these are atomic.
  104. */
  105. if (cd->desired_en)
  106. set_c0_status(mask);
  107. else
  108. clear_c0_status(mask);
  109. }
  110. static void octeon_irq_core_disable(struct irq_data *data)
  111. {
  112. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  113. cd->desired_en = false;
  114. }
  115. static void octeon_irq_core_enable(struct irq_data *data)
  116. {
  117. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  118. cd->desired_en = true;
  119. }
  120. static void octeon_irq_core_bus_lock(struct irq_data *data)
  121. {
  122. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  123. mutex_lock(&cd->core_irq_mutex);
  124. }
  125. static void octeon_irq_core_bus_sync_unlock(struct irq_data *data)
  126. {
  127. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  128. if (cd->desired_en != cd->current_en) {
  129. on_each_cpu(octeon_irq_core_set_enable_local, data, 1);
  130. cd->current_en = cd->desired_en;
  131. }
  132. mutex_unlock(&cd->core_irq_mutex);
  133. }
  134. static struct irq_chip octeon_irq_chip_core = {
  135. .name = "Core",
  136. .irq_enable = octeon_irq_core_enable,
  137. .irq_disable = octeon_irq_core_disable,
  138. .irq_ack = octeon_irq_core_ack,
  139. .irq_eoi = octeon_irq_core_eoi,
  140. .irq_bus_lock = octeon_irq_core_bus_lock,
  141. .irq_bus_sync_unlock = octeon_irq_core_bus_sync_unlock,
  142. .irq_cpu_online = octeon_irq_core_eoi,
  143. .irq_cpu_offline = octeon_irq_core_ack,
  144. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  145. };
  146. static void __init octeon_irq_init_core(void)
  147. {
  148. int i;
  149. int irq;
  150. struct octeon_core_chip_data *cd;
  151. for (i = 0; i < MIPS_CORE_IRQ_LINES; i++) {
  152. cd = &octeon_irq_core_chip_data[i];
  153. cd->current_en = false;
  154. cd->desired_en = false;
  155. cd->bit = i;
  156. mutex_init(&cd->core_irq_mutex);
  157. irq = OCTEON_IRQ_SW0 + i;
  158. irq_set_chip_data(irq, cd);
  159. irq_set_chip_and_handler(irq, &octeon_irq_chip_core,
  160. handle_percpu_irq);
  161. }
  162. }
  163. static int next_cpu_for_irq(struct irq_data *data)
  164. {
  165. #ifdef CONFIG_SMP
  166. int cpu;
  167. int weight = cpumask_weight(data->affinity);
  168. if (weight > 1) {
  169. cpu = smp_processor_id();
  170. for (;;) {
  171. cpu = cpumask_next(cpu, data->affinity);
  172. if (cpu >= nr_cpu_ids) {
  173. cpu = -1;
  174. continue;
  175. } else if (cpumask_test_cpu(cpu, cpu_online_mask)) {
  176. break;
  177. }
  178. }
  179. } else if (weight == 1) {
  180. cpu = cpumask_first(data->affinity);
  181. } else {
  182. cpu = smp_processor_id();
  183. }
  184. return cpu;
  185. #else
  186. return smp_processor_id();
  187. #endif
  188. }
  189. static void octeon_irq_ciu_enable(struct irq_data *data)
  190. {
  191. int cpu = next_cpu_for_irq(data);
  192. int coreid = octeon_coreid_for_cpu(cpu);
  193. unsigned long *pen;
  194. unsigned long flags;
  195. union octeon_ciu_chip_data cd;
  196. raw_spinlock_t *lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  197. cd.p = irq_data_get_irq_chip_data(data);
  198. raw_spin_lock_irqsave(lock, flags);
  199. if (cd.s.line == 0) {
  200. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  201. __set_bit(cd.s.bit, pen);
  202. /*
  203. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  204. * enabling the irq.
  205. */
  206. wmb();
  207. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  208. } else {
  209. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  210. __set_bit(cd.s.bit, pen);
  211. /*
  212. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  213. * enabling the irq.
  214. */
  215. wmb();
  216. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  217. }
  218. raw_spin_unlock_irqrestore(lock, flags);
  219. }
  220. static void octeon_irq_ciu_enable_local(struct irq_data *data)
  221. {
  222. unsigned long *pen;
  223. unsigned long flags;
  224. union octeon_ciu_chip_data cd;
  225. raw_spinlock_t *lock = &__get_cpu_var(octeon_irq_ciu_spinlock);
  226. cd.p = irq_data_get_irq_chip_data(data);
  227. raw_spin_lock_irqsave(lock, flags);
  228. if (cd.s.line == 0) {
  229. pen = &__get_cpu_var(octeon_irq_ciu0_en_mirror);
  230. __set_bit(cd.s.bit, pen);
  231. /*
  232. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  233. * enabling the irq.
  234. */
  235. wmb();
  236. cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
  237. } else {
  238. pen = &__get_cpu_var(octeon_irq_ciu1_en_mirror);
  239. __set_bit(cd.s.bit, pen);
  240. /*
  241. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  242. * enabling the irq.
  243. */
  244. wmb();
  245. cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
  246. }
  247. raw_spin_unlock_irqrestore(lock, flags);
  248. }
  249. static void octeon_irq_ciu_disable_local(struct irq_data *data)
  250. {
  251. unsigned long *pen;
  252. unsigned long flags;
  253. union octeon_ciu_chip_data cd;
  254. raw_spinlock_t *lock = &__get_cpu_var(octeon_irq_ciu_spinlock);
  255. cd.p = irq_data_get_irq_chip_data(data);
  256. raw_spin_lock_irqsave(lock, flags);
  257. if (cd.s.line == 0) {
  258. pen = &__get_cpu_var(octeon_irq_ciu0_en_mirror);
  259. __clear_bit(cd.s.bit, pen);
  260. /*
  261. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  262. * enabling the irq.
  263. */
  264. wmb();
  265. cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
  266. } else {
  267. pen = &__get_cpu_var(octeon_irq_ciu1_en_mirror);
  268. __clear_bit(cd.s.bit, pen);
  269. /*
  270. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  271. * enabling the irq.
  272. */
  273. wmb();
  274. cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
  275. }
  276. raw_spin_unlock_irqrestore(lock, flags);
  277. }
  278. static void octeon_irq_ciu_disable_all(struct irq_data *data)
  279. {
  280. unsigned long flags;
  281. unsigned long *pen;
  282. int cpu;
  283. union octeon_ciu_chip_data cd;
  284. raw_spinlock_t *lock;
  285. cd.p = irq_data_get_irq_chip_data(data);
  286. for_each_online_cpu(cpu) {
  287. int coreid = octeon_coreid_for_cpu(cpu);
  288. lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  289. if (cd.s.line == 0)
  290. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  291. else
  292. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  293. raw_spin_lock_irqsave(lock, flags);
  294. __clear_bit(cd.s.bit, pen);
  295. /*
  296. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  297. * enabling the irq.
  298. */
  299. wmb();
  300. if (cd.s.line == 0)
  301. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  302. else
  303. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  304. raw_spin_unlock_irqrestore(lock, flags);
  305. }
  306. }
  307. static void octeon_irq_ciu_enable_all(struct irq_data *data)
  308. {
  309. unsigned long flags;
  310. unsigned long *pen;
  311. int cpu;
  312. union octeon_ciu_chip_data cd;
  313. raw_spinlock_t *lock;
  314. cd.p = irq_data_get_irq_chip_data(data);
  315. for_each_online_cpu(cpu) {
  316. int coreid = octeon_coreid_for_cpu(cpu);
  317. lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  318. if (cd.s.line == 0)
  319. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  320. else
  321. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  322. raw_spin_lock_irqsave(lock, flags);
  323. __set_bit(cd.s.bit, pen);
  324. /*
  325. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  326. * enabling the irq.
  327. */
  328. wmb();
  329. if (cd.s.line == 0)
  330. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  331. else
  332. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  333. raw_spin_unlock_irqrestore(lock, flags);
  334. }
  335. }
  336. /*
  337. * Enable the irq on the next core in the affinity set for chips that
  338. * have the EN*_W1{S,C} registers.
  339. */
  340. static void octeon_irq_ciu_enable_v2(struct irq_data *data)
  341. {
  342. u64 mask;
  343. int cpu = next_cpu_for_irq(data);
  344. union octeon_ciu_chip_data cd;
  345. cd.p = irq_data_get_irq_chip_data(data);
  346. mask = 1ull << (cd.s.bit);
  347. /*
  348. * Called under the desc lock, so these should never get out
  349. * of sync.
  350. */
  351. if (cd.s.line == 0) {
  352. int index = octeon_coreid_for_cpu(cpu) * 2;
  353. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  354. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  355. } else {
  356. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  357. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  358. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  359. }
  360. }
  361. /*
  362. * Enable the irq on the current CPU for chips that
  363. * have the EN*_W1{S,C} registers.
  364. */
  365. static void octeon_irq_ciu_enable_local_v2(struct irq_data *data)
  366. {
  367. u64 mask;
  368. union octeon_ciu_chip_data cd;
  369. cd.p = irq_data_get_irq_chip_data(data);
  370. mask = 1ull << (cd.s.bit);
  371. if (cd.s.line == 0) {
  372. int index = cvmx_get_core_num() * 2;
  373. set_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu0_en_mirror));
  374. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  375. } else {
  376. int index = cvmx_get_core_num() * 2 + 1;
  377. set_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu1_en_mirror));
  378. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  379. }
  380. }
  381. static void octeon_irq_ciu_disable_local_v2(struct irq_data *data)
  382. {
  383. u64 mask;
  384. union octeon_ciu_chip_data cd;
  385. cd.p = irq_data_get_irq_chip_data(data);
  386. mask = 1ull << (cd.s.bit);
  387. if (cd.s.line == 0) {
  388. int index = cvmx_get_core_num() * 2;
  389. clear_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu0_en_mirror));
  390. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  391. } else {
  392. int index = cvmx_get_core_num() * 2 + 1;
  393. clear_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu1_en_mirror));
  394. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  395. }
  396. }
  397. /*
  398. * Write to the W1C bit in CVMX_CIU_INTX_SUM0 to clear the irq.
  399. */
  400. static void octeon_irq_ciu_ack(struct irq_data *data)
  401. {
  402. u64 mask;
  403. union octeon_ciu_chip_data cd;
  404. cd.p = irq_data_get_irq_chip_data(data);
  405. mask = 1ull << (cd.s.bit);
  406. if (cd.s.line == 0) {
  407. int index = cvmx_get_core_num() * 2;
  408. cvmx_write_csr(CVMX_CIU_INTX_SUM0(index), mask);
  409. } else {
  410. cvmx_write_csr(CVMX_CIU_INT_SUM1, mask);
  411. }
  412. }
  413. /*
  414. * Disable the irq on the all cores for chips that have the EN*_W1{S,C}
  415. * registers.
  416. */
  417. static void octeon_irq_ciu_disable_all_v2(struct irq_data *data)
  418. {
  419. int cpu;
  420. u64 mask;
  421. union octeon_ciu_chip_data cd;
  422. cd.p = irq_data_get_irq_chip_data(data);
  423. mask = 1ull << (cd.s.bit);
  424. if (cd.s.line == 0) {
  425. for_each_online_cpu(cpu) {
  426. int index = octeon_coreid_for_cpu(cpu) * 2;
  427. clear_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  428. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  429. }
  430. } else {
  431. for_each_online_cpu(cpu) {
  432. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  433. clear_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  434. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  435. }
  436. }
  437. }
  438. /*
  439. * Enable the irq on the all cores for chips that have the EN*_W1{S,C}
  440. * registers.
  441. */
  442. static void octeon_irq_ciu_enable_all_v2(struct irq_data *data)
  443. {
  444. int cpu;
  445. u64 mask;
  446. union octeon_ciu_chip_data cd;
  447. cd.p = irq_data_get_irq_chip_data(data);
  448. mask = 1ull << (cd.s.bit);
  449. if (cd.s.line == 0) {
  450. for_each_online_cpu(cpu) {
  451. int index = octeon_coreid_for_cpu(cpu) * 2;
  452. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  453. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  454. }
  455. } else {
  456. for_each_online_cpu(cpu) {
  457. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  458. set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  459. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  460. }
  461. }
  462. }
  463. static void octeon_irq_gpio_setup(struct irq_data *data)
  464. {
  465. union cvmx_gpio_bit_cfgx cfg;
  466. union octeon_ciu_chip_data cd;
  467. u32 t = irqd_get_trigger_type(data);
  468. cd.p = irq_data_get_irq_chip_data(data);
  469. cfg.u64 = 0;
  470. cfg.s.int_en = 1;
  471. cfg.s.int_type = (t & IRQ_TYPE_EDGE_BOTH) != 0;
  472. cfg.s.rx_xor = (t & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) != 0;
  473. /* 140 nS glitch filter*/
  474. cfg.s.fil_cnt = 7;
  475. cfg.s.fil_sel = 3;
  476. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), cfg.u64);
  477. }
  478. static void octeon_irq_ciu_enable_gpio_v2(struct irq_data *data)
  479. {
  480. octeon_irq_gpio_setup(data);
  481. octeon_irq_ciu_enable_v2(data);
  482. }
  483. static void octeon_irq_ciu_enable_gpio(struct irq_data *data)
  484. {
  485. octeon_irq_gpio_setup(data);
  486. octeon_irq_ciu_enable(data);
  487. }
  488. static int octeon_irq_ciu_gpio_set_type(struct irq_data *data, unsigned int t)
  489. {
  490. irqd_set_trigger_type(data, t);
  491. octeon_irq_gpio_setup(data);
  492. return IRQ_SET_MASK_OK;
  493. }
  494. static void octeon_irq_ciu_disable_gpio_v2(struct irq_data *data)
  495. {
  496. union octeon_ciu_chip_data cd;
  497. cd.p = irq_data_get_irq_chip_data(data);
  498. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
  499. octeon_irq_ciu_disable_all_v2(data);
  500. }
  501. static void octeon_irq_ciu_disable_gpio(struct irq_data *data)
  502. {
  503. union octeon_ciu_chip_data cd;
  504. cd.p = irq_data_get_irq_chip_data(data);
  505. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
  506. octeon_irq_ciu_disable_all(data);
  507. }
  508. static void octeon_irq_ciu_gpio_ack(struct irq_data *data)
  509. {
  510. union octeon_ciu_chip_data cd;
  511. u64 mask;
  512. cd.p = irq_data_get_irq_chip_data(data);
  513. mask = 1ull << (cd.s.gpio_line);
  514. cvmx_write_csr(CVMX_GPIO_INT_CLR, mask);
  515. }
  516. static void octeon_irq_handle_gpio(unsigned int irq, struct irq_desc *desc)
  517. {
  518. if (irqd_get_trigger_type(irq_desc_get_irq_data(desc)) & IRQ_TYPE_EDGE_BOTH)
  519. handle_edge_irq(irq, desc);
  520. else
  521. handle_level_irq(irq, desc);
  522. }
  523. #ifdef CONFIG_SMP
  524. static void octeon_irq_cpu_offline_ciu(struct irq_data *data)
  525. {
  526. int cpu = smp_processor_id();
  527. cpumask_t new_affinity;
  528. if (!cpumask_test_cpu(cpu, data->affinity))
  529. return;
  530. if (cpumask_weight(data->affinity) > 1) {
  531. /*
  532. * It has multi CPU affinity, just remove this CPU
  533. * from the affinity set.
  534. */
  535. cpumask_copy(&new_affinity, data->affinity);
  536. cpumask_clear_cpu(cpu, &new_affinity);
  537. } else {
  538. /* Otherwise, put it on lowest numbered online CPU. */
  539. cpumask_clear(&new_affinity);
  540. cpumask_set_cpu(cpumask_first(cpu_online_mask), &new_affinity);
  541. }
  542. __irq_set_affinity_locked(data, &new_affinity);
  543. }
  544. static int octeon_irq_ciu_set_affinity(struct irq_data *data,
  545. const struct cpumask *dest, bool force)
  546. {
  547. int cpu;
  548. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  549. unsigned long flags;
  550. union octeon_ciu_chip_data cd;
  551. unsigned long *pen;
  552. raw_spinlock_t *lock;
  553. cd.p = irq_data_get_irq_chip_data(data);
  554. /*
  555. * For non-v2 CIU, we will allow only single CPU affinity.
  556. * This removes the need to do locking in the .ack/.eoi
  557. * functions.
  558. */
  559. if (cpumask_weight(dest) != 1)
  560. return -EINVAL;
  561. if (!enable_one)
  562. return 0;
  563. for_each_online_cpu(cpu) {
  564. int coreid = octeon_coreid_for_cpu(cpu);
  565. lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  566. raw_spin_lock_irqsave(lock, flags);
  567. if (cd.s.line == 0)
  568. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  569. else
  570. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  571. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  572. enable_one = 0;
  573. __set_bit(cd.s.bit, pen);
  574. } else {
  575. __clear_bit(cd.s.bit, pen);
  576. }
  577. /*
  578. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  579. * enabling the irq.
  580. */
  581. wmb();
  582. if (cd.s.line == 0)
  583. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  584. else
  585. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  586. raw_spin_unlock_irqrestore(lock, flags);
  587. }
  588. return 0;
  589. }
  590. /*
  591. * Set affinity for the irq for chips that have the EN*_W1{S,C}
  592. * registers.
  593. */
  594. static int octeon_irq_ciu_set_affinity_v2(struct irq_data *data,
  595. const struct cpumask *dest,
  596. bool force)
  597. {
  598. int cpu;
  599. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  600. u64 mask;
  601. union octeon_ciu_chip_data cd;
  602. if (!enable_one)
  603. return 0;
  604. cd.p = irq_data_get_irq_chip_data(data);
  605. mask = 1ull << cd.s.bit;
  606. if (cd.s.line == 0) {
  607. for_each_online_cpu(cpu) {
  608. unsigned long *pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  609. int index = octeon_coreid_for_cpu(cpu) * 2;
  610. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  611. enable_one = false;
  612. set_bit(cd.s.bit, pen);
  613. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  614. } else {
  615. clear_bit(cd.s.bit, pen);
  616. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  617. }
  618. }
  619. } else {
  620. for_each_online_cpu(cpu) {
  621. unsigned long *pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  622. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  623. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  624. enable_one = false;
  625. set_bit(cd.s.bit, pen);
  626. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  627. } else {
  628. clear_bit(cd.s.bit, pen);
  629. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  630. }
  631. }
  632. }
  633. return 0;
  634. }
  635. #endif
  636. /*
  637. * Newer octeon chips have support for lockless CIU operation.
  638. */
  639. static struct irq_chip octeon_irq_chip_ciu_v2 = {
  640. .name = "CIU",
  641. .irq_enable = octeon_irq_ciu_enable_v2,
  642. .irq_disable = octeon_irq_ciu_disable_all_v2,
  643. .irq_ack = octeon_irq_ciu_ack,
  644. .irq_mask = octeon_irq_ciu_disable_local_v2,
  645. .irq_unmask = octeon_irq_ciu_enable_v2,
  646. #ifdef CONFIG_SMP
  647. .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
  648. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  649. #endif
  650. };
  651. static struct irq_chip octeon_irq_chip_ciu = {
  652. .name = "CIU",
  653. .irq_enable = octeon_irq_ciu_enable,
  654. .irq_disable = octeon_irq_ciu_disable_all,
  655. .irq_ack = octeon_irq_ciu_ack,
  656. .irq_mask = octeon_irq_ciu_disable_local,
  657. .irq_unmask = octeon_irq_ciu_enable,
  658. #ifdef CONFIG_SMP
  659. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  660. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  661. #endif
  662. };
  663. /* The mbox versions don't do any affinity or round-robin. */
  664. static struct irq_chip octeon_irq_chip_ciu_mbox_v2 = {
  665. .name = "CIU-M",
  666. .irq_enable = octeon_irq_ciu_enable_all_v2,
  667. .irq_disable = octeon_irq_ciu_disable_all_v2,
  668. .irq_ack = octeon_irq_ciu_disable_local_v2,
  669. .irq_eoi = octeon_irq_ciu_enable_local_v2,
  670. .irq_cpu_online = octeon_irq_ciu_enable_local_v2,
  671. .irq_cpu_offline = octeon_irq_ciu_disable_local_v2,
  672. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  673. };
  674. static struct irq_chip octeon_irq_chip_ciu_mbox = {
  675. .name = "CIU-M",
  676. .irq_enable = octeon_irq_ciu_enable_all,
  677. .irq_disable = octeon_irq_ciu_disable_all,
  678. .irq_ack = octeon_irq_ciu_disable_local,
  679. .irq_eoi = octeon_irq_ciu_enable_local,
  680. .irq_cpu_online = octeon_irq_ciu_enable_local,
  681. .irq_cpu_offline = octeon_irq_ciu_disable_local,
  682. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  683. };
  684. static struct irq_chip octeon_irq_chip_ciu_gpio_v2 = {
  685. .name = "CIU-GPIO",
  686. .irq_enable = octeon_irq_ciu_enable_gpio_v2,
  687. .irq_disable = octeon_irq_ciu_disable_gpio_v2,
  688. .irq_ack = octeon_irq_ciu_gpio_ack,
  689. .irq_mask = octeon_irq_ciu_disable_local_v2,
  690. .irq_unmask = octeon_irq_ciu_enable_v2,
  691. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  692. #ifdef CONFIG_SMP
  693. .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
  694. #endif
  695. .flags = IRQCHIP_SET_TYPE_MASKED,
  696. };
  697. static struct irq_chip octeon_irq_chip_ciu_gpio = {
  698. .name = "CIU-GPIO",
  699. .irq_enable = octeon_irq_ciu_enable_gpio,
  700. .irq_disable = octeon_irq_ciu_disable_gpio,
  701. .irq_mask = octeon_irq_ciu_disable_local,
  702. .irq_unmask = octeon_irq_ciu_enable,
  703. .irq_ack = octeon_irq_ciu_gpio_ack,
  704. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  705. #ifdef CONFIG_SMP
  706. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  707. #endif
  708. .flags = IRQCHIP_SET_TYPE_MASKED,
  709. };
  710. /*
  711. * Watchdog interrupts are special. They are associated with a single
  712. * core, so we hardwire the affinity to that core.
  713. */
  714. static void octeon_irq_ciu_wd_enable(struct irq_data *data)
  715. {
  716. unsigned long flags;
  717. unsigned long *pen;
  718. int coreid = data->irq - OCTEON_IRQ_WDOG0; /* Bit 0-63 of EN1 */
  719. int cpu = octeon_cpu_for_coreid(coreid);
  720. raw_spinlock_t *lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  721. raw_spin_lock_irqsave(lock, flags);
  722. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  723. __set_bit(coreid, pen);
  724. /*
  725. * Must be visible to octeon_irq_ip{2,3}_ciu() before enabling
  726. * the irq.
  727. */
  728. wmb();
  729. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  730. raw_spin_unlock_irqrestore(lock, flags);
  731. }
  732. /*
  733. * Watchdog interrupts are special. They are associated with a single
  734. * core, so we hardwire the affinity to that core.
  735. */
  736. static void octeon_irq_ciu1_wd_enable_v2(struct irq_data *data)
  737. {
  738. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  739. int cpu = octeon_cpu_for_coreid(coreid);
  740. set_bit(coreid, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  741. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(coreid * 2 + 1), 1ull << coreid);
  742. }
  743. static struct irq_chip octeon_irq_chip_ciu_wd_v2 = {
  744. .name = "CIU-W",
  745. .irq_enable = octeon_irq_ciu1_wd_enable_v2,
  746. .irq_disable = octeon_irq_ciu_disable_all_v2,
  747. .irq_mask = octeon_irq_ciu_disable_local_v2,
  748. .irq_unmask = octeon_irq_ciu_enable_local_v2,
  749. };
  750. static struct irq_chip octeon_irq_chip_ciu_wd = {
  751. .name = "CIU-W",
  752. .irq_enable = octeon_irq_ciu_wd_enable,
  753. .irq_disable = octeon_irq_ciu_disable_all,
  754. .irq_mask = octeon_irq_ciu_disable_local,
  755. .irq_unmask = octeon_irq_ciu_enable_local,
  756. };
  757. static bool octeon_irq_ciu_is_edge(unsigned int line, unsigned int bit)
  758. {
  759. bool edge = false;
  760. if (line == 0)
  761. switch (bit) {
  762. case 48 ... 49: /* GMX DRP */
  763. case 50: /* IPD_DRP */
  764. case 52 ... 55: /* Timers */
  765. case 58: /* MPI */
  766. edge = true;
  767. break;
  768. default:
  769. break;
  770. }
  771. else /* line == 1 */
  772. switch (bit) {
  773. case 47: /* PTP */
  774. edge = true;
  775. break;
  776. default:
  777. break;
  778. }
  779. return edge;
  780. }
  781. struct octeon_irq_gpio_domain_data {
  782. unsigned int base_hwirq;
  783. };
  784. static int octeon_irq_gpio_xlat(struct irq_domain *d,
  785. struct device_node *node,
  786. const u32 *intspec,
  787. unsigned int intsize,
  788. unsigned long *out_hwirq,
  789. unsigned int *out_type)
  790. {
  791. unsigned int type;
  792. unsigned int pin;
  793. unsigned int trigger;
  794. if (d->of_node != node)
  795. return -EINVAL;
  796. if (intsize < 2)
  797. return -EINVAL;
  798. pin = intspec[0];
  799. if (pin >= 16)
  800. return -EINVAL;
  801. trigger = intspec[1];
  802. switch (trigger) {
  803. case 1:
  804. type = IRQ_TYPE_EDGE_RISING;
  805. break;
  806. case 2:
  807. type = IRQ_TYPE_EDGE_FALLING;
  808. break;
  809. case 4:
  810. type = IRQ_TYPE_LEVEL_HIGH;
  811. break;
  812. case 8:
  813. type = IRQ_TYPE_LEVEL_LOW;
  814. break;
  815. default:
  816. pr_err("Error: (%s) Invalid irq trigger specification: %x\n",
  817. node->name,
  818. trigger);
  819. type = IRQ_TYPE_LEVEL_LOW;
  820. break;
  821. }
  822. *out_type = type;
  823. *out_hwirq = pin;
  824. return 0;
  825. }
  826. static int octeon_irq_ciu_xlat(struct irq_domain *d,
  827. struct device_node *node,
  828. const u32 *intspec,
  829. unsigned int intsize,
  830. unsigned long *out_hwirq,
  831. unsigned int *out_type)
  832. {
  833. unsigned int ciu, bit;
  834. ciu = intspec[0];
  835. bit = intspec[1];
  836. if (ciu > 1 || bit > 63)
  837. return -EINVAL;
  838. /* These are the GPIO lines */
  839. if (ciu == 0 && bit >= 16 && bit < 32)
  840. return -EINVAL;
  841. *out_hwirq = (ciu << 6) | bit;
  842. *out_type = 0;
  843. return 0;
  844. }
  845. static struct irq_chip *octeon_irq_ciu_chip;
  846. static struct irq_chip *octeon_irq_gpio_chip;
  847. static bool octeon_irq_virq_in_range(unsigned int virq)
  848. {
  849. /* We cannot let it overflow the mapping array. */
  850. if (virq < (1ul << 8 * sizeof(octeon_irq_ciu_to_irq[0][0])))
  851. return true;
  852. WARN_ONCE(true, "virq out of range %u.\n", virq);
  853. return false;
  854. }
  855. static int octeon_irq_ciu_map(struct irq_domain *d,
  856. unsigned int virq, irq_hw_number_t hw)
  857. {
  858. unsigned int line = hw >> 6;
  859. unsigned int bit = hw & 63;
  860. if (!octeon_irq_virq_in_range(virq))
  861. return -EINVAL;
  862. if (line > 1 || octeon_irq_ciu_to_irq[line][bit] != 0)
  863. return -EINVAL;
  864. if (octeon_irq_ciu_is_edge(line, bit))
  865. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  866. octeon_irq_ciu_chip,
  867. handle_edge_irq);
  868. else
  869. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  870. octeon_irq_ciu_chip,
  871. handle_level_irq);
  872. return 0;
  873. }
  874. static int octeon_irq_gpio_map_common(struct irq_domain *d,
  875. unsigned int virq, irq_hw_number_t hw,
  876. int line_limit, struct irq_chip *chip)
  877. {
  878. struct octeon_irq_gpio_domain_data *gpiod = d->host_data;
  879. unsigned int line, bit;
  880. if (!octeon_irq_virq_in_range(virq))
  881. return -EINVAL;
  882. hw += gpiod->base_hwirq;
  883. line = hw >> 6;
  884. bit = hw & 63;
  885. if (line > line_limit || octeon_irq_ciu_to_irq[line][bit] != 0)
  886. return -EINVAL;
  887. octeon_irq_set_ciu_mapping(virq, line, bit, hw,
  888. chip, octeon_irq_handle_gpio);
  889. return 0;
  890. }
  891. static int octeon_irq_gpio_map(struct irq_domain *d,
  892. unsigned int virq, irq_hw_number_t hw)
  893. {
  894. return octeon_irq_gpio_map_common(d, virq, hw, 1, octeon_irq_gpio_chip);
  895. }
  896. static struct irq_domain_ops octeon_irq_domain_ciu_ops = {
  897. .map = octeon_irq_ciu_map,
  898. .xlate = octeon_irq_ciu_xlat,
  899. };
  900. static struct irq_domain_ops octeon_irq_domain_gpio_ops = {
  901. .map = octeon_irq_gpio_map,
  902. .xlate = octeon_irq_gpio_xlat,
  903. };
  904. static void octeon_irq_ip2_ciu(void)
  905. {
  906. const unsigned long core_id = cvmx_get_core_num();
  907. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(core_id * 2));
  908. ciu_sum &= __get_cpu_var(octeon_irq_ciu0_en_mirror);
  909. if (likely(ciu_sum)) {
  910. int bit = fls64(ciu_sum) - 1;
  911. int irq = octeon_irq_ciu_to_irq[0][bit];
  912. if (likely(irq))
  913. do_IRQ(irq);
  914. else
  915. spurious_interrupt();
  916. } else {
  917. spurious_interrupt();
  918. }
  919. }
  920. static void octeon_irq_ip3_ciu(void)
  921. {
  922. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
  923. ciu_sum &= __get_cpu_var(octeon_irq_ciu1_en_mirror);
  924. if (likely(ciu_sum)) {
  925. int bit = fls64(ciu_sum) - 1;
  926. int irq = octeon_irq_ciu_to_irq[1][bit];
  927. if (likely(irq))
  928. do_IRQ(irq);
  929. else
  930. spurious_interrupt();
  931. } else {
  932. spurious_interrupt();
  933. }
  934. }
  935. static bool octeon_irq_use_ip4;
  936. static void __cpuinit octeon_irq_local_enable_ip4(void *arg)
  937. {
  938. set_c0_status(STATUSF_IP4);
  939. }
  940. static void octeon_irq_ip4_mask(void)
  941. {
  942. clear_c0_status(STATUSF_IP4);
  943. spurious_interrupt();
  944. }
  945. static void (*octeon_irq_ip2)(void);
  946. static void (*octeon_irq_ip3)(void);
  947. static void (*octeon_irq_ip4)(void);
  948. void __cpuinitdata (*octeon_irq_setup_secondary)(void);
  949. void __cpuinit octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t h)
  950. {
  951. octeon_irq_ip4 = h;
  952. octeon_irq_use_ip4 = true;
  953. on_each_cpu(octeon_irq_local_enable_ip4, NULL, 1);
  954. }
  955. static void __cpuinit octeon_irq_percpu_enable(void)
  956. {
  957. irq_cpu_online();
  958. }
  959. static void __cpuinit octeon_irq_init_ciu_percpu(void)
  960. {
  961. int coreid = cvmx_get_core_num();
  962. __get_cpu_var(octeon_irq_ciu0_en_mirror) = 0;
  963. __get_cpu_var(octeon_irq_ciu1_en_mirror) = 0;
  964. wmb();
  965. raw_spin_lock_init(&__get_cpu_var(octeon_irq_ciu_spinlock));
  966. /*
  967. * Disable All CIU Interrupts. The ones we need will be
  968. * enabled later. Read the SUM register so we know the write
  969. * completed.
  970. */
  971. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2)), 0);
  972. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2 + 1)), 0);
  973. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2)), 0);
  974. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2 + 1)), 0);
  975. cvmx_read_csr(CVMX_CIU_INTX_SUM0((coreid * 2)));
  976. }
  977. static void octeon_irq_init_ciu2_percpu(void)
  978. {
  979. u64 regx, ipx;
  980. int coreid = cvmx_get_core_num();
  981. u64 base = CVMX_CIU2_EN_PPX_IP2_WRKQ(coreid);
  982. /*
  983. * Disable All CIU2 Interrupts. The ones we need will be
  984. * enabled later. Read the SUM register so we know the write
  985. * completed.
  986. *
  987. * There are 9 registers and 3 IPX levels with strides 0x1000
  988. * and 0x200 respectivly. Use loops to clear them.
  989. */
  990. for (regx = 0; regx <= 0x8000; regx += 0x1000) {
  991. for (ipx = 0; ipx <= 0x400; ipx += 0x200)
  992. cvmx_write_csr(base + regx + ipx, 0);
  993. }
  994. cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid));
  995. }
  996. static void __cpuinit octeon_irq_setup_secondary_ciu(void)
  997. {
  998. octeon_irq_init_ciu_percpu();
  999. octeon_irq_percpu_enable();
  1000. /* Enable the CIU lines */
  1001. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1002. clear_c0_status(STATUSF_IP4);
  1003. }
  1004. static void octeon_irq_setup_secondary_ciu2(void)
  1005. {
  1006. octeon_irq_init_ciu2_percpu();
  1007. octeon_irq_percpu_enable();
  1008. /* Enable the CIU lines */
  1009. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1010. if (octeon_irq_use_ip4)
  1011. set_c0_status(STATUSF_IP4);
  1012. else
  1013. clear_c0_status(STATUSF_IP4);
  1014. }
  1015. static void __init octeon_irq_init_ciu(void)
  1016. {
  1017. unsigned int i;
  1018. struct irq_chip *chip;
  1019. struct irq_chip *chip_mbox;
  1020. struct irq_chip *chip_wd;
  1021. struct device_node *gpio_node;
  1022. struct device_node *ciu_node;
  1023. struct irq_domain *ciu_domain = NULL;
  1024. octeon_irq_init_ciu_percpu();
  1025. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu;
  1026. octeon_irq_ip2 = octeon_irq_ip2_ciu;
  1027. octeon_irq_ip3 = octeon_irq_ip3_ciu;
  1028. if (OCTEON_IS_MODEL(OCTEON_CN58XX_PASS2_X) ||
  1029. OCTEON_IS_MODEL(OCTEON_CN56XX_PASS2_X) ||
  1030. OCTEON_IS_MODEL(OCTEON_CN52XX_PASS2_X) ||
  1031. OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
  1032. chip = &octeon_irq_chip_ciu_v2;
  1033. chip_mbox = &octeon_irq_chip_ciu_mbox_v2;
  1034. chip_wd = &octeon_irq_chip_ciu_wd_v2;
  1035. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio_v2;
  1036. } else {
  1037. chip = &octeon_irq_chip_ciu;
  1038. chip_mbox = &octeon_irq_chip_ciu_mbox;
  1039. chip_wd = &octeon_irq_chip_ciu_wd;
  1040. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio;
  1041. }
  1042. octeon_irq_ciu_chip = chip;
  1043. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1044. /* Mips internal */
  1045. octeon_irq_init_core();
  1046. gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
  1047. if (gpio_node) {
  1048. struct octeon_irq_gpio_domain_data *gpiod;
  1049. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1050. if (gpiod) {
  1051. /* gpio domain host_data is the base hwirq number. */
  1052. gpiod->base_hwirq = 16;
  1053. irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_gpio_ops, gpiod);
  1054. of_node_put(gpio_node);
  1055. } else
  1056. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1057. } else
  1058. pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
  1059. ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-ciu");
  1060. if (ciu_node) {
  1061. ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu_ops, NULL);
  1062. irq_set_default_host(ciu_domain);
  1063. of_node_put(ciu_node);
  1064. } else
  1065. panic("Cannot find device node for cavium,octeon-3860-ciu.");
  1066. /* CIU_0 */
  1067. for (i = 0; i < 16; i++)
  1068. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i + 0);
  1069. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX0, 0, 32, 0, chip_mbox, handle_percpu_irq);
  1070. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX1, 0, 33, 0, chip_mbox, handle_percpu_irq);
  1071. for (i = 0; i < 4; i++)
  1072. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 0, i + 36);
  1073. for (i = 0; i < 4; i++)
  1074. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 0, i + 40);
  1075. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_RML, 0, 46);
  1076. for (i = 0; i < 4; i++)
  1077. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 0, i + 52);
  1078. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 0, 56);
  1079. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_BOOTDMA, 0, 63);
  1080. /* CIU_1 */
  1081. for (i = 0; i < 16; i++)
  1082. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i + 0, 0, chip_wd, handle_level_irq);
  1083. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB1, 1, 17);
  1084. /* Enable the CIU lines */
  1085. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1086. clear_c0_status(STATUSF_IP4);
  1087. }
  1088. /*
  1089. * Watchdog interrupts are special. They are associated with a single
  1090. * core, so we hardwire the affinity to that core.
  1091. */
  1092. static void octeon_irq_ciu2_wd_enable(struct irq_data *data)
  1093. {
  1094. u64 mask;
  1095. u64 en_addr;
  1096. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  1097. union octeon_ciu_chip_data cd;
  1098. cd.p = irq_data_get_irq_chip_data(data);
  1099. mask = 1ull << (cd.s.bit);
  1100. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1101. cvmx_write_csr(en_addr, mask);
  1102. }
  1103. static void octeon_irq_ciu2_enable(struct irq_data *data)
  1104. {
  1105. u64 mask;
  1106. u64 en_addr;
  1107. int cpu = next_cpu_for_irq(data);
  1108. int coreid = octeon_coreid_for_cpu(cpu);
  1109. union octeon_ciu_chip_data cd;
  1110. cd.p = irq_data_get_irq_chip_data(data);
  1111. mask = 1ull << (cd.s.bit);
  1112. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1113. cvmx_write_csr(en_addr, mask);
  1114. }
  1115. static void octeon_irq_ciu2_enable_local(struct irq_data *data)
  1116. {
  1117. u64 mask;
  1118. u64 en_addr;
  1119. int coreid = cvmx_get_core_num();
  1120. union octeon_ciu_chip_data cd;
  1121. cd.p = irq_data_get_irq_chip_data(data);
  1122. mask = 1ull << (cd.s.bit);
  1123. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1124. cvmx_write_csr(en_addr, mask);
  1125. }
  1126. static void octeon_irq_ciu2_disable_local(struct irq_data *data)
  1127. {
  1128. u64 mask;
  1129. u64 en_addr;
  1130. int coreid = cvmx_get_core_num();
  1131. union octeon_ciu_chip_data cd;
  1132. cd.p = irq_data_get_irq_chip_data(data);
  1133. mask = 1ull << (cd.s.bit);
  1134. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(coreid) + (0x1000ull * cd.s.line);
  1135. cvmx_write_csr(en_addr, mask);
  1136. }
  1137. static void octeon_irq_ciu2_ack(struct irq_data *data)
  1138. {
  1139. u64 mask;
  1140. u64 en_addr;
  1141. int coreid = cvmx_get_core_num();
  1142. union octeon_ciu_chip_data cd;
  1143. cd.p = irq_data_get_irq_chip_data(data);
  1144. mask = 1ull << (cd.s.bit);
  1145. en_addr = CVMX_CIU2_RAW_PPX_IP2_WRKQ(coreid) + (0x1000ull * cd.s.line);
  1146. cvmx_write_csr(en_addr, mask);
  1147. }
  1148. static void octeon_irq_ciu2_disable_all(struct irq_data *data)
  1149. {
  1150. int cpu;
  1151. u64 mask;
  1152. union octeon_ciu_chip_data cd;
  1153. cd.p = irq_data_get_irq_chip_data(data);
  1154. mask = 1ull << (cd.s.bit);
  1155. for_each_online_cpu(cpu) {
  1156. u64 en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1157. cvmx_write_csr(en_addr, mask);
  1158. }
  1159. }
  1160. static void octeon_irq_ciu2_mbox_enable_all(struct irq_data *data)
  1161. {
  1162. int cpu;
  1163. u64 mask;
  1164. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1165. for_each_online_cpu(cpu) {
  1166. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(octeon_coreid_for_cpu(cpu));
  1167. cvmx_write_csr(en_addr, mask);
  1168. }
  1169. }
  1170. static void octeon_irq_ciu2_mbox_disable_all(struct irq_data *data)
  1171. {
  1172. int cpu;
  1173. u64 mask;
  1174. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1175. for_each_online_cpu(cpu) {
  1176. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(octeon_coreid_for_cpu(cpu));
  1177. cvmx_write_csr(en_addr, mask);
  1178. }
  1179. }
  1180. static void octeon_irq_ciu2_mbox_enable_local(struct irq_data *data)
  1181. {
  1182. u64 mask;
  1183. u64 en_addr;
  1184. int coreid = cvmx_get_core_num();
  1185. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1186. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(coreid);
  1187. cvmx_write_csr(en_addr, mask);
  1188. }
  1189. static void octeon_irq_ciu2_mbox_disable_local(struct irq_data *data)
  1190. {
  1191. u64 mask;
  1192. u64 en_addr;
  1193. int coreid = cvmx_get_core_num();
  1194. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1195. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(coreid);
  1196. cvmx_write_csr(en_addr, mask);
  1197. }
  1198. #ifdef CONFIG_SMP
  1199. static int octeon_irq_ciu2_set_affinity(struct irq_data *data,
  1200. const struct cpumask *dest, bool force)
  1201. {
  1202. int cpu;
  1203. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  1204. u64 mask;
  1205. union octeon_ciu_chip_data cd;
  1206. if (!enable_one)
  1207. return 0;
  1208. cd.p = irq_data_get_irq_chip_data(data);
  1209. mask = 1ull << cd.s.bit;
  1210. for_each_online_cpu(cpu) {
  1211. u64 en_addr;
  1212. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  1213. enable_one = false;
  1214. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1215. } else {
  1216. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1217. }
  1218. cvmx_write_csr(en_addr, mask);
  1219. }
  1220. return 0;
  1221. }
  1222. #endif
  1223. static void octeon_irq_ciu2_enable_gpio(struct irq_data *data)
  1224. {
  1225. octeon_irq_gpio_setup(data);
  1226. octeon_irq_ciu2_enable(data);
  1227. }
  1228. static void octeon_irq_ciu2_disable_gpio(struct irq_data *data)
  1229. {
  1230. union octeon_ciu_chip_data cd;
  1231. cd.p = irq_data_get_irq_chip_data(data);
  1232. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
  1233. octeon_irq_ciu2_disable_all(data);
  1234. }
  1235. static struct irq_chip octeon_irq_chip_ciu2 = {
  1236. .name = "CIU2-E",
  1237. .irq_enable = octeon_irq_ciu2_enable,
  1238. .irq_disable = octeon_irq_ciu2_disable_all,
  1239. .irq_ack = octeon_irq_ciu2_ack,
  1240. .irq_mask = octeon_irq_ciu2_disable_local,
  1241. .irq_unmask = octeon_irq_ciu2_enable,
  1242. #ifdef CONFIG_SMP
  1243. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1244. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1245. #endif
  1246. };
  1247. static struct irq_chip octeon_irq_chip_ciu2_mbox = {
  1248. .name = "CIU2-M",
  1249. .irq_enable = octeon_irq_ciu2_mbox_enable_all,
  1250. .irq_disable = octeon_irq_ciu2_mbox_disable_all,
  1251. .irq_ack = octeon_irq_ciu2_mbox_disable_local,
  1252. .irq_eoi = octeon_irq_ciu2_mbox_enable_local,
  1253. .irq_cpu_online = octeon_irq_ciu2_mbox_enable_local,
  1254. .irq_cpu_offline = octeon_irq_ciu2_mbox_disable_local,
  1255. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  1256. };
  1257. static struct irq_chip octeon_irq_chip_ciu2_wd = {
  1258. .name = "CIU2-W",
  1259. .irq_enable = octeon_irq_ciu2_wd_enable,
  1260. .irq_disable = octeon_irq_ciu2_disable_all,
  1261. .irq_mask = octeon_irq_ciu2_disable_local,
  1262. .irq_unmask = octeon_irq_ciu2_enable_local,
  1263. };
  1264. static struct irq_chip octeon_irq_chip_ciu2_gpio = {
  1265. .name = "CIU-GPIO",
  1266. .irq_enable = octeon_irq_ciu2_enable_gpio,
  1267. .irq_disable = octeon_irq_ciu2_disable_gpio,
  1268. .irq_ack = octeon_irq_ciu_gpio_ack,
  1269. .irq_mask = octeon_irq_ciu2_disable_local,
  1270. .irq_unmask = octeon_irq_ciu2_enable,
  1271. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  1272. #ifdef CONFIG_SMP
  1273. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1274. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1275. #endif
  1276. .flags = IRQCHIP_SET_TYPE_MASKED,
  1277. };
  1278. static int octeon_irq_ciu2_xlat(struct irq_domain *d,
  1279. struct device_node *node,
  1280. const u32 *intspec,
  1281. unsigned int intsize,
  1282. unsigned long *out_hwirq,
  1283. unsigned int *out_type)
  1284. {
  1285. unsigned int ciu, bit;
  1286. ciu = intspec[0];
  1287. bit = intspec[1];
  1288. /* Line 7 are the GPIO lines */
  1289. if (ciu > 6 || bit > 63)
  1290. return -EINVAL;
  1291. *out_hwirq = (ciu << 6) | bit;
  1292. *out_type = 0;
  1293. return 0;
  1294. }
  1295. static bool octeon_irq_ciu2_is_edge(unsigned int line, unsigned int bit)
  1296. {
  1297. bool edge = false;
  1298. if (line == 3) /* MIO */
  1299. switch (bit) {
  1300. case 2: /* IPD_DRP */
  1301. case 8 ... 11: /* Timers */
  1302. case 48: /* PTP */
  1303. edge = true;
  1304. break;
  1305. default:
  1306. break;
  1307. }
  1308. else if (line == 6) /* PKT */
  1309. switch (bit) {
  1310. case 52 ... 53: /* ILK_DRP */
  1311. case 8 ... 12: /* GMX_DRP */
  1312. edge = true;
  1313. break;
  1314. default:
  1315. break;
  1316. }
  1317. return edge;
  1318. }
  1319. static int octeon_irq_ciu2_map(struct irq_domain *d,
  1320. unsigned int virq, irq_hw_number_t hw)
  1321. {
  1322. unsigned int line = hw >> 6;
  1323. unsigned int bit = hw & 63;
  1324. if (!octeon_irq_virq_in_range(virq))
  1325. return -EINVAL;
  1326. /* Line 7 are the GPIO lines */
  1327. if (line > 6 || octeon_irq_ciu_to_irq[line][bit] != 0)
  1328. return -EINVAL;
  1329. if (octeon_irq_ciu2_is_edge(line, bit))
  1330. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1331. &octeon_irq_chip_ciu2,
  1332. handle_edge_irq);
  1333. else
  1334. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1335. &octeon_irq_chip_ciu2,
  1336. handle_level_irq);
  1337. return 0;
  1338. }
  1339. static int octeon_irq_ciu2_gpio_map(struct irq_domain *d,
  1340. unsigned int virq, irq_hw_number_t hw)
  1341. {
  1342. return octeon_irq_gpio_map_common(d, virq, hw, 7, &octeon_irq_chip_ciu2_gpio);
  1343. }
  1344. static struct irq_domain_ops octeon_irq_domain_ciu2_ops = {
  1345. .map = octeon_irq_ciu2_map,
  1346. .xlate = octeon_irq_ciu2_xlat,
  1347. };
  1348. static struct irq_domain_ops octeon_irq_domain_ciu2_gpio_ops = {
  1349. .map = octeon_irq_ciu2_gpio_map,
  1350. .xlate = octeon_irq_gpio_xlat,
  1351. };
  1352. static void octeon_irq_ciu2(void)
  1353. {
  1354. int line;
  1355. int bit;
  1356. int irq;
  1357. u64 src_reg, src, sum;
  1358. const unsigned long core_id = cvmx_get_core_num();
  1359. sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(core_id)) & 0xfful;
  1360. if (unlikely(!sum))
  1361. goto spurious;
  1362. line = fls64(sum) - 1;
  1363. src_reg = CVMX_CIU2_SRC_PPX_IP2_WRKQ(core_id) + (0x1000 * line);
  1364. src = cvmx_read_csr(src_reg);
  1365. if (unlikely(!src))
  1366. goto spurious;
  1367. bit = fls64(src) - 1;
  1368. irq = octeon_irq_ciu_to_irq[line][bit];
  1369. if (unlikely(!irq))
  1370. goto spurious;
  1371. do_IRQ(irq);
  1372. goto out;
  1373. spurious:
  1374. spurious_interrupt();
  1375. out:
  1376. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1377. can stop interrupts from propagating */
  1378. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1379. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1380. else
  1381. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP2(core_id));
  1382. return;
  1383. }
  1384. static void octeon_irq_ciu2_mbox(void)
  1385. {
  1386. int line;
  1387. const unsigned long core_id = cvmx_get_core_num();
  1388. u64 sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP3(core_id)) >> 60;
  1389. if (unlikely(!sum))
  1390. goto spurious;
  1391. line = fls64(sum) - 1;
  1392. do_IRQ(OCTEON_IRQ_MBOX0 + line);
  1393. goto out;
  1394. spurious:
  1395. spurious_interrupt();
  1396. out:
  1397. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1398. can stop interrupts from propagating */
  1399. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1400. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1401. else
  1402. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP3(core_id));
  1403. return;
  1404. }
  1405. static void __init octeon_irq_init_ciu2(void)
  1406. {
  1407. unsigned int i;
  1408. struct device_node *gpio_node;
  1409. struct device_node *ciu_node;
  1410. struct irq_domain *ciu_domain = NULL;
  1411. octeon_irq_init_ciu2_percpu();
  1412. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu2;
  1413. octeon_irq_ip2 = octeon_irq_ciu2;
  1414. octeon_irq_ip3 = octeon_irq_ciu2_mbox;
  1415. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1416. /* Mips internal */
  1417. octeon_irq_init_core();
  1418. gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
  1419. if (gpio_node) {
  1420. struct octeon_irq_gpio_domain_data *gpiod;
  1421. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1422. if (gpiod) {
  1423. /* gpio domain host_data is the base hwirq number. */
  1424. gpiod->base_hwirq = 7 << 6;
  1425. irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_ciu2_gpio_ops, gpiod);
  1426. of_node_put(gpio_node);
  1427. } else
  1428. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1429. } else
  1430. pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
  1431. ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-6880-ciu2");
  1432. if (ciu_node) {
  1433. ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu2_ops, NULL);
  1434. irq_set_default_host(ciu_domain);
  1435. of_node_put(ciu_node);
  1436. } else
  1437. panic("Cannot find device node for cavium,octeon-6880-ciu2.");
  1438. /* CUI2 */
  1439. for (i = 0; i < 64; i++)
  1440. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i);
  1441. for (i = 0; i < 32; i++)
  1442. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i, 0,
  1443. &octeon_irq_chip_ciu2_wd, handle_level_irq);
  1444. for (i = 0; i < 4; i++)
  1445. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 3, i + 8);
  1446. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 3, 44);
  1447. for (i = 0; i < 4; i++)
  1448. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 4, i);
  1449. for (i = 0; i < 4; i++)
  1450. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 4, i + 8);
  1451. irq_set_chip_and_handler(OCTEON_IRQ_MBOX0, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1452. irq_set_chip_and_handler(OCTEON_IRQ_MBOX1, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1453. irq_set_chip_and_handler(OCTEON_IRQ_MBOX2, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1454. irq_set_chip_and_handler(OCTEON_IRQ_MBOX3, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1455. /* Enable the CIU lines */
  1456. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1457. clear_c0_status(STATUSF_IP4);
  1458. }
  1459. void __init arch_init_irq(void)
  1460. {
  1461. #ifdef CONFIG_SMP
  1462. /* Set the default affinity to the boot cpu. */
  1463. cpumask_clear(irq_default_affinity);
  1464. cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
  1465. #endif
  1466. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1467. octeon_irq_init_ciu2();
  1468. else
  1469. octeon_irq_init_ciu();
  1470. }
  1471. asmlinkage void plat_irq_dispatch(void)
  1472. {
  1473. unsigned long cop0_cause;
  1474. unsigned long cop0_status;
  1475. while (1) {
  1476. cop0_cause = read_c0_cause();
  1477. cop0_status = read_c0_status();
  1478. cop0_cause &= cop0_status;
  1479. cop0_cause &= ST0_IM;
  1480. if (unlikely(cop0_cause & STATUSF_IP2))
  1481. octeon_irq_ip2();
  1482. else if (unlikely(cop0_cause & STATUSF_IP3))
  1483. octeon_irq_ip3();
  1484. else if (unlikely(cop0_cause & STATUSF_IP4))
  1485. octeon_irq_ip4();
  1486. else if (likely(cop0_cause))
  1487. do_IRQ(fls(cop0_cause) - 9 + MIPS_CPU_IRQ_BASE);
  1488. else
  1489. break;
  1490. }
  1491. }
  1492. #ifdef CONFIG_HOTPLUG_CPU
  1493. void fixup_irqs(void)
  1494. {
  1495. irq_cpu_offline();
  1496. }
  1497. #endif /* CONFIG_HOTPLUG_CPU */