1dd08ebf6SMatthew Brost /* SPDX-License-Identifier: MIT */
2dd08ebf6SMatthew Brost /*
3dd08ebf6SMatthew Brost * Copyright © 2022 Intel Corporation
4dd08ebf6SMatthew Brost */
5dd08ebf6SMatthew Brost
6dd08ebf6SMatthew Brost #ifndef _XE_FORCE_WAKE_H_
7dd08ebf6SMatthew Brost #define _XE_FORCE_WAKE_H_
8dd08ebf6SMatthew Brost
9c73acc1eSFrancois Dugast #include "xe_assert.h"
10dd08ebf6SMatthew Brost #include "xe_force_wake_types.h"
11dd08ebf6SMatthew Brost
12dd08ebf6SMatthew Brost struct xe_gt;
13dd08ebf6SMatthew Brost
14dd08ebf6SMatthew Brost void xe_force_wake_init_gt(struct xe_gt *gt,
15dd08ebf6SMatthew Brost struct xe_force_wake *fw);
16dd08ebf6SMatthew Brost void xe_force_wake_init_engines(struct xe_gt *gt,
17dd08ebf6SMatthew Brost struct xe_force_wake *fw);
18dd08ebf6SMatthew Brost int xe_force_wake_get(struct xe_force_wake *fw,
19dd08ebf6SMatthew Brost enum xe_force_wake_domains domains);
20dd08ebf6SMatthew Brost int xe_force_wake_put(struct xe_force_wake *fw,
21dd08ebf6SMatthew Brost enum xe_force_wake_domains domains);
22dd08ebf6SMatthew Brost
23dd08ebf6SMatthew Brost static inline int
xe_force_wake_ref(struct xe_force_wake * fw,enum xe_force_wake_domains domain)24dd08ebf6SMatthew Brost xe_force_wake_ref(struct xe_force_wake *fw,
25dd08ebf6SMatthew Brost enum xe_force_wake_domains domain)
26dd08ebf6SMatthew Brost {
27*35feb8dbSHimal Prasad Ghimiray xe_gt_assert(fw->gt, domain != XE_FORCEWAKE_ALL);
28dd08ebf6SMatthew Brost return fw->domains[ffs(domain) - 1].ref;
29dd08ebf6SMatthew Brost }
30dd08ebf6SMatthew Brost
313541e19dSHimal Prasad Ghimiray /**
323541e19dSHimal Prasad Ghimiray * xe_force_wake_assert_held - asserts domain is awake
333541e19dSHimal Prasad Ghimiray * @fw : xe_force_wake structure
343541e19dSHimal Prasad Ghimiray * @domain: xe_force_wake_domains apart from XE_FORCEWAKE_ALL
353541e19dSHimal Prasad Ghimiray *
363541e19dSHimal Prasad Ghimiray * xe_force_wake_assert_held() is designed to confirm a particular
373541e19dSHimal Prasad Ghimiray * forcewake domain's wakefulness; it doesn't verify the wakefulness of
383541e19dSHimal Prasad Ghimiray * multiple domains. Make sure the caller doesn't input multiple
393541e19dSHimal Prasad Ghimiray * domains(XE_FORCEWAKE_ALL) as a parameter.
403541e19dSHimal Prasad Ghimiray */
41dd08ebf6SMatthew Brost static inline void
xe_force_wake_assert_held(struct xe_force_wake * fw,enum xe_force_wake_domains domain)42dd08ebf6SMatthew Brost xe_force_wake_assert_held(struct xe_force_wake *fw,
43dd08ebf6SMatthew Brost enum xe_force_wake_domains domain)
44dd08ebf6SMatthew Brost {
453541e19dSHimal Prasad Ghimiray xe_gt_assert(fw->gt, domain != XE_FORCEWAKE_ALL);
46c73acc1eSFrancois Dugast xe_gt_assert(fw->gt, fw->awake_domains & domain);
47dd08ebf6SMatthew Brost }
48dd08ebf6SMatthew Brost
49dd08ebf6SMatthew Brost #endif
50