Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Hibernation support specific for ARM
0004  *
0005  * Derived from work on ARM hibernation support by:
0006  *
0007  * Ubuntu project, hibernation support for mach-dove
0008  * Copyright (C) 2010 Nokia Corporation (Hiroshi Doyu)
0009  * Copyright (C) 2010 Texas Instruments, Inc. (Teerth Reddy et al.)
0010  *  https://lkml.org/lkml/2010/6/18/4
0011  *  https://lists.linux-foundation.org/pipermail/linux-pm/2010-June/027422.html
0012  *  https://patchwork.kernel.org/patch/96442/
0013  *
0014  * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
0015  */
0016 
0017 #include <linux/mm.h>
0018 #include <linux/suspend.h>
0019 #include <asm/system_misc.h>
0020 #include <asm/idmap.h>
0021 #include <asm/suspend.h>
0022 #include <asm/memory.h>
0023 #include <asm/sections.h>
0024 #include "reboot.h"
0025 
0026 int pfn_is_nosave(unsigned long pfn)
0027 {
0028     unsigned long nosave_begin_pfn = virt_to_pfn(&__nosave_begin);
0029     unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end - 1);
0030 
0031     return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
0032 }
0033 
0034 void notrace save_processor_state(void)
0035 {
0036     WARN_ON(num_online_cpus() != 1);
0037     local_fiq_disable();
0038 }
0039 
0040 void notrace restore_processor_state(void)
0041 {
0042     local_fiq_enable();
0043 }
0044 
0045 /*
0046  * Snapshot kernel memory and reset the system.
0047  *
0048  * swsusp_save() is executed in the suspend finisher so that the CPU
0049  * context pointer and memory are part of the saved image, which is
0050  * required by the resume kernel image to restart execution from
0051  * swsusp_arch_suspend().
0052  *
0053  * soft_restart is not technically needed, but is used to get success
0054  * returned from cpu_suspend.
0055  *
0056  * When soft reboot completes, the hibernation snapshot is written out.
0057  */
0058 static int notrace arch_save_image(unsigned long unused)
0059 {
0060     int ret;
0061 
0062     ret = swsusp_save();
0063     if (ret == 0)
0064         _soft_restart(virt_to_idmap(cpu_resume), false);
0065     return ret;
0066 }
0067 
0068 /*
0069  * Save the current CPU state before suspend / poweroff.
0070  */
0071 int notrace swsusp_arch_suspend(void)
0072 {
0073     return cpu_suspend(0, arch_save_image);
0074 }
0075 
0076 /*
0077  * Restore page contents for physical pages that were in use during loading
0078  * hibernation image.  Switch to idmap_pgd so the physical page tables
0079  * are overwritten with the same contents.
0080  */
0081 static void notrace arch_restore_image(void *unused)
0082 {
0083     struct pbe *pbe;
0084 
0085     cpu_switch_mm(idmap_pgd, &init_mm);
0086     for (pbe = restore_pblist; pbe; pbe = pbe->next)
0087         copy_page(pbe->orig_address, pbe->address);
0088 
0089     _soft_restart(virt_to_idmap(cpu_resume), false);
0090 }
0091 
0092 static u64 resume_stack[PAGE_SIZE/2/sizeof(u64)] __nosavedata;
0093 
0094 /*
0095  * Resume from the hibernation image.
0096  * Due to the kernel heap / data restore, stack contents change underneath
0097  * and that would make function calls impossible; switch to a temporary
0098  * stack within the nosave region to avoid that problem.
0099  */
0100 int swsusp_arch_resume(void)
0101 {
0102     call_with_stack(arch_restore_image, 0,
0103         resume_stack + ARRAY_SIZE(resume_stack));
0104     return 0;
0105 }