1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2019 Intel Corporation
5  */
6 
7 #ifndef INTEL_ENGINE_PM_H
8 #define INTEL_ENGINE_PM_H
9 
10 #include "i915_request.h"
11 #include "intel_engine_types.h"
12 #include "intel_wakeref.h"
13 
14 static inline bool
15 intel_engine_pm_is_awake(const struct intel_engine_cs *engine)
16 {
17 	return intel_wakeref_is_active(&engine->wakeref);
18 }
19 
20 static inline void intel_engine_pm_get(struct intel_engine_cs *engine)
21 {
22 	intel_wakeref_get(&engine->wakeref);
23 }
24 
25 static inline bool intel_engine_pm_get_if_awake(struct intel_engine_cs *engine)
26 {
27 	return intel_wakeref_get_if_active(&engine->wakeref);
28 }
29 
30 static inline void intel_engine_pm_put(struct intel_engine_cs *engine)
31 {
32 	intel_wakeref_put(&engine->wakeref);
33 }
34 
35 static inline void intel_engine_pm_put_async(struct intel_engine_cs *engine)
36 {
37 	intel_wakeref_put_async(&engine->wakeref);
38 }
39 
40 static inline void intel_engine_pm_put_delay(struct intel_engine_cs *engine,
41 					     unsigned long delay)
42 {
43 	intel_wakeref_put_delay(&engine->wakeref, delay);
44 }
45 
46 static inline void intel_engine_pm_flush(struct intel_engine_cs *engine)
47 {
48 	intel_wakeref_unlock_wait(&engine->wakeref);
49 }
50 
51 static inline struct i915_request *
52 intel_engine_create_kernel_request(struct intel_engine_cs *engine)
53 {
54 	struct i915_request *rq;
55 
56 	/*
57 	 * The engine->kernel_context is special as it is used inside
58 	 * the engine-pm barrier (see __engine_park()), circumventing
59 	 * the usual mutexes and relying on the engine-pm barrier
60 	 * instead. So whenever we use the engine->kernel_context
61 	 * outside of the barrier, we must manually handle the
62 	 * engine wakeref to serialise with the use inside.
63 	 */
64 	intel_engine_pm_get(engine);
65 	rq = i915_request_create(engine->kernel_context);
66 	intel_engine_pm_put(engine);
67 
68 	return rq;
69 }
70 
71 void intel_engine_init__pm(struct intel_engine_cs *engine);
72 
73 #endif /* INTEL_ENGINE_PM_H */
74