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