1366bb35aSHuacai Chen/* SPDX-License-Identifier: GPL-2.0 */ 2366bb35aSHuacai Chen/* 3366bb35aSHuacai Chen * Sleep helper for Loongson-3 sleep mode. 4366bb35aSHuacai Chen * 5366bb35aSHuacai Chen * Author: Huacai Chen <chenhuacai@loongson.cn> 6366bb35aSHuacai Chen * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 7366bb35aSHuacai Chen */ 8366bb35aSHuacai Chen 9366bb35aSHuacai Chen#include <asm/asm.h> 10366bb35aSHuacai Chen#include <asm/asmmacro.h> 11366bb35aSHuacai Chen#include <asm/addrspace.h> 12366bb35aSHuacai Chen#include <asm/loongarch.h> 13366bb35aSHuacai Chen#include <asm/stackframe.h> 14366bb35aSHuacai Chen 15366bb35aSHuacai Chen/* preparatory stuff */ 16366bb35aSHuacai Chen.macro SETUP_SLEEP 17366bb35aSHuacai Chen addi.d sp, sp, -PT_SIZE 18366bb35aSHuacai Chen st.d $r1, sp, PT_R1 19366bb35aSHuacai Chen st.d $r2, sp, PT_R2 20366bb35aSHuacai Chen st.d $r3, sp, PT_R3 21366bb35aSHuacai Chen st.d $r4, sp, PT_R4 22366bb35aSHuacai Chen st.d $r21, sp, PT_R21 23366bb35aSHuacai Chen st.d $r22, sp, PT_R22 24366bb35aSHuacai Chen st.d $r23, sp, PT_R23 25366bb35aSHuacai Chen st.d $r24, sp, PT_R24 26366bb35aSHuacai Chen st.d $r25, sp, PT_R25 27366bb35aSHuacai Chen st.d $r26, sp, PT_R26 28366bb35aSHuacai Chen st.d $r27, sp, PT_R27 29366bb35aSHuacai Chen st.d $r28, sp, PT_R28 30366bb35aSHuacai Chen st.d $r29, sp, PT_R29 31366bb35aSHuacai Chen st.d $r30, sp, PT_R30 32366bb35aSHuacai Chen st.d $r31, sp, PT_R31 33366bb35aSHuacai Chen 34366bb35aSHuacai Chen la.pcrel t0, acpi_saved_sp 35366bb35aSHuacai Chen st.d sp, t0, 0 36366bb35aSHuacai Chen.endm 37366bb35aSHuacai Chen 38366bb35aSHuacai Chen.macro SETUP_WAKEUP 39366bb35aSHuacai Chen ld.d $r1, sp, PT_R1 40366bb35aSHuacai Chen ld.d $r2, sp, PT_R2 41366bb35aSHuacai Chen ld.d $r3, sp, PT_R3 42366bb35aSHuacai Chen ld.d $r4, sp, PT_R4 43366bb35aSHuacai Chen ld.d $r21, sp, PT_R21 44366bb35aSHuacai Chen ld.d $r22, sp, PT_R22 45366bb35aSHuacai Chen ld.d $r23, sp, PT_R23 46366bb35aSHuacai Chen ld.d $r24, sp, PT_R24 47366bb35aSHuacai Chen ld.d $r25, sp, PT_R25 48366bb35aSHuacai Chen ld.d $r26, sp, PT_R26 49366bb35aSHuacai Chen ld.d $r27, sp, PT_R27 50366bb35aSHuacai Chen ld.d $r28, sp, PT_R28 51366bb35aSHuacai Chen ld.d $r29, sp, PT_R29 52366bb35aSHuacai Chen ld.d $r30, sp, PT_R30 53366bb35aSHuacai Chen ld.d $r31, sp, PT_R31 54366bb35aSHuacai Chen.endm 55366bb35aSHuacai Chen 56366bb35aSHuacai Chen .text 57366bb35aSHuacai Chen .align 12 58366bb35aSHuacai Chen 59366bb35aSHuacai Chen/* Sleep/wakeup code for Loongson-3 */ 60366bb35aSHuacai ChenSYM_FUNC_START(loongarch_suspend_enter) 61366bb35aSHuacai Chen SETUP_SLEEP 62366bb35aSHuacai Chen bl __flush_cache_all 63366bb35aSHuacai Chen 64366bb35aSHuacai Chen /* Pass RA and SP to BIOS */ 65366bb35aSHuacai Chen addi.d a1, sp, 0 66366bb35aSHuacai Chen la.pcrel a0, loongarch_wakeup_start 67366bb35aSHuacai Chen la.pcrel t0, loongarch_suspend_addr 68366bb35aSHuacai Chen ld.d t0, t0, 0 69366bb35aSHuacai Chen jirl a0, t0, 0 /* Call BIOS's STR sleep routine */ 70366bb35aSHuacai Chen 71366bb35aSHuacai Chen /* 72366bb35aSHuacai Chen * This is where we return upon wakeup. 73366bb35aSHuacai Chen * Reload all of the registers and return. 74366bb35aSHuacai Chen */ 75366bb35aSHuacai ChenSYM_INNER_LABEL(loongarch_wakeup_start, SYM_L_GLOBAL) 76366bb35aSHuacai Chen li.d t0, CSR_DMW0_INIT # UC, PLV0 77366bb35aSHuacai Chen csrwr t0, LOONGARCH_CSR_DMWIN0 78366bb35aSHuacai Chen li.d t0, CSR_DMW1_INIT # CA, PLV0 79366bb35aSHuacai Chen csrwr t0, LOONGARCH_CSR_DMWIN1 80366bb35aSHuacai Chen 81*8cbd5ebfSYouling Tang JUMP_VIRT_ADDR t0, t1 82*8cbd5ebfSYouling Tang 83366bb35aSHuacai Chen la.pcrel t0, acpi_saved_sp 84366bb35aSHuacai Chen ld.d sp, t0, 0 85366bb35aSHuacai Chen SETUP_WAKEUP 86366bb35aSHuacai Chen addi.d sp, sp, PT_SIZE 87366bb35aSHuacai Chen jr ra 88366bb35aSHuacai ChenSYM_FUNC_END(loongarch_suspend_enter) 89