xref: /linux/arch/loongarch/power/suspend_asm.S (revision d30c1683aaecb93d2ab95685dc4300a33d3cea7a)
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Sleep helper for Loongson-3 sleep mode.
4 *
5 * Author: Huacai Chen <chenhuacai@loongson.cn>
6 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
7 */
8
9#include <asm/asm.h>
10#include <asm/asmmacro.h>
11#include <asm/addrspace.h>
12#include <asm/loongarch.h>
13#include <asm/stackframe.h>
14
15/* preparatory stuff */
16.macro	SETUP_SLEEP
17	PTR_ADDI	sp, sp, -PT_SIZE
18	REG_S		$r1, sp, PT_R1
19	REG_S		$r2, sp, PT_R2
20	REG_S		$r3, sp, PT_R3
21	REG_S		$r4, sp, PT_R4
22	REG_S		$r21, sp, PT_R21
23	REG_S		$r22, sp, PT_R22
24	REG_S		$r23, sp, PT_R23
25	REG_S		$r24, sp, PT_R24
26	REG_S		$r25, sp, PT_R25
27	REG_S		$r26, sp, PT_R26
28	REG_S		$r27, sp, PT_R27
29	REG_S		$r28, sp, PT_R28
30	REG_S		$r29, sp, PT_R29
31	REG_S		$r30, sp, PT_R30
32	REG_S		$r31, sp, PT_R31
33.endm
34
35.macro SETUP_WAKEUP
36	REG_L		$r1, sp, PT_R1
37	REG_L		$r2, sp, PT_R2
38	REG_L		$r3, sp, PT_R3
39	REG_L		$r4, sp, PT_R4
40	REG_L		$r21, sp, PT_R21
41	REG_L		$r22, sp, PT_R22
42	REG_L		$r23, sp, PT_R23
43	REG_L		$r24, sp, PT_R24
44	REG_L		$r25, sp, PT_R25
45	REG_L		$r26, sp, PT_R26
46	REG_L		$r27, sp, PT_R27
47	REG_L		$r28, sp, PT_R28
48	REG_L		$r29, sp, PT_R29
49	REG_L		$r30, sp, PT_R30
50	REG_L		$r31, sp, PT_R31
51	PTR_ADDI	sp, sp, PT_SIZE
52.endm
53
54	.text
55	.align 12
56
57/* Sleep/wakeup code for Loongson-3 */
58SYM_FUNC_START(loongarch_suspend_enter)
59	SETUP_SLEEP
60
61	la.pcrel	t0, acpi_saved_sp
62	REG_S		sp, t0, 0
63
64	bl		__flush_cache_all
65
66	/* Pass RA and SP to BIOS */
67	PTR_ADDI	a1, sp, 0
68	la.pcrel	a0, loongarch_wakeup_start
69	la.pcrel	t0, loongarch_suspend_addr
70	REG_L		t0, t0, 0
71	jirl		ra, t0, 0 /* Call BIOS's STR sleep routine */
72
73	/*
74	 * This is where we return upon wakeup.
75	 * Reload all of the registers and return.
76	 */
77SYM_INNER_LABEL(loongarch_wakeup_start, SYM_L_GLOBAL)
78	SETUP_DMWINS	t0
79	JUMP_VIRT_ADDR	t0, t1
80
81	/* Enable PG */
82	li.w		t0, 0xb0		# PLV=0, IE=0, PG=1
83	csrwr		t0, LOONGARCH_CSR_CRMD
84
85	la.pcrel	t0, acpi_saved_sp
86	REG_L		sp, t0, 0
87
88	SETUP_WAKEUP
89	jr		ra
90SYM_FUNC_END(loongarch_suspend_enter)
91