hibernate-asm.S 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Hibernate low-level support
  4. *
  5. * Copyright (C) 2016 ARM Ltd.
  6. * Author: James Morse <[email protected]>
  7. */
  8. #include <linux/linkage.h>
  9. #include <linux/errno.h>
  10. #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>
  16. /*
  17. * Resume from hibernate
  18. *
  19. * Loads temporary page tables then restores the memory image.
  20. * Finally branches to cpu_resume() to restore the state saved by
  21. * swsusp_arch_suspend().
  22. *
  23. * Because this code has to be copied to a 'safe' page, it can't call out to
  24. * other functions by PC-relative address. Also remember that it may be
  25. * mid-way through over-writing other functions. For this reason it contains
  26. * code from caches_clean_inval_pou() and uses the copy_page() macro.
  27. *
  28. * This 'safe' page is mapped via ttbr0, and executed from there. This function
  29. * switches to a copy of the linear map in ttbr1, performs the restore, then
  30. * switches ttbr1 to the original kernel's swapper_pg_dir.
  31. *
  32. * All of memory gets written to, including code. We need to clean the kernel
  33. * text to the Point of Coherence (PoC) before secondary cores can be booted.
  34. * Because the kernel modules and executable pages mapped to user space are
  35. * also written as data, we clean all pages we touch to the Point of
  36. * Unification (PoU).
  37. *
  38. * x0: physical address of temporary page tables
  39. * x1: physical address of swapper page tables
  40. * x2: address of cpu_resume
  41. * x3: linear map address of restore_pblist in the current kernel
  42. * x4: physical address of __hyp_stub_vectors, or 0
  43. * x5: physical address of a zero page that remains zero after resume
  44. */
  45. .pushsection ".hibernate_exit.text", "ax"
  46. SYM_CODE_START(swsusp_arch_suspend_exit)
  47. /*
  48. * We execute from ttbr0, change ttbr1 to our copied linear map tables
  49. * with a break-before-make via the zero page
  50. */
  51. break_before_make_ttbr_switch x5, x0, x6, x8
  52. mov x21, x1
  53. mov x30, x2
  54. mov x24, x4
  55. mov x25, x5
  56. /* walk the restore_pblist and use copy_page() to over-write memory */
  57. mov x19, x3
  58. 1: ldr x10, [x19, #HIBERN_PBE_ORIG]
  59. mov x0, x10
  60. ldr x1, [x19, #HIBERN_PBE_ADDR]
  61. copy_page x0, x1, x2, x3, x4, x5, x6, x7, x8, x9
  62. add x1, x10, #PAGE_SIZE
  63. /* Clean the copied page to PoU - based on caches_clean_inval_pou() */
  64. raw_dcache_line_size x2, x3
  65. sub x3, x2, #1
  66. bic x4, x10, x3
  67. 2: /* clean D line / unified line */
  68. alternative_insn "dc cvau, x4", "dc civac, x4", ARM64_WORKAROUND_CLEAN_CACHE
  69. add x4, x4, x2
  70. cmp x4, x1
  71. b.lo 2b
  72. ldr x19, [x19, #HIBERN_PBE_NEXT]
  73. cbnz x19, 1b
  74. dsb ish /* wait for PoU cleaning to finish */
  75. /* switch to the restored kernels page tables */
  76. break_before_make_ttbr_switch x25, x21, x6, x8
  77. ic ialluis
  78. dsb ish
  79. isb
  80. cbz x24, 3f /* Do we need to re-initialise EL2? */
  81. hvc #0
  82. 3: ret
  83. SYM_CODE_END(swsusp_arch_suspend_exit)
  84. .popsection