ints-priority.c 29 KB

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