ints-priority.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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(uint32_t sec_gstat)
  398. {
  399. if (sec_gstat & SEC_GSTAT_ERR) {
  400. switch (sec_gstat & SEC_GSTAT_ERRC) {
  401. case 0:
  402. handle_sec_sfi_fault(sec_gstat);
  403. break;
  404. case SEC_GSTAT_SCIERR:
  405. handle_sec_sci_fault(sec_gstat);
  406. break;
  407. case SEC_GSTAT_SSIERR:
  408. handle_sec_ssi_fault(sec_gstat);
  409. break;
  410. }
  411. }
  412. }
  413. static struct irqaction bfin_fault_irq = {
  414. .name = "Blackfin fault",
  415. };
  416. static irqreturn_t bfin_fault_routine(int irq, void *data)
  417. {
  418. struct pt_regs *fp = get_irq_regs();
  419. switch (irq) {
  420. case IRQ_C0_DBL_FAULT:
  421. double_fault_c(fp);
  422. break;
  423. case IRQ_C0_HW_ERR:
  424. dump_bfin_process(fp);
  425. dump_bfin_mem(fp);
  426. show_regs(fp);
  427. printk(KERN_NOTICE "Kernel Stack\n");
  428. show_stack(current, NULL);
  429. print_modules();
  430. panic("Core 0 hardware error");
  431. break;
  432. case IRQ_C0_NMI_L1_PARITY_ERR:
  433. panic("Core 0 NMI L1 parity error");
  434. break;
  435. case IRQ_SEC_ERR:
  436. pr_err("SEC error\n");
  437. handle_sec_fault(bfin_read32(SEC_GSTAT));
  438. break;
  439. default:
  440. panic("Unknown fault %d", irq);
  441. }
  442. return IRQ_HANDLED;
  443. }
  444. #endif /* SEC_GCTL */
  445. static struct irq_chip bfin_core_irqchip = {
  446. .name = "CORE",
  447. .irq_mask = bfin_core_mask_irq,
  448. .irq_unmask = bfin_core_unmask_irq,
  449. };
  450. #ifndef SEC_GCTL
  451. static struct irq_chip bfin_internal_irqchip = {
  452. .name = "INTN",
  453. .irq_mask = bfin_internal_mask_irq_chip,
  454. .irq_unmask = bfin_internal_unmask_irq_chip,
  455. .irq_disable = bfin_internal_mask_irq_chip,
  456. .irq_enable = bfin_internal_unmask_irq_chip,
  457. #ifdef CONFIG_SMP
  458. .irq_set_affinity = bfin_internal_set_affinity,
  459. #endif
  460. .irq_set_wake = bfin_internal_set_wake_chip,
  461. };
  462. #else
  463. static struct irq_chip bfin_sec_irqchip = {
  464. .name = "SEC",
  465. .irq_mask_ack = bfin_sec_mask_ack_irq,
  466. .irq_mask = bfin_sec_mask_ack_irq,
  467. .irq_unmask = bfin_sec_unmask_irq,
  468. .irq_eoi = bfin_sec_unmask_irq,
  469. .irq_disable = bfin_sec_disable,
  470. .irq_enable = bfin_sec_enable,
  471. };
  472. #endif
  473. void bfin_handle_irq(unsigned irq)
  474. {
  475. #ifdef CONFIG_IPIPE
  476. struct pt_regs regs; /* Contents not used. */
  477. ipipe_trace_irq_entry(irq);
  478. __ipipe_handle_irq(irq, &regs);
  479. ipipe_trace_irq_exit(irq);
  480. #else /* !CONFIG_IPIPE */
  481. generic_handle_irq(irq);
  482. #endif /* !CONFIG_IPIPE */
  483. }
  484. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  485. static int mac_stat_int_mask;
  486. static void bfin_mac_status_ack_irq(unsigned int irq)
  487. {
  488. switch (irq) {
  489. case IRQ_MAC_MMCINT:
  490. bfin_write_EMAC_MMC_TIRQS(
  491. bfin_read_EMAC_MMC_TIRQE() &
  492. bfin_read_EMAC_MMC_TIRQS());
  493. bfin_write_EMAC_MMC_RIRQS(
  494. bfin_read_EMAC_MMC_RIRQE() &
  495. bfin_read_EMAC_MMC_RIRQS());
  496. break;
  497. case IRQ_MAC_RXFSINT:
  498. bfin_write_EMAC_RX_STKY(
  499. bfin_read_EMAC_RX_IRQE() &
  500. bfin_read_EMAC_RX_STKY());
  501. break;
  502. case IRQ_MAC_TXFSINT:
  503. bfin_write_EMAC_TX_STKY(
  504. bfin_read_EMAC_TX_IRQE() &
  505. bfin_read_EMAC_TX_STKY());
  506. break;
  507. case IRQ_MAC_WAKEDET:
  508. bfin_write_EMAC_WKUP_CTL(
  509. bfin_read_EMAC_WKUP_CTL() | MPKS | RWKS);
  510. break;
  511. default:
  512. /* These bits are W1C */
  513. bfin_write_EMAC_SYSTAT(1L << (irq - IRQ_MAC_PHYINT));
  514. break;
  515. }
  516. }
  517. static void bfin_mac_status_mask_irq(struct irq_data *d)
  518. {
  519. unsigned int irq = d->irq;
  520. mac_stat_int_mask &= ~(1L << (irq - IRQ_MAC_PHYINT));
  521. #ifdef BF537_FAMILY
  522. switch (irq) {
  523. case IRQ_MAC_PHYINT:
  524. bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() & ~PHYIE);
  525. break;
  526. default:
  527. break;
  528. }
  529. #else
  530. if (!mac_stat_int_mask)
  531. bfin_internal_mask_irq(IRQ_MAC_ERROR);
  532. #endif
  533. bfin_mac_status_ack_irq(irq);
  534. }
  535. static void bfin_mac_status_unmask_irq(struct irq_data *d)
  536. {
  537. unsigned int irq = d->irq;
  538. #ifdef BF537_FAMILY
  539. switch (irq) {
  540. case IRQ_MAC_PHYINT:
  541. bfin_write_EMAC_SYSCTL(bfin_read_EMAC_SYSCTL() | PHYIE);
  542. break;
  543. default:
  544. break;
  545. }
  546. #else
  547. if (!mac_stat_int_mask)
  548. bfin_internal_unmask_irq(IRQ_MAC_ERROR);
  549. #endif
  550. mac_stat_int_mask |= 1L << (irq - IRQ_MAC_PHYINT);
  551. }
  552. #ifdef CONFIG_PM
  553. int bfin_mac_status_set_wake(struct irq_data *d, unsigned int state)
  554. {
  555. #ifdef BF537_FAMILY
  556. return bfin_internal_set_wake(IRQ_GENERIC_ERROR, state);
  557. #else
  558. return bfin_internal_set_wake(IRQ_MAC_ERROR, state);
  559. #endif
  560. }
  561. #else
  562. # define bfin_mac_status_set_wake NULL
  563. #endif
  564. static struct irq_chip bfin_mac_status_irqchip = {
  565. .name = "MACST",
  566. .irq_mask = bfin_mac_status_mask_irq,
  567. .irq_unmask = bfin_mac_status_unmask_irq,
  568. .irq_set_wake = bfin_mac_status_set_wake,
  569. };
  570. void bfin_demux_mac_status_irq(unsigned int int_err_irq,
  571. struct irq_desc *inta_desc)
  572. {
  573. int i, irq = 0;
  574. u32 status = bfin_read_EMAC_SYSTAT();
  575. for (i = 0; i <= (IRQ_MAC_STMDONE - IRQ_MAC_PHYINT); i++)
  576. if (status & (1L << i)) {
  577. irq = IRQ_MAC_PHYINT + i;
  578. break;
  579. }
  580. if (irq) {
  581. if (mac_stat_int_mask & (1L << (irq - IRQ_MAC_PHYINT))) {
  582. bfin_handle_irq(irq);
  583. } else {
  584. bfin_mac_status_ack_irq(irq);
  585. pr_debug("IRQ %d:"
  586. " MASKED MAC ERROR INTERRUPT ASSERTED\n",
  587. irq);
  588. }
  589. } else
  590. printk(KERN_ERR
  591. "%s : %s : LINE %d :\nIRQ ?: MAC ERROR"
  592. " INTERRUPT ASSERTED BUT NO SOURCE FOUND"
  593. "(EMAC_SYSTAT=0x%X)\n",
  594. __func__, __FILE__, __LINE__, status);
  595. }
  596. #endif
  597. static inline void bfin_set_irq_handler(unsigned irq, irq_flow_handler_t handle)
  598. {
  599. #ifdef CONFIG_IPIPE
  600. handle = handle_level_irq;
  601. #endif
  602. __irq_set_handler_locked(irq, handle);
  603. }
  604. #ifdef CONFIG_GPIO_ADI
  605. static DECLARE_BITMAP(gpio_enabled, MAX_BLACKFIN_GPIOS);
  606. static void bfin_gpio_ack_irq(struct irq_data *d)
  607. {
  608. /* AFAIK ack_irq in case mask_ack is provided
  609. * get's only called for edge sense irqs
  610. */
  611. set_gpio_data(irq_to_gpio(d->irq), 0);
  612. }
  613. static void bfin_gpio_mask_ack_irq(struct irq_data *d)
  614. {
  615. unsigned int irq = d->irq;
  616. u32 gpionr = irq_to_gpio(irq);
  617. if (!irqd_is_level_type(d))
  618. set_gpio_data(gpionr, 0);
  619. set_gpio_maska(gpionr, 0);
  620. }
  621. static void bfin_gpio_mask_irq(struct irq_data *d)
  622. {
  623. set_gpio_maska(irq_to_gpio(d->irq), 0);
  624. }
  625. static void bfin_gpio_unmask_irq(struct irq_data *d)
  626. {
  627. set_gpio_maska(irq_to_gpio(d->irq), 1);
  628. }
  629. static unsigned int bfin_gpio_irq_startup(struct irq_data *d)
  630. {
  631. u32 gpionr = irq_to_gpio(d->irq);
  632. if (__test_and_set_bit(gpionr, gpio_enabled))
  633. bfin_gpio_irq_prepare(gpionr);
  634. bfin_gpio_unmask_irq(d);
  635. return 0;
  636. }
  637. static void bfin_gpio_irq_shutdown(struct irq_data *d)
  638. {
  639. u32 gpionr = irq_to_gpio(d->irq);
  640. bfin_gpio_mask_irq(d);
  641. __clear_bit(gpionr, gpio_enabled);
  642. bfin_gpio_irq_free(gpionr);
  643. }
  644. static int bfin_gpio_irq_type(struct irq_data *d, unsigned int type)
  645. {
  646. unsigned int irq = d->irq;
  647. int ret;
  648. char buf[16];
  649. u32 gpionr = irq_to_gpio(irq);
  650. if (type == IRQ_TYPE_PROBE) {
  651. /* only probe unenabled GPIO interrupt lines */
  652. if (test_bit(gpionr, gpio_enabled))
  653. return 0;
  654. type = IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING;
  655. }
  656. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
  657. IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
  658. snprintf(buf, 16, "gpio-irq%d", irq);
  659. ret = bfin_gpio_irq_request(gpionr, buf);
  660. if (ret)
  661. return ret;
  662. if (__test_and_set_bit(gpionr, gpio_enabled))
  663. bfin_gpio_irq_prepare(gpionr);
  664. } else {
  665. __clear_bit(gpionr, gpio_enabled);
  666. return 0;
  667. }
  668. set_gpio_inen(gpionr, 0);
  669. set_gpio_dir(gpionr, 0);
  670. if ((type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  671. == (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  672. set_gpio_both(gpionr, 1);
  673. else
  674. set_gpio_both(gpionr, 0);
  675. if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
  676. set_gpio_polar(gpionr, 1); /* low or falling edge denoted by one */
  677. else
  678. set_gpio_polar(gpionr, 0); /* high or rising edge denoted by zero */
  679. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING)) {
  680. set_gpio_edge(gpionr, 1);
  681. set_gpio_inen(gpionr, 1);
  682. set_gpio_data(gpionr, 0);
  683. } else {
  684. set_gpio_edge(gpionr, 0);
  685. set_gpio_inen(gpionr, 1);
  686. }
  687. if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING))
  688. bfin_set_irq_handler(irq, handle_edge_irq);
  689. else
  690. bfin_set_irq_handler(irq, handle_level_irq);
  691. return 0;
  692. }
  693. static void bfin_demux_gpio_block(unsigned int irq)
  694. {
  695. unsigned int gpio, mask;
  696. gpio = irq_to_gpio(irq);
  697. mask = get_gpiop_data(gpio) & get_gpiop_maska(gpio);
  698. while (mask) {
  699. if (mask & 1)
  700. bfin_handle_irq(irq);
  701. irq++;
  702. mask >>= 1;
  703. }
  704. }
  705. void bfin_demux_gpio_irq(unsigned int inta_irq,
  706. struct irq_desc *desc)
  707. {
  708. unsigned int irq;
  709. switch (inta_irq) {
  710. #if defined(BF537_FAMILY)
  711. case IRQ_PF_INTA_PG_INTA:
  712. bfin_demux_gpio_block(IRQ_PF0);
  713. irq = IRQ_PG0;
  714. break;
  715. case IRQ_PH_INTA_MAC_RX:
  716. irq = IRQ_PH0;
  717. break;
  718. #elif defined(BF533_FAMILY)
  719. case IRQ_PROG_INTA:
  720. irq = IRQ_PF0;
  721. break;
  722. #elif defined(BF538_FAMILY)
  723. case IRQ_PORTF_INTA:
  724. irq = IRQ_PF0;
  725. break;
  726. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  727. case IRQ_PORTF_INTA:
  728. irq = IRQ_PF0;
  729. break;
  730. case IRQ_PORTG_INTA:
  731. irq = IRQ_PG0;
  732. break;
  733. case IRQ_PORTH_INTA:
  734. irq = IRQ_PH0;
  735. break;
  736. #elif defined(CONFIG_BF561)
  737. case IRQ_PROG0_INTA:
  738. irq = IRQ_PF0;
  739. break;
  740. case IRQ_PROG1_INTA:
  741. irq = IRQ_PF16;
  742. break;
  743. case IRQ_PROG2_INTA:
  744. irq = IRQ_PF32;
  745. break;
  746. #endif
  747. default:
  748. BUG();
  749. return;
  750. }
  751. bfin_demux_gpio_block(irq);
  752. }
  753. #ifdef CONFIG_PM
  754. static int bfin_gpio_set_wake(struct irq_data *d, unsigned int state)
  755. {
  756. return bfin_gpio_pm_wakeup_ctrl(irq_to_gpio(d->irq), state);
  757. }
  758. #else
  759. # define bfin_gpio_set_wake NULL
  760. #endif
  761. static struct irq_chip bfin_gpio_irqchip = {
  762. .name = "GPIO",
  763. .irq_ack = bfin_gpio_ack_irq,
  764. .irq_mask = bfin_gpio_mask_irq,
  765. .irq_mask_ack = bfin_gpio_mask_ack_irq,
  766. .irq_unmask = bfin_gpio_unmask_irq,
  767. .irq_disable = bfin_gpio_mask_irq,
  768. .irq_enable = bfin_gpio_unmask_irq,
  769. .irq_set_type = bfin_gpio_irq_type,
  770. .irq_startup = bfin_gpio_irq_startup,
  771. .irq_shutdown = bfin_gpio_irq_shutdown,
  772. .irq_set_wake = bfin_gpio_set_wake,
  773. };
  774. #endif
  775. #ifdef CONFIG_PM
  776. #ifdef SEC_GCTL
  777. static u32 save_pint_sec_ctl[NR_PINT_SYS_IRQS];
  778. static int sec_suspend(void)
  779. {
  780. u32 bank;
  781. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
  782. save_pint_sec_ctl[bank] = bfin_read_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0));
  783. return 0;
  784. }
  785. static void sec_resume(void)
  786. {
  787. u32 bank;
  788. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
  789. udelay(100);
  790. bfin_write_SEC_GCTL(SEC_GCTL_EN);
  791. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
  792. for (bank = 0; bank < NR_PINT_SYS_IRQS; bank++)
  793. bfin_write_SEC_SCTL(bank + BFIN_SYSIRQ(IRQ_PINT0), save_pint_sec_ctl[bank]);
  794. }
  795. static struct syscore_ops sec_pm_syscore_ops = {
  796. .suspend = sec_suspend,
  797. .resume = sec_resume,
  798. };
  799. #endif
  800. #endif
  801. void init_exception_vectors(void)
  802. {
  803. /* cannot program in software:
  804. * evt0 - emulation (jtag)
  805. * evt1 - reset
  806. */
  807. bfin_write_EVT2(evt_nmi);
  808. bfin_write_EVT3(trap);
  809. bfin_write_EVT5(evt_ivhw);
  810. bfin_write_EVT6(evt_timer);
  811. bfin_write_EVT7(evt_evt7);
  812. bfin_write_EVT8(evt_evt8);
  813. bfin_write_EVT9(evt_evt9);
  814. bfin_write_EVT10(evt_evt10);
  815. bfin_write_EVT11(evt_evt11);
  816. bfin_write_EVT12(evt_evt12);
  817. bfin_write_EVT13(evt_evt13);
  818. bfin_write_EVT14(evt_evt14);
  819. bfin_write_EVT15(evt_system_call);
  820. CSYNC();
  821. }
  822. #ifndef SEC_GCTL
  823. /*
  824. * This function should be called during kernel startup to initialize
  825. * the BFin IRQ handling routines.
  826. */
  827. int __init init_arch_irq(void)
  828. {
  829. int irq;
  830. unsigned long ilat = 0;
  831. /* Disable all the peripheral intrs - page 4-29 HW Ref manual */
  832. #ifdef SIC_IMASK0
  833. bfin_write_SIC_IMASK0(SIC_UNMASK_ALL);
  834. bfin_write_SIC_IMASK1(SIC_UNMASK_ALL);
  835. # ifdef SIC_IMASK2
  836. bfin_write_SIC_IMASK2(SIC_UNMASK_ALL);
  837. # endif
  838. # if defined(CONFIG_SMP) || defined(CONFIG_ICC)
  839. bfin_write_SICB_IMASK0(SIC_UNMASK_ALL);
  840. bfin_write_SICB_IMASK1(SIC_UNMASK_ALL);
  841. # endif
  842. #else
  843. bfin_write_SIC_IMASK(SIC_UNMASK_ALL);
  844. #endif
  845. local_irq_disable();
  846. for (irq = 0; irq <= SYS_IRQS; irq++) {
  847. if (irq <= IRQ_CORETMR)
  848. irq_set_chip(irq, &bfin_core_irqchip);
  849. else
  850. irq_set_chip(irq, &bfin_internal_irqchip);
  851. switch (irq) {
  852. #if !BFIN_GPIO_PINT
  853. #if defined(BF537_FAMILY)
  854. case IRQ_PH_INTA_MAC_RX:
  855. case IRQ_PF_INTA_PG_INTA:
  856. #elif defined(BF533_FAMILY)
  857. case IRQ_PROG_INTA:
  858. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  859. case IRQ_PORTF_INTA:
  860. case IRQ_PORTG_INTA:
  861. case IRQ_PORTH_INTA:
  862. #elif defined(CONFIG_BF561)
  863. case IRQ_PROG0_INTA:
  864. case IRQ_PROG1_INTA:
  865. case IRQ_PROG2_INTA:
  866. #elif defined(BF538_FAMILY)
  867. case IRQ_PORTF_INTA:
  868. #endif
  869. irq_set_chained_handler(irq, bfin_demux_gpio_irq);
  870. break;
  871. #endif
  872. #if defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE)
  873. case IRQ_MAC_ERROR:
  874. irq_set_chained_handler(irq,
  875. bfin_demux_mac_status_irq);
  876. break;
  877. #endif
  878. #if defined(CONFIG_SMP) || defined(CONFIG_ICC)
  879. case IRQ_SUPPLE_0:
  880. case IRQ_SUPPLE_1:
  881. irq_set_handler(irq, handle_percpu_irq);
  882. break;
  883. #endif
  884. #ifdef CONFIG_TICKSOURCE_CORETMR
  885. case IRQ_CORETMR:
  886. # ifdef CONFIG_SMP
  887. irq_set_handler(irq, handle_percpu_irq);
  888. # else
  889. irq_set_handler(irq, handle_simple_irq);
  890. # endif
  891. break;
  892. #endif
  893. #ifdef CONFIG_TICKSOURCE_GPTMR0
  894. case IRQ_TIMER0:
  895. irq_set_handler(irq, handle_simple_irq);
  896. break;
  897. #endif
  898. default:
  899. #ifdef CONFIG_IPIPE
  900. irq_set_handler(irq, handle_level_irq);
  901. #else
  902. irq_set_handler(irq, handle_simple_irq);
  903. #endif
  904. break;
  905. }
  906. }
  907. init_mach_irq();
  908. #if (defined(CONFIG_BFIN_MAC) || defined(CONFIG_BFIN_MAC_MODULE))
  909. for (irq = IRQ_MAC_PHYINT; irq <= IRQ_MAC_STMDONE; irq++)
  910. irq_set_chip_and_handler(irq, &bfin_mac_status_irqchip,
  911. handle_level_irq);
  912. #endif
  913. /* if configured as edge, then will be changed to do_edge_IRQ */
  914. #ifdef CONFIG_GPIO_ADI
  915. for (irq = GPIO_IRQ_BASE;
  916. irq < (GPIO_IRQ_BASE + MAX_BLACKFIN_GPIOS); irq++)
  917. irq_set_chip_and_handler(irq, &bfin_gpio_irqchip,
  918. handle_level_irq);
  919. #endif
  920. bfin_write_IMASK(0);
  921. CSYNC();
  922. ilat = bfin_read_ILAT();
  923. CSYNC();
  924. bfin_write_ILAT(ilat);
  925. CSYNC();
  926. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  927. /* IMASK=xxx is equivalent to STI xx or bfin_irq_flags=xx,
  928. * local_irq_enable()
  929. */
  930. program_IAR();
  931. /* Therefore it's better to setup IARs before interrupts enabled */
  932. search_IAR();
  933. /* Enable interrupts IVG7-15 */
  934. bfin_irq_flags |= IMASK_IVG15 |
  935. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  936. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  937. /* This implicitly covers ANOMALY_05000171
  938. * Boot-ROM code modifies SICA_IWRx wakeup registers
  939. */
  940. #ifdef SIC_IWR0
  941. bfin_write_SIC_IWR0(IWR_DISABLE_ALL);
  942. # ifdef SIC_IWR1
  943. /* BF52x/BF51x system reset does not properly reset SIC_IWR1 which
  944. * will screw up the bootrom as it relies on MDMA0/1 waking it
  945. * up from IDLE instructions. See this report for more info:
  946. * http://blackfin.uclinux.org/gf/tracker/4323
  947. */
  948. if (ANOMALY_05000435)
  949. bfin_write_SIC_IWR1(IWR_ENABLE(10) | IWR_ENABLE(11));
  950. else
  951. bfin_write_SIC_IWR1(IWR_DISABLE_ALL);
  952. # endif
  953. # ifdef SIC_IWR2
  954. bfin_write_SIC_IWR2(IWR_DISABLE_ALL);
  955. # endif
  956. #else
  957. bfin_write_SIC_IWR(IWR_DISABLE_ALL);
  958. #endif
  959. return 0;
  960. }
  961. #ifdef CONFIG_DO_IRQ_L1
  962. __attribute__((l1_text))
  963. #endif
  964. static int vec_to_irq(int vec)
  965. {
  966. struct ivgx *ivg = ivg7_13[vec - IVG7].ifirst;
  967. struct ivgx *ivg_stop = ivg7_13[vec - IVG7].istop;
  968. unsigned long sic_status[3];
  969. if (likely(vec == EVT_IVTMR_P))
  970. return IRQ_CORETMR;
  971. #ifdef SIC_ISR
  972. sic_status[0] = bfin_read_SIC_IMASK() & bfin_read_SIC_ISR();
  973. #else
  974. if (smp_processor_id()) {
  975. # ifdef SICB_ISR0
  976. /* This will be optimized out in UP mode. */
  977. sic_status[0] = bfin_read_SICB_ISR0() & bfin_read_SICB_IMASK0();
  978. sic_status[1] = bfin_read_SICB_ISR1() & bfin_read_SICB_IMASK1();
  979. # endif
  980. } else {
  981. sic_status[0] = bfin_read_SIC_ISR0() & bfin_read_SIC_IMASK0();
  982. sic_status[1] = bfin_read_SIC_ISR1() & bfin_read_SIC_IMASK1();
  983. }
  984. #endif
  985. #ifdef SIC_ISR2
  986. sic_status[2] = bfin_read_SIC_ISR2() & bfin_read_SIC_IMASK2();
  987. #endif
  988. for (;; ivg++) {
  989. if (ivg >= ivg_stop)
  990. return -1;
  991. #ifdef SIC_ISR
  992. if (sic_status[0] & ivg->isrflag)
  993. #else
  994. if (sic_status[(ivg->irqno - IVG7) / 32] & ivg->isrflag)
  995. #endif
  996. return ivg->irqno;
  997. }
  998. }
  999. #else /* SEC_GCTL */
  1000. /*
  1001. * This function should be called during kernel startup to initialize
  1002. * the BFin IRQ handling routines.
  1003. */
  1004. int __init init_arch_irq(void)
  1005. {
  1006. int irq;
  1007. unsigned long ilat = 0;
  1008. bfin_write_SEC_GCTL(SEC_GCTL_RESET);
  1009. local_irq_disable();
  1010. for (irq = 0; irq <= SYS_IRQS; irq++) {
  1011. if (irq <= IRQ_CORETMR) {
  1012. irq_set_chip_and_handler(irq, &bfin_core_irqchip,
  1013. handle_simple_irq);
  1014. #if defined(CONFIG_TICKSOURCE_CORETMR) && defined(CONFIG_SMP)
  1015. if (irq == IRQ_CORETMR)
  1016. irq_set_handler(irq, handle_percpu_irq);
  1017. #endif
  1018. } else if (irq >= BFIN_IRQ(34) && irq <= BFIN_IRQ(37)) {
  1019. irq_set_chip_and_handler(irq, &bfin_sec_irqchip,
  1020. handle_percpu_irq);
  1021. } else {
  1022. irq_set_chip(irq, &bfin_sec_irqchip);
  1023. irq_set_handler(irq, handle_fasteoi_irq);
  1024. __irq_set_preflow_handler(irq, bfin_sec_preflow_handler);
  1025. }
  1026. }
  1027. bfin_write_IMASK(0);
  1028. CSYNC();
  1029. ilat = bfin_read_ILAT();
  1030. CSYNC();
  1031. bfin_write_ILAT(ilat);
  1032. CSYNC();
  1033. printk(KERN_INFO "Configuring Blackfin Priority Driven Interrupts\n");
  1034. bfin_sec_set_priority(CONFIG_SEC_IRQ_PRIORITY_LEVELS, sec_int_priority);
  1035. /* Enable interrupts IVG7-15 */
  1036. bfin_irq_flags |= IMASK_IVG15 |
  1037. IMASK_IVG14 | IMASK_IVG13 | IMASK_IVG12 | IMASK_IVG11 |
  1038. IMASK_IVG10 | IMASK_IVG9 | IMASK_IVG8 | IMASK_IVG7 | IMASK_IVGHW;
  1039. bfin_write_SEC_FCTL(SEC_FCTL_EN | SEC_FCTL_SYSRST_EN | SEC_FCTL_FLTIN_EN);
  1040. bfin_sec_enable_sci(BFIN_SYSIRQ(IRQ_WATCH0));
  1041. bfin_sec_enable_ssi(BFIN_SYSIRQ(IRQ_WATCH0));
  1042. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_RESET);
  1043. udelay(100);
  1044. bfin_write_SEC_GCTL(SEC_GCTL_EN);
  1045. bfin_write_SEC_SCI(0, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
  1046. bfin_write_SEC_SCI(1, SEC_CCTL, SEC_CCTL_EN | SEC_CCTL_NMI_EN);
  1047. init_software_driven_irq();
  1048. #ifdef CONFIG_PM
  1049. register_syscore_ops(&sec_pm_syscore_ops);
  1050. #endif
  1051. bfin_fault_irq.handler = bfin_fault_routine;
  1052. #ifdef CONFIG_L1_PARITY_CHECK
  1053. setup_irq(IRQ_C0_NMI_L1_PARITY_ERR, &bfin_fault_irq);
  1054. #endif
  1055. setup_irq(IRQ_C0_DBL_FAULT, &bfin_fault_irq);
  1056. setup_irq(IRQ_SEC_ERR, &bfin_fault_irq);
  1057. return 0;
  1058. }
  1059. #ifdef CONFIG_DO_IRQ_L1
  1060. __attribute__((l1_text))
  1061. #endif
  1062. static int vec_to_irq(int vec)
  1063. {
  1064. if (likely(vec == EVT_IVTMR_P))
  1065. return IRQ_CORETMR;
  1066. return BFIN_IRQ(bfin_read_SEC_SCI(0, SEC_CSID));
  1067. }
  1068. #endif /* SEC_GCTL */
  1069. #ifdef CONFIG_DO_IRQ_L1
  1070. __attribute__((l1_text))
  1071. #endif
  1072. void do_irq(int vec, struct pt_regs *fp)
  1073. {
  1074. int irq = vec_to_irq(vec);
  1075. if (irq == -1)
  1076. return;
  1077. asm_do_IRQ(irq, fp);
  1078. }
  1079. #ifdef CONFIG_IPIPE
  1080. int __ipipe_get_irq_priority(unsigned irq)
  1081. {
  1082. int ient, prio;
  1083. if (irq <= IRQ_CORETMR)
  1084. return irq;
  1085. #ifdef SEC_GCTL
  1086. if (irq >= BFIN_IRQ(0))
  1087. return IVG11;
  1088. #else
  1089. for (ient = 0; ient < NR_PERI_INTS; ient++) {
  1090. struct ivgx *ivg = ivg_table + ient;
  1091. if (ivg->irqno == irq) {
  1092. for (prio = 0; prio <= IVG13-IVG7; prio++) {
  1093. if (ivg7_13[prio].ifirst <= ivg &&
  1094. ivg7_13[prio].istop > ivg)
  1095. return IVG7 + prio;
  1096. }
  1097. }
  1098. }
  1099. #endif
  1100. return IVG15;
  1101. }
  1102. /* Hw interrupts are disabled on entry (check SAVE_CONTEXT). */
  1103. #ifdef CONFIG_DO_IRQ_L1
  1104. __attribute__((l1_text))
  1105. #endif
  1106. asmlinkage int __ipipe_grab_irq(int vec, struct pt_regs *regs)
  1107. {
  1108. struct ipipe_percpu_domain_data *p = ipipe_root_cpudom_ptr();
  1109. struct ipipe_domain *this_domain = __ipipe_current_domain;
  1110. int irq, s = 0;
  1111. irq = vec_to_irq(vec);
  1112. if (irq == -1)
  1113. return 0;
  1114. if (irq == IRQ_SYSTMR) {
  1115. #if !defined(CONFIG_GENERIC_CLOCKEVENTS) || defined(CONFIG_TICKSOURCE_GPTMR0)
  1116. bfin_write_TIMER_STATUS(1); /* Latch TIMIL0 */
  1117. #endif
  1118. /* This is basically what we need from the register frame. */
  1119. __raw_get_cpu_var(__ipipe_tick_regs).ipend = regs->ipend;
  1120. __raw_get_cpu_var(__ipipe_tick_regs).pc = regs->pc;
  1121. if (this_domain != ipipe_root_domain)
  1122. __raw_get_cpu_var(__ipipe_tick_regs).ipend &= ~0x10;
  1123. else
  1124. __raw_get_cpu_var(__ipipe_tick_regs).ipend |= 0x10;
  1125. }
  1126. /*
  1127. * We don't want Linux interrupt handlers to run at the
  1128. * current core priority level (i.e. < EVT15), since this
  1129. * might delay other interrupts handled by a high priority
  1130. * domain. Here is what we do instead:
  1131. *
  1132. * - we raise the SYNCDEFER bit to prevent
  1133. * __ipipe_handle_irq() to sync the pipeline for the root
  1134. * stage for the incoming interrupt. Upon return, that IRQ is
  1135. * pending in the interrupt log.
  1136. *
  1137. * - we raise the TIF_IRQ_SYNC bit for the current thread, so
  1138. * that _schedule_and_signal_from_int will eventually sync the
  1139. * pipeline from EVT15.
  1140. */
  1141. if (this_domain == ipipe_root_domain) {
  1142. s = __test_and_set_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1143. barrier();
  1144. }
  1145. ipipe_trace_irq_entry(irq);
  1146. __ipipe_handle_irq(irq, regs);
  1147. ipipe_trace_irq_exit(irq);
  1148. if (user_mode(regs) &&
  1149. !ipipe_test_foreign_stack() &&
  1150. (current->ipipe_flags & PF_EVTRET) != 0) {
  1151. /*
  1152. * Testing for user_regs() does NOT fully eliminate
  1153. * foreign stack contexts, because of the forged
  1154. * interrupt returns we do through
  1155. * __ipipe_call_irqtail. In that case, we might have
  1156. * preempted a foreign stack context in a high
  1157. * priority domain, with a single interrupt level now
  1158. * pending after the irqtail unwinding is done. In
  1159. * which case user_mode() is now true, and the event
  1160. * gets dispatched spuriously.
  1161. */
  1162. current->ipipe_flags &= ~PF_EVTRET;
  1163. __ipipe_dispatch_event(IPIPE_EVENT_RETURN, regs);
  1164. }
  1165. if (this_domain == ipipe_root_domain) {
  1166. set_thread_flag(TIF_IRQ_SYNC);
  1167. if (!s) {
  1168. __clear_bit(IPIPE_SYNCDEFER_FLAG, &p->status);
  1169. return !test_bit(IPIPE_STALL_FLAG, &p->status);
  1170. }
  1171. }
  1172. return 0;
  1173. }
  1174. #endif /* CONFIG_IPIPE */