suspend-asm.S 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Enter and leave deep sleep state on MPC83xx
  4. *
  5. * Copyright (c) 2006-2008 Freescale Semiconductor, Inc.
  6. * Author: Scott Wood <[email protected]>
  7. */
  8. #include <asm/page.h>
  9. #include <asm/ppc_asm.h>
  10. #include <asm/reg.h>
  11. #include <asm/asm-offsets.h>
  12. #define SS_MEMSAVE 0x00 /* First 8 bytes of RAM */
  13. #define SS_HID 0x08 /* 3 HIDs */
  14. #define SS_IABR 0x14 /* 2 IABRs */
  15. #define SS_IBCR 0x1c
  16. #define SS_DABR 0x20 /* 2 DABRs */
  17. #define SS_DBCR 0x28
  18. #define SS_SP 0x2c
  19. #define SS_SR 0x30 /* 16 segment registers */
  20. #define SS_R2 0x70
  21. #define SS_MSR 0x74
  22. #define SS_SDR1 0x78
  23. #define SS_LR 0x7c
  24. #define SS_SPRG 0x80 /* 8 SPRGs */
  25. #define SS_DBAT 0xa0 /* 8 DBATs */
  26. #define SS_IBAT 0xe0 /* 8 IBATs */
  27. #define SS_TB 0x120
  28. #define SS_CR 0x128
  29. #define SS_GPREG 0x12c /* r12-r31 */
  30. #define STATE_SAVE_SIZE 0x17c
  31. .section .data
  32. .align 5
  33. mpc83xx_sleep_save_area:
  34. .space STATE_SAVE_SIZE
  35. immrbase:
  36. .long 0
  37. .section .text
  38. .align 5
  39. /* r3 = physical address of IMMR */
  40. _GLOBAL(mpc83xx_enter_deep_sleep)
  41. lis r4, immrbase@ha
  42. stw r3, immrbase@l(r4)
  43. /* The first 2 words of memory are used to communicate with the
  44. * bootloader, to tell it how to resume.
  45. *
  46. * The first word is the magic number 0xf5153ae5, and the second
  47. * is the pointer to mpc83xx_deep_resume.
  48. *
  49. * The original content of these two words is saved in SS_MEMSAVE.
  50. */
  51. lis r3, mpc83xx_sleep_save_area@h
  52. ori r3, r3, mpc83xx_sleep_save_area@l
  53. lis r4, KERNELBASE@h
  54. lwz r5, 0(r4)
  55. lwz r6, 4(r4)
  56. stw r5, SS_MEMSAVE+0(r3)
  57. stw r6, SS_MEMSAVE+4(r3)
  58. mfspr r5, SPRN_HID0
  59. mfspr r6, SPRN_HID1
  60. mfspr r7, SPRN_HID2
  61. stw r5, SS_HID+0(r3)
  62. stw r6, SS_HID+4(r3)
  63. stw r7, SS_HID+8(r3)
  64. mfspr r4, SPRN_IABR
  65. mfspr r5, SPRN_IABR2
  66. mfspr r6, SPRN_IBCR
  67. mfspr r7, SPRN_DABR
  68. mfspr r8, SPRN_DABR2
  69. mfspr r9, SPRN_DBCR
  70. stw r4, SS_IABR+0(r3)
  71. stw r5, SS_IABR+4(r3)
  72. stw r6, SS_IBCR(r3)
  73. stw r7, SS_DABR+0(r3)
  74. stw r8, SS_DABR+4(r3)
  75. stw r9, SS_DBCR(r3)
  76. mfspr r4, SPRN_SPRG0
  77. mfspr r5, SPRN_SPRG1
  78. mfspr r6, SPRN_SPRG2
  79. mfspr r7, SPRN_SPRG3
  80. mfsdr1 r8
  81. stw r4, SS_SPRG+0(r3)
  82. stw r5, SS_SPRG+4(r3)
  83. stw r6, SS_SPRG+8(r3)
  84. stw r7, SS_SPRG+12(r3)
  85. stw r8, SS_SDR1(r3)
  86. mfspr r4, SPRN_SPRG4
  87. mfspr r5, SPRN_SPRG5
  88. mfspr r6, SPRN_SPRG6
  89. mfspr r7, SPRN_SPRG7
  90. stw r4, SS_SPRG+16(r3)
  91. stw r5, SS_SPRG+20(r3)
  92. stw r6, SS_SPRG+24(r3)
  93. stw r7, SS_SPRG+28(r3)
  94. mfspr r4, SPRN_DBAT0U
  95. mfspr r5, SPRN_DBAT0L
  96. mfspr r6, SPRN_DBAT1U
  97. mfspr r7, SPRN_DBAT1L
  98. stw r4, SS_DBAT+0x00(r3)
  99. stw r5, SS_DBAT+0x04(r3)
  100. stw r6, SS_DBAT+0x08(r3)
  101. stw r7, SS_DBAT+0x0c(r3)
  102. mfspr r4, SPRN_DBAT2U
  103. mfspr r5, SPRN_DBAT2L
  104. mfspr r6, SPRN_DBAT3U
  105. mfspr r7, SPRN_DBAT3L
  106. stw r4, SS_DBAT+0x10(r3)
  107. stw r5, SS_DBAT+0x14(r3)
  108. stw r6, SS_DBAT+0x18(r3)
  109. stw r7, SS_DBAT+0x1c(r3)
  110. mfspr r4, SPRN_DBAT4U
  111. mfspr r5, SPRN_DBAT4L
  112. mfspr r6, SPRN_DBAT5U
  113. mfspr r7, SPRN_DBAT5L
  114. stw r4, SS_DBAT+0x20(r3)
  115. stw r5, SS_DBAT+0x24(r3)
  116. stw r6, SS_DBAT+0x28(r3)
  117. stw r7, SS_DBAT+0x2c(r3)
  118. mfspr r4, SPRN_DBAT6U
  119. mfspr r5, SPRN_DBAT6L
  120. mfspr r6, SPRN_DBAT7U
  121. mfspr r7, SPRN_DBAT7L
  122. stw r4, SS_DBAT+0x30(r3)
  123. stw r5, SS_DBAT+0x34(r3)
  124. stw r6, SS_DBAT+0x38(r3)
  125. stw r7, SS_DBAT+0x3c(r3)
  126. mfspr r4, SPRN_IBAT0U
  127. mfspr r5, SPRN_IBAT0L
  128. mfspr r6, SPRN_IBAT1U
  129. mfspr r7, SPRN_IBAT1L
  130. stw r4, SS_IBAT+0x00(r3)
  131. stw r5, SS_IBAT+0x04(r3)
  132. stw r6, SS_IBAT+0x08(r3)
  133. stw r7, SS_IBAT+0x0c(r3)
  134. mfspr r4, SPRN_IBAT2U
  135. mfspr r5, SPRN_IBAT2L
  136. mfspr r6, SPRN_IBAT3U
  137. mfspr r7, SPRN_IBAT3L
  138. stw r4, SS_IBAT+0x10(r3)
  139. stw r5, SS_IBAT+0x14(r3)
  140. stw r6, SS_IBAT+0x18(r3)
  141. stw r7, SS_IBAT+0x1c(r3)
  142. mfspr r4, SPRN_IBAT4U
  143. mfspr r5, SPRN_IBAT4L
  144. mfspr r6, SPRN_IBAT5U
  145. mfspr r7, SPRN_IBAT5L
  146. stw r4, SS_IBAT+0x20(r3)
  147. stw r5, SS_IBAT+0x24(r3)
  148. stw r6, SS_IBAT+0x28(r3)
  149. stw r7, SS_IBAT+0x2c(r3)
  150. mfspr r4, SPRN_IBAT6U
  151. mfspr r5, SPRN_IBAT6L
  152. mfspr r6, SPRN_IBAT7U
  153. mfspr r7, SPRN_IBAT7L
  154. stw r4, SS_IBAT+0x30(r3)
  155. stw r5, SS_IBAT+0x34(r3)
  156. stw r6, SS_IBAT+0x38(r3)
  157. stw r7, SS_IBAT+0x3c(r3)
  158. mfmsr r4
  159. mflr r5
  160. mfcr r6
  161. stw r4, SS_MSR(r3)
  162. stw r5, SS_LR(r3)
  163. stw r6, SS_CR(r3)
  164. stw r1, SS_SP(r3)
  165. stw r2, SS_R2(r3)
  166. 1: mftbu r4
  167. mftb r5
  168. mftbu r6
  169. cmpw r4, r6
  170. bne 1b
  171. stw r4, SS_TB+0(r3)
  172. stw r5, SS_TB+4(r3)
  173. stmw r12, SS_GPREG(r3)
  174. li r4, 0
  175. addi r6, r3, SS_SR-4
  176. 1: mfsrin r5, r4
  177. stwu r5, 4(r6)
  178. addis r4, r4, 0x1000
  179. cmpwi r4, 0
  180. bne 1b
  181. /* Disable machine checks and critical exceptions */
  182. mfmsr r4
  183. rlwinm r4, r4, 0, ~MSR_CE
  184. rlwinm r4, r4, 0, ~MSR_ME
  185. mtmsr r4
  186. isync
  187. #define TMP_VIRT_IMMR 0xf0000000
  188. #define DEFAULT_IMMR_VALUE 0xff400000
  189. #define IMMRBAR_BASE 0x0000
  190. lis r4, immrbase@ha
  191. lwz r4, immrbase@l(r4)
  192. /* Use DBAT0 to address the current IMMR space */
  193. ori r4, r4, 0x002a
  194. mtspr SPRN_DBAT0L, r4
  195. lis r8, TMP_VIRT_IMMR@h
  196. ori r4, r8, 0x001e /* 1 MByte accessible from Kernel Space only */
  197. mtspr SPRN_DBAT0U, r4
  198. isync
  199. /* Use DBAT1 to address the original IMMR space */
  200. lis r4, DEFAULT_IMMR_VALUE@h
  201. ori r4, r4, 0x002a
  202. mtspr SPRN_DBAT1L, r4
  203. lis r9, (TMP_VIRT_IMMR + 0x01000000)@h
  204. ori r4, r9, 0x001e /* 1 MByte accessible from Kernel Space only */
  205. mtspr SPRN_DBAT1U, r4
  206. isync
  207. /* Use DBAT2 to address the beginning of RAM. This isn't done
  208. * using the normal virtual mapping, because with page debugging
  209. * enabled it will be read-only.
  210. */
  211. li r4, 0x0002
  212. mtspr SPRN_DBAT2L, r4
  213. lis r4, KERNELBASE@h
  214. ori r4, r4, 0x001e /* 1 MByte accessible from Kernel Space only */
  215. mtspr SPRN_DBAT2U, r4
  216. isync
  217. /* Flush the cache with our BAT, as there will be TLB misses
  218. * otherwise if page debugging is enabled, and these misses
  219. * will disturb the PLRU algorithm.
  220. */
  221. bl __flush_disable_L1
  222. /* Keep the i-cache enabled, so the hack below for low-boot
  223. * flash will work.
  224. */
  225. mfspr r3, SPRN_HID0
  226. ori r3, r3, HID0_ICE
  227. mtspr SPRN_HID0, r3
  228. isync
  229. lis r6, 0xf515
  230. ori r6, r6, 0x3ae5
  231. lis r7, mpc83xx_deep_resume@h
  232. ori r7, r7, mpc83xx_deep_resume@l
  233. tophys(r7, r7)
  234. lis r5, KERNELBASE@h
  235. stw r6, 0(r5)
  236. stw r7, 4(r5)
  237. /* Reset BARs */
  238. li r4, 0
  239. stw r4, 0x0024(r8)
  240. stw r4, 0x002c(r8)
  241. stw r4, 0x0034(r8)
  242. stw r4, 0x003c(r8)
  243. stw r4, 0x0064(r8)
  244. stw r4, 0x006c(r8)
  245. /* Rev 1 of the 8313 has problems with wakeup events that are
  246. * pending during the transition to deep sleep state (such as if
  247. * the PCI host sets the state to D3 and then D0 in rapid
  248. * succession). This check shrinks the race window somewhat.
  249. *
  250. * See erratum PCI23, though the problem is not limited
  251. * to PCI.
  252. */
  253. lwz r3, 0x0b04(r8)
  254. andi. r3, r3, 1
  255. bne- mpc83xx_deep_resume
  256. /* Move IMMR back to the default location, following the
  257. * procedure specified in the MPC8313 manual.
  258. */
  259. lwz r4, IMMRBAR_BASE(r8)
  260. isync
  261. lis r4, DEFAULT_IMMR_VALUE@h
  262. stw r4, IMMRBAR_BASE(r8)
  263. lis r4, KERNELBASE@h
  264. lwz r4, 0(r4)
  265. isync
  266. lwz r4, IMMRBAR_BASE(r9)
  267. mr r8, r9
  268. isync
  269. /* Check the Reset Configuration Word to see whether flash needs
  270. * to be mapped at a low address or a high address.
  271. */
  272. lwz r4, 0x0904(r8)
  273. andis. r4, r4, 0x0400
  274. li r4, 0
  275. beq boot_low
  276. lis r4, 0xff80
  277. boot_low:
  278. stw r4, 0x0020(r8)
  279. lis r7, 0x8000
  280. ori r7, r7, 0x0016
  281. mfspr r5, SPRN_HID0
  282. rlwinm r5, r5, 0, ~(HID0_DOZE | HID0_NAP)
  283. oris r5, r5, HID0_SLEEP@h
  284. mtspr SPRN_HID0, r5
  285. isync
  286. mfmsr r5
  287. oris r5, r5, MSR_POW@h
  288. /* Enable the flash mapping at the appropriate address. This
  289. * mapping will override the RAM mapping if booting low, so there's
  290. * no need to disable the latter. This must be done inside the same
  291. * cache line as setting MSR_POW, so that no instruction fetches
  292. * from RAM happen after the flash mapping is turned on.
  293. */
  294. .align 5
  295. stw r7, 0x0024(r8)
  296. sync
  297. isync
  298. mtmsr r5
  299. isync
  300. 1: b 1b
  301. mpc83xx_deep_resume:
  302. lis r4, 1f@h
  303. ori r4, r4, 1f@l
  304. tophys(r4, r4)
  305. mtsrr0 r4
  306. mfmsr r4
  307. rlwinm r4, r4, 0, ~(MSR_IR | MSR_DR)
  308. mtsrr1 r4
  309. rfi
  310. 1: tlbia
  311. bl __inval_enable_L1
  312. lis r3, mpc83xx_sleep_save_area@h
  313. ori r3, r3, mpc83xx_sleep_save_area@l
  314. tophys(r3, r3)
  315. lwz r5, SS_MEMSAVE+0(r3)
  316. lwz r6, SS_MEMSAVE+4(r3)
  317. stw r5, 0(0)
  318. stw r6, 4(0)
  319. lwz r5, SS_HID+0(r3)
  320. lwz r6, SS_HID+4(r3)
  321. lwz r7, SS_HID+8(r3)
  322. mtspr SPRN_HID0, r5
  323. mtspr SPRN_HID1, r6
  324. mtspr SPRN_HID2, r7
  325. lwz r4, SS_IABR+0(r3)
  326. lwz r5, SS_IABR+4(r3)
  327. lwz r6, SS_IBCR(r3)
  328. lwz r7, SS_DABR+0(r3)
  329. lwz r8, SS_DABR+4(r3)
  330. lwz r9, SS_DBCR(r3)
  331. mtspr SPRN_IABR, r4
  332. mtspr SPRN_IABR2, r5
  333. mtspr SPRN_IBCR, r6
  334. mtspr SPRN_DABR, r7
  335. mtspr SPRN_DABR2, r8
  336. mtspr SPRN_DBCR, r9
  337. li r4, 0
  338. addi r6, r3, SS_SR-4
  339. 1: lwzu r5, 4(r6)
  340. mtsrin r5, r4
  341. addis r4, r4, 0x1000
  342. cmpwi r4, 0
  343. bne 1b
  344. lwz r4, SS_DBAT+0x00(r3)
  345. lwz r5, SS_DBAT+0x04(r3)
  346. lwz r6, SS_DBAT+0x08(r3)
  347. lwz r7, SS_DBAT+0x0c(r3)
  348. mtspr SPRN_DBAT0U, r4
  349. mtspr SPRN_DBAT0L, r5
  350. mtspr SPRN_DBAT1U, r6
  351. mtspr SPRN_DBAT1L, r7
  352. lwz r4, SS_DBAT+0x10(r3)
  353. lwz r5, SS_DBAT+0x14(r3)
  354. lwz r6, SS_DBAT+0x18(r3)
  355. lwz r7, SS_DBAT+0x1c(r3)
  356. mtspr SPRN_DBAT2U, r4
  357. mtspr SPRN_DBAT2L, r5
  358. mtspr SPRN_DBAT3U, r6
  359. mtspr SPRN_DBAT3L, r7
  360. lwz r4, SS_DBAT+0x20(r3)
  361. lwz r5, SS_DBAT+0x24(r3)
  362. lwz r6, SS_DBAT+0x28(r3)
  363. lwz r7, SS_DBAT+0x2c(r3)
  364. mtspr SPRN_DBAT4U, r4
  365. mtspr SPRN_DBAT4L, r5
  366. mtspr SPRN_DBAT5U, r6
  367. mtspr SPRN_DBAT5L, r7
  368. lwz r4, SS_DBAT+0x30(r3)
  369. lwz r5, SS_DBAT+0x34(r3)
  370. lwz r6, SS_DBAT+0x38(r3)
  371. lwz r7, SS_DBAT+0x3c(r3)
  372. mtspr SPRN_DBAT6U, r4
  373. mtspr SPRN_DBAT6L, r5
  374. mtspr SPRN_DBAT7U, r6
  375. mtspr SPRN_DBAT7L, r7
  376. lwz r4, SS_IBAT+0x00(r3)
  377. lwz r5, SS_IBAT+0x04(r3)
  378. lwz r6, SS_IBAT+0x08(r3)
  379. lwz r7, SS_IBAT+0x0c(r3)
  380. mtspr SPRN_IBAT0U, r4
  381. mtspr SPRN_IBAT0L, r5
  382. mtspr SPRN_IBAT1U, r6
  383. mtspr SPRN_IBAT1L, r7
  384. lwz r4, SS_IBAT+0x10(r3)
  385. lwz r5, SS_IBAT+0x14(r3)
  386. lwz r6, SS_IBAT+0x18(r3)
  387. lwz r7, SS_IBAT+0x1c(r3)
  388. mtspr SPRN_IBAT2U, r4
  389. mtspr SPRN_IBAT2L, r5
  390. mtspr SPRN_IBAT3U, r6
  391. mtspr SPRN_IBAT3L, r7
  392. lwz r4, SS_IBAT+0x20(r3)
  393. lwz r5, SS_IBAT+0x24(r3)
  394. lwz r6, SS_IBAT+0x28(r3)
  395. lwz r7, SS_IBAT+0x2c(r3)
  396. mtspr SPRN_IBAT4U, r4
  397. mtspr SPRN_IBAT4L, r5
  398. mtspr SPRN_IBAT5U, r6
  399. mtspr SPRN_IBAT5L, r7
  400. lwz r4, SS_IBAT+0x30(r3)
  401. lwz r5, SS_IBAT+0x34(r3)
  402. lwz r6, SS_IBAT+0x38(r3)
  403. lwz r7, SS_IBAT+0x3c(r3)
  404. mtspr SPRN_IBAT6U, r4
  405. mtspr SPRN_IBAT6L, r5
  406. mtspr SPRN_IBAT7U, r6
  407. mtspr SPRN_IBAT7L, r7
  408. lwz r4, SS_SPRG+16(r3)
  409. lwz r5, SS_SPRG+20(r3)
  410. lwz r6, SS_SPRG+24(r3)
  411. lwz r7, SS_SPRG+28(r3)
  412. mtspr SPRN_SPRG4, r4
  413. mtspr SPRN_SPRG5, r5
  414. mtspr SPRN_SPRG6, r6
  415. mtspr SPRN_SPRG7, r7
  416. lwz r4, SS_SPRG+0(r3)
  417. lwz r5, SS_SPRG+4(r3)
  418. lwz r6, SS_SPRG+8(r3)
  419. lwz r7, SS_SPRG+12(r3)
  420. lwz r8, SS_SDR1(r3)
  421. mtspr SPRN_SPRG0, r4
  422. mtspr SPRN_SPRG1, r5
  423. mtspr SPRN_SPRG2, r6
  424. mtspr SPRN_SPRG3, r7
  425. mtsdr1 r8
  426. lwz r4, SS_MSR(r3)
  427. lwz r5, SS_LR(r3)
  428. lwz r6, SS_CR(r3)
  429. lwz r1, SS_SP(r3)
  430. lwz r2, SS_R2(r3)
  431. mtsrr1 r4
  432. mtsrr0 r5
  433. mtcr r6
  434. li r4, 0
  435. mtspr SPRN_TBWL, r4
  436. lwz r4, SS_TB+0(r3)
  437. lwz r5, SS_TB+4(r3)
  438. mtspr SPRN_TBWU, r4
  439. mtspr SPRN_TBWL, r5
  440. lmw r12, SS_GPREG(r3)
  441. /* Kick decrementer */
  442. li r0, 1
  443. mtdec r0
  444. rfi
  445. _ASM_NOKPROBE_SYMBOL(mpc83xx_deep_resume)