1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #include "xe_tuning.h" 7 8 #include <linux/error-injection.h> 9 10 #include <kunit/visibility.h> 11 12 #include <drm/drm_managed.h> 13 #include <drm/drm_print.h> 14 15 #include "regs/xe_engine_regs.h" 16 #include "regs/xe_gt_regs.h" 17 #include "xe_gt_types.h" 18 #include "xe_platform_types.h" 19 #include "xe_rtp.h" 20 #include "xe_sriov.h" 21 22 #undef XE_REG_MCR 23 #define XE_REG_MCR(...) XE_REG(__VA_ARGS__, .mcr = 1) 24 25 VISIBLE_IF_KUNIT const struct xe_rtp_table_sr gt_tunings = XE_RTP_TABLE_SR( 26 { XE_RTP_NAME("Tuning: Blend Fill Caching Optimization Disable"), 27 XE_RTP_RULES(PLATFORM(DG2)), 28 XE_RTP_ACTIONS(SET(XEHP_L3SCQREG7, BLEND_FILL_CACHING_OPT_DIS)) 29 }, 30 { XE_RTP_NAME("Tuning: 32B Access Enable"), 31 XE_RTP_RULES(PLATFORM(DG2)), 32 XE_RTP_ACTIONS(SET(XEHP_SQCM, EN_32B_ACCESS)) 33 }, 34 35 /* Xe2 */ 36 37 { XE_RTP_NAME("Tuning: L3 cache"), 38 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(2001, 3499)), 39 XE_RTP_ACTIONS(FIELD_SET(XEHP_L3SQCREG5, L3_PWM_TIMER_INIT_VAL_MASK, 40 REG_FIELD_PREP(L3_PWM_TIMER_INIT_VAL_MASK, 0x7f))) 41 }, 42 { XE_RTP_NAME("Tuning: L3 cache - media"), 43 XE_RTP_RULES(MEDIA_VERSION_RANGE(2000, 3499)), 44 XE_RTP_ACTIONS(FIELD_SET(XE2LPM_L3SQCREG5, L3_PWM_TIMER_INIT_VAL_MASK, 45 REG_FIELD_PREP(L3_PWM_TIMER_INIT_VAL_MASK, 0x7f))) 46 }, 47 { XE_RTP_NAME("Tuning: Compression Overfetch"), 48 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(2001, 3499), 49 FUNC(xe_rtp_match_has_flat_ccs)), 50 XE_RTP_ACTIONS(CLR(CCCHKNREG1, ENCOMPPERFFIX), 51 SET(CCCHKNREG1, L3CMPCTRL)) 52 }, 53 { XE_RTP_NAME("Tuning: Compression Overfetch - media"), 54 XE_RTP_RULES(MEDIA_VERSION_RANGE(2000, XE_RTP_END_VERSION_UNDEFINED)), 55 XE_RTP_ACTIONS(CLR(XE2LPM_CCCHKNREG1, ENCOMPPERFFIX), 56 SET(XE2LPM_CCCHKNREG1, L3CMPCTRL)) 57 }, 58 { XE_RTP_NAME("Tuning: Enable compressible partial write overfetch in L3"), 59 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(2001, 3499)), 60 XE_RTP_ACTIONS(SET(L3SQCREG3, COMPPWOVERFETCHEN)) 61 }, 62 { XE_RTP_NAME("Tuning: Enable compressible partial write overfetch in L3 - media"), 63 XE_RTP_RULES(MEDIA_VERSION_RANGE(2000, XE_RTP_END_VERSION_UNDEFINED)), 64 XE_RTP_ACTIONS(SET(XE2LPM_L3SQCREG3, COMPPWOVERFETCHEN)) 65 }, 66 { XE_RTP_NAME("Tuning: L2 Overfetch Compressible Only"), 67 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(2001, XE_RTP_END_VERSION_UNDEFINED), 68 FUNC(xe_rtp_match_has_flat_ccs)), 69 XE_RTP_ACTIONS(SET(L3SQCREG2, 70 COMPMEMRD256BOVRFETCHEN)) 71 }, 72 { XE_RTP_NAME("Tuning: L2 Overfetch Compressible Only - media"), 73 XE_RTP_RULES(MEDIA_VERSION_RANGE(2000, XE_RTP_END_VERSION_UNDEFINED), 74 FUNC(xe_rtp_match_has_flat_ccs)), 75 XE_RTP_ACTIONS(SET(XE2LPM_L3SQCREG2, 76 COMPMEMRD256BOVRFETCHEN)) 77 }, 78 { XE_RTP_NAME("Tuning: Stateless compression control"), 79 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(2001, XE_RTP_END_VERSION_UNDEFINED)), 80 XE_RTP_ACTIONS(FIELD_SET(STATELESS_COMPRESSION_CTRL, UNIFIED_COMPRESSION_FORMAT, 81 REG_FIELD_PREP(UNIFIED_COMPRESSION_FORMAT, 0))) 82 }, 83 { XE_RTP_NAME("Tuning: Stateless compression control - media"), 84 XE_RTP_RULES(MEDIA_VERSION_RANGE(1301, XE_RTP_END_VERSION_UNDEFINED)), 85 XE_RTP_ACTIONS(FIELD_SET(STATELESS_COMPRESSION_CTRL, UNIFIED_COMPRESSION_FORMAT, 86 REG_FIELD_PREP(UNIFIED_COMPRESSION_FORMAT, 0))) 87 }, 88 { XE_RTP_NAME("Tuning: L3 RW flush all Cache"), 89 XE_RTP_RULES(GRAPHICS_VERSION(2004)), 90 XE_RTP_ACTIONS(SET(SCRATCH3_LBCF, RWFLUSHALLEN)) 91 }, 92 { XE_RTP_NAME("Tuning: L3 RW flush all cache - media"), 93 XE_RTP_RULES(MEDIA_VERSION(2000)), 94 XE_RTP_ACTIONS(SET(XE2LPM_SCRATCH3_LBCF, RWFLUSHALLEN)) 95 }, 96 97 /* Xe3p */ 98 99 { XE_RTP_NAME("Tuning: Set STLB Bank Hash Mode to 4KB"), 100 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(3510, XE_RTP_END_VERSION_UNDEFINED), 101 IS_INTEGRATED), 102 XE_RTP_ACTIONS(FIELD_SET(GAMSTLB_CTRL, BANK_HASH_MODE, 103 BANK_HASH_4KB_MODE)) 104 }, 105 { XE_RTP_NAME("Tuning: Force All Non-Compressible Memory Reads to be 256B Overfetches"), 106 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(3510, XE_RTP_END_VERSION_UNDEFINED)), 107 XE_RTP_ACTIONS(SET(L3SQCREG2, NONCOMPMEMRD256BOVRFETCHEN)) 108 }, 109 ); 110 EXPORT_SYMBOL_IF_KUNIT(gt_tunings); 111 112 static const struct xe_rtp_table_sr engine_tunings = XE_RTP_TABLE_SR( 113 { XE_RTP_NAME("Tuning: L3 Hashing Mask"), 114 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(1200, 1210), 115 FUNC(xe_rtp_match_first_render_or_compute)), 116 XE_RTP_ACTIONS(CLR(XELP_GARBCNTL, XELP_BUS_HASH_CTL_BIT_EXC)) 117 }, 118 { XE_RTP_NAME("Tuning: Set Indirect State Override"), 119 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(1200, 1274), 120 ENGINE_CLASS(RENDER)), 121 XE_RTP_ACTIONS(SET(SAMPLER_MODE, INDIRECT_STATE_BASE_ADDR_OVERRIDE)) 122 }, 123 { XE_RTP_NAME("Tuning: Disable NULL query for Anyhit Shader"), 124 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(2000, XE_RTP_END_VERSION_UNDEFINED), 125 ENGINE_CLASS(RENDER)), 126 XE_RTP_ACTIONS(SET(RT_CTRL, DIS_NULL_QUERY)) 127 }, 128 { XE_RTP_NAME("Tuning: disable HW reporting of ctx switch to GHWSP"), 129 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(3500, XE_RTP_END_VERSION_UNDEFINED)), 130 XE_RTP_ACTIONS(SET(CSFE_CHICKEN1(0), 131 GHWSP_CSB_REPORT_DIS, 132 XE_RTP_ACTION_FLAG(ENGINE_BASE))) 133 }, 134 { XE_RTP_NAME("Tuning: TileY 2x2 Walk"), 135 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(3510, XE_RTP_END_VERSION_UNDEFINED), 136 FUNC(xe_rtp_match_first_render_or_compute)), 137 XE_RTP_ACTIONS(SET(TDL_TSL_CHICKEN2, TILEY_LOCALID)) 138 }, 139 ); 140 141 static const struct xe_rtp_table_sr lrc_tunings = XE_RTP_TABLE_SR( 142 { XE_RTP_NAME("Tuning: Windower HW Filtering"), 143 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(3000, 3599), ENGINE_CLASS(RENDER)), 144 XE_RTP_ACTIONS(SET(XEHP_COMMON_SLICE_CHICKEN4, HW_FILTERING)) 145 }, 146 147 /* DG2 */ 148 149 { XE_RTP_NAME("Tuning: L3 cache"), 150 XE_RTP_RULES(PLATFORM(DG2), ENGINE_CLASS(RENDER)), 151 XE_RTP_ACTIONS(FIELD_SET(XEHP_L3SQCREG5, L3_PWM_TIMER_INIT_VAL_MASK, 152 REG_FIELD_PREP(L3_PWM_TIMER_INIT_VAL_MASK, 0x7f))) 153 }, 154 { XE_RTP_NAME("Tuning: TDS gang timer"), 155 XE_RTP_RULES(PLATFORM(DG2), ENGINE_CLASS(RENDER)), 156 /* read verification is ignored as in i915 - need to check enabling */ 157 XE_RTP_ACTIONS(FIELD_SET_NO_READ_MASK(XEHP_FF_MODE2, 158 FF_MODE2_TDS_TIMER_MASK, 159 FF_MODE2_TDS_TIMER_128)) 160 }, 161 { XE_RTP_NAME("Tuning: TBIMR fast clip"), 162 XE_RTP_RULES(PLATFORM(DG2), ENGINE_CLASS(RENDER)), 163 XE_RTP_ACTIONS(SET(CHICKEN_RASTER_2, TBIMR_FAST_CLIP)) 164 }, 165 166 /* Xe_LPG */ 167 168 { XE_RTP_NAME("Tuning: L3 cache"), 169 XE_RTP_RULES(GRAPHICS_VERSION_RANGE(1270, 1274), ENGINE_CLASS(RENDER)), 170 XE_RTP_ACTIONS(FIELD_SET(XEHP_L3SQCREG5, L3_PWM_TIMER_INIT_VAL_MASK, 171 REG_FIELD_PREP(L3_PWM_TIMER_INIT_VAL_MASK, 0x7f))) 172 }, 173 174 /* Xe2_HPG */ 175 176 { XE_RTP_NAME("Tuning: vs hit max value"), 177 XE_RTP_RULES(GRAPHICS_VERSION(2001), ENGINE_CLASS(RENDER)), 178 XE_RTP_ACTIONS(FIELD_SET(FF_MODE, VS_HIT_MAX_VALUE_MASK, 179 REG_FIELD_PREP(VS_HIT_MAX_VALUE_MASK, 0x3f))) 180 }, 181 ); 182 183 /** 184 * xe_tuning_init - initialize gt with tunings bookkeeping 185 * @gt: GT instance to initialize 186 * 187 * Returns 0 for success, negative error code otherwise. 188 */ 189 int xe_tuning_init(struct xe_gt *gt) 190 { 191 struct xe_device *xe = gt_to_xe(gt); 192 size_t n_lrc, n_engine, n_gt, total; 193 unsigned long *p; 194 195 n_gt = BITS_TO_LONGS(gt_tunings.n_entries); 196 n_engine = BITS_TO_LONGS(engine_tunings.n_entries); 197 n_lrc = BITS_TO_LONGS(lrc_tunings.n_entries); 198 total = n_gt + n_engine + n_lrc; 199 200 p = drmm_kzalloc(&xe->drm, sizeof(*p) * total, GFP_KERNEL); 201 if (!p) 202 return -ENOMEM; 203 204 gt->tuning_active.gt = p; 205 p += n_gt; 206 gt->tuning_active.engine = p; 207 p += n_engine; 208 gt->tuning_active.lrc = p; 209 210 return 0; 211 } 212 ALLOW_ERROR_INJECTION(xe_tuning_init, ERRNO); /* See xe_pci_probe() */ 213 214 void xe_tuning_process_gt(struct xe_gt *gt) 215 { 216 struct xe_rtp_process_ctx ctx = XE_RTP_PROCESS_CTX_INITIALIZER(gt); 217 218 xe_rtp_process_ctx_enable_active_tracking(&ctx, 219 gt->tuning_active.gt, 220 gt_tunings.n_entries); 221 xe_rtp_process_to_sr(&ctx, >_tunings, >->reg_sr, false); 222 } 223 EXPORT_SYMBOL_IF_KUNIT(xe_tuning_process_gt); 224 225 void xe_tuning_process_engine(struct xe_hw_engine *hwe) 226 { 227 struct xe_rtp_process_ctx ctx = XE_RTP_PROCESS_CTX_INITIALIZER(hwe); 228 229 xe_rtp_process_ctx_enable_active_tracking(&ctx, 230 hwe->gt->tuning_active.engine, 231 engine_tunings.n_entries); 232 xe_rtp_process_to_sr(&ctx, &engine_tunings, &hwe->reg_sr, false); 233 } 234 EXPORT_SYMBOL_IF_KUNIT(xe_tuning_process_engine); 235 236 /** 237 * xe_tuning_process_lrc - process lrc tunings 238 * @hwe: engine instance to process tunings for 239 * 240 * Process LRC table for this platform, saving in @hwe all the tunings that need 241 * to be applied on context restore. These are tunings touching registers that 242 * are part of the HW context image. 243 */ 244 void xe_tuning_process_lrc(struct xe_hw_engine *hwe) 245 { 246 struct xe_rtp_process_ctx ctx = XE_RTP_PROCESS_CTX_INITIALIZER(hwe); 247 248 xe_rtp_process_ctx_enable_active_tracking(&ctx, 249 hwe->gt->tuning_active.lrc, 250 lrc_tunings.n_entries); 251 xe_rtp_process_to_sr(&ctx, &lrc_tunings, &hwe->reg_lrc, true); 252 } 253 254 /** 255 * xe_tuning_dump() - Dump GT tuning info into a drm printer. 256 * @gt: the &xe_gt 257 * @p: the &drm_printer 258 * 259 * Return: always 0. 260 */ 261 int xe_tuning_dump(struct xe_gt *gt, struct drm_printer *p) 262 { 263 size_t idx; 264 265 drm_printf(p, "GT Tunings\n"); 266 for_each_set_bit(idx, gt->tuning_active.gt, gt_tunings.n_entries) 267 drm_printf_indent(p, 1, "%s\n", gt_tunings.entries[idx].name); 268 269 drm_puts(p, "\n"); 270 drm_printf(p, "Engine Tunings\n"); 271 for_each_set_bit(idx, gt->tuning_active.engine, engine_tunings.n_entries) 272 drm_printf_indent(p, 1, "%s\n", engine_tunings.entries[idx].name); 273 274 drm_puts(p, "\n"); 275 drm_printf(p, "LRC Tunings\n"); 276 for_each_set_bit(idx, gt->tuning_active.lrc, lrc_tunings.n_entries) 277 drm_printf_indent(p, 1, "%s\n", lrc_tunings.entries[idx].name); 278 279 return 0; 280 } 281