1 From 12c7ea43b930976f35ce75d11fd3f55438868e13 Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.com>
3 Date: Fri, 4 Aug 2023 11:26:10 +0100
4 Subject: [PATCH] drm/v3d: Improve MMU support for larger pages
6 The built-in MMU driver went most of the way towards supporting larger
7 kernel pages, but dropped the ball when it comes to calculating indexes
8 into the page table. Fix it.
10 Signed-off-by: Phil Elwell <phil@raspberrypi.com>
12 drivers/gpu/drm/v3d/v3d_mmu.c | 15 ++++++++-------
13 1 file changed, 8 insertions(+), 7 deletions(-)
15 --- a/drivers/gpu/drm/v3d/v3d_mmu.c
16 +++ b/drivers/gpu/drm/v3d/v3d_mmu.c
20 #define V3D_MMU_PAGE_SHIFT 12
21 +#define V3D_PAGE_FACTOR (PAGE_SIZE >> V3D_MMU_PAGE_SHIFT)
23 /* Note: All PTEs for the 1MB superpage must be filled with the
25 @@ -88,7 +89,7 @@ void v3d_mmu_insert_ptes(struct v3d_bo *
27 struct drm_gem_shmem_object *shmem_obj = &bo->base;
28 struct v3d_dev *v3d = to_v3d_dev(shmem_obj->base.dev);
29 - u32 page = bo->node.start;
30 + u32 page = bo->node.start * V3D_PAGE_FACTOR;
31 u32 page_prot = V3D_PTE_WRITEABLE | V3D_PTE_VALID;
32 struct sg_dma_page_iter dma_iter;
34 @@ -98,13 +99,13 @@ void v3d_mmu_insert_ptes(struct v3d_bo *
35 u32 pte = page_prot | page_address;
38 - BUG_ON(page_address + (PAGE_SIZE >> V3D_MMU_PAGE_SHIFT) >=
39 + BUG_ON(page_address + V3D_PAGE_FACTOR >=
41 - for (i = 0; i < PAGE_SIZE >> V3D_MMU_PAGE_SHIFT; i++)
42 + for (i = 0; i < V3D_PAGE_FACTOR; i++)
43 v3d->pt[page++] = pte + i;
46 - WARN_ON_ONCE(page - bo->node.start !=
47 + WARN_ON_ONCE(page - (bo->node.start * V3D_PAGE_FACTOR) !=
48 shmem_obj->base.size >> V3D_MMU_PAGE_SHIFT);
50 if (v3d_mmu_flush_all(v3d))
51 @@ -115,10 +116,10 @@ void v3d_mmu_remove_ptes(struct v3d_bo *
53 struct v3d_dev *v3d = to_v3d_dev(bo->base.base.dev);
54 u32 npages = bo->base.base.size >> V3D_MMU_PAGE_SHIFT;
56 + u32 page = bo->node.start * V3D_PAGE_FACTOR;
58 - for (page = bo->node.start; page < bo->node.start + npages; page++)
61 + v3d->pt[page++] = 0;
63 if (v3d_mmu_flush_all(v3d))
64 dev_err(v3d->drm.dev, "MMU flush timeout\n");