162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2021 Western Digital Corporation or its affiliates. 462306a36Sopenharmony_ci * Copyright (c) 2022 Ventana Micro Systems Inc. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef _ASM_RISCV_SUSPEND_H 862306a36Sopenharmony_ci#define _ASM_RISCV_SUSPEND_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <asm/ptrace.h> 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_cistruct suspend_context { 1362306a36Sopenharmony_ci /* Saved and restored by low-level functions */ 1462306a36Sopenharmony_ci struct pt_regs regs; 1562306a36Sopenharmony_ci /* Saved and restored by high-level functions */ 1662306a36Sopenharmony_ci unsigned long scratch; 1762306a36Sopenharmony_ci unsigned long tvec; 1862306a36Sopenharmony_ci unsigned long ie; 1962306a36Sopenharmony_ci#ifdef CONFIG_MMU 2062306a36Sopenharmony_ci unsigned long satp; 2162306a36Sopenharmony_ci#endif 2262306a36Sopenharmony_ci}; 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* 2562306a36Sopenharmony_ci * Used by hibernation core and cleared during resume sequence 2662306a36Sopenharmony_ci */ 2762306a36Sopenharmony_ciextern int in_suspend; 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* Low-level CPU suspend entry function */ 3062306a36Sopenharmony_ciint __cpu_suspend_enter(struct suspend_context *context); 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* High-level CPU suspend which will save context and call finish() */ 3362306a36Sopenharmony_ciint cpu_suspend(unsigned long arg, 3462306a36Sopenharmony_ci int (*finish)(unsigned long arg, 3562306a36Sopenharmony_ci unsigned long entry, 3662306a36Sopenharmony_ci unsigned long context)); 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* Low-level CPU resume entry function */ 3962306a36Sopenharmony_ciint __cpu_resume_enter(unsigned long hartid, unsigned long context); 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* Used to save and restore the CSRs */ 4262306a36Sopenharmony_civoid suspend_save_csrs(struct suspend_context *context); 4362306a36Sopenharmony_civoid suspend_restore_csrs(struct suspend_context *context); 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci/* Low-level API to support hibernation */ 4662306a36Sopenharmony_ciint swsusp_arch_suspend(void); 4762306a36Sopenharmony_ciint swsusp_arch_resume(void); 4862306a36Sopenharmony_ciint arch_hibernation_header_save(void *addr, unsigned int max_size); 4962306a36Sopenharmony_ciint arch_hibernation_header_restore(void *addr); 5062306a36Sopenharmony_ciint __hibernate_cpu_resume(void); 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* Used to resume on the CPU we hibernated on */ 5362306a36Sopenharmony_ciint hibernate_resume_nonboot_cpu_disable(void); 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ciasmlinkage void hibernate_restore_image(unsigned long resume_satp, unsigned long satp_temp, 5662306a36Sopenharmony_ci unsigned long cpu_resume); 5762306a36Sopenharmony_ciasmlinkage int hibernate_core_restore_code(void); 5862306a36Sopenharmony_ci#endif 59