intel_gt_pm.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2019 Intel Corporation
  4. */
  5. #ifndef INTEL_GT_PM_H
  6. #define INTEL_GT_PM_H
  7. #include <linux/types.h>
  8. #include "intel_gt_types.h"
  9. #include "intel_wakeref.h"
  10. static inline bool intel_gt_pm_is_awake(const struct intel_gt *gt)
  11. {
  12. return intel_wakeref_is_active(&gt->wakeref);
  13. }
  14. static inline void intel_gt_pm_get_untracked(struct intel_gt *gt)
  15. {
  16. intel_wakeref_get(&gt->wakeref);
  17. }
  18. static inline intel_wakeref_t intel_gt_pm_get(struct intel_gt *gt)
  19. {
  20. intel_gt_pm_get_untracked(gt);
  21. return intel_wakeref_track(&gt->wakeref);
  22. }
  23. static inline void __intel_gt_pm_get(struct intel_gt *gt)
  24. {
  25. __intel_wakeref_get(&gt->wakeref);
  26. }
  27. static inline intel_wakeref_t intel_gt_pm_get_if_awake(struct intel_gt *gt)
  28. {
  29. if (!intel_wakeref_get_if_active(&gt->wakeref))
  30. return NULL;
  31. return intel_wakeref_track(&gt->wakeref);
  32. }
  33. static inline void intel_gt_pm_might_get(struct intel_gt *gt)
  34. {
  35. intel_wakeref_might_get(&gt->wakeref);
  36. }
  37. static inline void intel_gt_pm_put_untracked(struct intel_gt *gt)
  38. {
  39. intel_wakeref_put(&gt->wakeref);
  40. }
  41. static inline void intel_gt_pm_put(struct intel_gt *gt, intel_wakeref_t handle)
  42. {
  43. intel_wakeref_untrack(&gt->wakeref, handle);
  44. intel_gt_pm_put_untracked(gt);
  45. }
  46. static inline void intel_gt_pm_put_async_untracked(struct intel_gt *gt)
  47. {
  48. intel_wakeref_put_async(&gt->wakeref);
  49. }
  50. static inline void intel_gt_pm_might_put(struct intel_gt *gt)
  51. {
  52. intel_wakeref_might_put(&gt->wakeref);
  53. }
  54. static inline void intel_gt_pm_put_async(struct intel_gt *gt, intel_wakeref_t handle)
  55. {
  56. intel_wakeref_untrack(&gt->wakeref, handle);
  57. intel_gt_pm_put_async_untracked(gt);
  58. }
  59. #define with_intel_gt_pm(gt, wf) \
  60. for ((wf) = intel_gt_pm_get(gt); (wf); intel_gt_pm_put((gt), (wf)), (wf) = NULL)
  61. /**
  62. * with_intel_gt_pm_if_awake - if GT is PM awake, get a reference to prevent
  63. * it to sleep, run some code and then asynchrously put the reference
  64. * away.
  65. *
  66. * @gt: pointer to the gt
  67. * @wf: pointer to a temporary wakeref.
  68. */
  69. #define with_intel_gt_pm_if_awake(gt, wf) \
  70. for ((wf) = intel_gt_pm_get_if_awake(gt); (wf); intel_gt_pm_put_async((gt), (wf)), (wf) = NULL)
  71. static inline int intel_gt_pm_wait_for_idle(struct intel_gt *gt)
  72. {
  73. return intel_wakeref_wait_for_idle(&gt->wakeref);
  74. }
  75. void intel_gt_pm_init_early(struct intel_gt *gt);
  76. void intel_gt_pm_init(struct intel_gt *gt);
  77. void intel_gt_pm_fini(struct intel_gt *gt);
  78. void intel_gt_suspend_prepare(struct intel_gt *gt);
  79. void intel_gt_suspend_late(struct intel_gt *gt);
  80. int intel_gt_resume(struct intel_gt *gt);
  81. void intel_gt_resume_early(struct intel_gt *gt);
  82. void intel_gt_runtime_suspend(struct intel_gt *gt);
  83. int intel_gt_runtime_resume(struct intel_gt *gt);
  84. ktime_t intel_gt_get_awake_time(const struct intel_gt *gt);
  85. #define INTEL_WAKEREF_MOCK_GT ERR_PTR(-ENODEV)
  86. static inline bool is_mock_gt(const struct intel_gt *gt)
  87. {
  88. BUILD_BUG_ON(INTEL_WAKEREF_DEF == INTEL_WAKEREF_MOCK_GT);
  89. return I915_SELFTEST_ONLY(gt->awake == INTEL_WAKEREF_MOCK_GT);
  90. }
  91. #endif /* INTEL_GT_PM_H */