xref: /linux/drivers/gpu/drm/xe/xe_gt.h (revision 36f353a1ebf88280f58d1ebfe2731251d9159456)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5 
6 #ifndef _XE_GT_H_
7 #define _XE_GT_H_
8 
9 #include <drm/drm_util.h>
10 
11 #include "xe_device_types.h"
12 #include "xe_hw_engine.h"
13 
14 #define for_each_hw_engine(hwe__, gt__, id__) \
15 	for ((id__) = 0; (id__) < ARRAY_SIZE((gt__)->hw_engines); (id__)++) \
16 		for_each_if(((hwe__) = (gt__)->hw_engines + (id__)) && \
17 			  xe_hw_engine_is_valid((hwe__)))
18 
19 #define CCS_MASK(gt) (((gt)->info.engine_mask & XE_HW_ENGINE_CCS_MASK) >> XE_HW_ENGINE_CCS0)
20 
21 #ifdef CONFIG_FAULT_INJECTION
22 #include <linux/fault-inject.h> /* XXX: fault-inject.h is broken */
23 extern struct fault_attr gt_reset_failure;
24 static inline bool xe_fault_inject_gt_reset(void)
25 {
26 	return should_fail(&gt_reset_failure, 1);
27 }
28 #else
29 static inline bool xe_fault_inject_gt_reset(void)
30 {
31 	return false;
32 }
33 #endif
34 
35 struct xe_gt *xe_gt_alloc(struct xe_tile *tile);
36 int xe_gt_init_hwconfig(struct xe_gt *gt);
37 int xe_gt_init_early(struct xe_gt *gt);
38 int xe_gt_init(struct xe_gt *gt);
39 int xe_gt_record_default_lrcs(struct xe_gt *gt);
40 void xe_gt_suspend_prepare(struct xe_gt *gt);
41 int xe_gt_suspend(struct xe_gt *gt);
42 int xe_gt_resume(struct xe_gt *gt);
43 void xe_gt_reset_async(struct xe_gt *gt);
44 void xe_gt_sanitize(struct xe_gt *gt);
45 void xe_gt_remove(struct xe_gt *gt);
46 
47 /**
48  * xe_gt_any_hw_engine_by_reset_domain - scan the list of engines and return the
49  * first that matches the same reset domain as @class
50  * @gt: GT structure
51  * @class: hw engine class to lookup
52  */
53 struct xe_hw_engine *
54 xe_gt_any_hw_engine_by_reset_domain(struct xe_gt *gt, enum xe_engine_class class);
55 
56 struct xe_hw_engine *xe_gt_hw_engine(struct xe_gt *gt,
57 				     enum xe_engine_class class,
58 				     u16 instance,
59 				     bool logical);
60 
61 static inline bool xe_gt_is_media_type(struct xe_gt *gt)
62 {
63 	return gt->info.type == XE_GT_TYPE_MEDIA;
64 }
65 
66 static inline bool xe_gt_is_usm_hwe(struct xe_gt *gt, struct xe_hw_engine *hwe)
67 {
68 	struct xe_device *xe = gt_to_xe(gt);
69 
70 	return xe->info.has_usm && hwe->class == XE_ENGINE_CLASS_COPY &&
71 		hwe->instance == gt->usm.reserved_bcs_instance;
72 }
73 
74 #endif
75