Skip to contentSkip to conversation

drm/amdgpu: add vcpu_bo cpu address

PATCH In review Leo Liu 3 participants 9 messages May 31, 2017 – Jun 1, 2017 6 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Leo Liu

author
#0 lore raw

PATCH 1/3 drm/amdgpu: add vcpu_bo cpu address

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index 0a7f18c..c93f74a 100644
@@ -33,6 +33,7 @@
 struct amdgpu_vce {
 	struct amdgpu_bo	*vcpu_bo;
 	uint64_t		gpu_addr;
+	void			*cpu_addr;
 	unsigned		fw_version;
 	unsigned		fb_version;
 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#2 lore raw

PATCH 2/3 drm/amdgpu: use existing function amdgpu_bo_create_kernel

To simplify vce bo create

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 27 +++------------------------
 1 file changed, 3 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +3 -24
index 735c38d..b9b0906 100644
@@ -165,35 +165,14 @@ int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size)
 	adev->vce.fw_version = ((version_major << 24) | (version_minor << 16) |
 				(binary_id << 8));
 
-	/* allocate firmware, stack and heap BO */
-
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, true,
-			     AMDGPU_GEM_DOMAIN_VRAM,
-			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-			     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-			     NULL, NULL, &adev->vce.vcpu_bo);
+	r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+				    AMDGPU_GEM_DOMAIN_VRAM, &adev->vce.vcpu_bo,
+				    &adev->vce.gpu_addr, &adev->vce.cpu_addr);
 	if (r) {
 		dev_err(adev->dev, "(%d) failed to allocate VCE bo\n", r);
 		return r;
 	}
 
-	r = amdgpu_bo_reserve(adev->vce.vcpu_bo, false);
-	if (r) {
-		amdgpu_bo_unref(&adev->vce.vcpu_bo);
-		dev_err(adev->dev, "(%d) failed to reserve VCE bo\n", r);
-		return r;
-	}
-
-	r = amdgpu_bo_pin(adev->vce.vcpu_bo, AMDGPU_GEM_DOMAIN_VRAM,
-			  &adev->vce.gpu_addr);
-	amdgpu_bo_unreserve(adev->vce.vcpu_bo);
-	if (r) {
-		amdgpu_bo_unref(&adev->vce.vcpu_bo);
-		dev_err(adev->dev, "(%d) VCE bo pin failed\n", r);
-		return r;
-	}
-
-
 	ring = &adev->vce.ring[0];
 	rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL];
 	r = amd_sched_entity_init(&ring->sched, &adev->vce.entity,
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Re: [PATCH 2/3] drm/amdgpu: use existing function amdgpu_bo_create_kernel

Am 31.05.2017 um 21:28 schrieb Leo Liu:

Quoted 15 lines

To simplify vce bo create

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 27 +++------------------------
  1 file changed, 3 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -0
index 735c38d..b9b0906 100644
@@ -165,35 +165,14 @@ int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size)
  	adev->vce.fw_version = ((version_major << 24) | (version_minor << 16) |
  				(binary_id << 8));
 

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size) · line 170

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +3 -7
-	/* allocate firmware, stack and heap BO */
-
-	r = amdgpu_bo_create(adev, size, PAGE_SIZE, true,
-			     AMDGPU_GEM_DOMAIN_VRAM,
-			     AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-			     AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-			     NULL, NULL, &adev->vce.vcpu_bo);
+	r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+				    AMDGPU_GEM_DOMAIN_VRAM, &adev->vce.vcpu_bo,
+				    &adev->vce.gpu_addr, &adev->vce.cpu_addr);

When you now CPU map the BO you also need to make sure that this mapping is properly destroyed in amdgpu_vce_sw_fini().

In other words use amdgpu_bo_free_kernel() in amdgpu_vce_sw_fini() as well :)

Apart from that the set looks good to me,
Christian.

Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -10
  	if (r) {
  		dev_err(adev->dev, "(%d) failed to allocate VCE bo\n", r);
  		return r;
  	}
 
