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