2014-03-25 04:20:29 +04:00
|
|
|
/*
|
|
|
|
* Hibernation support specific for ARM
|
|
|
|
*
|
|
|
|
* Derived from work on ARM hibernation support by:
|
|
|
|
*
|
|
|
|
* Ubuntu project, hibernation support for mach-dove
|
|
|
|
* Copyright (C) 2010 Nokia Corporation (Hiroshi Doyu)
|
|
|
|
* Copyright (C) 2010 Texas Instruments, Inc. (Teerth Reddy et al.)
|
|
|
|
* https://lkml.org/lkml/2010/6/18/4
|
|
|
|
* https://lists.linux-foundation.org/pipermail/linux-pm/2010-June/027422.html
|
|
|
|
* https://patchwork.kernel.org/patch/96442/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl>
|
|
|
|
*
|
|
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/suspend.h>
|
|
|
|
#include <asm/system_misc.h>
|
|
|
|
#include <asm/idmap.h>
|
|
|
|
#include <asm/suspend.h>
|
|
|
|
#include <asm/memory.h>
|
2014-10-10 02:30:30 +04:00
|
|
|
#include <asm/sections.h>
|
ARM: fix broken hibernation
Normally, when a CPU wants to clear a cache line to zero in the external
L2 cache, it would generate bus cycles to write each word as it would do
with any other data access.
However, a Cortex A9 connected to a L2C-310 has a specific feature where
the CPU can detect this operation, and signal that it wants to zero an
entire cache line. This feature, known as Full Line of Zeros (FLZ),
involves a non-standard AXI signalling mechanism which only the L2C-310
can properly interpret.
There are separate enable bits in both the L2C-310 and the Cortex A9 -
the L2C-310 needs to be enabled and have the FLZ enable bit set in the
auxiliary control register before the Cortex A9 has this feature
enabled.
Unfortunately, the suspend code was not respecting this - it's not
obvious from the code:
swsusp_arch_suspend()
cpu_suspend() /* saves the Cortex A9 auxiliary control register */
arch_save_image()
soft_restart() /* turns off FLZ in Cortex A9, and disables L2C */
cpu_resume() /* restores the Cortex A9 registers, inc auxcr */
At this point, we end up with the L2C disabled, but the Cortex A9 with
FLZ enabled - which means any memset() or zeroing of a full cache line
will fail to take effect.
A similar issue exists in the resume path, but it's slightly more
complex:
swsusp_arch_suspend()
cpu_suspend() /* saves the Cortex A9 auxiliary control register */
arch_save_image() /* image with A9 auxcr saved */
...
swsusp_arch_resume()
call_with_stack()
arch_restore_image() /* restores image with A9 auxcr saved above */
soft_restart() /* turns off FLZ in Cortex A9, and disables L2C */
cpu_resume() /* restores the Cortex A9 registers, inc auxcr */
Again, here we end up with the L2C disabled, but Cortex A9 FLZ enabled.
There's no need to turn off the L2C in either of these two paths; there
are benefits from not doing so - for example, the page copies will be
faster with the L2C enabled.
Hence, fix this by providing a variant of soft_restart() which can be
used without turning the L2 cache controller off, and use it in both
of these paths to keep the L2C enabled across the respective resume
transitions.
Fixes: 8ef418c7178f ("ARM: l2c: trial at enabling some Cortex-A9 optimisations")
Reported-by: Sean Cross <xobs@kosagi.com>
Tested-by: Sean Cross <xobs@kosagi.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2015-04-01 18:20:39 +03:00
|
|
|
#include "reboot.h"
|
2014-03-25 04:20:29 +04:00
|
|
|
|
|
|
|
int pfn_is_nosave(unsigned long pfn)
|
|
|
|
{
|
|
|
|
unsigned long nosave_begin_pfn = virt_to_pfn(&__nosave_begin);
|
|
|
|
unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end - 1);
|
|
|
|
|
|
|
|
return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void notrace save_processor_state(void)
|
|
|
|
{
|
|
|
|
WARN_ON(num_online_cpus() != 1);
|
|
|
|
local_fiq_disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void notrace restore_processor_state(void)
|
|
|
|
{
|
|
|
|
local_fiq_enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Snapshot kernel memory and reset the system.
|
|
|
|
*
|
|
|
|
* swsusp_save() is executed in the suspend finisher so that the CPU
|
|
|
|
* context pointer and memory are part of the saved image, which is
|
|
|
|
* required by the resume kernel image to restart execution from
|
|
|
|
* swsusp_arch_suspend().
|
|
|
|
*
|
|
|
|
* soft_restart is not technically needed, but is used to get success
|
|
|
|
* returned from cpu_suspend.
|
|
|
|
*
|
|
|
|
* When soft reboot completes, the hibernation snapshot is written out.
|
|
|
|
*/
|
|
|
|
static int notrace arch_save_image(unsigned long unused)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = swsusp_save();
|
|
|
|
if (ret == 0)
|
2016-01-11 20:03:54 +03:00
|
|
|
_soft_restart(virt_to_idmap(cpu_resume), false);
|
2014-03-25 04:20:29 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save the current CPU state before suspend / poweroff.
|
|
|
|
*/
|
|
|
|
int notrace swsusp_arch_suspend(void)
|
|
|
|
{
|
|
|
|
return cpu_suspend(0, arch_save_image);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore page contents for physical pages that were in use during loading
|
|
|
|
* hibernation image. Switch to idmap_pgd so the physical page tables
|
|
|
|
* are overwritten with the same contents.
|
|
|
|
*/
|
|
|
|
static void notrace arch_restore_image(void *unused)
|
|
|
|
{
|
|
|
|
struct pbe *pbe;
|
|
|
|
|
|
|
|
cpu_switch_mm(idmap_pgd, &init_mm);
|
|
|
|
for (pbe = restore_pblist; pbe; pbe = pbe->next)
|
|
|
|
copy_page(pbe->orig_address, pbe->address);
|
|
|
|
|
2016-01-11 20:03:54 +03:00
|
|
|
_soft_restart(virt_to_idmap(cpu_resume), false);
|
2014-03-25 04:20:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static u64 resume_stack[PAGE_SIZE/2/sizeof(u64)] __nosavedata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Resume from the hibernation image.
|
|
|
|
* Due to the kernel heap / data restore, stack contents change underneath
|
|
|
|
* and that would make function calls impossible; switch to a temporary
|
|
|
|
* stack within the nosave region to avoid that problem.
|
|
|
|
*/
|
|
|
|
int swsusp_arch_resume(void)
|
|
|
|
{
|
|
|
|
call_with_stack(arch_restore_image, 0,
|
|
|
|
resume_stack + ARRAY_SIZE(resume_stack));
|
|
|
|
return 0;
|
|
|
|
}
|