plat_startup.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Copyright (C) 2012, Freescale Semiconductor, Inc. All Rights Reserved
  3. * THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
  4. * BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
  5. * Freescale Semiconductor, Inc.
  6. */
  7. /*!
  8. * @file plat_startup.inc
  9. * @brief This file contains start-up DCD.
  10. *
  11. * @ingroup diag_init
  12. */
  13. /* *INDENT-OFF* */
  14. #ifndef _PLAT_STARTUP_H_
  15. #define _PLAT_STARTUP_H_
  16. #include "soc_memory_map.h"
  17. #define IMAGE_ENTRY_ADDR 0x80000000
  18. #define IMAGE_SIZE 4*1024*1024
  19. #define L2CC_REG1_CTRL 0x00A02100
  20. #define L2CC_INV_REG 0x00A0277C
  21. #define L2CC_TAG_RAM_CTRL 0x00A02108
  22. #define L2CC_DAT_RAM_CTRL 0x00A0210C
  23. #define L2CC_PREFETCH_CTRL 0x00A02F60
  24. #define ROM_API_TABLE_BASE_ADDR (0x00000180)
  25. #define ROM_API_HWCNFG_SETUP_OFFSET (0x08)
  26. #define PLATFORM_INIT plat_dcd_startup
  27. #define ASM_REG32_WR(i, addr, val) \
  28. ldr r0, =addr; \
  29. ldr r1, =val; \
  30. str r1, [r0];
  31. // image starts at 0x00907000
  32. //flash header & DCD @ 0x400
  33. .macro plat_dcd_startup
  34. b startup
  35. .org 0x400
  36. /* First IVT to copy the plugin that initializes the system into OCRAM */
  37. ivt_header: .long 0x402000D1 //Tag=0xD1, Len=0x0020, Ver=0x40
  38. app_code_jump_v: .long 0x00907458 // Plugin entry point, address after the second IVT table
  39. reserv1: .long 0x0
  40. dcd_ptr: .long 0x0
  41. boot_data_ptr: .long 0x00907420
  42. self_ptr: .long 0x00907400
  43. app_code_csf: .long 0x0 // reserve 4K for csf
  44. reserv2: .long 0x0
  45. boot_data: .long 0x00907000
  46. image_len: .long 16*1024
  47. plugin: .long 0x1 // Enable plugin flag
  48. /* Second IVT to give entry point into the bootloader copied to DDR */
  49. ivt2_header: .long 0x402000D1 //Tag=0xD1, Len=0x0020, Ver=0x40
  50. app2_code_jump_v: .long startup // Entry point for the bootloader
  51. reserv3: .long 0x0
  52. dcd2_ptr: .long 0x0
  53. boot_data2_ptr: .long boot_data2
  54. self_ptr2: .long ivt2_header
  55. app_code_csf2: .long 0x0 // reserve 4K for csf
  56. reserv4: .long 0x0
  57. boot_data2: .long IMAGE_ENTRY_ADDR
  58. image_len2: .long IMAGE_SIZE
  59. plugin2: .long 0x0
  60. // Here starts the plugin code
  61. plugin_start:
  62. // Save the return address and the function arguments
  63. push {r0-r4, lr}
  64. #if defined(EVB) || defined(SABRE_LITE)
  65. ASM_REG32_WR(0, 0x020bc000, 0x30)
  66. ASM_REG32_WR(0, 0x020c4068, 0xffffffff)
  67. ASM_REG32_WR(0, 0x020c406c, 0xffffffff)
  68. ASM_REG32_WR(0, 0x020c4070, 0xffffffff)
  69. ASM_REG32_WR(0, 0x020c4074, 0xffffffff)
  70. ASM_REG32_WR(0, 0x020c4078, 0xffffffff)
  71. ASM_REG32_WR(0, 0x020c407c, 0xffffffff)
  72. ASM_REG32_WR(0, 0x020c4080, 0xffffffff)
  73. ASM_REG32_WR(0, 0x020c4084, 0xffffffff)
  74. ASM_REG32_WR(0, 0x020E04B4, 0x000C0000)
  75. ASM_REG32_WR(0, 0x020E04AC, 0x00000000)
  76. ASM_REG32_WR(0, 0x020E027C, 0x00000030)
  77. ASM_REG32_WR(0, 0x020E0250, 0x00000030)
  78. ASM_REG32_WR(0, 0x020E024C, 0x00000030)
  79. ASM_REG32_WR(0, 0x020E0490, 0x00000030)
  80. ASM_REG32_WR(0, 0x020E0288, 0x00000030)
  81. ASM_REG32_WR(0, 0x020E0270, 0x00000000)
  82. ASM_REG32_WR(0, 0x020E0260, 0x00000030)
  83. ASM_REG32_WR(0, 0x020E0264, 0x00000030)
  84. ASM_REG32_WR(0, 0x020E04A0, 0x00000030)
  85. ASM_REG32_WR(0, 0x020E0494, 0x00020000)
  86. ASM_REG32_WR(0, 0x020E0280, 0x00000030)
  87. ASM_REG32_WR(0, 0x020E0284, 0x00000030)
  88. ASM_REG32_WR(0, 0x020E04B0, 0x00020000)
  89. ASM_REG32_WR(0, 0x020E0498, 0x00000030)
  90. ASM_REG32_WR(0, 0x020E04A4, 0x00000030)
  91. ASM_REG32_WR(0, 0x020E0244, 0x00000030)
  92. ASM_REG32_WR(0, 0x020E0248, 0x00000030)
  93. ASM_REG32_WR(0, 0x021B001C, 0x00008000)
  94. ASM_REG32_WR(0, 0x021B0800, 0xA1390003)
  95. ASM_REG32_WR(0, 0x021B080C, 0x001b001E)
  96. ASM_REG32_WR(0, 0x021B083C, 0x42400240)
  97. ASM_REG32_WR(0, 0x021B0848, 0x00003A3E)
  98. ASM_REG32_WR(0, 0x021B0850, 0x00003230)
  99. ASM_REG32_WR(0, 0x021B081C, 0x33333333)
  100. ASM_REG32_WR(0, 0x021B0820, 0x33333333)
  101. ASM_REG32_WR(0, 0x021B082C, 0xf3333333)
  102. ASM_REG32_WR(0, 0x021B0830, 0xf3333333)
  103. ASM_REG32_WR(0, 0x021B08C0, 0x00922012)
  104. ASM_REG32_WR(0, 0x021B08b8, 0x00000800)
  105. ASM_REG32_WR(0, 0x021B0004, 0x0002002D)
  106. ASM_REG32_WR(0, 0x021B0008, 0x1B333000)
  107. ASM_REG32_WR(0, 0x021B000C, 0x676B54B3)
  108. ASM_REG32_WR(0, 0x021B0010, 0xB68E0A83)
  109. ASM_REG32_WR(0, 0x021B0014, 0x01FF00DB)
  110. ASM_REG32_WR(0, 0x021B0018, 0x00211740)
  111. ASM_REG32_WR(0, 0x021B001C, 0x00008000)
  112. ASM_REG32_WR(0, 0x021B002C, 0x000026D2)
  113. ASM_REG32_WR(0, 0x021B0030, 0x006C1023)
  114. ASM_REG32_WR(0, 0x021B0040, 0x0000005F)
  115. ASM_REG32_WR(0, 0x021B0000, 0x85180000)
  116. ASM_REG32_WR(0, 0x021B001C, 0x02008032)
  117. ASM_REG32_WR(0, 0x021B001C, 0x00008033)
  118. ASM_REG32_WR(0, 0x021B001C, 0x00048031)
  119. ASM_REG32_WR(0, 0x021B001C, 0x15208030)
  120. ASM_REG32_WR(0, 0x021B001C, 0x04008040)
  121. ASM_REG32_WR(0, 0x021B0020, 0x00000800)
  122. ASM_REG32_WR(0, 0x021B0818, 0x00000227)
  123. ASM_REG32_WR(0, 0x021B0004, 0x0002552D)
  124. ASM_REG32_WR(0, 0x021B0404, 0x00011006)
  125. ASM_REG32_WR(0, 0x021B001C, 0x00000000)
  126. #else
  127. #error "Please add the DDR initialization code for this board, unless you can make sure the existing code can be shared."
  128. #endif
  129. read_obds:
  130. /********************
  131. The following is to fill in those arguments for this ROM function
  132. pu_irom_hwcnfg_setup(void **start, size_t *bytes, const void *boot_data)
  133. This function is used to copy data from the storage media into DDR.
  134. start - Initial (possibly partial) image load address on entry. Final image load address on exit.
  135. bytes - Initial (possibly partial) image size on entry. Final image size on exit.
  136. boot_data - Initial @ref ivt Boot Data load address.
  137. */
  138. adr r0, DDR_DEST_ADDR
  139. adr r1, COPY_SIZE
  140. adr r2, BOOT_DATA
  141. /*
  142. * check the _pu_irom_api_table for the address
  143. */
  144. before_calling_rom___pu_irom_hwcnfg_setup:
  145. //mov r4, #0x2000
  146. //add r4, r4, #0xed
  147. //blx r4 // This address might change in future ROM versions.
  148. ldr r3, =ROM_API_TABLE_BASE_ADDR /* Address of rom_api_table is 0xc0 */
  149. ldr r4, [r3, #ROM_API_HWCNFG_SETUP_OFFSET] /* hwcnfg setup function address is 3rd entry in the api table address 0xc8 */
  150. blx r4 /* call into ROM function */
  151. after_calling_rom___pu_irom_hwcnfg_setup:
  152. /* SDRAM has been setup, binary image has been copied to SDRAM */
  153. b startup // Jump to our code directly
  154. DDR_DEST_ADDR: .word IMAGE_ENTRY_ADDR
  155. COPY_SIZE: .word IMAGE_SIZE
  156. BOOT_DATA: .word IMAGE_ENTRY_ADDR
  157. .word IMAGE_SIZE //real data to be copied by the pu_irom_hwcnfg_setup()
  158. .word 0
  159. .endm //plat_dcd_startup
  160. // #define PLATFORM_ASM_STARTUP platform_asm_startup
  161. .macro platform_asm_startup
  162. config_L2_cache:
  163. disable_L2_cache
  164. init_aips_start:
  165. init_aips
  166. init_reloc_start:
  167. /* Check if need to copy image to Redboot ROM space */
  168. ldr r0, =0xFFFFF000
  169. and r0, r0, pc
  170. ldr r1, =IMAGE_ENTRY_ADDR
  171. cmp r0, r1
  172. beq skip_SDRAM_copy
  173. add r2, r0, #IMAGE_SIZE
  174. 1: ldmia r0!, {r3-r10}
  175. stmia r1!, {r3-r10}
  176. cmp r0, r2
  177. ble 1b
  178. /* Jump to SDRAM */
  179. ldr r1, =0xFFFF
  180. and r0, pc, r1 /* offset of pc */
  181. ldr r1, =(IMAGE_ENTRY_ADDR + 0x8)
  182. add pc, r0, r1
  183. nop
  184. nop
  185. nop
  186. nop
  187. skip_SDRAM_copy:
  188. .endm //platform_asm_startup
  189. /* AIPS setup - Only setup MPROTx registers. The PACR default values are good.*/
  190. .macro init_aips
  191. /*
  192. * Set all MPROTx to be non-bufferable, trusted for R/W,
  193. * not forced to user-mode.
  194. */
  195. ldr r0, =AIPS_TZ1_BASE_ADDR
  196. ldr r1, =0x77777777
  197. str r1, [r0, #0x00]
  198. str r1, [r0, #0x04]
  199. ldr r0, =AIPS_TZ2_BASE_ADDR
  200. str r1, [r0, #0x00]
  201. str r1, [r0, #0x04]
  202. .endm /* init_aips */
  203. .macro clean_L1_DCache
  204. mov r0, #0
  205. mcr p15, 2, r0, c0, c0, 0 // select DCache
  206. mrc p15, 1, r0, c0, c0, 0 // read CCSIDR
  207. mov r0, r0, ASR #13
  208. ldr r3, =0x3FFF
  209. and r0, r0, r3
  210. cmp r0, #0x7F
  211. moveq r6, #0x1000 // 4KB * 4way = 16KB
  212. beq clean_and_invalidate_L1_dcache
  213. cmp r0, #0xFF
  214. moveq r6, #0x2000 // 32KB
  215. beq clean_and_invalidate_L1_dcache
  216. movne r6, #0x4000 // 64KB
  217. clean_and_invalidate_L1_dcache:
  218. mov r2, #0x00000000
  219. mov r3, #0x40000000
  220. mov r4, #0x80000000
  221. mov r5, #0xC0000000
  222. clean_and_invalidate_L1_dcache_byset:
  223. mcr p15, 0, r2, c7, c14, 2 //clean and invalidate dcache on way 0
  224. mcr p15, 0, r3, c7, c14, 2 //clean and invalidate dcache on way 1
  225. mcr p15, 0, r4, c7, c14, 2 //clean and invalidate dcache on way 2
  226. mcr p15, 0, r5, c7, c14, 2 //clean and invalidate dcache on way 3
  227. add r2, r2, #0x20
  228. add r3, r3, #0x20
  229. add r4, r4, #0x20
  230. add r5, r5, #0x20
  231. cmp r2, r6
  232. bne clean_and_invalidate_L1_dcache_byset
  233. .endm
  234. .macro enable_L1_cache
  235. mov r0, #0
  236. mcr p15, 0, r0, c7, c5, 6 // invalidate BTAC
  237. mcr p15, 0, r0, c7, c5, 0 // invalidate icache
  238. mov r0, #0
  239. mcr p15, 2, r0, c0, c0, 0 // select DCache
  240. mrc p15, 1, r0, c0, c0, 0 // read CCSIDR
  241. mov r0, r0, ASR #13
  242. ldr r3, =0x3FFF
  243. and r0, r0, r3
  244. cmp r0, #0x7F
  245. moveq r6, #0x1000 // 4KB * 4way = 16KB
  246. beq invalidate_dcache
  247. cmp r0, #0xFF
  248. moveq r6, #0x2000 // 32KB
  249. beq invalidate_dcache
  250. movne r6, #0x4000 // 64KB
  251. invalidate_dcache:
  252. mov r2, #0x00000000
  253. mov r3, #0x40000000
  254. mov r4, #0x80000000
  255. mov r5, #0xC0000000
  256. invalidate_dcache_byset:
  257. mcr p15, 0, r2, c7, c6, 2 //invalidate dcache on way 0
  258. mcr p15, 0, r3, c7, c6, 2 //invalidate dcache on way 1
  259. mcr p15, 0, r4, c7, c6, 2 //invalidate dcache on way 2
  260. mcr p15, 0, r5, c7, c6, 2 //invalidate dcache on way 3
  261. add r2, r2, #0x20
  262. add r3, r3, #0x20
  263. add r4, r4, #0x20
  264. add r5, r5, #0x20
  265. cmp r2, r6
  266. bne invalidate_dcache_byset
  267. ldr r0, =0x00930000 //where to store the TLB page table
  268. mcr p15, 0, r0, c2, c0, 0
  269. ldr r0, =0x55555555
  270. mcr p15, 0, r0, c3, c0, 0
  271. mrc p15, 0, r0, c1, c0, 0 // read CP15 register 1 into r0
  272. orr r0, r0, #(0x1<<12) // enable I Cache
  273. orr r0, r0, #(0x1<<11) // turn on BP
  274. orr r0, r0, #(0x1<<2) // enable D Cache
  275. /*Attention: If you want to enable MMU, must set up the TLB tables first!!*/
  276. bic r0, r0, #(0x1<<0) // disable MMU
  277. mcr p15, 0, r0, c1, c0, 0 // write CP15 register 1
  278. .endm
  279. .macro disable_L1_cache
  280. mrc p15, 0, r0, c1, c0, 0
  281. bic r0, r0, #(0x1<<12)
  282. bic r0, r0, #(0x1<<11)
  283. bic r0, r0, #(0x1<<2)
  284. bic r0, r0, #(0x1<<0)
  285. mcr p15, 0, r0, c1, c0, 0
  286. .endm
  287. .macro disable_L1_DCache
  288. mrc p15, 0, r0, c1, c0, 0
  289. ands r0, r0, #(0x1<<11) //check if L1 DCache has been disabled
  290. beq disable_L1_DCache_done
  291. bic r0, r0, #(0x1<<11)
  292. bic r0, r0, #(0x1<<0) //disable MMU
  293. mcr p15, 0, r0, c1, c0, 0
  294. clean_L1_DCache
  295. disable_L1_DCache_done:
  296. .endm
  297. .macro enable_L2_cache
  298. /* set latency: 4x cycles read, 2x cycles write, (3x cycles setup)*/
  299. ldr r1,= L2CC_TAG_RAM_CTRL
  300. ldr r0,=0x0132
  301. str r0,[r1]
  302. ldr r1, =L2CC_DAT_RAM_CTRL
  303. ldr r0,=0x0132
  304. str r0,[r1]
  305. /* invalidate L2Cache by way */
  306. ldr r1, =L2CC_INV_REG
  307. ldr r0, =0xffff
  308. str r0,[r1]
  309. l2cc_inv_done:
  310. ldr r2,[r1]
  311. mov r0,#0x0
  312. cmp r2,r0
  313. bne l2cc_inv_done
  314. /* turn on l2 cache */
  315. ldr r1, =L2CC_REG1_CTRL
  316. mov r0,#1
  317. str r0,[r1]
  318. .endm
  319. .macro disable_L2_cache
  320. ldr r1, =L2CC_REG1_CTRL
  321. mov r0,#0
  322. str r0,[r1]
  323. .endm
  324. #endif //_PLAT_STARTUP_H_