/* * Also leave a space between the unallocated reserved node after the * GTT and any objects within the GTT, i.e. we use the color adjustment * to insert a guard page to prevent prefetches crossing over the * GTT boundary.
*/
node = list_next_entry(node, node_list); if (node->color != color)
*end -= I915_GTT_PAGE_SIZE;
}
/** * i915_ggtt_init_hw - Initialize GGTT hardware * @i915: i915 device
*/ int i915_ggtt_init_hw(struct drm_i915_private *i915)
{ int ret;
/* * Note that we use page colouring to enforce a guard page at the * end of the address space. This is required as the CS may prefetch * beyond the end of the batch buffer, across the page boundary, * and beyond the end of the GTT if we do not provide a guard.
*/
ret = ggtt_init_hw(to_gt(i915)->ggtt); if (ret) return ret;
return 0;
}
/** * i915_ggtt_suspend_vm - Suspend the memory mappings for a GGTT or DPT VM * @vm: The VM to suspend the mappings for * @evict_all: Evict all VMAs * * Suspend the memory mappings for all objects mapped to HW via the GGTT or a * DPT page table.
*/ void i915_ggtt_suspend_vm(struct i915_address_space *vm, bool evict_all)
{ struct i915_vma *vma, *vn; int save_skip_rewrite;
if (i915_vma_is_pinned(vma) || !i915_vma_is_bound(vma, I915_VMA_GLOBAL_BIND)) continue;
/* unlikely to race when GPU is idle, so no worry about slowpath.. */ if (WARN_ON(!i915_gem_object_trylock(obj, NULL))) { /* * No dead objects should appear here, GPU should be * completely idle, and userspace suspended
*/
i915_gem_object_get(obj);
staticbool needs_wc_ggtt_mapping(struct drm_i915_private *i915)
{ /* * On BXT+/ICL+ writes larger than 64 bit to the GTT pagetable range * will be dropped. For WC mappings in general we have 64 byte burst * writes when the WC buffer is flushed, so we can't use it, but have to * resort to an uncached mapping. The WC issue is easily caught by the * readback check when writing GTT PTE entries.
*/ if (!IS_GEN9_LP(i915) && GRAPHICS_VER(i915) < 11) returntrue;
/* * Note that as an uncached mmio write, this will flush the * WCB of the writes into the GGTT before it triggers the invalidate. * * Only perform this when GGTT is mapped as WC, see ggtt_probe_common().
*/ if (needs_wc_ggtt_mapping(ggtt->vm.i915))
intel_uncore_write_fw(uncore, GFX_FLSH_CNTL_GEN6,
GFX_FLSH_CNTL_EN);
}
ce = gt->engine[BCS0]->bind_context;
GEM_BUG_ON(!ce);
/* * If the GT is not awake already at this stage then fallback * to pci based GGTT update otherwise __intel_wakeref_get_first() * would conflict with fs_reclaim trying to allocate memory while * doing rpm_resume().
*/
*wakeref = intel_gt_pm_get_if_awake(gt); if (!*wakeref) return NULL;
ce = gen8_ggtt_bind_get_ce(ggtt, &wakeref); if (!ce) returnfalse;
if (pages)
iter = __sgt_iter(pages->sgl, true);
while (num_entries) { int count = 0;
dma_addr_t addr; /* * MI_UPDATE_GTT can update 512 entries in a single command but * that end up with engine reset, 511 works.
*/
u32 n_ptes = min_t(u32, 511, num_entries);
if (mutex_lock_interruptible(&ce->timeline->mutex)) goto put_ce;
intel_context_enter(ce);
rq = __i915_request_create(ce, GFP_NOWAIT | GFP_ATOMIC);
intel_context_exit(ce); if (IS_ERR(rq)) {
GT_TRACE(gt, "Failed to get bind request\n");
mutex_unlock(&ce->timeline->mutex); goto put_ce;
}
cs = intel_ring_begin(rq, 2 * n_ptes + 2); if (IS_ERR(cs)) {
GT_TRACE(gt, "Failed to ring space for GGTT bind\n");
i915_request_set_error_once(rq, PTR_ERR(cs)); /* once a request is created, it must be queued */ goto queue_err_rq;
}
mutex_unlock(&ce->timeline->mutex); /* This will break if the request is complete or after engine reset */
i915_request_wait(rq, 0, MAX_SCHEDULE_TIMEOUT); if (rq->fence.error) goto err_rq;
/* * Binds an object into the global gtt with the specified cache level. * The object will be accessible to the GPU via commands whose operands * reference offsets within the global GTT as well as accessible by the GPU * through the GMADR mapped BAR (i915->mm.gtt->gtt).
*/ staticvoid gen6_ggtt_insert_entries(struct i915_address_space *vm, struct i915_vma_resource *vma_res, unsignedint pat_index,
u32 flags)
{ struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
gen6_pte_t __iomem *gte;
gen6_pte_t __iomem *end; struct sgt_iter iter;
dma_addr_t addr;
staticvoid bxt_vtd_ggtt_wa(struct i915_address_space *vm)
{ /* * Make sure the internal GAM fifo has been cleared of all GTT * writes before exiting stop_machine(). This guarantees that * any aperture accesses waiting to start in another process * cannot back up behind the GTT writes causing a hang. * The register can be any arbitrary GAM register.
*/
intel_uncore_posting_read_fw(vm->gt->uncore, GFX_FLSH_CNTL_GEN6);
}
if (vma_res->bound_flags & (~flags & I915_VMA_BIND_MASK)) return;
vma_res->bound_flags |= flags;
/* Applicable to VLV (gen8+ do not support RO in the GGTT) */
pte_flags = 0; if (vma_res->bi.readonly)
pte_flags |= PTE_READ_ONLY; if (vma_res->bi.lmem)
pte_flags |= PTE_LM;
/* * Reserve the top of the GuC address space for firmware images. Addresses * beyond GUC_GGTT_TOP in the GuC address space are inaccessible by GuC, * which makes for a suitable range to hold GuC/HuC firmware images if the * size of the GGTT is 4G. However, on a 32-bit platform the size of the GGTT * is limited to 2G, which is less than GUC_GGTT_TOP, but we reserve a chunk * of the same size anyway, which is far more than needed, to keep the logic * in uc_fw_ggtt_offset() simple.
*/ #define GUC_TOP_RESERVE_SIZE (SZ_4G - GUC_GGTT_TOP)
staticint ggtt_reserve_guc_top(struct i915_ggtt *ggtt)
{
u64 offset; int ret;
if (!intel_uc_uses_guc(&ggtt->vm.gt->uc)) return 0;
ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, &ggtt->uc_fw,
GUC_TOP_RESERVE_SIZE, offset,
I915_COLOR_UNEVICTABLE, PIN_NOEVICT); if (ret)
drm_dbg(&ggtt->vm.i915->drm, "Failed to reserve top of GGTT for GuC\n");
return ret;
}
staticvoid ggtt_release_guc_top(struct i915_ggtt *ggtt)
{ if (drm_mm_node_allocated(&ggtt->uc_fw))
drm_mm_remove_node(&ggtt->uc_fw);
}
staticint init_ggtt(struct i915_ggtt *ggtt)
{ /* * Let GEM Manage all of the aperture. * * However, leave one page at the end still bound to the scratch page. * There are a number of places where the hardware apparently prefetches * past the end of the object, and we've seen multiple hangs with the * GPU head pointer stuck in a batchbuffer bound at the last page of the * aperture. One page should be enough to keep any prefetching inside * of the aperture.
*/ unsignedlong hole_start, hole_end; struct drm_mm_node *entry; int ret;
/* * GuC requires all resources that we're sharing with it to be placed in * non-WOPCM memory. If GuC is not present or not in use we still need a * small bias as ring wraparound at offset 0 sometimes hangs. No idea * why.
*/
ggtt->pin_bias = max_t(u32, I915_GTT_PAGE_SIZE,
intel_wopcm_guc_size(&ggtt->vm.gt->wopcm));
ret = intel_vgt_balloon(ggtt); if (ret) return ret;
mutex_init(&ggtt->error_mutex); if (ggtt->mappable_end) { /* * Reserve a mappable slot for our lockless error capture. * * We strongly prefer taking address 0x0 in order to protect * other critical buffers against accidental overwrites, * as writing to address 0 is a very common mistake. * * Since 0 may already be in use by the system (e.g. the BIOS * framebuffer), we let the reservation fail quietly and hope * 0 remains reserved always. * * If we fail to reserve 0, and then fail to find any space * for an error-capture, remain silent. We can afford not * to reserve an error_capture node as we have fallback * paths, and we trust that 0 will remain reserved. However, * the only likely reason for failure to insert is a driver * bug, which we expect to cause other failures... * * Since CPU can perform speculative reads on error capture * (write-combining allows it) add scratch page after error * capture to avoid DMAR errors.
*/
ggtt->error_capture.size = 2 * I915_GTT_PAGE_SIZE;
ggtt->error_capture.color = I915_COLOR_UNEVICTABLE; if (drm_mm_reserve_node(&ggtt->vm.mm, &ggtt->error_capture))
drm_mm_insert_node_in_range(&ggtt->vm.mm,
&ggtt->error_capture,
ggtt->error_capture.size, 0,
ggtt->error_capture.color,
0, ggtt->mappable_end,
DRM_MM_INSERT_LOW);
} if (drm_mm_node_allocated(&ggtt->error_capture)) {
u64 start = ggtt->error_capture.start;
u64 size = ggtt->error_capture.size;
ggtt->vm.scratch_range(&ggtt->vm, start, size);
drm_dbg(&ggtt->vm.i915->drm, "Reserved GGTT:[%llx, %llx] for use by error capture\n",
start, start + size);
}
/* * The upper portion of the GuC address space has a sizeable hole * (several MB) that is inaccessible by GuC. Reserve this range within * GGTT as it can comfortably hold GuC/HuC firmware images.
*/
ret = ggtt_reserve_guc_top(ggtt); if (ret) goto err;
/* * Note we only pre-allocate as far as the end of the global * GTT. On 48b / 4-level page-tables, the difference is very, * very significant! We have to preallocate as GVT/vgpu does * not like the page directory disappearing.
*/
ppgtt->vm.allocate_va_range(&ppgtt->vm, &stash, 0, ggtt->vm.total);
/** * i915_ggtt_driver_late_release - Cleanup of GGTT that needs to be done after * all free objects have been drained. * @i915: i915 device
*/ void i915_ggtt_driver_late_release(struct drm_i915_private *i915)
{ struct i915_ggtt *ggtt = to_gt(i915)->ggtt;
if (!ggtt->gsm) {
drm_err(&i915->drm, "Failed to map the ggtt page table\n"); return -ENOMEM;
}
kref_init(&ggtt->vm.resv_ref);
ret = setup_scratch_page(&ggtt->vm); if (ret) {
drm_err(&i915->drm, "Scratch setup failed\n"); /* iounmap will also get called at remove, but meh */
iounmap(ggtt->gsm); return ret;
}
pte_flags = 0; if (i915_gem_object_is_lmem(ggtt->vm.scratch[0]))
pte_flags |= PTE_LM;
/* * Serialize GTT updates with aperture access on BXT if VT-d is on, * and always on CHV.
*/ if (intel_vm_no_concurrent_access_wa(i915)) {
ggtt->vm.insert_entries = bxt_vtd_ggtt_insert_entries__BKL;
ggtt->vm.insert_page = bxt_vtd_ggtt_insert_page__BKL;
/* * Calling stop_machine() version of GGTT update function * at error capture/reset path will raise lockdep warning. * Allow calling gen8_ggtt_insert_* directly at reset path * which is safe from parallel GGTT updates.
*/
ggtt->vm.raw_insert_page = gen8_ggtt_insert_page;
ggtt->vm.raw_insert_entries = gen8_ggtt_insert_entries;
if (i915_ggtt_require_binder(i915)) {
ggtt->vm.scratch_range = gen8_ggtt_scratch_range_bind;
ggtt->vm.insert_page = gen8_ggtt_insert_page_bind;
ggtt->vm.insert_entries = gen8_ggtt_insert_entries_bind; /* * On GPU is hung, we might bind VMAs for error capture. * Fallback to CPU GGTT updates in that case.
*/
ggtt->vm.raw_insert_page = gen8_ggtt_insert_page;
}
if (intel_uc_wants_guc_submission(&ggtt->vm.gt->uc))
ggtt->invalidate = guc_ggtt_invalidate; else
ggtt->invalidate = gen8_ggtt_invalidate;
/* * For pre-gen8 platforms pat_index is the same as enum i915_cache_level, * so the switch-case statements in these PTE encode functions are still valid. * See translation table LEGACY_CACHELEVEL.
*/ static u64 snb_pte_encode(dma_addr_t addr, unsignedint pat_index,
u32 flags)
{
gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
switch (pat_index) { case I915_CACHE_L3_LLC: case I915_CACHE_LLC:
pte |= GEN6_PTE_CACHE_LLC; break; case I915_CACHE_NONE:
pte |= GEN6_PTE_UNCACHED; break; default:
MISSING_CASE(pat_index);
}
/* * 64/512MB is the current min/max we actually know of, but this is * just a coarse sanity check.
*/ if (ggtt->mappable_end < (64 << 20) ||
ggtt->mappable_end > (512 << 20)) {
drm_err(&i915->drm, "Unknown GMADR size (%pa)\n",
&ggtt->mappable_end); return -ENXIO;
}
if (GRAPHICS_VER(i915) >= 8)
ret = gen8_gmch_probe(ggtt); elseif (GRAPHICS_VER(i915) >= 6)
ret = gen6_gmch_probe(ggtt); else
ret = intel_ggtt_gmch_probe(ggtt);
if (ret) {
dma_resv_fini(&ggtt->vm._resv); return ret;
}
if ((ggtt->vm.total - 1) >> 32) {
drm_err(&i915->drm, "We never expected a Global GTT with more than 32bits" " of address space! Found %lldM!\n",
ggtt->vm.total >> 20);
ggtt->vm.total = 1ULL << 32;
ggtt->mappable_end =
min_t(u64, ggtt->mappable_end, ggtt->vm.total);
}
if (ggtt->mappable_end > ggtt->vm.total) {
drm_err(&i915->drm, "mappable aperture extends past end of GGTT," " aperture=%pa, total=%llx\n",
&ggtt->mappable_end, ggtt->vm.total);
ggtt->mappable_end = ggtt->vm.total;
}
/* GMADR is the PCI mmio aperture into the global GTT. */
drm_dbg(&i915->drm, "GGTT size = %lluM\n", ggtt->vm.total >> 20);
drm_dbg(&i915->drm, "GMADR size = %lluM\n",
(u64)ggtt->mappable_end >> 20);
drm_dbg(&i915->drm, "DSM size = %lluM\n",
(u64)resource_size(&intel_graphics_stolen_res) >> 20);
ggtt = drmm_kzalloc(&i915->drm, sizeof(*ggtt), GFP_KERNEL); if (!ggtt) return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&ggtt->gt_list);
return ggtt;
}
int i915_ggtt_enable_hw(struct drm_i915_private *i915)
{ if (GRAPHICS_VER(i915) < 6) return intel_ggtt_gmch_enable_hw(i915);
return 0;
}
/** * i915_ggtt_resume_vm - Restore the memory mappings for a GGTT or DPT VM * @vm: The VM to restore the mappings for * @all_evicted: Were all VMAs expected to be evicted on suspend? * * Restore the memory mappings for all objects mapped to HW via the GGTT or a * DPT page table. * * Returns %true if restoring the mapping for any object that was in a write * domain before suspend.
*/ bool i915_ggtt_resume_vm(struct i915_address_space *vm, bool all_evicted)
{ struct i915_vma *vma; bool write_domain_objs = false;
if (all_evicted) {
drm_WARN_ON(&vm->i915->drm, !list_empty(&vm->bound_list)); returnfalse;
}
/* First fill our portion of the GTT with scratch pages */
vm->clear_range(vm, 0, vm->total);
/* clflush objects bound into the GGTT and rebind them. */
list_for_each_entry(vma, &vm->bound_list, vm_link) { struct drm_i915_gem_object *obj = vma->obj; unsignedint was_bound =
atomic_read(&vma->flags) & I915_VMA_BIND_MASK;
GEM_BUG_ON(!was_bound);
/* * Clear the bound flags of the vma resource to allow * ptes to be repopulated.
*/
vma->resource->bound_flags = 0;
vma->ops->bind_vma(vm, NULL, vma->resource,
obj ? obj->pat_index :
i915_gem_get_pat_index(vm->i915,
I915_CACHE_NONE),
was_bound);
if (obj) { /* only used during resume => exclusive access */
write_domain_objs |= fetch_and_zero(&obj->write_domain);
obj->read_domains |= I915_GEM_DOMAIN_GTT;
}
}
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.