ints-priority.c 31 KB

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