octeon-irq.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345
  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-2014 Cavium, Inc.
  7. */
  8. #include <linux/of_address.h>
  9. #include <linux/interrupt.h>
  10. #include <linux/irqdomain.h>
  11. #include <linux/bitops.h>
  12. #include <linux/of_irq.h>
  13. #include <linux/percpu.h>
  14. #include <linux/slab.h>
  15. #include <linux/irq.h>
  16. #include <linux/smp.h>
  17. #include <linux/of.h>
  18. #include <asm/octeon/octeon.h>
  19. #include <asm/octeon/cvmx-ciu2-defs.h>
  20. static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu0_en_mirror);
  21. static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu1_en_mirror);
  22. static DEFINE_PER_CPU(raw_spinlock_t, octeon_irq_ciu_spinlock);
  23. struct octeon_irq_ciu_domain_data {
  24. int num_sum; /* number of sum registers (2 or 3). */
  25. };
  26. static __read_mostly u8 octeon_irq_ciu_to_irq[8][64];
  27. struct octeon_ciu_chip_data {
  28. union {
  29. struct { /* only used for ciu3 */
  30. u64 ciu3_addr;
  31. unsigned int intsn;
  32. };
  33. struct { /* only used for ciu/ciu2 */
  34. u8 line;
  35. u8 bit;
  36. u8 gpio_line;
  37. };
  38. };
  39. int current_cpu; /* Next CPU expected to take this irq */
  40. };
  41. struct octeon_core_chip_data {
  42. struct mutex core_irq_mutex;
  43. bool current_en;
  44. bool desired_en;
  45. u8 bit;
  46. };
  47. #define MIPS_CORE_IRQ_LINES 8
  48. static struct octeon_core_chip_data octeon_irq_core_chip_data[MIPS_CORE_IRQ_LINES];
  49. static int octeon_irq_set_ciu_mapping(int irq, int line, int bit, int gpio_line,
  50. struct irq_chip *chip,
  51. irq_flow_handler_t handler)
  52. {
  53. struct octeon_ciu_chip_data *cd;
  54. cd = kzalloc(sizeof(*cd), GFP_KERNEL);
  55. if (!cd)
  56. return -ENOMEM;
  57. irq_set_chip_and_handler(irq, chip, handler);
  58. cd->line = line;
  59. cd->bit = bit;
  60. cd->gpio_line = gpio_line;
  61. irq_set_chip_data(irq, cd);
  62. octeon_irq_ciu_to_irq[line][bit] = irq;
  63. return 0;
  64. }
  65. static void octeon_irq_free_cd(struct irq_domain *d, unsigned int irq)
  66. {
  67. struct irq_data *data = irq_get_irq_data(irq);
  68. struct octeon_ciu_chip_data *cd = irq_data_get_irq_chip_data(data);
  69. irq_set_chip_data(irq, NULL);
  70. kfree(cd);
  71. }
  72. static int octeon_irq_force_ciu_mapping(struct irq_domain *domain,
  73. int irq, int line, int bit)
  74. {
  75. return irq_domain_associate(domain, irq, line << 6 | bit);
  76. }
  77. static int octeon_coreid_for_cpu(int cpu)
  78. {
  79. #ifdef CONFIG_SMP
  80. return cpu_logical_map(cpu);
  81. #else
  82. return cvmx_get_core_num();
  83. #endif
  84. }
  85. static int octeon_cpu_for_coreid(int coreid)
  86. {
  87. #ifdef CONFIG_SMP
  88. return cpu_number_map(coreid);
  89. #else
  90. return smp_processor_id();
  91. #endif
  92. }
  93. static void octeon_irq_core_ack(struct irq_data *data)
  94. {
  95. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  96. unsigned int bit = cd->bit;
  97. /*
  98. * We don't need to disable IRQs to make these atomic since
  99. * they are already disabled earlier in the low level
  100. * interrupt code.
  101. */
  102. clear_c0_status(0x100 << bit);
  103. /* The two user interrupts must be cleared manually. */
  104. if (bit < 2)
  105. clear_c0_cause(0x100 << bit);
  106. }
  107. static void octeon_irq_core_eoi(struct irq_data *data)
  108. {
  109. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  110. /*
  111. * We don't need to disable IRQs to make these atomic since
  112. * they are already disabled earlier in the low level
  113. * interrupt code.
  114. */
  115. set_c0_status(0x100 << cd->bit);
  116. }
  117. static void octeon_irq_core_set_enable_local(void *arg)
  118. {
  119. struct irq_data *data = arg;
  120. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  121. unsigned int mask = 0x100 << cd->bit;
  122. /*
  123. * Interrupts are already disabled, so these are atomic.
  124. */
  125. if (cd->desired_en)
  126. set_c0_status(mask);
  127. else
  128. clear_c0_status(mask);
  129. }
  130. static void octeon_irq_core_disable(struct irq_data *data)
  131. {
  132. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  133. cd->desired_en = false;
  134. }
  135. static void octeon_irq_core_enable(struct irq_data *data)
  136. {
  137. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  138. cd->desired_en = true;
  139. }
  140. static void octeon_irq_core_bus_lock(struct irq_data *data)
  141. {
  142. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  143. mutex_lock(&cd->core_irq_mutex);
  144. }
  145. static void octeon_irq_core_bus_sync_unlock(struct irq_data *data)
  146. {
  147. struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
  148. if (cd->desired_en != cd->current_en) {
  149. on_each_cpu(octeon_irq_core_set_enable_local, data, 1);
  150. cd->current_en = cd->desired_en;
  151. }
  152. mutex_unlock(&cd->core_irq_mutex);
  153. }
  154. static struct irq_chip octeon_irq_chip_core = {
  155. .name = "Core",
  156. .irq_enable = octeon_irq_core_enable,
  157. .irq_disable = octeon_irq_core_disable,
  158. .irq_ack = octeon_irq_core_ack,
  159. .irq_eoi = octeon_irq_core_eoi,
  160. .irq_bus_lock = octeon_irq_core_bus_lock,
  161. .irq_bus_sync_unlock = octeon_irq_core_bus_sync_unlock,
  162. .irq_cpu_online = octeon_irq_core_eoi,
  163. .irq_cpu_offline = octeon_irq_core_ack,
  164. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  165. };
  166. static void __init octeon_irq_init_core(void)
  167. {
  168. int i;
  169. int irq;
  170. struct octeon_core_chip_data *cd;
  171. for (i = 0; i < MIPS_CORE_IRQ_LINES; i++) {
  172. cd = &octeon_irq_core_chip_data[i];
  173. cd->current_en = false;
  174. cd->desired_en = false;
  175. cd->bit = i;
  176. mutex_init(&cd->core_irq_mutex);
  177. irq = OCTEON_IRQ_SW0 + i;
  178. irq_set_chip_data(irq, cd);
  179. irq_set_chip_and_handler(irq, &octeon_irq_chip_core,
  180. handle_percpu_irq);
  181. }
  182. }
  183. static int next_cpu_for_irq(struct irq_data *data)
  184. {
  185. #ifdef CONFIG_SMP
  186. int cpu;
  187. int weight = cpumask_weight(data->affinity);
  188. struct octeon_ciu_chip_data *cd = irq_data_get_irq_chip_data(data);
  189. if (weight > 1) {
  190. cpu = cd->current_cpu;
  191. for (;;) {
  192. cpu = cpumask_next(cpu, data->affinity);
  193. if (cpu >= nr_cpu_ids) {
  194. cpu = -1;
  195. continue;
  196. } else if (cpumask_test_cpu(cpu, cpu_online_mask)) {
  197. break;
  198. }
  199. }
  200. } else if (weight == 1) {
  201. cpu = cpumask_first(data->affinity);
  202. } else {
  203. cpu = smp_processor_id();
  204. }
  205. cd->current_cpu = cpu;
  206. return cpu;
  207. #else
  208. return smp_processor_id();
  209. #endif
  210. }
  211. static void octeon_irq_ciu_enable(struct irq_data *data)
  212. {
  213. int cpu = next_cpu_for_irq(data);
  214. int coreid = octeon_coreid_for_cpu(cpu);
  215. unsigned long *pen;
  216. unsigned long flags;
  217. struct octeon_ciu_chip_data *cd;
  218. raw_spinlock_t *lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  219. cd = irq_data_get_irq_chip_data(data);
  220. raw_spin_lock_irqsave(lock, flags);
  221. if (cd->line == 0) {
  222. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  223. __set_bit(cd->bit, pen);
  224. /*
  225. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  226. * enabling the irq.
  227. */
  228. wmb();
  229. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  230. } else {
  231. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  232. __set_bit(cd->bit, pen);
  233. /*
  234. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  235. * enabling the irq.
  236. */
  237. wmb();
  238. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  239. }
  240. raw_spin_unlock_irqrestore(lock, flags);
  241. }
  242. static void octeon_irq_ciu_enable_local(struct irq_data *data)
  243. {
  244. unsigned long *pen;
  245. unsigned long flags;
  246. struct octeon_ciu_chip_data *cd;
  247. raw_spinlock_t *lock = this_cpu_ptr(&octeon_irq_ciu_spinlock);
  248. cd = irq_data_get_irq_chip_data(data);
  249. raw_spin_lock_irqsave(lock, flags);
  250. if (cd->line == 0) {
  251. pen = this_cpu_ptr(&octeon_irq_ciu0_en_mirror);
  252. __set_bit(cd->bit, pen);
  253. /*
  254. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  255. * enabling the irq.
  256. */
  257. wmb();
  258. cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
  259. } else {
  260. pen = this_cpu_ptr(&octeon_irq_ciu1_en_mirror);
  261. __set_bit(cd->bit, pen);
  262. /*
  263. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  264. * enabling the irq.
  265. */
  266. wmb();
  267. cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
  268. }
  269. raw_spin_unlock_irqrestore(lock, flags);
  270. }
  271. static void octeon_irq_ciu_disable_local(struct irq_data *data)
  272. {
  273. unsigned long *pen;
  274. unsigned long flags;
  275. struct octeon_ciu_chip_data *cd;
  276. raw_spinlock_t *lock = this_cpu_ptr(&octeon_irq_ciu_spinlock);
  277. cd = irq_data_get_irq_chip_data(data);
  278. raw_spin_lock_irqsave(lock, flags);
  279. if (cd->line == 0) {
  280. pen = this_cpu_ptr(&octeon_irq_ciu0_en_mirror);
  281. __clear_bit(cd->bit, pen);
  282. /*
  283. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  284. * enabling the irq.
  285. */
  286. wmb();
  287. cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
  288. } else {
  289. pen = this_cpu_ptr(&octeon_irq_ciu1_en_mirror);
  290. __clear_bit(cd->bit, pen);
  291. /*
  292. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  293. * enabling the irq.
  294. */
  295. wmb();
  296. cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
  297. }
  298. raw_spin_unlock_irqrestore(lock, flags);
  299. }
  300. static void octeon_irq_ciu_disable_all(struct irq_data *data)
  301. {
  302. unsigned long flags;
  303. unsigned long *pen;
  304. int cpu;
  305. struct octeon_ciu_chip_data *cd;
  306. raw_spinlock_t *lock;
  307. cd = irq_data_get_irq_chip_data(data);
  308. for_each_online_cpu(cpu) {
  309. int coreid = octeon_coreid_for_cpu(cpu);
  310. lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  311. if (cd->line == 0)
  312. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  313. else
  314. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  315. raw_spin_lock_irqsave(lock, flags);
  316. __clear_bit(cd->bit, pen);
  317. /*
  318. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  319. * enabling the irq.
  320. */
  321. wmb();
  322. if (cd->line == 0)
  323. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  324. else
  325. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  326. raw_spin_unlock_irqrestore(lock, flags);
  327. }
  328. }
  329. static void octeon_irq_ciu_enable_all(struct irq_data *data)
  330. {
  331. unsigned long flags;
  332. unsigned long *pen;
  333. int cpu;
  334. struct octeon_ciu_chip_data *cd;
  335. raw_spinlock_t *lock;
  336. cd = irq_data_get_irq_chip_data(data);
  337. for_each_online_cpu(cpu) {
  338. int coreid = octeon_coreid_for_cpu(cpu);
  339. lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  340. if (cd->line == 0)
  341. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  342. else
  343. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  344. raw_spin_lock_irqsave(lock, flags);
  345. __set_bit(cd->bit, pen);
  346. /*
  347. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  348. * enabling the irq.
  349. */
  350. wmb();
  351. if (cd->line == 0)
  352. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  353. else
  354. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  355. raw_spin_unlock_irqrestore(lock, flags);
  356. }
  357. }
  358. /*
  359. * Enable the irq on the next core in the affinity set for chips that
  360. * have the EN*_W1{S,C} registers.
  361. */
  362. static void octeon_irq_ciu_enable_v2(struct irq_data *data)
  363. {
  364. u64 mask;
  365. int cpu = next_cpu_for_irq(data);
  366. struct octeon_ciu_chip_data *cd;
  367. cd = irq_data_get_irq_chip_data(data);
  368. mask = 1ull << (cd->bit);
  369. /*
  370. * Called under the desc lock, so these should never get out
  371. * of sync.
  372. */
  373. if (cd->line == 0) {
  374. int index = octeon_coreid_for_cpu(cpu) * 2;
  375. set_bit(cd->bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  376. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  377. } else {
  378. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  379. set_bit(cd->bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  380. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  381. }
  382. }
  383. /*
  384. * Enable the irq in the sum2 registers.
  385. */
  386. static void octeon_irq_ciu_enable_sum2(struct irq_data *data)
  387. {
  388. u64 mask;
  389. int cpu = next_cpu_for_irq(data);
  390. int index = octeon_coreid_for_cpu(cpu);
  391. struct octeon_ciu_chip_data *cd;
  392. cd = irq_data_get_irq_chip_data(data);
  393. mask = 1ull << (cd->bit);
  394. cvmx_write_csr(CVMX_CIU_EN2_PPX_IP4_W1S(index), mask);
  395. }
  396. /*
  397. * Disable the irq in the sum2 registers.
  398. */
  399. static void octeon_irq_ciu_disable_local_sum2(struct irq_data *data)
  400. {
  401. u64 mask;
  402. int cpu = next_cpu_for_irq(data);
  403. int index = octeon_coreid_for_cpu(cpu);
  404. struct octeon_ciu_chip_data *cd;
  405. cd = irq_data_get_irq_chip_data(data);
  406. mask = 1ull << (cd->bit);
  407. cvmx_write_csr(CVMX_CIU_EN2_PPX_IP4_W1C(index), mask);
  408. }
  409. static void octeon_irq_ciu_ack_sum2(struct irq_data *data)
  410. {
  411. u64 mask;
  412. int cpu = next_cpu_for_irq(data);
  413. int index = octeon_coreid_for_cpu(cpu);
  414. struct octeon_ciu_chip_data *cd;
  415. cd = irq_data_get_irq_chip_data(data);
  416. mask = 1ull << (cd->bit);
  417. cvmx_write_csr(CVMX_CIU_SUM2_PPX_IP4(index), mask);
  418. }
  419. static void octeon_irq_ciu_disable_all_sum2(struct irq_data *data)
  420. {
  421. int cpu;
  422. struct octeon_ciu_chip_data *cd;
  423. u64 mask;
  424. cd = irq_data_get_irq_chip_data(data);
  425. mask = 1ull << (cd->bit);
  426. for_each_online_cpu(cpu) {
  427. int coreid = octeon_coreid_for_cpu(cpu);
  428. cvmx_write_csr(CVMX_CIU_EN2_PPX_IP4_W1C(coreid), mask);
  429. }
  430. }
  431. /*
  432. * Enable the irq on the current CPU for chips that
  433. * have the EN*_W1{S,C} registers.
  434. */
  435. static void octeon_irq_ciu_enable_local_v2(struct irq_data *data)
  436. {
  437. u64 mask;
  438. struct octeon_ciu_chip_data *cd;
  439. cd = irq_data_get_irq_chip_data(data);
  440. mask = 1ull << (cd->bit);
  441. if (cd->line == 0) {
  442. int index = cvmx_get_core_num() * 2;
  443. set_bit(cd->bit, this_cpu_ptr(&octeon_irq_ciu0_en_mirror));
  444. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  445. } else {
  446. int index = cvmx_get_core_num() * 2 + 1;
  447. set_bit(cd->bit, this_cpu_ptr(&octeon_irq_ciu1_en_mirror));
  448. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  449. }
  450. }
  451. static void octeon_irq_ciu_disable_local_v2(struct irq_data *data)
  452. {
  453. u64 mask;
  454. struct octeon_ciu_chip_data *cd;
  455. cd = irq_data_get_irq_chip_data(data);
  456. mask = 1ull << (cd->bit);
  457. if (cd->line == 0) {
  458. int index = cvmx_get_core_num() * 2;
  459. clear_bit(cd->bit, this_cpu_ptr(&octeon_irq_ciu0_en_mirror));
  460. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  461. } else {
  462. int index = cvmx_get_core_num() * 2 + 1;
  463. clear_bit(cd->bit, this_cpu_ptr(&octeon_irq_ciu1_en_mirror));
  464. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  465. }
  466. }
  467. /*
  468. * Write to the W1C bit in CVMX_CIU_INTX_SUM0 to clear the irq.
  469. */
  470. static void octeon_irq_ciu_ack(struct irq_data *data)
  471. {
  472. u64 mask;
  473. struct octeon_ciu_chip_data *cd;
  474. cd = irq_data_get_irq_chip_data(data);
  475. mask = 1ull << (cd->bit);
  476. if (cd->line == 0) {
  477. int index = cvmx_get_core_num() * 2;
  478. cvmx_write_csr(CVMX_CIU_INTX_SUM0(index), mask);
  479. } else {
  480. cvmx_write_csr(CVMX_CIU_INT_SUM1, mask);
  481. }
  482. }
  483. /*
  484. * Disable the irq on the all cores for chips that have the EN*_W1{S,C}
  485. * registers.
  486. */
  487. static void octeon_irq_ciu_disable_all_v2(struct irq_data *data)
  488. {
  489. int cpu;
  490. u64 mask;
  491. struct octeon_ciu_chip_data *cd;
  492. cd = irq_data_get_irq_chip_data(data);
  493. mask = 1ull << (cd->bit);
  494. if (cd->line == 0) {
  495. for_each_online_cpu(cpu) {
  496. int index = octeon_coreid_for_cpu(cpu) * 2;
  497. clear_bit(cd->bit,
  498. &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  499. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  500. }
  501. } else {
  502. for_each_online_cpu(cpu) {
  503. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  504. clear_bit(cd->bit,
  505. &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  506. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  507. }
  508. }
  509. }
  510. /*
  511. * Enable the irq on the all cores for chips that have the EN*_W1{S,C}
  512. * registers.
  513. */
  514. static void octeon_irq_ciu_enable_all_v2(struct irq_data *data)
  515. {
  516. int cpu;
  517. u64 mask;
  518. struct octeon_ciu_chip_data *cd;
  519. cd = irq_data_get_irq_chip_data(data);
  520. mask = 1ull << (cd->bit);
  521. if (cd->line == 0) {
  522. for_each_online_cpu(cpu) {
  523. int index = octeon_coreid_for_cpu(cpu) * 2;
  524. set_bit(cd->bit,
  525. &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
  526. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  527. }
  528. } else {
  529. for_each_online_cpu(cpu) {
  530. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  531. set_bit(cd->bit,
  532. &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  533. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  534. }
  535. }
  536. }
  537. static void octeon_irq_gpio_setup(struct irq_data *data)
  538. {
  539. union cvmx_gpio_bit_cfgx cfg;
  540. struct octeon_ciu_chip_data *cd;
  541. u32 t = irqd_get_trigger_type(data);
  542. cd = irq_data_get_irq_chip_data(data);
  543. cfg.u64 = 0;
  544. cfg.s.int_en = 1;
  545. cfg.s.int_type = (t & IRQ_TYPE_EDGE_BOTH) != 0;
  546. cfg.s.rx_xor = (t & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) != 0;
  547. /* 140 nS glitch filter*/
  548. cfg.s.fil_cnt = 7;
  549. cfg.s.fil_sel = 3;
  550. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd->gpio_line), cfg.u64);
  551. }
  552. static void octeon_irq_ciu_enable_gpio_v2(struct irq_data *data)
  553. {
  554. octeon_irq_gpio_setup(data);
  555. octeon_irq_ciu_enable_v2(data);
  556. }
  557. static void octeon_irq_ciu_enable_gpio(struct irq_data *data)
  558. {
  559. octeon_irq_gpio_setup(data);
  560. octeon_irq_ciu_enable(data);
  561. }
  562. static int octeon_irq_ciu_gpio_set_type(struct irq_data *data, unsigned int t)
  563. {
  564. irqd_set_trigger_type(data, t);
  565. octeon_irq_gpio_setup(data);
  566. return IRQ_SET_MASK_OK;
  567. }
  568. static void octeon_irq_ciu_disable_gpio_v2(struct irq_data *data)
  569. {
  570. struct octeon_ciu_chip_data *cd;
  571. cd = irq_data_get_irq_chip_data(data);
  572. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd->gpio_line), 0);
  573. octeon_irq_ciu_disable_all_v2(data);
  574. }
  575. static void octeon_irq_ciu_disable_gpio(struct irq_data *data)
  576. {
  577. struct octeon_ciu_chip_data *cd;
  578. cd = irq_data_get_irq_chip_data(data);
  579. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd->gpio_line), 0);
  580. octeon_irq_ciu_disable_all(data);
  581. }
  582. static void octeon_irq_ciu_gpio_ack(struct irq_data *data)
  583. {
  584. struct octeon_ciu_chip_data *cd;
  585. u64 mask;
  586. cd = irq_data_get_irq_chip_data(data);
  587. mask = 1ull << (cd->gpio_line);
  588. cvmx_write_csr(CVMX_GPIO_INT_CLR, mask);
  589. }
  590. static void octeon_irq_handle_trigger(unsigned int irq, struct irq_desc *desc)
  591. {
  592. struct irq_data *data = irq_desc_get_irq_data(desc);
  593. if (irqd_get_trigger_type(data) & IRQ_TYPE_EDGE_BOTH)
  594. handle_edge_irq(irq, desc);
  595. else
  596. handle_level_irq(irq, desc);
  597. }
  598. #ifdef CONFIG_SMP
  599. static void octeon_irq_cpu_offline_ciu(struct irq_data *data)
  600. {
  601. int cpu = smp_processor_id();
  602. cpumask_t new_affinity;
  603. if (!cpumask_test_cpu(cpu, data->affinity))
  604. return;
  605. if (cpumask_weight(data->affinity) > 1) {
  606. /*
  607. * It has multi CPU affinity, just remove this CPU
  608. * from the affinity set.
  609. */
  610. cpumask_copy(&new_affinity, data->affinity);
  611. cpumask_clear_cpu(cpu, &new_affinity);
  612. } else {
  613. /* Otherwise, put it on lowest numbered online CPU. */
  614. cpumask_clear(&new_affinity);
  615. cpumask_set_cpu(cpumask_first(cpu_online_mask), &new_affinity);
  616. }
  617. irq_set_affinity_locked(data, &new_affinity, false);
  618. }
  619. static int octeon_irq_ciu_set_affinity(struct irq_data *data,
  620. const struct cpumask *dest, bool force)
  621. {
  622. int cpu;
  623. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  624. unsigned long flags;
  625. struct octeon_ciu_chip_data *cd;
  626. unsigned long *pen;
  627. raw_spinlock_t *lock;
  628. cd = irq_data_get_irq_chip_data(data);
  629. /*
  630. * For non-v2 CIU, we will allow only single CPU affinity.
  631. * This removes the need to do locking in the .ack/.eoi
  632. * functions.
  633. */
  634. if (cpumask_weight(dest) != 1)
  635. return -EINVAL;
  636. if (!enable_one)
  637. return 0;
  638. for_each_online_cpu(cpu) {
  639. int coreid = octeon_coreid_for_cpu(cpu);
  640. lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  641. raw_spin_lock_irqsave(lock, flags);
  642. if (cd->line == 0)
  643. pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  644. else
  645. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  646. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  647. enable_one = 0;
  648. __set_bit(cd->bit, pen);
  649. } else {
  650. __clear_bit(cd->bit, pen);
  651. }
  652. /*
  653. * Must be visible to octeon_irq_ip{2,3}_ciu() before
  654. * enabling the irq.
  655. */
  656. wmb();
  657. if (cd->line == 0)
  658. cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
  659. else
  660. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  661. raw_spin_unlock_irqrestore(lock, flags);
  662. }
  663. return 0;
  664. }
  665. /*
  666. * Set affinity for the irq for chips that have the EN*_W1{S,C}
  667. * registers.
  668. */
  669. static int octeon_irq_ciu_set_affinity_v2(struct irq_data *data,
  670. const struct cpumask *dest,
  671. bool force)
  672. {
  673. int cpu;
  674. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  675. u64 mask;
  676. struct octeon_ciu_chip_data *cd;
  677. if (!enable_one)
  678. return 0;
  679. cd = irq_data_get_irq_chip_data(data);
  680. mask = 1ull << cd->bit;
  681. if (cd->line == 0) {
  682. for_each_online_cpu(cpu) {
  683. unsigned long *pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
  684. int index = octeon_coreid_for_cpu(cpu) * 2;
  685. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  686. enable_one = false;
  687. set_bit(cd->bit, pen);
  688. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
  689. } else {
  690. clear_bit(cd->bit, pen);
  691. cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
  692. }
  693. }
  694. } else {
  695. for_each_online_cpu(cpu) {
  696. unsigned long *pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  697. int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
  698. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  699. enable_one = false;
  700. set_bit(cd->bit, pen);
  701. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
  702. } else {
  703. clear_bit(cd->bit, pen);
  704. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
  705. }
  706. }
  707. }
  708. return 0;
  709. }
  710. static int octeon_irq_ciu_set_affinity_sum2(struct irq_data *data,
  711. const struct cpumask *dest,
  712. bool force)
  713. {
  714. int cpu;
  715. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  716. u64 mask;
  717. struct octeon_ciu_chip_data *cd;
  718. if (!enable_one)
  719. return 0;
  720. cd = irq_data_get_irq_chip_data(data);
  721. mask = 1ull << cd->bit;
  722. for_each_online_cpu(cpu) {
  723. int index = octeon_coreid_for_cpu(cpu);
  724. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  725. enable_one = false;
  726. cvmx_write_csr(CVMX_CIU_EN2_PPX_IP4_W1S(index), mask);
  727. } else {
  728. cvmx_write_csr(CVMX_CIU_EN2_PPX_IP4_W1C(index), mask);
  729. }
  730. }
  731. return 0;
  732. }
  733. #endif
  734. /*
  735. * Newer octeon chips have support for lockless CIU operation.
  736. */
  737. static struct irq_chip octeon_irq_chip_ciu_v2 = {
  738. .name = "CIU",
  739. .irq_enable = octeon_irq_ciu_enable_v2,
  740. .irq_disable = octeon_irq_ciu_disable_all_v2,
  741. .irq_mask = octeon_irq_ciu_disable_local_v2,
  742. .irq_unmask = octeon_irq_ciu_enable_v2,
  743. #ifdef CONFIG_SMP
  744. .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
  745. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  746. #endif
  747. };
  748. static struct irq_chip octeon_irq_chip_ciu_v2_edge = {
  749. .name = "CIU",
  750. .irq_enable = octeon_irq_ciu_enable_v2,
  751. .irq_disable = octeon_irq_ciu_disable_all_v2,
  752. .irq_ack = octeon_irq_ciu_ack,
  753. .irq_mask = octeon_irq_ciu_disable_local_v2,
  754. .irq_unmask = octeon_irq_ciu_enable_v2,
  755. #ifdef CONFIG_SMP
  756. .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
  757. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  758. #endif
  759. };
  760. /*
  761. * Newer octeon chips have support for lockless CIU operation.
  762. */
  763. static struct irq_chip octeon_irq_chip_ciu_sum2 = {
  764. .name = "CIU",
  765. .irq_enable = octeon_irq_ciu_enable_sum2,
  766. .irq_disable = octeon_irq_ciu_disable_all_sum2,
  767. .irq_mask = octeon_irq_ciu_disable_local_sum2,
  768. .irq_unmask = octeon_irq_ciu_enable_sum2,
  769. #ifdef CONFIG_SMP
  770. .irq_set_affinity = octeon_irq_ciu_set_affinity_sum2,
  771. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  772. #endif
  773. };
  774. static struct irq_chip octeon_irq_chip_ciu_sum2_edge = {
  775. .name = "CIU",
  776. .irq_enable = octeon_irq_ciu_enable_sum2,
  777. .irq_disable = octeon_irq_ciu_disable_all_sum2,
  778. .irq_ack = octeon_irq_ciu_ack_sum2,
  779. .irq_mask = octeon_irq_ciu_disable_local_sum2,
  780. .irq_unmask = octeon_irq_ciu_enable_sum2,
  781. #ifdef CONFIG_SMP
  782. .irq_set_affinity = octeon_irq_ciu_set_affinity_sum2,
  783. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  784. #endif
  785. };
  786. static struct irq_chip octeon_irq_chip_ciu = {
  787. .name = "CIU",
  788. .irq_enable = octeon_irq_ciu_enable,
  789. .irq_disable = octeon_irq_ciu_disable_all,
  790. .irq_mask = octeon_irq_ciu_disable_local,
  791. .irq_unmask = octeon_irq_ciu_enable,
  792. #ifdef CONFIG_SMP
  793. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  794. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  795. #endif
  796. };
  797. static struct irq_chip octeon_irq_chip_ciu_edge = {
  798. .name = "CIU",
  799. .irq_enable = octeon_irq_ciu_enable,
  800. .irq_disable = octeon_irq_ciu_disable_all,
  801. .irq_ack = octeon_irq_ciu_ack,
  802. .irq_mask = octeon_irq_ciu_disable_local,
  803. .irq_unmask = octeon_irq_ciu_enable,
  804. #ifdef CONFIG_SMP
  805. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  806. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  807. #endif
  808. };
  809. /* The mbox versions don't do any affinity or round-robin. */
  810. static struct irq_chip octeon_irq_chip_ciu_mbox_v2 = {
  811. .name = "CIU-M",
  812. .irq_enable = octeon_irq_ciu_enable_all_v2,
  813. .irq_disable = octeon_irq_ciu_disable_all_v2,
  814. .irq_ack = octeon_irq_ciu_disable_local_v2,
  815. .irq_eoi = octeon_irq_ciu_enable_local_v2,
  816. .irq_cpu_online = octeon_irq_ciu_enable_local_v2,
  817. .irq_cpu_offline = octeon_irq_ciu_disable_local_v2,
  818. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  819. };
  820. static struct irq_chip octeon_irq_chip_ciu_mbox = {
  821. .name = "CIU-M",
  822. .irq_enable = octeon_irq_ciu_enable_all,
  823. .irq_disable = octeon_irq_ciu_disable_all,
  824. .irq_ack = octeon_irq_ciu_disable_local,
  825. .irq_eoi = octeon_irq_ciu_enable_local,
  826. .irq_cpu_online = octeon_irq_ciu_enable_local,
  827. .irq_cpu_offline = octeon_irq_ciu_disable_local,
  828. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  829. };
  830. static struct irq_chip octeon_irq_chip_ciu_gpio_v2 = {
  831. .name = "CIU-GPIO",
  832. .irq_enable = octeon_irq_ciu_enable_gpio_v2,
  833. .irq_disable = octeon_irq_ciu_disable_gpio_v2,
  834. .irq_ack = octeon_irq_ciu_gpio_ack,
  835. .irq_mask = octeon_irq_ciu_disable_local_v2,
  836. .irq_unmask = octeon_irq_ciu_enable_v2,
  837. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  838. #ifdef CONFIG_SMP
  839. .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
  840. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  841. #endif
  842. .flags = IRQCHIP_SET_TYPE_MASKED,
  843. };
  844. static struct irq_chip octeon_irq_chip_ciu_gpio = {
  845. .name = "CIU-GPIO",
  846. .irq_enable = octeon_irq_ciu_enable_gpio,
  847. .irq_disable = octeon_irq_ciu_disable_gpio,
  848. .irq_mask = octeon_irq_ciu_disable_local,
  849. .irq_unmask = octeon_irq_ciu_enable,
  850. .irq_ack = octeon_irq_ciu_gpio_ack,
  851. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  852. #ifdef CONFIG_SMP
  853. .irq_set_affinity = octeon_irq_ciu_set_affinity,
  854. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  855. #endif
  856. .flags = IRQCHIP_SET_TYPE_MASKED,
  857. };
  858. /*
  859. * Watchdog interrupts are special. They are associated with a single
  860. * core, so we hardwire the affinity to that core.
  861. */
  862. static void octeon_irq_ciu_wd_enable(struct irq_data *data)
  863. {
  864. unsigned long flags;
  865. unsigned long *pen;
  866. int coreid = data->irq - OCTEON_IRQ_WDOG0; /* Bit 0-63 of EN1 */
  867. int cpu = octeon_cpu_for_coreid(coreid);
  868. raw_spinlock_t *lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
  869. raw_spin_lock_irqsave(lock, flags);
  870. pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
  871. __set_bit(coreid, pen);
  872. /*
  873. * Must be visible to octeon_irq_ip{2,3}_ciu() before enabling
  874. * the irq.
  875. */
  876. wmb();
  877. cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
  878. raw_spin_unlock_irqrestore(lock, flags);
  879. }
  880. /*
  881. * Watchdog interrupts are special. They are associated with a single
  882. * core, so we hardwire the affinity to that core.
  883. */
  884. static void octeon_irq_ciu1_wd_enable_v2(struct irq_data *data)
  885. {
  886. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  887. int cpu = octeon_cpu_for_coreid(coreid);
  888. set_bit(coreid, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
  889. cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(coreid * 2 + 1), 1ull << coreid);
  890. }
  891. static struct irq_chip octeon_irq_chip_ciu_wd_v2 = {
  892. .name = "CIU-W",
  893. .irq_enable = octeon_irq_ciu1_wd_enable_v2,
  894. .irq_disable = octeon_irq_ciu_disable_all_v2,
  895. .irq_mask = octeon_irq_ciu_disable_local_v2,
  896. .irq_unmask = octeon_irq_ciu_enable_local_v2,
  897. };
  898. static struct irq_chip octeon_irq_chip_ciu_wd = {
  899. .name = "CIU-W",
  900. .irq_enable = octeon_irq_ciu_wd_enable,
  901. .irq_disable = octeon_irq_ciu_disable_all,
  902. .irq_mask = octeon_irq_ciu_disable_local,
  903. .irq_unmask = octeon_irq_ciu_enable_local,
  904. };
  905. static bool octeon_irq_ciu_is_edge(unsigned int line, unsigned int bit)
  906. {
  907. bool edge = false;
  908. if (line == 0)
  909. switch (bit) {
  910. case 48 ... 49: /* GMX DRP */
  911. case 50: /* IPD_DRP */
  912. case 52 ... 55: /* Timers */
  913. case 58: /* MPI */
  914. edge = true;
  915. break;
  916. default:
  917. break;
  918. }
  919. else /* line == 1 */
  920. switch (bit) {
  921. case 47: /* PTP */
  922. edge = true;
  923. break;
  924. default:
  925. break;
  926. }
  927. return edge;
  928. }
  929. struct octeon_irq_gpio_domain_data {
  930. unsigned int base_hwirq;
  931. };
  932. static int octeon_irq_gpio_xlat(struct irq_domain *d,
  933. struct device_node *node,
  934. const u32 *intspec,
  935. unsigned int intsize,
  936. unsigned long *out_hwirq,
  937. unsigned int *out_type)
  938. {
  939. unsigned int type;
  940. unsigned int pin;
  941. unsigned int trigger;
  942. if (d->of_node != node)
  943. return -EINVAL;
  944. if (intsize < 2)
  945. return -EINVAL;
  946. pin = intspec[0];
  947. if (pin >= 16)
  948. return -EINVAL;
  949. trigger = intspec[1];
  950. switch (trigger) {
  951. case 1:
  952. type = IRQ_TYPE_EDGE_RISING;
  953. break;
  954. case 2:
  955. type = IRQ_TYPE_EDGE_FALLING;
  956. break;
  957. case 4:
  958. type = IRQ_TYPE_LEVEL_HIGH;
  959. break;
  960. case 8:
  961. type = IRQ_TYPE_LEVEL_LOW;
  962. break;
  963. default:
  964. pr_err("Error: (%s) Invalid irq trigger specification: %x\n",
  965. node->name,
  966. trigger);
  967. type = IRQ_TYPE_LEVEL_LOW;
  968. break;
  969. }
  970. *out_type = type;
  971. *out_hwirq = pin;
  972. return 0;
  973. }
  974. static int octeon_irq_ciu_xlat(struct irq_domain *d,
  975. struct device_node *node,
  976. const u32 *intspec,
  977. unsigned int intsize,
  978. unsigned long *out_hwirq,
  979. unsigned int *out_type)
  980. {
  981. unsigned int ciu, bit;
  982. struct octeon_irq_ciu_domain_data *dd = d->host_data;
  983. ciu = intspec[0];
  984. bit = intspec[1];
  985. if (ciu >= dd->num_sum || bit > 63)
  986. return -EINVAL;
  987. *out_hwirq = (ciu << 6) | bit;
  988. *out_type = 0;
  989. return 0;
  990. }
  991. static struct irq_chip *octeon_irq_ciu_chip;
  992. static struct irq_chip *octeon_irq_ciu_chip_edge;
  993. static struct irq_chip *octeon_irq_gpio_chip;
  994. static bool octeon_irq_virq_in_range(unsigned int virq)
  995. {
  996. /* We cannot let it overflow the mapping array. */
  997. if (virq < (1ul << 8 * sizeof(octeon_irq_ciu_to_irq[0][0])))
  998. return true;
  999. WARN_ONCE(true, "virq out of range %u.\n", virq);
  1000. return false;
  1001. }
  1002. static int octeon_irq_ciu_map(struct irq_domain *d,
  1003. unsigned int virq, irq_hw_number_t hw)
  1004. {
  1005. int rv;
  1006. unsigned int line = hw >> 6;
  1007. unsigned int bit = hw & 63;
  1008. struct octeon_irq_ciu_domain_data *dd = d->host_data;
  1009. if (!octeon_irq_virq_in_range(virq))
  1010. return -EINVAL;
  1011. /* Don't map irq if it is reserved for GPIO. */
  1012. if (line == 0 && bit >= 16 && bit <32)
  1013. return 0;
  1014. if (line >= dd->num_sum || octeon_irq_ciu_to_irq[line][bit] != 0)
  1015. return -EINVAL;
  1016. if (line == 2) {
  1017. if (octeon_irq_ciu_is_edge(line, bit))
  1018. rv = octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1019. &octeon_irq_chip_ciu_sum2_edge,
  1020. handle_edge_irq);
  1021. else
  1022. rv = octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1023. &octeon_irq_chip_ciu_sum2,
  1024. handle_level_irq);
  1025. } else {
  1026. if (octeon_irq_ciu_is_edge(line, bit))
  1027. rv = octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1028. octeon_irq_ciu_chip_edge,
  1029. handle_edge_irq);
  1030. else
  1031. rv = octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1032. octeon_irq_ciu_chip,
  1033. handle_level_irq);
  1034. }
  1035. return rv;
  1036. }
  1037. static int octeon_irq_gpio_map(struct irq_domain *d,
  1038. unsigned int virq, irq_hw_number_t hw)
  1039. {
  1040. struct octeon_irq_gpio_domain_data *gpiod = d->host_data;
  1041. unsigned int line, bit;
  1042. int r;
  1043. if (!octeon_irq_virq_in_range(virq))
  1044. return -EINVAL;
  1045. line = (hw + gpiod->base_hwirq) >> 6;
  1046. bit = (hw + gpiod->base_hwirq) & 63;
  1047. if (line > ARRAY_SIZE(octeon_irq_ciu_to_irq) ||
  1048. octeon_irq_ciu_to_irq[line][bit] != 0)
  1049. return -EINVAL;
  1050. r = octeon_irq_set_ciu_mapping(virq, line, bit, hw,
  1051. octeon_irq_gpio_chip, octeon_irq_handle_trigger);
  1052. return r;
  1053. }
  1054. static struct irq_domain_ops octeon_irq_domain_ciu_ops = {
  1055. .map = octeon_irq_ciu_map,
  1056. .unmap = octeon_irq_free_cd,
  1057. .xlate = octeon_irq_ciu_xlat,
  1058. };
  1059. static struct irq_domain_ops octeon_irq_domain_gpio_ops = {
  1060. .map = octeon_irq_gpio_map,
  1061. .unmap = octeon_irq_free_cd,
  1062. .xlate = octeon_irq_gpio_xlat,
  1063. };
  1064. static void octeon_irq_ip2_ciu(void)
  1065. {
  1066. const unsigned long core_id = cvmx_get_core_num();
  1067. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(core_id * 2));
  1068. ciu_sum &= __this_cpu_read(octeon_irq_ciu0_en_mirror);
  1069. if (likely(ciu_sum)) {
  1070. int bit = fls64(ciu_sum) - 1;
  1071. int irq = octeon_irq_ciu_to_irq[0][bit];
  1072. if (likely(irq))
  1073. do_IRQ(irq);
  1074. else
  1075. spurious_interrupt();
  1076. } else {
  1077. spurious_interrupt();
  1078. }
  1079. }
  1080. static void octeon_irq_ip3_ciu(void)
  1081. {
  1082. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
  1083. ciu_sum &= __this_cpu_read(octeon_irq_ciu1_en_mirror);
  1084. if (likely(ciu_sum)) {
  1085. int bit = fls64(ciu_sum) - 1;
  1086. int irq = octeon_irq_ciu_to_irq[1][bit];
  1087. if (likely(irq))
  1088. do_IRQ(irq);
  1089. else
  1090. spurious_interrupt();
  1091. } else {
  1092. spurious_interrupt();
  1093. }
  1094. }
  1095. static void octeon_irq_ip4_ciu(void)
  1096. {
  1097. int coreid = cvmx_get_core_num();
  1098. u64 ciu_sum = cvmx_read_csr(CVMX_CIU_SUM2_PPX_IP4(coreid));
  1099. u64 ciu_en = cvmx_read_csr(CVMX_CIU_EN2_PPX_IP4(coreid));
  1100. ciu_sum &= ciu_en;
  1101. if (likely(ciu_sum)) {
  1102. int bit = fls64(ciu_sum) - 1;
  1103. int irq = octeon_irq_ciu_to_irq[2][bit];
  1104. if (likely(irq))
  1105. do_IRQ(irq);
  1106. else
  1107. spurious_interrupt();
  1108. } else {
  1109. spurious_interrupt();
  1110. }
  1111. }
  1112. static bool octeon_irq_use_ip4;
  1113. static void octeon_irq_local_enable_ip4(void *arg)
  1114. {
  1115. set_c0_status(STATUSF_IP4);
  1116. }
  1117. static void octeon_irq_ip4_mask(void)
  1118. {
  1119. clear_c0_status(STATUSF_IP4);
  1120. spurious_interrupt();
  1121. }
  1122. static void (*octeon_irq_ip2)(void);
  1123. static void (*octeon_irq_ip3)(void);
  1124. static void (*octeon_irq_ip4)(void);
  1125. void (*octeon_irq_setup_secondary)(void);
  1126. void octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t h)
  1127. {
  1128. octeon_irq_ip4 = h;
  1129. octeon_irq_use_ip4 = true;
  1130. on_each_cpu(octeon_irq_local_enable_ip4, NULL, 1);
  1131. }
  1132. static void octeon_irq_percpu_enable(void)
  1133. {
  1134. irq_cpu_online();
  1135. }
  1136. static void octeon_irq_init_ciu_percpu(void)
  1137. {
  1138. int coreid = cvmx_get_core_num();
  1139. __this_cpu_write(octeon_irq_ciu0_en_mirror, 0);
  1140. __this_cpu_write(octeon_irq_ciu1_en_mirror, 0);
  1141. wmb();
  1142. raw_spin_lock_init(this_cpu_ptr(&octeon_irq_ciu_spinlock));
  1143. /*
  1144. * Disable All CIU Interrupts. The ones we need will be
  1145. * enabled later. Read the SUM register so we know the write
  1146. * completed.
  1147. */
  1148. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2)), 0);
  1149. cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2 + 1)), 0);
  1150. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2)), 0);
  1151. cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2 + 1)), 0);
  1152. cvmx_read_csr(CVMX_CIU_INTX_SUM0((coreid * 2)));
  1153. }
  1154. static void octeon_irq_init_ciu2_percpu(void)
  1155. {
  1156. u64 regx, ipx;
  1157. int coreid = cvmx_get_core_num();
  1158. u64 base = CVMX_CIU2_EN_PPX_IP2_WRKQ(coreid);
  1159. /*
  1160. * Disable All CIU2 Interrupts. The ones we need will be
  1161. * enabled later. Read the SUM register so we know the write
  1162. * completed.
  1163. *
  1164. * There are 9 registers and 3 IPX levels with strides 0x1000
  1165. * and 0x200 respectivly. Use loops to clear them.
  1166. */
  1167. for (regx = 0; regx <= 0x8000; regx += 0x1000) {
  1168. for (ipx = 0; ipx <= 0x400; ipx += 0x200)
  1169. cvmx_write_csr(base + regx + ipx, 0);
  1170. }
  1171. cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid));
  1172. }
  1173. static void octeon_irq_setup_secondary_ciu(void)
  1174. {
  1175. octeon_irq_init_ciu_percpu();
  1176. octeon_irq_percpu_enable();
  1177. /* Enable the CIU lines */
  1178. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1179. if (octeon_irq_use_ip4)
  1180. set_c0_status(STATUSF_IP4);
  1181. else
  1182. clear_c0_status(STATUSF_IP4);
  1183. }
  1184. static void octeon_irq_setup_secondary_ciu2(void)
  1185. {
  1186. octeon_irq_init_ciu2_percpu();
  1187. octeon_irq_percpu_enable();
  1188. /* Enable the CIU lines */
  1189. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1190. if (octeon_irq_use_ip4)
  1191. set_c0_status(STATUSF_IP4);
  1192. else
  1193. clear_c0_status(STATUSF_IP4);
  1194. }
  1195. static int __init octeon_irq_init_ciu(
  1196. struct device_node *ciu_node, struct device_node *parent)
  1197. {
  1198. unsigned int i, r;
  1199. struct irq_chip *chip;
  1200. struct irq_chip *chip_edge;
  1201. struct irq_chip *chip_mbox;
  1202. struct irq_chip *chip_wd;
  1203. struct irq_domain *ciu_domain = NULL;
  1204. struct octeon_irq_ciu_domain_data *dd;
  1205. dd = kzalloc(sizeof(*dd), GFP_KERNEL);
  1206. if (!dd)
  1207. return -ENOMEM;
  1208. octeon_irq_init_ciu_percpu();
  1209. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu;
  1210. octeon_irq_ip2 = octeon_irq_ip2_ciu;
  1211. octeon_irq_ip3 = octeon_irq_ip3_ciu;
  1212. if ((OCTEON_IS_OCTEON2() || OCTEON_IS_OCTEON3())
  1213. && !OCTEON_IS_MODEL(OCTEON_CN63XX)) {
  1214. octeon_irq_ip4 = octeon_irq_ip4_ciu;
  1215. dd->num_sum = 3;
  1216. octeon_irq_use_ip4 = true;
  1217. } else {
  1218. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1219. dd->num_sum = 2;
  1220. octeon_irq_use_ip4 = false;
  1221. }
  1222. if (OCTEON_IS_MODEL(OCTEON_CN58XX_PASS2_X) ||
  1223. OCTEON_IS_MODEL(OCTEON_CN56XX_PASS2_X) ||
  1224. OCTEON_IS_MODEL(OCTEON_CN52XX_PASS2_X) ||
  1225. OCTEON_IS_OCTEON2() || OCTEON_IS_OCTEON3()) {
  1226. chip = &octeon_irq_chip_ciu_v2;
  1227. chip_edge = &octeon_irq_chip_ciu_v2_edge;
  1228. chip_mbox = &octeon_irq_chip_ciu_mbox_v2;
  1229. chip_wd = &octeon_irq_chip_ciu_wd_v2;
  1230. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio_v2;
  1231. } else {
  1232. chip = &octeon_irq_chip_ciu;
  1233. chip_edge = &octeon_irq_chip_ciu_edge;
  1234. chip_mbox = &octeon_irq_chip_ciu_mbox;
  1235. chip_wd = &octeon_irq_chip_ciu_wd;
  1236. octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio;
  1237. }
  1238. octeon_irq_ciu_chip = chip;
  1239. octeon_irq_ciu_chip_edge = chip_edge;
  1240. /* Mips internal */
  1241. octeon_irq_init_core();
  1242. ciu_domain = irq_domain_add_tree(
  1243. ciu_node, &octeon_irq_domain_ciu_ops, dd);
  1244. irq_set_default_host(ciu_domain);
  1245. /* CIU_0 */
  1246. for (i = 0; i < 16; i++) {
  1247. r = octeon_irq_force_ciu_mapping(
  1248. ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i + 0);
  1249. if (r)
  1250. goto err;
  1251. }
  1252. r = octeon_irq_set_ciu_mapping(
  1253. OCTEON_IRQ_MBOX0, 0, 32, 0, chip_mbox, handle_percpu_irq);
  1254. if (r)
  1255. goto err;
  1256. r = octeon_irq_set_ciu_mapping(
  1257. OCTEON_IRQ_MBOX1, 0, 33, 0, chip_mbox, handle_percpu_irq);
  1258. if (r)
  1259. goto err;
  1260. for (i = 0; i < 4; i++) {
  1261. r = octeon_irq_force_ciu_mapping(
  1262. ciu_domain, i + OCTEON_IRQ_PCI_INT0, 0, i + 36);
  1263. if (r)
  1264. goto err;
  1265. }
  1266. for (i = 0; i < 4; i++) {
  1267. r = octeon_irq_force_ciu_mapping(
  1268. ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 0, i + 40);
  1269. if (r)
  1270. goto err;
  1271. }
  1272. r = octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_TWSI, 0, 45);
  1273. if (r)
  1274. goto err;
  1275. r = octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_RML, 0, 46);
  1276. if (r)
  1277. goto err;
  1278. for (i = 0; i < 4; i++) {
  1279. r = octeon_irq_force_ciu_mapping(
  1280. ciu_domain, i + OCTEON_IRQ_TIMER0, 0, i + 52);
  1281. if (r)
  1282. goto err;
  1283. }
  1284. r = octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 0, 56);
  1285. if (r)
  1286. goto err;
  1287. r = octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_TWSI2, 0, 59);
  1288. if (r)
  1289. goto err;
  1290. /* CIU_1 */
  1291. for (i = 0; i < 16; i++) {
  1292. r = octeon_irq_set_ciu_mapping(
  1293. i + OCTEON_IRQ_WDOG0, 1, i + 0, 0, chip_wd,
  1294. handle_level_irq);
  1295. if (r)
  1296. goto err;
  1297. }
  1298. r = octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB1, 1, 17);
  1299. if (r)
  1300. goto err;
  1301. /* Enable the CIU lines */
  1302. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1303. if (octeon_irq_use_ip4)
  1304. set_c0_status(STATUSF_IP4);
  1305. else
  1306. clear_c0_status(STATUSF_IP4);
  1307. return 0;
  1308. err:
  1309. return r;
  1310. }
  1311. static int __init octeon_irq_init_gpio(
  1312. struct device_node *gpio_node, struct device_node *parent)
  1313. {
  1314. struct octeon_irq_gpio_domain_data *gpiod;
  1315. u32 interrupt_cells;
  1316. unsigned int base_hwirq;
  1317. int r;
  1318. r = of_property_read_u32(parent, "#interrupt-cells", &interrupt_cells);
  1319. if (r)
  1320. return r;
  1321. if (interrupt_cells == 1) {
  1322. u32 v;
  1323. r = of_property_read_u32_index(gpio_node, "interrupts", 0, &v);
  1324. if (r) {
  1325. pr_warn("No \"interrupts\" property.\n");
  1326. return r;
  1327. }
  1328. base_hwirq = v;
  1329. } else if (interrupt_cells == 2) {
  1330. u32 v0, v1;
  1331. r = of_property_read_u32_index(gpio_node, "interrupts", 0, &v0);
  1332. if (r) {
  1333. pr_warn("No \"interrupts\" property.\n");
  1334. return r;
  1335. }
  1336. r = of_property_read_u32_index(gpio_node, "interrupts", 1, &v1);
  1337. if (r) {
  1338. pr_warn("No \"interrupts\" property.\n");
  1339. return r;
  1340. }
  1341. base_hwirq = (v0 << 6) | v1;
  1342. } else {
  1343. pr_warn("Bad \"#interrupt-cells\" property: %u\n",
  1344. interrupt_cells);
  1345. return -EINVAL;
  1346. }
  1347. gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
  1348. if (gpiod) {
  1349. /* gpio domain host_data is the base hwirq number. */
  1350. gpiod->base_hwirq = base_hwirq;
  1351. irq_domain_add_linear(
  1352. gpio_node, 16, &octeon_irq_domain_gpio_ops, gpiod);
  1353. } else {
  1354. pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
  1355. return -ENOMEM;
  1356. }
  1357. return 0;
  1358. }
  1359. /*
  1360. * Watchdog interrupts are special. They are associated with a single
  1361. * core, so we hardwire the affinity to that core.
  1362. */
  1363. static void octeon_irq_ciu2_wd_enable(struct irq_data *data)
  1364. {
  1365. u64 mask;
  1366. u64 en_addr;
  1367. int coreid = data->irq - OCTEON_IRQ_WDOG0;
  1368. struct octeon_ciu_chip_data *cd;
  1369. cd = irq_data_get_irq_chip_data(data);
  1370. mask = 1ull << (cd->bit);
  1371. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) +
  1372. (0x1000ull * cd->line);
  1373. cvmx_write_csr(en_addr, mask);
  1374. }
  1375. static void octeon_irq_ciu2_enable(struct irq_data *data)
  1376. {
  1377. u64 mask;
  1378. u64 en_addr;
  1379. int cpu = next_cpu_for_irq(data);
  1380. int coreid = octeon_coreid_for_cpu(cpu);
  1381. struct octeon_ciu_chip_data *cd;
  1382. cd = irq_data_get_irq_chip_data(data);
  1383. mask = 1ull << (cd->bit);
  1384. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) +
  1385. (0x1000ull * cd->line);
  1386. cvmx_write_csr(en_addr, mask);
  1387. }
  1388. static void octeon_irq_ciu2_enable_local(struct irq_data *data)
  1389. {
  1390. u64 mask;
  1391. u64 en_addr;
  1392. int coreid = cvmx_get_core_num();
  1393. struct octeon_ciu_chip_data *cd;
  1394. cd = irq_data_get_irq_chip_data(data);
  1395. mask = 1ull << (cd->bit);
  1396. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) +
  1397. (0x1000ull * cd->line);
  1398. cvmx_write_csr(en_addr, mask);
  1399. }
  1400. static void octeon_irq_ciu2_disable_local(struct irq_data *data)
  1401. {
  1402. u64 mask;
  1403. u64 en_addr;
  1404. int coreid = cvmx_get_core_num();
  1405. struct octeon_ciu_chip_data *cd;
  1406. cd = irq_data_get_irq_chip_data(data);
  1407. mask = 1ull << (cd->bit);
  1408. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(coreid) +
  1409. (0x1000ull * cd->line);
  1410. cvmx_write_csr(en_addr, mask);
  1411. }
  1412. static void octeon_irq_ciu2_ack(struct irq_data *data)
  1413. {
  1414. u64 mask;
  1415. u64 en_addr;
  1416. int coreid = cvmx_get_core_num();
  1417. struct octeon_ciu_chip_data *cd;
  1418. cd = irq_data_get_irq_chip_data(data);
  1419. mask = 1ull << (cd->bit);
  1420. en_addr = CVMX_CIU2_RAW_PPX_IP2_WRKQ(coreid) + (0x1000ull * cd->line);
  1421. cvmx_write_csr(en_addr, mask);
  1422. }
  1423. static void octeon_irq_ciu2_disable_all(struct irq_data *data)
  1424. {
  1425. int cpu;
  1426. u64 mask;
  1427. struct octeon_ciu_chip_data *cd;
  1428. cd = irq_data_get_irq_chip_data(data);
  1429. mask = 1ull << (cd->bit);
  1430. for_each_online_cpu(cpu) {
  1431. u64 en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(
  1432. octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd->line);
  1433. cvmx_write_csr(en_addr, mask);
  1434. }
  1435. }
  1436. static void octeon_irq_ciu2_mbox_enable_all(struct irq_data *data)
  1437. {
  1438. int cpu;
  1439. u64 mask;
  1440. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1441. for_each_online_cpu(cpu) {
  1442. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(
  1443. octeon_coreid_for_cpu(cpu));
  1444. cvmx_write_csr(en_addr, mask);
  1445. }
  1446. }
  1447. static void octeon_irq_ciu2_mbox_disable_all(struct irq_data *data)
  1448. {
  1449. int cpu;
  1450. u64 mask;
  1451. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1452. for_each_online_cpu(cpu) {
  1453. u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(
  1454. octeon_coreid_for_cpu(cpu));
  1455. cvmx_write_csr(en_addr, mask);
  1456. }
  1457. }
  1458. static void octeon_irq_ciu2_mbox_enable_local(struct irq_data *data)
  1459. {
  1460. u64 mask;
  1461. u64 en_addr;
  1462. int coreid = cvmx_get_core_num();
  1463. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1464. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(coreid);
  1465. cvmx_write_csr(en_addr, mask);
  1466. }
  1467. static void octeon_irq_ciu2_mbox_disable_local(struct irq_data *data)
  1468. {
  1469. u64 mask;
  1470. u64 en_addr;
  1471. int coreid = cvmx_get_core_num();
  1472. mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
  1473. en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(coreid);
  1474. cvmx_write_csr(en_addr, mask);
  1475. }
  1476. #ifdef CONFIG_SMP
  1477. static int octeon_irq_ciu2_set_affinity(struct irq_data *data,
  1478. const struct cpumask *dest, bool force)
  1479. {
  1480. int cpu;
  1481. bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
  1482. u64 mask;
  1483. struct octeon_ciu_chip_data *cd;
  1484. if (!enable_one)
  1485. return 0;
  1486. cd = irq_data_get_irq_chip_data(data);
  1487. mask = 1ull << cd->bit;
  1488. for_each_online_cpu(cpu) {
  1489. u64 en_addr;
  1490. if (cpumask_test_cpu(cpu, dest) && enable_one) {
  1491. enable_one = false;
  1492. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(
  1493. octeon_coreid_for_cpu(cpu)) +
  1494. (0x1000ull * cd->line);
  1495. } else {
  1496. en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(
  1497. octeon_coreid_for_cpu(cpu)) +
  1498. (0x1000ull * cd->line);
  1499. }
  1500. cvmx_write_csr(en_addr, mask);
  1501. }
  1502. return 0;
  1503. }
  1504. #endif
  1505. static void octeon_irq_ciu2_enable_gpio(struct irq_data *data)
  1506. {
  1507. octeon_irq_gpio_setup(data);
  1508. octeon_irq_ciu2_enable(data);
  1509. }
  1510. static void octeon_irq_ciu2_disable_gpio(struct irq_data *data)
  1511. {
  1512. struct octeon_ciu_chip_data *cd;
  1513. cd = irq_data_get_irq_chip_data(data);
  1514. cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd->gpio_line), 0);
  1515. octeon_irq_ciu2_disable_all(data);
  1516. }
  1517. static struct irq_chip octeon_irq_chip_ciu2 = {
  1518. .name = "CIU2-E",
  1519. .irq_enable = octeon_irq_ciu2_enable,
  1520. .irq_disable = octeon_irq_ciu2_disable_all,
  1521. .irq_mask = octeon_irq_ciu2_disable_local,
  1522. .irq_unmask = octeon_irq_ciu2_enable,
  1523. #ifdef CONFIG_SMP
  1524. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1525. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1526. #endif
  1527. };
  1528. static struct irq_chip octeon_irq_chip_ciu2_edge = {
  1529. .name = "CIU2-E",
  1530. .irq_enable = octeon_irq_ciu2_enable,
  1531. .irq_disable = octeon_irq_ciu2_disable_all,
  1532. .irq_ack = octeon_irq_ciu2_ack,
  1533. .irq_mask = octeon_irq_ciu2_disable_local,
  1534. .irq_unmask = octeon_irq_ciu2_enable,
  1535. #ifdef CONFIG_SMP
  1536. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1537. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1538. #endif
  1539. };
  1540. static struct irq_chip octeon_irq_chip_ciu2_mbox = {
  1541. .name = "CIU2-M",
  1542. .irq_enable = octeon_irq_ciu2_mbox_enable_all,
  1543. .irq_disable = octeon_irq_ciu2_mbox_disable_all,
  1544. .irq_ack = octeon_irq_ciu2_mbox_disable_local,
  1545. .irq_eoi = octeon_irq_ciu2_mbox_enable_local,
  1546. .irq_cpu_online = octeon_irq_ciu2_mbox_enable_local,
  1547. .irq_cpu_offline = octeon_irq_ciu2_mbox_disable_local,
  1548. .flags = IRQCHIP_ONOFFLINE_ENABLED,
  1549. };
  1550. static struct irq_chip octeon_irq_chip_ciu2_wd = {
  1551. .name = "CIU2-W",
  1552. .irq_enable = octeon_irq_ciu2_wd_enable,
  1553. .irq_disable = octeon_irq_ciu2_disable_all,
  1554. .irq_mask = octeon_irq_ciu2_disable_local,
  1555. .irq_unmask = octeon_irq_ciu2_enable_local,
  1556. };
  1557. static struct irq_chip octeon_irq_chip_ciu2_gpio = {
  1558. .name = "CIU-GPIO",
  1559. .irq_enable = octeon_irq_ciu2_enable_gpio,
  1560. .irq_disable = octeon_irq_ciu2_disable_gpio,
  1561. .irq_ack = octeon_irq_ciu_gpio_ack,
  1562. .irq_mask = octeon_irq_ciu2_disable_local,
  1563. .irq_unmask = octeon_irq_ciu2_enable,
  1564. .irq_set_type = octeon_irq_ciu_gpio_set_type,
  1565. #ifdef CONFIG_SMP
  1566. .irq_set_affinity = octeon_irq_ciu2_set_affinity,
  1567. .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
  1568. #endif
  1569. .flags = IRQCHIP_SET_TYPE_MASKED,
  1570. };
  1571. static int octeon_irq_ciu2_xlat(struct irq_domain *d,
  1572. struct device_node *node,
  1573. const u32 *intspec,
  1574. unsigned int intsize,
  1575. unsigned long *out_hwirq,
  1576. unsigned int *out_type)
  1577. {
  1578. unsigned int ciu, bit;
  1579. ciu = intspec[0];
  1580. bit = intspec[1];
  1581. *out_hwirq = (ciu << 6) | bit;
  1582. *out_type = 0;
  1583. return 0;
  1584. }
  1585. static bool octeon_irq_ciu2_is_edge(unsigned int line, unsigned int bit)
  1586. {
  1587. bool edge = false;
  1588. if (line == 3) /* MIO */
  1589. switch (bit) {
  1590. case 2: /* IPD_DRP */
  1591. case 8 ... 11: /* Timers */
  1592. case 48: /* PTP */
  1593. edge = true;
  1594. break;
  1595. default:
  1596. break;
  1597. }
  1598. else if (line == 6) /* PKT */
  1599. switch (bit) {
  1600. case 52 ... 53: /* ILK_DRP */
  1601. case 8 ... 12: /* GMX_DRP */
  1602. edge = true;
  1603. break;
  1604. default:
  1605. break;
  1606. }
  1607. return edge;
  1608. }
  1609. static int octeon_irq_ciu2_map(struct irq_domain *d,
  1610. unsigned int virq, irq_hw_number_t hw)
  1611. {
  1612. unsigned int line = hw >> 6;
  1613. unsigned int bit = hw & 63;
  1614. if (!octeon_irq_virq_in_range(virq))
  1615. return -EINVAL;
  1616. /*
  1617. * Don't map irq if it is reserved for GPIO.
  1618. * (Line 7 are the GPIO lines.)
  1619. */
  1620. if (line == 7)
  1621. return 0;
  1622. if (line > 7 || octeon_irq_ciu_to_irq[line][bit] != 0)
  1623. return -EINVAL;
  1624. if (octeon_irq_ciu2_is_edge(line, bit))
  1625. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1626. &octeon_irq_chip_ciu2_edge,
  1627. handle_edge_irq);
  1628. else
  1629. octeon_irq_set_ciu_mapping(virq, line, bit, 0,
  1630. &octeon_irq_chip_ciu2,
  1631. handle_level_irq);
  1632. return 0;
  1633. }
  1634. static struct irq_domain_ops octeon_irq_domain_ciu2_ops = {
  1635. .map = octeon_irq_ciu2_map,
  1636. .unmap = octeon_irq_free_cd,
  1637. .xlate = octeon_irq_ciu2_xlat,
  1638. };
  1639. static void octeon_irq_ciu2(void)
  1640. {
  1641. int line;
  1642. int bit;
  1643. int irq;
  1644. u64 src_reg, src, sum;
  1645. const unsigned long core_id = cvmx_get_core_num();
  1646. sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(core_id)) & 0xfful;
  1647. if (unlikely(!sum))
  1648. goto spurious;
  1649. line = fls64(sum) - 1;
  1650. src_reg = CVMX_CIU2_SRC_PPX_IP2_WRKQ(core_id) + (0x1000 * line);
  1651. src = cvmx_read_csr(src_reg);
  1652. if (unlikely(!src))
  1653. goto spurious;
  1654. bit = fls64(src) - 1;
  1655. irq = octeon_irq_ciu_to_irq[line][bit];
  1656. if (unlikely(!irq))
  1657. goto spurious;
  1658. do_IRQ(irq);
  1659. goto out;
  1660. spurious:
  1661. spurious_interrupt();
  1662. out:
  1663. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1664. can stop interrupts from propagating */
  1665. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1666. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1667. else
  1668. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP2(core_id));
  1669. return;
  1670. }
  1671. static void octeon_irq_ciu2_mbox(void)
  1672. {
  1673. int line;
  1674. const unsigned long core_id = cvmx_get_core_num();
  1675. u64 sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP3(core_id)) >> 60;
  1676. if (unlikely(!sum))
  1677. goto spurious;
  1678. line = fls64(sum) - 1;
  1679. do_IRQ(OCTEON_IRQ_MBOX0 + line);
  1680. goto out;
  1681. spurious:
  1682. spurious_interrupt();
  1683. out:
  1684. /* CN68XX pass 1.x has an errata that accessing the ACK registers
  1685. can stop interrupts from propagating */
  1686. if (OCTEON_IS_MODEL(OCTEON_CN68XX))
  1687. cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
  1688. else
  1689. cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP3(core_id));
  1690. return;
  1691. }
  1692. static int __init octeon_irq_init_ciu2(
  1693. struct device_node *ciu_node, struct device_node *parent)
  1694. {
  1695. unsigned int i, r;
  1696. struct irq_domain *ciu_domain = NULL;
  1697. octeon_irq_init_ciu2_percpu();
  1698. octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu2;
  1699. octeon_irq_gpio_chip = &octeon_irq_chip_ciu2_gpio;
  1700. octeon_irq_ip2 = octeon_irq_ciu2;
  1701. octeon_irq_ip3 = octeon_irq_ciu2_mbox;
  1702. octeon_irq_ip4 = octeon_irq_ip4_mask;
  1703. /* Mips internal */
  1704. octeon_irq_init_core();
  1705. ciu_domain = irq_domain_add_tree(
  1706. ciu_node, &octeon_irq_domain_ciu2_ops, NULL);
  1707. irq_set_default_host(ciu_domain);
  1708. /* CUI2 */
  1709. for (i = 0; i < 64; i++) {
  1710. r = octeon_irq_force_ciu_mapping(
  1711. ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i);
  1712. if (r)
  1713. goto err;
  1714. }
  1715. for (i = 0; i < 32; i++) {
  1716. r = octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i, 0,
  1717. &octeon_irq_chip_ciu2_wd, handle_level_irq);
  1718. if (r)
  1719. goto err;
  1720. }
  1721. for (i = 0; i < 4; i++) {
  1722. r = octeon_irq_force_ciu_mapping(
  1723. ciu_domain, i + OCTEON_IRQ_TIMER0, 3, i + 8);
  1724. if (r)
  1725. goto err;
  1726. }
  1727. r = octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 3, 44);
  1728. if (r)
  1729. goto err;
  1730. for (i = 0; i < 4; i++) {
  1731. r = octeon_irq_force_ciu_mapping(
  1732. ciu_domain, i + OCTEON_IRQ_PCI_INT0, 4, i);
  1733. if (r)
  1734. goto err;
  1735. }
  1736. for (i = 0; i < 4; i++) {
  1737. r = octeon_irq_force_ciu_mapping(
  1738. ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 4, i + 8);
  1739. if (r)
  1740. goto err;
  1741. }
  1742. irq_set_chip_and_handler(OCTEON_IRQ_MBOX0, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1743. irq_set_chip_and_handler(OCTEON_IRQ_MBOX1, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1744. irq_set_chip_and_handler(OCTEON_IRQ_MBOX2, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1745. irq_set_chip_and_handler(OCTEON_IRQ_MBOX3, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
  1746. /* Enable the CIU lines */
  1747. set_c0_status(STATUSF_IP3 | STATUSF_IP2);
  1748. clear_c0_status(STATUSF_IP4);
  1749. return 0;
  1750. err:
  1751. return r;
  1752. }
  1753. struct octeon_irq_cib_host_data {
  1754. raw_spinlock_t lock;
  1755. u64 raw_reg;
  1756. u64 en_reg;
  1757. int max_bits;
  1758. };
  1759. struct octeon_irq_cib_chip_data {
  1760. struct octeon_irq_cib_host_data *host_data;
  1761. int bit;
  1762. };
  1763. static void octeon_irq_cib_enable(struct irq_data *data)
  1764. {
  1765. unsigned long flags;
  1766. u64 en;
  1767. struct octeon_irq_cib_chip_data *cd = irq_data_get_irq_chip_data(data);
  1768. struct octeon_irq_cib_host_data *host_data = cd->host_data;
  1769. raw_spin_lock_irqsave(&host_data->lock, flags);
  1770. en = cvmx_read_csr(host_data->en_reg);
  1771. en |= 1ull << cd->bit;
  1772. cvmx_write_csr(host_data->en_reg, en);
  1773. raw_spin_unlock_irqrestore(&host_data->lock, flags);
  1774. }
  1775. static void octeon_irq_cib_disable(struct irq_data *data)
  1776. {
  1777. unsigned long flags;
  1778. u64 en;
  1779. struct octeon_irq_cib_chip_data *cd = irq_data_get_irq_chip_data(data);
  1780. struct octeon_irq_cib_host_data *host_data = cd->host_data;
  1781. raw_spin_lock_irqsave(&host_data->lock, flags);
  1782. en = cvmx_read_csr(host_data->en_reg);
  1783. en &= ~(1ull << cd->bit);
  1784. cvmx_write_csr(host_data->en_reg, en);
  1785. raw_spin_unlock_irqrestore(&host_data->lock, flags);
  1786. }
  1787. static int octeon_irq_cib_set_type(struct irq_data *data, unsigned int t)
  1788. {
  1789. irqd_set_trigger_type(data, t);
  1790. return IRQ_SET_MASK_OK;
  1791. }
  1792. static struct irq_chip octeon_irq_chip_cib = {
  1793. .name = "CIB",
  1794. .irq_enable = octeon_irq_cib_enable,
  1795. .irq_disable = octeon_irq_cib_disable,
  1796. .irq_mask = octeon_irq_cib_disable,
  1797. .irq_unmask = octeon_irq_cib_enable,
  1798. .irq_set_type = octeon_irq_cib_set_type,
  1799. };
  1800. static int octeon_irq_cib_xlat(struct irq_domain *d,
  1801. struct device_node *node,
  1802. const u32 *intspec,
  1803. unsigned int intsize,
  1804. unsigned long *out_hwirq,
  1805. unsigned int *out_type)
  1806. {
  1807. unsigned int type = 0;
  1808. if (intsize == 2)
  1809. type = intspec[1];
  1810. switch (type) {
  1811. case 0: /* unofficial value, but we might as well let it work. */
  1812. case 4: /* official value for level triggering. */
  1813. *out_type = IRQ_TYPE_LEVEL_HIGH;
  1814. break;
  1815. case 1: /* official value for edge triggering. */
  1816. *out_type = IRQ_TYPE_EDGE_RISING;
  1817. break;
  1818. default: /* Nothing else is acceptable. */
  1819. return -EINVAL;
  1820. }
  1821. *out_hwirq = intspec[0];
  1822. return 0;
  1823. }
  1824. static int octeon_irq_cib_map(struct irq_domain *d,
  1825. unsigned int virq, irq_hw_number_t hw)
  1826. {
  1827. struct octeon_irq_cib_host_data *host_data = d->host_data;
  1828. struct octeon_irq_cib_chip_data *cd;
  1829. if (hw >= host_data->max_bits) {
  1830. pr_err("ERROR: %s mapping %u is to big!\n",
  1831. d->of_node->name, (unsigned)hw);
  1832. return -EINVAL;
  1833. }
  1834. cd = kzalloc(sizeof(*cd), GFP_KERNEL);
  1835. cd->host_data = host_data;
  1836. cd->bit = hw;
  1837. irq_set_chip_and_handler(virq, &octeon_irq_chip_cib,
  1838. handle_simple_irq);
  1839. irq_set_chip_data(virq, cd);
  1840. return 0;
  1841. }
  1842. static struct irq_domain_ops octeon_irq_domain_cib_ops = {
  1843. .map = octeon_irq_cib_map,
  1844. .unmap = octeon_irq_free_cd,
  1845. .xlate = octeon_irq_cib_xlat,
  1846. };
  1847. /* Chain to real handler. */
  1848. static irqreturn_t octeon_irq_cib_handler(int my_irq, void *data)
  1849. {
  1850. u64 en;
  1851. u64 raw;
  1852. u64 bits;
  1853. int i;
  1854. int irq;
  1855. struct irq_domain *cib_domain = data;
  1856. struct octeon_irq_cib_host_data *host_data = cib_domain->host_data;
  1857. en = cvmx_read_csr(host_data->en_reg);
  1858. raw = cvmx_read_csr(host_data->raw_reg);
  1859. bits = en & raw;
  1860. for (i = 0; i < host_data->max_bits; i++) {
  1861. if ((bits & 1ull << i) == 0)
  1862. continue;
  1863. irq = irq_find_mapping(cib_domain, i);
  1864. if (!irq) {
  1865. unsigned long flags;
  1866. pr_err("ERROR: CIB bit %d@%llx IRQ unhandled, disabling\n",
  1867. i, host_data->raw_reg);
  1868. raw_spin_lock_irqsave(&host_data->lock, flags);
  1869. en = cvmx_read_csr(host_data->en_reg);
  1870. en &= ~(1ull << i);
  1871. cvmx_write_csr(host_data->en_reg, en);
  1872. cvmx_write_csr(host_data->raw_reg, 1ull << i);
  1873. raw_spin_unlock_irqrestore(&host_data->lock, flags);
  1874. } else {
  1875. struct irq_desc *desc = irq_to_desc(irq);
  1876. struct irq_data *irq_data = irq_desc_get_irq_data(desc);
  1877. /* If edge, acknowledge the bit we will be sending. */
  1878. if (irqd_get_trigger_type(irq_data) &
  1879. IRQ_TYPE_EDGE_BOTH)
  1880. cvmx_write_csr(host_data->raw_reg, 1ull << i);
  1881. generic_handle_irq_desc(irq, desc);
  1882. }
  1883. }
  1884. return IRQ_HANDLED;
  1885. }
  1886. static int __init octeon_irq_init_cib(struct device_node *ciu_node,
  1887. struct device_node *parent)
  1888. {
  1889. const __be32 *addr;
  1890. u32 val;
  1891. struct octeon_irq_cib_host_data *host_data;
  1892. int parent_irq;
  1893. int r;
  1894. struct irq_domain *cib_domain;
  1895. parent_irq = irq_of_parse_and_map(ciu_node, 0);
  1896. if (!parent_irq) {
  1897. pr_err("ERROR: Couldn't acquire parent_irq for %s\n.",
  1898. ciu_node->name);
  1899. return -EINVAL;
  1900. }
  1901. host_data = kzalloc(sizeof(*host_data), GFP_KERNEL);
  1902. raw_spin_lock_init(&host_data->lock);
  1903. addr = of_get_address(ciu_node, 0, NULL, NULL);
  1904. if (!addr) {
  1905. pr_err("ERROR: Couldn't acquire reg(0) %s\n.", ciu_node->name);
  1906. return -EINVAL;
  1907. }
  1908. host_data->raw_reg = (u64)phys_to_virt(
  1909. of_translate_address(ciu_node, addr));
  1910. addr = of_get_address(ciu_node, 1, NULL, NULL);
  1911. if (!addr) {
  1912. pr_err("ERROR: Couldn't acquire reg(1) %s\n.", ciu_node->name);
  1913. return -EINVAL;
  1914. }
  1915. host_data->en_reg = (u64)phys_to_virt(
  1916. of_translate_address(ciu_node, addr));
  1917. r = of_property_read_u32(ciu_node, "cavium,max-bits", &val);
  1918. if (r) {
  1919. pr_err("ERROR: Couldn't read cavium,max-bits from %s\n.",
  1920. ciu_node->name);
  1921. return r;
  1922. }
  1923. host_data->max_bits = val;
  1924. cib_domain = irq_domain_add_linear(ciu_node, host_data->max_bits,
  1925. &octeon_irq_domain_cib_ops,
  1926. host_data);
  1927. if (!cib_domain) {
  1928. pr_err("ERROR: Couldn't irq_domain_add_linear()\n.");
  1929. return -ENOMEM;
  1930. }
  1931. cvmx_write_csr(host_data->en_reg, 0); /* disable all IRQs */
  1932. cvmx_write_csr(host_data->raw_reg, ~0); /* ack any outstanding */
  1933. r = request_irq(parent_irq, octeon_irq_cib_handler,
  1934. IRQF_NO_THREAD, "cib", cib_domain);
  1935. if (r) {
  1936. pr_err("request_irq cib failed %d\n", r);
  1937. return r;
  1938. }
  1939. pr_info("CIB interrupt controller probed: %llx %d\n",
  1940. host_data->raw_reg, host_data->max_bits);
  1941. return 0;
  1942. }
  1943. static struct of_device_id ciu_types[] __initdata = {
  1944. {.compatible = "cavium,octeon-3860-ciu", .data = octeon_irq_init_ciu},
  1945. {.compatible = "cavium,octeon-3860-gpio", .data = octeon_irq_init_gpio},
  1946. {.compatible = "cavium,octeon-6880-ciu2", .data = octeon_irq_init_ciu2},
  1947. {.compatible = "cavium,octeon-7130-cib", .data = octeon_irq_init_cib},
  1948. {}
  1949. };
  1950. void __init arch_init_irq(void)
  1951. {
  1952. #ifdef CONFIG_SMP
  1953. /* Set the default affinity to the boot cpu. */
  1954. cpumask_clear(irq_default_affinity);
  1955. cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
  1956. #endif
  1957. of_irq_init(ciu_types);
  1958. }
  1959. asmlinkage void plat_irq_dispatch(void)
  1960. {
  1961. unsigned long cop0_cause;
  1962. unsigned long cop0_status;
  1963. while (1) {
  1964. cop0_cause = read_c0_cause();
  1965. cop0_status = read_c0_status();
  1966. cop0_cause &= cop0_status;
  1967. cop0_cause &= ST0_IM;
  1968. if (cop0_cause & STATUSF_IP2)
  1969. octeon_irq_ip2();
  1970. else if (cop0_cause & STATUSF_IP3)
  1971. octeon_irq_ip3();
  1972. else if (cop0_cause & STATUSF_IP4)
  1973. octeon_irq_ip4();
  1974. else if (cop0_cause)
  1975. do_IRQ(fls(cop0_cause) - 9 + MIPS_CPU_IRQ_BASE);
  1976. else
  1977. break;
  1978. }
  1979. }
  1980. #ifdef CONFIG_HOTPLUG_CPU
  1981. void octeon_fixup_irqs(void)
  1982. {
  1983. irq_cpu_offline();
  1984. }
  1985. #endif /* CONFIG_HOTPLUG_CPU */