octeon-irq.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790
  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 = this_cpu_ptr(&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 = this_cpu_ptr(&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 = this_cpu_ptr(&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 = this_cpu_ptr(&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 = this_cpu_ptr(&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 = this_cpu_ptr(&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, this_cpu_ptr(&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, this_cpu_ptr(&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, this_cpu_ptr(&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, this_cpu_ptr(&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 (irq_get_trigger_type(irq) & 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, false);
  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. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  695. #endif
  696. .flags = IRQCHIP_SET_TYPE_MASKED,
  697. };
  698. static struct irq_chip octeon_irq_chip_ciu_gpio = {
  699. .name = "CIU-GPIO",
  700. .irq_enable = octeon_irq_ciu_enable_gpio,
  701. .irq_disable = octeon_irq_ciu_disable_gpio,
  702. .irq_mask = octeon_irq_ciu_disable_local,
  703. .irq_unmask = octeon_irq_ciu_enable,
  704. .irq_ack = octeon_irq_ciu_gpio_ack,
  705. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  706. #ifdef CONFIG_SMP
  707. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  708. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  709. #endif
  710. .flags = IRQCHIP_SET_TYPE_MASKED,
  711. };
  712. /*
  713. * Watchdog interrupts are special. They are associated with a single
  714. * core, so we hardwire the affinity to that core.
  715. */
  716. static void octeon_irq_ciu_wd_enable(struct irq_data *data)
  717. {
  718. unsigned long flags;
  719. unsigned long *pen;
  720. int coreid = data->irq - OCTEON_IRQ_WDOG0; /* Bit 0-63 of EN1 */
  721. int cpu = octeon_cpu_for_coreid(coreid);
  722. raw_spinlock_t *lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  723. raw_spin_lock_irqsave(lock, flags);
  724. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  725. __set_bit(coreid, pen);
  726. /*
  727. * Must be visible to octeon_irq_ip{2,3}_ciu() before enabling
  728. * the irq.
  729. */
  730. wmb();
  731. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  732. raw_spin_unlock_irqrestore(lock, flags);
  733. }
  734. /*
  735. * Watchdog interrupts are special. They are associated with a single
  736. * core, so we hardwire the affinity to that core.
  737. */
  738. static void octeon_irq_ciu1_wd_enable_v2(struct irq_data *data)
  739. {
  740. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  741. int cpu = octeon_cpu_for_coreid(coreid);
  742. set_bit(coreid, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  743. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(coreid * 2 + 1), 1ull << coreid);
  744. }
  745. static struct irq_chip octeon_irq_chip_ciu_wd_v2 = {
  746. .name = "CIU-W",
  747. .irq_enable = octeon_irq_ciu1_wd_enable_v2,
  748. .irq_disable = octeon_irq_ciu_disable_all_v2,
  749. .irq_mask = octeon_irq_ciu_disable_local_v2,
  750. .irq_unmask = octeon_irq_ciu_enable_local_v2,
  751. };
  752. static struct irq_chip octeon_irq_chip_ciu_wd = {
  753. .name = "CIU-W",
  754. .irq_enable = octeon_irq_ciu_wd_enable,
  755. .irq_disable = octeon_irq_ciu_disable_all,
  756. .irq_mask = octeon_irq_ciu_disable_local,
  757. .irq_unmask = octeon_irq_ciu_enable_local,
  758. };
  759. static bool octeon_irq_ciu_is_edge(unsigned int line, unsigned int bit)
  760. {
  761. bool edge = false;
  762. if (line == 0)
  763. switch (bit) {
  764. case 48 ... 49: /* GMX DRP */
  765. case 50: /* IPD_DRP */
  766. case 52 ... 55: /* Timers */
  767. case 58: /* MPI */
  768. edge = true;
  769. break;
  770. default:
  771. break;
  772. }
  773. else /* line == 1 */
  774. switch (bit) {
  775. case 47: /* PTP */
  776. edge = true;
  777. break;
  778. default:
  779. break;
  780. }
  781. return edge;
  782. }
  783. struct octeon_irq_gpio_domain_data {
  784. unsigned int base_hwirq;
  785. };
  786. static int octeon_irq_gpio_xlat(struct irq_domain *d,
  787. struct device_node *node,
  788. const u32 *intspec,
  789. unsigned int intsize,
  790. unsigned long *out_hwirq,
  791. unsigned int *out_type)
  792. {
  793. unsigned int type;
  794. unsigned int pin;
  795. unsigned int trigger;
  796. if (d->of_node != node)
  797. return -EINVAL;
  798. if (intsize < 2)
  799. return -EINVAL;
  800. pin = intspec[0];
  801. if (pin >= 16)
  802. return -EINVAL;
  803. trigger = intspec[1];
  804. switch (trigger) {
  805. case 1:
  806. type = IRQ_TYPE_EDGE_RISING;
  807. break;
  808. case 2:
  809. type = IRQ_TYPE_EDGE_FALLING;
  810. break;
  811. case 4:
  812. type = IRQ_TYPE_LEVEL_HIGH;
  813. break;
  814. case 8:
  815. type = IRQ_TYPE_LEVEL_LOW;
  816. break;
  817. default:
  818. pr_err("Error: (%s) Invalid irq trigger specification: %x\n",
  819. node->name,
  820. trigger);
  821. type = IRQ_TYPE_LEVEL_LOW;
  822. break;
  823. }
  824. *out_type = type;
  825. *out_hwirq = pin;
  826. return 0;
  827. }
  828. static int octeon_irq_ciu_xlat(struct irq_domain *d,
  829. struct device_node *node,
  830. const u32 *intspec,
  831. unsigned int intsize,
  832. unsigned long *out_hwirq,
  833. unsigned int *out_type)
  834. {
  835. unsigned int ciu, bit;
  836. ciu = intspec[0];
  837. bit = intspec[1];
  838. if (ciu > 1 || bit > 63)
  839. return -EINVAL;
  840. *out_hwirq = (ciu << 6) | bit;
  841. *out_type = 0;
  842. return 0;
  843. }
  844. static struct irq_chip *octeon_irq_ciu_chip;
  845. static struct irq_chip *octeon_irq_gpio_chip;
  846. static bool octeon_irq_virq_in_range(unsigned int virq)
  847. {
  848. /* We cannot let it overflow the mapping array. */
  849. if (virq < (1ul << 8 * sizeof(octeon_irq_ciu_to_irq[0][0])))
  850. return true;
  851. WARN_ONCE(true, "virq out of range %u.\n", virq);
  852. return false;
  853. }
  854. static int octeon_irq_ciu_map(struct irq_domain *d,
  855. unsigned int virq, irq_hw_number_t hw)
  856. {
  857. unsigned int line = hw >> 6;
  858. unsigned int bit = hw & 63;
  859. if (!octeon_irq_virq_in_range(virq))
  860. return -EINVAL;
  861. /* Don't map irq if it is reserved for GPIO. */
  862. if (line == 0 && bit >= 16 && bit <32)
  863. return 0;
  864. if (line > 1 || octeon_irq_ciu_to_irq[line][bit] != 0)
  865. return -EINVAL;
  866. if (octeon_irq_ciu_is_edge(line, bit))
  867. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  868. octeon_irq_ciu_chip,
  869. handle_edge_irq);
  870. else
  871. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  872. octeon_irq_ciu_chip,
  873. handle_level_irq);
  874. return 0;
  875. }
  876. static int octeon_irq_gpio_map_common(struct irq_domain *d,
  877. unsigned int virq, irq_hw_number_t hw,
  878. int line_limit, struct irq_chip *chip)
  879. {
  880. struct octeon_irq_gpio_domain_data *gpiod = d->host_data;
  881. unsigned int line, bit;
  882. if (!octeon_irq_virq_in_range(virq))
  883. return -EINVAL;
  884. line = (hw + gpiod->base_hwirq) >> 6;
  885. bit = (hw + gpiod->base_hwirq) & 63;
  886. if (line > line_limit || octeon_irq_ciu_to_irq[line][bit] != 0)
  887. return -EINVAL;
  888. octeon_irq_set_ciu_mapping(virq, line, bit, hw,
  889. chip, octeon_irq_handle_gpio);
  890. return 0;
  891. }
  892. static int octeon_irq_gpio_map(struct irq_domain *d,
  893. unsigned int virq, irq_hw_number_t hw)
  894. {
  895. return octeon_irq_gpio_map_common(d, virq, hw, 1, octeon_irq_gpio_chip);
  896. }
  897. static struct irq_domain_ops octeon_irq_domain_ciu_ops = {
  898. .map = octeon_irq_ciu_map,
  899. .xlate = octeon_irq_ciu_xlat,
  900. };
  901. static struct irq_domain_ops octeon_irq_domain_gpio_ops = {
  902. .map = octeon_irq_gpio_map,
  903. .xlate = octeon_irq_gpio_xlat,
  904. };
  905. static void octeon_irq_ip2_ciu(void)
  906. {
  907. const unsigned long core_id = cvmx_get_core_num();
  908. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(core_id * 2));
  909. ciu_sum &= __this_cpu_read(octeon_irq_ciu0_en_mirror);
  910. if (likely(ciu_sum)) {
  911. int bit = fls64(ciu_sum) - 1;
  912. int irq = octeon_irq_ciu_to_irq[0][bit];
  913. if (likely(irq))
  914. do_IRQ(irq);
  915. else
  916. spurious_interrupt();
  917. } else {
  918. spurious_interrupt();
  919. }
  920. }
  921. static void octeon_irq_ip3_ciu(void)
  922. {
  923. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
  924. ciu_sum &= __this_cpu_read(octeon_irq_ciu1_en_mirror);
  925. if (likely(ciu_sum)) {
  926. int bit = fls64(ciu_sum) - 1;
  927. int irq = octeon_irq_ciu_to_irq[1][bit];
  928. if (likely(irq))
  929. do_IRQ(irq);
  930. else
  931. spurious_interrupt();
  932. } else {
  933. spurious_interrupt();
  934. }
  935. }
  936. static bool octeon_irq_use_ip4;
  937. static void octeon_irq_local_enable_ip4(void *arg)
  938. {
  939. set_c0_status(STATUSF_IP4);
  940. }
  941. static void octeon_irq_ip4_mask(void)
  942. {
  943. clear_c0_status(STATUSF_IP4);
  944. spurious_interrupt();
  945. }
  946. static void (*octeon_irq_ip2)(void);
  947. static void (*octeon_irq_ip3)(void);
  948. static void (*octeon_irq_ip4)(void);
  949. void (*octeon_irq_setup_secondary)(void);
  950. void octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t h)
  951. {
  952. octeon_irq_ip4 = h;
  953. octeon_irq_use_ip4 = true;
  954. on_each_cpu(octeon_irq_local_enable_ip4, NULL, 1);
  955. }
  956. static void octeon_irq_percpu_enable(void)
  957. {
  958. irq_cpu_online();
  959. }
  960. static void octeon_irq_init_ciu_percpu(void)
  961. {
  962. int coreid = cvmx_get_core_num();
  963. __this_cpu_write(octeon_irq_ciu0_en_mirror, 0);
  964. __this_cpu_write(octeon_irq_ciu1_en_mirror, 0);
  965. wmb();
  966. raw_spin_lock_init(this_cpu_ptr(&octeon_irq_ciu_spinlock));
  967. /*
  968. * Disable All CIU Interrupts. The ones we need will be
  969. * enabled later. Read the SUM register so we know the write
  970. * completed.
  971. */
  972. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2)), 0);
  973. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2 + 1)), 0);
  974. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2)), 0);
  975. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2 + 1)), 0);
  976. cvmx_read_csr(CVMX_CIU_INTX_SUM0((coreid * 2)));
  977. }
  978. static void octeon_irq_init_ciu2_percpu(void)
  979. {
  980. u64 regx, ipx;
  981. int coreid = cvmx_get_core_num();
  982. u64 base = CVMX_CIU2_EN_PPX_IP2_WRKQ(coreid);
  983. /*
  984. * Disable All CIU2 Interrupts. The ones we need will be
  985. * enabled later. Read the SUM register so we know the write
  986. * completed.
  987. *
  988. * There are 9 registers and 3 IPX levels with strides 0x1000
  989. * and 0x200 respectivly. Use loops to clear them.
  990. */
  991. for (regx = 0; regx <= 0x8000; regx += 0x1000) {
  992. for (ipx = 0; ipx <= 0x400; ipx += 0x200)
  993. cvmx_write_csr(base + regx + ipx, 0);
  994. }
  995. cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid));
  996. }
  997. static void octeon_irq_setup_secondary_ciu(void)
  998. {
  999. octeon_irq_init_ciu_percpu();
  1000. octeon_irq_percpu_enable();
  1001. /* Enable the CIU lines */
  1002. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1003. clear_c0_status(STATUSF_IP4);
  1004. }
  1005. static void octeon_irq_setup_secondary_ciu2(void)
  1006. {
  1007. octeon_irq_init_ciu2_percpu();
  1008. octeon_irq_percpu_enable();
  1009. /* Enable the CIU lines */
  1010. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1011. if (octeon_irq_use_ip4)
  1012. set_c0_status(STATUSF_IP4);
  1013. else
  1014. clear_c0_status(STATUSF_IP4);
  1015. }
  1016. static void __init octeon_irq_init_ciu(void)
  1017. {
  1018. unsigned int i;
  1019. struct irq_chip *chip;
  1020. struct irq_chip *chip_mbox;
  1021. struct irq_chip *chip_wd;
  1022. struct device_node *gpio_node;
  1023. struct device_node *ciu_node;
  1024. struct irq_domain *ciu_domain = NULL;
  1025. octeon_irq_init_ciu_percpu();
  1026. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu;
  1027. octeon_irq_ip2 = octeon_irq_ip2_ciu;
  1028. octeon_irq_ip3 = octeon_irq_ip3_ciu;
  1029. if (OCTEON_IS_MODEL(OCTEON_CN58XX_PASS2_X) ||
  1030. OCTEON_IS_MODEL(OCTEON_CN56XX_PASS2_X) ||
  1031. OCTEON_IS_MODEL(OCTEON_CN52XX_PASS2_X) ||
  1032. OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
  1033. chip = &octeon_irq_chip_ciu_v2;
  1034. chip_mbox = &octeon_irq_chip_ciu_mbox_v2;
  1035. chip_wd = &octeon_irq_chip_ciu_wd_v2;
  1036. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio_v2;
  1037. } else {
  1038. chip = &octeon_irq_chip_ciu;
  1039. chip_mbox = &octeon_irq_chip_ciu_mbox;
  1040. chip_wd = &octeon_irq_chip_ciu_wd;
  1041. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio;
  1042. }
  1043. octeon_irq_ciu_chip = chip;
  1044. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1045. /* Mips internal */
  1046. octeon_irq_init_core();
  1047. gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
  1048. if (gpio_node) {
  1049. struct octeon_irq_gpio_domain_data *gpiod;
  1050. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1051. if (gpiod) {
  1052. /* gpio domain host_data is the base hwirq number. */
  1053. gpiod->base_hwirq = 16;
  1054. irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_gpio_ops, gpiod);
  1055. of_node_put(gpio_node);
  1056. } else
  1057. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1058. } else
  1059. pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
  1060. ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-ciu");
  1061. if (ciu_node) {
  1062. ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu_ops, NULL);
  1063. irq_set_default_host(ciu_domain);
  1064. of_node_put(ciu_node);
  1065. } else
  1066. panic("Cannot find device node for cavium,octeon-3860-ciu.");
  1067. /* CIU_0 */
  1068. for (i = 0; i < 16; i++)
  1069. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i + 0);
  1070. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX0, 0, 32, 0, chip_mbox, handle_percpu_irq);
  1071. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX1, 0, 33, 0, chip_mbox, handle_percpu_irq);
  1072. for (i = 0; i < 4; i++)
  1073. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 0, i + 36);
  1074. for (i = 0; i < 4; i++)
  1075. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 0, i + 40);
  1076. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_TWSI, 0, 45);
  1077. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_RML, 0, 46);
  1078. for (i = 0; i < 4; i++)
  1079. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 0, i + 52);
  1080. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 0, 56);
  1081. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_TWSI2, 0, 59);
  1082. /* CIU_1 */
  1083. for (i = 0; i < 16; i++)
  1084. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i + 0, 0, chip_wd, handle_level_irq);
  1085. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB1, 1, 17);
  1086. /* Enable the CIU lines */
  1087. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1088. clear_c0_status(STATUSF_IP4);
  1089. }
  1090. /*
  1091. * Watchdog interrupts are special. They are associated with a single
  1092. * core, so we hardwire the affinity to that core.
  1093. */
  1094. static void octeon_irq_ciu2_wd_enable(struct irq_data *data)
  1095. {
  1096. u64 mask;
  1097. u64 en_addr;
  1098. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  1099. union octeon_ciu_chip_data cd;
  1100. cd.p = irq_data_get_irq_chip_data(data);
  1101. mask = 1ull << (cd.s.bit);
  1102. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1103. cvmx_write_csr(en_addr, mask);
  1104. }
  1105. static void octeon_irq_ciu2_enable(struct irq_data *data)
  1106. {
  1107. u64 mask;
  1108. u64 en_addr;
  1109. int cpu = next_cpu_for_irq(data);
  1110. int coreid = octeon_coreid_for_cpu(cpu);
  1111. union octeon_ciu_chip_data cd;
  1112. cd.p = irq_data_get_irq_chip_data(data);
  1113. mask = 1ull << (cd.s.bit);
  1114. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1115. cvmx_write_csr(en_addr, mask);
  1116. }
  1117. static void octeon_irq_ciu2_enable_local(struct irq_data *data)
  1118. {
  1119. u64 mask;
  1120. u64 en_addr;
  1121. int coreid = cvmx_get_core_num();
  1122. union octeon_ciu_chip_data cd;
  1123. cd.p = irq_data_get_irq_chip_data(data);
  1124. mask = 1ull << (cd.s.bit);
  1125. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1126. cvmx_write_csr(en_addr, mask);
  1127. }
  1128. static void octeon_irq_ciu2_disable_local(struct irq_data *data)
  1129. {
  1130. u64 mask;
  1131. u64 en_addr;
  1132. int coreid = cvmx_get_core_num();
  1133. union octeon_ciu_chip_data cd;
  1134. cd.p = irq_data_get_irq_chip_data(data);
  1135. mask = 1ull << (cd.s.bit);
  1136. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(coreid) + (0x1000ull * cd.s.line);
  1137. cvmx_write_csr(en_addr, mask);
  1138. }
  1139. static void octeon_irq_ciu2_ack(struct irq_data *data)
  1140. {
  1141. u64 mask;
  1142. u64 en_addr;
  1143. int coreid = cvmx_get_core_num();
  1144. union octeon_ciu_chip_data cd;
  1145. cd.p = irq_data_get_irq_chip_data(data);
  1146. mask = 1ull << (cd.s.bit);
  1147. en_addr = CVMX_CIU2_RAW_PPX_IP2_WRKQ(coreid) + (0x1000ull * cd.s.line);
  1148. cvmx_write_csr(en_addr, mask);
  1149. }
  1150. static void octeon_irq_ciu2_disable_all(struct irq_data *data)
  1151. {
  1152. int cpu;
  1153. u64 mask;
  1154. union octeon_ciu_chip_data cd;
  1155. cd.p = irq_data_get_irq_chip_data(data);
  1156. mask = 1ull << (cd.s.bit);
  1157. for_each_online_cpu(cpu) {
  1158. u64 en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1159. cvmx_write_csr(en_addr, mask);
  1160. }
  1161. }
  1162. static void octeon_irq_ciu2_mbox_enable_all(struct irq_data *data)
  1163. {
  1164. int cpu;
  1165. u64 mask;
  1166. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1167. for_each_online_cpu(cpu) {
  1168. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(octeon_coreid_for_cpu(cpu));
  1169. cvmx_write_csr(en_addr, mask);
  1170. }
  1171. }
  1172. static void octeon_irq_ciu2_mbox_disable_all(struct irq_data *data)
  1173. {
  1174. int cpu;
  1175. u64 mask;
  1176. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1177. for_each_online_cpu(cpu) {
  1178. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(octeon_coreid_for_cpu(cpu));
  1179. cvmx_write_csr(en_addr, mask);
  1180. }
  1181. }
  1182. static void octeon_irq_ciu2_mbox_enable_local(struct irq_data *data)
  1183. {
  1184. u64 mask;
  1185. u64 en_addr;
  1186. int coreid = cvmx_get_core_num();
  1187. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1188. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(coreid);
  1189. cvmx_write_csr(en_addr, mask);
  1190. }
  1191. static void octeon_irq_ciu2_mbox_disable_local(struct irq_data *data)
  1192. {
  1193. u64 mask;
  1194. u64 en_addr;
  1195. int coreid = cvmx_get_core_num();
  1196. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1197. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(coreid);
  1198. cvmx_write_csr(en_addr, mask);
  1199. }
  1200. #ifdef CONFIG_SMP
  1201. static int octeon_irq_ciu2_set_affinity(struct irq_data *data,
  1202. const struct cpumask *dest, bool force)
  1203. {
  1204. int cpu;
  1205. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  1206. u64 mask;
  1207. union octeon_ciu_chip_data cd;
  1208. if (!enable_one)
  1209. return 0;
  1210. cd.p = irq_data_get_irq_chip_data(data);
  1211. mask = 1ull << cd.s.bit;
  1212. for_each_online_cpu(cpu) {
  1213. u64 en_addr;
  1214. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  1215. enable_one = false;
  1216. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1217. } else {
  1218. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1219. }
  1220. cvmx_write_csr(en_addr, mask);
  1221. }
  1222. return 0;
  1223. }
  1224. #endif
  1225. static void octeon_irq_ciu2_enable_gpio(struct irq_data *data)
  1226. {
  1227. octeon_irq_gpio_setup(data);
  1228. octeon_irq_ciu2_enable(data);
  1229. }
  1230. static void octeon_irq_ciu2_disable_gpio(struct irq_data *data)
  1231. {
  1232. union octeon_ciu_chip_data cd;
  1233. cd.p = irq_data_get_irq_chip_data(data);
  1234. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
  1235. octeon_irq_ciu2_disable_all(data);
  1236. }
  1237. static struct irq_chip octeon_irq_chip_ciu2 = {
  1238. .name = "CIU2-E",
  1239. .irq_enable = octeon_irq_ciu2_enable,
  1240. .irq_disable = octeon_irq_ciu2_disable_all,
  1241. .irq_ack = octeon_irq_ciu2_ack,
  1242. .irq_mask = octeon_irq_ciu2_disable_local,
  1243. .irq_unmask = octeon_irq_ciu2_enable,
  1244. #ifdef CONFIG_SMP
  1245. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1246. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1247. #endif
  1248. };
  1249. static struct irq_chip octeon_irq_chip_ciu2_mbox = {
  1250. .name = "CIU2-M",
  1251. .irq_enable = octeon_irq_ciu2_mbox_enable_all,
  1252. .irq_disable = octeon_irq_ciu2_mbox_disable_all,
  1253. .irq_ack = octeon_irq_ciu2_mbox_disable_local,
  1254. .irq_eoi = octeon_irq_ciu2_mbox_enable_local,
  1255. .irq_cpu_online = octeon_irq_ciu2_mbox_enable_local,
  1256. .irq_cpu_offline = octeon_irq_ciu2_mbox_disable_local,
  1257. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  1258. };
  1259. static struct irq_chip octeon_irq_chip_ciu2_wd = {
  1260. .name = "CIU2-W",
  1261. .irq_enable = octeon_irq_ciu2_wd_enable,
  1262. .irq_disable = octeon_irq_ciu2_disable_all,
  1263. .irq_mask = octeon_irq_ciu2_disable_local,
  1264. .irq_unmask = octeon_irq_ciu2_enable_local,
  1265. };
  1266. static struct irq_chip octeon_irq_chip_ciu2_gpio = {
  1267. .name = "CIU-GPIO",
  1268. .irq_enable = octeon_irq_ciu2_enable_gpio,
  1269. .irq_disable = octeon_irq_ciu2_disable_gpio,
  1270. .irq_ack = octeon_irq_ciu_gpio_ack,
  1271. .irq_mask = octeon_irq_ciu2_disable_local,
  1272. .irq_unmask = octeon_irq_ciu2_enable,
  1273. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  1274. #ifdef CONFIG_SMP
  1275. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1276. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1277. #endif
  1278. .flags = IRQCHIP_SET_TYPE_MASKED,
  1279. };
  1280. static int octeon_irq_ciu2_xlat(struct irq_domain *d,
  1281. struct device_node *node,
  1282. const u32 *intspec,
  1283. unsigned int intsize,
  1284. unsigned long *out_hwirq,
  1285. unsigned int *out_type)
  1286. {
  1287. unsigned int ciu, bit;
  1288. ciu = intspec[0];
  1289. bit = intspec[1];
  1290. *out_hwirq = (ciu << 6) | bit;
  1291. *out_type = 0;
  1292. return 0;
  1293. }
  1294. static bool octeon_irq_ciu2_is_edge(unsigned int line, unsigned int bit)
  1295. {
  1296. bool edge = false;
  1297. if (line == 3) /* MIO */
  1298. switch (bit) {
  1299. case 2: /* IPD_DRP */
  1300. case 8 ... 11: /* Timers */
  1301. case 48: /* PTP */
  1302. edge = true;
  1303. break;
  1304. default:
  1305. break;
  1306. }
  1307. else if (line == 6) /* PKT */
  1308. switch (bit) {
  1309. case 52 ... 53: /* ILK_DRP */
  1310. case 8 ... 12: /* GMX_DRP */
  1311. edge = true;
  1312. break;
  1313. default:
  1314. break;
  1315. }
  1316. return edge;
  1317. }
  1318. static int octeon_irq_ciu2_map(struct irq_domain *d,
  1319. unsigned int virq, irq_hw_number_t hw)
  1320. {
  1321. unsigned int line = hw >> 6;
  1322. unsigned int bit = hw & 63;
  1323. if (!octeon_irq_virq_in_range(virq))
  1324. return -EINVAL;
  1325. /*
  1326. * Don't map irq if it is reserved for GPIO.
  1327. * (Line 7 are the GPIO lines.)
  1328. */
  1329. if (line == 7)
  1330. return 0;
  1331. if (line > 7 || octeon_irq_ciu_to_irq[line][bit] != 0)
  1332. return -EINVAL;
  1333. if (octeon_irq_ciu2_is_edge(line, bit))
  1334. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1335. &octeon_irq_chip_ciu2,
  1336. handle_edge_irq);
  1337. else
  1338. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1339. &octeon_irq_chip_ciu2,
  1340. handle_level_irq);
  1341. return 0;
  1342. }
  1343. static int octeon_irq_ciu2_gpio_map(struct irq_domain *d,
  1344. unsigned int virq, irq_hw_number_t hw)
  1345. {
  1346. return octeon_irq_gpio_map_common(d, virq, hw, 7, &octeon_irq_chip_ciu2_gpio);
  1347. }
  1348. static struct irq_domain_ops octeon_irq_domain_ciu2_ops = {
  1349. .map = octeon_irq_ciu2_map,
  1350. .xlate = octeon_irq_ciu2_xlat,
  1351. };
  1352. static struct irq_domain_ops octeon_irq_domain_ciu2_gpio_ops = {
  1353. .map = octeon_irq_ciu2_gpio_map,
  1354. .xlate = octeon_irq_gpio_xlat,
  1355. };
  1356. static void octeon_irq_ciu2(void)
  1357. {
  1358. int line;
  1359. int bit;
  1360. int irq;
  1361. u64 src_reg, src, sum;
  1362. const unsigned long core_id = cvmx_get_core_num();
  1363. sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(core_id)) & 0xfful;
  1364. if (unlikely(!sum))
  1365. goto spurious;
  1366. line = fls64(sum) - 1;
  1367. src_reg = CVMX_CIU2_SRC_PPX_IP2_WRKQ(core_id) + (0x1000 * line);
  1368. src = cvmx_read_csr(src_reg);
  1369. if (unlikely(!src))
  1370. goto spurious;
  1371. bit = fls64(src) - 1;
  1372. irq = octeon_irq_ciu_to_irq[line][bit];
  1373. if (unlikely(!irq))
  1374. goto spurious;
  1375. do_IRQ(irq);
  1376. goto out;
  1377. spurious:
  1378. spurious_interrupt();
  1379. out:
  1380. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1381. can stop interrupts from propagating */
  1382. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1383. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1384. else
  1385. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP2(core_id));
  1386. return;
  1387. }
  1388. static void octeon_irq_ciu2_mbox(void)
  1389. {
  1390. int line;
  1391. const unsigned long core_id = cvmx_get_core_num();
  1392. u64 sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP3(core_id)) >> 60;
  1393. if (unlikely(!sum))
  1394. goto spurious;
  1395. line = fls64(sum) - 1;
  1396. do_IRQ(OCTEON_IRQ_MBOX0 + line);
  1397. goto out;
  1398. spurious:
  1399. spurious_interrupt();
  1400. out:
  1401. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1402. can stop interrupts from propagating */
  1403. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1404. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1405. else
  1406. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP3(core_id));
  1407. return;
  1408. }
  1409. static void __init octeon_irq_init_ciu2(void)
  1410. {
  1411. unsigned int i;
  1412. struct device_node *gpio_node;
  1413. struct device_node *ciu_node;
  1414. struct irq_domain *ciu_domain = NULL;
  1415. octeon_irq_init_ciu2_percpu();
  1416. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu2;
  1417. octeon_irq_ip2 = octeon_irq_ciu2;
  1418. octeon_irq_ip3 = octeon_irq_ciu2_mbox;
  1419. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1420. /* Mips internal */
  1421. octeon_irq_init_core();
  1422. gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
  1423. if (gpio_node) {
  1424. struct octeon_irq_gpio_domain_data *gpiod;
  1425. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1426. if (gpiod) {
  1427. /* gpio domain host_data is the base hwirq number. */
  1428. gpiod->base_hwirq = 7 << 6;
  1429. irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_ciu2_gpio_ops, gpiod);
  1430. of_node_put(gpio_node);
  1431. } else
  1432. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1433. } else
  1434. pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
  1435. ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-6880-ciu2");
  1436. if (ciu_node) {
  1437. ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu2_ops, NULL);
  1438. irq_set_default_host(ciu_domain);
  1439. of_node_put(ciu_node);
  1440. } else
  1441. panic("Cannot find device node for cavium,octeon-6880-ciu2.");
  1442. /* CUI2 */
  1443. for (i = 0; i < 64; i++)
  1444. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i);
  1445. for (i = 0; i < 32; i++)
  1446. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i, 0,
  1447. &octeon_irq_chip_ciu2_wd, handle_level_irq);
  1448. for (i = 0; i < 4; i++)
  1449. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 3, i + 8);
  1450. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 3, 44);
  1451. for (i = 0; i < 4; i++)
  1452. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 4, i);
  1453. for (i = 0; i < 4; i++)
  1454. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 4, i + 8);
  1455. irq_set_chip_and_handler(OCTEON_IRQ_MBOX0, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1456. irq_set_chip_and_handler(OCTEON_IRQ_MBOX1, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1457. irq_set_chip_and_handler(OCTEON_IRQ_MBOX2, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1458. irq_set_chip_and_handler(OCTEON_IRQ_MBOX3, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1459. /* Enable the CIU lines */
  1460. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1461. clear_c0_status(STATUSF_IP4);
  1462. }
  1463. void __init arch_init_irq(void)
  1464. {
  1465. #ifdef CONFIG_SMP
  1466. /* Set the default affinity to the boot cpu. */
  1467. cpumask_clear(irq_default_affinity);
  1468. cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
  1469. #endif
  1470. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1471. octeon_irq_init_ciu2();
  1472. else
  1473. octeon_irq_init_ciu();
  1474. }
  1475. asmlinkage void plat_irq_dispatch(void)
  1476. {
  1477. unsigned long cop0_cause;
  1478. unsigned long cop0_status;
  1479. while (1) {
  1480. cop0_cause = read_c0_cause();
  1481. cop0_status = read_c0_status();
  1482. cop0_cause &= cop0_status;
  1483. cop0_cause &= ST0_IM;
  1484. if (unlikely(cop0_cause & STATUSF_IP2))
  1485. octeon_irq_ip2();
  1486. else if (unlikely(cop0_cause & STATUSF_IP3))
  1487. octeon_irq_ip3();
  1488. else if (unlikely(cop0_cause & STATUSF_IP4))
  1489. octeon_irq_ip4();
  1490. else if (likely(cop0_cause))
  1491. do_IRQ(fls(cop0_cause) - 9 + MIPS_CPU_IRQ_BASE);
  1492. else
  1493. break;
  1494. }
  1495. }
  1496. #ifdef CONFIG_HOTPLUG_CPU
  1497. void octeon_fixup_irqs(void)
  1498. {
  1499. irq_cpu_offline();
  1500. }
  1501. #endif /* CONFIG_HOTPLUG_CPU */