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).
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.
13 #include <linux/config.h>
14 #include <asm/processor.h>
16 #include <asm/ppc_asm.h>
17 #include <asm/cputable.h>
18 #include <asm/cache.h>
20 #define MAGIC 0x4c617273 /* 'Lars' */
23 * Structure for storing CPU registers on the stack.
29 #define SL_SPRG0 0x10 /* 4 sprg's */
41 #define SL_R12 0x70 /* r12 to r31 */
42 #define SL_SIZE (SL_R12 + 80)
47 #if defined(CONFIG_PMAC_PBOOK)
49 /* This gets called by via-pmu.c late during the sleep process.
50 * The PMU was already send the sleep command and will shut us down
51 * soon. We need to save all that is needed and setup the wakeup
52 * vector that will be called by the ROM on wakeup
54 _GLOBAL(low_sleep_handler)
69 /* Get a stable timebase and save it */
86 stw r4,SL_SPRG0+12(r1)
100 stw r4,SL_DBAT2+4(r1)
104 stw r4,SL_DBAT3+4(r1)
108 stw r4,SL_IBAT0+4(r1)
112 stw r4,SL_IBAT1+4(r1)
116 stw r4,SL_IBAT2+4(r1)
120 stw r4,SL_IBAT3+4(r1)
122 /* Backup various CPU config stuffs */
125 /* The ROM can wake us up via 2 different vectors:
126 * - On wallstreet & lombard, we must write a magic
127 * value 'Lars' at address 4 and a pointer to a
128 * memory location containing the PC to resume from
130 * - On Core99, we must store the wakeup vector at
131 * address 0x80 and eventually it's parameters
132 * at address 0x84. I've have some trouble with those
133 * parameters however and I no longer use them.
135 lis r5,grackle_wake_up@ha
136 addi r5,r5,grackle_wake_up@l
146 /* Setup stuffs at 0x80-0x84 for Core99 */
147 lis r3,core99_wake_up@ha
148 addi r3,r3,core99_wake_up@l
152 /* Store a pointer to our backup storage into
155 lis r3,sleep_storage@ha
156 addi r3,r3,sleep_storage@l
159 /* Disable DPM during cache flush */
166 /* Turn off data relocation. */
167 mfmsr r3 /* Save MSR in r7 */
168 rlwinm r3,r3,0,28,26 /* Turn off DR bit */
173 /* Flush & disable L1 cache */
174 bl __flush_disable_L1
177 * Set the HID0 and MSR for sleep.
180 rlwinm r2,r2,0,10,7 /* clear doze, nap */
181 oris r2,r2,HID0_SLEEP@h
187 /* This loop puts us back to sleep in case we have a spurrious
188 * wakeup so that the host bridge properly stays asleep. The
189 * CPU will be turned off, either after a known time (about 1
190 * second) on wallstreet & lombard, or as soon as the CPU enters
191 * SLEEP mode on core99
201 * Here is the resume code.
206 * Core99 machines resume here
207 * r4 has the physical address of SL_PC(sp) (unused)
209 _GLOBAL(core99_wake_up)
210 /* Make sure HID0 no longer contains any sleep bit */
212 rlwinm r3,r3,0,11,7 /* clear SLEEP, NAP, DOZE bits */
217 /* Won't that cause problems on CPU that doesn't support it ? */
223 ori r3,r3,MSR_EE|MSR_IP
224 xori r3,r3,MSR_EE|MSR_IP
231 /* Recover sleep storage */
232 lis r3,sleep_storage@ha
233 addi r3,r3,sleep_storage@l
237 /* Pass thru to older resume code ... */
239 * Here is the resume code for older machines.
240 * r1 has the physical address of SL_PC(sp).
244 /* Invalidate & enable L1 cache, we don't care about
245 * whatever the ROM may have tried to write to memory
249 /* Restore the kernel's segment registers before
250 * we do any r1 memory access as we are not sure they
251 * are in a sane state above the first 256Mb region
253 li r0,16 /* load up segment register values */
254 mtctr r0 /* for context 0 */
255 lis r3,0x2000 /* Ku = 1, VSID = 0 */
258 addi r3,r3,0x111 /* increment VSID */
259 addis r4,r4,0x1000 /* address of next segment */
266 /* Restore various CPU config stuffs */
267 bl __restore_cpu_setup
269 /* Restore the BATs, and SDR1. Then we can turn on the MMU. */
274 lwz r4,SL_SPRG0+4(r1)
276 lwz r4,SL_SPRG0+8(r1)
278 lwz r4,SL_SPRG0+12(r1)
283 lwz r4,SL_DBAT0+4(r1)
287 lwz r4,SL_DBAT1+4(r1)
291 lwz r4,SL_DBAT2+4(r1)
295 lwz r4,SL_DBAT3+4(r1)
299 lwz r4,SL_IBAT0+4(r1)
303 lwz r4,SL_IBAT1+4(r1)
307 lwz r4,SL_IBAT2+4(r1)
311 lwz r4,SL_IBAT3+4(r1)
332 END_FTR_SECTION_IFSET(CPU_FTR_HAS_HIGH_BATS)
336 1: addic. r4,r4,-0x1000
341 /* restore the MSR and turn on the MMU */
345 /* get back the stack pointer */
356 /* Restore the callee-saved registers and return */
375 #endif /* defined(CONFIG_PMAC_PBOOK) */
378 .balign L1_CACHE_LINE_SIZE
381 .balign L1_CACHE_LINE_SIZE, 0