163b13e64SAnup Patel /* SPDX-License-Identifier: GPL-2.0-only */ 263b13e64SAnup Patel /* 363b13e64SAnup Patel * Copyright (c) 2021 Western Digital Corporation or its affiliates. 463b13e64SAnup Patel * Copyright (c) 2022 Ventana Micro Systems Inc. 563b13e64SAnup Patel */ 663b13e64SAnup Patel 763b13e64SAnup Patel #ifndef _ASM_RISCV_SUSPEND_H 863b13e64SAnup Patel #define _ASM_RISCV_SUSPEND_H 963b13e64SAnup Patel 1063b13e64SAnup Patel #include <asm/ptrace.h> 1163b13e64SAnup Patel 1263b13e64SAnup Patel struct suspend_context { 1363b13e64SAnup Patel /* Saved and restored by low-level functions */ 1463b13e64SAnup Patel struct pt_regs regs; 1563b13e64SAnup Patel /* Saved and restored by high-level functions */ 1663b13e64SAnup Patel unsigned long scratch; 1763b13e64SAnup Patel unsigned long tvec; 1863b13e64SAnup Patel unsigned long ie; 1963b13e64SAnup Patel #ifdef CONFIG_MMU 2063b13e64SAnup Patel unsigned long satp; 2163b13e64SAnup Patel #endif 2263b13e64SAnup Patel }; 2363b13e64SAnup Patel 24*c0317210SSia Jee Heng /* 25*c0317210SSia Jee Heng * Used by hibernation core and cleared during resume sequence 26*c0317210SSia Jee Heng */ 27*c0317210SSia Jee Heng extern int in_suspend; 28*c0317210SSia Jee Heng 2963b13e64SAnup Patel /* Low-level CPU suspend entry function */ 3063b13e64SAnup Patel int __cpu_suspend_enter(struct suspend_context *context); 3163b13e64SAnup Patel 3263b13e64SAnup Patel /* High-level CPU suspend which will save context and call finish() */ 3363b13e64SAnup Patel int cpu_suspend(unsigned long arg, 3463b13e64SAnup Patel int (*finish)(unsigned long arg, 3563b13e64SAnup Patel unsigned long entry, 3663b13e64SAnup Patel unsigned long context)); 3763b13e64SAnup Patel 3863b13e64SAnup Patel /* Low-level CPU resume entry function */ 3963b13e64SAnup Patel int __cpu_resume_enter(unsigned long hartid, unsigned long context); 4063b13e64SAnup Patel 410def12f3SSia Jee Heng /* Used to save and restore the CSRs */ 420def12f3SSia Jee Heng void suspend_save_csrs(struct suspend_context *context); 430def12f3SSia Jee Heng void suspend_restore_csrs(struct suspend_context *context); 44*c0317210SSia Jee Heng 45*c0317210SSia Jee Heng /* Low-level API to support hibernation */ 46*c0317210SSia Jee Heng int swsusp_arch_suspend(void); 47*c0317210SSia Jee Heng int swsusp_arch_resume(void); 48*c0317210SSia Jee Heng int arch_hibernation_header_save(void *addr, unsigned int max_size); 49*c0317210SSia Jee Heng int arch_hibernation_header_restore(void *addr); 50*c0317210SSia Jee Heng int __hibernate_cpu_resume(void); 51*c0317210SSia Jee Heng 52*c0317210SSia Jee Heng /* Used to resume on the CPU we hibernated on */ 53*c0317210SSia Jee Heng int hibernate_resume_nonboot_cpu_disable(void); 54*c0317210SSia Jee Heng 55*c0317210SSia Jee Heng asmlinkage void hibernate_restore_image(unsigned long resume_satp, unsigned long satp_temp, 56*c0317210SSia Jee Heng unsigned long cpu_resume); 57*c0317210SSia Jee Heng asmlinkage int hibernate_core_restore_code(void); 5863b13e64SAnup Patel #endif 59