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.h" 12 #include "xe_device_types.h" 13 #include "xe_gt_sriov_vf.h" 14 #include "xe_hw_engine.h" 15 16 #define for_each_hw_engine(hwe__, gt__, id__) \ 17 for ((id__) = 0; (id__) < ARRAY_SIZE((gt__)->hw_engines); (id__)++) \ 18 for_each_if(((hwe__) = (gt__)->hw_engines + (id__)) && \ 19 xe_hw_engine_is_valid((hwe__))) 20 21 #define XE_ENGINE_INSTANCES_FROM_MASK(gt, NAME) \ 22 (((gt)->info.engine_mask & XE_HW_ENGINE_##NAME##_MASK) >> XE_HW_ENGINE_##NAME##0) 23 24 #define RCS_INSTANCES(gt) XE_ENGINE_INSTANCES_FROM_MASK(gt, RCS) 25 #define VCS_INSTANCES(gt) XE_ENGINE_INSTANCES_FROM_MASK(gt, VCS) 26 #define VECS_INSTANCES(gt) XE_ENGINE_INSTANCES_FROM_MASK(gt, VECS) 27 #define CCS_INSTANCES(gt) XE_ENGINE_INSTANCES_FROM_MASK(gt, CCS) 28 #define GSCCS_INSTANCES(gt) XE_ENGINE_INSTANCES_FROM_MASK(gt, GSCCS) 29 30 /* Our devices have up to 4 media slices */ 31 #define MAX_MEDIA_SLICES 4 32 33 #define GT_VER(gt) ({ \ 34 typeof(gt) gt_ = (gt); \ 35 struct xe_device *xe = gt_to_xe(gt_); \ 36 xe_gt_is_media_type(gt_) ? MEDIA_VER(xe) : GRAPHICS_VER(xe); \ 37 }) 38 39 struct xe_gt *xe_gt_alloc(struct xe_tile *tile); 40 int xe_gt_init_early(struct xe_gt *gt); 41 int xe_gt_init(struct xe_gt *gt); 42 void xe_gt_mmio_init(struct xe_gt *gt); 43 void xe_gt_declare_wedged(struct xe_gt *gt); 44 int xe_gt_record_default_lrcs(struct xe_gt *gt); 45 46 /** 47 * xe_gt_record_user_engines - save data related to engines available to 48 * userspace 49 * @gt: GT structure 50 * 51 * Walk the available HW engines from gt->info.engine_mask and calculate data 52 * related to those engines that may be used by userspace. To be used whenever 53 * available engines change in runtime (e.g. with ccs_mode) or during 54 * initialization 55 */ 56 void xe_gt_record_user_engines(struct xe_gt *gt); 57 58 void xe_gt_suspend_prepare(struct xe_gt *gt); 59 int xe_gt_suspend(struct xe_gt *gt); 60 void xe_gt_shutdown(struct xe_gt *gt); 61 int xe_gt_resume(struct xe_gt *gt); 62 void xe_gt_reset_async(struct xe_gt *gt); 63 int xe_gt_runtime_resume(struct xe_gt *gt); 64 int xe_gt_runtime_suspend(struct xe_gt *gt); 65 void xe_gt_sanitize(struct xe_gt *gt); 66 int xe_gt_sanitize_freq(struct xe_gt *gt); 67 68 /** 69 * xe_gt_wait_for_reset - wait for gt's async reset to finalize. 70 * @gt: GT structure 71 * Return: 72 * %true if it waited for the work to finish execution, 73 * %false if there was no scheduled reset or it was done. 74 */ 75 static inline bool xe_gt_wait_for_reset(struct xe_gt *gt) 76 { 77 return flush_work(>->reset.worker); 78 } 79 80 /** 81 * xe_gt_reset - perform synchronous reset 82 * @gt: GT structure 83 * Return: 84 * %true if it waited for the reset to finish, 85 * %false if there was no scheduled reset. 86 */ 87 static inline bool xe_gt_reset(struct xe_gt *gt) 88 { 89 xe_gt_reset_async(gt); 90 return xe_gt_wait_for_reset(gt); 91 } 92 93 /** 94 * xe_gt_any_hw_engine_by_reset_domain - scan the list of engines and return the 95 * first that matches the same reset domain as @class 96 * @gt: GT structure 97 * @class: hw engine class to lookup 98 */ 99 struct xe_hw_engine * 100 xe_gt_any_hw_engine_by_reset_domain(struct xe_gt *gt, enum xe_engine_class class); 101 102 /** 103 * xe_gt_any_hw_engine - scan the list of engines and return the 104 * first available 105 * @gt: GT structure 106 */ 107 struct xe_hw_engine *xe_gt_any_hw_engine(struct xe_gt *gt); 108 109 struct xe_hw_engine *xe_gt_hw_engine(struct xe_gt *gt, 110 enum xe_engine_class class, 111 u16 instance, 112 bool logical); 113 114 static inline bool xe_gt_has_indirect_ring_state(struct xe_gt *gt) 115 { 116 return gt->info.has_indirect_ring_state && 117 xe_device_uc_enabled(gt_to_xe(gt)); 118 } 119 120 static inline bool xe_gt_is_main_type(struct xe_gt *gt) 121 { 122 return gt->info.type == XE_GT_TYPE_MAIN; 123 } 124 125 static inline bool xe_gt_is_media_type(struct xe_gt *gt) 126 { 127 return gt->info.type == XE_GT_TYPE_MEDIA; 128 } 129 130 static inline bool xe_gt_is_usm_hwe(struct xe_gt *gt, struct xe_hw_engine *hwe) 131 { 132 return hwe->class == XE_ENGINE_CLASS_COPY && 133 (gt->usm.paging_logical_mask & BIT(hwe->logical_instance)); 134 } 135 136 /** 137 * xe_gt_recovery_pending() - GT recovery pending 138 * @gt: the &xe_gt 139 * 140 * Return: True if GT recovery in pending, False otherwise 141 */ 142 static inline bool xe_gt_recovery_pending(struct xe_gt *gt) 143 { 144 return IS_SRIOV_VF(gt_to_xe(gt)) && 145 xe_gt_sriov_vf_recovery_pending(gt); 146 } 147 148 /** 149 * xe_gt_supports_multi_queue() - Check if gt supports multi queue for the 150 * specified engine class. 151 * 152 * @gt: the GT object 153 * @class: hwe class type 154 * 155 * Return: true if the hw engine class supports multi queue, else false 156 */ 157 static inline bool xe_gt_supports_multi_queue(const struct xe_gt *gt, 158 enum xe_engine_class class) 159 { 160 return gt->info.multi_queue_engine_class_mask & BIT(class); 161 } 162 163 #endif 164