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