2 * This file contains sleep low-level functions for PowerBook G3.
3 * Copyright (C) 1999 Benjamin Herrenschmidt (bh40@calva.net)
4 * and Paul Mackerras (paulus@cs.anu.edu.au).
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 "ppc_asm.tmpl"
14 #include <asm/processor.h>
17 #define MAGIC 0x4c617273 /* 'Lars' */
20 * Structure for storing CPU registers on the stack.
26 #define SL_SPRG0 0x10 /* 4 sprg's */
38 #define SL_R12 0x70 /* r12 to r31 */
39 #define SL_SIZE (SL_R12 + 80)
41 #define tophys(rd,rs) addis rd,rs,-KERNELBASE@h
42 #define tovirt(rd,rs) addis rd,rs,KERNELBASE@h
46 _GLOBAL(low_sleep_handler)
53 /* Save MSR, SDR1, TB */
75 stw r4,SL_SPRG0+12(r1)
101 stw r4,SL_IBAT1+4(r1)
105 stw r4,SL_IBAT2+4(r1)
109 stw r4,SL_IBAT3+4(r1)
115 /* Set up stuff at address 0 */
129 * Flush the L1 data cache by reading the first 64kB of RAM
130 * and then flushing the same area with the dcbf instruction.
131 * The L2 cache has already been disabled.
133 li r4,0x0800 /* 64kB / 32B */
138 addi r4,r4,0x0020 /* Go to start of next cache line */
142 li r4,0x0800 /* 64k */
147 addi r4,r4,0x0020 /* Go to start of next cache line */
152 * Set the HID0 and MSR for sleep.
155 rlwinm r2,r2,0,10,7 /* clear doze, nap */
156 oris r2,r2,HID0_SLEEP@h
169 * Here is the resume code.
170 * r1 has the physical address of SL_PC(sp).
174 /* Restore the HID0 register. This turns on the L1 caches. */
182 /* Restore the kernel's segment registers, the
183 BATs, and SDR1. Then we can turn on the MMU. */
184 li r0,16 /* load up segment register values */
185 mtctr r0 /* for context 0 */
186 lis r3,0x2000 /* Ku = 1, VSID = 0 */
189 addi r3,r3,1 /* increment VSID */
190 addis r4,r4,0x1000 /* address of next segment */
197 lwz r4,SL_SPRG0+4(r1)
199 lwz r4,SL_SPRG0+8(r1)
201 lwz r4,SL_SPRG0+12(r1)
206 lwz r4,SL_DBAT0+4(r1)
210 lwz r4,SL_DBAT1+4(r1)
214 lwz r4,SL_DBAT2+4(r1)
218 lwz r4,SL_DBAT3+4(r1)
222 lwz r4,SL_IBAT0+4(r1)
226 lwz r4,SL_IBAT1+4(r1)
230 lwz r4,SL_IBAT2+4(r1)
234 lwz r4,SL_IBAT3+4(r1)
237 /* restore the MSR and turn on the MMU */
241 /* get back the stack pointer */
250 /* Restore the callee-saved registers and return */