ints-priority.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318
  1. /*
  2. * File: arch/blackfin/mach-common/ints-priority.c
  3. *
  4. * Description: Set up the interrupt priorities
  5. *
  6. * Modified:
  7. * 1996 Roman Zippel
  8. * 1999 D. Jeff Dionne <jeff@uclinux.org>
  9. * 2000-2001 Lineo, Inc. D. Jefff Dionne <jeff@lineo.ca>
  10. * 2002 Arcturus Networks Inc. MaTed <mated@sympatico.ca>
  11. * 2003 Metrowerks/Motorola
  12. * 2003 Bas Vermeulen <bas@buyways.nl>
  13. * Copyright 2004-2008 Analog Devices Inc.
  14. *
  15. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, see the file COPYING, or write
  29. * to the Free Software Foundation, Inc.,
  30. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  31. */
  32. #include <linux/module.h>
  33. #include <linux/kernel_stat.h>
  34. #include <linux/seq_file.h>
  35. #include <linux/irq.h>
  36. #ifdef CONFIG_IPIPE
  37. #include <linux/ipipe.h>
  38. #endif
  39. #ifdef CONFIG_KGDB
  40. #include <linux/kgdb.h>
  41. #endif
  42. #include <asm/traps.h>
  43. #include <asm/blackfin.h>
  44. #include <asm/gpio.h>
  45. #include <asm/irq_handler.h>
  46. #define SIC_SYSIRQ(irq) (irq - (IRQ_CORETMR + 1))
  47. #ifdef BF537_FAMILY
  48. # define BF537_GENERIC_ERROR_INT_DEMUX
  49. #else
  50. # undef BF537_GENERIC_ERROR_INT_DEMUX
  51. #endif
  52. /*
  53. * NOTES:
  54. * - we have separated the physical Hardware interrupt from the
  55. * levels that the LINUX kernel sees (see the description in irq.h)
  56. * -
  57. */
  58. #ifndef CONFIG_SMP
  59. /* Initialize this to an actual value to force it into the .data
  60. * section so that we know it is properly initialized at entry into
  61. * the kernel but before bss is initialized to zero (which is where
  62. * it would live otherwise). The 0x1f magic represents the IRQs we
  63. * cannot actually mask out in hardware.
  64. */
  65. unsigned long bfin_irq_flags = 0x1f;
  66. EXPORT_SYMBOL(bfin_irq_flags);
  67. #endif
  68. /* The number of spurious interrupts */
  69. atomic_t num_spurious;
  70. #ifdef CONFIG_PM
  71. unsigned long bfin_sic_iwr[3]; /* Up to 3 SIC_IWRx registers */
  72. unsigned vr_wakeup;
  73. #endif
  74. struct ivgx {
  75. /* irq number for request_irq, available in mach-bf5xx/irq.h */
  76. unsigned int irqno;
  77. /* corresponding bit in the SIC_ISR register */
  78. unsigned int isrflag;
  79. } ivg_table[NR_PERI_INTS];
  80. struct ivg_slice {
  81. /* position of first irq in ivg_table for given ivg */
  82. struct ivgx *ifirst;
  83. struct ivgx *istop;
  84. } ivg7_13[IVG13 - IVG7 + 1];
  85. /*
  86. * Search SIC_IAR and fill tables with the irqvalues
  87. * and their positions in the SIC_ISR register.
  88. */
  89. static void __init search_IAR(void)
  90. {
  91. unsigned ivg, irq_pos = 0;
  92. for (ivg = 0; ivg <= IVG13 - IVG7; ivg++) {
  93. int irqn;
  94. ivg7_13[ivg].istop = ivg7_13[ivg].ifirst = &ivg_table[irq_pos];
  95. for (irqn = 0; irqn < NR_PERI_INTS; irqn++) {
  96. int iar_shift = (irqn & 7) * 4;
  97. if (ivg == (0xf &
  98. #if defined(CONFIG_BF52x) || defined(CONFIG_BF538) \
  99. || defined(CONFIG_BF539) || defined(CONFIG_BF51x)
  100. bfin_read32((unsigned long *)SIC_IAR0 +
  101. ((irqn % 32) >> 3) + ((irqn / 32) *
  102. ((SIC_IAR4 - SIC_IAR0) / 4))) >> iar_shift)) {
  103. #else
  104. bfin_read32((unsigned long *)SIC_IAR0 +
  105. (irqn >> 3)) >> iar_shift)) {
  106. #endif
  107. ivg_table[irq_pos].irqno = IVG7 + irqn;
  108. ivg_table[irq_pos].isrflag = 1 << (irqn % 32);
  109. ivg7_13[ivg].istop++;
  110. irq_pos++;
  111. }
  112. }
  113. }
  114. }
  115. /*
  116. * This is for core internal IRQs
  117. */
  118. static void bfin_ack_noop(unsigned int irq)
  119. {
  120. /* Dummy function. */
  121. }
  122. static void bfin_core_mask_irq(unsigned int irq)
  123. {
  124. bfin_irq_flags &= ~(1 << irq);
  125. if (!irqs_disabled_hw())
  126. local_irq_enable_hw();
  127. }
  128. static void bfin_core_unmask_irq(unsigned int irq)
  129. {
  130. bfin_irq_flags |= 1 << irq;
  131. /*
  132. * If interrupts are enabled, IMASK must contain the same value
  133. * as bfin_irq_flags. Make sure that invariant holds. If interrupts
  134. * are currently disabled we need not do anything; one of the
  135. * callers will take care of setting IMASK to the proper value
  136. * when reenabling interrupts.
  137. * local_irq_enable just does "STI bfin_irq_flags", so it's exactly
  138. * what we need.
  139. */
  140. if (!irqs_disabled_hw())
  141. local_irq_enable_hw();
  142. return;
  143. }
  144. static void bfin_internal_mask_irq(unsigned int irq)
  145. {
  146. unsigned long flags;
  147. #ifdef CONFIG_BF53x
  148. local_irq_save_hw(flags);
  149. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() &
  150. ~(1 << SIC_SYSIRQ(irq)));
  151. #else
  152. unsigned mask_bank, mask_bit;
  153. local_irq_save_hw(flags);
  154. mask_bank = SIC_SYSIRQ(irq) / 32;
  155. mask_bit = SIC_SYSIRQ(irq) % 32;
  156. bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) &
  157. ~(1 << mask_bit));
  158. #ifdef CONFIG_SMP
  159. bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) &
  160. ~(1 << mask_bit));
  161. #endif
  162. #endif
  163. local_irq_restore_hw(flags);
  164. }
  165. static void bfin_internal_unmask_irq(unsigned int irq)
  166. {
  167. unsigned long flags;
  168. #ifdef CONFIG_BF53x
  169. local_irq_save_hw(flags);
  170. bfin_write_SIC_IMASK(bfin_read_SIC_IMASK() |
  171. (1 << SIC_SYSIRQ(irq)));
  172. #else
  173. unsigned mask_bank, mask_bit;
  174. local_irq_save_hw(flags);
  175. mask_bank = SIC_SYSIRQ(irq) / 32;
  176. mask_bit = SIC_SYSIRQ(irq) % 32;
  177. bfin_write_SIC_IMASK(mask_bank, bfin_read_SIC_IMASK(mask_bank) |
  178. (1 << mask_bit));
  179. #ifdef CONFIG_SMP
  180. bfin_write_SICB_IMASK(mask_bank, bfin_read_SICB_IMASK(mask_bank) |
  181. (1 << mask_bit));
  182. #endif
  183. #endif
  184. local_irq_restore_hw(flags);
  185. }
  186. #ifdef CONFIG_PM
  187. int bfin_internal_set_wake(unsigned int irq, unsigned int state)
  188. {
  189. u32 bank, bit, wakeup = 0;
  190. unsigned long flags;
  191. bank = SIC_SYSIRQ(irq) / 32;
  192. bit = SIC_SYSIRQ(irq) % 32;
  193. switch (irq) {
  194. #ifdef IRQ_RTC
  195. case IRQ_RTC:
  196. wakeup |= WAKE;
  197. break;
  198. #endif
  199. #ifdef IRQ_CAN0_RX
  200. case IRQ_CAN0_RX:
  201. wakeup |= CANWE;
  202. break;
  203. #endif
  204. #ifdef IRQ_CAN1_RX
  205. case IRQ_CAN1_RX:
  206. wakeup |= CANWE;
  207. break;
  208. #endif
  209. #ifdef IRQ_USB_INT0
  210. case IRQ_USB_INT0:
  211. wakeup |= USBWE;
  212. break;
  213. #endif
  214. #ifdef IRQ_KEY
  215. case IRQ_KEY:
  216. wakeup |= KPADWE;
  217. break;
  218. #endif
  219. #ifdef CONFIG_BF54x
  220. case IRQ_CNT:
  221. wakeup |= ROTWE;
  222. break;
  223. #endif
  224. default:
  225. break;
  226. }
  227. local_irq_save_hw(flags);
  228. if (state) {
  229. bfin_sic_iwr[bank] |= (1 << bit);
  230. vr_wakeup |= wakeup;
  231. } else {
  232. bfin_sic_iwr[bank] &= ~(1 << bit);
  233. vr_wakeup &= ~wakeup;
  234. }
  235. local_irq_restore_hw(flags);
  236. return 0;
  237. }
  238. #endif
  239. static struct irq_chip bfin_core_irqchip = {
  240. .name = "CORE",
  241. .ack = bfin_ack_noop,
  242. .mask = bfin_core_mask_irq,
  243. .unmask = bfin_core_unmask_irq,
  244. };
  245. static struct irq_chip bfin_internal_irqchip = {
  246. .name = "INTN",
  247. .ack = bfin_ack_noop,
  248. .mask = bfin_internal_mask_irq,
  249. .unmask = bfin_internal_unmask_irq,
  250. .mask_ack = bfin_internal_mask_irq,
  251. .disable = bfin_internal_mask_irq,
  252. .enable = bfin_internal_unmask_irq,
  253. #ifdef CONFIG_PM
  254. .set_wake = bfin_internal_set_wake,
  255. #endif
  256. };
  257. static void bfin_handle_irq(unsigned irq)
  258. {
  259. #ifdef CONFIG_IPIPE
  260. struct pt_regs regs; /* Contents not used. */
  261. ipipe_trace_irq_entry(irq);
  262. __ipipe_handle_irq(irq, &regs);
  263. ipipe_trace_irq_exit(irq);
  264. #else /* !CONFIG_IPIPE */
  265. struct irq_desc *desc = irq_desc + irq;
  266. desc->handle_irq(irq, desc);
  267. #endif /* !CONFIG_IPIPE */
  268. }
  269. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  270. static int error_int_mask;
  271. static void bfin_generic_error_mask_irq(unsigned int irq)
  272. {
  273. error_int_mask &= ~(1L << (irq - IRQ_PPI_ERROR));
  274. if (!error_int_mask)
  275. bfin_internal_mask_irq(IRQ_GENERIC_ERROR);
  276. }
  277. static void bfin_generic_error_unmask_irq(unsigned int irq)
  278. {
  279. bfin_internal_unmask_irq(IRQ_GENERIC_ERROR);
  280. error_int_mask |= 1L << (irq - IRQ_PPI_ERROR);
  281. }
  282. static struct irq_chip bfin_generic_error_irqchip = {
  283. .name = "ERROR",
  284. .ack = bfin_ack_noop,
  285. .mask_ack = bfin_generic_error_mask_irq,
  286. .mask = bfin_generic_error_mask_irq,
  287. .unmask = bfin_generic_error_unmask_irq,
  288. };
  289. static void bfin_demux_error_irq(unsigned int int_err_irq,
  290. struct irq_desc *inta_desc)
  291. {
  292. int irq = 0;
  293. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  294. if (bfin_read_EMAC_SYSTAT() & EMAC_ERR_MASK)
  295. irq = IRQ_MAC_ERROR;
  296. else
  297. #endif
  298. if (bfin_read_SPORT0_STAT() & SPORT_ERR_MASK)
  299. irq = IRQ_SPORT0_ERROR;
  300. else if (bfin_read_SPORT1_STAT() & SPORT_ERR_MASK)
  301. irq = IRQ_SPORT1_ERROR;
  302. else if (bfin_read_PPI_STATUS() & PPI_ERR_MASK)
  303. irq = IRQ_PPI_ERROR;
  304. else if (bfin_read_CAN_GIF() & CAN_ERR_MASK)
  305. irq = IRQ_CAN_ERROR;
  306. else if (bfin_read_SPI_STAT() & SPI_ERR_MASK)
  307. irq = IRQ_SPI_ERROR;
  308. else if ((bfin_read_UART0_IIR() & UART_ERR_MASK_STAT1) &&
  309. (bfin_read_UART0_IIR() & UART_ERR_MASK_STAT0))
  310. irq = IRQ_UART0_ERROR;
  311. else if ((bfin_read_UART1_IIR() & UART_ERR_MASK_STAT1) &&
  312. (bfin_read_UART1_IIR() & UART_ERR_MASK_STAT0))
  313. irq = IRQ_UART1_ERROR;
  314. if (irq) {
  315. if (error_int_mask & (1L << (irq - IRQ_PPI_ERROR)))
  316. bfin_handle_irq(irq);
  317. else {
  318. switch (irq) {
  319. case IRQ_PPI_ERROR:
  320. bfin_write_PPI_STATUS(PPI_ERR_MASK);
  321. break;
  322. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  323. case IRQ_MAC_ERROR:
  324. bfin_write_EMAC_SYSTAT(EMAC_ERR_MASK);
  325. break;
  326. #endif
  327. case IRQ_SPORT0_ERROR:
  328. bfin_write_SPORT0_STAT(SPORT_ERR_MASK);
  329. break;
  330. case IRQ_SPORT1_ERROR:
  331. bfin_write_SPORT1_STAT(SPORT_ERR_MASK);
  332. break;
  333. case IRQ_CAN_ERROR:
  334. bfin_write_CAN_GIS(CAN_ERR_MASK);
  335. break;
  336. case IRQ_SPI_ERROR:
  337. bfin_write_SPI_STAT(SPI_ERR_MASK);
  338. break;
  339. default:
  340. break;
  341. }
  342. pr_debug("IRQ %d:"
  343. " MASKED PERIPHERAL ERROR INTERRUPT ASSERTED\n",
  344. irq);
  345. }
  346. } else
  347. printk(KERN_ERR
  348. "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
  349. " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
  350. __func__, __FILE__, __LINE__);
  351. }
  352. #endif /* BF537_GENERIC_ERROR_INT_DEMUX */
  353. static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
  354. {
  355. #ifdef CONFIG_IPIPE
  356. _set_irq_handler(irq, handle_level_irq);
  357. #else
  358. struct irq_desc *desc = irq_desc + irq;
  359. /* May not call generic set_irq_handler() due to spinlock
  360. recursion. */
  361. desc->handle_irq = handle;
  362. #endif
  363. }
  364. static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
  365. extern void bfin_gpio_irq_prepare(unsigned gpio);
  366. #if !defined(CONFIG_BF54x)
  367. static void bfin_gpio_ack_irq(unsigned int irq)
  368. {
  369. /* AFAIK ack_irq in case mask_ack is provided
  370. * get's only called for edge sense irqs
  371. */
  372. set_gpio_data(irq_to_gpio(irq), 0);
  373. }
  374. static void bfin_gpio_mask_ack_irq(unsigned int irq)
  375. {
  376. struct irq_desc *desc = irq_desc + irq;
  377. u32 gpionr = irq_to_gpio(irq);
  378. if (desc->handle_irq == handle_edge_irq)
  379. set_gpio_data(gpionr, 0);
  380. set_gpio_maska(gpionr, 0);
  381. }
  382. static void bfin_gpio_mask_irq(unsigned int irq)
  383. {
  384. set_gpio_maska(irq_to_gpio(irq), 0);
  385. }
  386. static void bfin_gpio_unmask_irq(unsigned int irq)
  387. {
  388. set_gpio_maska(irq_to_gpio(irq), 1);
  389. }
  390. static unsigned int bfin_gpio_irq_startup(unsigned int irq)
  391. {
  392. u32 gpionr = irq_to_gpio(irq);
  393. if (__test_and_set_bit(gpionr, gpio_enabled))
  394. bfin_gpio_irq_prepare(gpionr);
  395. bfin_gpio_unmask_irq(irq);
  396. return 0;
  397. }
  398. static void bfin_gpio_irq_shutdown(unsigned int irq)
  399. {
  400. u32 gpionr = irq_to_gpio(irq);
  401. bfin_gpio_mask_irq(irq);
  402. __clear_bit(gpionr, gpio_enabled);
  403. bfin_gpio_irq_free(gpionr);
  404. }
  405. static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
  406. {
  407. int ret;
  408. char buf[16];
  409. u32 gpionr = irq_to_gpio(irq);
  410. if (type == IRQ_TYPE_PROBE) {
  411. /* only probe unenabled GPIO interrupt lines */
  412. if (__test_bit(gpionr, gpio_enabled))
  413. return 0;
  414. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  415. }
  416. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  417. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  418. snprintf(buf, 16, "gpio-irq%d", irq);
  419. ret = bfin_gpio_irq_request(gpionr, buf);
  420. if (ret)
  421. return ret;
  422. if (__test_and_set_bit(gpionr, gpio_enabled))
  423. bfin_gpio_irq_prepare(gpionr);
  424. } else {
  425. __clear_bit(gpionr, gpio_enabled);
  426. return 0;
  427. }
  428. set_gpio_inen(gpionr, 0);
  429. set_gpio_dir(gpionr, 0);
  430. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  431. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  432. set_gpio_both(gpionr, 1);
  433. else
  434. set_gpio_both(gpionr, 0);
  435. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  436. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  437. else
  438. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  439. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  440. set_gpio_edge(gpionr, 1);
  441. set_gpio_inen(gpionr, 1);
  442. set_gpio_data(gpionr, 0);
  443. } else {
  444. set_gpio_edge(gpionr, 0);
  445. set_gpio_inen(gpionr, 1);
  446. }
  447. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  448. bfin_set_irq_handler(irq, handle_edge_irq);
  449. else
  450. bfin_set_irq_handler(irq, handle_level_irq);
  451. return 0;
  452. }
  453. #ifdef CONFIG_PM
  454. int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
  455. {
  456. unsigned gpio = irq_to_gpio(irq);
  457. if (state)
  458. gpio_pm_wakeup_request(gpio, PM_WAKE_IGNORE);
  459. else
  460. gpio_pm_wakeup_free(gpio);
  461. return 0;
  462. }
  463. #endif
  464. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  465. struct irq_desc *desc)
  466. {
  467. unsigned int i, gpio, mask, irq, search = 0;
  468. switch (inta_irq) {
  469. #if defined(CONFIG_BF53x)
  470. case IRQ_PROG_INTA:
  471. irq = IRQ_PF0;
  472. search = 1;
  473. break;
  474. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  475. case IRQ_MAC_RX:
  476. irq = IRQ_PH0;
  477. break;
  478. # endif
  479. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  480. case IRQ_PORTF_INTA:
  481. irq = IRQ_PF0;
  482. break;
  483. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  484. case IRQ_PORTF_INTA:
  485. irq = IRQ_PF0;
  486. break;
  487. case IRQ_PORTG_INTA:
  488. irq = IRQ_PG0;
  489. break;
  490. case IRQ_PORTH_INTA:
  491. irq = IRQ_PH0;
  492. break;
  493. #elif defined(CONFIG_BF561)
  494. case IRQ_PROG0_INTA:
  495. irq = IRQ_PF0;
  496. break;
  497. case IRQ_PROG1_INTA:
  498. irq = IRQ_PF16;
  499. break;
  500. case IRQ_PROG2_INTA:
  501. irq = IRQ_PF32;
  502. break;
  503. #endif
  504. default:
  505. BUG();
  506. return;
  507. }
  508. if (search) {
  509. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  510. irq += i;
  511. mask = get_gpiop_data(i) & get_gpiop_maska(i);
  512. while (mask) {
  513. if (mask & 1)
  514. bfin_handle_irq(irq);
  515. irq++;
  516. mask >>= 1;
  517. }
  518. }
  519. } else {
  520. gpio = irq_to_gpio(irq);
  521. mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
  522. do {
  523. if (mask & 1)
  524. bfin_handle_irq(irq);
  525. irq++;
  526. mask >>= 1;
  527. } while (mask);
  528. }
  529. }
  530. #else /* CONFIG_BF54x */
  531. #define NR_PINT_SYS_IRQS 4
  532. #define NR_PINT_BITS 32
  533. #define NR_PINTS 160
  534. #define IRQ_NOT_AVAIL 0xFF
  535. #define PINT_2_BANK(x) ((x) >> 5)
  536. #define PINT_2_BIT(x) ((x) & 0x1F)
  537. #define PINT_BIT(x) (1 << (PINT_2_BIT(x)))
  538. static unsigned char irq2pint_lut[NR_PINTS];
  539. static unsigned char pint2irq_lut[NR_PINT_SYS_IRQS * NR_PINT_BITS];
  540. struct pin_int_t {
  541. unsigned int mask_set;
  542. unsigned int mask_clear;
  543. unsigned int request;
  544. unsigned int assign;
  545. unsigned int edge_set;
  546. unsigned int edge_clear;
  547. unsigned int invert_set;
  548. unsigned int invert_clear;
  549. unsigned int pinstate;
  550. unsigned int latch;
  551. };
  552. static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
  553. (struct pin_int_t *)PINT0_MASK_SET,
  554. (struct pin_int_t *)PINT1_MASK_SET,
  555. (struct pin_int_t *)PINT2_MASK_SET,
  556. (struct pin_int_t *)PINT3_MASK_SET,
  557. };
  558. inline unsigned int get_irq_base(u32 bank, u8 bmap)
  559. {
  560. unsigned int irq_base;
  561. if (bank < 2) { /*PA-PB */
  562. irq_base = IRQ_PA0 + bmap * 16;
  563. } else { /*PC-PJ */
  564. irq_base = IRQ_PC0 + bmap * 16;
  565. }
  566. return irq_base;
  567. }
  568. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  569. void init_pint_lut(void)
  570. {
  571. u16 bank, bit, irq_base, bit_pos;
  572. u32 pint_assign;
  573. u8 bmap;
  574. memset(irq2pint_lut, IRQ_NOT_AVAIL, sizeof(irq2pint_lut));
  575. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++) {
  576. pint_assign = pint[bank]->assign;
  577. for (bit = 0; bit < NR_PINT_BITS; bit++) {
  578. bmap = (pint_assign >> ((bit / 8) * 8)) & 0xFF;
  579. irq_base = get_irq_base(bank, bmap);
  580. irq_base += (bit % 8) + ((bit / 8) & 1 ? 8 : 0);
  581. bit_pos = bit + bank * NR_PINT_BITS;
  582. pint2irq_lut[bit_pos] = irq_base - SYS_IRQS;
  583. irq2pint_lut[irq_base - SYS_IRQS] = bit_pos;
  584. }
  585. }
  586. }
  587. static void bfin_gpio_ack_irq(unsigned int irq)
  588. {
  589. struct irq_desc *desc = irq_desc + irq;
  590. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  591. u32 pintbit = PINT_BIT(pint_val);
  592. u32 bank = PINT_2_BANK(pint_val);
  593. if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  594. if (pint[bank]->invert_set & pintbit)
  595. pint[bank]->invert_clear = pintbit;
  596. else
  597. pint[bank]->invert_set = pintbit;
  598. }
  599. pint[bank]->request = pintbit;
  600. }
  601. static void bfin_gpio_mask_ack_irq(unsigned int irq)
  602. {
  603. struct irq_desc *desc = irq_desc + irq;
  604. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  605. u32 pintbit = PINT_BIT(pint_val);
  606. u32 bank = PINT_2_BANK(pint_val);
  607. if ((desc->status & IRQ_TYPE_SENSE_MASK) == IRQ_TYPE_EDGE_BOTH) {
  608. if (pint[bank]->invert_set & pintbit)
  609. pint[bank]->invert_clear = pintbit;
  610. else
  611. pint[bank]->invert_set = pintbit;
  612. }
  613. pint[bank]->request = pintbit;
  614. pint[bank]->mask_clear = pintbit;
  615. }
  616. static void bfin_gpio_mask_irq(unsigned int irq)
  617. {
  618. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  619. pint[PINT_2_BANK(pint_val)]->mask_clear = PINT_BIT(pint_val);
  620. }
  621. static void bfin_gpio_unmask_irq(unsigned int irq)
  622. {
  623. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  624. u32 pintbit = PINT_BIT(pint_val);
  625. u32 bank = PINT_2_BANK(pint_val);
  626. pint[bank]->request = pintbit;
  627. pint[bank]->mask_set = pintbit;
  628. }
  629. static unsigned int bfin_gpio_irq_startup(unsigned int irq)
  630. {
  631. u32 gpionr = irq_to_gpio(irq);
  632. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  633. if (pint_val == IRQ_NOT_AVAIL) {
  634. printk(KERN_ERR
  635. "GPIO IRQ %d :Not in PINT Assign table "
  636. "Reconfigure Interrupt to Port Assignemt\n", irq);
  637. return -ENODEV;
  638. }
  639. if (__test_and_set_bit(gpionr, gpio_enabled))
  640. bfin_gpio_irq_prepare(gpionr);
  641. bfin_gpio_unmask_irq(irq);
  642. return 0;
  643. }
  644. static void bfin_gpio_irq_shutdown(unsigned int irq)
  645. {
  646. u32 gpionr = irq_to_gpio(irq);
  647. bfin_gpio_mask_irq(irq);
  648. __clear_bit(gpionr, gpio_enabled);
  649. bfin_gpio_irq_free(gpionr);
  650. }
  651. static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
  652. {
  653. int ret;
  654. char buf[16];
  655. u32 gpionr = irq_to_gpio(irq);
  656. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  657. u32 pintbit = PINT_BIT(pint_val);
  658. u32 bank = PINT_2_BANK(pint_val);
  659. if (pint_val == IRQ_NOT_AVAIL)
  660. return -ENODEV;
  661. if (type == IRQ_TYPE_PROBE) {
  662. /* only probe unenabled GPIO interrupt lines */
  663. if (__test_bit(gpionr, gpio_enabled))
  664. return 0;
  665. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  666. }
  667. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  668. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  669. snprintf(buf, 16, "gpio-irq%d", irq);
  670. ret = bfin_gpio_irq_request(gpionr, buf);
  671. if (ret)
  672. return ret;
  673. if (__test_and_set_bit(gpionr, gpio_enabled))
  674. bfin_gpio_irq_prepare(gpionr);
  675. } else {
  676. __clear_bit(gpionr, gpio_enabled);
  677. return 0;
  678. }
  679. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  680. pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
  681. else
  682. pint[bank]->invert_clear = pintbit; /* high or rising edge denoted by zero */
  683. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  684. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  685. if (gpio_get_value(gpionr))
  686. pint[bank]->invert_set = pintbit;
  687. else
  688. pint[bank]->invert_clear = pintbit;
  689. }
  690. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  691. pint[bank]->edge_set = pintbit;
  692. bfin_set_irq_handler(irq, handle_edge_irq);
  693. } else {
  694. pint[bank]->edge_clear = pintbit;
  695. bfin_set_irq_handler(irq, handle_level_irq);
  696. }
  697. return 0;
  698. }
  699. #ifdef CONFIG_PM
  700. u32 pint_saved_masks[NR_PINT_SYS_IRQS];
  701. u32 pint_wakeup_masks[NR_PINT_SYS_IRQS];
  702. int bfin_gpio_set_wake(unsigned int irq, unsigned int state)
  703. {
  704. u32 pint_irq;
  705. u32 pint_val = irq2pint_lut[irq - SYS_IRQS];
  706. u32 bank = PINT_2_BANK(pint_val);
  707. u32 pintbit = PINT_BIT(pint_val);
  708. switch (bank) {
  709. case 0:
  710. pint_irq = IRQ_PINT0;
  711. break;
  712. case 2:
  713. pint_irq = IRQ_PINT2;
  714. break;
  715. case 3:
  716. pint_irq = IRQ_PINT3;
  717. break;
  718. case 1:
  719. pint_irq = IRQ_PINT1;
  720. break;
  721. default:
  722. return -EINVAL;
  723. }
  724. bfin_internal_set_wake(pint_irq, state);
  725. if (state)
  726. pint_wakeup_masks[bank] |= pintbit;
  727. else
  728. pint_wakeup_masks[bank] &= ~pintbit;
  729. return 0;
  730. }
  731. u32 bfin_pm_setup(void)
  732. {
  733. u32 val, i;
  734. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  735. val = pint[i]->mask_clear;
  736. pint_saved_masks[i] = val;
  737. if (val ^ pint_wakeup_masks[i]) {
  738. pint[i]->mask_clear = val;
  739. pint[i]->mask_set = pint_wakeup_masks[i];
  740. }
  741. }
  742. return 0;
  743. }
  744. void bfin_pm_restore(void)
  745. {
  746. u32 i, val;
  747. for (i = 0; i < NR_PINT_SYS_IRQS; i++) {
  748. val = pint_saved_masks[i];
  749. if (val ^ pint_wakeup_masks[i]) {
  750. pint[i]->mask_clear = pint[i]->mask_clear;
  751. pint[i]->mask_set = val;
  752. }
  753. }
  754. }
  755. #endif
  756. static void bfin_demux_gpio_irq(unsigned int inta_irq,
  757. struct irq_desc *desc)
  758. {
  759. u32 bank, pint_val;
  760. u32 request, irq;
  761. switch (inta_irq) {
  762. case IRQ_PINT0:
  763. bank = 0;
  764. break;
  765. case IRQ_PINT2:
  766. bank = 2;
  767. break;
  768. case IRQ_PINT3:
  769. bank = 3;
  770. break;
  771. case IRQ_PINT1:
  772. bank = 1;
  773. break;
  774. default:
  775. return;
  776. }
  777. pint_val = bank * NR_PINT_BITS;
  778. request = pint[bank]->request;
  779. while (request) {
  780. if (request & 1) {
  781. irq = pint2irq_lut[pint_val] + SYS_IRQS;
  782. bfin_handle_irq(irq);
  783. }
  784. pint_val++;
  785. request >>= 1;
  786. }
  787. }
  788. #endif
  789. static struct irq_chip bfin_gpio_irqchip = {
  790. .name = "GPIO",
  791. .ack = bfin_gpio_ack_irq,
  792. .mask = bfin_gpio_mask_irq,
  793. .mask_ack = bfin_gpio_mask_ack_irq,
  794. .unmask = bfin_gpio_unmask_irq,
  795. .disable = bfin_gpio_mask_irq,
  796. .enable = bfin_gpio_unmask_irq,
  797. .set_type = bfin_gpio_irq_type,
  798. .startup = bfin_gpio_irq_startup,
  799. .shutdown = bfin_gpio_irq_shutdown,
  800. #ifdef CONFIG_PM
  801. .set_wake = bfin_gpio_set_wake,
  802. #endif
  803. };
  804. void __cpuinit init_exception_vectors(void)
  805. {
  806. /* cannot program in software:
  807. * evt0 - emulation (jtag)
  808. * evt1 - reset
  809. */
  810. bfin_write_EVT2(evt_nmi);
  811. bfin_write_EVT3(trap);
  812. bfin_write_EVT5(evt_ivhw);
  813. bfin_write_EVT6(evt_timer);
  814. bfin_write_EVT7(evt_evt7);
  815. bfin_write_EVT8(evt_evt8);
  816. bfin_write_EVT9(evt_evt9);
  817. bfin_write_EVT10(evt_evt10);
  818. bfin_write_EVT11(evt_evt11);
  819. bfin_write_EVT12(evt_evt12);
  820. bfin_write_EVT13(evt_evt13);
  821. bfin_write_EVT14(evt14_softirq);
  822. bfin_write_EVT15(evt_system_call);
  823. CSYNC();
  824. }
  825. /*
  826. * This function should be called during kernel startup to initialize
  827. * the BFin IRQ handling routines.
  828. */
  829. int __init init_arch_irq(void)
  830. {
  831. int irq;
  832. unsigned long ilat = 0;
  833. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  834. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
  835. || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
  836. bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
  837. bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
  838. # ifdef CONFIG_BF54x
  839. bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
  840. # endif
  841. # ifdef CONFIG_SMP
  842. bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
  843. bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
  844. # endif
  845. #else
  846. bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
  847. #endif
  848. local_irq_disable();
  849. #if (defined(CONFIG_BF537) || defined(CONFIG_BF536))
  850. /* Clear EMAC Interrupt Status bits so we can demux it later */
  851. bfin_write_EMAC_SYSTAT(-1);
  852. #endif
  853. #ifdef CONFIG_BF54x
  854. # ifdef CONFIG_PINTx_REASSIGN
  855. pint[0]->assign = CONFIG_PINT0_ASSIGN;
  856. pint[1]->assign = CONFIG_PINT1_ASSIGN;
  857. pint[2]->assign = CONFIG_PINT2_ASSIGN;
  858. pint[3]->assign = CONFIG_PINT3_ASSIGN;
  859. # endif
  860. /* Whenever PINTx_ASSIGN is altered init_pint_lut() must be executed! */
  861. init_pint_lut();
  862. #endif
  863. for (irq = 0; irq <= SYS_IRQS; irq++) {
  864. if (irq <= IRQ_CORETMR)
  865. set_irq_chip(irq, &bfin_core_irqchip);
  866. else
  867. set_irq_chip(irq, &bfin_internal_irqchip);
  868. switch (irq) {
  869. #if defined(CONFIG_BF53x)
  870. case IRQ_PROG_INTA:
  871. # if defined(BF537_FAMILY) && !(defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  872. case IRQ_MAC_RX:
  873. # endif
  874. #elif defined(CONFIG_BF54x)
  875. case IRQ_PINT0:
  876. case IRQ_PINT1:
  877. case IRQ_PINT2:
  878. case IRQ_PINT3:
  879. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  880. case IRQ_PORTF_INTA:
  881. case IRQ_PORTG_INTA:
  882. case IRQ_PORTH_INTA:
  883. #elif defined(CONFIG_BF561)
  884. case IRQ_PROG0_INTA:
  885. case IRQ_PROG1_INTA:
  886. case IRQ_PROG2_INTA:
  887. #elif defined(CONFIG_BF538) || defined(CONFIG_BF539)
  888. case IRQ_PORTF_INTA:
  889. #endif
  890. set_irq_chained_handler(irq,
  891. bfin_demux_gpio_irq);
  892. break;
  893. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  894. case IRQ_GENERIC_ERROR:
  895. set_irq_chained_handler(irq, bfin_demux_error_irq);
  896. break;
  897. #endif
  898. #if defined(CONFIG_TICK_SOURCE_SYSTMR0) || defined(CONFIG_IPIPE)
  899. case IRQ_TIMER0:
  900. set_irq_handler(irq, handle_percpu_irq);
  901. break;
  902. #endif
  903. #ifdef CONFIG_SMP
  904. case IRQ_SUPPLE_0:
  905. case IRQ_SUPPLE_1:
  906. set_irq_handler(irq, handle_percpu_irq);
  907. break;
  908. #endif
  909. default:
  910. #ifdef CONFIG_IPIPE
  911. /*
  912. * We want internal interrupt sources to be
  913. * masked, because ISRs may trigger interrupts
  914. * recursively (e.g. DMA), but interrupts are
  915. * _not_ masked at CPU level. So let's handle
  916. * most of them as level interrupts, except
  917. * the timer interrupt which is special.
  918. */
  919. if (irq == IRQ_SYSTMR || irq == IRQ_CORETMR)
  920. set_irq_handler(irq, handle_simple_irq);
  921. else
  922. set_irq_handler(irq, handle_level_irq);
  923. #else /* !CONFIG_IPIPE */
  924. set_irq_handler(irq, handle_simple_irq);
  925. #endif /* !CONFIG_IPIPE */
  926. break;
  927. }
  928. }
  929. #ifdef BF537_GENERIC_ERROR_INT_DEMUX
  930. for (irq = IRQ_PPI_ERROR; irq <= IRQ_UART1_ERROR; irq++)
  931. set_irq_chip_and_handler(irq, &bfin_generic_error_irqchip,
  932. handle_level_irq);
  933. #endif
  934. /* if configured as edge, then will be changed to do_edge_IRQ */
  935. for (irq = GPIO_IRQ_BASE; irq < NR_IRQS; irq++)
  936. set_irq_chip_and_handler(irq, &bfin_gpio_irqchip,
  937. handle_level_irq);
  938. bfin_write_IMASK(0);
  939. CSYNC();
  940. ilat = bfin_read_ILAT();
  941. CSYNC();
  942. bfin_write_ILAT(ilat);
  943. CSYNC();
  944. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  945. /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
  946. * local_irq_enable()
  947. */
  948. program_IAR();
  949. /* Therefore it's better to setup IARs before interrupts enabled */
  950. search_IAR();
  951. /* Enable interrupts IVG7-15 */
  952. bfin_irq_flags |= IMASK_IVG15 |
  953. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  954. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  955. #ifdef SIC_IWR0
  956. bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
  957. # ifdef SIC_IWR1
  958. /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
  959. * will screw up the bootrom as it relies on MDMA0/1 waking it
  960. * up from IDLE instructions. See this report for more info:
  961. * http://blackfin.uclinux.org/gf/tracker/4323
  962. */
  963. if (ANOMALY_05000435)
  964. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  965. else
  966. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  967. # endif
  968. # ifdef SIC_IWR2
  969. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  970. # endif
  971. #else
  972. bfin_write_SIC_IWR(IWR_DISABLE_ALL);
  973. #endif
  974. #ifdef CONFIG_IPIPE
  975. for (irq = 0; irq < NR_IRQS; irq++) {
  976. struct irq_desc *desc = irq_to_desc(irq);
  977. desc->ic_prio = __ipipe_get_irq_priority(irq);
  978. }
  979. #endif /* CONFIG_IPIPE */
  980. return 0;
  981. }
  982. #ifdef CONFIG_DO_IRQ_L1
  983. __attribute__((l1_text))
  984. #endif
  985. void do_irq(int vec, struct pt_regs *fp)
  986. {
  987. if (vec == EVT_IVTMR_P) {
  988. vec = IRQ_CORETMR;
  989. } else {
  990. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  991. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  992. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561) \
  993. || defined(BF538_FAMILY) || defined(CONFIG_BF51x)
  994. unsigned long sic_status[3];
  995. if (smp_processor_id()) {
  996. #ifdef CONFIG_SMP
  997. /* This will be optimized out in UP mode. */
  998. sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
  999. sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
  1000. #endif
  1001. } else {
  1002. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  1003. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  1004. }
  1005. #ifdef CONFIG_BF54x
  1006. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  1007. #endif
  1008. for (;; ivg++) {
  1009. if (ivg >= ivg_stop) {
  1010. atomic_inc(&num_spurious);
  1011. return;
  1012. }
  1013. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  1014. break;
  1015. }
  1016. #else
  1017. unsigned long sic_status;
  1018. sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  1019. for (;; ivg++) {
  1020. if (ivg >= ivg_stop) {
  1021. atomic_inc(&num_spurious);
  1022. return;
  1023. } else if (sic_status & ivg->isrflag)
  1024. break;
  1025. }
  1026. #endif
  1027. vec = ivg->irqno;
  1028. }
  1029. asm_do_IRQ(vec, fp);
  1030. }
  1031. #ifdef CONFIG_IPIPE
  1032. int __ipipe_get_irq_priority(unsigned irq)
  1033. {
  1034. int ient, prio;
  1035. if (irq <= IRQ_CORETMR)
  1036. return irq;
  1037. for (ient = 0; ient < NR_PERI_INTS; ient++) {
  1038. struct ivgx *ivg = ivg_table + ient;
  1039. if (ivg->irqno == irq) {
  1040. for (prio = 0; prio <= IVG13-IVG7; prio++) {
  1041. if (ivg7_13[prio].ifirst <= ivg &&
  1042. ivg7_13[prio].istop > ivg)
  1043. return IVG7 + prio;
  1044. }
  1045. }
  1046. }
  1047. return IVG15;
  1048. }
  1049. /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
  1050. #ifdef CONFIG_DO_IRQ_L1
  1051. __attribute__((l1_text))
  1052. #endif
  1053. asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
  1054. {
  1055. struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
  1056. struct ipipe_domain *this_domain = ipipe_current_domain;
  1057. struct ivgx *ivg_stop = ivg7_13[vec-IVG7].istop;
  1058. struct ivgx *ivg = ivg7_13[vec-IVG7].ifirst;
  1059. int irq, s;
  1060. if (likely(vec == EVT_IVTMR_P)) {
  1061. irq = IRQ_CORETMR;
  1062. goto core_tick;
  1063. }
  1064. SSYNC();
  1065. #if defined(CONFIG_BF54x) || defined(CONFIG_BF52x) || defined(CONFIG_BF561)
  1066. {
  1067. unsigned long sic_status[3];
  1068. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  1069. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  1070. #ifdef CONFIG_BF54x
  1071. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  1072. #endif
  1073. for (;; ivg++) {
  1074. if (ivg >= ivg_stop) {
  1075. atomic_inc(&num_spurious);
  1076. return 0;
  1077. }
  1078. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  1079. break;
  1080. }
  1081. }
  1082. #else
  1083. {
  1084. unsigned long sic_status;
  1085. sic_status = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  1086. for (;; ivg++) {
  1087. if (ivg >= ivg_stop) {
  1088. atomic_inc(&num_spurious);
  1089. return 0;
  1090. } else if (sic_status & ivg->isrflag)
  1091. break;
  1092. }
  1093. }
  1094. #endif
  1095. irq = ivg->irqno;
  1096. if (irq == IRQ_SYSTMR) {
  1097. #ifdef CONFIG_GENERIC_CLOCKEVENTS
  1098. core_tick:
  1099. #else
  1100. bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
  1101. #endif
  1102. /* This is basically what we need from the register frame. */
  1103. __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
  1104. __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
  1105. if (this_domain != ipipe_root_domain)
  1106. __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
  1107. else
  1108. __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
  1109. }
  1110. #ifndef CONFIG_GENERIC_CLOCKEVENTS
  1111. core_tick:
  1112. #endif
  1113. if (this_domain == ipipe_root_domain) {
  1114. s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1115. barrier();
  1116. }
  1117. ipipe_trace_irq_entry(irq);
  1118. __ipipe_handle_irq(irq, regs);
  1119. ipipe_trace_irq_exit(irq);
  1120. if (this_domain == ipipe_root_domain) {
  1121. set_thread_flag(TIF_IRQ_SYNC);
  1122. if (!s) {
  1123. __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1124. return !test_bit(IPIPE_STALL_FLAG, &p->status);
  1125. }
  1126. }
  1127. return 0;
  1128. }
  1129. #endif /* CONFIG_IPIPE */