-	r = amdgpu_bo_reserve(adev->vce.vcpu_bo, false);
-	if (r) {
-		amdgpu_bo_unref(&adev->vce.vcpu_bo);
-		dev_err(adev->dev, "(%d) failed to reserve VCE bo\n", r);
-		return r;
-	}
-
-	r = amdgpu_bo_pin(adev->vce.vcpu_bo, AMDGPU_GEM_DOMAIN_VRAM,
-			  &adev->vce.gpu_addr);
-	amdgpu_bo_unreserve(adev->vce.vcpu_bo);

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size) · line 178

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -7
-	if (r) {
-		amdgpu_bo_unref(&adev->vce.vcpu_bo);
-		dev_err(adev->dev, "(%d) VCE bo pin failed\n", r);
-		return r;
-	}
-
-
  	ring = &adev->vce.ring[0];
  	rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL];
  	r = amd_sched_entity_init(&ring->sched, &adev->vce.entity,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 852ceaa1-a899-40ab-a6a2-fb33001885b0-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

author
#6 lore raw

Re: [PATCH 2/3] drm/amdgpu: use existing function amdgpu_bo_create_kernel

Quoted 31 lines · Christian König

Am 31.05.2017 um 21:28 schrieb Leo Liu:

Quoted 18 lines

To simplify vce bo create

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 27 
+++------------------------
  1 file changed, 3 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -0
index 735c38d..b9b0906 100644
@@ -165,35 +165,14 @@ int amdgpu_vce_sw_init(struct amdgpu_device 
 *adev, unsigned long size)
      adev->vce.fw_version = ((version_major << 24) | (version_minor 

<< 16) |

                  (binary_id << 8));

- /* allocate firmware, stack and heap BO */

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size) · line 170

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +3 -6
-
-    r = amdgpu_bo_create(adev, size, PAGE_SIZE, true,
-                 AMDGPU_GEM_DOMAIN_VRAM,
-                 AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
-                 AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS,
-                 NULL, NULL, &adev->vce.vcpu_bo);
+    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+                    AMDGPU_GEM_DOMAIN_VRAM, &adev->vce.vcpu_bo,
+                    &adev->vce.gpu_addr, &adev->vce.cpu_addr);

When you now CPU map the BO you also need to make sure that this mapping is properly destroyed in amdgpu_vce_sw_fini().

Quoted 1 line

In other words use amdgpu_bo_free_kernel() in amdgpu_vce_sw_fini() as well :)

Thanks for pointing this out. I will add it following your comment.

Thanks,
Leo

Quoted 20 lines

Apart from that the set looks good to me,
Christian.

Quoted 16 lines
      if (r) {
          dev_err(adev->dev, "(%d) failed to allocate VCE bo\n", r);
          return r;
      }

