octeon-irq.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  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. line = (hw + gpiod->base_hwirq) >> 6;
  883. bit = (hw + gpiod->base_hwirq) & 63;
  884. if (line > line_limit || octeon_irq_ciu_to_irq[line][bit] != 0)
  885. return -EINVAL;
  886. octeon_irq_set_ciu_mapping(virq, line, bit, hw,
  887. chip, octeon_irq_handle_gpio);
  888. return 0;
  889. }
  890. static int octeon_irq_gpio_map(struct irq_domain *d,
  891. unsigned int virq, irq_hw_number_t hw)
  892. {
  893. return octeon_irq_gpio_map_common(d, virq, hw, 1, octeon_irq_gpio_chip);
  894. }
  895. static struct irq_domain_ops octeon_irq_domain_ciu_ops = {
  896. .map = octeon_irq_ciu_map,
  897. .xlate = octeon_irq_ciu_xlat,
  898. };
  899. static struct irq_domain_ops octeon_irq_domain_gpio_ops = {
  900. .map = octeon_irq_gpio_map,
  901. .xlate = octeon_irq_gpio_xlat,
  902. };
  903. static void octeon_irq_ip2_ciu(void)
  904. {
  905. const unsigned long core_id = cvmx_get_core_num();
  906. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(core_id * 2));
  907. ciu_sum &= __get_cpu_var(octeon_irq_ciu0_en_mirror);
  908. if (likely(ciu_sum)) {
  909. int bit = fls64(ciu_sum) - 1;
  910. int irq = octeon_irq_ciu_to_irq[0][bit];
  911. if (likely(irq))
  912. do_IRQ(irq);
  913. else
  914. spurious_interrupt();
  915. } else {
  916. spurious_interrupt();
  917. }
  918. }
  919. static void octeon_irq_ip3_ciu(void)
  920. {
  921. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
  922. ciu_sum &= __get_cpu_var(octeon_irq_ciu1_en_mirror);
  923. if (likely(ciu_sum)) {
  924. int bit = fls64(ciu_sum) - 1;
  925. int irq = octeon_irq_ciu_to_irq[1][bit];
  926. if (likely(irq))
  927. do_IRQ(irq);
  928. else
  929. spurious_interrupt();
  930. } else {
  931. spurious_interrupt();
  932. }
  933. }
  934. static bool octeon_irq_use_ip4;
  935. static void __cpuinit octeon_irq_local_enable_ip4(void *arg)
  936. {
  937. set_c0_status(STATUSF_IP4);
  938. }
  939. static void octeon_irq_ip4_mask(void)
  940. {
  941. clear_c0_status(STATUSF_IP4);
  942. spurious_interrupt();
  943. }
  944. static void (*octeon_irq_ip2)(void);
  945. static void (*octeon_irq_ip3)(void);
  946. static void (*octeon_irq_ip4)(void);
  947. void __cpuinitdata (*octeon_irq_setup_secondary)(void);
  948. void __cpuinit octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t h)
  949. {
  950. octeon_irq_ip4 = h;
  951. octeon_irq_use_ip4 = true;
  952. on_each_cpu(octeon_irq_local_enable_ip4, NULL, 1);
  953. }
  954. static void __cpuinit octeon_irq_percpu_enable(void)
  955. {
  956. irq_cpu_online();
  957. }
  958. static void __cpuinit octeon_irq_init_ciu_percpu(void)
  959. {
  960. int coreid = cvmx_get_core_num();
  961. __get_cpu_var(octeon_irq_ciu0_en_mirror) = 0;
  962. __get_cpu_var(octeon_irq_ciu1_en_mirror) = 0;
  963. wmb();
  964. raw_spin_lock_init(&__get_cpu_var(octeon_irq_ciu_spinlock));
  965. /*
  966. * Disable All CIU Interrupts. The ones we need will be
  967. * enabled later. Read the SUM register so we know the write
  968. * completed.
  969. */
  970. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2)), 0);
  971. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2 + 1)), 0);
  972. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2)), 0);
  973. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2 + 1)), 0);
  974. cvmx_read_csr(CVMX_CIU_INTX_SUM0((coreid * 2)));
  975. }
  976. static void octeon_irq_init_ciu2_percpu(void)
  977. {
  978. u64 regx, ipx;
  979. int coreid = cvmx_get_core_num();
  980. u64 base = CVMX_CIU2_EN_PPX_IP2_WRKQ(coreid);
  981. /*
  982. * Disable All CIU2 Interrupts. The ones we need will be
  983. * enabled later. Read the SUM register so we know the write
  984. * completed.
  985. *
  986. * There are 9 registers and 3 IPX levels with strides 0x1000
  987. * and 0x200 respectivly. Use loops to clear them.
  988. */
  989. for (regx = 0; regx <= 0x8000; regx += 0x1000) {
  990. for (ipx = 0; ipx <= 0x400; ipx += 0x200)
  991. cvmx_write_csr(base + regx + ipx, 0);
  992. }
  993. cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid));
  994. }
  995. static void __cpuinit octeon_irq_setup_secondary_ciu(void)
  996. {
  997. octeon_irq_init_ciu_percpu();
  998. octeon_irq_percpu_enable();
  999. /* Enable the CIU lines */
  1000. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1001. clear_c0_status(STATUSF_IP4);
  1002. }
  1003. static void octeon_irq_setup_secondary_ciu2(void)
  1004. {
  1005. octeon_irq_init_ciu2_percpu();
  1006. octeon_irq_percpu_enable();
  1007. /* Enable the CIU lines */
  1008. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1009. if (octeon_irq_use_ip4)
  1010. set_c0_status(STATUSF_IP4);
  1011. else
  1012. clear_c0_status(STATUSF_IP4);
  1013. }
  1014. static void __init octeon_irq_init_ciu(void)
  1015. {
  1016. unsigned int i;
  1017. struct irq_chip *chip;
  1018. struct irq_chip *chip_mbox;
  1019. struct irq_chip *chip_wd;
  1020. struct device_node *gpio_node;
  1021. struct device_node *ciu_node;
  1022. struct irq_domain *ciu_domain = NULL;
  1023. octeon_irq_init_ciu_percpu();
  1024. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu;
  1025. octeon_irq_ip2 = octeon_irq_ip2_ciu;
  1026. octeon_irq_ip3 = octeon_irq_ip3_ciu;
  1027. if (OCTEON_IS_MODEL(OCTEON_CN58XX_PASS2_X) ||
  1028. OCTEON_IS_MODEL(OCTEON_CN56XX_PASS2_X) ||
  1029. OCTEON_IS_MODEL(OCTEON_CN52XX_PASS2_X) ||
  1030. OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
  1031. chip = &octeon_irq_chip_ciu_v2;
  1032. chip_mbox = &octeon_irq_chip_ciu_mbox_v2;
  1033. chip_wd = &octeon_irq_chip_ciu_wd_v2;
  1034. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio_v2;
  1035. } else {
  1036. chip = &octeon_irq_chip_ciu;
  1037. chip_mbox = &octeon_irq_chip_ciu_mbox;
  1038. chip_wd = &octeon_irq_chip_ciu_wd;
  1039. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio;
  1040. }
  1041. octeon_irq_ciu_chip = chip;
  1042. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1043. /* Mips internal */
  1044. octeon_irq_init_core();
  1045. gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
  1046. if (gpio_node) {
  1047. struct octeon_irq_gpio_domain_data *gpiod;
  1048. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1049. if (gpiod) {
  1050. /* gpio domain host_data is the base hwirq number. */
  1051. gpiod->base_hwirq = 16;
  1052. irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_gpio_ops, gpiod);
  1053. of_node_put(gpio_node);
  1054. } else
  1055. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1056. } else
  1057. pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
  1058. ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-ciu");
  1059. if (ciu_node) {
  1060. ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu_ops, NULL);
  1061. irq_set_default_host(ciu_domain);
  1062. of_node_put(ciu_node);
  1063. } else
  1064. panic("Cannot find device node for cavium,octeon-3860-ciu.");
  1065. /* CIU_0 */
  1066. for (i = 0; i < 16; i++)
  1067. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i + 0);
  1068. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX0, 0, 32, 0, chip_mbox, handle_percpu_irq);
  1069. octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX1, 0, 33, 0, chip_mbox, handle_percpu_irq);
  1070. for (i = 0; i < 4; i++)
  1071. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 0, i + 36);
  1072. for (i = 0; i < 4; i++)
  1073. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 0, i + 40);
  1074. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_RML, 0, 46);
  1075. for (i = 0; i < 4; i++)
  1076. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 0, i + 52);
  1077. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 0, 56);
  1078. /* CIU_1 */
  1079. for (i = 0; i < 16; i++)
  1080. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i + 0, 0, chip_wd, handle_level_irq);
  1081. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB1, 1, 17);
  1082. /* Enable the CIU lines */
  1083. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1084. clear_c0_status(STATUSF_IP4);
  1085. }
  1086. /*
  1087. * Watchdog interrupts are special. They are associated with a single
  1088. * core, so we hardwire the affinity to that core.
  1089. */
  1090. static void octeon_irq_ciu2_wd_enable(struct irq_data *data)
  1091. {
  1092. u64 mask;
  1093. u64 en_addr;
  1094. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  1095. union octeon_ciu_chip_data cd;
  1096. cd.p = irq_data_get_irq_chip_data(data);
  1097. mask = 1ull << (cd.s.bit);
  1098. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1099. cvmx_write_csr(en_addr, mask);
  1100. }
  1101. static void octeon_irq_ciu2_enable(struct irq_data *data)
  1102. {
  1103. u64 mask;
  1104. u64 en_addr;
  1105. int cpu = next_cpu_for_irq(data);
  1106. int coreid = octeon_coreid_for_cpu(cpu);
  1107. union octeon_ciu_chip_data cd;
  1108. cd.p = irq_data_get_irq_chip_data(data);
  1109. mask = 1ull << (cd.s.bit);
  1110. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1111. cvmx_write_csr(en_addr, mask);
  1112. }
  1113. static void octeon_irq_ciu2_enable_local(struct irq_data *data)
  1114. {
  1115. u64 mask;
  1116. u64 en_addr;
  1117. int coreid = cvmx_get_core_num();
  1118. union octeon_ciu_chip_data cd;
  1119. cd.p = irq_data_get_irq_chip_data(data);
  1120. mask = 1ull << (cd.s.bit);
  1121. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
  1122. cvmx_write_csr(en_addr, mask);
  1123. }
  1124. static void octeon_irq_ciu2_disable_local(struct irq_data *data)
  1125. {
  1126. u64 mask;
  1127. u64 en_addr;
  1128. int coreid = cvmx_get_core_num();
  1129. union octeon_ciu_chip_data cd;
  1130. cd.p = irq_data_get_irq_chip_data(data);
  1131. mask = 1ull << (cd.s.bit);
  1132. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(coreid) + (0x1000ull * cd.s.line);
  1133. cvmx_write_csr(en_addr, mask);
  1134. }
  1135. static void octeon_irq_ciu2_ack(struct irq_data *data)
  1136. {
  1137. u64 mask;
  1138. u64 en_addr;
  1139. int coreid = cvmx_get_core_num();
  1140. union octeon_ciu_chip_data cd;
  1141. cd.p = irq_data_get_irq_chip_data(data);
  1142. mask = 1ull << (cd.s.bit);
  1143. en_addr = CVMX_CIU2_RAW_PPX_IP2_WRKQ(coreid) + (0x1000ull * cd.s.line);
  1144. cvmx_write_csr(en_addr, mask);
  1145. }
  1146. static void octeon_irq_ciu2_disable_all(struct irq_data *data)
  1147. {
  1148. int cpu;
  1149. u64 mask;
  1150. union octeon_ciu_chip_data cd;
  1151. cd.p = irq_data_get_irq_chip_data(data);
  1152. mask = 1ull << (cd.s.bit);
  1153. for_each_online_cpu(cpu) {
  1154. u64 en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1155. cvmx_write_csr(en_addr, mask);
  1156. }
  1157. }
  1158. static void octeon_irq_ciu2_mbox_enable_all(struct irq_data *data)
  1159. {
  1160. int cpu;
  1161. u64 mask;
  1162. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1163. for_each_online_cpu(cpu) {
  1164. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(octeon_coreid_for_cpu(cpu));
  1165. cvmx_write_csr(en_addr, mask);
  1166. }
  1167. }
  1168. static void octeon_irq_ciu2_mbox_disable_all(struct irq_data *data)
  1169. {
  1170. int cpu;
  1171. u64 mask;
  1172. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1173. for_each_online_cpu(cpu) {
  1174. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(octeon_coreid_for_cpu(cpu));
  1175. cvmx_write_csr(en_addr, mask);
  1176. }
  1177. }
  1178. static void octeon_irq_ciu2_mbox_enable_local(struct irq_data *data)
  1179. {
  1180. u64 mask;
  1181. u64 en_addr;
  1182. int coreid = cvmx_get_core_num();
  1183. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1184. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(coreid);
  1185. cvmx_write_csr(en_addr, mask);
  1186. }
  1187. static void octeon_irq_ciu2_mbox_disable_local(struct irq_data *data)
  1188. {
  1189. u64 mask;
  1190. u64 en_addr;
  1191. int coreid = cvmx_get_core_num();
  1192. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1193. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(coreid);
  1194. cvmx_write_csr(en_addr, mask);
  1195. }
  1196. #ifdef CONFIG_SMP
  1197. static int octeon_irq_ciu2_set_affinity(struct irq_data *data,
  1198. const struct cpumask *dest, bool force)
  1199. {
  1200. int cpu;
  1201. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  1202. u64 mask;
  1203. union octeon_ciu_chip_data cd;
  1204. if (!enable_one)
  1205. return 0;
  1206. cd.p = irq_data_get_irq_chip_data(data);
  1207. mask = 1ull << cd.s.bit;
  1208. for_each_online_cpu(cpu) {
  1209. u64 en_addr;
  1210. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  1211. enable_one = false;
  1212. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1213. } else {
  1214. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
  1215. }
  1216. cvmx_write_csr(en_addr, mask);
  1217. }
  1218. return 0;
  1219. }
  1220. #endif
  1221. static void octeon_irq_ciu2_enable_gpio(struct irq_data *data)
  1222. {
  1223. octeon_irq_gpio_setup(data);
  1224. octeon_irq_ciu2_enable(data);
  1225. }
  1226. static void octeon_irq_ciu2_disable_gpio(struct irq_data *data)
  1227. {
  1228. union octeon_ciu_chip_data cd;
  1229. cd.p = irq_data_get_irq_chip_data(data);
  1230. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
  1231. octeon_irq_ciu2_disable_all(data);
  1232. }
  1233. static struct irq_chip octeon_irq_chip_ciu2 = {
  1234. .name = "CIU2-E",
  1235. .irq_enable = octeon_irq_ciu2_enable,
  1236. .irq_disable = octeon_irq_ciu2_disable_all,
  1237. .irq_ack = octeon_irq_ciu2_ack,
  1238. .irq_mask = octeon_irq_ciu2_disable_local,
  1239. .irq_unmask = octeon_irq_ciu2_enable,
  1240. #ifdef CONFIG_SMP
  1241. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1242. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1243. #endif
  1244. };
  1245. static struct irq_chip octeon_irq_chip_ciu2_mbox = {
  1246. .name = "CIU2-M",
  1247. .irq_enable = octeon_irq_ciu2_mbox_enable_all,
  1248. .irq_disable = octeon_irq_ciu2_mbox_disable_all,
  1249. .irq_ack = octeon_irq_ciu2_mbox_disable_local,
  1250. .irq_eoi = octeon_irq_ciu2_mbox_enable_local,
  1251. .irq_cpu_online = octeon_irq_ciu2_mbox_enable_local,
  1252. .irq_cpu_offline = octeon_irq_ciu2_mbox_disable_local,
  1253. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  1254. };
  1255. static struct irq_chip octeon_irq_chip_ciu2_wd = {
  1256. .name = "CIU2-W",
  1257. .irq_enable = octeon_irq_ciu2_wd_enable,
  1258. .irq_disable = octeon_irq_ciu2_disable_all,
  1259. .irq_mask = octeon_irq_ciu2_disable_local,
  1260. .irq_unmask = octeon_irq_ciu2_enable_local,
  1261. };
  1262. static struct irq_chip octeon_irq_chip_ciu2_gpio = {
  1263. .name = "CIU-GPIO",
  1264. .irq_enable = octeon_irq_ciu2_enable_gpio,
  1265. .irq_disable = octeon_irq_ciu2_disable_gpio,
  1266. .irq_ack = octeon_irq_ciu_gpio_ack,
  1267. .irq_mask = octeon_irq_ciu2_disable_local,
  1268. .irq_unmask = octeon_irq_ciu2_enable,
  1269. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  1270. #ifdef CONFIG_SMP
  1271. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1272. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1273. #endif
  1274. .flags = IRQCHIP_SET_TYPE_MASKED,
  1275. };
  1276. static int octeon_irq_ciu2_xlat(struct irq_domain *d,
  1277. struct device_node *node,
  1278. const u32 *intspec,
  1279. unsigned int intsize,
  1280. unsigned long *out_hwirq,
  1281. unsigned int *out_type)
  1282. {
  1283. unsigned int ciu, bit;
  1284. ciu = intspec[0];
  1285. bit = intspec[1];
  1286. /* Line 7 are the GPIO lines */
  1287. if (ciu > 6 || bit > 63)
  1288. return -EINVAL;
  1289. *out_hwirq = (ciu << 6) | bit;
  1290. *out_type = 0;
  1291. return 0;
  1292. }
  1293. static bool octeon_irq_ciu2_is_edge(unsigned int line, unsigned int bit)
  1294. {
  1295. bool edge = false;
  1296. if (line == 3) /* MIO */
  1297. switch (bit) {
  1298. case 2: /* IPD_DRP */
  1299. case 8 ... 11: /* Timers */
  1300. case 48: /* PTP */
  1301. edge = true;
  1302. break;
  1303. default:
  1304. break;
  1305. }
  1306. else if (line == 6) /* PKT */
  1307. switch (bit) {
  1308. case 52 ... 53: /* ILK_DRP */
  1309. case 8 ... 12: /* GMX_DRP */
  1310. edge = true;
  1311. break;
  1312. default:
  1313. break;
  1314. }
  1315. return edge;
  1316. }
  1317. static int octeon_irq_ciu2_map(struct irq_domain *d,
  1318. unsigned int virq, irq_hw_number_t hw)
  1319. {
  1320. unsigned int line = hw >> 6;
  1321. unsigned int bit = hw & 63;
  1322. if (!octeon_irq_virq_in_range(virq))
  1323. return -EINVAL;
  1324. /* Line 7 are the GPIO lines */
  1325. if (line > 6 || octeon_irq_ciu_to_irq[line][bit] != 0)
  1326. return -EINVAL;
  1327. if (octeon_irq_ciu2_is_edge(line, bit))
  1328. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1329. &octeon_irq_chip_ciu2,
  1330. handle_edge_irq);
  1331. else
  1332. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1333. &octeon_irq_chip_ciu2,
  1334. handle_level_irq);
  1335. return 0;
  1336. }
  1337. static int octeon_irq_ciu2_gpio_map(struct irq_domain *d,
  1338. unsigned int virq, irq_hw_number_t hw)
  1339. {
  1340. return octeon_irq_gpio_map_common(d, virq, hw, 7, &octeon_irq_chip_ciu2_gpio);
  1341. }
  1342. static struct irq_domain_ops octeon_irq_domain_ciu2_ops = {
  1343. .map = octeon_irq_ciu2_map,
  1344. .xlate = octeon_irq_ciu2_xlat,
  1345. };
  1346. static struct irq_domain_ops octeon_irq_domain_ciu2_gpio_ops = {
  1347. .map = octeon_irq_ciu2_gpio_map,
  1348. .xlate = octeon_irq_gpio_xlat,
  1349. };
  1350. static void octeon_irq_ciu2(void)
  1351. {
  1352. int line;
  1353. int bit;
  1354. int irq;
  1355. u64 src_reg, src, sum;
  1356. const unsigned long core_id = cvmx_get_core_num();
  1357. sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(core_id)) & 0xfful;
  1358. if (unlikely(!sum))
  1359. goto spurious;
  1360. line = fls64(sum) - 1;
  1361. src_reg = CVMX_CIU2_SRC_PPX_IP2_WRKQ(core_id) + (0x1000 * line);
  1362. src = cvmx_read_csr(src_reg);
  1363. if (unlikely(!src))
  1364. goto spurious;
  1365. bit = fls64(src) - 1;
  1366. irq = octeon_irq_ciu_to_irq[line][bit];
  1367. if (unlikely(!irq))
  1368. goto spurious;
  1369. do_IRQ(irq);
  1370. goto out;
  1371. spurious:
  1372. spurious_interrupt();
  1373. out:
  1374. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1375. can stop interrupts from propagating */
  1376. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1377. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1378. else
  1379. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP2(core_id));
  1380. return;
  1381. }
  1382. static void octeon_irq_ciu2_mbox(void)
  1383. {
  1384. int line;
  1385. const unsigned long core_id = cvmx_get_core_num();
  1386. u64 sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP3(core_id)) >> 60;
  1387. if (unlikely(!sum))
  1388. goto spurious;
  1389. line = fls64(sum) - 1;
  1390. do_IRQ(OCTEON_IRQ_MBOX0 + line);
  1391. goto out;
  1392. spurious:
  1393. spurious_interrupt();
  1394. out:
  1395. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1396. can stop interrupts from propagating */
  1397. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1398. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1399. else
  1400. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP3(core_id));
  1401. return;
  1402. }
  1403. static void __init octeon_irq_init_ciu2(void)
  1404. {
  1405. unsigned int i;
  1406. struct device_node *gpio_node;
  1407. struct device_node *ciu_node;
  1408. struct irq_domain *ciu_domain = NULL;
  1409. octeon_irq_init_ciu2_percpu();
  1410. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu2;
  1411. octeon_irq_ip2 = octeon_irq_ciu2;
  1412. octeon_irq_ip3 = octeon_irq_ciu2_mbox;
  1413. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1414. /* Mips internal */
  1415. octeon_irq_init_core();
  1416. gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
  1417. if (gpio_node) {
  1418. struct octeon_irq_gpio_domain_data *gpiod;
  1419. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1420. if (gpiod) {
  1421. /* gpio domain host_data is the base hwirq number. */
  1422. gpiod->base_hwirq = 7 << 6;
  1423. irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_ciu2_gpio_ops, gpiod);
  1424. of_node_put(gpio_node);
  1425. } else
  1426. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1427. } else
  1428. pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
  1429. ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-6880-ciu2");
  1430. if (ciu_node) {
  1431. ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu2_ops, NULL);
  1432. irq_set_default_host(ciu_domain);
  1433. of_node_put(ciu_node);
  1434. } else
  1435. panic("Cannot find device node for cavium,octeon-6880-ciu2.");
  1436. /* CUI2 */
  1437. for (i = 0; i < 64; i++)
  1438. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i);
  1439. for (i = 0; i < 32; i++)
  1440. octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i, 0,
  1441. &octeon_irq_chip_ciu2_wd, handle_level_irq);
  1442. for (i = 0; i < 4; i++)
  1443. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 3, i + 8);
  1444. octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 3, 44);
  1445. for (i = 0; i < 4; i++)
  1446. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 4, i);
  1447. for (i = 0; i < 4; i++)
  1448. octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 4, i + 8);
  1449. irq_set_chip_and_handler(OCTEON_IRQ_MBOX0, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1450. irq_set_chip_and_handler(OCTEON_IRQ_MBOX1, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1451. irq_set_chip_and_handler(OCTEON_IRQ_MBOX2, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1452. irq_set_chip_and_handler(OCTEON_IRQ_MBOX3, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1453. /* Enable the CIU lines */
  1454. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1455. clear_c0_status(STATUSF_IP4);
  1456. }
  1457. void __init arch_init_irq(void)
  1458. {
  1459. #ifdef CONFIG_SMP
  1460. /* Set the default affinity to the boot cpu. */
  1461. cpumask_clear(irq_default_affinity);
  1462. cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
  1463. #endif
  1464. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1465. octeon_irq_init_ciu2();
  1466. else
  1467. octeon_irq_init_ciu();
  1468. }
  1469. asmlinkage void plat_irq_dispatch(void)
  1470. {
  1471. unsigned long cop0_cause;
  1472. unsigned long cop0_status;
  1473. while (1) {
  1474. cop0_cause = read_c0_cause();
  1475. cop0_status = read_c0_status();
  1476. cop0_cause &= cop0_status;
  1477. cop0_cause &= ST0_IM;
  1478. if (unlikely(cop0_cause & STATUSF_IP2))
  1479. octeon_irq_ip2();
  1480. else if (unlikely(cop0_cause & STATUSF_IP3))
  1481. octeon_irq_ip3();
  1482. else if (unlikely(cop0_cause & STATUSF_IP4))
  1483. octeon_irq_ip4();
  1484. else if (likely(cop0_cause))
  1485. do_IRQ(fls(cop0_cause) - 9 + MIPS_CPU_IRQ_BASE);
  1486. else
  1487. break;
  1488. }
  1489. }
  1490. #ifdef CONFIG_HOTPLUG_CPU
  1491. void fixup_irqs(void)
  1492. {
  1493. irq_cpu_offline();
  1494. }
  1495. #endif /* CONFIG_HOTPLUG_CPU */