drm/ttm: add io_mem_pfn callback
authorChristian König <christian.koenig@amd.com>
Tue, 28 Mar 2017 14:54:50 +0000 (16:54 +0200)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 5 Apr 2017 03:33:42 +0000 (23:33 -0400)
This allows the driver to handle io_mem mappings on their own.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
13 files changed:
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
drivers/gpu/drm/ast/ast_ttm.c
drivers/gpu/drm/bochs/bochs_mm.c
drivers/gpu/drm/cirrus/cirrus_ttm.c
drivers/gpu/drm/mgag200/mgag200_ttm.c
drivers/gpu/drm/nouveau/nouveau_bo.c
drivers/gpu/drm/qxl/qxl_ttm.c
drivers/gpu/drm/radeon/radeon_ttm.c
drivers/gpu/drm/ttm/ttm_bo_vm.c
drivers/gpu/drm/virtio/virtgpu_ttm.c
drivers/gpu/drm/vmwgfx/vmwgfx_buffer.c
include/drm/ttm/ttm_bo_api.h
include/drm/ttm/ttm_bo_driver.h

index 244bb9aacf862d3676c91af04701991b4d5d2673..7b6463b288aa6741cd52421ffac3b7c09007d6d7 100644 (file)
@@ -1089,6 +1089,7 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
        .fault_reserve_notify = &amdgpu_bo_fault_reserve_notify,
        .io_mem_reserve = &amdgpu_ttm_io_mem_reserve,
        .io_mem_free = &amdgpu_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int amdgpu_ttm_init(struct amdgpu_device *adev)
