Skip to content

Commit dfced2e

Browse files
samli111alexdeucher
authored andcommitted
drm/amdgpu: Add gem_prime_mmap support
v2: drop hdp invalidate/flush. v3: honor pgoff during prime mmap. Add a barrier after cpu access. v4: drop begin/end_cpu_access() for now, revisit later. Signed-off-by: Samuel Li <Samuel.Li@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent aec8d5c commit dfced2e

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
413413
struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
414414
void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
415415
void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
416+
int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
416417
int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
417418

418419
/* sub-allocation manager, it has to be protected by another lock.

drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ static struct drm_driver kms_driver = {
855855
.gem_prime_import_sg_table = amdgpu_gem_prime_import_sg_table,
856856
.gem_prime_vmap = amdgpu_gem_prime_vmap,
857857
.gem_prime_vunmap = amdgpu_gem_prime_vunmap,
858+
.gem_prime_mmap = amdgpu_gem_prime_mmap,
858859

859860
.name = DRIVER_NAME,
860861
.desc = DRIVER_DESC,

drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,40 @@ void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr)
5757
ttm_bo_kunmap(&bo->dma_buf_vmap);
5858
}
5959

60+
int amdgpu_gem_prime_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
61+
{
62+
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
63+
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
64+
unsigned asize = amdgpu_bo_size(bo);
65+
int ret;
66+
67+
if (!vma->vm_file)
68+
return -ENODEV;
69+
70+
if (adev == NULL)
71+
return -ENODEV;
72+
73+
/* Check for valid size. */
74+
if (asize < vma->vm_end - vma->vm_start)
75+
return -EINVAL;
76+
77+
if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) ||
78+
(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)) {
79+
return -EPERM;
80+
}
81+
vma->vm_pgoff += amdgpu_bo_mmap_offset(bo) >> PAGE_SHIFT;
82+
83+
/* prime mmap does not need to check access, so allow here */
84+
ret = drm_vma_node_allow(&obj->vma_node, vma->vm_file->private_data);
85+
if (ret)
86+
return ret;
87+
88+
ret = ttm_bo_mmap(vma->vm_file, vma, &adev->mman.bdev);
89+
drm_vma_node_revoke(&obj->vma_node, vma->vm_file->private_data);
90+
91+
return ret;
92+
}
93+
6094
struct drm_gem_object *
6195
amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
6296
struct dma_buf_attachment *attach,

0 commit comments

Comments
 (0)