/* * To avoid severe over-allocation when dealing with min_page_size * restrictions, we override that behaviour here by allowing an object * size and page layout which can be smaller. In practice this should be * totally fine, since GTT paging structures are not typically inserted * into the GTT. * * Note that we also hit this path for the scratch page, and for this * case it might need to be 64K, but that should work fine here since we * used the passed in size for the page size, which should ensure it * also has the same alignment.
*/
obj = __i915_gem_object_create_lmem_with_ps(vm->i915, sz, sz,
vm->lmem_pt_obj_flags); /* * Ensure all paging structures for this vm share the same dma-resv * object underneath, with the idea that one object_lock() will lock * them all at once.
*/ if (!IS_ERR(obj)) {
obj->base.resv = i915_vm_resv_get(vm);
obj->shares_resv_from = vm;
if (vm->fpriv)
i915_drm_client_add_object(vm->fpriv->client, obj);
}
if (I915_SELFTEST_ONLY(should_fail(&vm->fault_attr, 1)))
i915_gem_shrink_all(vm->i915);
obj = i915_gem_object_create_internal(vm->i915, sz); /* * Ensure all paging structures for this vm share the same dma-resv * object underneath, with the idea that one object_lock() will lock * them all at once.
*/ if (!IS_ERR(obj)) {
obj->base.resv = i915_vm_resv_get(vm);
obj->shares_resv_from = vm;
if (vm->fpriv)
i915_drm_client_add_object(vm->fpriv->client, obj);
}
type = intel_gt_coherent_map_type(vm->gt, obj, true); /* * FIXME: It is suspected that some Address Translation Service (ATS) * issue on IOMMU is causing CAT errors to occur on some MTL workloads. * Applying a write barrier to the ppgtt set entry functions appeared * to have no effect, so we must temporarily use I915_MAP_WC here on * MTL until a proper ATS solution is found.
*/ if (IS_METEORLAKE(vm->i915))
type = I915_MAP_WC;
vaddr = i915_gem_object_pin_map_unlocked(obj, type); if (IS_ERR(vaddr)) return PTR_ERR(vaddr);
type = intel_gt_coherent_map_type(vm->gt, obj, true); /* * FIXME: It is suspected that some Address Translation Service (ATS) * issue on IOMMU is causing CAT errors to occur on some MTL workloads. * Applying a write barrier to the ppgtt set entry functions appeared * to have no effect, so we must temporarily use I915_MAP_WC here on * MTL until a proper ATS solution is found.
*/ if (IS_METEORLAKE(vm->i915))
type = I915_MAP_WC;
vaddr = i915_gem_object_pin_map(obj, type); if (IS_ERR(vaddr)) return PTR_ERR(vaddr);
if (!i915_gem_object_get_rcu(obj)) { /* * Object is dying, but has not yet cleared its * vma list. * Unbind the dying vma to ensure our list * is completely drained. We leave the destruction to * the object destructor to avoid the vma * disappearing under it.
*/
atomic_and(~I915_VMA_PIN_MASK, &vma->flags);
WARN_ON(__i915_vma_unbind(vma));
/* Remove from the unbound list */
list_del_init(&vma->vm_link);
/* * Delay the vm and vm mutex freeing until the * object is done with destruction.
*/
i915_vm_resv_get(vma->vm);
vma->vm_ddestroy = true;
} else {
i915_vma_destroy_locked(vma);
i915_gem_object_put(obj);
}
}
}
/* Check for must-fix unanticipated side-effects */
GEM_BUG_ON(!list_empty(&vm->bound_list));
GEM_BUG_ON(!list_empty(&vm->unbound_list));
mutex_unlock(&vm->mutex);
}
/* lock the vm into the current ww, if we lock one, we lock all */ int i915_vm_lock_objects(struct i915_address_space *vm, struct i915_gem_ww_ctx *ww)
{ if (vm->scratch[0]->base.resv == &vm->_resv) { return i915_gem_object_lock(vm->scratch[0], ww);
} else { struct i915_ppgtt *ppgtt = i915_vm_to_ppgtt(vm);
/* We borrowed the scratch page from ggtt, take the top level object */ return i915_gem_object_lock(ppgtt->pd->pt.base, ww);
}
}
/** * i915_vm_resv_release - Final struct i915_address_space destructor * @kref: Pointer to the &i915_address_space.resv_ref member. * * This function is called when the last lock sharer no longer shares the * &i915_address_space._resv lock, and also if we raced when * destroying a vma by the vma destruction
*/ void i915_vm_resv_release(struct kref *kref)
{ struct i915_address_space *vm =
container_of(kref, typeof(*vm), resv_ref);
/* * The vm->mutex must be reclaim safe (for use in the shrinker). * Do a dummy acquire now under fs_reclaim so that any allocation * attempt holding the lock is immediately reported by lockdep.
*/
mutex_init(&vm->mutex);
lockdep_set_subclass(&vm->mutex, subclass);
if (!intel_vm_no_concurrent_access_wa(vm->i915)) {
i915_gem_shrinker_taints_mutex(vm->i915, &vm->mutex);
} else { /* * CHV + BXT VTD workaround use stop_machine(), * which is allowed to allocate memory. This means &vm->mutex * is the outer lock, and in theory we can allocate memory inside * it through stop_machine(). * * Add the annotation for this, we use trylock in shrinker.
*/
mutex_acquire(&vm->mutex.dep_map, 0, 0, _THIS_IP_);
might_alloc(GFP_KERNEL);
mutex_release(&vm->mutex.dep_map, _THIS_IP_);
}
dma_resv_init(&vm->_resv);
int setup_scratch_page(struct i915_address_space *vm)
{ unsignedlong size;
/* * In order to utilize 64K pages for an object with a size < 2M, we will * need to support a 64K scratch page, given that every 16th entry for a * page-table operating in 64K mode must point to a properly aligned 64K * region, including any PTEs which happen to point to scratch. * * This is only relevant for the 48b PPGTT where we support * huge-gtt-pages, see also i915_vma_insert(). However, as we share the * scratch (read-only) between all vm, we create one 64k scratch page * for all.
*/
size = I915_GTT_PAGE_SIZE_4K; if (i915_vm_is_4lvl(vm) &&
HAS_PAGE_SIZES(vm->i915, I915_GTT_PAGE_SIZE_64K) &&
!HAS_64K_PAGES(vm->i915))
size = I915_GTT_PAGE_SIZE_64K;
do { struct drm_i915_gem_object *obj;
obj = vm->alloc_scratch_dma(vm, size); if (IS_ERR(obj)) goto skip;
if (map_pt_dma(vm, obj)) goto skip_obj;
/* We need a single contiguous page for our scratch */ if (obj->mm.page_sizes.sg < size) goto skip_obj;
/* And it needs to be correspondingly aligned */ if (__px_dma(obj) & (size - 1)) goto skip_obj;
/* * Use a non-zero scratch page for debugging. * * We want a value that should be reasonably obvious * to spot in the error state, while also causing a GPU hang * if executed. We prefer using a clear page in production, so * should it ever be accidentally used, the effect should be * fairly benign.
*/
poison_scratch_page(obj);
/* * This function is for gtt related workarounds. This function is * called on driver load and after a GPU reset, so you can place * workarounds here even if they get overwritten by GPU reset.
*/ /* WaIncreaseDefaultTLBEntries:chv,bdw,skl,bxt,kbl,glk,cfl,cnl,icl */ if (IS_BROADWELL(i915))
intel_uncore_write(uncore,
GEN8_L3_LRA_1_GPGPU,
GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_BDW); elseif (IS_CHERRYVIEW(i915))
intel_uncore_write(uncore,
GEN8_L3_LRA_1_GPGPU,
GEN8_L3_LRA_1_GPGPU_DEFAULT_VALUE_CHV); elseif (IS_GEN9_LP(i915))
intel_uncore_write(uncore,
GEN8_L3_LRA_1_GPGPU,
GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_BXT); elseif (GRAPHICS_VER(i915) >= 9 && GRAPHICS_VER(i915) <= 11)
intel_uncore_write(uncore,
GEN8_L3_LRA_1_GPGPU,
GEN9_L3_LRA_1_GPGPU_DEFAULT_VALUE_SKL);
/* * To support 64K PTEs we need to first enable the use of the * Intermediate-Page-Size(IPS) bit of the PDE field via some magical * mmio, otherwise the page-walker will simply ignore the IPS bit. This * shouldn't be needed after GEN10. * * 64K pages were first introduced from BDW+, although technically they * only *work* from gen9+. For pre-BDW we instead have the option for * 32K pages, but we don't currently have any support for it in our * driver.
*/ if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_64K) &&
GRAPHICS_VER(i915) <= 10)
intel_uncore_rmw(uncore,
GEN8_GAMW_ECO_DEV_RW_IA,
0,
GAMW_ECO_ENABLE_64K_IPS_FIELD);
if (IS_GRAPHICS_VER(i915, 8, 11)) { bool can_use_gtt_cache = true;
/* * According to the BSpec if we use 2M/1G pages then we also * need to disable the GTT cache. At least on BDW we can see * visual corruption when using 2M pages, and not disabling the * GTT cache.
*/ if (HAS_PAGE_SIZES(i915, I915_GTT_PAGE_SIZE_2M))
can_use_gtt_cache = false;
/* * The GGTT and PPGTT need a private PPAT setup in order to handle cacheability * bits. When using advanced contexts each context stores its own PAT, but * writing this data shouldn't be harmful even in those cases.
*/ staticvoid bdw_setup_private_ppat(struct intel_uncore *uncore)
{ struct drm_i915_private *i915 = uncore->i915;
u64 pat;
pat = GEN8_PPAT(0, GEN8_PPAT_WB | GEN8_PPAT_LLC) | /* for normal objects, no eLLC */
GEN8_PPAT(1, GEN8_PPAT_WC | GEN8_PPAT_LLCELLC) | /* for something pointing to ptes? */
GEN8_PPAT(3, GEN8_PPAT_UC) | /* Uncached objects, mostly for scanout */
GEN8_PPAT(4, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(0)) |
GEN8_PPAT(5, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(1)) |
GEN8_PPAT(6, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(2)) |
GEN8_PPAT(7, GEN8_PPAT_WB | GEN8_PPAT_LLCELLC | GEN8_PPAT_AGE(3));
/* for scanout with eLLC */ if (GRAPHICS_VER(i915) >= 9)
pat |= GEN8_PPAT(2, GEN8_PPAT_WB | GEN8_PPAT_ELLC_OVERRIDE); else
pat |= GEN8_PPAT(2, GEN8_PPAT_WT | GEN8_PPAT_LLCELLC);
/* * Map WB on BDW to snooped on CHV. * * Only the snoop bit has meaning for CHV, the rest is * ignored. * * The hardware will never snoop for certain types of accesses: * - CPU GTT (GMADR->GGTT->no snoop->memory) * - PPGTT page tables * - some other special cycles * * As with BDW, we also need to consider the following for GT accesses: * "For GGTT, there is NO pat_sel[2:0] from the entry, * so RTL will always use the value corresponding to * pat_sel = 000". * Which means we must set the snoop bit in PAT entry 0 * in order to keep the global status page working.
*/
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.