1 // SPDX-License-Identifier: MIT
3 * Copyright © 2022 Intel Corporation
6 #include "intel_ggtt_gmch.h"
8 #include <drm/intel/intel-gtt.h>
10 #include <linux/agp_backend.h>
13 #include "i915_utils.h"
14 #include "intel_gtt.h"
15 #include "intel_gt_regs.h"
18 static void gmch_ggtt_insert_page(struct i915_address_space *vm,
21 unsigned int pat_index,
24 unsigned int flags = (pat_index == I915_CACHE_NONE) ?
25 AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
27 intel_gmch_gtt_insert_page(addr, offset >> PAGE_SHIFT, flags);
30 static void gmch_ggtt_insert_entries(struct i915_address_space *vm,
31 struct i915_vma_resource *vma_res,
32 unsigned int pat_index,
35 unsigned int flags = (pat_index == I915_CACHE_NONE) ?
36 AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
38 intel_gmch_gtt_insert_sg_entries(vma_res->bi.pages, vma_res->start >> PAGE_SHIFT,
42 static void gmch_ggtt_invalidate(struct i915_ggtt *ggtt)
44 intel_gmch_gtt_flush();
47 static void gmch_ggtt_clear_range(struct i915_address_space *vm,
48 u64 start, u64 length)
50 intel_gmch_gtt_clear_range(start >> PAGE_SHIFT, length >> PAGE_SHIFT);
53 static void gmch_ggtt_remove(struct i915_address_space *vm)
59 * Certain Gen5 chipsets require idling the GPU before unmapping anything from
60 * the GTT when VT-d is enabled.
62 static bool needs_idle_maps(struct drm_i915_private *i915)
65 * Query intel_iommu to see if we need the workaround. Presumably that
68 if (!i915_vtd_active(i915))
71 if (GRAPHICS_VER(i915) == 5 && IS_MOBILE(i915))
77 int intel_ggtt_gmch_probe(struct i915_ggtt *ggtt)
79 struct drm_i915_private *i915 = ggtt->vm.i915;
80 phys_addr_t gmadr_base;
83 ret = intel_gmch_probe(i915->gmch.pdev, to_pci_dev(i915->drm.dev), NULL);
85 drm_err(&i915->drm, "failed to set up gmch\n");
89 intel_gmch_gtt_get(&ggtt->vm.total, &gmadr_base, &ggtt->mappable_end);
91 ggtt->gmadr = DEFINE_RES_MEM(gmadr_base, ggtt->mappable_end);
93 ggtt->vm.alloc_pt_dma = alloc_pt_dma;
94 ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
96 if (needs_idle_maps(i915)) {
97 drm_notice(&i915->drm,
98 "Flushing DMA requests before IOMMU unmaps; performance may be degraded\n");
99 ggtt->do_idle_maps = true;
102 ggtt->vm.insert_page = gmch_ggtt_insert_page;
103 ggtt->vm.insert_entries = gmch_ggtt_insert_entries;
104 ggtt->vm.clear_range = gmch_ggtt_clear_range;
105 ggtt->vm.scratch_range = gmch_ggtt_clear_range;
106 ggtt->vm.cleanup = gmch_ggtt_remove;
108 ggtt->invalidate = gmch_ggtt_invalidate;
110 ggtt->vm.vma_ops.bind_vma = intel_ggtt_bind_vma;
111 ggtt->vm.vma_ops.unbind_vma = intel_ggtt_unbind_vma;
113 if (unlikely(ggtt->do_idle_maps))
114 drm_notice(&i915->drm,
115 "Applying Ironlake quirks for intel_iommu\n");
120 int intel_ggtt_gmch_enable_hw(struct drm_i915_private *i915)
122 if (!intel_gmch_enable_gtt())
128 void intel_ggtt_gmch_flush(void)
130 intel_gmch_gtt_flush();