1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * This file contains sleep low-level functions for PowerBook G3.
4 * Copyright (C) 1999 Benjamin Herrenschmidt (benh@kernel.crashing.org)
5 * and Paul Mackerras (paulus@samba.org).
8 #include <asm/processor.h>
10 #include <asm/ppc_asm.h>
11 #include <asm/cputable.h>
12 #include <asm/cache.h>
13 #include <asm/thread_info.h>
14 #include <asm/asm-offsets.h>
16 #include <asm/feature-fixups.h>
18 #define MAGIC 0x4c617273 /* 'Lars' */
21 * Structure for storing CPU registers on the stack.
27 #define SL_SPRG0 0x10 /* 4 sprg's */
48 #define SL_R12 0xb4 /* r12 to r31 */
49 #define SL_SIZE (SL_R12 + 80)
54 #if defined(CONFIG_PM) || defined(CONFIG_CPU_FREQ_PMAC) || \
55 (defined(CONFIG_HOTPLUG_CPU) && defined(CONFIG_PPC32))
57 /* This gets called by via-pmu.c late during the sleep process.
58 * The PMU was already send the sleep command and will shut us down
59 * soon. We need to save all that is needed and setup the wakeup
60 * vector that will be called by the ROM on wakeup
62 _GLOBAL(low_sleep_handler)
63 #ifndef CONFIG_PPC_BOOK3S_32
67 lis r11,sleep_storage@ha
68 addi r11,r11,sleep_storage@l
82 /* Get a stable timebase and save it */
95 stw r4,SL_SPRG0+4(r11)
97 stw r4,SL_SPRG0+8(r11)
99 stw r4,SL_SPRG0+12(r11)
105 stw r4,SL_DBAT0+4(r11)
109 stw r4,SL_DBAT1+4(r11)
113 stw r4,SL_DBAT2+4(r11)
117 stw r4,SL_DBAT3+4(r11)
121 stw r4,SL_IBAT0+4(r11)
125 stw r4,SL_IBAT1+4(r11)
129 stw r4,SL_IBAT2+4(r11)
133 stw r4,SL_IBAT3+4(r11)
135 BEGIN_MMU_FTR_SECTION
139 stw r4,SL_DBAT4+4(r11)
143 stw r4,SL_DBAT5+4(r11)
147 stw r4,SL_DBAT6+4(r11)
151 stw r4,SL_DBAT7+4(r11)
155 stw r4,SL_IBAT4+4(r11)
159 stw r4,SL_IBAT5+4(r11)
163 stw r4,SL_IBAT6+4(r11)
167 stw r4,SL_IBAT7+4(r11)
168 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
170 /* Backup various CPU config stuffs */
173 /* The ROM can wake us up via 2 different vectors:
174 * - On wallstreet & lombard, we must write a magic
175 * value 'Lars' at address 4 and a pointer to a
176 * memory location containing the PC to resume from
178 * - On Core99, we must store the wakeup vector at
179 * address 0x80 and eventually it's parameters
180 * at address 0x84. I've have some trouble with those
181 * parameters however and I no longer use them.
183 lis r5,grackle_wake_up@ha
184 addi r5,r5,grackle_wake_up@l
194 /* Setup stuffs at 0x80-0x84 for Core99 */
195 lis r3,core99_wake_up@ha
196 addi r3,r3,core99_wake_up@l
201 .globl low_cpu_offline_self
202 low_cpu_offline_self:
203 /* Flush & disable all caches */
204 bl flush_disable_caches
206 /* Turn off data relocation. */
207 mfmsr r3 /* Save MSR in r7 */
208 rlwinm r3,r3,0,28,26 /* Turn off DR bit */
214 /* Flush any pending L2 data prefetches to work around HW bug */
217 lwz r0,0(r3) /* perform cache-inhibited load to ROM */
218 sync /* (caches are disabled at this point) */
219 END_FTR_SECTION_IFSET(CPU_FTR_SPEC7450)
222 * Set the HID0 and MSR for sleep.
225 rlwinm r2,r2,0,10,7 /* clear doze, nap */
226 oris r2,r2,HID0_SLEEP@h
232 /* This loop puts us back to sleep in case we have a spurrious
233 * wakeup so that the host bridge properly stays asleep. The
234 * CPU will be turned off, either after a known time (about 1
235 * second) on wallstreet & lombard, or as soon as the CPU enters
236 * SLEEP mode on core99
244 _ASM_NOKPROBE_SYMBOL(low_cpu_offline_self)
246 * Here is the resume code.
251 * Core99 machines resume here
252 * r4 has the physical address of SL_PC(sp) (unused)
254 _GLOBAL(core99_wake_up)
255 /* Make sure HID0 no longer contains any sleep bit and that data cache
259 rlwinm r3,r3,0,11,7 /* clear SLEEP, NAP, DOZE bits */
260 rlwinm 3,r3,0,18,15 /* clear DCE, ICE */
267 ori r3,r3,MSR_EE|MSR_IP
268 xori r3,r3,MSR_EE|MSR_IP
275 /* Recover sleep storage */
276 lis r3,sleep_storage@ha
277 addi r3,r3,sleep_storage@l
281 /* Pass thru to older resume code ... */
282 _ASM_NOKPROBE_SYMBOL(core99_wake_up)
284 * Here is the resume code for older machines.
285 * r1 has the physical address of SL_PC(sp).
290 /* Restore the kernel's segment registers before
291 * we do any r1 memory access as we are not sure they
292 * are in a sane state above the first 256Mb region
294 bl load_segment_registers
300 /* Restore various CPU config stuffs */
301 bl __restore_cpu_setup
303 /* Make sure all FPRs have been initialized */
305 bl __init_fpu_registers
307 /* Invalidate & enable L1 cache, we don't care about
308 * whatever the ROM may have tried to write to memory
312 /* Restore the BATs, and SDR1. Then we can turn on the MMU. */
317 lwz r4,SL_SPRG0+4(r1)
319 lwz r4,SL_SPRG0+8(r1)
321 lwz r4,SL_SPRG0+12(r1)
326 lwz r4,SL_DBAT0+4(r1)
330 lwz r4,SL_DBAT1+4(r1)
334 lwz r4,SL_DBAT2+4(r1)
338 lwz r4,SL_DBAT3+4(r1)
342 lwz r4,SL_IBAT0+4(r1)
346 lwz r4,SL_IBAT1+4(r1)
350 lwz r4,SL_IBAT2+4(r1)
354 lwz r4,SL_IBAT3+4(r1)
357 BEGIN_MMU_FTR_SECTION
360 lwz r4,SL_DBAT4+4(r1)
364 lwz r4,SL_DBAT5+4(r1)
368 lwz r4,SL_DBAT6+4(r1)
372 lwz r4,SL_DBAT7+4(r1)
376 lwz r4,SL_IBAT4+4(r1)
380 lwz r4,SL_IBAT5+4(r1)
384 lwz r4,SL_IBAT6+4(r1)
388 lwz r4,SL_IBAT7+4(r1)
390 END_MMU_FTR_SECTION_IFSET(MMU_FTR_USE_HIGH_BATS)
394 1: addic. r4,r4,-0x1000
407 /* Restore the callee-saved registers and return */
413 /* restore the MSR and SP and turn on the MMU and return */
422 _ASM_NOKPROBE_SYMBOL(grackle_wake_up)
424 #endif /* defined(CONFIG_PM) || defined(CONFIG_CPU_FREQ) */
427 .balign L1_CACHE_BYTES
430 .balign L1_CACHE_BYTES, 0
432 #endif /* CONFIG_PPC_BOOK3S_32 */