- r = amdgpu_bo_reserve(adev->vce.vcpu_bo, false);

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -11
-    if (r) {
-        amdgpu_bo_unref(&adev->vce.vcpu_bo);
-        dev_err(adev->dev, "(%d) failed to reserve VCE bo\n", r);
-        return r;
-    }
-
-    r = amdgpu_bo_pin(adev->vce.vcpu_bo, AMDGPU_GEM_DOMAIN_VRAM,
-              &adev->vce.gpu_addr);
-    amdgpu_bo_unreserve(adev->vce.vcpu_bo);
-    if (r) {
-        amdgpu_bo_unref(&adev->vce.vcpu_bo);
Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsigned long size) · line 178

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +0 -5
-        dev_err(adev->dev, "(%d) VCE bo pin failed\n", r);
-        return r;
-    }
-
-
      ring = &adev->vce.ring[0];
      rq = &ring->sched.sched_rq[AMD_SCHED_PRIORITY_NORMAL];
      r = amd_sched_entity_init(&ring->sched, &adev->vce.entity,

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#7 lore raw

PATCH 3/3 drm/amdgpu: add saved_bo to save vce 4.0 context when suspend

In reply to a message not in the archive

We are using PSP to resume firmware after suspend, and it is resumed at where it got suspended, so we'd better save the the context.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c   | 39 ++++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index c93f74a..5ce54cd 100644
@@ -34,6 +34,7 @@ struct amdgpu_vce {
 	struct amdgpu_bo	*vcpu_bo;
 	uint64_t		gpu_addr;
 	void			*cpu_addr;
+	void			*saved_bo;
 	unsigned		fw_version;
 	unsigned		fb_version;
 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +34 -5
index 0b7fcc1..2230a99 100644
@@ -522,8 +522,22 @@ static int vce_v4_0_hw_fini(void *handle)
 
 static int vce_v4_0_suspend(void *handle)
 {
-	int r;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int r;
+
+	if (adev->vce.vcpu_bo == NULL)
+		return 0;
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+		void *ptr = adev->vce.cpu_addr;
+
+		adev->vce.saved_bo = kmalloc(size, GFP_KERNEL);
+		if (!adev->vce.saved_bo)
+			return -ENOMEM;
+
+		memcpy_fromio(adev->vce.saved_bo, ptr, size);
+	}
 
 	r = vce_v4_0_hw_fini(adev);
 	if (r)
@@ -534,12 +548,27 @@ static int vce_v4_0_suspend(void *handle)
 
 static int vce_v4_0_resume(void *handle)
 {
-	int r;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int r;
 
-	r = amdgpu_vce_resume(adev);
-	if (r)
-		return r;
+	if (adev->vce.vcpu_bo == NULL)
+		return -EINVAL;
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+		void *ptr = adev->vce.cpu_addr;
+
+		if (adev->vce.saved_bo != NULL) {
+			memcpy_toio(ptr, adev->vce.saved_bo, size);
+			kfree(adev->vce.saved_bo);
+			adev->vce.saved_bo = NULL;
+		} else
+			memset_io(ptr, 0, size);
+	} else {
+		r = amdgpu_vce_resume(adev);
+		if (r)
+			return r;
+	}
 
 	return vce_v4_0_hw_init(adev);
 }
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by Alex Deucher
#9 lore raw

RE: [PATCH 3/3] drm/amdgpu: add saved_bo to save vce 4.0 context when suspend

Quoted 9 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Leo Liu
Sent: Wednesday, May 31, 2017 3:28 PM
To: [email protected]
Cc: Liu, Leo
Subject: [PATCH 3/3] drm/amdgpu: add saved_bo to save vce 4.0 context when suspend

Quoted 5 lines

We are using PSP to resume firmware after suspend, and it is resumed at where it got suspended, so we'd better save the the context.

Patches 1, 2 are:

A few comments below on patch 3.

Quoted 30 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c   | 39
++++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index c93f74a..5ce54cd 100644
@@ -34,6 +34,7 @@ struct amdgpu_vce {
 	struct amdgpu_bo	*vcpu_bo;
 	uint64_t		gpu_addr;
 	void			*cpu_addr;
+	void			*saved_bo;
 	unsigned		fw_version;
 	unsigned		fb_version;
 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +0 -1
index 0b7fcc1..2230a99 100644
@@ -522,8 +522,22 @@ static int vce_v4_0_hw_fini(void *handle)
 
 static int vce_v4_0_suspend(void *handle)
 {
-	int r;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;

drivers/gpu/drm/amd/amdgpu/vce_v4_0.c static int vce_v4_0_hw_fini(void *handle) · line 535

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +10 -0
+	int r;
+
+	if (adev->vce.vcpu_bo == NULL)
+		return 0;
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+		void *ptr = adev->vce.cpu_addr;
+
+		adev->vce.saved_bo = kmalloc(size, GFP_KERNEL);

Might want to avoid malloc/free in the suspend/resume paths. Just malloc/free the memory at sw_init/fini time.

Quoted 21 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +8 -4
+		if (!adev->vce.saved_bo)
+			return -ENOMEM;
+
+		memcpy_fromio(adev->vce.saved_bo, ptr, size);
+	}
 
 	r = vce_v4_0_hw_fini(adev);
 	if (r)
@@ -534,12 +548,27 @@ static int vce_v4_0_suspend(void *handle)
 
 static int vce_v4_0_resume(void *handle)
 {
-	int r;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int r;
 
-	r = amdgpu_vce_resume(adev);
-	if (r)
-		return r;
+	if (adev->vce.vcpu_bo == NULL)
+		return -EINVAL;

drivers/gpu/drm/amd/amdgpu/vce_v4_0.c static int vce_v4_0_suspend(void *handle) · line 565

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +10 -0
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+		void *ptr = adev->vce.cpu_addr;
+
+		if (adev->vce.saved_bo != NULL) {
+			memcpy_toio(ptr, adev->vce.saved_bo, size);
+			kfree(adev->vce.saved_bo);
+			adev->vce.saved_bo = NULL;
+		} else

Kernel coding style; should be } else { ... } to match the chunk above.

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +6 -1
+			memset_io(ptr, 0, size);
+	} else {
+		r = amdgpu_vce_resume(adev);
+		if (r)
+			return r;
+	}
 
 	return vce_v4_0_hw_init(adev);
 }
