qcom_hib.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #include <linux/cpuidle.h>
  6. #include <linux/module.h>
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <trace/hooks/cpuidle_psci.h>
  10. #include <trace/hooks/bl_hib.h>
  11. #include <linux/blkdev.h>
  12. #include <linux/swap.h>
  13. #include <soc/qcom/qcom_hibernation.h>
  14. #define __NEW_UTS_LEN 64
  15. struct block_device *hiber_bdev;
  16. EXPORT_SYMBOL(hiber_bdev);
  17. struct arch_hibernate_hdr_invariants {
  18. char uts_version[__NEW_UTS_LEN + 1];
  19. };
  20. struct arch_hibernate_hdr {
  21. struct arch_hibernate_hdr_invariants invariants;
  22. /* These are needed to find the relocated kernel if built with kaslr */
  23. phys_addr_t ttbr1_el1;
  24. void (*reenter_kernel)(void);
  25. /*
  26. * We need to know where the __hyp_stub_vectors are after restore to
  27. * re-configure el2.
  28. */
  29. phys_addr_t __hyp_stub_vectors;
  30. u64 sleep_cpu_mpidr;
  31. ANDROID_VENDOR_DATA(1);
  32. };
  33. static void save_hib_resume_bdev(void *data, struct block_device *hib_resume_bdev)
  34. {
  35. hiber_bdev = hib_resume_bdev;
  36. }
  37. static void check_hibernation_swap(void *data, struct block_device *dev,
  38. bool *hib_swap)
  39. {
  40. if (dev == hiber_bdev)
  41. *hib_swap = true;
  42. else
  43. *hib_swap = false;
  44. }
  45. static void save_cpu_resume(void *data, u64 *addr, u64 phys_addr)
  46. {
  47. *addr = phys_addr;
  48. }
  49. static int __init init_s2d_hooks(void)
  50. {
  51. register_trace_android_vh_save_hib_resume_bdev(save_hib_resume_bdev, NULL);
  52. register_trace_android_vh_check_hibernation_swap(check_hibernation_swap, NULL);
  53. register_trace_android_vh_save_cpu_resume(save_cpu_resume, NULL);
  54. return 0;
  55. }
  56. module_init(init_s2d_hooks);
  57. MODULE_DESCRIPTION("Qualcomm Technologies, Inc. Bootloader Hibernation Vendor hooks");
  58. MODULE_LICENSE("GPL");