diff options
author | Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com> | 2017-10-06 17:36:35 -0400 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-10-19 15:27:08 -0400 |
commit | e1d515052f9075eb1b791b21467d79db3529db83 (patch) | |
tree | a805ac42a1f8430de2fdcaed9d8c842d4ab63a8a /drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | |
parent | 1eca5a530dc3ac0a2fadd21da1c9e6c729a4a2a1 (diff) |
drm/amdgpu: Add amdgpu_find_mm_node()
Replace some commonly repeated code with a function.
v2: Use amdgpu_find_mm_node() in amdgpu_ttm_io_mem_pfn()
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 382c0ae0561e..51eacefadea1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | |||
@@ -291,7 +291,24 @@ static uint64_t amdgpu_mm_node_addr(struct ttm_buffer_object *bo, | |||
291 | } | 291 | } |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * amdgpu_ttm_copy_mem_to_mem - Helper function for copy | 294 | * amdgpu_find_mm_node - Helper function finds the drm_mm_node |
295 | * corresponding to @offset. It also modifies the offset to be | ||
296 | * within the drm_mm_node returned | ||
297 | */ | ||
298 | static struct drm_mm_node *amdgpu_find_mm_node(struct ttm_mem_reg *mem, | ||
299 | unsigned long *offset) | ||
300 | { | ||
301 | struct drm_mm_node *mm_node = mem->mm_node; | ||
302 | |||
303 | while (*offset >= (mm_node->size << PAGE_SHIFT)) { | ||
304 | *offset -= (mm_node->size << PAGE_SHIFT); | ||
305 | ++mm_node; | ||
306 | } | ||
307 | return mm_node; | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * amdgpu_copy_ttm_mem_to_mem - Helper function for copy | ||
295 | * | 312 | * |
296 | * The function copies @size bytes from {src->mem + src->offset} to | 313 | * The function copies @size bytes from {src->mem + src->offset} to |
297 | * {dst->mem + dst->offset}. src->bo and dst->bo could be same BO for a | 314 | * {dst->mem + dst->offset}. src->bo and dst->bo could be same BO for a |
@@ -320,21 +337,13 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, | |||
320 | return -EINVAL; | 337 | return -EINVAL; |
321 | } | 338 | } |
322 | 339 | ||
323 | src_mm = src->mem->mm_node; | 340 | src_mm = amdgpu_find_mm_node(src->mem, &src->offset); |
324 | while (src->offset >= (src_mm->size << PAGE_SHIFT)) { | ||
325 | src->offset -= (src_mm->size << PAGE_SHIFT); | ||
326 | ++src_mm; | ||
327 | } | ||
328 | src_node_start = amdgpu_mm_node_addr(src->bo, src_mm, src->mem) + | 341 | src_node_start = amdgpu_mm_node_addr(src->bo, src_mm, src->mem) + |
329 | src->offset; | 342 | src->offset; |
330 | src_node_size = (src_mm->size << PAGE_SHIFT) - src->offset; | 343 | src_node_size = (src_mm->size << PAGE_SHIFT) - src->offset; |
331 | src_page_offset = src_node_start & (PAGE_SIZE - 1); | 344 | src_page_offset = src_node_start & (PAGE_SIZE - 1); |
332 | 345 | ||
333 | dst_mm = dst->mem->mm_node; | 346 | dst_mm = amdgpu_find_mm_node(dst->mem, &dst->offset); |
334 | while (dst->offset >= (dst_mm->size << PAGE_SHIFT)) { | ||
335 | dst->offset -= (dst_mm->size << PAGE_SHIFT); | ||
336 | ++dst_mm; | ||
337 | } | ||
338 | dst_node_start = amdgpu_mm_node_addr(dst->bo, dst_mm, dst->mem) + | 347 | dst_node_start = amdgpu_mm_node_addr(dst->bo, dst_mm, dst->mem) + |
339 | dst->offset; | 348 | dst->offset; |
340 | dst_node_size = (dst_mm->size << PAGE_SHIFT) - dst->offset; | 349 | dst_node_size = (dst_mm->size << PAGE_SHIFT) - dst->offset; |
@@ -654,13 +663,12 @@ static void amdgpu_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_re | |||
654 | static unsigned long amdgpu_ttm_io_mem_pfn(struct ttm_buffer_object *bo, | 663 | static unsigned long amdgpu_ttm_io_mem_pfn(struct ttm_buffer_object *bo, |
655 | unsigned long page_offset) | 664 | unsigned long page_offset) |
656 | { | 665 | { |
657 | struct drm_mm_node *mm = bo->mem.mm_node; | 666 | struct drm_mm_node *mm; |
658 | uint64_t size = mm->size; | 667 | unsigned long offset = (page_offset << PAGE_SHIFT); |
659 | uint64_t offset = page_offset; | ||
660 | 668 | ||
661 | page_offset = do_div(offset, size); | 669 | mm = amdgpu_find_mm_node(&bo->mem, &offset); |
662 | mm += offset; | 670 | return (bo->mem.bus.base >> PAGE_SHIFT) + mm->start + |
663 | return (bo->mem.bus.base >> PAGE_SHIFT) + mm->start + page_offset; | 671 | (offset >> PAGE_SHIFT); |
664 | } | 672 | } |
665 | 673 | ||
666 | /* | 674 | /* |
@@ -1216,7 +1224,7 @@ static int amdgpu_ttm_access_memory(struct ttm_buffer_object *bo, | |||
1216 | { | 1224 | { |
1217 | struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo); | 1225 | struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo); |
1218 | struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev); | 1226 | struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev); |
1219 | struct drm_mm_node *nodes = abo->tbo.mem.mm_node; | 1227 | struct drm_mm_node *nodes; |
1220 | uint32_t value = 0; | 1228 | uint32_t value = 0; |
1221 | int ret = 0; | 1229 | int ret = 0; |
1222 | uint64_t pos; | 1230 | uint64_t pos; |
@@ -1225,10 +1233,7 @@ static int amdgpu_ttm_access_memory(struct ttm_buffer_object *bo, | |||
1225 | if (bo->mem.mem_type != TTM_PL_VRAM) | 1233 | if (bo->mem.mem_type != TTM_PL_VRAM) |
1226 | return -EIO; | 1234 | return -EIO; |
1227 | 1235 | ||
1228 | while (offset >= (nodes->size << PAGE_SHIFT)) { | 1236 | nodes = amdgpu_find_mm_node(&abo->tbo.mem, &offset); |
1229 | offset -= nodes->size << PAGE_SHIFT; | ||
1230 | ++nodes; | ||
1231 | } | ||
1232 | pos = (nodes->start << PAGE_SHIFT) + offset; | 1237 | pos = (nodes->start << PAGE_SHIFT) + offset; |
1233 | 1238 | ||
1234 | while (len && pos < adev->mc.mc_vram_size) { | 1239 | while (len && pos < adev->mc.mc_vram_size) { |