xref: /linux/drivers/gpu/drm/xe/xe_force_wake.h (revision a9aaf1ff88a8cb99a1335c9eb76de637f0cf8c10)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #ifndef _XE_FORCE_WAKE_H_
7 #define _XE_FORCE_WAKE_H_
8 
9 #include "xe_assert.h"
10 #include "xe_force_wake_types.h"
11 
12 struct xe_gt;
13 
14 void xe_force_wake_init_gt(struct xe_gt *gt,
15 			   struct xe_force_wake *fw);
16 void xe_force_wake_init_engines(struct xe_gt *gt,
17 				struct xe_force_wake *fw);
18 int xe_force_wake_get(struct xe_force_wake *fw,
19 		      enum xe_force_wake_domains domains);
20 int xe_force_wake_put(struct xe_force_wake *fw,
21 		      enum xe_force_wake_domains domains);
22 
23 static inline int
24 xe_force_wake_ref(struct xe_force_wake *fw,
25 		  enum xe_force_wake_domains domain)
26 {
27 	xe_gt_assert(fw->gt, domain != XE_FORCEWAKE_ALL);
28 	return fw->domains[ffs(domain) - 1].ref;
29 }
30 
31 /**
32  * xe_force_wake_assert_held - asserts domain is awake
33  * @fw : xe_force_wake structure
34  * @domain: xe_force_wake_domains apart from XE_FORCEWAKE_ALL
35  *
36  * xe_force_wake_assert_held() is designed to confirm a particular
37  * forcewake domain's wakefulness; it doesn't verify the wakefulness of
38  * multiple domains. Make sure the caller doesn't input multiple
39  * domains(XE_FORCEWAKE_ALL) as a parameter.
40  */
41 static inline void
42 xe_force_wake_assert_held(struct xe_force_wake *fw,
43 			  enum xe_force_wake_domains domain)
44 {
45 	xe_gt_assert(fw->gt, domain != XE_FORCEWAKE_ALL);
46 	xe_gt_assert(fw->gt, fw->awake_domains & domain);
47 }
48 
49 #endif
50