ints-priority.c 29 KB

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