xref: /openbmc/linux/drivers/gpu/drm/i915/gt/intel_engine_pm.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
124f90d66SChris Wilson /* SPDX-License-Identifier: MIT */
279ffac85SChris Wilson /*
379ffac85SChris Wilson  * Copyright © 2019 Intel Corporation
479ffac85SChris Wilson  */
579ffac85SChris Wilson 
679ffac85SChris Wilson #ifndef INTEL_ENGINE_PM_H
779ffac85SChris Wilson #define INTEL_ENGINE_PM_H
879ffac85SChris Wilson 
9*f61eae18SMatthew Brost #include "i915_drv.h"
10de5825beSChris Wilson #include "i915_request.h"
115f22e5b3SChris Wilson #include "intel_engine_types.h"
125f22e5b3SChris Wilson #include "intel_wakeref.h"
13*f61eae18SMatthew Brost #include "intel_gt_pm.h"
145f22e5b3SChris Wilson 
155f22e5b3SChris Wilson static inline bool
intel_engine_pm_is_awake(const struct intel_engine_cs * engine)165f22e5b3SChris Wilson intel_engine_pm_is_awake(const struct intel_engine_cs *engine)
175f22e5b3SChris Wilson {
185f22e5b3SChris Wilson 	return intel_wakeref_is_active(&engine->wakeref);
195f22e5b3SChris Wilson }
205f22e5b3SChris Wilson 
__intel_engine_pm_get(struct intel_engine_cs * engine)211a52faedSMatthew Brost static inline void __intel_engine_pm_get(struct intel_engine_cs *engine)
221a52faedSMatthew Brost {
231a52faedSMatthew Brost 	__intel_wakeref_get(&engine->wakeref);
241a52faedSMatthew Brost }
251a52faedSMatthew Brost 
intel_engine_pm_get(struct intel_engine_cs * engine)26c7302f20SChris Wilson static inline void intel_engine_pm_get(struct intel_engine_cs *engine)
27c7302f20SChris Wilson {
28c7302f20SChris Wilson 	intel_wakeref_get(&engine->wakeref);
29c7302f20SChris Wilson }
30c7302f20SChris Wilson 
intel_engine_pm_get_if_awake(struct intel_engine_cs * engine)31c7302f20SChris Wilson static inline bool intel_engine_pm_get_if_awake(struct intel_engine_cs *engine)
32de5147b8SChris Wilson {
33de5147b8SChris Wilson 	return intel_wakeref_get_if_active(&engine->wakeref);
34de5147b8SChris Wilson }
35de5147b8SChris Wilson 
intel_engine_pm_might_get(struct intel_engine_cs * engine)36*f61eae18SMatthew Brost static inline void intel_engine_pm_might_get(struct intel_engine_cs *engine)
37*f61eae18SMatthew Brost {
38*f61eae18SMatthew Brost 	if (!intel_engine_is_virtual(engine)) {
39*f61eae18SMatthew Brost 		intel_wakeref_might_get(&engine->wakeref);
40*f61eae18SMatthew Brost 	} else {
41*f61eae18SMatthew Brost 		struct intel_gt *gt = engine->gt;
42*f61eae18SMatthew Brost 		struct intel_engine_cs *tengine;
43*f61eae18SMatthew Brost 		intel_engine_mask_t tmp, mask = engine->mask;
44*f61eae18SMatthew Brost 
45*f61eae18SMatthew Brost 		for_each_engine_masked(tengine, gt, mask, tmp)
46*f61eae18SMatthew Brost 			intel_wakeref_might_get(&tengine->wakeref);
47*f61eae18SMatthew Brost 	}
48*f61eae18SMatthew Brost 	intel_gt_pm_might_get(engine->gt);
49*f61eae18SMatthew Brost }
50*f61eae18SMatthew Brost 
intel_engine_pm_put(struct intel_engine_cs * engine)51c7302f20SChris Wilson static inline void intel_engine_pm_put(struct intel_engine_cs *engine)
52c7302f20SChris Wilson {
53c7302f20SChris Wilson 	intel_wakeref_put(&engine->wakeref);
54c7302f20SChris Wilson }
55c34c5bcaSChris Wilson 
intel_engine_pm_put_async(struct intel_engine_cs * engine)5607779a76SChris Wilson static inline void intel_engine_pm_put_async(struct intel_engine_cs *engine)
5707779a76SChris Wilson {
5807779a76SChris Wilson 	intel_wakeref_put_async(&engine->wakeref);
5907779a76SChris Wilson }
6007779a76SChris Wilson 
intel_engine_pm_put_delay(struct intel_engine_cs * engine,unsigned long delay)61e9037e7fSChris Wilson static inline void intel_engine_pm_put_delay(struct intel_engine_cs *engine,
62e9037e7fSChris Wilson 					     unsigned long delay)
63e9037e7fSChris Wilson {
64e9037e7fSChris Wilson 	intel_wakeref_put_delay(&engine->wakeref, delay);
65e9037e7fSChris Wilson }
66e9037e7fSChris Wilson 
intel_engine_pm_flush(struct intel_engine_cs * engine)6707779a76SChris Wilson static inline void intel_engine_pm_flush(struct intel_engine_cs *engine)
6807779a76SChris Wilson {
6907779a76SChris Wilson 	intel_wakeref_unlock_wait(&engine->wakeref);
7007779a76SChris Wilson }
7107779a76SChris Wilson 
intel_engine_pm_might_put(struct intel_engine_cs * engine)72*f61eae18SMatthew Brost static inline void intel_engine_pm_might_put(struct intel_engine_cs *engine)
73*f61eae18SMatthew Brost {
74*f61eae18SMatthew Brost 	if (!intel_engine_is_virtual(engine)) {
75*f61eae18SMatthew Brost 		intel_wakeref_might_put(&engine->wakeref);
76*f61eae18SMatthew Brost 	} else {
77*f61eae18SMatthew Brost 		struct intel_gt *gt = engine->gt;
78*f61eae18SMatthew Brost 		struct intel_engine_cs *tengine;
79*f61eae18SMatthew Brost 		intel_engine_mask_t tmp, mask = engine->mask;
80*f61eae18SMatthew Brost 
81*f61eae18SMatthew Brost 		for_each_engine_masked(tengine, gt, mask, tmp)
82*f61eae18SMatthew Brost 			intel_wakeref_might_put(&tengine->wakeref);
83*f61eae18SMatthew Brost 	}
84*f61eae18SMatthew Brost 	intel_gt_pm_might_put(engine->gt);
85*f61eae18SMatthew Brost }
86*f61eae18SMatthew Brost 
87de5825beSChris Wilson static inline struct i915_request *
intel_engine_create_kernel_request(struct intel_engine_cs * engine)88de5825beSChris Wilson intel_engine_create_kernel_request(struct intel_engine_cs *engine)
89de5825beSChris Wilson {
90de5825beSChris Wilson 	struct i915_request *rq;
91de5825beSChris Wilson 
92de5825beSChris Wilson 	/*
93de5825beSChris Wilson 	 * The engine->kernel_context is special as it is used inside
94de5825beSChris Wilson 	 * the engine-pm barrier (see __engine_park()), circumventing
95de5825beSChris Wilson 	 * the usual mutexes and relying on the engine-pm barrier
96de5825beSChris Wilson 	 * instead. So whenever we use the engine->kernel_context
97de5825beSChris Wilson 	 * outside of the barrier, we must manually handle the
98de5825beSChris Wilson 	 * engine wakeref to serialise with the use inside.
99de5825beSChris Wilson 	 */
100de5825beSChris Wilson 	intel_engine_pm_get(engine);
101de5825beSChris Wilson 	rq = i915_request_create(engine->kernel_context);
102de5825beSChris Wilson 	intel_engine_pm_put(engine);
103de5825beSChris Wilson 
104de5825beSChris Wilson 	return rq;
105de5825beSChris Wilson }
106de5825beSChris Wilson 
10779ffac85SChris Wilson void intel_engine_init__pm(struct intel_engine_cs *engine);
10879ffac85SChris Wilson 
1093e42cc61SThomas Hellström void intel_engine_reset_pinned_contexts(struct intel_engine_cs *engine);
1103e42cc61SThomas Hellström 
11179ffac85SChris Wilson #endif /* INTEL_ENGINE_PM_H */
112