Lines Matching defs:ggtt
56 static int ggtt_init_hw(struct i915_ggtt *ggtt)
58 struct drm_i915_private *i915 = ggtt->vm.i915;
60 i915_address_space_init(&ggtt->vm, VM_CLASS_GGTT);
62 ggtt->vm.is_ggtt = true;
65 ggtt->vm.has_read_only = IS_VALLEYVIEW(i915);
68 ggtt->vm.mm.color_adjust = i915_ggtt_color_adjust;
70 if (ggtt->mappable_end) {
72 if (!io_mapping_init_wc(&ggtt->iomap,
73 ggtt->gmadr.start,
74 ggtt->mappable_end)) {
75 ggtt->vm.cleanup(&ggtt->vm);
79 ggtt->mtrr = arch_phys_wc_add(ggtt->gmadr.start,
80 ggtt->mappable_end);
86 uvm_page_physload(atop(ggtt->gmadr.start),
87 atop(ggtt->gmadr.start + ggtt->mappable_end),
88 atop(ggtt->gmadr.start),
89 atop(ggtt->gmadr.start + ggtt->mappable_end),
92 i915->pgs = PHYS_TO_VM_PAGE(ggtt->gmadr.start);
99 for (i = 0; i < atop(ggtt->mappable_end); i++)
102 if (bus_space_map(i915->bst, ggtt->gmadr.start,
103 ggtt->mappable_end,
106 ggtt->iomap.base = ggtt->gmadr.start;
107 ggtt->iomap.size = ggtt->mappable_end;
108 ggtt->iomap.iomem = bus_space_vaddr(i915->bst, bsh);
112 intel_ggtt_init_fences(ggtt);
131 ret = ggtt_init_hw(to_gt(i915)->ggtt);
208 void i915_ggtt_suspend(struct i915_ggtt *ggtt)
212 i915_ggtt_suspend_vm(&ggtt->vm);
213 ggtt->invalidate(ggtt);
215 list_for_each_entry(gt, &ggtt->gt_list, ggtt_link)
219 void gen6_ggtt_invalidate(struct i915_ggtt *ggtt)
221 struct intel_uncore *uncore = ggtt->vm.gt->uncore;
244 static void gen8_ggtt_invalidate(struct i915_ggtt *ggtt)
246 struct intel_uncore *uncore = ggtt->vm.gt->uncore;
254 if (needs_wc_ggtt_mapping(ggtt->vm.i915))
259 static void guc_ggtt_invalidate(struct i915_ggtt *ggtt)
261 struct drm_i915_private *i915 = ggtt->vm.i915;
263 gen8_ggtt_invalidate(ggtt);
268 list_for_each_entry(gt, &ggtt->gt_list, ggtt_link)
273 intel_uncore_write_fw(ggtt->vm.gt->uncore,
310 static bool should_update_ggtt_with_bind(struct i915_ggtt *ggtt)
312 struct intel_gt *gt = ggtt->vm.gt;
317 static struct intel_context *gen8_ggtt_bind_get_ce(struct i915_ggtt *ggtt)
320 struct intel_gt *gt = ggtt->vm.gt;
348 static bool gen8_ggtt_bind_ptes(struct i915_ggtt *ggtt, u32 offset,
353 struct intel_gt *gt = ggtt->vm.gt;
354 const gen8_pte_t scratch_pte = ggtt->vm.scratch[0]->encode;
363 ce = gen8_ggtt_bind_get_ce(ggtt);
460 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
462 (gen8_pte_t __iomem *)ggtt->gsm + offset / I915_GTT_PAGE_SIZE;
464 gen8_set_pte(pte, ggtt->vm.pte_encode(addr, pat_index, flags));
466 ggtt->invalidate(ggtt);
473 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
476 pte = ggtt->vm.pte_encode(addr, pat_index, flags);
478 gen8_ggtt_bind_ptes(ggtt, offset, NULL, 1, pte))
479 return ggtt->invalidate(ggtt);
489 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
490 const gen8_pte_t pte_encode = ggtt->vm.pte_encode(0, pat_index, flags);
501 gte = (gen8_pte_t __iomem *)ggtt->gsm;
520 ggtt->invalidate(ggtt);
527 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
532 pte_encode = ggtt->vm.pte_encode(0, pat_index, flags);
535 if (!gen8_ggtt_bind_ptes(ggtt, start, NULL, end - start, scratch_pte))
540 if (!gen8_ggtt_bind_ptes(ggtt, start, vma_res->bi.pages,
545 if (!gen8_ggtt_bind_ptes(ggtt, start, NULL, end - start, scratch_pte))
558 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
562 return ggtt->invalidate(ggtt);
570 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
575 (gen8_pte_t __iomem *)ggtt->gsm + first_entry;
576 const int max_entries = ggtt_total_entries(ggtt) - first_entry;
591 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
595 const int max_entries = ggtt_total_entries(ggtt) - first_entry;
602 if (should_update_ggtt_with_bind(ggtt) && gen8_ggtt_bind_ptes(ggtt, first_entry,
604 return ggtt->invalidate(ggtt);
615 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
617 (gen6_pte_t __iomem *)ggtt->gsm + offset / I915_GTT_PAGE_SIZE;
621 ggtt->invalidate(ggtt);
635 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
641 gte = (gen6_pte_t __iomem *)ggtt->gsm;
660 ggtt->invalidate(ggtt);
740 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
744 (gen6_pte_t __iomem *)ggtt->gsm + first_entry;
745 const int max_entries = ggtt_total_entries(ggtt) - first_entry;
799 static int ggtt_reserve_guc_top(struct i915_ggtt *ggtt)
804 if (!intel_uc_uses_guc(&ggtt->vm.gt->uc))
807 GEM_BUG_ON(ggtt->vm.total <= GUC_TOP_RESERVE_SIZE);
808 offset = ggtt->vm.total - GUC_TOP_RESERVE_SIZE;
810 ret = i915_gem_gtt_reserve(&ggtt->vm, NULL, &ggtt->uc_fw,
814 drm_dbg(&ggtt->vm.i915->drm,
820 static void ggtt_release_guc_top(struct i915_ggtt *ggtt)
822 if (drm_mm_node_allocated(&ggtt->uc_fw))
823 drm_mm_remove_node(&ggtt->uc_fw);
826 static void cleanup_init_ggtt(struct i915_ggtt *ggtt)
828 ggtt_release_guc_top(ggtt);
829 if (drm_mm_node_allocated(&ggtt->error_capture))
830 drm_mm_remove_node(&ggtt->error_capture);
831 mutex_destroy(&ggtt->error_mutex);
834 static int init_ggtt(struct i915_ggtt *ggtt)
856 ggtt->pin_bias = max_t(u32, I915_GTT_PAGE_SIZE,
857 intel_wopcm_guc_size(&ggtt->vm.gt->wopcm));
859 ret = intel_vgt_balloon(ggtt);
863 rw_init(&ggtt->error_mutex, "ggtter");
864 if (ggtt->mappable_end) {
887 ggtt->error_capture.size = 2 * I915_GTT_PAGE_SIZE;
888 ggtt->error_capture.color = I915_COLOR_UNEVICTABLE;
889 if (drm_mm_reserve_node(&ggtt->vm.mm, &ggtt->error_capture))
890 drm_mm_insert_node_in_range(&ggtt->vm.mm,
891 &ggtt->error_capture,
892 ggtt->error_capture.size, 0,
893 ggtt->error_capture.color,
894 0, ggtt->mappable_end,
897 if (drm_mm_node_allocated(&ggtt->error_capture)) {
898 u64 start = ggtt->error_capture.start;
899 u64 size = ggtt->error_capture.size;
901 ggtt->vm.scratch_range(&ggtt->vm, start, size);
902 drm_dbg(&ggtt->vm.i915->drm,
912 ret = ggtt_reserve_guc_top(ggtt);
917 drm_mm_for_each_hole(entry, &ggtt->vm.mm, hole_start, hole_end) {
918 drm_dbg(&ggtt->vm.i915->drm,
921 ggtt->vm.clear_range(&ggtt->vm, hole_start,
926 ggtt->vm.clear_range(&ggtt->vm, ggtt->vm.total - PAGE_SIZE, PAGE_SIZE);
931 cleanup_init_ggtt(ggtt);
968 static int init_aliasing_ppgtt(struct i915_ggtt *ggtt)
974 ppgtt = i915_ppgtt_create(ggtt->vm.gt, 0);
978 if (GEM_WARN_ON(ppgtt->vm.total < ggtt->vm.total)) {
983 err = i915_vm_alloc_pt_stash(&ppgtt->vm, &stash, ggtt->vm.total);
999 ppgtt->vm.allocate_va_range(&ppgtt->vm, &stash, 0, ggtt->vm.total);
1001 ggtt->alias = ppgtt;
1002 ggtt->vm.bind_async_flags |= ppgtt->vm.bind_async_flags;
1004 GEM_BUG_ON(ggtt->vm.vma_ops.bind_vma != intel_ggtt_bind_vma);
1005 ggtt->vm.vma_ops.bind_vma = aliasing_gtt_bind_vma;
1007 GEM_BUG_ON(ggtt->vm.vma_ops.unbind_vma != intel_ggtt_unbind_vma);
1008 ggtt->vm.vma_ops.unbind_vma = aliasing_gtt_unbind_vma;
1020 static void fini_aliasing_ppgtt(struct i915_ggtt *ggtt)
1024 ppgtt = fetch_and_zero(&ggtt->alias);
1030 ggtt->vm.vma_ops.bind_vma = intel_ggtt_bind_vma;
1031 ggtt->vm.vma_ops.unbind_vma = intel_ggtt_unbind_vma;
1038 ret = init_ggtt(to_gt(i915)->ggtt);
1043 ret = init_aliasing_ppgtt(to_gt(i915)->ggtt);
1045 cleanup_init_ggtt(to_gt(i915)->ggtt);
1051 static void ggtt_cleanup_hw(struct i915_ggtt *ggtt)
1055 flush_workqueue(ggtt->vm.i915->wq);
1056 i915_gem_drain_freed_objects(ggtt->vm.i915);
1058 mutex_lock(&ggtt->vm.mutex);
1060 ggtt->vm.skip_pte_rewrite = true;
1062 list_for_each_entry_safe(vma, vn, &ggtt->vm.bound_list, vm_link) {
1074 if (drm_mm_node_allocated(&ggtt->error_capture))
1075 drm_mm_remove_node(&ggtt->error_capture);
1076 mutex_destroy(&ggtt->error_mutex);
1078 ggtt_release_guc_top(ggtt);
1079 intel_vgt_deballoon(ggtt);
1081 ggtt->vm.cleanup(&ggtt->vm);
1083 mutex_unlock(&ggtt->vm.mutex);
1084 i915_address_space_fini(&ggtt->vm);
1087 arch_phys_wc_del(ggtt->mtrr);
1089 if (ggtt->iomap.size)
1090 io_mapping_fini(&ggtt->iomap);
1100 struct i915_ggtt *ggtt = to_gt(i915)->ggtt;
1102 fini_aliasing_ppgtt(ggtt);
1104 intel_ggtt_fini_fences(ggtt);
1105 ggtt_cleanup_hw(ggtt);
1115 struct i915_ggtt *ggtt = to_gt(i915)->ggtt;
1117 GEM_WARN_ON(kref_read(&ggtt->vm.resv_ref) != 1);
1118 dma_resv_fini(&ggtt->vm._resv);
1172 static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size)
1174 struct drm_i915_private *i915 = ggtt->vm.i915;
1175 struct intel_uncore *uncore = ggtt->vm.gt->uncore;
1191 ggtt->gsm = ioremap_wc(phys_addr, size);
1193 ggtt->gsm = ioremap(phys_addr, size);
1195 if (!ggtt->gsm) {
1196 drm_err(&i915->drm, "Failed to map the ggtt page table\n");
1200 kref_init(&ggtt->vm.resv_ref);
1201 ret = setup_scratch_page(&ggtt->vm);
1205 iounmap(ggtt->gsm);
1210 if (i915_gem_object_is_lmem(ggtt->vm.scratch[0]))
1213 ggtt->vm.scratch[0]->encode =
1214 ggtt->vm.pte_encode(px_dma(ggtt->vm.scratch[0]),
1224 static int ggtt_probe_common(struct i915_ggtt *ggtt, u64 size)
1226 struct drm_i915_private *i915 = ggtt->vm.i915;
1227 struct intel_uncore *uncore = ggtt->vm.gt->uncore;
1258 flags | BUS_SPACE_MAP_LINEAR, &ggtt->gsm_bsh);
1260 drm_err(&i915->drm, "Failed to map the ggtt page table\n");
1263 ggtt->gsm = bus_space_vaddr(i915->bst, ggtt->gsm_bsh);
1264 ggtt->gsm_size = size;
1265 if (!ggtt->gsm) {
1266 drm_err(&i915->drm, "Failed to map the ggtt page table\n");
1270 kref_init(&ggtt->vm.resv_ref);
1271 ret = setup_scratch_page(&ggtt->vm);
1275 bus_space_unmap(i915->bst, ggtt->gsm_bsh, size);
1280 if (i915_gem_object_is_lmem(ggtt->vm.scratch[0]))
1283 ggtt->vm.scratch[0]->encode =
1284 ggtt->vm.pte_encode(px_dma(ggtt->vm.scratch[0]),
1296 struct i915_ggtt *ggtt = i915_vm_to_ggtt(vm);
1299 iounmap(ggtt->gsm);
1301 bus_space_unmap(vm->i915->bst, ggtt->gsm_bsh, ggtt->gsm_size);
1314 static int gen8_gmch_probe(struct i915_ggtt *ggtt)
1316 struct drm_i915_private *i915 = ggtt->vm.i915;
1326 ggtt->gmadr = pci_resource(pdev, GEN4_GMADR_BAR);
1327 ggtt->mappable_end = resource_size(&ggtt->gmadr);
1339 ggtt->gmadr.start = base;
1340 ggtt->mappable_end = sz;
1350 ggtt->vm.alloc_pt_dma = alloc_pt_dma;
1351 ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
1352 ggtt->vm.lmem_pt_obj_flags = I915_BO_ALLOC_PM_EARLY;
1354 ggtt->vm.total = (size / sizeof(gen8_pte_t)) * I915_GTT_PAGE_SIZE;
1355 ggtt->vm.cleanup = gen6_gmch_remove;
1356 ggtt->vm.insert_page = gen8_ggtt_insert_page;
1357 ggtt->vm.clear_range = nop_clear_range;
1358 ggtt->vm.scratch_range = gen8_ggtt_clear_range;
1360 ggtt->vm.insert_entries = gen8_ggtt_insert_entries;
1367 ggtt->vm.insert_entries = bxt_vtd_ggtt_insert_entries__BKL;
1368 ggtt->vm.insert_page = bxt_vtd_ggtt_insert_page__BKL;
1376 ggtt->vm.raw_insert_page = gen8_ggtt_insert_page;
1377 ggtt->vm.raw_insert_entries = gen8_ggtt_insert_entries;
1379 ggtt->vm.bind_async_flags =
1384 ggtt->vm.scratch_range = gen8_ggtt_scratch_range_bind;
1385 ggtt->vm.insert_page = gen8_ggtt_insert_page_bind;
1386 ggtt->vm.insert_entries = gen8_ggtt_insert_entries_bind;
1391 ggtt->vm.raw_insert_page = gen8_ggtt_insert_page;
1394 if (intel_uc_wants_guc(&ggtt->vm.gt->uc))
1395 ggtt->invalidate = guc_ggtt_invalidate;
1397 ggtt->invalidate = gen8_ggtt_invalidate;
1399 ggtt->vm.vma_ops.bind_vma = intel_ggtt_bind_vma;
1400 ggtt->vm.vma_ops.unbind_vma = intel_ggtt_unbind_vma;
1403 ggtt->vm.pte_encode = mtl_ggtt_pte_encode;
1405 ggtt->vm.pte_encode = gen8_ggtt_pte_encode;
1407 return ggtt_probe_common(ggtt, size);
1506 static int gen6_gmch_probe(struct i915_ggtt *ggtt)
1508 struct drm_i915_private *i915 = ggtt->vm.i915;
1517 ggtt->gmadr = pci_resource(pdev, GEN4_GMADR_BAR);
1518 ggtt->mappable_end = resource_size(&ggtt->gmadr);
1530 ggtt->gmadr.start = base;
1531 ggtt->mappable_end = sz;
1538 if (ggtt->mappable_end < (64 << 20) ||
1539 ggtt->mappable_end > (512 << 20)) {
1541 &ggtt->mappable_end);
1548 ggtt->vm.total = (size / sizeof(gen6_pte_t)) * I915_GTT_PAGE_SIZE;
1550 ggtt->vm.alloc_pt_dma = alloc_pt_dma;
1551 ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
1553 ggtt->vm.clear_range = nop_clear_range;
1555 ggtt->vm.clear_range = gen6_ggtt_clear_range;
1556 ggtt->vm.scratch_range = gen6_ggtt_clear_range;
1557 ggtt->vm.insert_page = gen6_ggtt_insert_page;
1558 ggtt->vm.insert_entries = gen6_ggtt_insert_entries;
1559 ggtt->vm.cleanup = gen6_gmch_remove;
1561 ggtt->invalidate = gen6_ggtt_invalidate;
1564 ggtt->vm.pte_encode = iris_pte_encode;
1566 ggtt->vm.pte_encode = hsw_pte_encode;
1568 ggtt->vm.pte_encode = byt_pte_encode;
1570 ggtt->vm.pte_encode = ivb_pte_encode;
1572 ggtt->vm.pte_encode = snb_pte_encode;
1574 ggtt->vm.vma_ops.bind_vma = intel_ggtt_bind_vma;
1575 ggtt->vm.vma_ops.unbind_vma = intel_ggtt_unbind_vma;
1577 return ggtt_probe_common(ggtt, size);
1580 static int ggtt_probe_hw(struct i915_ggtt *ggtt, struct intel_gt *gt)
1585 ggtt->vm.gt = gt;
1586 ggtt->vm.i915 = i915;
1588 ggtt->vm.dma = i915->drm.dev;
1590 dma_resv_init(&ggtt->vm._resv);
1593 ret = gen8_gmch_probe(ggtt);
1595 ret = gen6_gmch_probe(ggtt);
1597 ret = intel_ggtt_gmch_probe(ggtt);
1600 dma_resv_fini(&ggtt->vm._resv);
1604 if ((ggtt->vm.total - 1) >> 32) {
1608 ggtt->vm.total >> 20);
1609 ggtt->vm.total = 1ULL << 32;
1610 ggtt->mappable_end =
1611 min_t(u64, ggtt->mappable_end, ggtt->vm.total);
1614 if (ggtt->mappable_end > ggtt->vm.total) {
1618 &ggtt->mappable_end, ggtt->vm.total);
1619 ggtt->mappable_end = ggtt->vm.total;
1623 drm_dbg(&i915->drm, "GGTT size = %lluM\n", ggtt->vm.total >> 20);
1625 (u64)ggtt->mappable_end >> 20);
1647 ret = ggtt_probe_hw(to_gt(i915)->ggtt, to_gt(i915));
1659 struct i915_ggtt *ggtt;
1661 ggtt = drmm_kzalloc(&i915->drm, sizeof(*ggtt), GFP_KERNEL);
1662 if (!ggtt)
1665 INIT_LIST_HEAD(&ggtt->gt_list);
1667 return ggtt;
1726 void i915_ggtt_resume(struct i915_ggtt *ggtt)
1731 list_for_each_entry(gt, &ggtt->gt_list, ggtt_link)
1734 flush = i915_ggtt_resume_vm(&ggtt->vm);
1736 if (drm_mm_node_allocated(&ggtt->error_capture))
1737 ggtt->vm.scratch_range(&ggtt->vm, ggtt->error_capture.start,
1738 ggtt->error_capture.size);
1740 list_for_each_entry(gt, &ggtt->gt_list, ggtt_link)
1743 ggtt->invalidate(ggtt);
1748 intel_ggtt_restore_fences(ggtt);