1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2020 Intel Corporation 4 */ 5 6 #include <linux/slab.h> /* fault-inject.h is not standalone! */ 7 8 #include <linux/fault-inject.h> 9 #include <linux/sched/mm.h> 10 11 #include <drm/drm_cache.h> 12 13 #include "gem/i915_gem_internal.h" 14 #include "gem/i915_gem_lmem.h" 15 #include "i915_trace.h" 16 #include "i915_utils.h" 17 #include "intel_gt.h" 18 #include "intel_gt_regs.h" 19 #include "intel_gtt.h" 20 21 22 static bool intel_ggtt_update_needs_vtd_wa(struct drm_i915_private *i915) 23 { 24 return IS_BROXTON(i915) && i915_vtd_active(i915); 25 } 26 27 bool intel_vm_no_concurrent_access_wa(struct drm_i915_private *i915) 28 { 29 return IS_CHERRYVIEW(i915) || intel_ggtt_update_needs_vtd_wa(i915); 30 } 31 32 struct drm_i915_gem_object *alloc_pt_lmem(struct i915_address_space *vm, int sz) 33 { 34 struct drm_i915_gem_object *obj; 35 36 /* 37 * To avoid severe over-allocation when dealing with min_page_size 38 * restrictions, we override that behaviour here by allowing an object 39 * size and page layout which can be smaller. In practice this should be 40 * totally fine, since GTT paging structures are not typically inserted 41 * into the GTT. 42 * 43 * Note that we also hit this path for the scratch page, and for this 44 * case it might need to be 64K, but that should work fine here since we 45 * used the passed in size for the page size, which should ensure it 46 * also has the same alignment. 47 */ 48 obj = __i915_gem_object_create_lmem_with_ps(vm->i915, sz, sz, 49 vm->lmem_pt_obj_flags); 50 /* 51 * Ensure all paging structures for this vm share the same dma-resv 52 * object underneath, with the idea that one object_lock() will lock 53 * them all at once. 54 */ 55 if (!IS_ERR(obj)) { 56 obj->base.resv = i915_vm_resv_get(vm); 57 obj->shares_resv_from = vm; 58 } 59 60 return obj; 61 } 62 63 struct drm_i915_gem_object *alloc_pt_dma(struct i915_address_space *vm, int sz) 64 { 65 struct drm_i915_gem_object *obj; 66 67 if (I915_SELFTEST_ONLY(should_fail(&vm->fault_attr, 1))) 68 i915_gem_shrink_all(vm->i915); 69 70 obj = i915_gem_object_create_internal(vm->i915, sz); 71 /* 72 * Ensure all paging structures for this vm share the same dma-resv 73 * object underneath, with the idea that one object_lock() will lock 74 * them all at once. 75 */ 76 if (!IS_ERR(obj)) { 77 obj->base.resv = i915_vm_resv_get(vm); 78 obj->shares_resv_from = vm; 79 } 80 81 return obj; 82 } 83 84 int map_pt_dma(struct i915_address_space *vm, struct drm_i915_gem_object *obj) 85 { 86 enum i915_map_type type; 87 void *vaddr; 88 89 type = i915_coherent_map_type(vm->i915, obj, true); 90 vaddr = i915_gem_object_pin_map_unlocked(obj, type); 91 if (IS_ERR(vaddr)) 92 return PTR_ERR(vaddr); 93 94 i915_gem_object_make_unshrinkable(obj); 95 return 0; 96 } 97 98 int map_pt_dma_locked(struct i915_address_space *vm, struct drm_i915_gem_object *obj) 99 { 100 enum i915_map_type type; 101 void *vaddr; 102 103 type = i915_coherent_map_type(vm->i915, obj, true); 104 vaddr = i915_gem_object_pin_map(obj, type); 105 if (IS_ERR(vaddr)) 106 return PTR_ERR(vaddr); 107 108 i915_gem_object_make_unshrinkable(obj); 109 return 0; 110 } 111 112 void __i915_vm_close(struct i915_address_space *vm) 113 { 114 struct i915_vma *vma, *vn; 115 116 if (!atomic_dec_and_mutex_lock(&vm->open, &vm->mutex)) 117 return; 118 119 list_for_each_entry_safe(vma, vn, &vm->bound_list, vm_link) { 120 struct drm_i915_gem_object *obj = vma->obj; 121 122 if (!kref_get_unless_zero(&obj->base.refcount)) { 123 /* 124 * Unbind the dying vma to ensure the bound_list 125 * is completely drained. We leave the destruction to 126 * the object destructor. 127 */ 128 atomic_and(~I915_VMA_PIN_MASK, &vma->flags); 129 WARN_ON(__i915_vma_unbind(vma)); 130 continue; 131 } 132 133 /* Keep the obj (and hence the vma) alive as _we_ destroy it */ 134 i915_vma_destroy_locked(vma); 135 i915_gem_object_put(obj); 136 } 137 GEM_BUG_ON(!list_empty(&vm->bound_list)); 138 139 mutex_unlock(&vm->mutex); 140 } 141 142 /* lock the vm into the current ww, if we lock one, we lock all */ 143 int i915_vm_lock_objects(struct i915_address_space *vm, 144 struct i915_gem_ww_ctx *ww) 145 { 146 if (vm->scratch[0]->base.resv == &vm->_resv) { 147 return i915_gem_object_lock(vm->scratch[0], ww); 148 } else { 149 struct i915_ppgtt *ppgtt = i915_vm_to_ppgtt(vm); 150 151 /* We borrowed the scratch page from ggtt, take the top level object */ 152 return i915_gem_object_lock(ppgtt->pd->pt.base, ww); 153 } 154 } 155 156 void i915_address_space_fini(struct i915_address_space *vm) 157 { 158 drm_mm_takedown(&vm->mm); 159 mutex_destroy(&vm->mutex); 160 } 161 162 /** 163 * i915_vm_resv_release - Final struct i915_address_space destructor 164 * @kref: Pointer to the &i915_address_space.resv_ref member. 165 * 166 * This function is called when the last lock sharer no longer shares the 167 * &i915_address_space._resv lock. 168 */ 169 void i915_vm_resv_release(struct kref *kref) 170 { 171 struct i915_address_space *vm = 172 container_of(kref, typeof(*vm), resv_ref); 173 174 dma_resv_fini(&vm->_resv); 175 kfree(vm); 176 } 177 178 static void __i915_vm_release(struct work_struct *work) 179 { 180 struct i915_address_space *vm = 181 container_of(work, struct i915_address_space, release_work); 182 183 /* Synchronize async unbinds. */ 184 i915_vma_resource_bind_dep_sync_all(vm); 185 186 vm->cleanup(vm); 187 i915_address_space_fini(vm); 188 189 i915_vm_resv_put(vm); 190 } 191 192 void i915_vm_release(struct kref *kref) 193 { 194 struct i915_address_space *vm = 195 container_of(kref, struct i915_address_space, ref); 196 197 GEM_BUG_ON(i915_is_ggtt(vm)); 198 trace_i915_ppgtt_release(vm); 199 200 queue_work(vm->i915->wq, &vm->release_work); 201 } 202 203 void i915_address_space_init(struct i915_address_space *vm, int subclass) 204 { 205 kref_init(&vm->ref); 206 207 /* 208 * Special case for GGTT that has already done an early 209 * kref_init here. 210 */ 211 if (!kref_read(&vm->resv_ref)) 212 kref_init(&vm->resv_ref); 213 214 vm->pending_unbind = RB_ROOT_CACHED; 215 INIT_WORK(&vm->release_work, __i915_vm_release); 216 atomic_set(&vm->open, 1); 217 218 /* 219 * The vm->mutex must be reclaim safe (for use in the shrinker). 220 * Do a dummy acquire now under fs_reclaim so that any allocation 221 * attempt holding the lock is immediately reported by lockdep. 222 */ 223 mutex_init(&vm->mutex); 224 lockdep_set_subclass(&vm->mutex, subclass); 225 226 if (!intel_vm_no_concurrent_access_wa(vm->i915)) { 227 i915_gem_shrinker_taints_mutex(vm->i915, &vm->mutex); 228 } else { 229 /* 230 * CHV + BXT VTD workaround use stop_machine(), 231 * which is allowed to allocate memory. This means &vm->mutex 232 * is the outer lock, and in theory we can allocate memory inside 233 * it through stop_machine(). 234 * 235 * Add the annotation for this, we use trylock in shrinker. 236 */ 237 mutex_acquire(&vm->mutex.dep_map, 0, 0, _THIS_IP_); 238 might_alloc(GFP_KERNEL); 239 mutex_release(&vm->mutex.dep_map, _THIS_IP_); 240 } 241 dma_resv_init(&vm->_resv); 242 243 GEM_BUG_ON(!vm->total); 244 drm_mm_init(&vm->mm, 0, vm->total); 245 246 memset64(vm->min_alignment, I915_GTT_MIN_ALIGNMENT, 247 ARRAY_SIZE(vm->min_alignment)); 248 249 if (HAS_64K_PAGES(vm->i915) && NEEDS_COMPACT_PT(vm->i915) && 250 subclass == VM_CLASS_PPGTT) { 251 vm->min_alignment[INTEL_MEMORY_LOCAL] = I915_GTT_PAGE_SIZE_2M; 252 vm->min_alignment[INTEL_MEMORY_STOLEN_LOCAL] = I915_GTT_PAGE_SIZE_2M; 253 } else if (HAS_64K_PAGES(vm->i915)) { 254 vm->min_alignment[INTEL_MEMORY_LOCAL] = I915_GTT_PAGE_SIZE_64K; 255 vm->min_alignment[INTEL_MEMORY_STOLEN_LOCAL] = I915_GTT_PAGE_SIZE_64K; 256 } 257 258 vm->mm.head_node.color = I915_COLOR_UNEVICTABLE; 259 260 INIT_LIST_HEAD(&vm->bound_list); 261 } 262 263 void *__px_vaddr(struct drm_i915_gem_object *p) 264 { 265 enum i915_map_type type; 266 267 GEM_BUG_ON(!i915_gem_object_has_pages(p)); 268 return page_unpack_bits(p->mm.mapping, &type); 269 } 270 271 dma_addr_t __px_dma(struct drm_i915_gem_object *p) 272 { 273 GEM_BUG_ON(!i915_gem_object_has_pages(p)); 274 return sg_dma_address(p->mm.pages->sgl); 275 } 276 277 struct page *__px_page(struct drm_i915_gem_object *p) 278 { 279 GEM_BUG_ON(!i915_gem_object_has_pages(p)); 280 return sg_page(p->mm.pages->sgl); 281 } 282 283 void 284 fill_page_dma(struct drm_i915_gem_object *p, const u64 val, unsigned int count) 285 { 286 void *vaddr = __px_vaddr(p); 287 288 memset64(vaddr, val, count); 289 clflush_cache_range(vaddr, PAGE_SIZE); 290 } 291 292 static void poison_scratch_page(struct drm_i915_gem_object *scratch) 293 { 294 void *vaddr = __px_vaddr(scratch); 295 u8 val; 296 297 val = 0; 298 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) 299 val = POISON_FREE; 300 301 memset(vaddr, val, scratch->base.size); 302 drm_clflush_virt_range(vaddr, scratch->base.size); 303 } 304 305 int setup_scratch_page(struct i915_address_space *vm) 306 { 307 unsigned long size; 308 309 /* 310 * In order to utilize 64K pages for an object with a size < 2M, we will 311 * need to support a 64K scratch page, given that every 16th entry for a 312 * page-table operating in 64K mode must point to a properly aligned 64K 313 * region, including any PTEs which happen to point to scratch. 314 * 315 * This is only relevant for the 48b PPGTT where we support 316 * huge-gtt-pages, see also i915_vma_insert(). However, as we share the 317 * scratch (read-only) between all vm, we create one 64k scratch page 318 * for all. 319 */ 320 size = I915_GTT_PAGE_SIZE_4K; 321 if (i915_vm_is_4lvl(vm) && 322 HAS_PAGE_SIZES(vm->i915, I915_GTT_PAGE_SIZE_64K)) 323 size = I915_GTT_PAGE_SIZE_64K; 324 325 do { 326 struct drm_i915_gem_object *obj; 327 328 obj = vm->alloc_scratch_dma(vm, size); 329 if (IS_ERR(obj)) 330 goto skip; 331 332 if (map_pt_dma(vm, obj)) 333 goto skip_obj; 334 335 /* We need a single contiguous page for our scratch */ 336 if (obj->mm.page_sizes.sg < size) 337 goto skip_obj; 338 339 /* And it needs to be correspondingly aligned */ 340 if (__px_dma(obj) & (size - 1)) 341 goto skip_obj; 342 343 /* 344 * Use a non-zero scratch page for debugging. 345 * 346 * We want a value that should be reasonably obvious 347 * to spot in the error state, while also causing a GPU hang 348 * if executed. We prefer using a clear page in production, so 349 * should it ever be accidentally used, the effect should be 350 * fairly benign. 351 */ 352 poison_scratch_page(obj); 353 354 vm->scratch[0] = obj; 355 vm->scratch_order = get_order(size); 356 return 0; 357 358 skip_obj: 359 i915_gem_object_put(obj); 360 skip: 361 if (size == I915_GTT_PAGE_SIZE_4K) 362 return -ENOMEM; 363 364 /* 365 * If we need 64K minimum GTT pages for device local-memory, 366 * like on XEHPSDV, then we need to fail the allocation here, 367 * otherwise we can't safely support the insertion of 368 * local-memory pages for this vm, since the HW expects the 369 * correct physical alignment and size when the page-table is 370 * operating in 64K GTT mode, which includes any scratch PTEs, 371 * since userspace can still touch them. 372 */ 373 if (HAS_64K_PAGES(vm->i915)) 374 return -ENOMEM; 375 376 size = I915_GTT_PAGE_SIZE_4K; 377 } while (1); 378 } 379 380 void free_scratch(struct i915_address_space *vm) 381 { 382 int i; 383 384 for (i = 0; i <= vm->top; i++) 385 i915_gem_object_put(vm->scratch[i]); 386 } 387 388 void gtt_write_workarounds(struct intel_gt *gt) 389 { 390 struct drm_i915_private *i915 = gt->i915; 391 struct intel_uncore *uncore = gt->uncore; 392 393 /* 394 * This function is for gtt related workarounds. This function is 395 * called on driver load and after a GPU reset, so you can place 396 * workarounds here even if they get overwritten by GPU reset. 397 */ 398 /* WaIncreaseDefaultTLBEntries:chv,bdw,skl,bxt,kbl,glk,cfl,cnl,icl */ 399 if (IS_BROADWELL(i915)) 400 intel_uncore_write(uncore, 401 GEN8_L3_LRA_1_GPGPU, 402 GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_BDW); 403 else if (IS_CHERRYVIEW(i915)) 404 intel_uncore_write(uncore, 405 GEN8_L3_LRA_1_GPGPU, 406 GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_CHV); 407 else if (IS_GEN9_LP(i915)) 408 intel_uncore_write(uncore, 409 GEN8_L3_LRA_1_GPGPU, 410 GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_BXT); 411 else if (GRAPHICS_VER(i915) >= 9 && GRAPHICS_VER(i915) <= 11) 412 intel_uncore_write(uncore, 413 GEN8_L3_LRA_1_GPGPU, 414 GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_SKL); 415 416 /* 417 * To support 64K PTEs we need to first enable the use of the 418 * Intermediate-Page-Size(IPS) bit of the PDE field via some magical 419 * mmio, otherwise the page-walker will simply ignore the IPS bit. This 420 * shouldn't be needed after GEN10. 421 * 422 * 64K pages were first introduced from BDW+, although technically they 423 * only *work* from gen9+. For pre-BDW we instead have the option for 424 * 32K pages, but we don't currently have any support for it in our 425 * driver. 426 */ 427 if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_64K) && 428 GRAPHICS_VER(i915) <= 10) 429 intel_uncore_rmw(uncore, 430 GEN8_GAMW_ECO_DEV_RW_IA, 431 0, 432 GAMW_ECO_ENABLE_64K_IPS_FIELD); 433 434 if (IS_GRAPHICS_VER(i915, 8, 11)) { 435 bool can_use_gtt_cache = true; 436 437 /* 438 * According to the BSpec if we use 2M/1G pages then we also 439 * need to disable the GTT cache. At least on BDW we can see 440 * visual corruption when using 2M pages, and not disabling the 441 * GTT cache. 442 */ 443 if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_2M)) 444 can_use_gtt_cache = false; 445 446 /* WaGttCachingOffByDefault */ 447 intel_uncore_write(uncore, 448 HSW_GTT_CACHE_EN, 449 can_use_gtt_cache ? GTT_CACHE_EN_ALL : 0); 450 drm_WARN_ON_ONCE(&i915->drm, can_use_gtt_cache && 451 intel_uncore_read(uncore, 452 HSW_GTT_CACHE_EN) == 0); 453 } 454 } 455 456 static void tgl_setup_private_ppat(struct intel_uncore *uncore) 457 { 458 /* TGL doesn't support LLC or AGE settings */ 459 intel_uncore_write(uncore, GEN12_PAT_INDEX(0), GEN8_PPAT_WB); 460 intel_uncore_write(uncore, GEN12_PAT_INDEX(1), GEN8_PPAT_WC); 461 intel_uncore_write(uncore, GEN12_PAT_INDEX(2), GEN8_PPAT_WT); 462 intel_uncore_write(uncore, GEN12_PAT_INDEX(3), GEN8_PPAT_UC); 463 intel_uncore_write(uncore, GEN12_PAT_INDEX(4), GEN8_PPAT_WB); 464 intel_uncore_write(uncore, GEN12_PAT_INDEX(5), GEN8_PPAT_WB); 465 intel_uncore_write(uncore, GEN12_PAT_INDEX(6), GEN8_PPAT_WB); 466 intel_uncore_write(uncore, GEN12_PAT_INDEX(7), GEN8_PPAT_WB); 467 } 468 469 static void icl_setup_private_ppat(struct intel_uncore *uncore) 470 { 471 intel_uncore_write(uncore, 472 GEN10_PAT_INDEX(0), 473 GEN8_PPAT_WB | GEN8_PPAT_LLC); 474 intel_uncore_write(uncore, 475 GEN10_PAT_INDEX(1), 476 GEN8_PPAT_WC | GEN8_PPAT_LLCELLC); 477 intel_uncore_write(uncore, 478 GEN10_PAT_INDEX(2), 479 GEN8_PPAT_WB | GEN8_PPAT_ELLC_OVERRIDE); 480 intel_uncore_write(uncore, 481 GEN10_PAT_INDEX(3), 482 GEN8_PPAT_UC); 483 intel_uncore_write(uncore, 484 GEN10_PAT_INDEX(4), 485 GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)); 486 intel_uncore_write(uncore, 487 GEN10_PAT_INDEX(5), 488 GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)); 489 intel_uncore_write(uncore, 490 GEN10_PAT_INDEX(6), 491 GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)); 492 intel_uncore_write(uncore, 493 GEN10_PAT_INDEX(7), 494 GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 495 } 496 497 /* 498 * The GGTT and PPGTT need a private PPAT setup in order to handle cacheability 499 * bits. When using advanced contexts each context stores its own PAT, but 500 * writing this data shouldn't be harmful even in those cases. 501 */ 502 static void bdw_setup_private_ppat(struct intel_uncore *uncore) 503 { 504 struct drm_i915_private *i915 = uncore->i915; 505 u64 pat; 506 507 pat = GEN8_PPAT(0, GEN8_PPAT_WB | GEN8_PPAT_LLC) | /* for normal objects, no eLLC */ 508 GEN8_PPAT(1, GEN8_PPAT_WC | GEN8_PPAT_LLCELLC) | /* for something pointing to ptes? */ 509 GEN8_PPAT(3, GEN8_PPAT_UC) | /* Uncached objects, mostly for scanout */ 510 GEN8_PPAT(4, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)) | 511 GEN8_PPAT(5, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)) | 512 GEN8_PPAT(6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)) | 513 GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3)); 514 515 /* for scanout with eLLC */ 516 if (GRAPHICS_VER(i915) >= 9) 517 pat |= GEN8_PPAT(2, GEN8_PPAT_WB | GEN8_PPAT_ELLC_OVERRIDE); 518 else 519 pat |= GEN8_PPAT(2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC); 520 521 intel_uncore_write(uncore, GEN8_PRIVATE_PAT_LO, lower_32_bits(pat)); 522 intel_uncore_write(uncore, GEN8_PRIVATE_PAT_HI, upper_32_bits(pat)); 523 } 524 525 static void chv_setup_private_ppat(struct intel_uncore *uncore) 526 { 527 u64 pat; 528 529 /* 530 * Map WB on BDW to snooped on CHV. 531 * 532 * Only the snoop bit has meaning for CHV, the rest is 533 * ignored. 534 * 535 * The hardware will never snoop for certain types of accesses: 536 * - CPU GTT (GMADR->GGTT->no snoop->memory) 537 * - PPGTT page tables 538 * - some other special cycles 539 * 540 * As with BDW, we also need to consider the following for GT accesses: 541 * "For GGTT, there is NO pat_sel[2:0] from the entry, 542 * so RTL will always use the value corresponding to 543 * pat_sel = 000". 544 * Which means we must set the snoop bit in PAT entry 0 545 * in order to keep the global status page working. 546 */ 547 548 pat = GEN8_PPAT(0, CHV_PPAT_SNOOP) | 549 GEN8_PPAT(1, 0) | 550 GEN8_PPAT(2, 0) | 551 GEN8_PPAT(3, 0) | 552 GEN8_PPAT(4, CHV_PPAT_SNOOP) | 553 GEN8_PPAT(5, CHV_PPAT_SNOOP) | 554 GEN8_PPAT(6, CHV_PPAT_SNOOP) | 555 GEN8_PPAT(7, CHV_PPAT_SNOOP); 556 557 intel_uncore_write(uncore, GEN8_PRIVATE_PAT_LO, lower_32_bits(pat)); 558 intel_uncore_write(uncore, GEN8_PRIVATE_PAT_HI, upper_32_bits(pat)); 559 } 560 561 void setup_private_pat(struct intel_uncore *uncore) 562 { 563 struct drm_i915_private *i915 = uncore->i915; 564 565 GEM_BUG_ON(GRAPHICS_VER(i915) < 8); 566 567 if (GRAPHICS_VER(i915) >= 12) 568 tgl_setup_private_ppat(uncore); 569 else if (GRAPHICS_VER(i915) >= 11) 570 icl_setup_private_ppat(uncore); 571 else if (IS_CHERRYVIEW(i915) || IS_GEN9_LP(i915)) 572 chv_setup_private_ppat(uncore); 573 else 574 bdw_setup_private_ppat(uncore); 575 } 576 577 struct i915_vma * 578 __vm_create_scratch_for_read(struct i915_address_space *vm, unsigned long size) 579 { 580 struct drm_i915_gem_object *obj; 581 struct i915_vma *vma; 582 583 obj = i915_gem_object_create_internal(vm->i915, PAGE_ALIGN(size)); 584 if (IS_ERR(obj)) 585 return ERR_CAST(obj); 586 587 i915_gem_object_set_cache_coherency(obj, I915_CACHING_CACHED); 588 589 vma = i915_vma_instance(obj, vm, NULL); 590 if (IS_ERR(vma)) { 591 i915_gem_object_put(obj); 592 return vma; 593 } 594 595 return vma; 596 } 597 598 struct i915_vma * 599 __vm_create_scratch_for_read_pinned(struct i915_address_space *vm, unsigned long size) 600 { 601 struct i915_vma *vma; 602 int err; 603 604 vma = __vm_create_scratch_for_read(vm, size); 605 if (IS_ERR(vma)) 606 return vma; 607 608 err = i915_vma_pin(vma, 0, 0, 609 i915_vma_is_ggtt(vma) ? PIN_GLOBAL : PIN_USER); 610 if (err) { 611 i915_vma_put(vma); 612 return ERR_PTR(err); 613 } 614 615 return vma; 616 } 617 618 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 619 #include "selftests/mock_gtt.c" 620 #endif 621