[PATCH 6/8] drm/amdgpu: link all shadow bo

Chunming Zhou David1.Zhou at amd.com
Wed Aug 17 06:05:17 UTC 2016


Change-Id: I8af3b42e1b5d84ca04277f95aeca44cbc534ccb2
Signed-off-by: Chunming Zhou <David1.Zhou at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  5 +++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 14 +++++++++++++-
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index f653291..b6552ed 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -520,6 +520,7 @@ struct amdgpu_bo {
 	struct ttm_bo_kmap_obj		dma_buf_vmap;
 	struct amdgpu_mn		*mn;
 	struct list_head		mn_list;
+	struct list_head		shadow_list;
 };
 #define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
 
@@ -2171,6 +2172,10 @@ struct amdgpu_device {
 	struct kfd_dev          *kfd;
 
 	struct amdgpu_virtualization virtualization;
+
+	/* link all shadow bo */
+	struct list_head                shadow_list;
+	spinlock_t                      shadow_list_lock;
 };
 
 bool amdgpu_device_is_px(struct drm_device *dev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 027dfb3..9247aca 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1588,6 +1588,9 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	spin_lock_init(&adev->gc_cac_idx_lock);
 	spin_lock_init(&adev->audio_endpt_idx_lock);
 
+	INIT_LIST_HEAD(&adev->shadow_list);
+	spin_lock_init(&adev->shadow_list_lock);
+
 	adev->rmmio_base = pci_resource_start(adev->pdev, 5);
 	adev->rmmio_size = pci_resource_len(adev->pdev, 5);
 	adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 3ba0448..5b536a7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -313,6 +313,7 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 	}
 	bo->adev = adev;
 	INIT_LIST_HEAD(&bo->list);
+	INIT_LIST_HEAD(&bo->shadow_list);
 	INIT_LIST_HEAD(&bo->va);
 	bo->prefered_domains = domain & (AMDGPU_GEM_DOMAIN_VRAM |
 					 AMDGPU_GEM_DOMAIN_GTT |
@@ -405,8 +406,12 @@ static int amdgpu_bo_create_shadow(struct amdgpu_device *adev,
 					NULL, &placement,
 					bo->tbo.resv,
 					&bo->shadow);
-	if (!r)
+	if (!r) {
 		bo->shadow->parent = amdgpu_bo_ref(bo);
+		spin_lock(&adev->shadow_list_lock);
+		list_add_tail(&bo->shadow_list, &adev->shadow_list);
+		spin_unlock(&adev->shadow_list_lock);
+	}
 
 	return r;
 }
@@ -541,6 +546,13 @@ void amdgpu_bo_unref(struct amdgpu_bo **bo)
 	if ((*bo) == NULL)
 		return;
 
+	/* shadow must be freed before bo itself */
+	if ((!(*bo)->shadow) && !list_empty(&(*bo)->shadow_list)) {
+		spin_lock(&(*bo)->adev->shadow_list_lock);
+		list_del_init(&(*bo)->shadow_list);
+		spin_unlock(&(*bo)->adev->shadow_list_lock);
+
+	}
 	tbo = &((*bo)->tbo);
 	ttm_bo_unref(&tbo);
 	if (tbo == NULL)
-- 
1.9.1



More information about the amd-gfx mailing list