Path: blob/master/arch/powerpc/platforms/83xx/suspend-asm.S
26481 views
/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Enter and leave deep sleep state on MPC83xx3*4* Copyright (c) 2006-2008 Freescale Semiconductor, Inc.5* Author: Scott Wood <[email protected]>6*/78#include <asm/page.h>9#include <asm/ppc_asm.h>10#include <asm/reg.h>11#include <asm/asm-offsets.h>1213#define SS_MEMSAVE 0x00 /* First 8 bytes of RAM */14#define SS_HID 0x08 /* 3 HIDs */15#define SS_IABR 0x14 /* 2 IABRs */16#define SS_IBCR 0x1c17#define SS_DABR 0x20 /* 2 DABRs */18#define SS_DBCR 0x2819#define SS_SP 0x2c20#define SS_SR 0x30 /* 16 segment registers */21#define SS_R2 0x7022#define SS_MSR 0x7423#define SS_SDR1 0x7824#define SS_LR 0x7c25#define SS_SPRG 0x80 /* 8 SPRGs */26#define SS_DBAT 0xa0 /* 8 DBATs */27#define SS_IBAT 0xe0 /* 8 IBATs */28#define SS_TB 0x12029#define SS_CR 0x12830#define SS_GPREG 0x12c /* r12-r31 */31#define STATE_SAVE_SIZE 0x17c3233.section .data34.align 53536mpc83xx_sleep_save_area:37.space STATE_SAVE_SIZE38immrbase:39.long 04041.section .text42.align 54344/* r3 = physical address of IMMR */45_GLOBAL(mpc83xx_enter_deep_sleep)46lis r4, immrbase@ha47stw r3, immrbase@l(r4)4849/* The first 2 words of memory are used to communicate with the50* bootloader, to tell it how to resume.51*52* The first word is the magic number 0xf5153ae5, and the second53* is the pointer to mpc83xx_deep_resume.54*55* The original content of these two words is saved in SS_MEMSAVE.56*/5758lis r3, mpc83xx_sleep_save_area@h59ori r3, r3, mpc83xx_sleep_save_area@l6061lis r4, KERNELBASE@h62lwz r5, 0(r4)63lwz r6, 4(r4)6465stw r5, SS_MEMSAVE+0(r3)66stw r6, SS_MEMSAVE+4(r3)6768mfspr r5, SPRN_HID069mfspr r6, SPRN_HID170/* FIXME: Should this use SPRN_HID2_G2_LE? */71mfspr r7, SPRN_HID2_750FX7273stw r5, SS_HID+0(r3)74stw r6, SS_HID+4(r3)75stw r7, SS_HID+8(r3)7677mfspr r4, SPRN_IABR78mfspr r5, SPRN_IABR279mfspr r6, SPRN_IBCR80mfspr r7, SPRN_DABR81mfspr r8, SPRN_DABR282mfspr r9, SPRN_DBCR8384stw r4, SS_IABR+0(r3)85stw r5, SS_IABR+4(r3)86stw r6, SS_IBCR(r3)87stw r7, SS_DABR+0(r3)88stw r8, SS_DABR+4(r3)89stw r9, SS_DBCR(r3)9091mfspr r4, SPRN_SPRG092mfspr r5, SPRN_SPRG193mfspr r6, SPRN_SPRG294mfspr r7, SPRN_SPRG395mfsdr1 r89697stw r4, SS_SPRG+0(r3)98stw r5, SS_SPRG+4(r3)99stw r6, SS_SPRG+8(r3)100stw r7, SS_SPRG+12(r3)101stw r8, SS_SDR1(r3)102103mfspr r4, SPRN_SPRG4104mfspr r5, SPRN_SPRG5105mfspr r6, SPRN_SPRG6106mfspr r7, SPRN_SPRG7107108stw r4, SS_SPRG+16(r3)109stw r5, SS_SPRG+20(r3)110stw r6, SS_SPRG+24(r3)111stw r7, SS_SPRG+28(r3)112113mfspr r4, SPRN_DBAT0U114mfspr r5, SPRN_DBAT0L115mfspr r6, SPRN_DBAT1U116mfspr r7, SPRN_DBAT1L117118stw r4, SS_DBAT+0x00(r3)119stw r5, SS_DBAT+0x04(r3)120stw r6, SS_DBAT+0x08(r3)121stw r7, SS_DBAT+0x0c(r3)122123mfspr r4, SPRN_DBAT2U124mfspr r5, SPRN_DBAT2L125mfspr r6, SPRN_DBAT3U126mfspr r7, SPRN_DBAT3L127128stw r4, SS_DBAT+0x10(r3)129stw r5, SS_DBAT+0x14(r3)130stw r6, SS_DBAT+0x18(r3)131stw r7, SS_DBAT+0x1c(r3)132133mfspr r4, SPRN_DBAT4U134mfspr r5, SPRN_DBAT4L135mfspr r6, SPRN_DBAT5U136mfspr r7, SPRN_DBAT5L137138stw r4, SS_DBAT+0x20(r3)139stw r5, SS_DBAT+0x24(r3)140stw r6, SS_DBAT+0x28(r3)141stw r7, SS_DBAT+0x2c(r3)142143mfspr r4, SPRN_DBAT6U144mfspr r5, SPRN_DBAT6L145mfspr r6, SPRN_DBAT7U146mfspr r7, SPRN_DBAT7L147148stw r4, SS_DBAT+0x30(r3)149stw r5, SS_DBAT+0x34(r3)150stw r6, SS_DBAT+0x38(r3)151stw r7, SS_DBAT+0x3c(r3)152153mfspr r4, SPRN_IBAT0U154mfspr r5, SPRN_IBAT0L155mfspr r6, SPRN_IBAT1U156mfspr r7, SPRN_IBAT1L157158stw r4, SS_IBAT+0x00(r3)159stw r5, SS_IBAT+0x04(r3)160stw r6, SS_IBAT+0x08(r3)161stw r7, SS_IBAT+0x0c(r3)162163mfspr r4, SPRN_IBAT2U164mfspr r5, SPRN_IBAT2L165mfspr r6, SPRN_IBAT3U166mfspr r7, SPRN_IBAT3L167168stw r4, SS_IBAT+0x10(r3)169stw r5, SS_IBAT+0x14(r3)170stw r6, SS_IBAT+0x18(r3)171stw r7, SS_IBAT+0x1c(r3)172173mfspr r4, SPRN_IBAT4U174mfspr r5, SPRN_IBAT4L175mfspr r6, SPRN_IBAT5U176mfspr r7, SPRN_IBAT5L177178stw r4, SS_IBAT+0x20(r3)179stw r5, SS_IBAT+0x24(r3)180stw r6, SS_IBAT+0x28(r3)181stw r7, SS_IBAT+0x2c(r3)182183mfspr r4, SPRN_IBAT6U184mfspr r5, SPRN_IBAT6L185mfspr r6, SPRN_IBAT7U186mfspr r7, SPRN_IBAT7L187188stw r4, SS_IBAT+0x30(r3)189stw r5, SS_IBAT+0x34(r3)190stw r6, SS_IBAT+0x38(r3)191stw r7, SS_IBAT+0x3c(r3)192193mfmsr r4194mflr r5195mfcr r6196197stw r4, SS_MSR(r3)198stw r5, SS_LR(r3)199stw r6, SS_CR(r3)200stw r1, SS_SP(r3)201stw r2, SS_R2(r3)2022031: mftbu r4204mftb r5205mftbu r6206cmpw r4, r6207bne 1b208209stw r4, SS_TB+0(r3)210stw r5, SS_TB+4(r3)211212stmw r12, SS_GPREG(r3)213214li r4, 0215addi r6, r3, SS_SR-42161: mfsrin r5, r4217stwu r5, 4(r6)218addis r4, r4, 0x1000219cmpwi r4, 0220bne 1b221222/* Disable machine checks and critical exceptions */223mfmsr r4224rlwinm r4, r4, 0, ~MSR_CE225rlwinm r4, r4, 0, ~MSR_ME226mtmsr r4227isync228229#define TMP_VIRT_IMMR 0xf0000000230#define DEFAULT_IMMR_VALUE 0xff400000231#define IMMRBAR_BASE 0x0000232233lis r4, immrbase@ha234lwz r4, immrbase@l(r4)235236/* Use DBAT0 to address the current IMMR space */237238ori r4, r4, 0x002a239mtspr SPRN_DBAT0L, r4240lis r8, TMP_VIRT_IMMR@h241ori r4, r8, 0x001e /* 1 MByte accessible from Kernel Space only */242mtspr SPRN_DBAT0U, r4243isync244245/* Use DBAT1 to address the original IMMR space */246247lis r4, DEFAULT_IMMR_VALUE@h248ori r4, r4, 0x002a249mtspr SPRN_DBAT1L, r4250lis r9, (TMP_VIRT_IMMR + 0x01000000)@h251ori r4, r9, 0x001e /* 1 MByte accessible from Kernel Space only */252mtspr SPRN_DBAT1U, r4253isync254255/* Use DBAT2 to address the beginning of RAM. This isn't done256* using the normal virtual mapping, because with page debugging257* enabled it will be read-only.258*/259260li r4, 0x0002261mtspr SPRN_DBAT2L, r4262lis r4, KERNELBASE@h263ori r4, r4, 0x001e /* 1 MByte accessible from Kernel Space only */264mtspr SPRN_DBAT2U, r4265isync266267/* Flush the cache with our BAT, as there will be TLB misses268* otherwise if page debugging is enabled, and these misses269* will disturb the PLRU algorithm.270*/271272bl __flush_disable_L1273274/* Keep the i-cache enabled, so the hack below for low-boot275* flash will work.276*/277mfspr r3, SPRN_HID0278ori r3, r3, HID0_ICE279mtspr SPRN_HID0, r3280isync281282lis r6, 0xf515283ori r6, r6, 0x3ae5284285lis r7, mpc83xx_deep_resume@h286ori r7, r7, mpc83xx_deep_resume@l287tophys(r7, r7)288289lis r5, KERNELBASE@h290stw r6, 0(r5)291stw r7, 4(r5)292293/* Reset BARs */294295li r4, 0296stw r4, 0x0024(r8)297stw r4, 0x002c(r8)298stw r4, 0x0034(r8)299stw r4, 0x003c(r8)300stw r4, 0x0064(r8)301stw r4, 0x006c(r8)302303/* Rev 1 of the 8313 has problems with wakeup events that are304* pending during the transition to deep sleep state (such as if305* the PCI host sets the state to D3 and then D0 in rapid306* succession). This check shrinks the race window somewhat.307*308* See erratum PCI23, though the problem is not limited309* to PCI.310*/311312lwz r3, 0x0b04(r8)313andi. r3, r3, 1314bne- mpc83xx_deep_resume315316/* Move IMMR back to the default location, following the317* procedure specified in the MPC8313 manual.318*/319lwz r4, IMMRBAR_BASE(r8)320isync321lis r4, DEFAULT_IMMR_VALUE@h322stw r4, IMMRBAR_BASE(r8)323lis r4, KERNELBASE@h324lwz r4, 0(r4)325isync326lwz r4, IMMRBAR_BASE(r9)327mr r8, r9328isync329330/* Check the Reset Configuration Word to see whether flash needs331* to be mapped at a low address or a high address.332*/333334lwz r4, 0x0904(r8)335andis. r4, r4, 0x0400336li r4, 0337beq boot_low338lis r4, 0xff80339boot_low:340stw r4, 0x0020(r8)341lis r7, 0x8000342ori r7, r7, 0x0016343344mfspr r5, SPRN_HID0345rlwinm r5, r5, 0, ~(HID0_DOZE | HID0_NAP)346oris r5, r5, HID0_SLEEP@h347mtspr SPRN_HID0, r5348isync349350mfmsr r5351oris r5, r5, MSR_POW@h352353/* Enable the flash mapping at the appropriate address. This354* mapping will override the RAM mapping if booting low, so there's355* no need to disable the latter. This must be done inside the same356* cache line as setting MSR_POW, so that no instruction fetches357* from RAM happen after the flash mapping is turned on.358*/359360.align 5361stw r7, 0x0024(r8)362sync363isync364mtmsr r5365isync3661: b 1b367368mpc83xx_deep_resume:369lis r4, 1f@h370ori r4, r4, 1f@l371tophys(r4, r4)372mtsrr0 r4373374mfmsr r4375rlwinm r4, r4, 0, ~(MSR_IR | MSR_DR)376mtsrr1 r4377378rfi3793801: tlbia381bl __inval_enable_L1382383lis r3, mpc83xx_sleep_save_area@h384ori r3, r3, mpc83xx_sleep_save_area@l385tophys(r3, r3)386387lwz r5, SS_MEMSAVE+0(r3)388lwz r6, SS_MEMSAVE+4(r3)389390stw r5, 0(0)391stw r6, 4(0)392393lwz r5, SS_HID+0(r3)394lwz r6, SS_HID+4(r3)395lwz r7, SS_HID+8(r3)396397mtspr SPRN_HID0, r5398mtspr SPRN_HID1, r6399/* FIXME: Should this use SPRN_HID2_G2_LE? */400mtspr SPRN_HID2_750FX, r7401402lwz r4, SS_IABR+0(r3)403lwz r5, SS_IABR+4(r3)404lwz r6, SS_IBCR(r3)405lwz r7, SS_DABR+0(r3)406lwz r8, SS_DABR+4(r3)407lwz r9, SS_DBCR(r3)408409mtspr SPRN_IABR, r4410mtspr SPRN_IABR2, r5411mtspr SPRN_IBCR, r6412mtspr SPRN_DABR, r7413mtspr SPRN_DABR2, r8414mtspr SPRN_DBCR, r9415416li r4, 0417addi r6, r3, SS_SR-44181: lwzu r5, 4(r6)419mtsrin r5, r4420addis r4, r4, 0x1000421cmpwi r4, 0422bne 1b423424lwz r4, SS_DBAT+0x00(r3)425lwz r5, SS_DBAT+0x04(r3)426lwz r6, SS_DBAT+0x08(r3)427lwz r7, SS_DBAT+0x0c(r3)428429mtspr SPRN_DBAT0U, r4430mtspr SPRN_DBAT0L, r5431mtspr SPRN_DBAT1U, r6432mtspr SPRN_DBAT1L, r7433434lwz r4, SS_DBAT+0x10(r3)435lwz r5, SS_DBAT+0x14(r3)436lwz r6, SS_DBAT+0x18(r3)437lwz r7, SS_DBAT+0x1c(r3)438439mtspr SPRN_DBAT2U, r4440mtspr SPRN_DBAT2L, r5441mtspr SPRN_DBAT3U, r6442mtspr SPRN_DBAT3L, r7443444lwz r4, SS_DBAT+0x20(r3)445lwz r5, SS_DBAT+0x24(r3)446lwz r6, SS_DBAT+0x28(r3)447lwz r7, SS_DBAT+0x2c(r3)448449mtspr SPRN_DBAT4U, r4450mtspr SPRN_DBAT4L, r5451mtspr SPRN_DBAT5U, r6452mtspr SPRN_DBAT5L, r7453454lwz r4, SS_DBAT+0x30(r3)455lwz r5, SS_DBAT+0x34(r3)456lwz r6, SS_DBAT+0x38(r3)457lwz r7, SS_DBAT+0x3c(r3)458459mtspr SPRN_DBAT6U, r4460mtspr SPRN_DBAT6L, r5461mtspr SPRN_DBAT7U, r6462mtspr SPRN_DBAT7L, r7463464lwz r4, SS_IBAT+0x00(r3)465lwz r5, SS_IBAT+0x04(r3)466lwz r6, SS_IBAT+0x08(r3)467lwz r7, SS_IBAT+0x0c(r3)468469mtspr SPRN_IBAT0U, r4470mtspr SPRN_IBAT0L, r5471mtspr SPRN_IBAT1U, r6472mtspr SPRN_IBAT1L, r7473474lwz r4, SS_IBAT+0x10(r3)475lwz r5, SS_IBAT+0x14(r3)476lwz r6, SS_IBAT+0x18(r3)477lwz r7, SS_IBAT+0x1c(r3)478479mtspr SPRN_IBAT2U, r4480mtspr SPRN_IBAT2L, r5481mtspr SPRN_IBAT3U, r6482mtspr SPRN_IBAT3L, r7483484lwz r4, SS_IBAT+0x20(r3)485lwz r5, SS_IBAT+0x24(r3)486lwz r6, SS_IBAT+0x28(r3)487lwz r7, SS_IBAT+0x2c(r3)488489mtspr SPRN_IBAT4U, r4490mtspr SPRN_IBAT4L, r5491mtspr SPRN_IBAT5U, r6492mtspr SPRN_IBAT5L, r7493494lwz r4, SS_IBAT+0x30(r3)495lwz r5, SS_IBAT+0x34(r3)496lwz r6, SS_IBAT+0x38(r3)497lwz r7, SS_IBAT+0x3c(r3)498499mtspr SPRN_IBAT6U, r4500mtspr SPRN_IBAT6L, r5501mtspr SPRN_IBAT7U, r6502mtspr SPRN_IBAT7L, r7503504lwz r4, SS_SPRG+16(r3)505lwz r5, SS_SPRG+20(r3)506lwz r6, SS_SPRG+24(r3)507lwz r7, SS_SPRG+28(r3)508509mtspr SPRN_SPRG4, r4510mtspr SPRN_SPRG5, r5511mtspr SPRN_SPRG6, r6512mtspr SPRN_SPRG7, r7513514lwz r4, SS_SPRG+0(r3)515lwz r5, SS_SPRG+4(r3)516lwz r6, SS_SPRG+8(r3)517lwz r7, SS_SPRG+12(r3)518lwz r8, SS_SDR1(r3)519520mtspr SPRN_SPRG0, r4521mtspr SPRN_SPRG1, r5522mtspr SPRN_SPRG2, r6523mtspr SPRN_SPRG3, r7524mtsdr1 r8525526lwz r4, SS_MSR(r3)527lwz r5, SS_LR(r3)528lwz r6, SS_CR(r3)529lwz r1, SS_SP(r3)530lwz r2, SS_R2(r3)531532mtsrr1 r4533mtsrr0 r5534mtcr r6535536li r4, 0537mtspr SPRN_TBWL, r4538539lwz r4, SS_TB+0(r3)540lwz r5, SS_TB+4(r3)541542mtspr SPRN_TBWU, r4543mtspr SPRN_TBWL, r5544545lmw r12, SS_GPREG(r3)546547/* Kick decrementer */548li r0, 1549mtdec r0550551rfi552_ASM_NOKPROBE_SYMBOL(mpc83xx_deep_resume)553554555