ints-priority.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  1. /*
  2. * Set up the interrupt priorities
  3. *
  4. * Copyright 2004-2009 Analog Devices Inc.
  5. * 2003 Bas Vermeulen <bas@buyways.nl>
  6. * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
  7. * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
  8. * 1999 D. Jeff Dionne <jeff@uclinux.org>
  9. * 1996 Roman Zippel
  10. *
  11. * Licensed under the GPL-2
  12. */
  13. #include <linux/module.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/irq.h>
  17. #include <linux/sched.h>
  18. #include <linux/syscore_ops.h>
  19. #include <asm/delay.h>
  20. #ifdef CONFIG_IPIPE
  21. #include <linux/ipipe.h>
  22. #endif
  23. #include <asm/traps.h>
  24. #include <asm/blackfin.h>
  25. #include <asm/gpio.h>
  26. #include <asm/irq_handler.h>
  27. #include <asm/dpmc.h>
  28. #include <asm/traps.h>
  29. /*
  30. * NOTES:
  31. * - we have separated the physical Hardware interrupt from the
  32. * levels that the LINUX kernel sees (see the description in irq.h)
  33. * -
  34. */
  35. #ifndef CONFIG_SMP
  36. /* Initialize this to an actual value to force it into the .data
  37. * section so that we know it is properly initialized at entry into
  38. * the kernel but before bss is initialized to zero (which is where
  39. * it would live otherwise). The 0x1f magic represents the IRQs we
  40. * cannot actually mask out in hardware.
  41. */
  42. unsigned long bfin_irq_flags = 0x1f;
  43. EXPORT_SYMBOL(bfin_irq_flags);
  44. #endif
  45. #ifdef CONFIG_PM
  46. unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
  47. unsigned vr_wakeup;
  48. #endif
  49. #ifndef SEC_GCTL
  50. static struct ivgx {
  51. /* irq number for request_irq, available in mach-bf5xx/irq.h */
  52. unsigned int irqno;
  53. /* corresponding bit in the SIC_ISR register */
  54. unsigned int isrflag;
  55. } ivg_table[NR_PERI_INTS];
  56. static struct ivg_slice {
  57. /* position of first irq in ivg_table for given ivg */
  58. struct ivgx *ifirst;
  59. struct ivgx *istop;
  60. } ivg7_13[IVG13 - IVG7 + 1];
  61. /*
  62. * Search SIC_IAR and fill tables with the irqvalues
  63. * and their positions in the SIC_ISR register.
  64. */
  65. static void __init search_IAR(void)
  66. {
  67. unsigned ivg, irq_pos = 0;
  68. for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
  69. int irqN;
  70. ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
  71. for (irqN = 0; irqN < NR_PERI_INTS; irqN += 4) {
  72. int irqn;
  73. u32 iar =
  74. bfin_read32((unsigned long *)SIC_IAR0 +
  75. #if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || \
  76. defined(CONFIG_BF538) || defined(CONFIG_BF539)
  77. ((irqN % 32) >> 3) + ((irqN / 32) * ((SIC_IAR4 - SIC_IAR0) / 4))
  78. #else
  79. (irqN >> 3)
  80. #endif
  81. );
  82. for (irqn = irqN; irqn < irqN + 4; ++irqn) {
  83. int iar_shift = (irqn & 7) * 4;
  84. if (ivg == (0xf & (iar >> iar_shift))) {
  85. ivg_table[irq_pos].irqno = IVG7 + irqn;
  86. ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
  87. ivg7_13[ivg].istop++;
  88. irq_pos++;
  89. }
  90. }
  91. }
  92. }
  93. }
  94. #endif
  95. /*
  96. * This is for core internal IRQs
  97. */
  98. void bfin_ack_noop(struct irq_data *d)
  99. {
  100. /* Dummy function. */
  101. }
  102. static void bfin_core_mask_irq(struct irq_data *d)
  103. {
  104. bfin_irq_flags &= ~(1 << d->irq);
  105. if (!hard_irqs_disabled())
  106. hard_local_irq_enable();
  107. }
  108. static void bfin_core_unmask_irq(struct irq_data *d)
  109. {
  110. bfin_irq_flags |= 1 << d->irq;
  111. /*
  112. * If interrupts are enabled, IMASK must contain the same value
  113. * as bfin_irq_flags. Make sure that invariant holds. If interrupts
  114. * are currently disabled we need not do anything; one of the
  115. * callers will take care of setting IMASK to the proper value
  116. * when reenabling interrupts.
  117. * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
  118. * what we need.
  119. */
  120. if (!hard_irqs_disabled())
  121. hard_local_irq_enable();
  122. return;
  123. }
  124. #ifndef SEC_GCTL
  125. void bfin_internal_mask_irq(unsigned int irq)
  126. {
  127. unsigned long flags = hard_local_irq_save();
  128. #ifdef SIC_IMASK0
  129. unsigned mask_bank = BFIN_SYSIRQ(irq) / 32;
  130. unsigned mask_bit = BFIN_SYSIRQ(irq) % 32;
  131. bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
  132. ~(1 << mask_bit));
  133. # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
  134. bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
  135. ~(1 << mask_bit));
  136. # endif
  137. #else
  138. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
  139. ~(1 << BFIN_SYSIRQ(irq)));
  140. #endif /* end of SIC_IMASK0 */
  141. hard_local_irq_restore(flags);
  142. }
  143. static void bfin_internal_mask_irq_chip(struct irq_data *d)
  144. {
  145. bfin_internal_mask_irq(d->irq);
  146. }
  147. #ifdef CONFIG_SMP
  148. void bfin_internal_unmask_irq_affinity(unsigned int irq,
  149. const struct cpumask *affinity)
  150. #else
  151. void bfin_internal_unmask_irq(unsigned int irq)
  152. #endif
  153. {
  154. unsigned long flags = hard_local_irq_save();
  155. #ifdef SIC_IMASK0
  156. unsigned mask_bank = BFIN_SYSIRQ(irq) / 32;
  157. unsigned mask_bit = BFIN_SYSIRQ(irq) % 32;
  158. # ifdef CONFIG_SMP
  159. if (cpumask_test_cpu(0, affinity))
  160. # endif
  161. bfin_write_SIC_IMASK(mask_bank,
  162. bfin_read_SIC_IMASK(mask_bank) |
  163. (1 << mask_bit));
  164. # ifdef CONFIG_SMP
  165. if (cpumask_test_cpu(1, affinity))
  166. bfin_write_SICB_IMASK(mask_bank,
  167. bfin_read_SICB_IMASK(mask_bank) |
  168. (1 << mask_bit));
  169. # endif
  170. #else
  171. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
  172. (1 << BFIN_SYSIRQ(irq)));
  173. #endif
  174. hard_local_irq_restore(flags);
  175. }
  176. #ifdef CONFIG_SMP
  177. static void bfin_internal_unmask_irq_chip(struct irq_data *d)
  178. {
  179. bfin_internal_unmask_irq_affinity(d->irq, d->affinity);
  180. }
  181. static int bfin_internal_set_affinity(struct irq_data *d,
  182. const struct cpumask *mask, bool force)
  183. {
  184. bfin_internal_mask_irq(d->irq);
  185. bfin_internal_unmask_irq_affinity(d->irq, mask);
  186. return 0;
  187. }
  188. #else
  189. static void bfin_internal_unmask_irq_chip(struct irq_data *d)
  190. {
  191. bfin_internal_unmask_irq(d->irq);
  192. }
  193. #endif
  194. #if defined(CONFIG_PM)
  195. int bfin_internal_set_wake(unsigned int irq, unsigned int state)
  196. {
  197. u32 bank, bit, wakeup = 0;
  198. unsigned long flags;
  199. bank = BFIN_SYSIRQ(irq) / 32;
  200. bit = BFIN_SYSIRQ(irq) % 32;
  201. switch (irq) {
  202. #ifdef IRQ_RTC
  203. case IRQ_RTC:
  204. wakeup |= WAKE;
  205. break;
  206. #endif
  207. #ifdef IRQ_CAN0_RX
  208. case IRQ_CAN0_RX:
  209. wakeup |= CANWE;
  210. break;
  211. #endif
  212. #ifdef IRQ_CAN1_RX
  213. case IRQ_CAN1_RX:
  214. wakeup |= CANWE;
  215. break;
  216. #endif
  217. #ifdef IRQ_USB_INT0
  218. case IRQ_USB_INT0:
  219. wakeup |= USBWE;
  220. break;
  221. #endif
  222. #ifdef CONFIG_BF54x
  223. case IRQ_CNT:
  224. wakeup |= ROTWE;
  225. break;
  226. #endif
  227. default:
  228. break;
  229. }
  230. flags = hard_local_irq_save();
  231. if (state) {
  232. bfin_sic_iwr[bank] |= (1 << bit);
  233. vr_wakeup |= wakeup;
  234. } else {
  235. bfin_sic_iwr[bank] &= ~(1 << bit);
  236. vr_wakeup &= ~wakeup;
  237. }
  238. hard_local_irq_restore(flags);
  239. return 0;
  240. }
  241. static int bfin_internal_set_wake_chip(struct irq_data *d, unsigned int state)
  242. {
  243. return bfin_internal_set_wake(d->irq, state);
  244. }
  245. #else
  246. inline int bfin_internal_set_wake(unsigned int irq, unsigned int state)
  247. {
  248. return 0;
  249. }
  250. # define bfin_internal_set_wake_chip NULL
  251. #endif
  252. #else /* SEC_GCTL */
  253. static void bfin_sec_preflow_handler(struct irq_data *d)
  254. {
  255. unsigned long flags = hard_local_irq_save();
  256. unsigned int sid = BFIN_SYSIRQ(d->irq);
  257. bfin_write_SEC_SCI(0, SEC_CSID, sid);
  258. hard_local_irq_restore(flags);
  259. }
  260. static void bfin_sec_mask_ack_irq(struct irq_data *d)
  261. {
  262. unsigned long flags = hard_local_irq_save();
  263. unsigned int sid = BFIN_SYSIRQ(d->irq);
  264. bfin_write_SEC_SCI(0, SEC_CSID, sid);
  265. hard_local_irq_restore(flags);
  266. }
  267. static void bfin_sec_unmask_irq(struct irq_data *d)
  268. {
  269. unsigned long flags = hard_local_irq_save();
  270. unsigned int sid = BFIN_SYSIRQ(d->irq);
  271. bfin_write32(SEC_END, sid);
  272. hard_local_irq_restore(flags);
  273. }
  274. static void bfin_sec_enable_ssi(unsigned int sid)
  275. {
  276. unsigned long flags = hard_local_irq_save();
  277. uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
  278. reg_sctl |= SEC_SCTL_SRC_EN;
  279. bfin_write_SEC_SCTL(sid, reg_sctl);
  280. hard_local_irq_restore(flags);
  281. }
  282. static void bfin_sec_disable_ssi(unsigned int sid)
  283. {
  284. unsigned long flags = hard_local_irq_save();
  285. uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
  286. reg_sctl &= ((uint32_t)~SEC_SCTL_SRC_EN);
  287. bfin_write_SEC_SCTL(sid, reg_sctl);
  288. hard_local_irq_restore(flags);
  289. }
  290. static void bfin_sec_set_ssi_coreid(unsigned int sid, unsigned int coreid)
  291. {
  292. unsigned long flags = hard_local_irq_save();
  293. uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
  294. reg_sctl &= ((uint32_t)~SEC_SCTL_CTG);
  295. bfin_write_SEC_SCTL(sid, reg_sctl | ((coreid << 20) & SEC_SCTL_CTG));
  296. hard_local_irq_restore(flags);
  297. }
  298. static void bfin_sec_enable_sci(unsigned int sid)
  299. {
  300. unsigned long flags = hard_local_irq_save();
  301. uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
  302. if (sid == BFIN_SYSIRQ(IRQ_WATCH0))
  303. reg_sctl |= SEC_SCTL_FAULT_EN;
  304. else
  305. reg_sctl |= SEC_SCTL_INT_EN;
  306. bfin_write_SEC_SCTL(sid, reg_sctl);
  307. hard_local_irq_restore(flags);
  308. }
  309. static void bfin_sec_disable_sci(unsigned int sid)
  310. {
  311. unsigned long flags = hard_local_irq_save();
  312. uint32_t reg_sctl = bfin_read_SEC_SCTL(sid);
  313. reg_sctl &= ((uint32_t)~SEC_SCTL_INT_EN);
  314. bfin_write_SEC_SCTL(sid, reg_sctl);
  315. hard_local_irq_restore(flags);
  316. }
  317. static void bfin_sec_enable(struct irq_data *d)
  318. {
  319. unsigned long flags = hard_local_irq_save();
  320. unsigned int sid = BFIN_SYSIRQ(d->irq);
  321. bfin_sec_enable_sci(sid);
  322. bfin_sec_enable_ssi(sid);
  323. hard_local_irq_restore(flags);
  324. }
  325. static void bfin_sec_disable(struct irq_data *d)
  326. {
  327. unsigned long flags = hard_local_irq_save();
  328. unsigned int sid = BFIN_SYSIRQ(d->irq);
  329. bfin_sec_disable_sci(sid);
  330. bfin_sec_disable_ssi(sid);
  331. hard_local_irq_restore(flags);
  332. }
  333. static void bfin_sec_set_priority(unsigned int sec_int_levels, u8 *sec_int_priority)
  334. {
  335. unsigned long flags = hard_local_irq_save();
  336. uint32_t reg_sctl;
  337. int i;
  338. bfin_write_SEC_SCI(0, SEC_CPLVL, sec_int_levels);
  339. for (i = 0; i < SYS_IRQS - BFIN_IRQ(0); i++) {
  340. reg_sctl = bfin_read_SEC_SCTL(i) & ~SEC_SCTL_PRIO;
  341. reg_sctl |= sec_int_priority[i] << SEC_SCTL_PRIO_OFFSET;
  342. bfin_write_SEC_SCTL(i, reg_sctl);
  343. }
  344. hard_local_irq_restore(flags);
  345. }
  346. void bfin_sec_raise_irq(unsigned int irq)
  347. {
  348. unsigned long flags = hard_local_irq_save();
  349. unsigned int sid = BFIN_SYSIRQ(irq);
  350. bfin_write32(SEC_RAISE, sid);
  351. hard_local_irq_restore(flags);
  352. }
  353. static void init_software_driven_irq(void)
  354. {
  355. bfin_sec_set_ssi_coreid(34, 0);
  356. bfin_sec_set_ssi_coreid(35, 1);
  357. bfin_sec_enable_sci(35);
  358. bfin_sec_enable_ssi(35);
  359. bfin_sec_set_ssi_coreid(36, 0);
  360. bfin_sec_set_ssi_coreid(37, 1);
  361. bfin_sec_enable_sci(37);
  362. bfin_sec_enable_ssi(37);
  363. }
  364. void handle_sec_sfi_fault(uint32_t gstat)
  365. {
  366. }
  367. void handle_sec_sci_fault(uint32_t gstat)
  368. {
  369. uint32_t core_id;
  370. uint32_t cstat;
  371. core_id = gstat & SEC_GSTAT_SCI;
  372. cstat = bfin_read_SEC_SCI(core_id, SEC_CSTAT);
  373. if (cstat & SEC_CSTAT_ERR) {
  374. switch (cstat & SEC_CSTAT_ERRC) {
  375. case SEC_CSTAT_ACKERR:
  376. printk(KERN_DEBUG "sec ack err\n");
  377. break;
  378. default:
  379. printk(KERN_DEBUG "sec sci unknown err\n");
  380. }
  381. }
  382. }
  383. void handle_sec_ssi_fault(uint32_t gstat)
  384. {
  385. uint32_t sid;
  386. uint32_t sstat;
  387. sid = gstat & SEC_GSTAT_SID;
  388. sstat = bfin_read_SEC_SSTAT(sid);
  389. }
  390. void handle_sec_fault(uint32_t sec_gstat)
  391. {
  392. if (sec_gstat & SEC_GSTAT_ERR) {
  393. switch (sec_gstat & SEC_GSTAT_ERRC) {
  394. case 0:
  395. handle_sec_sfi_fault(sec_gstat);
  396. break;
  397. case SEC_GSTAT_SCIERR:
  398. handle_sec_sci_fault(sec_gstat);
  399. break;
  400. case SEC_GSTAT_SSIERR:
  401. handle_sec_ssi_fault(sec_gstat);
  402. break;
  403. }
  404. }
  405. }
  406. static struct irqaction bfin_fault_irq = {
  407. .name = "Blackfin fault",
  408. };
  409. static irqreturn_t bfin_fault_routine(int irq, void *data)
  410. {
  411. struct pt_regs *fp = get_irq_regs();
  412. switch (irq) {
  413. case IRQ_C0_DBL_FAULT:
  414. double_fault_c(fp);
  415. break;
  416. case IRQ_C0_HW_ERR:
  417. dump_bfin_process(fp);
  418. dump_bfin_mem(fp);
  419. show_regs(fp);
  420. printk(KERN_NOTICE "Kernel Stack\n");
  421. show_stack(current, NULL);
  422. print_modules();
  423. panic("Core 0 hardware error");
  424. break;
  425. case IRQ_C0_NMI_L1_PARITY_ERR:
  426. panic("Core 0 NMI L1 parity error");
  427. break;
  428. case IRQ_SEC_ERR:
  429. pr_err("SEC error\n");
  430. handle_sec_fault(bfin_read32(SEC_GSTAT));
  431. break;
  432. default:
  433. panic("Unknown fault %d", irq);
  434. }
  435. return IRQ_HANDLED;
  436. }
  437. #endif /* SEC_GCTL */
  438. static struct irq_chip bfin_core_irqchip = {
  439. .name = "CORE",
  440. .irq_mask = bfin_core_mask_irq,
  441. .irq_unmask = bfin_core_unmask_irq,
  442. };
  443. #ifndef SEC_GCTL
  444. static struct irq_chip bfin_internal_irqchip = {
  445. .name = "INTN",
  446. .irq_mask = bfin_internal_mask_irq_chip,
  447. .irq_unmask = bfin_internal_unmask_irq_chip,
  448. .irq_disable = bfin_internal_mask_irq_chip,
  449. .irq_enable = bfin_internal_unmask_irq_chip,
  450. #ifdef CONFIG_SMP
  451. .irq_set_affinity = bfin_internal_set_affinity,
  452. #endif
  453. .irq_set_wake = bfin_internal_set_wake_chip,
  454. };
  455. #else
  456. static struct irq_chip bfin_sec_irqchip = {
  457. .name = "SEC",
  458. .irq_mask_ack = bfin_sec_mask_ack_irq,
  459. .irq_mask = bfin_sec_mask_ack_irq,
  460. .irq_unmask = bfin_sec_unmask_irq,
  461. .irq_eoi = bfin_sec_unmask_irq,
  462. .irq_disable = bfin_sec_disable,
  463. .irq_enable = bfin_sec_enable,
  464. };
  465. #endif
  466. void bfin_handle_irq(unsigned irq)
  467. {
  468. #ifdef CONFIG_IPIPE
  469. struct pt_regs regs; /* Contents not used. */
  470. ipipe_trace_irq_entry(irq);
  471. __ipipe_handle_irq(irq, &regs);
  472. ipipe_trace_irq_exit(irq);
  473. #else /* !CONFIG_IPIPE */
  474. generic_handle_irq(irq);
  475. #endif /* !CONFIG_IPIPE */
  476. }
  477. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  478. static int mac_stat_int_mask;
  479. static void bfin_mac_status_ack_irq(unsigned int irq)
  480. {
  481. switch (irq) {
  482. case IRQ_MAC_MMCINT:
  483. bfin_write_EMAC_MMC_TIRQS(
  484. bfin_read_EMAC_MMC_TIRQE() &
  485. bfin_read_EMAC_MMC_TIRQS());
  486. bfin_write_EMAC_MMC_RIRQS(
  487. bfin_read_EMAC_MMC_RIRQE() &
  488. bfin_read_EMAC_MMC_RIRQS());
  489. break;
  490. case IRQ_MAC_RXFSINT:
  491. bfin_write_EMAC_RX_STKY(
  492. bfin_read_EMAC_RX_IRQE() &
  493. bfin_read_EMAC_RX_STKY());
  494. break;
  495. case IRQ_MAC_TXFSINT:
  496. bfin_write_EMAC_TX_STKY(
  497. bfin_read_EMAC_TX_IRQE() &
  498. bfin_read_EMAC_TX_STKY());
  499. break;
  500. case IRQ_MAC_WAKEDET:
  501. bfin_write_EMAC_WKUP_CTL(
  502. bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
  503. break;
  504. default:
  505. /* These bits are W1C */
  506. bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
  507. break;
  508. }
  509. }
  510. static void bfin_mac_status_mask_irq(struct irq_data *d)
  511. {
  512. unsigned int irq = d->irq;
  513. mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
  514. #ifdef BF537_FAMILY
  515. switch (irq) {
  516. case IRQ_MAC_PHYINT:
  517. bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
  518. break;
  519. default:
  520. break;
  521. }
  522. #else
  523. if (!mac_stat_int_mask)
  524. bfin_internal_mask_irq(IRQ_MAC_ERROR);
  525. #endif
  526. bfin_mac_status_ack_irq(irq);
  527. }
  528. static void bfin_mac_status_unmask_irq(struct irq_data *d)
  529. {
  530. unsigned int irq = d->irq;
  531. #ifdef BF537_FAMILY
  532. switch (irq) {
  533. case IRQ_MAC_PHYINT:
  534. bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
  535. break;
  536. default:
  537. break;
  538. }
  539. #else
  540. if (!mac_stat_int_mask)
  541. bfin_internal_unmask_irq(IRQ_MAC_ERROR);
  542. #endif
  543. mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
  544. }
  545. #ifdef CONFIG_PM
  546. int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
  547. {
  548. #ifdef BF537_FAMILY
  549. return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
  550. #else
  551. return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
  552. #endif
  553. }
  554. #else
  555. # define bfin_mac_status_set_wake NULL
  556. #endif
  557. static struct irq_chip bfin_mac_status_irqchip = {
  558. .name = "MACST",
  559. .irq_mask = bfin_mac_status_mask_irq,
  560. .irq_unmask = bfin_mac_status_unmask_irq,
  561. .irq_set_wake = bfin_mac_status_set_wake,
  562. };
  563. void bfin_demux_mac_status_irq(unsigned int int_err_irq,
  564. struct irq_desc *inta_desc)
  565. {
  566. int i, irq = 0;
  567. u32 status = bfin_read_EMAC_SYSTAT();
  568. for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
  569. if (status & (1L << i)) {
  570. irq = IRQ_MAC_PHYINT + i;
  571. break;
  572. }
  573. if (irq) {
  574. if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
  575. bfin_handle_irq(irq);
  576. } else {
  577. bfin_mac_status_ack_irq(irq);
  578. pr_debug("IRQ %d:"
  579. " MASKED MAC ERROR INTERRUPT ASSERTED\n",
  580. irq);
  581. }
  582. } else
  583. printk(KERN_ERR
  584. "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
  585. " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
  586. "(EMAC_SYSTAT=0x%X)\n",
  587. __func__, __FILE__, __LINE__, status);
  588. }
  589. #endif
  590. static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
  591. {
  592. #ifdef CONFIG_IPIPE
  593. handle = handle_level_irq;
  594. #endif
  595. __irq_set_handler_locked(irq, handle);
  596. }
  597. #ifdef CONFIG_GPIO_ADI
  598. static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
  599. static void bfin_gpio_ack_irq(struct irq_data *d)
  600. {
  601. /* AFAIK ack_irq in case mask_ack is provided
  602. * get's only called for edge sense irqs
  603. */
  604. set_gpio_data(irq_to_gpio(d->irq), 0);
  605. }
  606. static void bfin_gpio_mask_ack_irq(struct irq_data *d)
  607. {
  608. unsigned int irq = d->irq;
  609. u32 gpionr = irq_to_gpio(irq);
  610. if (!irqd_is_level_type(d))
  611. set_gpio_data(gpionr, 0);
  612. set_gpio_maska(gpionr, 0);
  613. }
  614. static void bfin_gpio_mask_irq(struct irq_data *d)
  615. {
  616. set_gpio_maska(irq_to_gpio(d->irq), 0);
  617. }
  618. static void bfin_gpio_unmask_irq(struct irq_data *d)
  619. {
  620. set_gpio_maska(irq_to_gpio(d->irq), 1);
  621. }
  622. static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
  623. {
  624. u32 gpionr = irq_to_gpio(d->irq);
  625. if (__test_and_set_bit(gpionr, gpio_enabled))
  626. bfin_gpio_irq_prepare(gpionr);
  627. bfin_gpio_unmask_irq(d);
  628. return 0;
  629. }
  630. static void bfin_gpio_irq_shutdown(struct irq_data *d)
  631. {
  632. u32 gpionr = irq_to_gpio(d->irq);
  633. bfin_gpio_mask_irq(d);
  634. __clear_bit(gpionr, gpio_enabled);
  635. bfin_gpio_irq_free(gpionr);
  636. }
  637. static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
  638. {
  639. unsigned int irq = d->irq;
  640. int ret;
  641. char buf[16];
  642. u32 gpionr = irq_to_gpio(irq);
  643. if (type == IRQ_TYPE_PROBE) {
  644. /* only probe unenabled GPIO interrupt lines */
  645. if (test_bit(gpionr, gpio_enabled))
  646. return 0;
  647. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  648. }
  649. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  650. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  651. snprintf(buf, 16, "gpio-irq%d", irq);
  652. ret = bfin_gpio_irq_request(gpionr, buf);
  653. if (ret)
  654. return ret;
  655. if (__test_and_set_bit(gpionr, gpio_enabled))
  656. bfin_gpio_irq_prepare(gpionr);
  657. } else {
  658. __clear_bit(gpionr, gpio_enabled);
  659. return 0;
  660. }
  661. set_gpio_inen(gpionr, 0);
  662. set_gpio_dir(gpionr, 0);
  663. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  664. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  665. set_gpio_both(gpionr, 1);
  666. else
  667. set_gpio_both(gpionr, 0);
  668. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  669. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  670. else
  671. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  672. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  673. set_gpio_edge(gpionr, 1);
  674. set_gpio_inen(gpionr, 1);
  675. set_gpio_data(gpionr, 0);
  676. } else {
  677. set_gpio_edge(gpionr, 0);
  678. set_gpio_inen(gpionr, 1);
  679. }
  680. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  681. bfin_set_irq_handler(irq, handle_edge_irq);
  682. else
  683. bfin_set_irq_handler(irq, handle_level_irq);
  684. return 0;
  685. }
  686. static void bfin_demux_gpio_block(unsigned int irq)
  687. {
  688. unsigned int gpio, mask;
  689. gpio = irq_to_gpio(irq);
  690. mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
  691. while (mask) {
  692. if (mask & 1)
  693. bfin_handle_irq(irq);
  694. irq++;
  695. mask >>= 1;
  696. }
  697. }
  698. void bfin_demux_gpio_irq(unsigned int inta_irq,
  699. struct irq_desc *desc)
  700. {
  701. unsigned int irq;
  702. switch (inta_irq) {
  703. #if defined(BF537_FAMILY)
  704. case IRQ_PF_INTA_PG_INTA:
  705. bfin_demux_gpio_block(IRQ_PF0);
  706. irq = IRQ_PG0;
  707. break;
  708. case IRQ_PH_INTA_MAC_RX:
  709. irq = IRQ_PH0;
  710. break;
  711. #elif defined(BF533_FAMILY)
  712. case IRQ_PROG_INTA:
  713. irq = IRQ_PF0;
  714. break;
  715. #elif defined(BF538_FAMILY)
  716. case IRQ_PORTF_INTA:
  717. irq = IRQ_PF0;
  718. break;
  719. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  720. case IRQ_PORTF_INTA:
  721. irq = IRQ_PF0;
  722. break;
  723. case IRQ_PORTG_INTA:
  724. irq = IRQ_PG0;
  725. break;
  726. case IRQ_PORTH_INTA:
  727. irq = IRQ_PH0;
  728. break;
  729. #elif defined(CONFIG_BF561)
  730. case IRQ_PROG0_INTA:
  731. irq = IRQ_PF0;
  732. break;
  733. case IRQ_PROG1_INTA:
  734. irq = IRQ_PF16;
  735. break;
  736. case IRQ_PROG2_INTA:
  737. irq = IRQ_PF32;
  738. break;
  739. #endif
  740. default:
  741. BUG();
  742. return;
  743. }
  744. bfin_demux_gpio_block(irq);
  745. }
  746. #ifdef CONFIG_PM
  747. static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
  748. {
  749. return bfin_gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
  750. }
  751. #else
  752. # define bfin_gpio_set_wake NULL
  753. #endif
  754. static struct irq_chip bfin_gpio_irqchip = {
  755. .name = "GPIO",
  756. .irq_ack = bfin_gpio_ack_irq,
  757. .irq_mask = bfin_gpio_mask_irq,
  758. .irq_mask_ack = bfin_gpio_mask_ack_irq,
  759. .irq_unmask = bfin_gpio_unmask_irq,
  760. .irq_disable = bfin_gpio_mask_irq,
  761. .irq_enable = bfin_gpio_unmask_irq,
  762. .irq_set_type = bfin_gpio_irq_type,
  763. .irq_startup = bfin_gpio_irq_startup,
  764. .irq_shutdown = bfin_gpio_irq_shutdown,
  765. .irq_set_wake = bfin_gpio_set_wake,
  766. };
  767. #endif
  768. #ifdef CONFIG_PM
  769. #ifdef SEC_GCTL
  770. static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
  771. static int sec_suspend(void)
  772. {
  773. u32 bank;
  774. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
  775. save_pint_sec_ctl[bank] = bfin_read_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0));
  776. return 0;
  777. }
  778. static void sec_resume(void)
  779. {
  780. u32 bank;
  781. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
  782. udelay(100);
  783. bfin_write_SEC_GCTL(SEC_GCTL_EN);
  784. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
  785. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
  786. bfin_write_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0), save_pint_sec_ctl[bank]);
  787. }
  788. static struct syscore_ops sec_pm_syscore_ops = {
  789. .suspend = sec_suspend,
  790. .resume = sec_resume,
  791. };
  792. #endif
  793. #endif
  794. void init_exception_vectors(void)
  795. {
  796. /* cannot program in software:
  797. * evt0 - emulation (jtag)
  798. * evt1 - reset
  799. */
  800. bfin_write_EVT2(evt_nmi);
  801. bfin_write_EVT3(trap);
  802. bfin_write_EVT5(evt_ivhw);
  803. bfin_write_EVT6(evt_timer);
  804. bfin_write_EVT7(evt_evt7);
  805. bfin_write_EVT8(evt_evt8);
  806. bfin_write_EVT9(evt_evt9);
  807. bfin_write_EVT10(evt_evt10);
  808. bfin_write_EVT11(evt_evt11);
  809. bfin_write_EVT12(evt_evt12);
  810. bfin_write_EVT13(evt_evt13);
  811. bfin_write_EVT14(evt_evt14);
  812. bfin_write_EVT15(evt_system_call);
  813. CSYNC();
  814. }
  815. #ifndef SEC_GCTL
  816. /*
  817. * This function should be called during kernel startup to initialize
  818. * the BFin IRQ handling routines.
  819. */
  820. int __init init_arch_irq(void)
  821. {
  822. int irq;
  823. unsigned long ilat = 0;
  824. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  825. #ifdef SIC_IMASK0
  826. bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
  827. bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
  828. # ifdef SIC_IMASK2
  829. bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
  830. # endif
  831. # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
  832. bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
  833. bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
  834. # endif
  835. #else
  836. bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
  837. #endif
  838. local_irq_disable();
  839. for (irq = 0; irq <= SYS_IRQS; irq++) {
  840. if (irq <= IRQ_CORETMR)
  841. irq_set_chip(irq, &bfin_core_irqchip);
  842. else
  843. irq_set_chip(irq, &bfin_internal_irqchip);
  844. switch (irq) {
  845. #if !BFIN_GPIO_PINT
  846. #if defined(BF537_FAMILY)
  847. case IRQ_PH_INTA_MAC_RX:
  848. case IRQ_PF_INTA_PG_INTA:
  849. #elif defined(BF533_FAMILY)
  850. case IRQ_PROG_INTA:
  851. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  852. case IRQ_PORTF_INTA:
  853. case IRQ_PORTG_INTA:
  854. case IRQ_PORTH_INTA:
  855. #elif defined(CONFIG_BF561)
  856. case IRQ_PROG0_INTA:
  857. case IRQ_PROG1_INTA:
  858. case IRQ_PROG2_INTA:
  859. #elif defined(BF538_FAMILY)
  860. case IRQ_PORTF_INTA:
  861. #endif
  862. irq_set_chained_handler(irq, bfin_demux_gpio_irq);
  863. break;
  864. #endif
  865. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  866. case IRQ_MAC_ERROR:
  867. irq_set_chained_handler(irq,
  868. bfin_demux_mac_status_irq);
  869. break;
  870. #endif
  871. #if defined(CONFIG_SMP) || defined(CONFIG_ICC)
  872. case IRQ_SUPPLE_0:
  873. case IRQ_SUPPLE_1:
  874. irq_set_handler(irq, handle_percpu_irq);
  875. break;
  876. #endif
  877. #ifdef CONFIG_TICKSOURCE_CORETMR
  878. case IRQ_CORETMR:
  879. # ifdef CONFIG_SMP
  880. irq_set_handler(irq, handle_percpu_irq);
  881. # else
  882. irq_set_handler(irq, handle_simple_irq);
  883. # endif
  884. break;
  885. #endif
  886. #ifdef CONFIG_TICKSOURCE_GPTMR0
  887. case IRQ_TIMER0:
  888. irq_set_handler(irq, handle_simple_irq);
  889. break;
  890. #endif
  891. default:
  892. #ifdef CONFIG_IPIPE
  893. irq_set_handler(irq, handle_level_irq);
  894. #else
  895. irq_set_handler(irq, handle_simple_irq);
  896. #endif
  897. break;
  898. }
  899. }
  900. init_mach_irq();
  901. #if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  902. for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
  903. irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
  904. handle_level_irq);
  905. #endif
  906. /* if configured as edge, then will be changed to do_edge_IRQ */
  907. #ifdef CONFIG_GPIO_ADI
  908. for (irq = GPIO_IRQ_BASE;
  909. irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
  910. irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
  911. handle_level_irq);
  912. #endif
  913. bfin_write_IMASK(0);
  914. CSYNC();
  915. ilat = bfin_read_ILAT();
  916. CSYNC();
  917. bfin_write_ILAT(ilat);
  918. CSYNC();
  919. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  920. /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
  921. * local_irq_enable()
  922. */
  923. program_IAR();
  924. /* Therefore it's better to setup IARs before interrupts enabled */
  925. search_IAR();
  926. /* Enable interrupts IVG7-15 */
  927. bfin_irq_flags |= IMASK_IVG15 |
  928. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  929. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  930. /* This implicitly covers ANOMALY_05000171
  931. * Boot-ROM code modifies SICA_IWRx wakeup registers
  932. */
  933. #ifdef SIC_IWR0
  934. bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
  935. # ifdef SIC_IWR1
  936. /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
  937. * will screw up the bootrom as it relies on MDMA0/1 waking it
  938. * up from IDLE instructions. See this report for more info:
  939. * http://blackfin.uclinux.org/gf/tracker/4323
  940. */
  941. if (ANOMALY_05000435)
  942. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  943. else
  944. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  945. # endif
  946. # ifdef SIC_IWR2
  947. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  948. # endif
  949. #else
  950. bfin_write_SIC_IWR(IWR_DISABLE_ALL);
  951. #endif
  952. return 0;
  953. }
  954. #ifdef CONFIG_DO_IRQ_L1
  955. __attribute__((l1_text))
  956. #endif
  957. static int vec_to_irq(int vec)
  958. {
  959. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  960. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  961. unsigned long sic_status[3];
  962. if (likely(vec == EVT_IVTMR_P))
  963. return IRQ_CORETMR;
  964. #ifdef SIC_ISR
  965. sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  966. #else
  967. if (smp_processor_id()) {
  968. # ifdef SICB_ISR0
  969. /* This will be optimized out in UP mode. */
  970. sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
  971. sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
  972. # endif
  973. } else {
  974. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  975. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  976. }
  977. #endif
  978. #ifdef SIC_ISR2
  979. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  980. #endif
  981. for (;; ivg++) {
  982. if (ivg >= ivg_stop)
  983. return -1;
  984. #ifdef SIC_ISR
  985. if (sic_status[0] & ivg->isrflag)
  986. #else
  987. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  988. #endif
  989. return ivg->irqno;
  990. }
  991. }
  992. #else /* SEC_GCTL */
  993. /*
  994. * This function should be called during kernel startup to initialize
  995. * the BFin IRQ handling routines.
  996. */
  997. int __init init_arch_irq(void)
  998. {
  999. int irq;
  1000. unsigned long ilat = 0;
  1001. bfin_write_SEC_GCTL(SEC_GCTL_RESET);
  1002. local_irq_disable();
  1003. for (irq = 0; irq <= SYS_IRQS; irq++) {
  1004. if (irq <= IRQ_CORETMR) {
  1005. irq_set_chip_and_handler(irq, &bfin_core_irqchip,
  1006. handle_simple_irq);
  1007. #if defined(CONFIG_TICKSOURCE_CORETMR) && defined(CONFIG_SMP)
  1008. if (irq == IRQ_CORETMR)
  1009. irq_set_handler(irq, handle_percpu_irq);
  1010. #endif
  1011. } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
  1012. irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
  1013. handle_percpu_irq);
  1014. } else {
  1015. irq_set_chip(irq, &bfin_sec_irqchip);
  1016. irq_set_handler(irq, handle_fasteoi_irq);
  1017. __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
  1018. }
  1019. }
  1020. bfin_write_IMASK(0);
  1021. CSYNC();
  1022. ilat = bfin_read_ILAT();
  1023. CSYNC();
  1024. bfin_write_ILAT(ilat);
  1025. CSYNC();
  1026. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  1027. bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
  1028. /* Enable interrupts IVG7-15 */
  1029. bfin_irq_flags |= IMASK_IVG15 |
  1030. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  1031. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  1032. bfin_write_SEC_FCTL(SEC_FCTL_EN | SEC_FCTL_SYSRST_EN | SEC_FCTL_FLTIN_EN);
  1033. bfin_sec_enable_sci(BFIN_SYSIRQ(IRQ_WATCH0));
  1034. bfin_sec_enable_ssi(BFIN_SYSIRQ(IRQ_WATCH0));
  1035. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
  1036. udelay(100);
  1037. bfin_write_SEC_GCTL(SEC_GCTL_EN);
  1038. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
  1039. bfin_write_SEC_SCI(1, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
  1040. init_software_driven_irq();
  1041. #ifdef CONFIG_PM
  1042. register_syscore_ops(&sec_pm_syscore_ops);
  1043. #endif
  1044. bfin_fault_irq.handler = bfin_fault_routine;
  1045. #ifdef CONFIG_L1_PARITY_CHECK
  1046. setup_irq(IRQ_C0_NMI_L1_PARITY_ERR, &bfin_fault_irq);
  1047. #endif
  1048. setup_irq(IRQ_C0_DBL_FAULT, &bfin_fault_irq);
  1049. setup_irq(IRQ_SEC_ERR, &bfin_fault_irq);
  1050. return 0;
  1051. }
  1052. #ifdef CONFIG_DO_IRQ_L1
  1053. __attribute__((l1_text))
  1054. #endif
  1055. static int vec_to_irq(int vec)
  1056. {
  1057. if (likely(vec == EVT_IVTMR_P))
  1058. return IRQ_CORETMR;
  1059. return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID));
  1060. }
  1061. #endif /* SEC_GCTL */
  1062. #ifdef CONFIG_DO_IRQ_L1
  1063. __attribute__((l1_text))
  1064. #endif
  1065. void do_irq(int vec, struct pt_regs *fp)
  1066. {
  1067. int irq = vec_to_irq(vec);
  1068. if (irq == -1)
  1069. return;
  1070. asm_do_IRQ(irq, fp);
  1071. }
  1072. #ifdef CONFIG_IPIPE
  1073. int __ipipe_get_irq_priority(unsigned irq)
  1074. {
  1075. int ient, prio;
  1076. if (irq <= IRQ_CORETMR)
  1077. return irq;
  1078. #ifdef SEC_GCTL
  1079. if (irq >= BFIN_IRQ(0))
  1080. return IVG11;
  1081. #else
  1082. for (ient = 0; ient < NR_PERI_INTS; ient++) {
  1083. struct ivgx *ivg = ivg_table + ient;
  1084. if (ivg->irqno == irq) {
  1085. for (prio = 0; prio <= IVG13-IVG7; prio++) {
  1086. if (ivg7_13[prio].ifirst <= ivg &&
  1087. ivg7_13[prio].istop > ivg)
  1088. return IVG7 + prio;
  1089. }
  1090. }
  1091. }
  1092. #endif
  1093. return IVG15;
  1094. }
  1095. /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
  1096. #ifdef CONFIG_DO_IRQ_L1
  1097. __attribute__((l1_text))
  1098. #endif
  1099. asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
  1100. {
  1101. struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
  1102. struct ipipe_domain *this_domain = __ipipe_current_domain;
  1103. int irq, s = 0;
  1104. irq = vec_to_irq(vec);
  1105. if (irq == -1)
  1106. return 0;
  1107. if (irq == IRQ_SYSTMR) {
  1108. #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
  1109. bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
  1110. #endif
  1111. /* This is basically what we need from the register frame. */
  1112. __this_cpu_write(__ipipe_tick_regs.ipend, regs->ipend);
  1113. __this_cpu_write(__ipipe_tick_regs.pc, regs->pc);
  1114. if (this_domain != ipipe_root_domain)
  1115. __this_cpu_and(__ipipe_tick_regs.ipend, ~0x10);
  1116. else
  1117. __this_cpu_or(__ipipe_tick_regs.ipend, 0x10);
  1118. }
  1119. /*
  1120. * We don't want Linux interrupt handlers to run at the
  1121. * current core priority level (i.e. < EVT15), since this
  1122. * might delay other interrupts handled by a high priority
  1123. * domain. Here is what we do instead:
  1124. *
  1125. * - we raise the SYNCDEFER bit to prevent
  1126. * __ipipe_handle_irq() to sync the pipeline for the root
  1127. * stage for the incoming interrupt. Upon return, that IRQ is
  1128. * pending in the interrupt log.
  1129. *
  1130. * - we raise the TIF_IRQ_SYNC bit for the current thread, so
  1131. * that _schedule_and_signal_from_int will eventually sync the
  1132. * pipeline from EVT15.
  1133. */
  1134. if (this_domain == ipipe_root_domain) {
  1135. s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1136. barrier();
  1137. }
  1138. ipipe_trace_irq_entry(irq);
  1139. __ipipe_handle_irq(irq, regs);
  1140. ipipe_trace_irq_exit(irq);
  1141. if (user_mode(regs) &&
  1142. !ipipe_test_foreign_stack() &&
  1143. (current->ipipe_flags & PF_EVTRET) != 0) {
  1144. /*
  1145. * Testing for user_regs() does NOT fully eliminate
  1146. * foreign stack contexts, because of the forged
  1147. * interrupt returns we do through
  1148. * __ipipe_call_irqtail. In that case, we might have
  1149. * preempted a foreign stack context in a high
  1150. * priority domain, with a single interrupt level now
  1151. * pending after the irqtail unwinding is done. In
  1152. * which case user_mode() is now true, and the event
  1153. * gets dispatched spuriously.
  1154. */
  1155. current->ipipe_flags &= ~PF_EVTRET;
  1156. __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
  1157. }
  1158. if (this_domain == ipipe_root_domain) {
  1159. set_thread_flag(TIF_IRQ_SYNC);
  1160. if (!s) {
  1161. __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1162. return !test_bit(IPIPE_STALL_FLAG, &p->status);
  1163. }
  1164. }
  1165. return 0;
  1166. }
  1167. #endif /* CONFIG_IPIPE */