--

2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): BN6PR12MB1652D083E4A3123CFE3B3628F7F10-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

author
#11 lore raw

Re: [PATCH 3/3] drm/amdgpu: add saved_bo to save vce 4.0 context when suspend

Quoted 46 lines · Alexander
Quoted 9 lines

-----Original Message-----
From: amd-gfx [mailto:amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org] On Behalf Of Leo Liu
Sent: Wednesday, May 31, 2017 3:28 PM
To: [email protected]
Cc: Liu, Leo
Subject: [PATCH 3/3] drm/amdgpu: add saved_bo to save vce 4.0 context
when suspend

Quoted 5 lines

We are using PSP to resume firmware after suspend, and it is resumed at where it got suspended, so we'd better save the the context.

Patches 1, 2 are:

A few comments below on patch 3.

Quoted 26 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c   | 39
++++++++++++++++++++++++++++-----
 2 files changed, 35 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index c93f74a..5ce54cd 100644
@@ -34,6 +34,7 @@ struct amdgpu_vce {
       struct amdgpu_bo        *vcpu_bo;
       uint64_t                gpu_addr;
       void                    *cpu_addr;
+     void                    *saved_bo;
       unsigned                fw_version;
       unsigned                fb_version;
       atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +0 -0
index 0b7fcc1..2230a99 100644
@@ -522,8 +522,22 @@ static int vce_v4_0_hw_fini(void *handle)
 
Quoted 16 lines
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +0 -1
 static int vce_v4_0_suspend(void *handle)
 {
-     int r;
       struct amdgpu_device *adev = (struct amdgpu_device *)handle;

drivers/gpu/drm/amd/amdgpu/vce_v4_0.c static int vce_v4_0_hw_fini(void *handle) · line 535

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +10 -0
+     int r;
+
+     if (adev->vce.vcpu_bo == NULL)
+             return 0;
+
+     if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+             unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+             void *ptr = adev->vce.cpu_addr;
+
+             adev->vce.saved_bo = kmalloc(size, GFP_KERNEL);

Might want to avoid malloc/free in the suspend/resume paths. Just malloc/free the memory at sw_init/fini time.

Just waste a bit memory if it never goes to suspend, but sure, I will fix it in v2.

Thanks,
Leo

Quoted 26 lines
Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +12 -4
+             if (!adev->vce.saved_bo)
+                     return -ENOMEM;
+
+             memcpy_fromio(adev->vce.saved_bo, ptr, size);
+     }
 
       r = vce_v4_0_hw_fini(adev);
       if (r)
@@ -534,12 +548,27 @@ static int vce_v4_0_suspend(void *handle)
 
 static int vce_v4_0_resume(void *handle)
 {
-     int r;
       struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+     int r;
 
-     r = amdgpu_vce_resume(adev);
-     if (r)
-             return r;
+     if (adev->vce.vcpu_bo == NULL)
+             return -EINVAL;
+
+     if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+             unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+             void *ptr = adev->vce.cpu_addr;
Quoted 25 lines

drivers/gpu/drm/amd/amdgpu/vce_v4_0.c static int vce_v4_0_suspend(void *handle) · line 565

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +6 -0
+
+             if (adev->vce.saved_bo != NULL) {
+                     memcpy_toio(ptr, adev->vce.saved_bo, size);
+                     kfree(adev->vce.saved_bo);
+                     adev->vce.saved_bo = NULL;
+             } else

Kernel coding style; should be } else { ... } to match the chunk above.

Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +6 -1
+                     memset_io(ptr, 0, size);
+     } else {
+             r = amdgpu_vce_resume(adev);
+             if (r)
+                     return r;
+     }
 
       return vce_v4_0_hw_init(adev);
 }
--

2.7.4

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#12 lore raw

PATCH 3/3 drm/amdgpu: add saved_bo to save vce 4.0 context when suspend

In reply to a message not in the archive

We are using PSP to resume firmware after suspend, and it is resumed at where it got suspended, so we'd better save the the context.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c   | 45 +++++++++++++++++++++++++++------
 2 files changed, 38 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index f5f35cc..f83e0c3 100644
