Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / arch / loongarch / power / hibernate.c
blob1e0590542f987cd59c0bad22f938b51ad0e4f2a5
1 // SPDX-License-Identifier: GPL-2.0
2 #include <asm/fpu.h>
3 #include <asm/loongson.h>
4 #include <asm/sections.h>
5 #include <asm/tlbflush.h>
6 #include <linux/suspend.h>
8 static u32 saved_crmd;
9 static u32 saved_prmd;
10 static u32 saved_euen;
11 static u32 saved_ecfg;
12 static u64 saved_pcpu_base;
13 struct pt_regs saved_regs;
15 void save_processor_state(void)
17 saved_crmd = csr_read32(LOONGARCH_CSR_CRMD);
18 saved_prmd = csr_read32(LOONGARCH_CSR_PRMD);
19 saved_euen = csr_read32(LOONGARCH_CSR_EUEN);
20 saved_ecfg = csr_read32(LOONGARCH_CSR_ECFG);
21 saved_pcpu_base = csr_read64(PERCPU_BASE_KS);
23 if (is_fpu_owner())
24 save_fp(current);
27 void restore_processor_state(void)
29 csr_write32(saved_crmd, LOONGARCH_CSR_CRMD);
30 csr_write32(saved_prmd, LOONGARCH_CSR_PRMD);
31 csr_write32(saved_euen, LOONGARCH_CSR_EUEN);
32 csr_write32(saved_ecfg, LOONGARCH_CSR_ECFG);
33 csr_write64(saved_pcpu_base, PERCPU_BASE_KS);
35 if (is_fpu_owner())
36 restore_fp(current);
39 int pfn_is_nosave(unsigned long pfn)
41 unsigned long nosave_begin_pfn = PFN_DOWN(__pa(&__nosave_begin));
42 unsigned long nosave_end_pfn = PFN_UP(__pa(&__nosave_end));
44 return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn);
47 extern int swsusp_asm_suspend(void);
49 int swsusp_arch_suspend(void)
51 enable_pci_wakeup();
52 return swsusp_asm_suspend();
55 extern int swsusp_asm_resume(void);
57 int swsusp_arch_resume(void)
59 /* Avoid TLB mismatch during and after kernel resume */
60 local_flush_tlb_all();
61 return swsusp_asm_resume();