hibernate-asm.S 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Hibernation low level support for RISCV.
  4. *
  5. * Copyright (C) 2023 StarFive Technology Co., Ltd.
  6. *
  7. * Author: Jee Heng Sia <jeeheng.sia@starfivetech.com>
  8. */
  9. #include <asm/asm.h>
  10. #include <asm/asm-offsets.h>
  11. #include <asm/assembler.h>
  12. #include <asm/csr.h>
  13. #include <linux/linkage.h>
  14. /*
  15. * int __hibernate_cpu_resume(void)
  16. * Switch back to the hibernated image's page table prior to restoring the CPU
  17. * context.
  18. *
  19. * Always returns 0
  20. */
  21. SYM_FUNC_START(__hibernate_cpu_resume)
  22. /* switch to hibernated image's page table. */
  23. csrw CSR_SATP, s0
  24. sfence.vma
  25. REG_L a0, hibernate_cpu_context
  26. suspend_restore_regs
  27. /* Return zero value. */
  28. mv a0, zero
  29. ret
  30. SYM_FUNC_END(__hibernate_cpu_resume)
  31. /*
  32. * Prepare to restore the image.
  33. * a0: satp of saved page tables.
  34. * a1: satp of temporary page tables.
  35. * a2: cpu_resume.
  36. */
  37. SYM_FUNC_START(hibernate_restore_image)
  38. mv s0, a0
  39. mv s1, a1
  40. mv s2, a2
  41. REG_L s4, restore_pblist
  42. REG_L a1, relocated_restore_code
  43. jr a1
  44. SYM_FUNC_END(hibernate_restore_image)
  45. /*
  46. * The below code will be executed from a 'safe' page.
  47. * It first switches to the temporary page table, then starts to copy the pages
  48. * back to the original memory location. Finally, it jumps to __hibernate_cpu_resume()
  49. * to restore the CPU context.
  50. */
  51. SYM_FUNC_START(hibernate_core_restore_code)
  52. /* switch to temp page table. */
  53. csrw satp, s1
  54. sfence.vma
  55. .Lcopy:
  56. /* The below code will restore the hibernated image. */
  57. REG_L a1, HIBERN_PBE_ADDR(s4)
  58. REG_L a0, HIBERN_PBE_ORIG(s4)
  59. copy_page a0, a1
  60. REG_L s4, HIBERN_PBE_NEXT(s4)
  61. bnez s4, .Lcopy
  62. jr s2
  63. SYM_FUNC_END(hibernate_core_restore_code)