xref: /linux/drivers/gpu/drm/xe/xe_force_wake.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
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 unsigned int __must_check xe_force_wake_get(struct xe_force_wake *fw,
19 					    enum xe_force_wake_domains domains);
20 void xe_force_wake_put(struct xe_force_wake *fw, unsigned int fw_ref);
21 
22 static inline int
23 xe_force_wake_ref(struct xe_force_wake *fw,
24 		  enum xe_force_wake_domains domain)
25 {
26 	xe_gt_assert(fw->gt, domain != XE_FORCEWAKE_ALL);
27 	return fw->domains[ffs(domain) - 1].ref;
28 }
29 
30 /**
31  * xe_force_wake_assert_held - asserts domain is awake
32  * @fw : xe_force_wake structure
33  * @domain: xe_force_wake_domains apart from XE_FORCEWAKE_ALL
34  *
35  * xe_force_wake_assert_held() is designed to confirm a particular
36  * forcewake domain's wakefulness; it doesn't verify the wakefulness of
37  * multiple domains. Make sure the caller doesn't input multiple
38  * domains(XE_FORCEWAKE_ALL) as a parameter.
39  */
40 static inline void
41 xe_force_wake_assert_held(struct xe_force_wake *fw,
42 			  enum xe_force_wake_domains domain)
43 {
44 	xe_gt_assert(fw->gt, domain != XE_FORCEWAKE_ALL);
45 	xe_gt_assert(fw->gt, fw->awake_domains & domain);
46 }
47 
48 /**
49  * xe_force_wake_ref_has_domain - verifies if the domains are in fw_ref
50  * @fw_ref : the force_wake reference
51  * @domain : forcewake domain to verify
52  *
53  * This function confirms whether the @fw_ref includes a reference to the
54  * specified @domain.
55  *
56  * Return: true if domain is refcounted.
57  */
58 static inline bool
59 xe_force_wake_ref_has_domain(unsigned int fw_ref, enum xe_force_wake_domains domain)
60 {
61 	return fw_ref & domain;
62 }
63 
64 #endif
65