/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Hibernate low-level support3*4* Copyright (C) 2016 ARM Ltd.5* Author: James Morse <[email protected]>6*/7#include <linux/linkage.h>8#include <linux/errno.h>910#include <asm/asm-offsets.h>11#include <asm/assembler.h>12#include <asm/cputype.h>13#include <asm/memory.h>14#include <asm/page.h>15#include <asm/virt.h>1617/*18* Resume from hibernate19*20* Loads temporary page tables then restores the memory image.21* Finally branches to cpu_resume() to restore the state saved by22* swsusp_arch_suspend().23*24* Because this code has to be copied to a 'safe' page, it can't call out to25* other functions by PC-relative address. Also remember that it may be26* mid-way through over-writing other functions. For this reason it contains27* code from caches_clean_inval_pou() and uses the copy_page() macro.28*29* This 'safe' page is mapped via ttbr0, and executed from there. This function30* switches to a copy of the linear map in ttbr1, performs the restore, then31* switches ttbr1 to the original kernel's swapper_pg_dir.32*33* All of memory gets written to, including code. We need to clean the kernel34* text to the Point of Coherence (PoC) before secondary cores can be booted.35* Because the kernel modules and executable pages mapped to user space are36* also written as data, we clean all pages we touch to the Point of37* Unification (PoU).38*39* x0: physical address of temporary page tables40* x1: physical address of swapper page tables41* x2: address of cpu_resume42* x3: linear map address of restore_pblist in the current kernel43* x4: physical address of __hyp_stub_vectors, or 044* x5: physical address of a zero page that remains zero after resume45*/46.pushsection ".hibernate_exit.text", "ax"47SYM_CODE_START(swsusp_arch_suspend_exit)48/*49* We execute from ttbr0, change ttbr1 to our copied linear map tables50* with a break-before-make via the zero page51*/52break_before_make_ttbr_switch x5, x0, x6, x85354mov x21, x155mov x30, x256mov x24, x457mov x25, x55859/* walk the restore_pblist and use copy_page() to over-write memory */60mov x19, x361621: ldr x10, [x19, #HIBERN_PBE_ORIG]63mov x0, x1064ldr x1, [x19, #HIBERN_PBE_ADDR]6566copy_page x0, x1, x2, x3, x4, x5, x6, x7, x8, x96768add x1, x10, #PAGE_SIZE69/* Clean the copied page to PoU - based on caches_clean_inval_pou() */70raw_dcache_line_size x2, x371sub x3, x2, #172bic x4, x10, x3732: /* clean D line / unified line */74alternative_insn "dc cvau, x4", "dc civac, x4", ARM64_WORKAROUND_CLEAN_CACHE75add x4, x4, x276cmp x4, x177b.lo 2b7879ldr x19, [x19, #HIBERN_PBE_NEXT]80cbnz x19, 1b81dsb ish /* wait for PoU cleaning to finish */8283/* switch to the restored kernels page tables */84break_before_make_ttbr_switch x25, x21, x6, x88586ic ialluis87dsb ish88isb8990cbz x24, 3f /* Do we need to re-initialise EL2? */91hvc #0923: ret93SYM_CODE_END(swsusp_arch_suspend_exit)94.popsection959697