octeon-irq.c 44 KB

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