sleep.S 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /*
  2. * This file contains sleep low-level functions for PowerBook G3.
  3. * Copyright (C) 1999 Benjamin Herrenschmidt (benh@kernel.crashing.org)
  4. * and Paul Mackerras (paulus@samba.org).
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. */
  12. #include <asm/processor.h>
  13. #include <asm/page.h>
  14. #include <asm/ppc_asm.h>
  15. #include <asm/cputable.h>
  16. #include <asm/cache.h>
  17. #include <asm/thread_info.h>
  18. #include <asm/asm-offsets.h>
  19. #include <asm/mmu.h>
  20. #define MAGIC 0x4c617273 /* 'Lars' */
  21. /*
  22. * Structure for storing CPU registers on the stack.
  23. */
  24. #define SL_SP 0
  25. #define SL_PC 4
  26. #define SL_MSR 8
  27. #define SL_SDR1 0xc
  28. #define SL_SPRG0 0x10 /* 4 sprg's */
  29. #define SL_DBAT0 0x20
  30. #define SL_IBAT0 0x28
  31. #define SL_DBAT1 0x30
  32. #define SL_IBAT1 0x38
  33. #define SL_DBAT2 0x40
  34. #define SL_IBAT2 0x48
  35. #define SL_DBAT3 0x50
  36. #define SL_IBAT3 0x58
  37. #define SL_TB 0x60
  38. #define SL_R2 0x68
  39. #define SL_CR 0x6c
  40. #define SL_R12 0x70 /* r12 to r31 */
  41. #define SL_SIZE (SL_R12 + 80)
  42. .section .text
  43. .align 5
  44. #if defined(CONFIG_PM) || defined(CONFIG_CPU_FREQ_PMAC) || \
  45. (defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PPC32))
  46. /* This gets called by via-pmu.c late during the sleep process.
  47. * The PMU was already send the sleep command and will shut us down
  48. * soon. We need to save all that is needed and setup the wakeup
  49. * vector that will be called by the ROM on wakeup
  50. */
  51. _GLOBAL(low_sleep_handler)
  52. #ifndef CONFIG_6xx
  53. blr
  54. #else
  55. mflr r0
  56. stw r0,4(r1)
  57. stwu r1,-SL_SIZE(r1)
  58. mfcr r0
  59. stw r0,SL_CR(r1)
  60. stw r2,SL_R2(r1)
  61. stmw r12,SL_R12(r1)
  62. /* Save MSR & SDR1 */
  63. mfmsr r4
  64. stw r4,SL_MSR(r1)
  65. mfsdr1 r4
  66. stw r4,SL_SDR1(r1)
  67. /* Get a stable timebase and save it */
  68. 1: mftbu r4
  69. stw r4,SL_TB(r1)
  70. mftb r5
  71. stw r5,SL_TB+4(r1)
  72. mftbu r3
  73. cmpw r3,r4
  74. bne 1b
  75. /* Save SPRGs */
  76. mfsprg r4,0
  77. stw r4,SL_SPRG0(r1)
  78. mfsprg r4,1
  79. stw r4,SL_SPRG0+4(r1)
  80. mfsprg r4,2
  81. stw r4,SL_SPRG0+8(r1)
  82. mfsprg r4,3
  83. stw r4,SL_SPRG0+12(r1)
  84. /* Save BATs */
  85. mfdbatu r4,0
  86. stw r4,SL_DBAT0(r1)
  87. mfdbatl r4,0
  88. stw r4,SL_DBAT0+4(r1)
  89. mfdbatu r4,1
  90. stw r4,SL_DBAT1(r1)
  91. mfdbatl r4,1
  92. stw r4,SL_DBAT1+4(r1)
  93. mfdbatu r4,2
  94. stw r4,SL_DBAT2(r1)
  95. mfdbatl r4,2
  96. stw r4,SL_DBAT2+4(r1)
  97. mfdbatu r4,3
  98. stw r4,SL_DBAT3(r1)
  99. mfdbatl r4,3
  100. stw r4,SL_DBAT3+4(r1)
  101. mfibatu r4,0
  102. stw r4,SL_IBAT0(r1)
  103. mfibatl r4,0
  104. stw r4,SL_IBAT0+4(r1)
  105. mfibatu r4,1
  106. stw r4,SL_IBAT1(r1)
  107. mfibatl r4,1
  108. stw r4,SL_IBAT1+4(r1)
  109. mfibatu r4,2
  110. stw r4,SL_IBAT2(r1)
  111. mfibatl r4,2
  112. stw r4,SL_IBAT2+4(r1)
  113. mfibatu r4,3
  114. stw r4,SL_IBAT3(r1)
  115. mfibatl r4,3
  116. stw r4,SL_IBAT3+4(r1)
  117. /* Backup various CPU config stuffs */
  118. bl __save_cpu_setup
  119. /* The ROM can wake us up via 2 different vectors:
  120. * - On wallstreet & lombard, we must write a magic
  121. * value 'Lars' at address 4 and a pointer to a
  122. * memory location containing the PC to resume from
  123. * at address 0.
  124. * - On Core99, we must store the wakeup vector at
  125. * address 0x80 and eventually it's parameters
  126. * at address 0x84. I've have some trouble with those
  127. * parameters however and I no longer use them.
  128. */
  129. lis r5,grackle_wake_up@ha
  130. addi r5,r5,grackle_wake_up@l
  131. tophys(r5,r5)
  132. stw r5,SL_PC(r1)
  133. lis r4,KERNELBASE@h
  134. tophys(r5,r1)
  135. addi r5,r5,SL_PC
  136. lis r6,MAGIC@ha
  137. addi r6,r6,MAGIC@l
  138. stw r5,0(r4)
  139. stw r6,4(r4)
  140. /* Setup stuffs at 0x80-0x84 for Core99 */
  141. lis r3,core99_wake_up@ha
  142. addi r3,r3,core99_wake_up@l
  143. tophys(r3,r3)
  144. stw r3,0x80(r4)
  145. stw r5,0x84(r4)
  146. /* Store a pointer to our backup storage into
  147. * a kernel global
  148. */
  149. lis r3,sleep_storage@ha
  150. addi r3,r3,sleep_storage@l
  151. stw r5,0(r3)
  152. .globl low_cpu_die
  153. low_cpu_die:
  154. /* Flush & disable all caches */
  155. bl flush_disable_caches
  156. /* Turn off data relocation. */
  157. mfmsr r3 /* Save MSR in r7 */
  158. rlwinm r3,r3,0,28,26 /* Turn off DR bit */
  159. sync
  160. mtmsr r3
  161. isync
  162. BEGIN_FTR_SECTION
  163. /* Flush any pending L2 data prefetches to work around HW bug */
  164. sync
  165. lis r3,0xfff0
  166. lwz r0,0(r3) /* perform cache-inhibited load to ROM */
  167. sync /* (caches are disabled at this point) */
  168. END_FTR_SECTION_IFSET(CPU_FTR_SPEC7450)
  169. /*
  170. * Set the HID0 and MSR for sleep.
  171. */
  172. mfspr r2,SPRN_HID0
  173. rlwinm r2,r2,0,10,7 /* clear doze, nap */
  174. oris r2,r2,HID0_SLEEP@h
  175. sync
  176. isync
  177. mtspr SPRN_HID0,r2
  178. sync
  179. /* This loop puts us back to sleep in case we have a spurrious
  180. * wakeup so that the host bridge properly stays asleep. The
  181. * CPU will be turned off, either after a known time (about 1
  182. * second) on wallstreet & lombard, or as soon as the CPU enters
  183. * SLEEP mode on core99
  184. */
  185. mfmsr r2
  186. oris r2,r2,MSR_POW@h
  187. 1: sync
  188. mtmsr r2
  189. isync
  190. b 1b
  191. /*
  192. * Here is the resume code.
  193. */
  194. /*
  195. * Core99 machines resume here
  196. * r4 has the physical address of SL_PC(sp) (unused)
  197. */
  198. _GLOBAL(core99_wake_up)
  199. /* Make sure HID0 no longer contains any sleep bit and that data cache
  200. * is disabled
  201. */
  202. mfspr r3,SPRN_HID0
  203. rlwinm r3,r3,0,11,7 /* clear SLEEP, NAP, DOZE bits */
  204. rlwinm 3,r3,0,18,15 /* clear DCE, ICE */
  205. mtspr SPRN_HID0,r3
  206. sync
  207. isync
  208. /* sanitize MSR */
  209. mfmsr r3
  210. ori r3,r3,MSR_EE|MSR_IP
  211. xori r3,r3,MSR_EE|MSR_IP
  212. sync
  213. isync
  214. mtmsr r3
  215. sync
  216. isync
  217. /* Recover sleep storage */
  218. lis r3,sleep_storage@ha
  219. addi r3,r3,sleep_storage@l
  220. tophys(r3,r3)
  221. lwz r1,0(r3)
  222. /* Pass thru to older resume code ... */
  223. /*
  224. * Here is the resume code for older machines.
  225. * r1 has the physical address of SL_PC(sp).
  226. */
  227. grackle_wake_up:
  228. /* Restore the kernel's segment registers before
  229. * we do any r1 memory access as we are not sure they
  230. * are in a sane state above the first 256Mb region
  231. */
  232. li r0,16 /* load up segment register values */
  233. mtctr r0 /* for context 0 */
  234. lis r3,0x2000 /* Ku = 1, VSID = 0 */
  235. li r4,0
  236. 3: mtsrin r3,r4
  237. addi r3,r3,0x111 /* increment VSID */
  238. addis r4,r4,0x1000 /* address of next segment */
  239. bdnz 3b
  240. sync
  241. isync
  242. subi r1,r1,SL_PC
  243. /* Restore various CPU config stuffs */
  244. bl __restore_cpu_setup
  245. /* Make sure all FPRs have been initialized */
  246. bl reloc_offset
  247. bl __init_fpu_registers
  248. /* Invalidate & enable L1 cache, we don't care about
  249. * whatever the ROM may have tried to write to memory
  250. */
  251. bl __inval_enable_L1
  252. /* Restore the BATs, and SDR1. Then we can turn on the MMU. */
  253. lwz r4,SL_SDR1(r1)
  254. mtsdr1 r4
  255. lwz r4,SL_SPRG0(r1)
  256. mtsprg 0,r4
  257. lwz r4,SL_SPRG0+4(r1)
  258. mtsprg 1,r4
  259. lwz r4,SL_SPRG0+8(r1)
  260. mtsprg 2,r4
  261. lwz r4,SL_SPRG0+12(r1)
  262. mtsprg 3,r4
  263. lwz r4,SL_DBAT0(r1)
  264. mtdbatu 0,r4
  265. lwz r4,SL_DBAT0+4(r1)
  266. mtdbatl 0,r4
  267. lwz r4,SL_DBAT1(r1)
  268. mtdbatu 1,r4
  269. lwz r4,SL_DBAT1+4(r1)
  270. mtdbatl 1,r4
  271. lwz r4,SL_DBAT2(r1)
  272. mtdbatu 2,r4
  273. lwz r4,SL_DBAT2+4(r1)
  274. mtdbatl 2,r4
  275. lwz r4,SL_DBAT3(r1)
  276. mtdbatu 3,r4
  277. lwz r4,SL_DBAT3+4(r1)
  278. mtdbatl 3,r4
  279. lwz r4,SL_IBAT0(r1)
  280. mtibatu 0,r4
  281. lwz r4,SL_IBAT0+4(r1)
  282. mtibatl 0,r4
  283. lwz r4,SL_IBAT1(r1)
  284. mtibatu 1,r4
  285. lwz r4,SL_IBAT1+4(r1)
  286. mtibatl 1,r4
  287. lwz r4,SL_IBAT2(r1)
  288. mtibatu 2,r4
  289. lwz r4,SL_IBAT2+4(r1)
  290. mtibatl 2,r4
  291. lwz r4,SL_IBAT3(r1)
  292. mtibatu 3,r4
  293. lwz r4,SL_IBAT3+4(r1)
  294. mtibatl 3,r4
  295. BEGIN_MMU_FTR_SECTION
  296. li r4,0
  297. mtspr SPRN_DBAT4U,r4
  298. mtspr SPRN_DBAT4L,r4
  299. mtspr SPRN_DBAT5U,r4
  300. mtspr SPRN_DBAT5L,r4
  301. mtspr SPRN_DBAT6U,r4
  302. mtspr SPRN_DBAT6L,r4
  303. mtspr SPRN_DBAT7U,r4
  304. mtspr SPRN_DBAT7L,r4
  305. mtspr SPRN_IBAT4U,r4
  306. mtspr SPRN_IBAT4L,r4
  307. mtspr SPRN_IBAT5U,r4
  308. mtspr SPRN_IBAT5L,r4
  309. mtspr SPRN_IBAT6U,r4
  310. mtspr SPRN_IBAT6L,r4
  311. mtspr SPRN_IBAT7U,r4
  312. mtspr SPRN_IBAT7L,r4
  313. END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
  314. /* Flush all TLBs */
  315. lis r4,0x1000
  316. 1: addic. r4,r4,-0x1000
  317. tlbie r4
  318. blt 1b
  319. sync
  320. /* restore the MSR and turn on the MMU */
  321. lwz r3,SL_MSR(r1)
  322. bl turn_on_mmu
  323. /* get back the stack pointer */
  324. tovirt(r1,r1)
  325. /* Restore TB */
  326. li r3,0
  327. mttbl r3
  328. lwz r3,SL_TB(r1)
  329. lwz r4,SL_TB+4(r1)
  330. mttbu r3
  331. mttbl r4
  332. /* Restore the callee-saved registers and return */
  333. lwz r0,SL_CR(r1)
  334. mtcr r0
  335. lwz r2,SL_R2(r1)
  336. lmw r12,SL_R12(r1)
  337. addi r1,r1,SL_SIZE
  338. lwz r0,4(r1)
  339. mtlr r0
  340. blr
  341. turn_on_mmu:
  342. mflr r4
  343. tovirt(r4,r4)
  344. mtsrr0 r4
  345. mtsrr1 r3
  346. sync
  347. isync
  348. rfi
  349. #endif /* defined(CONFIG_PM) || defined(CONFIG_CPU_FREQ) */
  350. .section .data
  351. .balign L1_CACHE_BYTES
  352. sleep_storage:
  353. .long 0
  354. .balign L1_CACHE_BYTES, 0
  355. #endif /* CONFIG_6xx */
  356. .section .text