18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 48c2ecf20Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 58c2ecf20Sopenharmony_ci * for more details. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Sleep helper for Loongson-3 sleep mode. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Copyright (C) 2020 Loongson Technology Co., Ltd. 108c2ecf20Sopenharmony_ci * Author: Huacai Chen <chenhuacai@loongson.cn> 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <asm/asm.h> 148c2ecf20Sopenharmony_ci#include <asm/asmmacro.h> 158c2ecf20Sopenharmony_ci#include <asm/loongarchregs.h> 168c2ecf20Sopenharmony_ci#include <asm/stackframe.h> 178c2ecf20Sopenharmony_ci#include <asm/addrspace.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* preparatory stuff */ 208c2ecf20Sopenharmony_ci.macro SETUP_SLEEP 218c2ecf20Sopenharmony_ci addi.d sp, sp, -PT_SIZE 228c2ecf20Sopenharmony_ci st.d $r1, sp, PT_R1 238c2ecf20Sopenharmony_ci st.d $r2, sp, PT_R2 248c2ecf20Sopenharmony_ci st.d $r3, sp, PT_R3 258c2ecf20Sopenharmony_ci st.d $r4, sp, PT_R4 268c2ecf20Sopenharmony_ci st.d $r21, sp, PT_R21 278c2ecf20Sopenharmony_ci st.d $r22, sp, PT_R22 288c2ecf20Sopenharmony_ci st.d $r23, sp, PT_R23 298c2ecf20Sopenharmony_ci st.d $r24, sp, PT_R24 308c2ecf20Sopenharmony_ci st.d $r25, sp, PT_R25 318c2ecf20Sopenharmony_ci st.d $r26, sp, PT_R26 328c2ecf20Sopenharmony_ci st.d $r27, sp, PT_R27 338c2ecf20Sopenharmony_ci st.d $r28, sp, PT_R28 348c2ecf20Sopenharmony_ci st.d $r29, sp, PT_R29 358c2ecf20Sopenharmony_ci st.d $r30, sp, PT_R30 368c2ecf20Sopenharmony_ci st.d $r31, sp, PT_R31 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci la.pcrel t0, acpi_saved_sp 398c2ecf20Sopenharmony_ci st.d sp, t0, 0 408c2ecf20Sopenharmony_ci.endm 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci.macro SETUP_WAKEUP 438c2ecf20Sopenharmony_ci ld.d $r1, sp, PT_R1 448c2ecf20Sopenharmony_ci ld.d $r2, sp, PT_R2 458c2ecf20Sopenharmony_ci ld.d $r3, sp, PT_R3 468c2ecf20Sopenharmony_ci ld.d $r4, sp, PT_R4 478c2ecf20Sopenharmony_ci ld.d $r21, sp, PT_R21 488c2ecf20Sopenharmony_ci ld.d $r22, sp, PT_R22 498c2ecf20Sopenharmony_ci ld.d $r23, sp, PT_R23 508c2ecf20Sopenharmony_ci ld.d $r24, sp, PT_R24 518c2ecf20Sopenharmony_ci ld.d $r25, sp, PT_R25 528c2ecf20Sopenharmony_ci ld.d $r26, sp, PT_R26 538c2ecf20Sopenharmony_ci ld.d $r27, sp, PT_R27 548c2ecf20Sopenharmony_ci ld.d $r28, sp, PT_R28 558c2ecf20Sopenharmony_ci ld.d $r29, sp, PT_R29 568c2ecf20Sopenharmony_ci ld.d $r30, sp, PT_R30 578c2ecf20Sopenharmony_ci ld.d $r31, sp, PT_R31 588c2ecf20Sopenharmony_ci.endm 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci .text 618c2ecf20Sopenharmony_ci .align 12 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* Sleep/wakeup code for Loongson-3 */ 648c2ecf20Sopenharmony_ciSYM_FUNC_START(loongarch_suspend_enter) 658c2ecf20Sopenharmony_ci SETUP_SLEEP 668c2ecf20Sopenharmony_ci bl __flush_cache_all 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci /* Pass RA and SP to BIOS */ 698c2ecf20Sopenharmony_ci addi.d a1, sp, 0 708c2ecf20Sopenharmony_ci la.pcrel a0, loongarch_wakeup_start 718c2ecf20Sopenharmony_ci la.pcrel t0, loongarch_suspend_addr 728c2ecf20Sopenharmony_ci ld.d t0, t0, 0 738c2ecf20Sopenharmony_ci jirl a0, t0, 0 /* Call BIOS's STR sleep routine */ 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci /* 768c2ecf20Sopenharmony_ci * This is where we return upon wakeup. 778c2ecf20Sopenharmony_ci * Reload all of the registers and return. 788c2ecf20Sopenharmony_ci */ 798c2ecf20Sopenharmony_ciSYM_INNER_LABEL(loongarch_wakeup_start, SYM_L_GLOBAL) 808c2ecf20Sopenharmony_ci li.d t0, CSR_DMW0_INIT # UC, PLV0 818c2ecf20Sopenharmony_ci csrwr t0, LOONGARCH_CSR_DMWIN0 828c2ecf20Sopenharmony_ci li.d t0, CSR_DMW1_INIT # CA, PLV0 838c2ecf20Sopenharmony_ci csrwr t0, LOONGARCH_CSR_DMWIN1 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci JUMP_VIRT_ADDR t0, t1 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci /* Enable PG */ 888c2ecf20Sopenharmony_ci li.w t0, 0xb0 # PLV=0, IE=0, PG=1 898c2ecf20Sopenharmony_ci csrwr t0, LOONGARCH_CSR_CRMD 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci la.pcrel t0, acpi_saved_sp 928c2ecf20Sopenharmony_ci ld.d sp, t0, 0 938c2ecf20Sopenharmony_ci SETUP_WAKEUP 948c2ecf20Sopenharmony_ci addi.d sp, sp, PT_SIZE 958c2ecf20Sopenharmony_ci jr ra 968c2ecf20Sopenharmony_ciSYM_FUNC_END(loongarch_suspend_enter) 97