ints-priority.c 31 KB

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