index 50c910efa13da4f6e02f56ac69db03f14b11b168..e879496b8a423145010997dccbadd751cbe559ca 100644 (file)
@@ -236,6 +236,7 @@ struct ttm_bo_driver ast_bo_driver = {
        .verify_access = ast_bo_verify_access,
        .io_mem_reserve = &ast_ttm_io_mem_reserve,
        .io_mem_free = &ast_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int ast_mm_init(struct ast_private *ast)
index 857755ac2d702050d05f8eb4484fdf0590f9aa80..c4cadb638460eb86f06488f4ab5f8a75d3be8701 100644 (file)
@@ -205,6 +205,7 @@ struct ttm_bo_driver bochs_bo_driver = {
        .verify_access = bochs_bo_verify_access,
        .io_mem_reserve = &bochs_ttm_io_mem_reserve,
        .io_mem_free = &bochs_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int bochs_mm_init(struct bochs_device *bochs)
index f53aa8f4a143eb840048e5dd502ab8fa3f637ab1..93dbcd38355d9c2e89f5489e38e63f3d849e5204 100644 (file)
@@ -236,6 +236,7 @@ struct ttm_bo_driver cirrus_bo_driver = {
        .verify_access = cirrus_bo_verify_access,
        .io_mem_reserve = &cirrus_ttm_io_mem_reserve,
        .io_mem_free = &cirrus_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int cirrus_mm_init(struct cirrus_device *cirrus)
index 657598bb1e6bcece8a1e4bb8734796e40f78cc59..565a217b46f2519f318c22ca6a522572dd7d93bf 100644 (file)
@@ -236,6 +236,7 @@ struct ttm_bo_driver mgag200_bo_driver = {
        .verify_access = mgag200_bo_verify_access,
        .io_mem_reserve = &mgag200_ttm_io_mem_reserve,
        .io_mem_free = &mgag200_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int mgag200_mm_init(struct mga_device *mdev)
index 548f36d33924e4bb88c90117db6df172892c2ae8..e427f80344c4da3f8681d28b7114e2375b6be350 100644 (file)
@@ -1574,6 +1574,7 @@ struct ttm_bo_driver nouveau_bo_driver = {
        .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify,
        .io_mem_reserve = &nouveau_ttm_io_mem_reserve,
        .io_mem_free = &nouveau_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 struct nvkm_vma *
index 7d1cab57c89ea86a5eb612399d4e871652ad84c0..0fdedee4509ddbfb14b53c4f85c5ecd48d28eb12 100644 (file)
@@ -393,6 +393,7 @@ static struct ttm_bo_driver qxl_bo_driver = {
        .verify_access = &qxl_verify_access,
        .io_mem_reserve = &qxl_ttm_io_mem_reserve,
        .io_mem_free = &qxl_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
        .move_notify = &qxl_bo_move_notify,
 };
 
index 684f1703aa5c7189bc55ca1633aeafd78a97c55a..bfb06469db46d0d6c7df53608ccba2eb96428fc3 100644 (file)
@@ -873,6 +873,7 @@ static struct ttm_bo_driver radeon_bo_driver = {
        .fault_reserve_notify = &radeon_bo_fault_reserve_notify,
        .io_mem_reserve = &radeon_ttm_io_mem_reserve,
        .io_mem_free = &radeon_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
 
 int radeon_ttm_init(struct radeon_device *rdev)
index 35ffb3754febc5e2acccfffe0d8c8cc9dc8a8909..9f53df95f35c55a061f2682ef35a5bfe6dec40c2 100644 (file)
@@ -231,7 +231,7 @@ static int ttm_bo_vm_fault(struct vm_fault *vmf)
         */
        for (i = 0; i < TTM_BO_VM_NUM_PREFAULT; ++i) {
                if (bo->mem.bus.is_iomem)
-                       pfn = ((bo->mem.bus.base + bo->mem.bus.offset) >> PAGE_SHIFT) + page_offset;
+                       pfn = bdev->driver->io_mem_pfn(bo, page_offset);
                else {
                        page = ttm->pages[page_offset];
                        if (unlikely(!page && i == 0)) {
@@ -324,6 +324,14 @@ static struct ttm_buffer_object *ttm_bo_vm_lookup(struct ttm_bo_device *bdev,
        return bo;
 }
 
+unsigned long ttm_bo_default_io_mem_pfn(struct ttm_buffer_object *bo,
+                                       unsigned long page_offset)
+{
+       return ((bo->mem.bus.base + bo->mem.bus.offset) >> PAGE_SHIFT)
+               + page_offset;
+}
+EXPORT_SYMBOL(ttm_bo_default_io_mem_pfn);
+
 int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma,
                struct ttm_bo_device *bdev)
 {
index 70ec8ca8d9b19cb6fb1a078a2ceaeec309d57523..4e8e27d50922eb1216e8c4a040548e51429f9c95 100644 (file)
@@ -431,6 +431,7 @@ static struct ttm_bo_driver virtio_gpu_bo_driver = {
        .verify_access = &virtio_gpu_verify_access,
        .io_mem_reserve = &virtio_gpu_ttm_io_mem_reserve,
        .io_mem_free = &virtio_gpu_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
        .move_notify = &virtio_gpu_bo_move_notify,
        .swap_notify = &virtio_gpu_bo_swap_notify,
 };
index 4c7f24a67a2e8e681986f964cffe59f7e15f2a63..35bf781e418e339eae86760c04697b9a1b128d25 100644 (file)
@@ -859,4 +859,5 @@ struct ttm_bo_driver vmw_bo_driver = {
        .fault_reserve_notify = &vmw_ttm_fault_reserve_notify,
        .io_mem_reserve = &vmw_ttm_io_mem_reserve,
        .io_mem_free = &vmw_ttm_io_mem_free,
+       .io_mem_pfn = ttm_bo_default_io_mem_pfn,
 };
index 0b1ce05e2c2e8c2df0e87adc3f67b798032c7ae1..fa07be19794500a6c4096b810742c2311201407c 100644 (file)
@@ -710,6 +710,17 @@ extern void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map);
 extern int ttm_fbdev_mmap(struct vm_area_struct *vma,
                          struct ttm_buffer_object *bo);
 
+/**
+ * ttm_bo_default_iomem_pfn - get a pfn for a page offset
+ *
+ * @bo: the BO we need to look up the pfn for
+ * @page_offset: offset inside the BO to look up.
+ *
+ * Calculate the PFN for iomem based mappings during page fault
+ */
+unsigned long ttm_bo_default_io_mem_pfn(struct ttm_buffer_object *bo,
+                                       unsigned long page_offset);
+
 /**
  * ttm_bo_mmap - mmap out of the ttm device address space.
  *
index 3641c6128ac2d0f35e71280cb9f0b482d17a086a..6bbd34d25a8de0d2d137ba1b9de82b29990f858a 100644 (file)
@@ -462,6 +462,15 @@ struct ttm_bo_driver {
                              struct ttm_mem_reg *mem);
        void (*io_mem_free)(struct ttm_bo_device *bdev,
                            struct ttm_mem_reg *mem);
+
+       /**
+        * Return the pfn for a given page_offset inside the BO.
+        *
+        * @bo: the BO to look up the pfn for
+        * @page_offset: the offset to look up
+        */
+       unsigned long (*io_mem_pfn)(struct ttm_buffer_object *bo,
+                                   unsigned long page_offset);
 };
 
 /**