octeon-irq.c 57 KB

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