drm/v3d: Improve MMU support for larger pages
authorPhil Elwell <phil@raspberrypi.com>
Fri, 4 Aug 2023 10:26:10 +0000 (11:26 +0100)
committerDom Cobley <popcornmix@gmail.com>
Mon, 19 Feb 2024 11:34:50 +0000 (11:34 +0000)
The built-in MMU driver went most of the way towards supporting larger
kernel pages, but dropped the ball when it comes to calculating indexes
into the page table. Fix it.

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
drivers/gpu/drm/v3d/v3d_mmu.c

index 5a45353..b52ae2a 100644 (file)
@@ -22,6 +22,7 @@
 #include "v3d_regs.h"
 
 #define V3D_MMU_PAGE_SHIFT 12
+#define V3D_PAGE_FACTOR (PAGE_SIZE >> V3D_MMU_PAGE_SHIFT)
 
 /* Note: All PTEs for the 1MB superpage must be filled with the
  * superpage bit set.
@@ -88,7 +89,7 @@ void v3d_mmu_insert_ptes(struct v3d_bo *bo)
 {
        struct drm_gem_shmem_object *shmem_obj = &bo->base;
        struct v3d_dev *v3d = to_v3d_dev(shmem_obj->base.dev);
-       u32 page = bo->node.start;
+       u32 page = bo->node.start * V3D_PAGE_FACTOR;
        u32 page_prot = V3D_PTE_WRITEABLE | V3D_PTE_VALID;
        struct sg_dma_page_iter dma_iter;
 
@@ -98,13 +99,13 @@ void v3d_mmu_insert_ptes(struct v3d_bo *bo)
                u32 pte = page_prot | page_address;
                u32 i;
 
-               BUG_ON(page_address + (PAGE_SIZE >> V3D_MMU_PAGE_SHIFT) >=
+               BUG_ON(page_address + V3D_PAGE_FACTOR >=
                       BIT(24));
-               for (i = 0; i < PAGE_SIZE >> V3D_MMU_PAGE_SHIFT; i++)
+               for (i = 0; i < V3D_PAGE_FACTOR; i++)
                        v3d->pt[page++] = pte + i;
        }
 
-       WARN_ON_ONCE(page - bo->node.start !=
+       WARN_ON_ONCE(page - (bo->node.start * V3D_PAGE_FACTOR) !=
                     shmem_obj->base.size >> V3D_MMU_PAGE_SHIFT);
 
        if (v3d_mmu_flush_all(v3d))
@@ -115,10 +116,10 @@ void v3d_mmu_remove_ptes(struct v3d_bo *bo)
 {
        struct v3d_dev *v3d = to_v3d_dev(bo->base.base.dev);
        u32 npages = bo->base.base.size >> V3D_MMU_PAGE_SHIFT;
-       u32 page;
+       u32 page = bo->node.start * V3D_PAGE_FACTOR;
 
-       for (page = bo->node.start; page < bo->node.start + npages; page++)
-               v3d->pt[page] = 0;
+       while (npages--)
+               v3d->pt[page++] = 0;
 
        if (v3d_mmu_flush_all(v3d))
                dev_err(v3d->drm.dev, "MMU flush timeout\n");