Skip to content

Commit e552ee4

Browse files
fxkamdalexdeucher
authored andcommitted
drm/amdgpu: Move dmabuf attach/detach to backend_(un)bind
The dmabuf attachment should be updated by moving the SG BO to DOMAIN_CPU and back to DOMAIN_GTT. This does not necessarily invoke the populate/unpopulate callbacks. Do this in backend_bind/unbind instead. Signed-off-by: Felix Kuehling <[email protected]> Reviewed-by: Christian König <[email protected]> Acked-by: Oak Zeng <[email protected]> Acked-by: Ramesh Errabolu <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 5ac3c3e commit e552ee4

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,6 @@ kfd_mem_dmaunmap_dmabuf(struct kfd_mem_attachment *attachment)
587587

588588
amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_CPU);
589589
ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
590-
/* FIXME: This does not guarantee that amdgpu_ttm_tt_unpopulate is
591-
* called
592-
*/
593590
}
594591

595592
static void

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

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,23 @@ static int amdgpu_ttm_backend_bind(struct ttm_device *bdev,
907907
DRM_ERROR("failed to pin userptr\n");
908908
return r;
909909
}
910+
} else if (ttm->page_flags & TTM_PAGE_FLAG_SG) {
911+
if (!ttm->sg) {
912+
struct dma_buf_attachment *attach;
913+
struct sg_table *sgt;
914+
915+
attach = gtt->gobj->import_attach;
916+
sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
917+
if (IS_ERR(sgt))
918+
return PTR_ERR(sgt);
919+
920+
ttm->sg = sgt;
921+
}
922+
923+
drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
924+
ttm->num_pages);
910925
}
926+
911927
if (!ttm->num_pages) {
912928
WARN(1, "nothing to bind %u pages for mreg %p back %p!\n",
913929
ttm->num_pages, bo_mem, ttm);
@@ -1034,8 +1050,15 @@ static void amdgpu_ttm_backend_unbind(struct ttm_device *bdev,
10341050
int r;
10351051

10361052
/* if the pages have userptr pinning then clear that first */
1037-
if (gtt->userptr)
1053+
if (gtt->userptr) {
10381054
amdgpu_ttm_tt_unpin_userptr(bdev, ttm);
1055+
} else if (ttm->sg && gtt->gobj->import_attach) {
1056+
struct dma_buf_attachment *attach;
1057+
1058+
attach = gtt->gobj->import_attach;
1059+
dma_buf_unmap_attachment(attach, ttm->sg, DMA_BIDIRECTIONAL);
1060+
ttm->sg = NULL;
1061+
}
10391062

10401063
if (!gtt->bound)
10411064
return;
@@ -1122,23 +1145,8 @@ static int amdgpu_ttm_tt_populate(struct ttm_device *bdev,
11221145
return 0;
11231146
}
11241147

1125-
if (ttm->page_flags & TTM_PAGE_FLAG_SG) {
1126-
if (!ttm->sg) {
1127-
struct dma_buf_attachment *attach;
1128-
struct sg_table *sgt;
1129-
1130-
attach = gtt->gobj->import_attach;
1131-
sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
1132-
if (IS_ERR(sgt))
1133-
return PTR_ERR(sgt);
1134-
1135-
ttm->sg = sgt;
1136-
}
1137-
1138-
drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
1139-
ttm->num_pages);
1148+
if (ttm->page_flags & TTM_PAGE_FLAG_SG)
11401149
return 0;
1141-
}
11421150

11431151
return ttm_pool_alloc(&adev->mman.bdev.pool, ttm, ctx);
11441152
}
@@ -1162,15 +1170,6 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_device *bdev,
11621170
return;
11631171
}
11641172

1165-
if (ttm->sg && gtt->gobj->import_attach) {
1166-
struct dma_buf_attachment *attach;
1167-
1168-
attach = gtt->gobj->import_attach;
1169-
dma_buf_unmap_attachment(attach, ttm->sg, DMA_BIDIRECTIONAL);
1170-
ttm->sg = NULL;
1171-
return;
1172-
}
1173-
11741173
if (ttm->page_flags & TTM_PAGE_FLAG_SG)
11751174
return;
11761175

0 commit comments

Comments
 (0)