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 */ 1605ab803dSSamuel Holland unsigned long envcfg; 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 24c0317210SSia Jee Heng /* 25c0317210SSia Jee Heng * Used by hibernation core and cleared during resume sequence 26c0317210SSia Jee Heng */ 27c0317210SSia Jee Heng extern int in_suspend; 28c0317210SSia 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); 44c0317210SSia Jee Heng 45c0317210SSia Jee Heng /* Low-level API to support hibernation */ 46c0317210SSia Jee Heng int swsusp_arch_suspend(void); 47c0317210SSia Jee Heng int swsusp_arch_resume(void); 48c0317210SSia Jee Heng int arch_hibernation_header_save(void *addr, unsigned int max_size); 49c0317210SSia Jee Heng int arch_hibernation_header_restore(void *addr); 50c0317210SSia Jee Heng int __hibernate_cpu_resume(void); 51c0317210SSia Jee Heng 52c0317210SSia Jee Heng /* Used to resume on the CPU we hibernated on */ 53c0317210SSia Jee Heng int hibernate_resume_nonboot_cpu_disable(void); 54c0317210SSia Jee Heng 55c0317210SSia Jee Heng asmlinkage void hibernate_restore_image(unsigned long resume_satp, unsigned long satp_temp, 56c0317210SSia Jee Heng unsigned long cpu_resume); 57c0317210SSia Jee Heng asmlinkage int hibernate_core_restore_code(void); 58*6649182aSSunil V L bool riscv_sbi_hsm_is_supported(void); 59*6649182aSSunil V L bool riscv_sbi_suspend_state_is_valid(u32 state); 60*6649182aSSunil V L int riscv_sbi_hart_suspend(u32 state); 6163b13e64SAnup Patel #endif 62