/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Hibernation low level support for RISCV.3*4* Copyright (C) 2023 StarFive Technology Co., Ltd.5*6* Author: Jee Heng Sia <[email protected]>7*/89#include <asm/asm.h>10#include <asm/asm-offsets.h>11#include <asm/assembler.h>12#include <asm/csr.h>1314#include <linux/linkage.h>1516/*17* int __hibernate_cpu_resume(void)18* Switch back to the hibernated image's page table prior to restoring the CPU19* context.20*21* Always returns 022*/23SYM_FUNC_START(__hibernate_cpu_resume)24/* switch to hibernated image's page table. */25csrw CSR_SATP, s026sfence.vma2728REG_L a0, hibernate_cpu_context2930suspend_restore_regs3132/* Return zero value. */33mv a0, zero3435ret36SYM_FUNC_END(__hibernate_cpu_resume)3738/*39* Prepare to restore the image.40* a0: satp of saved page tables.41* a1: satp of temporary page tables.42* a2: cpu_resume.43*/44SYM_FUNC_START(hibernate_restore_image)45mv s0, a046mv s1, a147mv s2, a248REG_L s4, restore_pblist49REG_L a1, relocated_restore_code5051jr a152SYM_FUNC_END(hibernate_restore_image)5354/*55* The below code will be executed from a 'safe' page.56* It first switches to the temporary page table, then starts to copy the pages57* back to the original memory location. Finally, it jumps to __hibernate_cpu_resume()58* to restore the CPU context.59*/60SYM_FUNC_START(hibernate_core_restore_code)61/* switch to temp page table. */62csrw satp, s163sfence.vma64.Lcopy:65/* The below code will restore the hibernated image. */66REG_L a1, HIBERN_PBE_ADDR(s4)67REG_L a0, HIBERN_PBE_ORIG(s4)6869copy_page a0, a17071REG_L s4, HIBERN_PBE_NEXT(s4)72bnez s4, .Lcopy7374jr s275SYM_FUNC_END(hibernate_core_restore_code)767778