1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * Copyright (c) 2021 Western Digital Corporation or its affiliates. 4 * Copyright (c) 2022 Ventana Micro Systems Inc. 5 */ 6 7#ifndef _ASM_RISCV_SUSPEND_H 8#define _ASM_RISCV_SUSPEND_H 9 10#include <asm/ptrace.h> 11 12struct suspend_context { 13 /* Saved and restored by low-level functions */ 14 struct pt_regs regs; 15 /* Saved and restored by high-level functions */ 16 unsigned long scratch; 17 unsigned long envcfg; 18 unsigned long tvec; 19 unsigned long ie; 20#ifdef CONFIG_MMU 21 unsigned long satp; 22#endif 23}; 24 25/* 26 * Used by hibernation core and cleared during resume sequence 27 */ 28extern int in_suspend; 29 30/* Low-level CPU suspend entry function */ 31int __cpu_suspend_enter(struct suspend_context *context); 32 33/* High-level CPU suspend which will save context and call finish() */ 34int cpu_suspend(unsigned long arg, 35 int (*finish)(unsigned long arg, 36 unsigned long entry, 37 unsigned long context)); 38 39/* Low-level CPU resume entry function */ 40int __cpu_resume_enter(unsigned long hartid, unsigned long context); 41 42/* Used to save and restore the CSRs */ 43void suspend_save_csrs(struct suspend_context *context); 44void suspend_restore_csrs(struct suspend_context *context); 45 46/* Low-level API to support hibernation */ 47int swsusp_arch_suspend(void); 48int swsusp_arch_resume(void); 49int arch_hibernation_header_save(void *addr, unsigned int max_size); 50int arch_hibernation_header_restore(void *addr); 51int __hibernate_cpu_resume(void); 52 53/* Used to resume on the CPU we hibernated on */ 54int hibernate_resume_nonboot_cpu_disable(void); 55 56asmlinkage void hibernate_restore_image(unsigned long resume_satp, unsigned long satp_temp, 57 unsigned long cpu_resume); 58asmlinkage int hibernate_core_restore_code(void); 59bool riscv_sbi_hsm_is_supported(void); 60bool riscv_sbi_suspend_state_is_valid(u32 state); 61int riscv_sbi_hart_suspend(u32 state); 62#endif 63