@@ -34,6 +34,7 @@ struct amdgpu_vce {
 	struct amdgpu_bo	*vcpu_bo;
 	uint64_t		gpu_addr;
 	void			*cpu_addr;
+	void			*saved_bo;
 	unsigned		fw_version;
 	unsigned		fb_version;
 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +37 -8

78 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): [email protected]

Reviewed-by Alex Deucher
#14 lore raw

RE: [PATCH 3/3] drm/amdgpu: add saved_bo to save vce 4.0 context when suspend

Quoted 9 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Leo Liu
Sent: Wednesday, May 31, 2017 5:01 PM
To: [email protected]
Cc: Liu, Leo
Subject: [PATCH 3/3] drm/amdgpu: add saved_bo to save vce 4.0 context when suspend

Quoted 5 lines

We are using PSP to resume firmware after suspend, and it is resumed at where it got suspended, so we'd better save the the context.

Quoted 114 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h |  1 +
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c   | 45
+++++++++++++++++++++++++++------
 2 files changed, 38 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +1 -0
index f5f35cc..f83e0c3 100644
@@ -34,6 +34,7 @@ struct amdgpu_vce {
 	struct amdgpu_bo	*vcpu_bo;
 	uint64_t		gpu_addr;
 	void			*cpu_addr;
+	void			*saved_bo;
 	unsigned		fw_version;
 	unsigned		fb_version;
 	atomic_t		handles[AMDGPU_MAX_VCE_HANDLES];
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +6 -0
index ada2d0a..5229593 100644
@@ -419,15 +419,19 @@ static int vce_v4_0_sw_init(void *handle)
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
 		const struct common_firmware_header *hdr;
+		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+
+		adev->vce.saved_bo = kmalloc(size, GFP_KERNEL);
+		if (!adev->vce.saved_bo)
+			return -ENOMEM;
+
 		hdr = (const struct common_firmware_header *)adev-
 >vce.fw->data;
 		adev-
Quoted 1 line

firmware.ucode[AMDGPU_UCODE_ID_VCE].ucode_id =

AMDGPU_UCODE_ID_VCE;
adev->firmware.ucode[AMDGPU_UCODE_ID_VCE].fw =
adev->vce.fw;

drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +0 -0
 		adev->firmware.fw_size +=
 			ALIGN(le32_to_cpu(hdr->ucode_size_bytes),

PAGE_SIZE);

drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +31 -9
 		DRM_INFO("PSP loading VCE firmware\n");
-	}
-
-	if (adev->firmware.load_type != AMDGPU_FW_LOAD_PSP) {
+	} else {
 		r = amdgpu_vce_resume(adev);
 		if (r)
 			return r;
@@ -466,6 +470,11 @@ static int vce_v4_0_sw_fini(void *handle)
 	/* free MM table */
 	amdgpu_virt_free_mm_table(adev);
 
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		kfree(adev->vce.saved_bo);
+		adev->vce.saved_bo = NULL;
+	}
+
 	r = amdgpu_vce_suspend(adev);
 	if (r)
 		return r;
@@ -522,8 +531,18 @@ static int vce_v4_0_hw_fini(void *handle)
 
 static int vce_v4_0_suspend(void *handle)
 {
-	int r;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int r;
+
+	if (adev->vce.vcpu_bo == NULL)
+		return 0;
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+		void *ptr = adev->vce.cpu_addr;
+
+		memcpy_fromio(adev->vce.saved_bo, ptr, size);
+	}
 
 	r = vce_v4_0_hw_fini(adev);
 	if (r)
@@ -534,12 +553,22 @@ static int vce_v4_0_suspend(void *handle)
 
 static int vce_v4_0_resume(void *handle)
 {
-	int r;
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
+	int r;
 
-	r = amdgpu_vce_resume(adev);
-	if (r)
-		return r;
+	if (adev->vce.vcpu_bo == NULL)
+		return -EINVAL;
+
+	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
+		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
+		void *ptr = adev->vce.cpu_addr;
+
+		memcpy_toio(ptr, adev->vce.saved_bo, size);
+	} else {
+		r = amdgpu_vce_resume(adev);
+		if (r)
+			return r;
+	}
 
 	return vce_v4_0_hw_init(adev);
 }
--

2.7.4

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx