drm/xe: Set PTE_DM bit for stolen on MTL
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 26 Jul 2023 16:07:04 +0000 (09:07 -0700)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 21 Dec 2023 16:39:05 +0000 (11:39 -0500)
Integrated graphics 1270 and beyond should set the PTE_LM bit in the PTE
when it's stolen memory. Add a new function, xe_bo_is_stolen_devmem(),
and use it when encoding the PTE.

In some places in the spec the PTE bit is called "Local Memory",
abbreviated as LM, and in others it's called "Device Memory" (DM). Since
we moved away from "Local Memory" and preferred the "vram" terminology,
also rename the macros as DM to follow the name of the new function.

Reviewed-by: Matt Roper <matthew.d.roper@intel.com>
Link: https://lore.kernel.org/r/20230726160708.3967790-7-lucas.demarchi@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_bo.c
drivers/gpu/drm/xe/xe_bo.h
drivers/gpu/drm/xe/xe_ggtt.c
drivers/gpu/drm/xe/xe_migrate.c
drivers/gpu/drm/xe/xe_pt.c

index d4e60a96ed64abe3762f16e75db766e16f7fdc5e..65b56e7a2fde50a981a0f8e866b55780eaf20f38 100644 (file)
@@ -80,6 +80,21 @@ bool xe_bo_is_stolen(struct xe_bo *bo)
        return bo->ttm.resource->mem_type == XE_PL_STOLEN;
 }
 
+/**
+ * xe_bo_is_stolen_devmem - check if BO is of stolen type accessed via PCI BAR
+ * @bo: The BO
+ *
+ * The stolen memory is accessed through the PCI BAR for both DGFX and some
+ * integrated platforms that have a dedicated bit in the PTE for devmem (DM).
+ *
+ * Returns: true if it's stolen memory accessed via PCI BAR, false otherwise.
+ */
+bool xe_bo_is_stolen_devmem(struct xe_bo *bo)
+{
+       return xe_bo_is_stolen(bo) &&
+               GRAPHICS_VERx100(xe_bo_device(bo)) >= 1270;
+}
+
 static bool xe_bo_is_user(struct xe_bo *bo)
 {
        return bo->flags & XE_BO_CREATE_USER_BIT;
index b8817e13aeeb6f2a41e55da6d73beaf4c1f46c15..a9a32d6802084fb941d5f7a3b3472be5287bd177 100644 (file)
@@ -67,9 +67,9 @@
 #define XE_PDPE_PS_1G                  BIT_ULL(7)
 #define XE_PDE_IPS_64K                 BIT_ULL(11)
 
-#define XE_GGTT_PTE_LM                 BIT_ULL(1)
+#define XE_GGTT_PTE_DM                 BIT_ULL(1)
 #define XE_USM_PPGTT_PTE_AE            BIT_ULL(10)
-#define XE_PPGTT_PTE_LM                        BIT_ULL(11)
+#define XE_PPGTT_PTE_DM                        BIT_ULL(11)
 #define XE_PDE_64K                     BIT_ULL(6)
 #define XE_PTE_PS64                    BIT_ULL(8)
 #define XE_PTE_NULL                    BIT_ULL(9)
@@ -239,6 +239,7 @@ void xe_bo_vunmap(struct xe_bo *bo);
 bool mem_type_is_vram(u32 mem_type);
 bool xe_bo_is_vram(struct xe_bo *bo);
 bool xe_bo_is_stolen(struct xe_bo *bo);
+bool xe_bo_is_stolen_devmem(struct xe_bo *bo);
 uint64_t vram_region_gpu_offset(struct ttm_resource *res);
 
 bool xe_bo_can_migrate(struct xe_bo *bo, u32 mem_type);
index 3eea65bd1bcda7b5cf396e8f0efb8b832bf141c8..bf46b90a76ad72f4f963032f2347271724cdb15b 100644 (file)
@@ -35,8 +35,8 @@ u64 xe_ggtt_pte_encode(struct xe_bo *bo, u64 bo_offset)
        pte = xe_bo_addr(bo, bo_offset, XE_PAGE_SIZE);
        pte |= XE_PAGE_PRESENT;
 
-       if (xe_bo_is_vram(bo))
-               pte |= XE_GGTT_PTE_LM;
+       if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo))
+               pte |= XE_GGTT_PTE_DM;
 
        /* FIXME: vfunc + pass in caching rules */
        if (xe->info.platform == XE_METEORLAKE) {
index 03f50a14c5c2df707fc49de14080cb899c5d0380..0405136bc0b1fb371c64e6ac971fd1d842df1848 100644 (file)
@@ -258,7 +258,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
                level = 2;
                ofs = map_ofs + XE_PAGE_SIZE * level + 256 * 8;
                flags = XE_PAGE_RW | XE_PAGE_PRESENT | PPAT_CACHED |
-                       XE_PPGTT_PTE_LM | XE_PDPE_PS_1G;
+                       XE_PPGTT_PTE_DM | XE_PDPE_PS_1G;
 
                /*
                 * Use 1GB pages, it shouldn't matter the physical amount of
@@ -463,7 +463,7 @@ static void emit_pte(struct xe_migrate *m,
                                }
 
                                addr += vram_region_gpu_offset(bo->ttm.resource);
-                               addr |= XE_PPGTT_PTE_LM;
+                               addr |= XE_PPGTT_PTE_DM;
                        }
                        addr |= PPAT_CACHED | XE_PAGE_PRESENT | XE_PAGE_RW;
                        bb->cs[bb->len++] = lower_32_bits(addr);
index f69f7dbaca55809c6408db78e7d65d5bd67865d2..d9192bf503624c850b1e9986cf933e1344324192 100644 (file)
@@ -127,8 +127,8 @@ u64 xe_pte_encode(struct xe_bo *bo, u64 offset, enum xe_cache_level cache,
        u64 pte;
 
        pte = xe_bo_addr(bo, offset, XE_PAGE_SIZE);
-       if (xe_bo_is_vram(bo))
-               pte |= XE_PPGTT_PTE_LM;
+       if (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo))
+               pte |= XE_PPGTT_PTE_DM;
 
        return __pte_encode(pte, cache, NULL, pt_level);
 }
@@ -714,7 +714,8 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
                 struct xe_vm_pgtable_update *entries, u32 *num_entries)
 {
        struct xe_bo *bo = xe_vma_bo(vma);
-       bool is_vram = !xe_vma_is_userptr(vma) && bo && xe_bo_is_vram(bo);
+       bool is_devmem = !xe_vma_is_userptr(vma) && bo &&
+               (xe_bo_is_vram(bo) || xe_bo_is_stolen_devmem(bo));
        struct xe_res_cursor curs;
        struct xe_pt_stage_bind_walk xe_walk = {
                .base = {
@@ -728,13 +729,13 @@ xe_pt_stage_bind(struct xe_tile *tile, struct xe_vma *vma,
                .va_curs_start = xe_vma_start(vma),
                .vma = vma,
                .wupd.entries = entries,
-               .needs_64K = (xe_vma_vm(vma)->flags & XE_VM_FLAG_64K) && is_vram,
+               .needs_64K = (xe_vma_vm(vma)->flags & XE_VM_FLAG_64K) && is_devmem,
        };
        struct xe_pt *pt = xe_vma_vm(vma)->pt_root[tile->id];
        int ret;
 
-       if (is_vram) {
-               xe_walk.default_pte = XE_PPGTT_PTE_LM;
+       if (is_devmem) {
+               xe_walk.default_pte = XE_PPGTT_PTE_DM;
                if (vma && vma->gpuva.flags & XE_VMA_ATOMIC_PTE_BIT)
                        xe_walk.default_pte |= XE_USM_PPGTT_PTE_AE;
                xe_walk.dma_offset = vram_region_gpu_offset(bo->ttm.resource);