1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Hibernation low level support for RISCV.
5 * Copyright (C) 2023 StarFive Technology Co., Ltd.
7 * Author: Jee Heng Sia <jeeheng.sia@starfivetech.com>
11 #include <asm/asm-offsets.h>
12 #include <asm/assembler.h>
15 #include <linux/linkage.h>
18 * int __hibernate_cpu_resume(void)
19 * Switch back to the hibernated image's page table prior to restoring the CPU
24 SYM_FUNC_START(__hibernate_cpu_resume)
25 /* switch to hibernated image's page table. */
29 REG_L a0, hibernate_cpu_context
33 /* Return zero value. */
37 SYM_FUNC_END(__hibernate_cpu_resume)
40 * Prepare to restore the image.
41 * a0: satp of saved page tables.
42 * a1: satp of temporary page tables.
45 SYM_FUNC_START(hibernate_restore_image)
49 REG_L s4, restore_pblist
50 REG_L a1, relocated_restore_code
53 SYM_FUNC_END(hibernate_restore_image)
56 * The below code will be executed from a 'safe' page.
57 * It first switches to the temporary page table, then starts to copy the pages
58 * back to the original memory location. Finally, it jumps to __hibernate_cpu_resume()
59 * to restore the CPU context.
61 SYM_FUNC_START(hibernate_core_restore_code)
62 /* switch to temp page table. */
66 /* The below code will restore the hibernated image. */
67 REG_L a1, HIBERN_PBE_ADDR(s4)
68 REG_L a0, HIBERN_PBE_ORIG(s4)
72 REG_L s4, HIBERN_PBE_NEXT(s4)
76 SYM_FUNC_END(hibernate_core_restore_code)