Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: preparation for using PAT index

This patch is a preparation for replacing enum i915_cache_level with PAT
index. Caching policy for buffer objects is set through the PAT index in
PTE, the old i915_cache_level is not sufficient to represent all caching
modes supported by the hardware.

Preparing the transition by adding some platform dependent data structures
and helper functions to translate the cache_level to pat_index.

cachelevel_to_pat: a platform dependent array mapping cache_level to
pat_index.

max_pat_index: the maximum PAT index recommended in hardware specification
Needed for validating the PAT index passed in from user
space.

i915_gem_get_pat_index: function to convert cache_level to PAT index.

obj_to_i915(obj): macro moved to header file for wider usage.

I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
convenience of coding.

Cc: Chris Wilson <chris.p.wilson@linux.intel.com>
Cc: Matt Roper <matthew.d.roper@intel.com>
Signed-off-by: Fei Yang <fei.yang@intel.com>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230509165200.1740-2-fei.yang@intel.com

authored by

Fei Yang and committed by
Andi Shyti
5e352e32 5b8ff071

+116 -11
+9
drivers/gpu/drm/i915/gem/i915_gem_object.c
··· 45 45 46 46 static const struct drm_gem_object_funcs i915_gem_object_funcs; 47 47 48 + unsigned int i915_gem_get_pat_index(struct drm_i915_private *i915, 49 + enum i915_cache_level level) 50 + { 51 + if (drm_WARN_ON(&i915->drm, level >= I915_MAX_CACHE_LEVEL)) 52 + return 0; 53 + 54 + return INTEL_INFO(i915)->cachelevel_to_pat[level]; 55 + } 56 + 48 57 struct drm_i915_gem_object *i915_gem_object_alloc(void) 49 58 { 50 59 struct drm_i915_gem_object *obj;
+4
drivers/gpu/drm/i915/gem/i915_gem_object.h
··· 20 20 21 21 enum intel_region_id; 22 22 23 + #define obj_to_i915(obj__) to_i915((obj__)->base.dev) 24 + 23 25 static inline bool i915_gem_object_size_2big(u64 size) 24 26 { 25 27 struct drm_i915_gem_object *obj; ··· 32 30 return false; 33 31 } 34 32 33 + unsigned int i915_gem_get_pat_index(struct drm_i915_private *i915, 34 + enum i915_cache_level level); 35 35 void i915_gem_init__objects(struct drm_i915_private *i915); 36 36 37 37 void i915_objects_module_exit(void);
+7
drivers/gpu/drm/i915/gem/i915_gem_object_types.h
··· 194 194 * engine. 195 195 */ 196 196 I915_CACHE_WT, 197 + /** 198 + * @I915_MAX_CACHE_LEVEL: 199 + * 200 + * Mark the last entry in the enum. Used for defining cachelevel_to_pat 201 + * array for cache_level to pat translation table. 202 + */ 203 + I915_MAX_CACHE_LEVEL, 197 204 }; 198 205 199 206 enum i915_map_type {
-2
drivers/gpu/drm/i915/gem/i915_gem_shrinker.c
··· 460 460 fs_reclaim_release(GFP_KERNEL); 461 461 } 462 462 463 - #define obj_to_i915(obj__) to_i915((obj__)->base.dev) 464 - 465 463 /** 466 464 * i915_gem_object_make_unshrinkable - Hide the object from the shrinker. By 467 465 * default all object types that support shrinking(see IS_SHRINKABLE), will also
+6
drivers/gpu/drm/i915/gt/gen8_ppgtt.c
··· 78 78 case I915_CACHE_WT: 79 79 pte |= GEN12_PPGTT_PTE_PAT0; 80 80 break; 81 + default: 82 + /* This should never happen. Added to deal with the compile 83 + * error due to the addition of I915_MAX_CACHE_LEVEL. Will 84 + * be removed by the pat_index patch. 85 + */ 86 + break; 81 87 } 82 88 83 89 return pte;
+6
drivers/gpu/drm/i915/gt/intel_ggtt.c
··· 242 242 case I915_CACHE_WT: 243 243 pte |= MTL_GGTT_PTE_PAT0; 244 244 break; 245 + default: 246 + /* This should never happen. Added to deal with the compile 247 + * error due to the addition of I915_MAX_CACHE_LEVEL. Will 248 + * be removed by the pat_index patch. 249 + */ 250 + break; 245 251 } 246 252 247 253 return pte;
+70 -9
drivers/gpu/drm/i915/i915_pci.c
··· 29 29 #include "display/intel_display.h" 30 30 #include "gt/intel_gt_regs.h" 31 31 #include "gt/intel_sa_media.h" 32 + #include "gem/i915_gem_object_types.h" 32 33 33 34 #include "i915_driver.h" 34 35 #include "i915_drv.h" ··· 164 163 .gamma_lut_tests = DRM_COLOR_LUT_NON_DECREASING, \ 165 164 } 166 165 166 + #define LEGACY_CACHELEVEL \ 167 + .cachelevel_to_pat = { \ 168 + [I915_CACHE_NONE] = 0, \ 169 + [I915_CACHE_LLC] = 1, \ 170 + [I915_CACHE_L3_LLC] = 2, \ 171 + [I915_CACHE_WT] = 3, \ 172 + } 173 + 174 + #define TGL_CACHELEVEL \ 175 + .cachelevel_to_pat = { \ 176 + [I915_CACHE_NONE] = 3, \ 177 + [I915_CACHE_LLC] = 0, \ 178 + [I915_CACHE_L3_LLC] = 0, \ 179 + [I915_CACHE_WT] = 2, \ 180 + } 181 + 182 + #define PVC_CACHELEVEL \ 183 + .cachelevel_to_pat = { \ 184 + [I915_CACHE_NONE] = 0, \ 185 + [I915_CACHE_LLC] = 3, \ 186 + [I915_CACHE_L3_LLC] = 3, \ 187 + [I915_CACHE_WT] = 2, \ 188 + } 189 + 190 + #define MTL_CACHELEVEL \ 191 + .cachelevel_to_pat = { \ 192 + [I915_CACHE_NONE] = 2, \ 193 + [I915_CACHE_LLC] = 3, \ 194 + [I915_CACHE_L3_LLC] = 3, \ 195 + [I915_CACHE_WT] = 1, \ 196 + } 197 + 167 198 /* Keep in gen based order, and chronological order within a gen */ 168 199 169 200 #define GEN_DEFAULT_PAGE_SIZES \ ··· 221 188 .has_snoop = true, \ 222 189 .has_coherent_ggtt = false, \ 223 190 .dma_mask_size = 32, \ 191 + .max_pat_index = 3, \ 224 192 I9XX_PIPE_OFFSETS, \ 225 193 I9XX_CURSOR_OFFSETS, \ 226 194 I9XX_COLORS, \ 227 195 GEN_DEFAULT_PAGE_SIZES, \ 228 - GEN_DEFAULT_REGIONS 196 + GEN_DEFAULT_REGIONS, \ 197 + LEGACY_CACHELEVEL 229 198 230 199 #define I845_FEATURES \ 231 200 GEN(2), \ ··· 244 209 .has_snoop = true, \ 245 210 .has_coherent_ggtt = false, \ 246 211 .dma_mask_size = 32, \ 212 + .max_pat_index = 3, \ 247 213 I845_PIPE_OFFSETS, \ 248 214 I845_CURSOR_OFFSETS, \ 249 215 I845_COLORS, \ 250 216 GEN_DEFAULT_PAGE_SIZES, \ 251 - GEN_DEFAULT_REGIONS 217 + GEN_DEFAULT_REGIONS, \ 218 + LEGACY_CACHELEVEL 252 219 253 220 static const struct intel_device_info i830_info = { 254 221 I830_FEATURES, ··· 285 248 .has_snoop = true, \ 286 249 .has_coherent_ggtt = true, \ 287 250 .dma_mask_size = 32, \ 251 + .max_pat_index = 3, \ 288 252 I9XX_PIPE_OFFSETS, \ 289 253 I9XX_CURSOR_OFFSETS, \ 290 254 I9XX_COLORS, \ 291 255 GEN_DEFAULT_PAGE_SIZES, \ 292 - GEN_DEFAULT_REGIONS 256 + GEN_DEFAULT_REGIONS, \ 257 + LEGACY_CACHELEVEL 293 258 294 259 static const struct intel_device_info i915g_info = { 295 260 GEN3_FEATURES, ··· 379 340 .has_snoop = true, \ 380 341 .has_coherent_ggtt = true, \ 381 342 .dma_mask_size = 36, \ 343 + .max_pat_index = 3, \ 382 344 I9XX_PIPE_OFFSETS, \ 383 345 I9XX_CURSOR_OFFSETS, \ 384 346 I9XX_COLORS, \ 385 347 GEN_DEFAULT_PAGE_SIZES, \ 386 - GEN_DEFAULT_REGIONS 348 + GEN_DEFAULT_REGIONS, \ 349 + LEGACY_CACHELEVEL 387 350 388 351 static const struct intel_device_info i965g_info = { 389 352 GEN4_FEATURES, ··· 435 394 /* ilk does support rc6, but we do not implement [power] contexts */ \ 436 395 .has_rc6 = 0, \ 437 396 .dma_mask_size = 36, \ 397 + .max_pat_index = 3, \ 438 398 I9XX_PIPE_OFFSETS, \ 439 399 I9XX_CURSOR_OFFSETS, \ 440 400 ILK_COLORS, \ 441 401 GEN_DEFAULT_PAGE_SIZES, \ 442 - GEN_DEFAULT_REGIONS 402 + GEN_DEFAULT_REGIONS, \ 403 + LEGACY_CACHELEVEL 443 404 444 405 static const struct intel_device_info ilk_d_info = { 445 406 GEN5_FEATURES, ··· 471 428 .has_rc6p = 0, \ 472 429 .has_rps = true, \ 473 430 .dma_mask_size = 40, \ 431 + .max_pat_index = 3, \ 474 432 .__runtime.ppgtt_type = INTEL_PPGTT_ALIASING, \ 475 433 .__runtime.ppgtt_size = 31, \ 476 434 I9XX_PIPE_OFFSETS, \ 477 435 I9XX_CURSOR_OFFSETS, \ 478 436 ILK_COLORS, \ 479 437 GEN_DEFAULT_PAGE_SIZES, \ 480 - GEN_DEFAULT_REGIONS 438 + GEN_DEFAULT_REGIONS, \ 439 + LEGACY_CACHELEVEL 481 440 482 441 #define SNB_D_PLATFORM \ 483 442 GEN6_FEATURES, \ ··· 526 481 .has_reset_engine = true, \ 527 482 .has_rps = true, \ 528 483 .dma_mask_size = 40, \ 484 + .max_pat_index = 3, \ 529 485 .__runtime.ppgtt_type = INTEL_PPGTT_ALIASING, \ 530 486 .__runtime.ppgtt_size = 31, \ 531 487 IVB_PIPE_OFFSETS, \ 532 488 IVB_CURSOR_OFFSETS, \ 533 489 IVB_COLORS, \ 534 490 GEN_DEFAULT_PAGE_SIZES, \ 535 - GEN_DEFAULT_REGIONS 491 + GEN_DEFAULT_REGIONS, \ 492 + LEGACY_CACHELEVEL 536 493 537 494 #define IVB_D_PLATFORM \ 538 495 GEN7_FEATURES, \ ··· 588 541 .display.has_gmch = 1, 589 542 .display.has_hotplug = 1, 590 543 .dma_mask_size = 40, 544 + .max_pat_index = 3, 591 545 .__runtime.ppgtt_type = INTEL_PPGTT_ALIASING, 592 546 .__runtime.ppgtt_size = 31, 593 547 .has_snoop = true, ··· 600 552 I9XX_COLORS, 601 553 GEN_DEFAULT_PAGE_SIZES, 602 554 GEN_DEFAULT_REGIONS, 555 + LEGACY_CACHELEVEL, 603 556 }; 604 557 605 558 #define G75_FEATURES \ ··· 688 639 .has_logical_ring_contexts = 1, 689 640 .display.has_gmch = 1, 690 641 .dma_mask_size = 39, 642 + .max_pat_index = 3, 691 643 .__runtime.ppgtt_type = INTEL_PPGTT_FULL, 692 644 .__runtime.ppgtt_size = 32, 693 645 .has_reset_engine = 1, ··· 700 650 CHV_COLORS, 701 651 GEN_DEFAULT_PAGE_SIZES, 702 652 GEN_DEFAULT_REGIONS, 653 + LEGACY_CACHELEVEL, 703 654 }; 704 655 705 656 #define GEN9_DEFAULT_PAGE_SIZES \ ··· 782 731 .has_snoop = true, \ 783 732 .has_coherent_ggtt = false, \ 784 733 .display.has_ipc = 1, \ 734 + .max_pat_index = 3, \ 785 735 HSW_PIPE_OFFSETS, \ 786 736 IVB_CURSOR_OFFSETS, \ 787 737 IVB_COLORS, \ 788 738 GEN9_DEFAULT_PAGE_SIZES, \ 789 - GEN_DEFAULT_REGIONS 739 + GEN_DEFAULT_REGIONS, \ 740 + LEGACY_CACHELEVEL 790 741 791 742 static const struct intel_device_info bxt_info = { 792 743 GEN9_LP_FEATURES, ··· 942 889 [TRANSCODER_DSI_1] = TRANSCODER_DSI1_OFFSET, \ 943 890 }, \ 944 891 TGL_CURSOR_OFFSETS, \ 892 + TGL_CACHELEVEL, \ 945 893 .has_global_mocs = 1, \ 946 894 .has_pxp = 1, \ 947 - .display.has_dsb = 1 895 + .display.has_dsb = 1, \ 896 + .max_pat_index = 3 948 897 949 898 static const struct intel_device_info tgl_info = { 950 899 GEN12_FEATURES, ··· 1068 1013 .__runtime.graphics.ip.ver = 12, \ 1069 1014 .__runtime.graphics.ip.rel = 50, \ 1070 1015 XE_HP_PAGE_SIZES, \ 1016 + TGL_CACHELEVEL, \ 1071 1017 .dma_mask_size = 46, \ 1072 1018 .has_3d_pipeline = 1, \ 1073 1019 .has_64bit_reloc = 1, \ ··· 1087 1031 .has_reset_engine = 1, \ 1088 1032 .has_rps = 1, \ 1089 1033 .has_runtime_pm = 1, \ 1034 + .max_pat_index = 3, \ 1090 1035 .__runtime.ppgtt_size = 48, \ 1091 1036 .__runtime.ppgtt_type = INTEL_PPGTT_FULL 1092 1037 ··· 1164 1107 PLATFORM(INTEL_PONTEVECCHIO), 1165 1108 NO_DISPLAY, 1166 1109 .has_flat_ccs = 0, 1110 + .max_pat_index = 7, 1167 1111 .__runtime.platform_engine_mask = 1168 1112 BIT(BCS0) | 1169 1113 BIT(VCS0) | 1170 1114 BIT(CCS0) | BIT(CCS1) | BIT(CCS2) | BIT(CCS3), 1171 1115 .require_force_probe = 1, 1116 + PVC_CACHELEVEL, 1172 1117 }; 1173 1118 1174 1119 #define XE_LPDP_FEATURES \ ··· 1208 1149 .has_llc = 0, 1209 1150 .has_mslice_steering = 0, 1210 1151 .has_snoop = 1, 1152 + .max_pat_index = 4, 1211 1153 .__runtime.memory_regions = REGION_SMEM | REGION_STOLEN_LMEM, 1212 1154 .__runtime.platform_engine_mask = BIT(RCS0) | BIT(BCS0) | BIT(CCS0), 1213 1155 .require_force_probe = 1, 1156 + MTL_CACHELEVEL, 1214 1157 }; 1215 1158 1216 1159 #undef PLATFORM
+5
drivers/gpu/drm/i915/intel_device_info.h
··· 35 35 #include "gt/intel_context_types.h" 36 36 #include "gt/intel_sseu.h" 37 37 38 + #include "gem/i915_gem_object_types.h" 39 + 38 40 struct drm_printer; 39 41 struct drm_i915_private; 40 42 struct intel_gt_definition; ··· 310 308 * Initial runtime info. Do not access outside of i915_driver_create(). 311 309 */ 312 310 const struct intel_runtime_info __runtime; 311 + 312 + u32 cachelevel_to_pat[I915_MAX_CACHE_LEVEL]; 313 + u32 max_pat_index; 313 314 }; 314 315 315 316 struct intel_driver_caps {
+9
drivers/gpu/drm/i915/selftests/mock_gem_device.c
··· 123 123 static struct dev_iommu fake_iommu = { .priv = (void *)-1 }; 124 124 #endif 125 125 struct drm_i915_private *i915; 126 + struct intel_device_info *i915_info; 126 127 struct pci_dev *pdev; 128 + unsigned int i; 127 129 int ret; 128 130 129 131 pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); ··· 182 180 I915_GTT_PAGE_SIZE_2M; 183 181 184 182 RUNTIME_INFO(i915)->memory_regions = REGION_SMEM; 183 + 184 + /* simply use legacy cache level for mock device */ 185 + i915_info = (struct intel_device_info *)INTEL_INFO(i915); 186 + i915_info->max_pat_index = 3; 187 + for (i = 0; i < I915_MAX_CACHE_LEVEL; i++) 188 + i915_info->cachelevel_to_pat[i] = i; 189 + 185 190 intel_memory_regions_hw_probe(i915); 186 191 187 192 spin_lock_init(&i915->gpu_error.lock);