KeyStone_common.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. /******************************************************************************
  2. Copyright (C), 2001-2012, Texas Instrument.
  3. ******************************************************************************
  4. File Name : KeyStone_common.h
  5. Version : Initial Draft
  6. Author : Zhan
  7. Created : 2012/10/30
  8. Last Modified :
  9. Description : KeyStone_common.c header file, KeyStone common miscellaneous functions and definitions
  10. Function List :
  11. History :
  12. 1.Date : 2010-12-12
  13. Author : Brighton Feng
  14. Modification: Created file
  15. 2.Date : 2012/10/6
  16. Author : Brighton Feng
  17. Modification : For memory protection configuration
  18. 3.Date : 2014-12-8
  19. Author : Brighton Feng
  20. Modification : Add common device, CPU, interrupt initialization functions.
  21. Print device information including device type, speed grade,
  22. boot mode, required voltage, ID��
  23. Add EDMA enable/disable functions.
  24. To support square wave generation by timer.
  25. ******************************************************************************/
  26. #ifndef _KEYSTONE_COMMON_H_
  27. #define _KEYSTONE_COMMON_H_
  28. #include <c6x.h>
  29. #include <tistdtypes.h>
  30. #include <cslr_pllc.h>
  31. #include <cslr_xmc.h>
  32. #include <cslr_cgem.h>
  33. #include <csl_cgemAux.h>
  34. #include <cslr_bootcfg.h>
  35. #include <cslr_tpcc.h>
  36. #include <cslr_tptc.h>
  37. #include <cslr_device.h>
  38. #include <cslr_cpintc.h>
  39. #include <cslr_tmr.h>
  40. #include <cslr_srio.h>
  41. #include <cslr_vusr.h>
  42. #include <csl_psc.h>
  43. #include <csl_tmr.h>
  44. #include <csl_cache.h>
  45. #include <csl_cacheAux.h>
  46. #include <csl_xmcAux.h>
  47. #include <cslr_msmc.h>
  48. #include <csl_idma.h>
  49. #include <cslr_mpu.h>
  50. #include <cslr_gpio.h>
  51. #include <cslr_emif4f.h>
  52. #include <stdio.h>
  53. /*----------------------PLL registers definition----------------*/
  54. #define PLLCTL0_PLLD_SHIFT (0)
  55. #define PLLCTL0_PLLD_MASK (0x3F<<PLLCTL0_PLLD_SHIFT)
  56. #define PLLCTL0_PLLM_SHIFT (6)
  57. #define PLLCTL0_PLLM_MASK (0x1FFF<<PLLCTL0_PLLM_SHIFT)
  58. #define PLLCTL_OD_SHIFT (19)
  59. #define PLLCTL_OD_MASK (0xF<<PLLCTL_OD_SHIFT)
  60. #define PLLCTL_BYPASS_SHIFT (23)
  61. #define PLLCTL_BYPASS_MASK (0x1<<PLLCTL_BYPASS_SHIFT)
  62. #define PLLCTL0_BWADJ_SHIFT (24)
  63. #define PLLCTL0_BWADJ_MASK (0xFF<<PLLCTL0_BWADJ_SHIFT)
  64. #define PLLCTL1_BWADJ_SHIFT (0)
  65. #define PLLCTL1_BWADJ_MASK (0xF<<PLLCTL1_BWADJ_SHIFT)
  66. #define PLLCTL1_ENSAT_SHIFT (6)
  67. #define PLLCTL1_ENSAT_MASK (0x1<<PLLCTL1_ENSAT_SHIFT)
  68. #define PLLCTL1_PAPLL_SHIFT (13)
  69. #define PLLCTL1_PAPLL_MASK (0x1<<PLLCTL1_PAPLL_SHIFT)
  70. #define PLLCTL1_PLLRESET_SHIFT (14)
  71. #define PLLCTL1_PLLRESET_MASK (0x1<<PLLCTL1_PLLRESET_SHIFT)
  72. /*----------------------Boot Config registers definition----------------*/
  73. #define DEVSPEED (*(unsigned int *)0x026203F8u)
  74. #define DEVSPEED_1000_MHZ_MASK_L (1<<0)
  75. #define DEVSPEED_1200_MHZ_MASK_L (1<<1)
  76. #define DEVSPEED_1250_MHZ_MASK_L (1<<2)
  77. #define DEVSPEED_1400_MHZ_MASK_L (1<<3)
  78. #define DEVSPEED_1400_MHZ_MASK_H (1<<4)
  79. #define DEVSPEED_1250_MHZ_MASK_H (1<<5)
  80. #define DEVSPEED_1200_MHZ_MASK_H (1<<6)
  81. #define DEVSPEED_1000_MHZ_MASK_H (1<<7)
  82. #define DEVSPEED_800_MHZ_MASK_H (1<<8)
  83. #define DEVSPEED_DSP_SPEED_MASK (0x1FFu<<23u)
  84. #define DEVSPEED_DSP_SPEED_SHIFT (23u)
  85. #define DEVSTAT_LENDIAN_SHIFT (0)
  86. #define DEVSTAT_BOOTMODE_SHIFT (1)
  87. #define DEVSTAT_SYSPLL_SHIFT (11)
  88. #define DEVSTAT_BOOTMASTER_SHIFT (14)
  89. #define DEVSTAT_LENDIAN_MASK (1<<0)
  90. #define DEVSTAT_BOOTMODE_MASK (7<<1)
  91. #define DEVSTAT_SYSPLL_MASK (7<<11)
  92. #define DEVSTAT_BOOTMASTER_MASK (1<<14)
  93. /*----------------------Timer plus registers definition----------------*/
  94. typedef struct {
  95. volatile Uint32 PID12;
  96. volatile Uint32 EMUMGT_CLKSPD;
  97. volatile Uint32 GPINT_EN;
  98. volatile Uint32 GPDIR_DAT;
  99. volatile Uint32 CNTLO;
  100. volatile Uint32 CNTHI;
  101. volatile Uint32 PRDLO;
  102. volatile Uint32 PRDHI;
  103. volatile Uint32 TCR;
  104. volatile Uint32 TGCR;
  105. volatile Uint32 WDTCR;
  106. volatile Uint32 TLGC;
  107. volatile Uint32 TLMR;
  108. volatile Uint32 RELLO;
  109. volatile Uint32 RELHI;
  110. volatile Uint32 CAPLO;
  111. volatile Uint32 CAPHI;
  112. volatile Uint32 INTCTL_STAT;
  113. volatile Uint8 RSVD0[24];
  114. volatile Uint32 TIMERLO_COMPARE_REG[8];
  115. volatile Uint8 RSVD1[32];
  116. } CSL_TmrPlusRegs;
  117. #define TMR_TCR_READRSTMODE_HI_SHIFT (26)
  118. #define TMR_TCR_CAPEVTMODE_LO_SHIFT (12)
  119. #define TMR_TCR_CAPMODE_LO_SHIFT (11)
  120. #define TMR_TCR_READRSTMODE_LO_SHIFT (10)
  121. #define TMR_TCR_READRSTMODE_HI_MASK (1<<26)
  122. #define TMR_TCR_CAPEVTMODE_LO_MASK (3<<12)
  123. #define TMR_TCR_CAPMODE_LO_MASK (1<<11)
  124. #define TMR_TCR_READRSTMODE_LO_MASK (1<<10)
  125. #define TMR_TGCR_PLUSEN_SHIFT 4
  126. #define TMR_TGCR_PLUSEN_MASK (1<<4)
  127. #define TMR_INTCTLSTAT_EN_ALL_CLR_ALL 0x000F000F
  128. #define CSL_TMR_WDTCR_WDKEY_CMD1 (0x0000A5C6u)
  129. #define CSL_TMR_WDTCR_WDKEY_CMD2 (0x0000DA7Eu)
  130. #define CSL_TMR_ENAMODE_CONT_RELOAD 3
  131. /*----------------------------------------------*
  132. * macros *
  133. *----------------------------------------------*/
  134. /*convert local address to global address for DMA on multi-core DSP*/
  135. #define GLOBAL_ADDR(addr) ((Uint32)addr<0x1000000?\
  136. (Uint32)addr+(0x10000000+DNUM*0x1000000):\
  137. (Uint32)addr)
  138. /*according to default mapping, convert DDR3 logic address to
  139. 32-bit physical address (36-bit physical address right shift by 4)*/
  140. #define DDR_PHY_ADDR(addr) ((((Uint32)addr & 0x7FFFFFFF)>>4) | 0x80000000)
  141. /*max number in two numbers*/
  142. #define MAX(a, b) (a>b?a:b)
  143. /*min number in two numbers*/
  144. #define MIN(a, b) (a<b?a:b)
  145. extern CSL_XmcRegs * gpXMC_regs;
  146. extern CSL_CgemRegs * gpCGEM_regs;
  147. extern CSL_BootcfgRegs * gpBootCfgRegs;
  148. extern CSL_PllcRegs * gpPLLC_regs;
  149. extern CSL_PscRegs * gpPSC_regs;
  150. extern CSL_MsmcRegs * gpMSMC_regs;
  151. extern CSL_GpioRegs * gpGPIO_regs;
  152. extern CSL_CPINTCRegs* gpCIC0_regs;
  153. extern CSL_CPINTCRegs* gpCIC1_regs;
  154. /*The register pointer for the CIC routing events DSP core.
  155. By default, it is CIC0; but for core 4~7 of C6678, it is CIC1*/
  156. extern CSL_CPINTCRegs* gpCIC_regs;
  157. extern CSL_TpccRegs* gpEDMA_CC0_regs;
  158. extern CSL_TpccRegs* gpEDMA_CC1_regs;
  159. extern CSL_TpccRegs* gpEDMA_CC2_regs;
  160. extern CSL_TpccRegs* gpEDMA_CC_regs[];
  161. extern CSL_TptcRegs * gpEDMA_TC_0_0_regs;
  162. extern CSL_TptcRegs * gpEDMA_TC_0_1_regs;
  163. extern CSL_TptcRegs * gpEDMA_TC_1_0_regs;
  164. extern CSL_TptcRegs * gpEDMA_TC_1_1_regs;
  165. extern CSL_TptcRegs * gpEDMA_TC_1_2_regs;
  166. extern CSL_TptcRegs * gpEDMA_TC_1_3_regs;
  167. extern CSL_TptcRegs * gpEDMA_TC_2_0_regs;
  168. extern CSL_TptcRegs * gpEDMA_TC_2_1_regs;
  169. extern CSL_TptcRegs * gpEDMA_TC_2_2_regs;
  170. extern CSL_TptcRegs * gpEDMA_TC_2_3_regs;
  171. extern CSL_TptcRegs * gpEDMA_TC_regs[];
  172. extern CSL_TmrPlusRegs * gpTimer0Regs;
  173. extern CSL_TmrPlusRegs * gpTimer1Regs;
  174. extern CSL_TmrPlusRegs * gpTimer2Regs;
  175. extern CSL_TmrPlusRegs * gpTimer3Regs;
  176. extern CSL_TmrPlusRegs * gpTimer4Regs;
  177. extern CSL_TmrPlusRegs * gpTimer5Regs;
  178. extern CSL_TmrPlusRegs * gpTimer6Regs;
  179. extern CSL_TmrPlusRegs * gpTimer7Regs;
  180. extern CSL_TmrPlusRegs * gpTimer8Regs;
  181. extern CSL_TmrPlusRegs * gpTimerRegs[];
  182. /*MPU for peripherals registers and data space*/
  183. extern CSL_MpuRegs * gpMPU0_regs;
  184. extern CSL_MpuRegs * gpMPU1_regs;
  185. extern CSL_MpuRegs * gpMPU2_regs;
  186. extern CSL_MpuRegs * gpMPU_regs[];
  187. extern CSL_Emif4fRegs * gpDDR_regs;
  188. extern CSL_MpuRegs * gpMPU3_regs;
  189. extern unsigned int gDSP_Core_Speed_Hz; //DSP core clock speed in Hz
  190. /*DSP core PLL configuration
  191. DSP core will be configured to run at ref_clock_MHz*multiplier/divisor
  192. Input : float ref_clock_MHz
  193. unsigned int main_PLLM: 1~4096
  194. unsigned int multiplier: 1~64
  195. */
  196. extern void KeyStone_main_PLL_init (float ref_clock_MHz,
  197. unsigned int multiplier, unsigned int divisor);
  198. typedef struct {
  199. volatile Uint32 PLL_CTL0;
  200. volatile Uint32 PLL_CTL1;
  201. }PLL_ControlRegs;
  202. /*****************************************************************************
  203. Prototype : KeyStone_PLL_init
  204. Description : Config the PLL of ARM, PA and DDR
  205. target clock speed will be ref_clock_MHz/inputDivisor*multiplier/outputDivisor
  206. Input : unsigned int inputDivisor
  207. unsigned int multiplier
  208. unsigned int outputDivisor
  209. Return Value : 0 for success, other value for error
  210. *****************************************************************************/
  211. extern int KeyStone_PLL_init (PLL_ControlRegs * PLL_Regs, unsigned int inputDivisor,
  212. unsigned int multiplier, unsigned int outputDivisor);
  213. /*****************************************************************************
  214. Prototype : KeyStone_PASS_PLL_init
  215. Description : Config the PASS PLL
  216. target clock speed will be ref_clock_MHz/divisor*multiplier
  217. Input : float ref_clock_MHz
  218. unsigned int multiplier: 1~4096
  219. unsigned int divisor: 1~64
  220. *****************************************************************************/
  221. extern void KeyStone_PASS_PLL_init (float ref_clock_MHz,
  222. unsigned int multiplier, unsigned int divisor);
  223. /*****************************************************************************
  224. Prototype : KeyStone_DDR_PLL_init
  225. Description : Config the DDR PLL
  226. target clock speed will be ref_clock_MHz/divisor*multiplier
  227. Input : float ref_clock_MHz
  228. unsigned int multiplier: 1~4096
  229. unsigned int divisor: 1~64
  230. *****************************************************************************/
  231. extern void KeyStone_DDR_PLL_init (float ref_clock_MHz,
  232. unsigned int multiplier, unsigned int divisor);
  233. /*===============================TSC===================================*/
  234. extern unsigned int cycle_measure_overhead;
  235. /*get the delay between current and prvious TSC
  236. The delay must be less than 32 bit
  237. enable the TSC with "TSCL= 0;" before use this macro*/
  238. #define TSC_getDelay(startTSC) ((unsigned int)((0xFFFFFFFFl+TSCL)- (unsigned long long)startTSC)+ 1)
  239. #define TSC_count_cycle_from(startTSC) (TSC_getDelay(startTSC)- cycle_measure_overhead)
  240. /* Initialize Time stamp counter to measure cycles*/
  241. extern void TSC_init();
  242. /*delay in millisecond*/
  243. extern void TSC_delay_ms(Uint32 ms);
  244. /*delay in microsecond*/
  245. extern void TSC_delay_us(Uint32 us);
  246. /*===============================Timer=================================*/
  247. typedef enum
  248. {
  249. TIMER_ONE_SHOT_PULSE = 0, /*generate one shot pulse with timer*/
  250. TIMER_PERIODIC_PULSE, /*generate periodic pulse with timer*/
  251. TIMER_PERIODIC_CLOCK, /*generate periodic clock with timer*/
  252. /*generate periodic square wave with period reload feature, the difference
  253. between wave and clock is the duty cycle of clock is always 50%*/
  254. TIMER_PERIODIC_WAVE,
  255. TIMER_WATCH_DOG /*configure timer as watch dog*/
  256. }TTimerMode;
  257. typedef struct {
  258. int timer_num; /*select one timer*/
  259. TTimerMode timerMode; /*select function of the timer*/
  260. unsigned long long period; /*in the unit of DSP core clock/6*/
  261. unsigned long long reload_period; /*the reload value of period*/
  262. int pulseWidth; /*pulse width between 0~3*/
  263. }Timer64_Config;
  264. extern void Reset_Timer(int timer_num);
  265. /*Initailize a 64-bit timer*/
  266. extern void Timer64_Init(Timer64_Config * tmrCfg);
  267. typedef enum
  268. {
  269. WD_OUT_NONE = 0,
  270. WD_RESET_LOCAL = 2,
  271. WD_TRIGGER_NMI = 3,
  272. WD_TRIGGER_NMI_RESET_LOCAL = 4,
  273. WD_RESET_DEVICE = 5
  274. }TWatchdogOutputMode;
  275. /*write sequence of a A5C6h followed by a DA7Eh
  276. to services the watchdog timer.*/
  277. extern void Service_Watchdog(int timer_num);
  278. /*===============================PSC===================================*/
  279. extern Int32 KeyStone_enable_PSC_module (Uint32 pwrDmnNum, Uint32 moduleNum);
  280. extern Int32 KeyStone_disable_PSC_module (Uint32 pwrDmnNum, Uint32 moduleNum);
  281. extern Int32 KeyStone_disable_PSC_Power_Domain (Uint32 pwrDmnNum);
  282. /*============================EDMA=====================================*/
  283. #define NUM_EDMA_TC 10
  284. #define NUM_EDMA_CC 3
  285. //enum to indicate the EDMA CC number, and channel number
  286. typedef enum
  287. {
  288. EDMA_CC0_CH0 = ((0<<16)|0 ),
  289. EDMA_CC0_CH1 = ((0<<16)|1 ),
  290. EDMA_CC0_CH2 = ((0<<16)|2 ),
  291. EDMA_CC0_CH3 = ((0<<16)|3 ),
  292. EDMA_CC0_CH4 = ((0<<16)|4 ),
  293. EDMA_CC0_CH5 = ((0<<16)|5 ),
  294. EDMA_CC0_CH6 = ((0<<16)|6 ),
  295. EDMA_CC0_CH7 = ((0<<16)|7 ),
  296. EDMA_CC0_CH8 = ((0<<16)|8 ),
  297. EDMA_CC0_CH9 = ((0<<16)|9 ),
  298. EDMA_CC0_CH10= ((0<<16)|10),
  299. EDMA_CC0_CH11= ((0<<16)|11),
  300. EDMA_CC0_CH12= ((0<<16)|12),
  301. EDMA_CC0_CH13= ((0<<16)|13),
  302. EDMA_CC0_CH14= ((0<<16)|14),
  303. EDMA_CC0_CH15= ((0<<16)|15),
  304. EDMA_CC1_CH0 = ((1<<16)|0 ),
  305. EDMA_CC1_CH1 = ((1<<16)|1 ),
  306. EDMA_CC1_CH2 = ((1<<16)|2 ),
  307. EDMA_CC1_CH3 = ((1<<16)|3 ),
  308. EDMA_CC1_CH4 = ((1<<16)|4 ),
  309. EDMA_CC1_CH5 = ((1<<16)|5 ),
  310. EDMA_CC1_CH6 = ((1<<16)|6 ),
  311. EDMA_CC1_CH7 = ((1<<16)|7 ),
  312. EDMA_CC1_CH8 = ((1<<16)|8 ),
  313. EDMA_CC1_CH9 = ((1<<16)|9 ),
  314. EDMA_CC1_CH10= ((1<<16)|10),
  315. EDMA_CC1_CH11= ((1<<16)|11),
  316. EDMA_CC1_CH12= ((1<<16)|12),
  317. EDMA_CC1_CH13= ((1<<16)|13),
  318. EDMA_CC1_CH14= ((1<<16)|14),
  319. EDMA_CC1_CH15= ((1<<16)|15),
  320. EDMA_CC1_CH16= ((1<<16)|16),
  321. EDMA_CC1_CH17= ((1<<16)|17),
  322. EDMA_CC1_CH18= ((1<<16)|18),
  323. EDMA_CC1_CH19= ((1<<16)|19),
  324. EDMA_CC1_CH20= ((1<<16)|20),
  325. EDMA_CC1_CH21= ((1<<16)|21),
  326. EDMA_CC1_CH22= ((1<<16)|22),
  327. EDMA_CC1_CH23= ((1<<16)|23),
  328. EDMA_CC1_CH24= ((1<<16)|24),
  329. EDMA_CC1_CH25= ((1<<16)|25),
  330. EDMA_CC1_CH26= ((1<<16)|26),
  331. EDMA_CC1_CH27= ((1<<16)|27),
  332. EDMA_CC1_CH28= ((1<<16)|28),
  333. EDMA_CC1_CH29= ((1<<16)|29),
  334. EDMA_CC1_CH30= ((1<<16)|30),
  335. EDMA_CC1_CH31= ((1<<16)|31),
  336. EDMA_CC1_CH32= ((1<<16)|32),
  337. EDMA_CC1_CH33= ((1<<16)|33),
  338. EDMA_CC1_CH34= ((1<<16)|34),
  339. EDMA_CC1_CH35= ((1<<16)|35),
  340. EDMA_CC1_CH36= ((1<<16)|36),
  341. EDMA_CC1_CH37= ((1<<16)|37),
  342. EDMA_CC1_CH38= ((1<<16)|38),
  343. EDMA_CC1_CH39= ((1<<16)|39),
  344. EDMA_CC1_CH40= ((1<<16)|40),
  345. EDMA_CC1_CH41= ((1<<16)|41),
  346. EDMA_CC1_CH42= ((1<<16)|42),
  347. EDMA_CC1_CH43= ((1<<16)|43),
  348. EDMA_CC1_CH44= ((1<<16)|44),
  349. EDMA_CC1_CH45= ((1<<16)|45),
  350. EDMA_CC1_CH46= ((1<<16)|46),
  351. EDMA_CC1_CH47= ((1<<16)|47),
  352. EDMA_CC1_CH48= ((1<<16)|48),
  353. EDMA_CC1_CH49= ((1<<16)|49),
  354. EDMA_CC1_CH50= ((1<<16)|50),
  355. EDMA_CC1_CH51= ((1<<16)|51),
  356. EDMA_CC1_CH52= ((1<<16)|52),
  357. EDMA_CC1_CH53= ((1<<16)|53),
  358. EDMA_CC1_CH54= ((1<<16)|54),
  359. EDMA_CC1_CH55= ((1<<16)|55),
  360. EDMA_CC1_CH56= ((1<<16)|56),
  361. EDMA_CC1_CH57= ((1<<16)|57),
  362. EDMA_CC1_CH58= ((1<<16)|58),
  363. EDMA_CC1_CH59= ((1<<16)|59),
  364. EDMA_CC1_CH60= ((1<<16)|60),
  365. EDMA_CC1_CH61= ((1<<16)|61),
  366. EDMA_CC1_CH62= ((1<<16)|62),
  367. EDMA_CC1_CH63= ((1<<16)|63),
  368. EDMA_CC2_CH0 = ((2<<16)|0 ),
  369. EDMA_CC2_CH1 = ((2<<16)|1 ),
  370. EDMA_CC2_CH2 = ((2<<16)|2 ),
  371. EDMA_CC2_CH3 = ((2<<16)|3 ),
  372. EDMA_CC2_CH4 = ((2<<16)|4 ),
  373. EDMA_CC2_CH5 = ((2<<16)|5 ),
  374. EDMA_CC2_CH6 = ((2<<16)|6 ),
  375. EDMA_CC2_CH7 = ((2<<16)|7 ),
  376. EDMA_CC2_CH8 = ((2<<16)|8 ),
  377. EDMA_CC2_CH9 = ((2<<16)|9 ),
  378. EDMA_CC2_CH10= ((2<<16)|10),
  379. EDMA_CC2_CH11= ((2<<16)|11),
  380. EDMA_CC2_CH12= ((2<<16)|12),
  381. EDMA_CC2_CH13= ((2<<16)|13),
  382. EDMA_CC2_CH14= ((2<<16)|14),
  383. EDMA_CC2_CH15= ((2<<16)|15),
  384. EDMA_CC2_CH16= ((2<<16)|16),
  385. EDMA_CC2_CH17= ((2<<16)|17),
  386. EDMA_CC2_CH18= ((2<<16)|18),
  387. EDMA_CC2_CH19= ((2<<16)|19),
  388. EDMA_CC2_CH20= ((2<<16)|20),
  389. EDMA_CC2_CH21= ((2<<16)|21),
  390. EDMA_CC2_CH22= ((2<<16)|22),
  391. EDMA_CC2_CH23= ((2<<16)|23),
  392. EDMA_CC2_CH24= ((2<<16)|24),
  393. EDMA_CC2_CH25= ((2<<16)|25),
  394. EDMA_CC2_CH26= ((2<<16)|26),
  395. EDMA_CC2_CH27= ((2<<16)|27),
  396. EDMA_CC2_CH28= ((2<<16)|28),
  397. EDMA_CC2_CH29= ((2<<16)|29),
  398. EDMA_CC2_CH30= ((2<<16)|30),
  399. EDMA_CC2_CH31= ((2<<16)|31),
  400. EDMA_CC2_CH32= ((2<<16)|32),
  401. EDMA_CC2_CH33= ((2<<16)|33),
  402. EDMA_CC2_CH34= ((2<<16)|34),
  403. EDMA_CC2_CH35= ((2<<16)|35),
  404. EDMA_CC2_CH36= ((2<<16)|36),
  405. EDMA_CC2_CH37= ((2<<16)|37),
  406. EDMA_CC2_CH38= ((2<<16)|38),
  407. EDMA_CC2_CH39= ((2<<16)|39),
  408. EDMA_CC2_CH40= ((2<<16)|40),
  409. EDMA_CC2_CH41= ((2<<16)|41),
  410. EDMA_CC2_CH42= ((2<<16)|42),
  411. EDMA_CC2_CH43= ((2<<16)|43),
  412. EDMA_CC2_CH44= ((2<<16)|44),
  413. EDMA_CC2_CH45= ((2<<16)|45),
  414. EDMA_CC2_CH46= ((2<<16)|46),
  415. EDMA_CC2_CH47= ((2<<16)|47),
  416. EDMA_CC2_CH48= ((2<<16)|48),
  417. EDMA_CC2_CH49= ((2<<16)|49),
  418. EDMA_CC2_CH50= ((2<<16)|50),
  419. EDMA_CC2_CH51= ((2<<16)|51),
  420. EDMA_CC2_CH52= ((2<<16)|52),
  421. EDMA_CC2_CH53= ((2<<16)|53),
  422. EDMA_CC2_CH54= ((2<<16)|54),
  423. EDMA_CC2_CH55= ((2<<16)|55),
  424. EDMA_CC2_CH56= ((2<<16)|56),
  425. EDMA_CC2_CH57= ((2<<16)|57),
  426. EDMA_CC2_CH58= ((2<<16)|58),
  427. EDMA_CC2_CH59= ((2<<16)|59),
  428. EDMA_CC2_CH60= ((2<<16)|60),
  429. EDMA_CC2_CH61= ((2<<16)|61),
  430. EDMA_CC2_CH62= ((2<<16)|62),
  431. EDMA_CC2_CH63= ((2<<16)|63)
  432. }EDMA_CC_Channel_Num;
  433. typedef enum
  434. {
  435. DMA_NO_WAIT= 0, /*do not wait DMA complete*/
  436. DMA_WAIT /*wait DMA complete*/
  437. }DMA_Wait;
  438. /*a structure to define a EDMA channel*/
  439. typedef struct
  440. {
  441. Uint8 CC_num; //number of the CC for the channel
  442. Uint8 channel_num;
  443. Uint8 TC_num; //number of the TC used for the channel
  444. }EDMA_CC_Chanel_TC;
  445. /*setup uiChannel of an EDMA to use uiTC*/
  446. extern void EDMA_channel_TC_cfg (Uint32 uiCC,
  447. Uint32 uiChannel, Uint32 uiTC);
  448. extern void EDMA_TC_priority_cfg(Uint32 uiCC,
  449. Uint32 uiPri, Uint32 uiTC);
  450. extern void EDMA_init();
  451. extern void EDMA_event_enable(Uint32 uiCC, Uint32 uiChannel);
  452. extern void EDMA_event_disable(Uint32 uiCC, Uint32 uiChannel);
  453. extern void EDMA_interrupt_enable(Uint32 uiCC, Uint32 uiIntNum);
  454. extern void EDMA_interrupt_disable(Uint32 uiCC, Uint32 uiIntNum);
  455. /*wait the pending EDMA complete*/
  456. extern void EDMA_wait(EDMA_CC_Channel_Num CC_channel);
  457. extern void EDMA_copy(unsigned int srcAddr, unsigned int dstAddr,
  458. unsigned int byteCount, EDMA_CC_Channel_Num CC_channel, DMA_Wait wait);
  459. extern void EDMA_fill(unsigned int address, unsigned long long data,
  460. unsigned int byteCount, EDMA_CC_Channel_Num CC_channel);
  461. /*wait the pending IDMA complete*/
  462. extern void IDMA_wait();
  463. extern void IDMA_copy(unsigned int srcAddr, unsigned int dstAddr,
  464. unsigned int byteCount, DMA_Wait wait);
  465. /*======================memory protection==============================*/
  466. /*Memory Protection access permision mask*/
  467. #define MP_NONE 0
  468. #define MP_UX (1<<0)
  469. #define MP_UW (1<<1)
  470. #define MP_UR (1<<2)
  471. #define MP_SX (1<<3)
  472. #define MP_SW (1<<4)
  473. #define MP_SR (1<<5)
  474. /*for peripheral MPU only*/
  475. #define MP_NS (1<<7)
  476. #define MP_EMU (1<<6)
  477. /*Memory Protection mask for enabling AIDs*/
  478. #define MP_LOCAL (1<<8)
  479. #define MP_AIDX (1<<9)
  480. #define MP_AID0 (1<<10)
  481. #define MP_AID1 (1<<11)
  482. #define MP_AID2 (1<<12)
  483. #define MP_AID3 (1<<13)
  484. #define MP_AID4 (1<<14)
  485. #define MP_AID5 (1<<15)
  486. #define MP_AID0_5 0xFC00
  487. /*for peripheral MPU only*/
  488. #define MP_AID6 (1<<16)
  489. #define MP_AID7 (1<<17)
  490. #define MP_AID8 (1<<18)
  491. #define MP_AID9 (1<<19)
  492. #define MP_AID10 (1<<20)
  493. #define MP_AID11 (1<<21)
  494. #define MP_AID12 (1<<22)
  495. #define MP_AID13 (1<<23)
  496. #define MP_AID14 (1<<24)
  497. #define MP_AID15 (1<<25)
  498. #define MP_AID0_15 0x03FFFC00
  499. #define MP_AID0_7 0x0003FC00
  500. #define MP_AID8_15 0x03FC0000
  501. #define MPU_DENY_ALL (MP_AID0_15|MP_NONE)
  502. #define MAX_AID_NUM 16
  503. typedef enum
  504. {
  505. PRIVID_COREPAC0 = 0,
  506. PRIVID_COREPAC1 = 1,
  507. PRIVID_COREPAC2 = 2,
  508. PRIVID_COREPAC3 = 3,
  509. PRIVID_COREPAC4 = 4, /*C6678 ONLY*/
  510. PRIVID_COREPAC5 = 5, /*C6678 ONLY*/
  511. PRIVID_COREPAC6 = 6, /*C6678 ONLY*/
  512. PRIVID_COREPAC7 = 7, /*C6678 ONLY*/
  513. PRIVID_AIF2 = 4, /*TCI6614/8 ONLY*/
  514. PRIVID_TAC = 5, /*TCI6614/8 ONLY*/
  515. PRIVID_RAC = 6, /*TCI6614/8 ONLY*/
  516. PRIVID_ARM = 7, /*TCI6614 ONLY*/
  517. PRIVID_PCIE= 11,
  518. PRIVID_DEBUG_SS = 12,
  519. PRIVID_HYPERLINK_FIRST_ID = 13,
  520. PRIVID_HYPERLINK_SECOND_ID = 14,
  521. /*--------FOR C6678/4/2----------*/
  522. PRIVID_NETCP_C6678 = 8,
  523. PRIVID_SRIO_C6678 = 9,
  524. PRIVID_QMSS_C6678 = 10,
  525. PRIVID_TSIP = 15,
  526. /*--------FOR C6670----------*/
  527. PRIVID_FFTC_C6670 = 7,
  528. PRIVID_QMSS_SECOND_C6670 = 8,
  529. PRIVID_SRIO_C6670 = 9,
  530. PRIVID_QMSSPKTDMA_NETCP_C6670= 10,
  531. PRIVID_TE_SCR_3M_C6670 = 15, /*BCP, TCP3D_C, FFTC_C*/
  532. /*--------FOR TCI6614/2----------*/
  533. PRIVID_PASS_FFTC_BCPPKTDMA_SRIOPKTDMA_QMSSPKTDMA_TCI6614 = 8,
  534. PRIVID_SRIODIO_TCI6614 = 9,
  535. PRIVID_QMSS_SECOND_TCI6614 = 10,
  536. PRIVID_BCP_DIO_TCI6614 = 15,
  537. PRIVID_ERROR = 16
  538. }KeyStone_PrivID;
  539. extern unsigned int mem_prot_key[4];
  540. extern void lock_mem_prot_regs();
  541. extern void unlock_mem_prot_regs();
  542. /*setup the memory protection for local L1 memory*/
  543. extern void L1_MPPA_setup(volatile Uint32 MPPA_regs[], Uint32 MPPA[]);
  544. /*config "AccessPermisionMask" for L1P*/
  545. extern void L1P_memory_protection_cfg(Uint32 AccessPermisionMask);
  546. /*config "AccessPermisionMask" for L1D*/
  547. extern void L1D_memory_protection_cfg(Uint32 AccessPermisionMask);
  548. /*---- protect L1 as cache ----*/
  549. extern void L1_cache_protection();
  550. /*----setup the memory protection for local L2 memory----
  551. usage example:
  552. Uint32 MPPA[32]=
  553. {
  554. MP_LOCAL|MP_SX|MP_UX, //page 0 for local code only
  555. MP_LOCAL|MP_SR|MP_SW|MP_UR|MP_UW, //page 1 for local data only
  556. ......
  557. }
  558. ......
  559. LL2_MPPA_setup(MPPA);
  560. */
  561. extern void LL2_MPPA_setup(Uint32 MPPA[]);
  562. /*config "AccessPermisionMask" for local L2 memory section from
  563. "startAddress" with "byteCount" size*/
  564. extern void LL2_Memory_Protection_cfg(Uint32 startAddress,
  565. Uint32 byteCount, Uint32 AccessPermisionMask);
  566. /*map CorePac AID to PrivID:
  567. map_table[0] assign the PrivID for AID0,
  568. map_table[1] assign the PrivID for AID1
  569. ......
  570. map_table[5] assign the PrivID for AID5*/
  571. extern void KeyStone_CorePac_AID_map(Uint8 map_table[]);
  572. /* privilege ID remap to AID */
  573. extern void KeyStone_PrivID_Remap(int privID, int AID);
  574. /* Register Overlay Structure MPAX*/
  575. typedef struct
  576. {
  577. volatile Uint32 MPAXL;
  578. volatile Uint32 MPAXH;
  579. }MPAX_Regs;
  580. /*memory protection and address extension configuration*/
  581. typedef struct
  582. {
  583. Uint32 BADDR; /*32-bit virtual base address*/
  584. /*36-bit physical replace address, right shift by 4 to get the value here)*/
  585. Uint32 RADDR;
  586. Uint32 SegementSize; /*Segment size in byte, must be power of 2*/
  587. Uint32 AccessPermisionMask; /*Access types allowed in this address range.*/
  588. }MPAX_Config;
  589. /*configure one MPAX segment*/
  590. extern void KeyStone_MPAX_seg_setup(MPAX_Regs * MPAX_regs, Uint32 BADDR,
  591. Uint32 RADDR, Uint32 SegementSize, Uint32 AccessPermisionMask);
  592. /*configure multiple MPAX segments in XMC with a configuration table*/
  593. extern void KeyStone_XMC_MPAX_setup(MPAX_Config MPAX_cfg[],
  594. Uint32 firstSeg, Uint32 numSegs);
  595. /*configure multiple MPAX segments in SMS of MSMC with a configuration table*/
  596. extern void KeyStone_SMS_MPAX_setup(MPAX_Config MPAX_cfg[],
  597. Uint32 firstSeg, Uint32 numSegs, Uint32 PrivID);
  598. /*configure multiple MPAX segments in SES of MSMC with a configuration table*/
  599. extern void KeyStone_SES_MPAX_setup(MPAX_Config MPAX_cfg[],
  600. Uint32 firstSeg, Uint32 numSegs, Uint32 PrivID);
  601. /*Enable MSMC Memory protection error interrupt for PrivIDs indicated by "PRIVID_MASK"*/
  602. extern void KeyStone_MSMC_MP_interrupt_en(Uint32 PRIVID_MASK);
  603. /*==========Peripherals registers and internal data buffer MPU=============*/
  604. /*peripherals memory protection unit configuration*/
  605. typedef struct
  606. {
  607. Uint32 StartAddr; /*32-bit start address*/
  608. Uint32 EndAddr; /*32-bit end address*/
  609. Uint32 AccessPermisionMask; /*Access types allowed in this address range.*/
  610. }MPU_Range_Config;
  611. typedef struct
  612. {
  613. Uint32 StartAddr; /*32-bit start address*/
  614. Uint32 EndAddr; /*32-bit end address*/
  615. }MPU_Addr;
  616. extern CSL_MpuRegs * gpMPU_regs[];
  617. /*configure one range in peripheral MPU*/
  618. extern void KeyStone_MPU_range_setup(CSL_MpuProg_regionRegs *MPPA_regs,
  619. Uint32 uiStartAddress, Uint32 uiEndAddress, Uint32 AccessPermisionMask);
  620. /*peripherals MPU ranges configuration*/
  621. extern void KeyStone_MPU_setup(Uint32 uiMPU_num,
  622. MPU_Range_Config MPU_cfg[], Uint32 numRangeCfg);
  623. /*search the range which match a address and then modify
  624. the access permission of that range.*/
  625. extern void KeyStone_MPU_MPPA_modify(Uint32 uiMPU_num,
  626. Uint32 uiAddress, Uint32 AccessPermisionMask);
  627. /* enable one MPU interrupt */
  628. extern void KeyStone_MPU_interrupt_enable(Uint32 uiMPU_num);
  629. /* enable all MPU interrupts */
  630. extern void KeyStone_MPU_interrupts_enable();
  631. /*======================memory EDC=====================================*/
  632. /*Enable MSMC EDC and setup scrubbing cycle counter*/
  633. extern void KeyStone_SL2_EDC_enable(Uint32 scrubCnt);
  634. /*Enable MSMC EDC error interrupt*/
  635. extern void KeyStone_SL2_EDC_interrupt_en();
  636. /*enable LL2 EDC and scrub whole LL2*/
  637. extern void LL2_EDC_setup();
  638. /*---- L1P EDC setup ----*/
  639. extern void L1P_EDC_setup();
  640. /*scrub a block in LL2 for EDC.
  641. Number of bytes must be multiple of 128 bits and less than 64KB.
  642. This function should be called periodically, for example,
  643. if every 1 minute, call it with: LL2_EDC_scrub(1024);
  644. For 1MB LL2, the whole space will be scrubbed in 1024 minutes(17 hours)*/
  645. extern void LL2_EDC_scrub(Uint32 uiByteCnt);
  646. /*LL2 EDC exception/interrupt handler*/
  647. extern void LL2_EDC_handler(Bool bCorrected);
  648. /*SL2 EDC handler*/
  649. extern void KeyStone_SL2_EDC_handler();
  650. /*===============================Exception=============================*/
  651. typedef union {
  652. volatile Uint32 MPFSR; /*copy of MPFSR register for L1P, L1D or LL2*/
  653. volatile Uint32 SMPFR; /*copy of SMPFR register for MSMC*/
  654. volatile Uint32 MPU_FAULT_STATUS; /*copy of FAULT_STATUS register for MPU*/
  655. volatile Uint32 L1PEDSTAT; /*copy of L1PEDSTAT register*/
  656. volatile Uint32 L2EDSTAT; /*copy of L2EDSTAT register*/
  657. volatile Uint32 SMESTAT; /*copy of SMESTAT register for SL2 EDC*/
  658. volatile Uint32 DDR_IRQSTATUS_SYS; /*copy of IRQSTATUS_SYS for DDR ECC*/
  659. } Memory_Fault_Info;
  660. typedef struct{
  661. Uint32 fault_address;
  662. Memory_Fault_Info fault_status;
  663. volatile Uint32 BUS_ERROR; /*copy of MDMAERR or ECFGERR register*/
  664. } Memory_Exception_Info;
  665. typedef struct{
  666. volatile Uint32 EMR; /*copy of TPTC_EMR register*/
  667. volatile Uint32 EMRH; /*copy of TPTC_EMRH register*/
  668. volatile Uint32 QEMR; /*copy of TPTC_QEMR register*/
  669. volatile Uint32 CCERR; /*copy of TPTC_CCERR register*/
  670. } EDMA_CC_Exception_Info;
  671. typedef struct{
  672. volatile Uint32 ERRSTAT; /*copy of TPTC_ERRSTAT register*/
  673. volatile Uint32 ERRDET; /*copy of TPTC_ERRDET register*/
  674. } EDMA_TC_Exception_Info;
  675. typedef union{
  676. EDMA_CC_Exception_Info CC_info;
  677. EDMA_TC_Exception_Info TC_info;
  678. } EDMA_Exception_Info;
  679. typedef union {
  680. volatile Uint32 INTXSTAT; /*copy of INTXSTAT register*/
  681. Memory_Exception_Info memory;
  682. EDMA_Exception_Info edma;
  683. } Exception_Info;
  684. typedef struct{
  685. volatile Uint32 MEXPFLAG[4]; /*copy of the MEXPFLAG0..3 registers */
  686. volatile Uint32 CIC_STATUS[7]; /*copy of the CIC status registers */
  687. Exception_Info info;
  688. } External_Exception_Status;
  689. typedef union {
  690. volatile Uint32 IERR; /*copy of the IERR register */
  691. External_Exception_Status ext_sts;
  692. } Exception_Status;
  693. /**
  694. This structure is used to record exception information during
  695. exception processing.
  696. Please note, if multiple exceptions happens at the same time,
  697. only the last excpetion are record.
  698. Multiple unions are used in the structure to save space.
  699. * */
  700. typedef struct {
  701. volatile Uint32 B3; /*copy of B3 register (return pointer of caller) */
  702. volatile Uint32 A4; /*copy of the A4 register (first input parameter of caller)*/
  703. volatile Uint32 B4; /*copy of the B4 register (second input parameter of caller)*/
  704. volatile Uint32 B14; /*copy of the B14 register (data pointer)*/
  705. volatile Uint32 B15; /*copy of the B15 register (stack pointer)*/
  706. volatile Uint32 TSCL; /*copy of the TSCL register (time stamp)*/
  707. volatile Uint32 TSCH; /*copy of the TSCH register (time stamp)*/
  708. volatile Uint32 NTSR; /*copy of the NTSR register */
  709. volatile Uint32 NRP; /*copy of the NRP register */
  710. volatile Uint32 EFR; /*copy of the EFR register */
  711. volatile Uint32 ITSR; /*copy of the ITSR register */
  712. volatile Uint32 IRP; /*copy of the IRP register */
  713. Exception_Status status;
  714. } Exception_Record;
  715. //data structure to save exception info
  716. extern Exception_Record exception_record;
  717. /*some exception events routed from CIC to INTC and then to exception moduel,
  718. all these events are routed to one input of INTC*/
  719. extern Uint32 guwIntcCICExcEvtIdx; /*INTC event number mapping to CIC exception events*/
  720. extern Uint32 gCIC_EXC_out_num; //CIC output event number
  721. /* Config the system error and exception to generate the NMI.
  722. If bGlobalExceptionMaster==TRUE, the global exception events
  723. from CIC will be routed to exception model of this CPU core.
  724. Call this function as last step after all configuration/initialization complete*/
  725. extern void KeyStone_Exception_cfg(Bool bGlobalExceptionMaster);
  726. extern void Bus_error_handler(unsigned int ERR_REG);
  727. /*===============================Cache=================================*/
  728. /*enable workaround for the "L2 Cache Corruption During Block and Global Coherence Operations
  729. Issue" described in errata of some devices.
  730. Check your device errata to see if this is needed*/
  731. #define CACHE_DISABLE_INT 1
  732. static inline void InvalidCache(void * blockPtr, Uint32 byteCnt)
  733. {
  734. #if CACHE_DISABLE_INT
  735. /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations
  736. Issue" described in errata of some devices*/
  737. Uint32 uiOldGIE= _disable_interrupts();
  738. #endif
  739. if(byteCnt>0xFFFF*4)
  740. byteCnt= 0xFFFF*4;
  741. if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2
  742. {
  743. CACHE_invL1d((void *)blockPtr, byteCnt, CACHE_WAIT);
  744. CSL_XMC_invalidatePrefetchBuffer();
  745. }
  746. else if((Uint32)blockPtr>=0x10000000) //DDR or other cores
  747. {
  748. CACHE_invL2((void *)blockPtr, byteCnt, CACHE_WAIT);
  749. CSL_XMC_invalidatePrefetchBuffer();
  750. }
  751. _mfence();
  752. _mfence();
  753. #if CACHE_DISABLE_INT
  754. /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations
  755. Issue" described in errata of some devices*/
  756. asm(" nop 8");
  757. asm(" nop 8");
  758. _restore_interrupts(uiOldGIE); //restore interrupt
  759. #endif
  760. }
  761. static inline void WritebackCache(void * blockPtr, Uint32 byteCnt)
  762. {
  763. if(byteCnt>0xFFFF*4)
  764. byteCnt= 0xFFFF*4;
  765. if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2
  766. {
  767. CACHE_wbL1d((void *)blockPtr, byteCnt, CACHE_WAIT);
  768. }
  769. else if((Uint32)blockPtr>=0x10000000) //DDR or other cores
  770. {
  771. CACHE_wbL2((void *)blockPtr, byteCnt, CACHE_WAIT);
  772. }
  773. _mfence();
  774. _mfence();
  775. }
  776. static inline void WritebackAllCache(void * blockPtr)
  777. {
  778. if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2
  779. {
  780. CACHE_wbAllL1d(CACHE_WAIT);;
  781. }
  782. else if((Uint32)blockPtr>=0x10000000) //DDR or other cores
  783. {
  784. CACHE_wbAllL2(CACHE_WAIT);
  785. }
  786. _mfence();
  787. _mfence();
  788. }
  789. static inline void WritebackInvalidCache(void * blockPtr, Uint32 byteCnt)
  790. {
  791. #if CACHE_DISABLE_INT
  792. /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations
  793. Issue" described in errata of some devices*/
  794. Uint32 uiOldGIE= _disable_interrupts();
  795. #endif
  796. if(byteCnt>0xFFFF*4)
  797. byteCnt= 0xFFFF*4;
  798. if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2
  799. {
  800. CACHE_wbInvL1d((void *)blockPtr, byteCnt, CACHE_WAIT);
  801. CSL_XMC_invalidatePrefetchBuffer();
  802. }
  803. else if((Uint32)blockPtr>=0x10000000) //DDR or other cores
  804. {
  805. CACHE_wbInvL2((void *)blockPtr, byteCnt, CACHE_WAIT);
  806. CSL_XMC_invalidatePrefetchBuffer();
  807. }
  808. _mfence();
  809. _mfence();
  810. #if CACHE_DISABLE_INT
  811. /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations
  812. Issue" described in errata of some devices*/
  813. asm(" nop 8");
  814. asm(" nop 8");
  815. _restore_interrupts(uiOldGIE); //restore interrupt
  816. #endif
  817. }
  818. static inline void WritebackInvalidAllCache(void * blockPtr)
  819. {
  820. #if CACHE_DISABLE_INT
  821. /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations
  822. Issue" described in errata of some devices*/
  823. Uint32 uiOldGIE= _disable_interrupts();
  824. #endif
  825. if((Uint32)blockPtr>=0x0C000000&&(Uint32)blockPtr<0x0D000000) //SL2
  826. {
  827. CACHE_wbInvAllL1d(CACHE_WAIT);//CACHE_invL1d((void *)blockPtr, byteCnt, CACHE_WAIT);
  828. CSL_XMC_invalidatePrefetchBuffer();
  829. }
  830. else if((Uint32)blockPtr>=0x10000000) //DDR or other cores
  831. {
  832. //CACHE_invL2((void *)blockPtr, byteCnt, CACHE_WAIT);
  833. CACHE_wbInvAllL2(CACHE_WAIT);
  834. CSL_XMC_invalidatePrefetchBuffer();
  835. }
  836. _mfence();
  837. _mfence();
  838. #if CACHE_DISABLE_INT
  839. /*workaround for the "L2 Cache Corruption During Block and Global Coherence Operations
  840. Issue" described in errata of some devices*/
  841. asm(" nop 8");
  842. asm(" nop 8");
  843. _restore_interrupts(uiOldGIE); //restore interrupt
  844. #endif
  845. }
  846. static inline unsigned int SWAP_ENDIAN(unsigned int byte_index)
  847. {
  848. #ifdef _BIG_ENDIAN
  849. return ((byte_index&0xFFFFFFFC)+(3-byte_index&3));
  850. #else
  851. return byte_index;
  852. #endif
  853. }
  854. static inline void KeyStone_CIC_clear_system_event(CSL_CPINTCRegs* cpIntcRegs,
  855. int input_event_num)
  856. {
  857. volatile Uint32 dummy_value;
  858. /*clear input interrupts events*/
  859. cpIntcRegs->STATUS_CLR_INDEX_REG= input_event_num;
  860. /*dummy read to make sure the previous write data land into the register*/
  861. dummy_value= cpIntcRegs->STATUS_CLR_INDEX_REG;
  862. }
  863. static inline void KeyStone_CIC_disable_host_int(CSL_CPINTCRegs* cpIntcRegs,
  864. int host_int_num)
  865. {
  866. volatile Uint32 dummy_value;
  867. /* Disable the host interrupt */
  868. cpIntcRegs->HINT_ENABLE_CLR_INDEX_REG = host_int_num;
  869. /*dummy read to make sure the previous write data land into the register*/
  870. dummy_value= cpIntcRegs->HINT_ENABLE_CLR_INDEX_REG;
  871. }
  872. static inline void KeyStone_CIC_enable_host_int(CSL_CPINTCRegs* cpIntcRegs,
  873. int host_int_num)
  874. {
  875. volatile Uint32 dummy_value;
  876. /* Enable the host interrupt */
  877. cpIntcRegs->HINT_ENABLE_SET_INDEX_REG = host_int_num;
  878. /*dummy read to make sure the previous write data land into the register*/
  879. dummy_value= cpIntcRegs->HINT_ENABLE_SET_INDEX_REG;
  880. }
  881. static inline void KeyStone_CIC_event_map(CSL_CPINTCRegs* cpIntcRegs,
  882. int input_event_num, int out_num)
  883. {
  884. /*Map input event to output*/
  885. cpIntcRegs->CH_MAP[SWAP_ENDIAN(input_event_num)]= out_num;
  886. /*clear input interrupts events*/
  887. cpIntcRegs->STATUS_CLR_INDEX_REG= input_event_num;
  888. /*enable input interrupts events*/
  889. cpIntcRegs->ENABLE_SET_INDEX_REG= input_event_num;
  890. /*enable output*/
  891. cpIntcRegs->HINT_ENABLE_SET_INDEX_REG= out_num;
  892. }
  893. typedef enum
  894. {
  895. DUAL_NYQUIST_EVM = 0,
  896. C6670_EVM,
  897. C6678_EVM,
  898. TCI6614_EVM,
  899. C6657_EVM,
  900. UNKNOWN
  901. }TDSP_Board_Type;
  902. extern TDSP_Board_Type gDSP_board_type;
  903. static inline TDSP_Board_Type KeyStone_Get_dsp_board_type()
  904. {
  905. Uint32 deviceID= gpBootCfgRegs->DEVICE_ID_REG0&0x0FFFFFFF;
  906. gDSP_board_type= UNKNOWN;
  907. if(0x0009D02F == deviceID)
  908. gDSP_board_type= DUAL_NYQUIST_EVM;
  909. if(0x0B94102F == deviceID)
  910. {
  911. gDSP_board_type= C6670_EVM;
  912. //DSP_Board_Type= DUAL_NYQUIST_EVM;
  913. }
  914. if(0x0009E02F == deviceID)
  915. gDSP_board_type= C6678_EVM;
  916. if(0x0B96202F == deviceID)
  917. gDSP_board_type= TCI6614_EVM;
  918. if(0x0B97A02F == deviceID)
  919. gDSP_board_type= C6657_EVM;
  920. return gDSP_board_type;
  921. }
  922. static inline Uint32 KeyStone_Get_DSP_Number()
  923. {
  924. TDSP_Board_Type DSP_Board_Type= KeyStone_Get_dsp_board_type();
  925. if(DUAL_NYQUIST_EVM==DSP_Board_Type)
  926. {
  927. /*Nyquist EVM use boot configure pin 4 and 5 to identify DSPs*/
  928. return (( gpBootCfgRegs->BOOT_REG0 >> (3+1) ) & 0x03);
  929. }
  930. /*if use DNUM to differentiate DSPs for two DSPs test,
  931. the program must be run on core 0 of DSP 0 and core 1 of DSP1*/
  932. return DNUM;
  933. }
  934. /*clear all interrupt flag/status, setup ISTP to begining of LL2*/
  935. extern void CPU_interrupt_init();
  936. /*enable interrupt to CPU: IER |= uiIER_en_mask; GIE=1*/
  937. extern void CPU_interrupt_enable(Uint32 uiIER_en_mask);
  938. //get device speed grade from the EFUSE register
  939. extern void KeyStone_get_device_speed_grade();
  940. /*Get device information including device type, boot mode, endian information,
  941. speed grade, required voltage...*/
  942. extern void KeyStone_get_device_info();
  943. /*common initialization for internal modules in K2 device.
  944. enable memory protection interrupts, EDC for MSMC RAM*/
  945. extern void KeyStone_common_device_init();
  946. /* enable TSC, EDC for local RAM; clear cache; protect L1 as cache */
  947. extern void KeyStone_common_CPU_init();
  948. #endif