ls1088a.S 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817
  1. /*
  2. * Copyright 2022 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. .section .text, "ax"
  7. #include <asm_macros.S>
  8. #include <lib/psci/psci.h>
  9. #include <nxp_timer.h>
  10. #include <plat_gic.h>
  11. #include "bl31_data.h"
  12. #include "plat_psci.h"
  13. #include "platform_def.h"
  14. /*
  15. * the BASE address for these offsets is AUX_01_DATA in the
  16. * bootcore's psci data region
  17. */
  18. #define DEVDISR2_MASK_OFFSET 0x0 /* references AUX_01_DATA */
  19. #define DEVDISR5_MASK_OFFSET 0x8 /* references AUX_02_DATA */
  20. /*
  21. * the BASE address for these offsets is AUX_04_DATA in the
  22. * bootcore's psci data region
  23. */
  24. #define GICD_BASE_ADDR_OFFSET 0x0 /* references AUX_04_DATA */
  25. #define GICC_BASE_ADDR_OFFSET 0x8 /* references AUX_05_DATA */
  26. #define IPSTPACK_RETRY_CNT 0x10000
  27. #define DDR_SLEEP_RETRY_CNT 0x10000
  28. #define CPUACTLR_EL1 S3_1_C15_C2_0
  29. #define DDR_SDRAM_CFG_2_FRCSR 0x80000000
  30. #define DDR_SDRAM_CFG_2_OFFSET 0x114
  31. #define DDR_TIMING_CFG_4_OFFSET 0x160
  32. #define DDR_CNTRL_BASE_ADDR 0x01080000
  33. #define DLL_LOCK_MASK 0x3
  34. #define DLL_LOCK_VALUE 0x2
  35. #define ERROR_DDR_SLEEP -1
  36. #define ERROR_DDR_WAKE -2
  37. #define ERROR_NO_QUIESCE -3
  38. #define CORE_RESTARTABLE 0
  39. #define CORE_NOT_RESTARTABLE 1
  40. .global soc_init_lowlevel
  41. .global soc_init_percpu
  42. .global _soc_core_release
  43. .global _soc_core_restart
  44. .global _soc_ck_disabled
  45. .global _soc_sys_reset
  46. .global _soc_sys_off
  47. .global _soc_core_prep_off
  48. .global _soc_core_entr_off
  49. .global _soc_core_exit_off
  50. .global _soc_core_prep_stdby
  51. .global _soc_core_entr_stdby
  52. .global _soc_core_exit_stdby
  53. .global _soc_core_prep_pwrdn
  54. .global _soc_core_entr_pwrdn
  55. .global _soc_core_exit_pwrdn
  56. .global _soc_clstr_prep_stdby
  57. .global _soc_clstr_exit_stdby
  58. .global _soc_clstr_prep_pwrdn
  59. .global _soc_clstr_exit_pwrdn
  60. .global _soc_sys_prep_stdby
  61. .global _soc_sys_exit_stdby
  62. .global _soc_sys_prep_pwrdn
  63. .global _soc_sys_pwrdn_wfi
  64. .global _soc_sys_exit_pwrdn
  65. .global _set_platform_security
  66. .global _soc_set_start_addr
  67. .equ TZPCDECPROT_0_SET_BASE, 0x02200804
  68. .equ TZPCDECPROT_1_SET_BASE, 0x02200810
  69. .equ TZPCDECPROT_2_SET_BASE, 0x0220081C
  70. .equ TZASC_REGION_ATTRIBUTES_0_0, 0x01100110
  71. .equ MPIDR_AFFINITY0_MASK, 0x00FF
  72. .equ MPIDR_AFFINITY1_MASK, 0xFF00
  73. .equ CPUECTLR_DISABLE_TWALK_PREFETCH, 0x4000000000
  74. .equ CPUECTLR_INS_PREFETCH_MASK, 0x1800000000
  75. .equ CPUECTLR_DAT_PREFETCH_MASK, 0x0300000000
  76. .equ OSDLR_EL1_DLK_LOCK, 0x1
  77. .equ CNTP_CTL_EL0_EN, 0x1
  78. .equ CNTP_CTL_EL0_IMASK, 0x2
  79. /* shifted value for incrementing cluster count in mpidr */
  80. .equ MPIDR_CLUSTER, 0x100
  81. /*
  82. * This function initialize the soc,
  83. * in: none
  84. * out: none
  85. * uses x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11
  86. */
  87. func soc_init_lowlevel
  88. /*
  89. * called from C, so save the non-volatile regs
  90. * save these as pairs of registers to maintain the
  91. * required 16-byte alignment on the stack
  92. */
  93. stp x4, x5, [sp, #-16]!
  94. stp x6, x7, [sp, #-16]!
  95. stp x8, x9, [sp, #-16]!
  96. stp x10, x11, [sp, #-16]!
  97. stp x12, x13, [sp, #-16]!
  98. stp x18, x30, [sp, #-16]!
  99. /*
  100. * make sure the personality has been established by releasing cores
  101. * that are marked "to-be-disabled" from reset
  102. */
  103. bl release_disabled
  104. /* set SCRATCHRW7 to 0x0 */
  105. ldr x0, =DCFG_SCRATCHRW7_OFFSET
  106. mov x1, xzr
  107. bl _write_reg_dcfg
  108. /* restore the aarch32/64 non-volatile registers */
  109. ldp x18, x30, [sp], #16
  110. ldp x12, x13, [sp], #16
  111. ldp x10, x11, [sp], #16
  112. ldp x8, x9, [sp], #16
  113. ldp x6, x7, [sp], #16
  114. ldp x4, x5, [sp], #16
  115. ret
  116. endfunc soc_init_lowlevel
  117. /*
  118. * void soc_init_percpu(void)
  119. * this function performs any soc-specific initialization that is needed on
  120. * a per-core basis
  121. * in: none
  122. * out: none
  123. * uses x0, x1, x2, x3
  124. */
  125. func soc_init_percpu
  126. stp x4, x30, [sp, #-16]!
  127. bl plat_my_core_mask
  128. mov x2, x0
  129. /* x2 = core mask */
  130. /* see if this core is marked for prefetch disable */
  131. mov x0, #PREFETCH_DIS_OFFSET
  132. bl _get_global_data
  133. tst x0, x2
  134. b.eq 1f
  135. bl _disable_ldstr_pfetch_A53
  136. 1:
  137. mov x0, #NXP_PMU_ADDR
  138. bl enable_timer_base_to_cluster
  139. ldp x4, x30, [sp], #16
  140. ret
  141. endfunc soc_init_percpu
  142. /*
  143. * this function sets the security mechanisms in the SoC to implement the
  144. * Platform Security Policy
  145. */
  146. func _set_platform_security
  147. mov x3, x30
  148. #if (!SUPPRESS_TZC)
  149. /* initialize the tzpc */
  150. bl init_tzpc
  151. #endif
  152. #if (!SUPPRESS_SEC)
  153. /* initialize secmon */
  154. bl initSecMon
  155. #endif
  156. mov x30, x3
  157. ret
  158. endfunc _set_platform_security
  159. /*
  160. * this function writes a 64-bit address to bootlocptrh/l
  161. * in: x0, 64-bit address to write to BOOTLOCPTRL/H
  162. * out: none
  163. * uses x0, x1, x2
  164. */
  165. func _soc_set_start_addr
  166. /* get the 64-bit base address of the dcfg block */
  167. ldr x2, =NXP_DCFG_ADDR
  168. /* write the 32-bit BOOTLOCPTRL register */
  169. mov x1, x0
  170. str w1, [x2, #DCFG_BOOTLOCPTRL_OFFSET]
  171. /* write the 32-bit BOOTLOCPTRH register */
  172. lsr x1, x0, #32
  173. str w1, [x2, #DCFG_BOOTLOCPTRH_OFFSET]
  174. ret
  175. endfunc _soc_set_start_addr
  176. /*
  177. * part of CPU_ON
  178. * this function releases a secondary core from reset
  179. * in: x0 = core_mask_lsb
  180. * out: none
  181. * uses: x0, x1, x2, x3
  182. */
  183. _soc_core_release:
  184. mov x3, x30
  185. /* x0 = core mask */
  186. ldr x1, =NXP_SEC_REGFILE_ADDR
  187. /*
  188. * write to CORE_HOLD to tell the bootrom that we want this core
  189. * to run
  190. */
  191. str w0, [x1, #CORE_HOLD_OFFSET]
  192. /* x0 = core mask */
  193. /* read-modify-write BRRL to release core */
  194. mov x1, #NXP_RESET_ADDR
  195. ldr w2, [x1, #BRR_OFFSET]
  196. orr w2, w2, w0
  197. str w2, [x1, #BRR_OFFSET]
  198. dsb sy
  199. isb
  200. /* send event */
  201. sev
  202. isb
  203. mov x30, x3
  204. ret
  205. /*
  206. * this function determines if a core is disabled via COREDISABLEDSR
  207. * in: w0 = core_mask_lsb
  208. * out: w0 = 0, core not disabled
  209. * w0 != 0, core disabled
  210. * uses x0, x1
  211. */
  212. _soc_ck_disabled:
  213. /* get base addr of dcfg block */
  214. ldr x1, =NXP_DCFG_ADDR
  215. /* read COREDISABLEDSR */
  216. ldr w1, [x1, #DCFG_COREDISABLEDSR_OFFSET]
  217. /* test core bit */
  218. and w0, w1, w0
  219. ret
  220. /*
  221. * part of CPU_ON
  222. * this function restarts a core shutdown via _soc_core_entr_off
  223. * in: x0 = core mask lsb (of the target cpu)
  224. * out: x0 == 0, on success
  225. * x0 != 0, on failure
  226. * uses x0, x1, x2, x3, x4, x5, x6
  227. */
  228. _soc_core_restart:
  229. mov x6, x30
  230. mov x4, x0
  231. /* x4 = core mask lsb */
  232. /* pgm GICD_CTLR - enable secure grp0 */
  233. mov x5, #NXP_GICD_ADDR
  234. ldr w2, [x5, #GICD_CTLR_OFFSET]
  235. orr w2, w2, #GICD_CTLR_EN_GRP_0
  236. str w2, [x5, #GICD_CTLR_OFFSET]
  237. dsb sy
  238. isb
  239. /* poll on RWP til write completes */
  240. 4:
  241. ldr w2, [x5, #GICD_CTLR_OFFSET]
  242. tst w2, #GICD_CTLR_RWP
  243. b.ne 4b
  244. /*
  245. * x4 = core mask lsb
  246. * x5 = gicd base addr
  247. */
  248. mov x0, x4
  249. bl get_mpidr_value
  250. /*
  251. * x0 = mpidr of target core
  252. * x4 = core mask lsb of target core
  253. * x5 = gicd base addr
  254. */
  255. /* generate target list bit */
  256. and x1, x0, #MPIDR_AFFINITY0_MASK
  257. mov x2, #1
  258. lsl x2, x2, x1
  259. /* get the affinity1 field */
  260. and x1, x0, #MPIDR_AFFINITY1_MASK
  261. lsl x1, x1, #8
  262. orr x2, x2, x1
  263. /* insert the INTID for SGI15 */
  264. orr x2, x2, #ICC_SGI0R_EL1_INTID
  265. /* fire the SGI */
  266. msr ICC_SGI0R_EL1, x2
  267. dsb sy
  268. isb
  269. /* load '0' on success */
  270. mov x0, xzr
  271. mov x30, x6
  272. ret
  273. /*
  274. * part of CPU_OFF
  275. * this function programs SoC & GIC registers in preparation for shutting down
  276. * the core
  277. * in: x0 = core mask lsb
  278. * out: none
  279. * uses x0, x1, x2, x3, x4, x5, x6, x7
  280. */
  281. _soc_core_prep_off:
  282. mov x8, x30
  283. mov x7, x0
  284. /* x7 = core mask lsb */
  285. mrs x1, CPUECTLR_EL1
  286. /* set smp and disable L2 snoops in cpuectlr */
  287. orr x1, x1, #CPUECTLR_SMPEN_EN
  288. orr x1, x1, #CPUECTLR_DISABLE_TWALK_PREFETCH
  289. bic x1, x1, #CPUECTLR_INS_PREFETCH_MASK
  290. bic x1, x1, #CPUECTLR_DAT_PREFETCH_MASK
  291. /* set retention control in cpuectlr */
  292. bic x1, x1, #CPUECTLR_TIMER_MASK
  293. orr x1, x1, #CPUECTLR_TIMER_8TICKS
  294. msr CPUECTLR_EL1, x1
  295. /* get redistributor rd base addr for this core */
  296. mov x0, x7
  297. bl get_gic_rd_base
  298. mov x6, x0
  299. /* get redistributor sgi base addr for this core */
  300. mov x0, x7
  301. bl get_gic_sgi_base
  302. mov x5, x0
  303. /* x5 = gicr sgi base addr
  304. * x6 = gicr rd base addr
  305. * x7 = core mask lsb
  306. */
  307. /* disable SGI 15 at redistributor - GICR_ICENABLER0 */
  308. mov w3, #GICR_ICENABLER0_SGI15
  309. str w3, [x5, #GICR_ICENABLER0_OFFSET]
  310. 2:
  311. /* poll on rwp bit in GICR_CTLR */
  312. ldr w4, [x6, #GICR_CTLR_OFFSET]
  313. tst w4, #GICR_CTLR_RWP
  314. b.ne 2b
  315. /* disable GRP1 interrupts at cpu interface */
  316. msr ICC_IGRPEN1_EL3, xzr
  317. /* disable GRP0 ints at cpu interface */
  318. msr ICC_IGRPEN0_EL1, xzr
  319. /* program the redistributor - poll on GICR_CTLR.RWP as needed */
  320. /* define SGI 15 as Grp0 - GICR_IGROUPR0 */
  321. ldr w4, [x5, #GICR_IGROUPR0_OFFSET]
  322. bic w4, w4, #GICR_IGROUPR0_SGI15
  323. str w4, [x5, #GICR_IGROUPR0_OFFSET]
  324. /* define SGI 15 as Grp0 - GICR_IGRPMODR0 */
  325. ldr w3, [x5, #GICR_IGRPMODR0_OFFSET]
  326. bic w3, w3, #GICR_IGRPMODR0_SGI15
  327. str w3, [x5, #GICR_IGRPMODR0_OFFSET]
  328. /* set priority of SGI 15 to highest (0x0) - GICR_IPRIORITYR3 */
  329. ldr w4, [x5, #GICR_IPRIORITYR3_OFFSET]
  330. bic w4, w4, #GICR_IPRIORITYR3_SGI15_MASK
  331. str w4, [x5, #GICR_IPRIORITYR3_OFFSET]
  332. /* enable SGI 15 at redistributor - GICR_ISENABLER0 */
  333. mov w3, #GICR_ISENABLER0_SGI15
  334. str w3, [x5, #GICR_ISENABLER0_OFFSET]
  335. dsb sy
  336. isb
  337. 3:
  338. /* poll on rwp bit in GICR_CTLR */
  339. ldr w4, [x6, #GICR_CTLR_OFFSET]
  340. tst w4, #GICR_CTLR_RWP
  341. b.ne 3b
  342. /* quiesce the debug interfaces */
  343. mrs x3, osdlr_el1
  344. orr x3, x3, #OSDLR_EL1_DLK_LOCK
  345. msr osdlr_el1, x3
  346. isb
  347. /* enable grp0 ints */
  348. mov x3, #ICC_IGRPEN0_EL1_EN
  349. msr ICC_IGRPEN0_EL1, x3
  350. /*
  351. * x5 = gicr sgi base addr
  352. * x6 = gicr rd base addr
  353. * x7 = core mask lsb
  354. */
  355. /* clear any pending interrupts */
  356. mvn w1, wzr
  357. str w1, [x5, #GICR_ICPENDR0_OFFSET]
  358. /* make sure system counter is enabled */
  359. ldr x3, =NXP_TIMER_ADDR
  360. ldr w0, [x3, #SYS_COUNTER_CNTCR_OFFSET]
  361. tst w0, #SYS_COUNTER_CNTCR_EN
  362. b.ne 4f
  363. orr w0, w0, #SYS_COUNTER_CNTCR_EN
  364. str w0, [x3, #SYS_COUNTER_CNTCR_OFFSET]
  365. 4:
  366. /* enable the core timer and mask timer interrupt */
  367. mov x1, #CNTP_CTL_EL0_EN
  368. orr x1, x1, #CNTP_CTL_EL0_IMASK
  369. msr cntp_ctl_el0, x1
  370. mov x30, x8
  371. ret
  372. /*
  373. * part of CPU_OFF
  374. * this function performs the final steps to shutdown the core
  375. * in: x0 = core mask lsb
  376. * out: none
  377. * uses x0, x1, x2, x3, x4, x5
  378. */
  379. _soc_core_entr_off:
  380. mov x5, x30
  381. mov x4, x0
  382. /* x4 = core mask */
  383. 1:
  384. /* enter low-power state by executing wfi */
  385. wfi
  386. /* see if SGI15 woke us up */
  387. mrs x2, ICC_IAR0_EL1
  388. mov x3, #ICC_IAR0_EL1_SGI15
  389. cmp x2, x3
  390. b.ne 2f
  391. /* deactivate the int */
  392. msr ICC_EOIR0_EL1, x2
  393. /* x4 = core mask */
  394. 2:
  395. /* check if core has been turned on */
  396. mov x0, x4
  397. bl _getCoreState
  398. /* x0 = core state */
  399. cmp x0, #CORE_WAKEUP
  400. b.ne 1b
  401. /* if we get here, then we have exited the wfi */
  402. mov x30, x5
  403. ret
  404. /*
  405. * part of CPU_OFF
  406. * this function starts the process of starting a core back up
  407. * in: x0 = core mask lsb
  408. * out: none
  409. * uses x0, x1, x2, x3, x4, x5, x6
  410. */
  411. _soc_core_exit_off:
  412. mov x6, x30
  413. mov x5, x0
  414. /* disable forwarding of GRP0 ints at cpu interface */
  415. msr ICC_IGRPEN0_EL1, xzr
  416. /* get redistributor sgi base addr for this core */
  417. mov x0, x5
  418. bl get_gic_sgi_base
  419. mov x4, x0
  420. /*
  421. * x4 = gicr sgi base addr
  422. * x5 = core mask
  423. */
  424. /* disable SGI 15 at redistributor - GICR_ICENABLER0 */
  425. mov w1, #GICR_ICENABLER0_SGI15
  426. str w1, [x4, #GICR_ICENABLER0_OFFSET]
  427. /* get redistributor rd base addr for this core */
  428. mov x0, x5
  429. bl get_gic_rd_base
  430. mov x4, x0
  431. /* x4 = gicr rd base addr */
  432. 2:
  433. /* poll on rwp bit in GICR_CTLR */
  434. ldr w2, [x4, #GICR_CTLR_OFFSET]
  435. tst w2, #GICR_CTLR_RWP
  436. b.ne 2b
  437. /* x4 = gicr rd base addr */
  438. /* unlock the debug interfaces */
  439. mrs x3, osdlr_el1
  440. bic x3, x3, #OSDLR_EL1_DLK_LOCK
  441. msr osdlr_el1, x3
  442. isb
  443. dsb sy
  444. isb
  445. mov x30, x6
  446. ret
  447. /*
  448. * this function requests a reset of the entire SOC
  449. * in: none
  450. * out: none
  451. * uses: x0, x1, x2, x3, x4, x5, x6
  452. */
  453. _soc_sys_reset:
  454. mov x3, x30
  455. /* make sure the mask is cleared in the reset request mask register */
  456. mov x0, #RST_RSTRQMR1_OFFSET
  457. mov w1, wzr
  458. bl _write_reg_reset
  459. /* set the reset request */
  460. mov x4, #RST_RSTCR_OFFSET
  461. mov x0, x4
  462. mov w1, #RSTCR_RESET_REQ
  463. bl _write_reg_reset
  464. /* x4 = RST_RSTCR_OFFSET */
  465. /*
  466. * just in case this address range is mapped as cacheable,
  467. * flush the write out of the dcaches
  468. */
  469. mov x2, #NXP_RESET_ADDR
  470. add x2, x2, x4
  471. dc cvac, x2
  472. dsb st
  473. isb
  474. /* this function does not return */
  475. b .
  476. /*
  477. * this function turns off the SoC
  478. * Note: this function is not intended to return, and the only allowable
  479. * recovery is POR
  480. * in: none
  481. * out: none
  482. * uses x0, x1, x2, x3
  483. */
  484. _soc_sys_off:
  485. /*
  486. * A-009810: LPM20 entry sequence might cause
  487. * spurious timeout reset request
  488. * workaround: MASK RESET REQ RPTOE
  489. */
  490. ldr x0, =NXP_RESET_ADDR
  491. ldr w1, [x0, #RST_RSTRQMR1_OFFSET]
  492. orr w1, w1, #RSTRQMR_RPTOE_MASK
  493. str w1, [x0, #RST_RSTRQMR1_OFFSET]
  494. /* disable SEC, QBman spi and qspi */
  495. ldr x2, =NXP_DCFG_ADDR
  496. ldr x0, =DCFG_DEVDISR1_OFFSET
  497. ldr w1, =DCFG_DEVDISR1_SEC
  498. str w1, [x2, x0]
  499. ldr x0, =DCFG_DEVDISR3_OFFSET
  500. ldr w1, =DCFG_DEVDISR3_QBMAIN
  501. str w1, [x2, x0]
  502. ldr x0, =DCFG_DEVDISR4_OFFSET
  503. ldr w1, =DCFG_DEVDISR4_SPI_QSPI
  504. str w1, [x2, x0]
  505. /* set TPMWAKEMR0 */
  506. ldr x0, =TPMWAKEMR0_ADDR
  507. mov w1, #0x1
  508. str w1, [x0]
  509. /* disable icache, dcache, mmu @ EL1 */
  510. mov x1, #SCTLR_I_C_M_MASK
  511. mrs x0, sctlr_el1
  512. bic x0, x0, x1
  513. msr sctlr_el1, x0
  514. /* disable L2 prefetches */
  515. mrs x0, CPUECTLR_EL1
  516. orr x0, x0, #CPUECTLR_SMPEN_EN
  517. orr x0, x0, #CPUECTLR_TIMER_8TICKS
  518. msr CPUECTLR_EL1, x0
  519. dsb sy
  520. isb
  521. /* disable CCN snoop domain */
  522. ldr x0, =NXP_CCI_ADDR
  523. mov w1, #0x1
  524. str w1, [x0]
  525. mov x2, #DAIF_SET_MASK
  526. mrs x1, spsr_el1
  527. orr x1, x1, x2
  528. msr spsr_el1, x1
  529. mrs x1, spsr_el2
  530. orr x1, x1, x2
  531. msr spsr_el2, x1
  532. bl get_pmu_idle_cluster_mask
  533. mov x3, #NXP_PMU_ADDR
  534. /* x3 = pmu base addr */
  535. /* idle the ACP interfaces */
  536. str w0, [x3, #PMU_CLAINACTSETR_OFFSET]
  537. /* force the debug interface to be quiescent */
  538. mrs x0, osdlr_el1
  539. orr x0, x0, #0x1
  540. msr osdlr_el1, x0
  541. bl get_pmu_flush_cluster_mask
  542. /* x3 = pmu base addr */
  543. mov x3, #NXP_PMU_ADDR
  544. /* clear flush request and status */
  545. ldr x2, =PMU_CLSL2FLUSHCLRR_OFFSET
  546. str w0, [x3, x2]
  547. /* close the Skyros master port */
  548. ldr x2, =PMU_CLSINACTSETR_OFFSET
  549. str w0, [x3, x2]
  550. /* request lpm20 */
  551. ldr x0, =PMU_POWMGTCSR_OFFSET
  552. ldr w1, =PMU_POWMGTCSR_VAL
  553. str w1, [x3, x0]
  554. /* this function does not return */
  555. 1:
  556. wfi
  557. b 1b
  558. /*
  559. * part of CPU_SUSPEND
  560. * this function performs SoC-specific programming prior to standby
  561. * in: x0 = core mask lsb
  562. * out: none
  563. * uses x0, x1
  564. */
  565. _soc_core_prep_stdby:
  566. /* clear CPUECTLR_EL1[2:0] */
  567. mrs x1, CPUECTLR_EL1
  568. bic x1, x1, #CPUECTLR_TIMER_MASK
  569. msr CPUECTLR_EL1, x1
  570. ret
  571. /*
  572. * part of CPU_SUSPEND
  573. * this function puts the calling core into standby state
  574. * in: x0 = core mask lsb
  575. * out: none
  576. * uses x0
  577. */
  578. _soc_core_entr_stdby:
  579. /* X0 = core mask lsb */
  580. dsb sy
  581. isb
  582. wfi
  583. ret
  584. /*
  585. * part of CPU_SUSPEND
  586. * this function performs any SoC-specific cleanup after standby state
  587. * in: x0 = core mask lsb
  588. * out: none
  589. * uses none
  590. */
  591. _soc_core_exit_stdby:
  592. ret
  593. /*
  594. * part of CPU_SUSPEND
  595. * this function performs SoC-specific programming prior to power-down
  596. * in: x0 = core mask lsb
  597. * out: none
  598. * uses x0, x1, x2, x3
  599. */
  600. _soc_core_prep_pwrdn:
  601. /* make sure system counter is enabled */
  602. ldr x3, =NXP_TIMER_ADDR
  603. ldr w0, [x3, #SYS_COUNTER_CNTCR_OFFSET]
  604. tst w0, #SYS_COUNTER_CNTCR_EN
  605. b.ne 1f
  606. orr w0, w0, #SYS_COUNTER_CNTCR_EN
  607. str w0, [x3, #SYS_COUNTER_CNTCR_OFFSET]
  608. 1:
  609. /*
  610. * enable dynamic retention control (CPUECTLR[2:0])
  611. * set the SMPEN bit (CPUECTLR[6])
  612. */
  613. mrs x1, CPUECTLR_EL1
  614. bic x1, x1, #CPUECTLR_RET_MASK
  615. orr x1, x1, #CPUECTLR_TIMER_8TICKS
  616. orr x1, x1, #CPUECTLR_SMPEN_EN
  617. msr CPUECTLR_EL1, x1
  618. isb
  619. ret
  620. /*
  621. * part of CPU_SUSPEND
  622. * this function puts the calling core into a power-down state
  623. * in: x0 = core mask lsb
  624. * out: none
  625. * uses x0
  626. */
  627. _soc_core_entr_pwrdn:
  628. /* X0 = core mask lsb */
  629. dsb sy
  630. isb
  631. wfi
  632. ret
  633. /*
  634. * part of CPU_SUSPEND
  635. * this function cleans up after a core exits power-down
  636. * in: x0 = core mask lsb
  637. * out: none
  638. * uses
  639. */
  640. _soc_core_exit_pwrdn:
  641. ret
  642. /*
  643. * part of CPU_SUSPEND
  644. * this function performs SoC-specific programming prior to standby
  645. * in: x0 = core mask lsb
  646. * out: none
  647. * uses x0, x1
  648. */
  649. _soc_clstr_prep_stdby:
  650. /* clear CPUECTLR_EL1[2:0] */
  651. mrs x1, CPUECTLR_EL1
  652. bic x1, x1, #CPUECTLR_TIMER_MASK
  653. msr CPUECTLR_EL1, x1
  654. ret
  655. /*
  656. * part of CPU_SUSPEND
  657. * this function performs any SoC-specific cleanup after standby state
  658. * in: x0 = core mask lsb
  659. * out: none
  660. * uses none
  661. */
  662. _soc_clstr_exit_stdby:
  663. ret
  664. /*
  665. * part of CPU_SUSPEND
  666. * this function performs SoC-specific programming prior to power-down
  667. * in: x0 = core mask lsb
  668. * out: none
  669. * uses x0, x1, x2, x3
  670. */
  671. _soc_clstr_prep_pwrdn:
  672. /* make sure system counter is enabled */
  673. ldr x3, =NXP_TIMER_ADDR
  674. ldr w0, [x3, #SYS_COUNTER_CNTCR_OFFSET]
  675. tst w0, #SYS_COUNTER_CNTCR_EN
  676. b.ne 1f
  677. orr w0, w0, #SYS_COUNTER_CNTCR_EN
  678. str w0, [x3, #SYS_COUNTER_CNTCR_OFFSET]
  679. 1:
  680. /*
  681. * enable dynamic retention control (CPUECTLR[2:0])
  682. * set the SMPEN bit (CPUECTLR[6])
  683. */
  684. mrs x1, CPUECTLR_EL1
  685. bic x1, x1, #CPUECTLR_RET_MASK
  686. orr x1, x1, #CPUECTLR_TIMER_8TICKS
  687. orr x1, x1, #CPUECTLR_SMPEN_EN
  688. msr CPUECTLR_EL1, x1
  689. isb
  690. ret
  691. /*
  692. * part of CPU_SUSPEND
  693. * this function cleans up after a core exits power-down
  694. * in: x0 = core mask lsb
  695. * out: none
  696. * uses
  697. */
  698. _soc_clstr_exit_pwrdn:
  699. ret
  700. /*
  701. * part of CPU_SUSPEND
  702. * this function performs SoC-specific programming prior to standby
  703. * in: x0 = core mask lsb
  704. * out: none
  705. * uses x0, x1
  706. */
  707. _soc_sys_prep_stdby:
  708. /* clear CPUECTLR_EL1[2:0] */
  709. mrs x1, CPUECTLR_EL1
  710. bic x1, x1, #CPUECTLR_TIMER_MASK
  711. msr CPUECTLR_EL1, x1
  712. ret
  713. /*
  714. * part of CPU_SUSPEND
  715. * this function performs any SoC-specific cleanup after standby state
  716. * in: x0 = core mask lsb
  717. * out: none
  718. * uses none
  719. */
  720. _soc_sys_exit_stdby:
  721. ret
  722. /*
  723. * part of CPU_SUSPEND
  724. * this function performs SoC-specific programming prior to
  725. * suspend-to-power-down
  726. * in: x0 = core mask lsb
  727. * out: none
  728. * uses x0
  729. */
  730. _soc_sys_prep_pwrdn:
  731. /* set retention control */
  732. mrs x0, CPUECTLR_EL1
  733. bic x0, x0, #CPUECTLR_TIMER_MASK
  734. orr x0, x0, #CPUECTLR_TIMER_8TICKS
  735. orr x0, x0, #CPUECTLR_SMPEN_EN
  736. msr CPUECTLR_EL1, x0
  737. dsb sy
  738. isb
  739. ret
  740. /*
  741. * part of CPU_SUSPEND
  742. * this function puts the calling core, and potentially the soc, into a
  743. * low-power state
  744. * in: x0 = core mask lsb
  745. * out: x0 = 0, success
  746. * x0 < 0, failure
  747. * uses x0, x1, x2, x3, x4, x5, x6, x7, x8
  748. */
  749. _soc_sys_pwrdn_wfi:
  750. /* Save LR to stack */
  751. stp x18, x30, [sp, #-16]!
  752. /* Poll PCPW20SR for all secondary cores to be placed in PW20 */
  753. bl get_tot_num_cores
  754. mov x3, #0x1
  755. lsl x3, x3, x0
  756. sub x3, x3, #2
  757. 1:
  758. mov x0, #NXP_PMU_ADDR
  759. ldr w1, [x0, #PMU_PCPW20SR_OFFSET]
  760. cmp w1, w3
  761. b.ne 1b
  762. /* backup EPU registers to stack */
  763. mov x3, #NXP_PMU_ADDR
  764. ldr x2, =NXP_EPU_ADDR
  765. ldr w4, [x2, #EPU_EPIMCR10_OFFSET]
  766. ldr w5, [x2, #EPU_EPCCR10_OFFSET]
  767. ldr w6, [x2, #EPU_EPCTR10_OFFSET]
  768. ldr w7, [x2, #EPU_EPGCR_OFFSET]
  769. stp x4, x5, [sp, #-16]!
  770. stp x6, x7, [sp, #-16]!
  771. /*
  772. * x2 = epu base addr
  773. * x3 = pmu base addr
  774. */
  775. /* set up EPU event to receive the wake signal from PMU */
  776. mov w4, #EPU_EPIMCR10_VAL
  777. mov w5, #EPU_EPCCR10_VAL
  778. mov w6, #EPU_EPCTR10_VAL
  779. mov w7, #EPU_EPGCR_VAL
  780. str w4, [x2, #EPU_EPIMCR10_OFFSET]
  781. str w5, [x2, #EPU_EPCCR10_OFFSET]
  782. str w6, [x2, #EPU_EPCTR10_OFFSET]
  783. str w7, [x2, #EPU_EPGCR_OFFSET]
  784. /*
  785. * A-010194: There is logic problem
  786. * in the path of GIC-to-PMU to issue
  787. * wake request to core0
  788. * Workaround: Re-target the wakeup interrupts
  789. * to a core other than the last active core0
  790. */
  791. ldr x2, =NXP_GICD_ADDR
  792. /* backup flextimer/mmc/usb interrupt router */
  793. ldr x0, =GICD_IROUTER60_OFFSET
  794. ldr x1, =GICD_IROUTER76_OFFSET
  795. ldr w4, [x2, x0]
  796. ldr w5, [x2, x1]
  797. ldr x0, =GICD_IROUTER112_OFFSET
  798. ldr x1, =GICD_IROUTER113_OFFSET
  799. ldr w6, [x2, x0]
  800. ldr w7, [x2, x1]
  801. stp x4, x5, [sp, #-16]!
  802. stp x6, x7, [sp, #-16]!
  803. /*
  804. * x2 = gicd base addr
  805. * x0 = GICD_IROUTER112_OFFSET
  806. * x1 = GICD_IROUTER113_OFFSET
  807. */
  808. /* re-route interrupt to cluster 1 */
  809. ldr w4, =GICD_IROUTER_VALUE
  810. str w4, [x2, x0]
  811. str w4, [x2, x1]
  812. ldr x0, =GICD_IROUTER60_OFFSET
  813. ldr x1, =GICD_IROUTER76_OFFSET
  814. str w4, [x2, x0]
  815. str w4, [x2, x1]
  816. dsb sy
  817. isb
  818. /* backup flextimer/mmc/usb interrupt enabler */
  819. ldr x0, =GICD_ISENABLER_1
  820. ldr w4, [x2, x0]
  821. ldr x1, =GICD_ISENABLER_2
  822. ldr w5, [x2, x1]
  823. stp x4, x5, [sp, #-16]!
  824. ldr x0, =GICD_ISENABLER_3
  825. ldr w4, [x2, x0]
  826. ldr x1, =GICD_ICENABLER_1
  827. ldr w5, [x2, x1]
  828. stp x4, x5, [sp, #-16]!
  829. ldr x0, =GICD_ICENABLER_2
  830. ldr w4, [x2, x0]
  831. ldr x1, =GICD_ICENABLER_3
  832. ldr w5, [x2, x1]
  833. stp x4, x5, [sp, #-16]!
  834. /* enable related interrupt routing */
  835. ldr w4, =GICD_ISENABLER_1_VALUE
  836. ldr x0, =GICD_ISENABLER_1
  837. str w4, [x2, x0]
  838. dsb sy
  839. isb
  840. ldr w4, =GICD_ISENABLER_2_VALUE
  841. ldr x0, =GICD_ISENABLER_2
  842. str w4, [x2, x0]
  843. dsb sy
  844. isb
  845. ldr w4, =GICD_ISENABLER_3_VALUE
  846. ldr x0, =GICD_ISENABLER_3
  847. str w4, [x2, x0]
  848. dsb sy
  849. isb
  850. /* set POWMGTDCR [STP_PV_EN] = 1 */
  851. ldr x2, =NXP_POWMGTDCR
  852. ldr w4, =0x01
  853. str w4, [x2]
  854. /* program IPSTPCR for override stop request (except DDR) */
  855. mov x3, #NXP_PMU_ADDR
  856. /* build an override mask for IPSTPCR4/IPSTPACK4/DEVDISR5 */
  857. ldr x2, =PMU_IPPDEXPCR4_OFFSET
  858. ldr w7, [x3, x2]
  859. mov x5, xzr
  860. ldr x6, =IPPDEXPCR4_MASK
  861. and x6, x6, x7
  862. cbz x6, 1f
  863. /*
  864. * x5 = override mask
  865. * x6 = IPPDEXPCR bits for DEVDISR5
  866. * x7 = IPPDEXPCR
  867. */
  868. /* get the overrides */
  869. orr x4, x5, #DEVDISR5_FLX_TMR
  870. tst x6, #IPPDEXPCR_FLX_TMR
  871. csel x5, x5, x4, EQ
  872. 1:
  873. /* store the DEVDISR5 override mask */
  874. ldr x2, =BC_PSCI_BASE
  875. add x2, x2, #AUX_01_DATA
  876. str w5, [x2, #DEVDISR5_MASK_OFFSET]
  877. mov x3, #NXP_PMU_ADDR
  878. /* write IPSTPCR0 - no overrides */
  879. ldr x2, =PMU_IPSTPCR0_OFFSET
  880. ldr w5, =IPSTPCR0_VALUE
  881. str w5, [x3, x2]
  882. /* write IPSTPCR1 - no overrides */
  883. ldr x2, =PMU_IPSTPCR1_OFFSET
  884. ldr w5, =IPSTPCR1_VALUE
  885. str w5, [x3, x2]
  886. /* write IPSTPCR2 - no overrides */
  887. ldr x2, =PMU_IPSTPCR2_OFFSET
  888. ldr w5, =IPSTPCR2_VALUE
  889. str w5, [x3, x2]
  890. /* write IPSTPCR3 - no overrides */
  891. ldr x2, =PMU_IPSTPCR3_OFFSET
  892. ldr w5, =IPSTPCR3_VALUE
  893. str w5, [x3, x2]
  894. /* write IPSTPCR4 - overrides possible */
  895. ldr x2, =BC_PSCI_BASE
  896. add x2, x2, #AUX_01_DATA
  897. ldr w6, [x2, #DEVDISR5_MASK_OFFSET]
  898. ldr x2, =PMU_IPSTPCR4_OFFSET
  899. ldr w5, =IPSTPCR4_VALUE
  900. bic x5, x5, x6
  901. str w5, [x3, x2]
  902. /* write IPSTPCR5 - no overrides */
  903. ldr x2, =PMU_IPSTPCR5_OFFSET
  904. ldr w5, =IPSTPCR5_VALUE
  905. str w5, [x3, x2]
  906. /* write IPSTPCR6 - no overrides */
  907. ldr x2, =PMU_IPSTPCR6_OFFSET
  908. ldr w5, =IPSTPCR6_VALUE
  909. str w5, [x3, x2]
  910. /* poll IPSTPACK for IP stop acknowledgment (except DDR) */
  911. mov x3, #NXP_PMU_ADDR
  912. /* poll on IPSTPACK0 */
  913. ldr x2, =PMU_IPSTPACK0_OFFSET
  914. ldr x4, =IPSTPCR0_VALUE
  915. ldr x7, =IPSTPACK_RETRY_CNT
  916. 3:
  917. ldr w0, [x3, x2]
  918. cmp x0, x4
  919. b.eq 14f
  920. sub x7, x7, #1
  921. cbnz x7, 3b
  922. 14:
  923. /* poll on IPSTPACK1 */
  924. ldr x2, =PMU_IPSTPACK1_OFFSET
  925. ldr x4, =IPSTPCR1_VALUE
  926. ldr x7, =IPSTPACK_RETRY_CNT
  927. 4:
  928. ldr w0, [x3, x2]
  929. cmp x0, x4
  930. b.eq 15f
  931. sub x7, x7, #1
  932. cbnz x7, 4b
  933. 15:
  934. /* poll on IPSTPACK2 */
  935. ldr x2, =PMU_IPSTPACK2_OFFSET
  936. ldr x4, =IPSTPCR2_VALUE
  937. ldr x7, =IPSTPACK_RETRY_CNT
  938. 5:
  939. ldr w0, [x3, x2]
  940. cmp x0, x4
  941. b.eq 16f
  942. sub x7, x7, #1
  943. cbnz x7, 5b
  944. 16:
  945. /* poll on IPSTPACK3 */
  946. ldr x2, =PMU_IPSTPACK3_OFFSET
  947. ldr x4, =IPSTPCR3_VALUE
  948. ldr x7, =IPSTPACK_RETRY_CNT
  949. 6:
  950. ldr w0, [x3, x2]
  951. cmp x0, x4
  952. b.eq 17f
  953. sub x7, x7, #1
  954. cbnz x7, 6b
  955. 17:
  956. /* poll on IPSTPACK4 */
  957. ldr x2, =PMU_IPSTPACK4_OFFSET
  958. ldr x4, =IPSTPCR4_VALUE
  959. ldr x7, =IPSTPACK_RETRY_CNT
  960. 7:
  961. ldr w0, [x3, x2]
  962. cmp x0, x4
  963. b.eq 18f
  964. sub x7, x7, #1
  965. cbnz x7, 7b
  966. 18:
  967. /* poll on IPSTPACK5 */
  968. ldr x2, =PMU_IPSTPACK5_OFFSET
  969. ldr x4, =IPSTPCR5_VALUE
  970. ldr x7, =IPSTPACK_RETRY_CNT
  971. 8:
  972. ldr w0, [x3, x2]
  973. cmp x0, x4
  974. b.eq 19f
  975. sub x7, x7, #1
  976. cbnz x7, 8b
  977. 19:
  978. /* poll on IPSTPACK6 */
  979. ldr x2, =PMU_IPSTPACK6_OFFSET
  980. ldr x4, =IPSTPCR6_VALUE
  981. ldr x7, =IPSTPACK_RETRY_CNT
  982. 9:
  983. ldr w0, [x3, x2]
  984. cmp x0, x4
  985. b.eq 20f
  986. sub x7, x7, #1
  987. cbnz x7, 9b
  988. 20:
  989. /* save current DEVDISR states to DDR. */
  990. ldr x2, =NXP_DCFG_ADDR
  991. /* save DEVDISR1 and load new value */
  992. ldr x0, =DCFG_DEVDISR1_OFFSET
  993. ldr w1, [x2, x0]
  994. mov w13, w1
  995. ldr x1, =DEVDISR1_VALUE
  996. str w1, [x2, x0]
  997. /* save DEVDISR2 and load new value */
  998. ldr x0, =DCFG_DEVDISR2_OFFSET
  999. ldr w1, [x2, x0]
  1000. mov w14, w1
  1001. ldr x1, =DEVDISR2_VALUE
  1002. str w1, [x2, x0]
  1003. /* x6 = DEVDISR5 override mask */
  1004. /* save DEVDISR3 and load new value */
  1005. ldr x0, =DCFG_DEVDISR3_OFFSET
  1006. ldr w1, [x2, x0]
  1007. mov w15, w1
  1008. ldr x1, =DEVDISR3_VALUE
  1009. str w1, [x2, x0]
  1010. /* save DEVDISR4 and load new value */
  1011. ldr x0, =DCFG_DEVDISR4_OFFSET
  1012. ldr w1, [x2, x0]
  1013. mov w16, w1
  1014. /* not stop uart print */
  1015. ldr x1, =0x0000332
  1016. str w1, [x2, x0]
  1017. /* save DEVDISR5 and load new value */
  1018. ldr x0, =DCFG_DEVDISR5_OFFSET
  1019. ldr w1, [x2, x0]
  1020. mov w17, w1
  1021. /* Enable this wakeup will fail, should enable OCRAM */
  1022. ldr x1, =0x00102300
  1023. str w1, [x2, x0]
  1024. /* save DEVDISR6 and load new value */
  1025. ldr x0, =DCFG_DEVDISR6_OFFSET
  1026. ldr w1, [x2, x0]
  1027. mov w18, w1
  1028. ldr x1, =DEVDISR6_VALUE
  1029. str w1, [x2, x0]
  1030. /*
  1031. * w13 = DEVDISR1 saved value
  1032. * w14 = DEVDISR2 saved value
  1033. * w15 = DEVDISR3 saved value
  1034. * w16 = DEVDISR4 saved value
  1035. * w17 = DEVDISR5 saved value
  1036. * w18 = DEVDISR6 saved value
  1037. */
  1038. /*
  1039. * A-009810: LPM20 entry sequence might cause
  1040. * spurious timeout reset request
  1041. * workaround: MASK RESET REQ RPTOE
  1042. */
  1043. ldr x0, =NXP_RESET_ADDR
  1044. ldr w1, =RSTRQMR_RPTOE_MASK
  1045. str w1, [x0, #RST_RSTRQMR1_OFFSET]
  1046. /* disable SEC, QBman spi and qspi */
  1047. ldr x2, =NXP_DCFG_ADDR
  1048. ldr x0, =DCFG_DEVDISR1_OFFSET
  1049. ldr w1, =DCFG_DEVDISR1_SEC
  1050. str w1, [x2, x0]
  1051. ldr x0, =DCFG_DEVDISR3_OFFSET
  1052. ldr w1, =DCFG_DEVDISR3_QBMAIN
  1053. str w1, [x2, x0]
  1054. ldr x0, =DCFG_DEVDISR4_OFFSET
  1055. ldr w1, =DCFG_DEVDISR4_SPI_QSPI
  1056. str w1, [x2, x0]
  1057. /*
  1058. * write the GICR_WAKER.ProcessorSleep bits to 1
  1059. * enable the WakeRequest signal
  1060. * x3 is cpu mask starting from cpu7
  1061. */
  1062. bl get_tot_num_cores
  1063. sub x0, x0, #1
  1064. mov x3, #0x1
  1065. lsl x3, x3, x0
  1066. 2:
  1067. mov x0, x3
  1068. bl get_gic_rd_base
  1069. ldr w1, [x0, #GICR_WAKER_OFFSET]
  1070. orr w1, w1, #GICR_WAKER_SLEEP_BIT
  1071. str w1, [x0, #GICR_WAKER_OFFSET]
  1072. 1:
  1073. ldr w1, [x0, #GICR_WAKER_OFFSET]
  1074. cmp w1, #GICR_WAKER_ASLEEP
  1075. b.ne 1b
  1076. lsr x3, x3, #1
  1077. cbnz x3, 2b
  1078. /* x3 = pmu base addr */
  1079. /* perform Icache Warming Sequence */
  1080. ldr x5, =IPSTPCR4_VALUE
  1081. mov x6, DDR_CNTRL_BASE_ADDR
  1082. mov x7, #NXP_PMU_ADDR
  1083. mov x8, #NXP_DCFG_ADDR
  1084. mov x10, #PMU_IPSTPCR4_OFFSET
  1085. mov x11, #PMU_IPSTPACK4_OFFSET
  1086. mov x12, #PMU_IPSTPCR3_OFFSET
  1087. mov x18, #PMU_IPSTPCR2_OFFSET
  1088. mov x19, #PMU_IPSTPCR1_OFFSET
  1089. mov x21, #PMU_IPSTPCR0_OFFSET
  1090. ldr x22, =DCFG_DEVDISR5_OFFSET
  1091. ldr x23, =NXP_EPU_ADDR
  1092. mov x9, #CORE_RESTARTABLE
  1093. bl final_pwrdown
  1094. /*
  1095. * disable the WakeRequest signal on cpu 0-7
  1096. * x3 is cpu mask starting from cpu7
  1097. */
  1098. bl get_tot_num_cores
  1099. sub x0, x0, #1
  1100. mov x3, #0x1
  1101. lsl x3, x3, x0
  1102. 2:
  1103. mov x0, x3
  1104. bl get_gic_rd_base
  1105. ldr w1, [x0, #GICR_WAKER_OFFSET]
  1106. bic w1, w1, #GICR_WAKER_SLEEP_BIT
  1107. str w1, [x0, #GICR_WAKER_OFFSET]
  1108. 1:
  1109. ldr w1, [x0, #GICR_WAKER_OFFSET]
  1110. cbnz w1, 1b
  1111. lsr x3, x3, #1
  1112. cbnz x3, 2b
  1113. /* set SGI for secondary core wakeup */
  1114. ldr x0, =0x1000002
  1115. msr S3_0_C12_C11_7, x0
  1116. isb
  1117. ldr x0, =0x2000004
  1118. msr S3_0_C12_C11_7, x0
  1119. isb
  1120. ldr x0, =0x3000008
  1121. msr S3_0_C12_C11_7, x0
  1122. isb
  1123. ldr x0, =0x4010001
  1124. msr S3_0_C12_C11_7, x0
  1125. isb
  1126. ldr x0, =0x5010002
  1127. msr S3_0_C12_C11_7, x0
  1128. isb
  1129. ldr x0, =0x6010004
  1130. msr S3_0_C12_C11_7, x0
  1131. isb
  1132. ldr x0, =0x7010008
  1133. msr S3_0_C12_C11_7, x0
  1134. /* enable SEC, QBman spi and qspi */
  1135. ldr x2, =NXP_DCFG_ADDR
  1136. str wzr, [x2, #DCFG_DEVDISR1_OFFSET]
  1137. str wzr, [x2, #DCFG_DEVDISR3_OFFSET]
  1138. str wzr, [x2, #DCFG_DEVDISR4_OFFSET]
  1139. /* clear POWMGTDCR [STP_PV_EN] */
  1140. ldr x2, =NXP_POWMGTDCR
  1141. ldr w4, [x2]
  1142. bic w4, w4, #0x01
  1143. str w4, [x2]
  1144. /* restore flextimer/mmc/usb interrupt enabler */
  1145. ldr x3, =NXP_GICD_ADDR
  1146. ldp x0, x2, [sp], #16
  1147. ldr x1, =GICD_ICENABLER_2
  1148. mvn w0, w0
  1149. str w0, [x3, x1]
  1150. ldr x1, =GICD_ICENABLER_3
  1151. mvn w2, w2
  1152. str w2, [x3, x1]
  1153. ldp x0, x2, [sp], #16
  1154. ldr x1, =GICD_ISENABLER_3
  1155. str w0, [x3, x1]
  1156. ldr x1, =GICD_ICENABLER_1
  1157. mvn w2, w2
  1158. str w0, [x3, x1]
  1159. ldp x0, x2, [sp], #16
  1160. ldr x1, =GICD_ISENABLER_1
  1161. str w0, [x3, x1]
  1162. ldr x1, =GICD_ISENABLER_2
  1163. str w0, [x3, x1]
  1164. /* restore flextimer/mmc/usb interrupt router */
  1165. ldr x3, =NXP_GICD_ADDR
  1166. ldp x0, x2, [sp], #16
  1167. ldr x1, =GICD_IROUTER113_OFFSET
  1168. str w2, [x3, x1]
  1169. ldr x1, =GICD_IROUTER112_OFFSET
  1170. str w0, [x3, x1]
  1171. ldp x0, x2, [sp], #16
  1172. ldr x1, =GICD_IROUTER76_OFFSET
  1173. str w2, [x3, x1]
  1174. ldr x1, =GICD_IROUTER60_OFFSET
  1175. str w0, [x3, x1]
  1176. /* restore EPU registers */
  1177. ldr x3, =NXP_EPU_ADDR
  1178. ldp x0, x2, [sp], #16
  1179. str w2, [x3, #EPU_EPGCR_OFFSET]
  1180. str w0, [x3, #EPU_EPCTR10_OFFSET]
  1181. ldp x2, x1, [sp], #16
  1182. str w1, [x3, #EPU_EPCCR10_OFFSET]
  1183. str w2, [x3, #EPU_EPIMCR10_OFFSET]
  1184. isb
  1185. /* Restor LR */
  1186. ldp x18, x30, [sp], #16
  1187. ret
  1188. /*
  1189. * part of CPU_SUSPEND
  1190. * this function performs any SoC-specific cleanup after power-down
  1191. * in: x0 = core mask lsb
  1192. * out: none
  1193. * uses x0, x1
  1194. */
  1195. _soc_sys_exit_pwrdn:
  1196. mrs x1, SCTLR_EL1
  1197. orr x1, x1, #SCTLR_I_MASK
  1198. msr SCTLR_EL1, x1
  1199. isb
  1200. ret
  1201. /*
  1202. * this function checks to see if cores which are to be disabled have been
  1203. * released from reset - if not, it releases them
  1204. * in: none
  1205. * out: none
  1206. * uses x0, x1, x2, x3, x4, x5, x6, x7, x8
  1207. */
  1208. release_disabled:
  1209. mov x8, x30
  1210. /* read COREDISABLESR */
  1211. mov x0, #NXP_DCFG_ADDR
  1212. ldr w4, [x0, #DCFG_COREDISABLEDSR_OFFSET]
  1213. /* get the number of cpus on this device */
  1214. mov x6, #PLATFORM_CORE_COUNT
  1215. mov x0, #NXP_RESET_ADDR
  1216. ldr w5, [x0, #BRR_OFFSET]
  1217. /* load the core mask for the first core */
  1218. mov x7, #1
  1219. /*
  1220. * x4 = COREDISABLESR
  1221. * x5 = BRR
  1222. * x6 = loop count
  1223. * x7 = core mask bit
  1224. */
  1225. 2:
  1226. /* check if the core is to be disabled */
  1227. tst x4, x7
  1228. b.eq 1f
  1229. /* see if disabled cores have already been released from reset */
  1230. tst x5, x7
  1231. b.ne 1f
  1232. /* if core has not been released, then release it (0-3) */
  1233. mov x0, x7
  1234. bl _soc_core_release
  1235. /* record the core state in the data area (0-3) */
  1236. mov x0, x7
  1237. mov x1, #CORE_DISABLED
  1238. bl _setCoreState
  1239. 1:
  1240. /* decrement the counter */
  1241. subs x6, x6, #1
  1242. b.le 3f
  1243. /* shift the core mask to the next core */
  1244. lsl x7, x7, #1
  1245. /* continue */
  1246. b 2b
  1247. 3:
  1248. mov x30, x8
  1249. ret
  1250. /*
  1251. * write a register in the DCFG block
  1252. * in: x0 = offset
  1253. * in: w1 = value to write
  1254. * uses x0, x1, x2
  1255. */
  1256. _write_reg_dcfg:
  1257. ldr x2, =NXP_DCFG_ADDR
  1258. str w1, [x2, x0]
  1259. ret
  1260. /*
  1261. * read a register in the DCFG block
  1262. * in: x0 = offset
  1263. * out: w0 = value read
  1264. * uses x0, x1
  1265. */
  1266. _read_reg_dcfg:
  1267. ldr x1, =NXP_DCFG_ADDR
  1268. ldr w0, [x1, x0]
  1269. ret
  1270. /*
  1271. * this function sets up the TrustZone Address Space Controller (TZASC)
  1272. * in: none
  1273. * out: none
  1274. * uses x0, x1
  1275. */
  1276. init_tzpc:
  1277. /*
  1278. * set Non Secure access for all devices protected via TZPC
  1279. * decode Protection-0 Set Reg
  1280. */
  1281. ldr x1, =TZPCDECPROT_0_SET_BASE
  1282. /* set decode region to NS, Bits[7:0] */
  1283. mov w0, #0xFF
  1284. str w0, [x1]
  1285. /* decode Protection-1 Set Reg */
  1286. ldr x1, =TZPCDECPROT_1_SET_BASE
  1287. /* set decode region to NS, Bits[7:0] */
  1288. mov w0, #0xFF
  1289. str w0, [x1]
  1290. /* decode Protection-2 Set Reg */
  1291. ldr x1, =TZPCDECPROT_2_SET_BASE
  1292. /* set decode region to NS, Bits[7:0] */
  1293. mov w0, #0xFF
  1294. str w0, [x1]
  1295. /*
  1296. * entire SRAM as NS
  1297. * secure RAM region size Reg
  1298. */
  1299. ldr x1, =NXP_OCRAM_TZPC_ADDR
  1300. /* 0x00000000 = no secure region */
  1301. mov w0, #0x00000000
  1302. str w0, [x1]
  1303. ret
  1304. /* this function performs initialization on SecMon for boot services */
  1305. initSecMon:
  1306. /* read the register hpcomr */
  1307. ldr x1, =NXP_SNVS_ADDR
  1308. ldr w0, [x1, #SECMON_HPCOMR_OFFSET]
  1309. /* turn off secure access for the privileged registers */
  1310. orr w0, w0, #SECMON_HPCOMR_NPSWAEN
  1311. /* write back */
  1312. str w0, [x1, #SECMON_HPCOMR_OFFSET]
  1313. ret
  1314. /*
  1315. * this function returns the redistributor base address for the core specified
  1316. * in x1
  1317. * in: x0 - core mask lsb of specified core
  1318. * out: x0 = redistributor rd base address for specified core
  1319. * uses x0, x1, x2
  1320. */
  1321. get_gic_rd_base:
  1322. /* get the 0-based core number */
  1323. clz w1, w0
  1324. mov w2, #0x20
  1325. sub w2, w2, w1
  1326. sub w2, w2, #1
  1327. /* x2 = core number / loop counter */
  1328. ldr x0, =NXP_GICR_ADDR
  1329. mov x1, #GIC_RD_OFFSET
  1330. 2:
  1331. cbz x2, 1f
  1332. add x0, x0, x1
  1333. sub x2, x2, #1
  1334. b 2b
  1335. 1:
  1336. ret
  1337. /*
  1338. * this function returns the redistributor base address for the core specified
  1339. * in x1
  1340. * in: x0 - core mask lsb of specified core
  1341. * out: x0 = redistributor sgi base address for specified core
  1342. * uses x0, x1, x2
  1343. */
  1344. get_gic_sgi_base:
  1345. /* get the 0-based core number */
  1346. clz w1, w0
  1347. mov w2, #0x20
  1348. sub w2, w2, w1
  1349. sub w2, w2, #1
  1350. /* x2 = core number / loop counter */
  1351. ldr x0, =NXP_GICR_SGI_ADDR
  1352. mov x1, #GIC_SGI_OFFSET
  1353. 2:
  1354. cbz x2, 1f
  1355. add x0, x0, x1
  1356. sub x2, x2, #1
  1357. b 2b
  1358. 1:
  1359. ret
  1360. /*
  1361. * this function returns an mpidr value for a core, given a core_mask_lsb
  1362. * in: x0 = core mask lsb
  1363. * out: x0 = affinity2:affinity1:affinity0, where affinity is 8-bits
  1364. * uses x0, x1
  1365. */
  1366. get_mpidr_value:
  1367. /* convert a core mask to an SoC core number */
  1368. clz w0, w0
  1369. mov w1, #31
  1370. sub w0, w1, w0
  1371. /* w0 = SoC core number */
  1372. mov w1, wzr
  1373. 2:
  1374. cmp w0, #CORES_PER_CLUSTER
  1375. b.lt 1f
  1376. sub w0, w0, #CORES_PER_CLUSTER
  1377. add w1, w1, #MPIDR_CLUSTER
  1378. b 2b
  1379. /* insert the mpidr core number */
  1380. 1:
  1381. orr w0, w1, w0
  1382. ret
  1383. /*
  1384. * write a register in the RESET block
  1385. * in: x0 = offset
  1386. * in: w1 = value to write
  1387. * uses x0, x1, x2
  1388. */
  1389. _write_reg_reset:
  1390. ldr x2, =NXP_RESET_ADDR
  1391. str w1, [x2, x0]
  1392. ret
  1393. /*
  1394. * read a register in the RESET block
  1395. * in: x0 = offset
  1396. * out: w0 = value read
  1397. * uses x0, x1
  1398. */
  1399. _read_reg_reset:
  1400. ldr x1, =NXP_RESET_ADDR
  1401. ldr w0, [x1, x0]
  1402. ret
  1403. /*
  1404. * this function will pwrdown ddr and the final core - it will do this
  1405. * by loading itself into the icache and then executing from there
  1406. * in: x5 = ipstpcr4 (IPSTPCR4_VALUE bic DEVDISR5_MASK)
  1407. * x6 = DDR_CNTRL_BASE_ADDR
  1408. * x7 = NXP_PMU_ADDR
  1409. * x8 = NXP_DCFG_ADDR
  1410. * x9 = 0, restartable
  1411. * = 1, non-restartable
  1412. * x10 = PMU_IPSTPCR4_OFFSET
  1413. * x11 = PMU_IPSTPACK4_OFFSET
  1414. * x12 = PMU_IPSTPCR3_OFFSET
  1415. * x18 = PMU_IPSTPCR2_OFFSET
  1416. * x19 = PMU_IPSTPCR1_OFFSET
  1417. * x21 = PMU_IPSTPCR0_OFFSET
  1418. * w13 = DEVDISR1 saved value
  1419. * w14 = DEVDISR2 saved value
  1420. * w15 = DEVDISR3 saved value
  1421. * w16 = DEVDISR4 saved value
  1422. * w17 = DEVDISR5 saved value
  1423. * x22 = DCFG_DEVDISR5_OFFSET
  1424. * x23 = NXP_EPU_ADDR
  1425. * out: none
  1426. * uses x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x13, x14, x15, x16, x17
  1427. * x10, x11, x12, x18, x19, x21, x22, x23
  1428. */
  1429. final_pwrdown:
  1430. /* delay */
  1431. mov w4, #0xffffff
  1432. 554:
  1433. sub w4, w4, #1
  1434. cmp w4, #0
  1435. b.ge 554b
  1436. mov x0, xzr
  1437. b touch_line_0
  1438. /* 4Kb aligned */
  1439. .align 12
  1440. start_line_0:
  1441. mov x0, #1
  1442. /* put ddr in self refresh - start */
  1443. mov x2, #DDR_SDRAM_CFG_2_FRCSR
  1444. ldr w3, [x6, #DDR_SDRAM_CFG_2_OFFSET]
  1445. orr w3, w3, w2
  1446. /* put ddr in self refresh - end */
  1447. str w3, [x6, #DDR_SDRAM_CFG_2_OFFSET]
  1448. nop
  1449. nop
  1450. touch_line_0:
  1451. cbz x0, touch_line_1
  1452. start_line_1:
  1453. /* quiesce ddr clocks - start */
  1454. orr w3, w5, #DCFG_DEVDISR5_MEM
  1455. mov w4, w3
  1456. /* quiesce ddr clocks - end */
  1457. str w4, [x7, x10]
  1458. mov w3, #DCFG_DEVDISR5_MEM
  1459. /* poll on ipstpack4 - start */
  1460. mov x2, #DDR_SLEEP_RETRY_CNT
  1461. nop
  1462. nop
  1463. touch_line_1:
  1464. cbz x0, touch_line_2
  1465. start_line_2:
  1466. /* x11 = PMU_IPSTPACK4_OFFSET */
  1467. ldr w1, [x7, x11]
  1468. tst w1, w3
  1469. b.ne 5f
  1470. subs x2, x2, #1
  1471. /* poll on ipstpack4 - end */
  1472. b.gt start_line_2
  1473. /* if we get here, we have a timeout err */
  1474. mov w4, w5
  1475. /* x10 = PMU_IPSTPCR4_OFFSET re-enable ddr clks interface */
  1476. str w4, [x7, x10]
  1477. touch_line_2:
  1478. cbz x0, touch_line_3
  1479. start_line_3:
  1480. /* load error code */
  1481. mov x0, #ERROR_DDR_SLEEP
  1482. b 2f
  1483. 5:
  1484. wfe
  1485. ldr w1, [x23, #EPU_EPCTR10_OFFSET]
  1486. cbz w1, 5b
  1487. mov w4, w5
  1488. touch_line_3:
  1489. cbz x0, touch_line_4
  1490. start_line_4:
  1491. /* re-enable ddr in devdisr5 */
  1492. str w4, [x8, x22]
  1493. /* re-enable ddr clk in ipstpcr4 */
  1494. str w4, [x7, x10]
  1495. 13:
  1496. /* poll on ipstpack4 - start */
  1497. ldr w1, [x7, x11]
  1498. tst w1, w3
  1499. b.eq 2f
  1500. nop
  1501. b 13b
  1502. /* poll on ipstpack4 - end */
  1503. 2:
  1504. touch_line_4:
  1505. cbz x0, touch_line_5
  1506. start_line_5:
  1507. /* take ddr out-of self refresh - start */
  1508. mov x2, #DDR_SDRAM_CFG_2_FRCSR
  1509. ldr w3, [x6, #DDR_SDRAM_CFG_2_OFFSET]
  1510. mov w4, w3
  1511. bic w4, w4, w2
  1512. mov w3, w4
  1513. /* wait for ddr cntrlr clock- start */
  1514. mov x1, #DDR_SLEEP_RETRY_CNT
  1515. 3:
  1516. subs x1, x1, #1
  1517. touch_line_5:
  1518. cbz x0, touch_line_6
  1519. start_line_6:
  1520. /* wait for ddr cntrlr clock - end */
  1521. b.gt 3b
  1522. /* take ddr out-of self refresh - end */
  1523. str w3, [x6, #DDR_SDRAM_CFG_2_OFFSET]
  1524. mov w1, w17
  1525. /* reset devdisr5 */
  1526. str w1, [x8, #DCFG_DEVDISR5_OFFSET]
  1527. mov w1, w16
  1528. /* reset devdisr4 */
  1529. str w1, [x8, #DCFG_DEVDISR4_OFFSET]
  1530. mov w1, w15
  1531. touch_line_6:
  1532. cbz x0, touch_line_7
  1533. start_line_7:
  1534. /* reset devdisr3 */
  1535. str w1, [x8, #DCFG_DEVDISR3_OFFSET]
  1536. mov w1, w14
  1537. /* reset devdisr2 */
  1538. str w1, [x8, #DCFG_DEVDISR2_OFFSET]
  1539. mov w1, w13
  1540. /* reset devdisr1 */
  1541. str w1, [x8, #DCFG_DEVDISR1_OFFSET]
  1542. /* reset ipstpcr4 */
  1543. str wzr, [x7, x10]
  1544. /* reset ipstpcr3 */
  1545. str wzr, [x7, x12]
  1546. touch_line_7:
  1547. cbz x0, touch_line_8
  1548. start_line_8:
  1549. /* reset ipstpcr2 */
  1550. str wzr, [x7, x18]
  1551. /* reset ipstpcr1 */
  1552. str wzr, [x7, x19]
  1553. /* reset ipstpcr0 */
  1554. str wzr, [x7, x21]
  1555. touch_line_8:
  1556. cbz x0, touch_line_9
  1557. start_line_9:
  1558. b continue_restart
  1559. touch_line_9:
  1560. cbz x0, start_line_0
  1561. /* execute here after ddr is back up */
  1562. continue_restart:
  1563. /*
  1564. * if x0 = 1, all is well
  1565. * if x0 < 1, we had an error
  1566. */
  1567. cmp x0, #1
  1568. b.ne 4f
  1569. mov x0, #0
  1570. 4:
  1571. ret