aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian König <christian.koenig@amd.com>2017-06-30 04:41:07 -0400
committerAlex Deucher <alexander.deucher@amd.com>2017-07-14 11:05:59 -0400
commit98a7f88ce9a9ed26cea939558f33e3d483cfb4f0 (patch)
tree9a7b8c40e96b9e8ec7128cc66b2f369f30c39bfe
parent92c60d9cf6636fdf740ebc98af0d68426f07b19b (diff)
drm/amdgpu: bind BOs with GTT space allocated directly v2
This avoids binding them later on. v2: fix typo in function name Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Acked-by: Felix Kuehling <Felix.Kuehling@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c16
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c49
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h1
3 files changed, 46 insertions, 20 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index f7d22c44034d..1ef625550442 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -81,6 +81,20 @@ static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
81} 81}
82 82
83/** 83/**
84 * amdgpu_gtt_mgr_is_allocated - Check if mem has address space
85 *
86 * @mem: the mem object to check
87 *
88 * Check if a mem object has already address space allocated.
89 */
90bool amdgpu_gtt_mgr_is_allocated(struct ttm_mem_reg *mem)
91{
92 struct drm_mm_node *node = mem->mm_node;
93
94 return (node->start != AMDGPU_BO_INVALID_OFFSET);
95}
96
97/**
84 * amdgpu_gtt_mgr_alloc - allocate new ranges 98 * amdgpu_gtt_mgr_alloc - allocate new ranges
85 * 99 *
86 * @man: TTM memory type manager 100 * @man: TTM memory type manager
@@ -101,7 +115,7 @@ int amdgpu_gtt_mgr_alloc(struct ttm_mem_type_manager *man,
101 unsigned long fpfn, lpfn; 115 unsigned long fpfn, lpfn;
102 int r; 116 int r;
103 117
104 if (node->start != AMDGPU_BO_INVALID_OFFSET) 118 if (amdgpu_gtt_mgr_is_allocated(mem))
105 return 0; 119 return 0;
106 120
107 if (place) 121 if (place)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index e97dfe888d55..7064d31f0be5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -681,6 +681,31 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
681 sg_free_table(ttm->sg); 681 sg_free_table(ttm->sg);
682} 682}
683 683
684static int amdgpu_ttm_do_bind(struct ttm_tt *ttm, struct ttm_mem_reg *mem)
685{
686 struct amdgpu_ttm_tt *gtt = (void *)ttm;
687 uint64_t flags;
688 int r;
689
690 spin_lock(&gtt->adev->gtt_list_lock);
691 flags = amdgpu_ttm_tt_pte_flags(gtt->adev, ttm, mem);
692 gtt->offset = (u64)mem->start << PAGE_SHIFT;
693 r = amdgpu_gart_bind(gtt->adev, gtt->offset, ttm->num_pages,
694 ttm->pages, gtt->ttm.dma_address, flags);
695
696 if (r) {
697 DRM_ERROR("failed to bind %lu pages at 0x%08llX\n",
698 ttm->num_pages, gtt->offset);
699 goto error_gart_bind;
700 }
701
702 list_add_tail(&gtt->list, &gtt->adev->gtt_list);
703error_gart_bind:
704 spin_unlock(&gtt->adev->gtt_list_lock);
705 return r;
706
707}
708
684static int amdgpu_ttm_backend_bind(struct ttm_tt *ttm, 709static int amdgpu_ttm_backend_bind(struct ttm_tt *ttm,
685 struct ttm_mem_reg *bo_mem) 710 struct ttm_mem_reg *bo_mem)
686{ 711{
@@ -704,7 +729,10 @@ static int amdgpu_ttm_backend_bind(struct ttm_tt *ttm,
704 bo_mem->mem_type == AMDGPU_PL_OA) 729 bo_mem->mem_type == AMDGPU_PL_OA)
705 return -EINVAL; 730 return -EINVAL;
706 731
707 return 0; 732 if (amdgpu_gtt_mgr_is_allocated(bo_mem))
733 r = amdgpu_ttm_do_bind(ttm, bo_mem);
734
735 return r;
708} 736}
709 737
710bool amdgpu_ttm_is_bound(struct ttm_tt *ttm) 738bool amdgpu_ttm_is_bound(struct ttm_tt *ttm)
@@ -717,8 +745,6 @@ bool amdgpu_ttm_is_bound(struct ttm_tt *ttm)
717int amdgpu_ttm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *bo_mem) 745int amdgpu_ttm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *bo_mem)
718{ 746{
719 struct ttm_tt *ttm = bo->ttm; 747 struct ttm_tt *ttm = bo->ttm;
720 struct amdgpu_ttm_tt *gtt = (void *)bo->ttm;
721 uint64_t flags;
722 int r; 748 int r;
723 749
724 if (!ttm || amdgpu_ttm_is_bound(ttm)) 750 if (!ttm || amdgpu_ttm_is_bound(ttm))
@@ -731,22 +757,7 @@ int amdgpu_ttm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *bo_mem)
731 return r; 757 return r;
732 } 758 }
733 759
734 spin_lock(&gtt->adev->gtt_list_lock); 760 return amdgpu_ttm_do_bind(ttm, bo_mem);
735 flags = amdgpu_ttm_tt_pte_flags(gtt->adev, ttm, bo_mem);
736 gtt->offset = (u64)bo_mem->start << PAGE_SHIFT;
737 r = amdgpu_gart_bind(gtt->adev, gtt->offset, ttm->num_pages,
738 ttm->pages, gtt->ttm.dma_address, flags);
739
740 if (r) {
741 DRM_ERROR("failed to bind %lu pages at 0x%08llX\n",
742 ttm->num_pages, gtt->offset);
743 goto error_gart_bind;
744 }
745
746 list_add_tail(&gtt->list, &gtt->adev->gtt_list);
747error_gart_bind:
748 spin_unlock(&gtt->adev->gtt_list_lock);
749 return r;
750} 761}
751 762
752int amdgpu_ttm_recover_gart(struct amdgpu_device *adev) 763int amdgpu_ttm_recover_gart(struct amdgpu_device *adev)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index cd5bbfa2773f..776a20ae40c4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -56,6 +56,7 @@ struct amdgpu_mman {
56extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func; 56extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
57extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func; 57extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
58 58
59bool amdgpu_gtt_mgr_is_allocated(struct ttm_mem_reg *mem);
59int amdgpu_gtt_mgr_alloc(struct ttm_mem_type_manager *man, 60int amdgpu_gtt_mgr_alloc(struct ttm_mem_type_manager *man,
60 struct ttm_buffer_object *tbo, 61 struct ttm_buffer_object *tbo,
61 const struct ttm_place *place, 62 const struct ttm_place *place,