xref: /linux/drivers/gpu/drm/i915/gt/intel_gt_pm.h (revision 2672031b20f6681514bef14ddcfe8c62c2757d11)
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(&gt->wakeref);
17 }
18 
19 static inline void intel_gt_pm_get_untracked(struct intel_gt *gt)
20 {
21 	intel_wakeref_get(&gt->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(&gt->wakeref);
28 }
29 
30 static inline void __intel_gt_pm_get(struct intel_gt *gt)
31 {
32 	__intel_wakeref_get(&gt->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(&gt->wakeref))
38 		return 0;
39 
40 	return intel_wakeref_track(&gt->wakeref);
41 }
42 
43 static inline void intel_gt_pm_might_get(struct intel_gt *gt)
44 {
45 	intel_wakeref_might_get(&gt->wakeref);
46 }
47 
48 static inline void intel_gt_pm_put_untracked(struct intel_gt *gt)
49 {
50 	intel_wakeref_put(&gt->wakeref);
51 }
52 
53 static inline void intel_gt_pm_put(struct intel_gt *gt, intel_wakeref_t handle)
54 {
55 	intel_wakeref_untrack(&gt->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(&gt->wakeref);
62 }
63 
64 static inline void intel_gt_pm_might_put(struct intel_gt *gt)
65 {
66 	intel_wakeref_might_put(&gt->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(&gt->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 = 0)
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 = 0)
88 
89 static inline int intel_gt_pm_wait_for_idle(struct intel_gt *gt)
90 {
91 	return intel_wakeref_wait_for_idle(&gt->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 static inline bool is_mock_gt(const struct intel_gt *gt)
109 {
110 	return I915_SELFTEST_ONLY(gt->awake == -ENODEV);
111 }
112 
113 #endif /* INTEL_GT_PM_H */
114