Skip to contentSkip to conversation

drm/amdgpu: Refine function amdgpu_csa_vaddr

PATCH In review Rex Zhu 3 participants 19 messages Dec 6, 2018 11 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Rex Zhu

author
#0 lore raw

PATCH 2/9 drm/amdgpu: Refine function amdgpu_csa_vaddr

on baremetal, driver create csa per ctx. So add a function argument: ctx_id to get csa gpu addr.
In Sriov, driver create csa per process, so ctx id always 1.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c | 5 +++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 6 +++---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 4 ++--
 5 files changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +3 -2
index 0c590dd..44b046f 100644
@@ -24,11 +24,12 @@
 
 #include "amdgpu.h"
 
-uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
+uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id)
 {
 	uint64_t addr = adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT;
 
-	addr -= AMDGPU_VA_RESERVED_SIZE;
+	addr -= AMDGPU_VA_RESERVED_SIZE * id;
+
 	addr = amdgpu_gmc_sign_extend(addr);
 
 	return addr;
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h +1 -1
index 524b443..aaf1fba 100644
@@ -28,7 +28,7 @@
 #define AMDGPU_CSA_SIZE		(128 * 1024)
 
 uint32_t amdgpu_get_total_csa_size(struct amdgpu_device *adev);
-uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev);
+uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id);
 int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo **bo,
 				u32 domain, uint32_t size);
 int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -2
index 08d04f6..f736bda 100644
@@ -977,9 +977,9 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 		goto error_vm;
 	}
 
-	if (amdgpu_sriov_vf(adev)) {
-		uint64_t csa_addr = amdgpu_csa_vaddr(adev) & AMDGPU_GMC_HOLE_MASK;
 
+	if (amdgpu_sriov_vf(adev)) {
+		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
 		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
 						&fpriv->csa_va, csa_addr, AMDGPU_CSA_SIZE);
 		if (r)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +3 -3
index bdae563..d529cef 100644
@@ -7192,11 +7192,11 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
 	} ce_payload = {};
 
 	if (ring->adev->virt.chained_ib_support) {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
+		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
 			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
 		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
 	} else {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
+		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
 			offsetof(struct vi_gfx_meta_data, ce_payload);
 		cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
 	}
@@ -7220,7 +7220,7 @@ static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
 		struct vi_de_ib_state_chained_ib chained;
 	} de_payload = {};
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev);
+	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
 	gds_addr = csa_addr + 4096;
 	if (ring->adev->virt.chained_ib_support) {
 		de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -2
index 928034c..81c1578 100644
@@ -4327,7 +4327,7 @@ static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
 	int cnt;
 
 	cnt = (sizeof(ce_payload) >> 2) + 4 - 2;
-	csa_addr = amdgpu_csa_vaddr(ring->adev);
+	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
 
 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt));
 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |
@@ -4345,7 +4345,7 @@ static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring)
 	uint64_t csa_addr, gds_addr;
 	int cnt;
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev);
+	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
 	gds_addr = csa_addr + 4096;
 	de_payload.gds_backup_addrlo = lower_32_bits(gds_addr);
 	de_payload.gds_backup_addrhi = upper_32_bits(gds_addr);
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-1-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 3/9 drm/amdgpu: Use dynamical reserved vm size

Use dynamical reserved vm size instand of hardcode.

driver always reserve AMDGPU_VA_RESERVED_SIZE at the bottom of VM space.

for gfx/sdma mcbp feature,
reserve AMDGPU_VA_RESERVED_SIZ * AMDGPU_VM_MAX_NUM_CTX at the top of VM space.
For sriov, only need to reserve AMDGPU_VA_RESERVED_SIZE at the top.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c |  8 ++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 10 ++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  3 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   |  2 +-
 9 files changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +8 -0
index 44b046f..caa71c7 100644
@@ -24,6 +24,14 @@
 
 #include "amdgpu.h"
 
+uint64_t amdgpu_get_reserved_csa_size(struct amdgpu_device *adev)
+{
+	if (amdgpu_sriov_vf(adev))
+		return AMDGPU_VA_RESERVED_SIZE;
+	else
+		return AMDGPU_VA_RESERVED_SIZE * AMDGPU_VM_MAX_NUM_CTX;
+}
+
 uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id)
 {
 	uint64_t addr = adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT;
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h +1 -0
index aaf1fba..7159d6d 100644
@@ -27,6 +27,7 @@
 
 #define AMDGPU_CSA_SIZE		(128 * 1024)
 
+uint64_t amdgpu_get_reserved_csa_size(struct amdgpu_device *adev);
 uint32_t amdgpu_get_total_csa_size(struct amdgpu_device *adev);
 uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id);
 int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo **bo,
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10 -0
index 7b3d1eb..4c12de8 100644
@@ -557,6 +557,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 	struct ww_acquire_ctx ticket;
 	struct list_head list, duplicates;
 	uint64_t va_flags;
+	uint64_t va_reserved, va_top;
 	int r = 0;
 
 	if (args->va_address < AMDGPU_VA_RESERVED_SIZE) {
@@ -565,6 +566,15 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
 			args->va_address, AMDGPU_VA_RESERVED_SIZE);
 		return -EINVAL;
 	}
+	va_top = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+	va_reserved = va_top - adev->vm_manager.reserved_vm_size;
+
+	if (args->va_address > va_reserved && args->va_address < va_top) {
+		dev_dbg(&dev->pdev->dev,
+			"va_address 0x%LX is in reserved area 0x%LX\n",
+			args->va_address, adev->vm_manager.reserved_vm_size);
+		return -EINVAL;
+	}
 
 	if (args->va_address >= AMDGPU_GMC_HOLE_START &&
 	    args->va_address < AMDGPU_GMC_HOLE_END) {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -2
index f736bda..52e4e90 100644
@@ -702,7 +702,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
 
 		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-		vm_size -= AMDGPU_VA_RESERVED_SIZE;
+		vm_size -= adev->vm_manager.reserved_vm_size;
 
 		/* Older VCE FW versions are buggy and can handle only 40bits */
 		if (adev->vce.fw_version &&
@@ -977,7 +977,6 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 		goto error_vm;
 	}
 
-
 	if (amdgpu_sriov_vf(adev)) {
 		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
 		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
index 352b304..2f2b9f4 100644
@@ -2901,6 +2901,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
 	}
 
 	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
+	adev->vm_manager.reserved_vm_size = amdgpu_get_reserved_csa_size(adev);
 
 	tmp = roundup_pow_of_two(adev->vm_manager.max_pfn);
 	if (amdgpu_vm_block_size != -1)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
index 2a8898d..ec650ac 100644
@@ -260,6 +260,7 @@ struct amdgpu_vm_manager {
 	unsigned				seqno[AMDGPU_MAX_RINGS];
 
 	uint64_t				max_pfn;
+	uint64_t				reserved_vm_size;
 	uint32_t				num_level;
 	uint32_t				block_size;
 	uint32_t				fragment_size;
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +1 -1
index 2821d1d..3351b56 100644
@@ -471,7 +471,7 @@ static void gmc_v6_0_set_prt(struct amdgpu_device *adev, bool enable)
 	if (enable) {
 		uint32_t low = AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT;
 		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT);
+				(adev->vm_manager.reserved_vm_size >> AMDGPU_GPU_PAGE_SHIFT);
 
 		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
 		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low);
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +1 -1
index 761dcfb..92bd175 100644
@@ -568,7 +568,7 @@ static void gmc_v7_0_set_prt(struct amdgpu_device *adev, bool enable)
 	if (enable) {
 		uint32_t low = AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT;
 		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT);
+				(adev->vm_manager.reserved_vm_size >> AMDGPU_GPU_PAGE_SHIFT);
 
 		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
 		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
index 531aaf3..d909ddf 100644
@@ -772,7 +772,7 @@ static void gmc_v8_0_set_prt(struct amdgpu_device *adev, bool enable)
 	if (enable) {
 		uint32_t low = AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT;
 		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT);
+				(adev->vm_manager.reserved_vm_size >> AMDGPU_GPU_PAGE_SHIFT);
 
 		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
 		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low);
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-2-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 3/9] drm/amdgpu: Use dynamical reserved vm size

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 29 lines

Use dynamical reserved vm size instand of hardcode.

driver always reserve AMDGPU_VA_RESERVED_SIZE at the bottom of VM space.

for gfx/sdma mcbp feature,
reserve AMDGPU_VA_RESERVED_SIZ * AMDGPU_VM_MAX_NUM_CTX at the top of VM space.
For sriov, only need to reserve AMDGPU_VA_RESERVED_SIZE at the top.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c |  8 ++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 10 ++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  3 +--
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   |  2 +-
  9 files changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +0 -0
index 44b046f..caa71c7 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c line 32

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +6 -0
@@ -24,6 +24,14 @@
 
  #include "amdgpu.h"
 
+uint64_t amdgpu_get_reserved_csa_size(struct amdgpu_device *adev)
+{
+	if (amdgpu_sriov_vf(adev))
+		return AMDGPU_VA_RESERVED_SIZE;
+	else
+		return AMDGPU_VA_RESERVED_SIZE * AMDGPU_VM_MAX_NUM_CTX;

Do we really want AMDGPU_VA_RESERVED_SIZE * AMDGPU_VM_MAX_NUM_CTX here?

AMDGPU_CSA_SIZE * AMDGPU_VM_MAX_NUM_CTX should be sufficient I think.

And we should name the function to amdgpu_csa_get_reserved_vm_space().

Quoted 71 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +2 -0
+}
+
  uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id)
  {
  	uint64_t addr = adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT;
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h +1 -0
index aaf1fba..7159d6d 100644
@@ -27,6 +27,7 @@
 
  #define AMDGPU_CSA_SIZE		(128 * 1024)
 
+uint64_t amdgpu_get_reserved_csa_size(struct amdgpu_device *adev);
  uint32_t amdgpu_get_total_csa_size(struct amdgpu_device *adev);
  uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id);
  int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo **bo,
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +10 -0
index 7b3d1eb..4c12de8 100644
@@ -557,6 +557,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
  	struct ww_acquire_ctx ticket;
  	struct list_head list, duplicates;
  	uint64_t va_flags;
+	uint64_t va_reserved, va_top;
  	int r = 0;
 
  	if (args->va_address < AMDGPU_VA_RESERVED_SIZE) {
@@ -565,6 +566,15 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
  			args->va_address, AMDGPU_VA_RESERVED_SIZE);
  		return -EINVAL;
  	}
+	va_top = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+	va_reserved = va_top - adev->vm_manager.reserved_vm_size;
+
+	if (args->va_address > va_reserved && args->va_address < va_top) {
+		dev_dbg(&dev->pdev->dev,
+			"va_address 0x%LX is in reserved area 0x%LX\n",
+			args->va_address, adev->vm_manager.reserved_vm_size);
+		return -EINVAL;
+	}
 
  	if (args->va_address >= AMDGPU_GMC_HOLE_START &&
  	    args->va_address < AMDGPU_GMC_HOLE_END) {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -2
index f736bda..52e4e90 100644
@@ -702,7 +702,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
  			dev_info.ids_flags |= AMDGPU_IDS_FLAGS_PREEMPTION;
 
  		vm_size = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
-		vm_size -= AMDGPU_VA_RESERVED_SIZE;
+		vm_size -= adev->vm_manager.reserved_vm_size;
 
  		/* Older VCE FW versions are buggy and can handle only 40bits */
  		if (adev->vce.fw_version &&
@@ -977,7 +977,6 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  		goto error_vm;
  	}
 
-
  	if (amdgpu_sriov_vf(adev)) {
  		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
  		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 352b304..2f2b9f4 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size, · line 2904

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
@@ -2901,6 +2901,7 @@ void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
  	}
 
  	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
+	adev->vm_manager.reserved_vm_size = amdgpu_get_reserved_csa_size(adev);

Maybe calculate that directly as max_pfn - reserved and name it something like max_user_pfn.

Regards,
Christian.

Quoted 46 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
  	tmp = roundup_pow_of_two(adev->vm_manager.max_pfn);
  	if (amdgpu_vm_block_size != -1)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
index 2a8898d..ec650ac 100644
@@ -260,6 +260,7 @@ struct amdgpu_vm_manager {
  	unsigned				seqno[AMDGPU_MAX_RINGS];
 
  	uint64_t				max_pfn;
+	uint64_t				reserved_vm_size;
  	uint32_t				num_level;
  	uint32_t				block_size;
  	uint32_t				fragment_size;
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +1 -1
index 2821d1d..3351b56 100644
@@ -471,7 +471,7 @@ static void gmc_v6_0_set_prt(struct amdgpu_device *adev, bool enable)
  	if (enable) {
  		uint32_t low = AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT;
  		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT);
+				(adev->vm_manager.reserved_vm_size >> AMDGPU_GPU_PAGE_SHIFT);
 
  		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
  		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low);
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +1 -1
index 761dcfb..92bd175 100644
@@ -568,7 +568,7 @@ static void gmc_v7_0_set_prt(struct amdgpu_device *adev, bool enable)
  	if (enable) {
  		uint32_t low = AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT;
  		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT);
+				(adev->vm_manager.reserved_vm_size >> AMDGPU_GPU_PAGE_SHIFT);
 
  		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
  		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
index 531aaf3..d909ddf 100644

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static void gmc_v8_0_set_prt(struct amdgpu_device *adev, bool enable) · line 778

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -1
@@ -772,7 +772,7 @@ static void gmc_v8_0_set_prt(struct amdgpu_device *adev, bool enable)
  	if (enable) {
  		uint32_t low = AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT;
  		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >> AMDGPU_GPU_PAGE_SHIFT);
+				(adev->vm_manager.reserved_vm_size >> AMDGPU_GPU_PAGE_SHIFT);
 
  		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
  		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low);

_______________________________________________
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): ca2a8aaa-3a0b-8c8e-1d5a-ec2e12c70434-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

author
#6 lore raw

RE: [PATCH 3/9] drm/amdgpu: Use dynamical reserved vm size

Quoted 49 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, December 6, 2018 8:33 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH 3/9] drm/amdgpu: Use dynamical reserved vm size

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 7 lines

Use dynamical reserved vm size instand of hardcode.

driver always reserve AMDGPU_VA_RESERVED_SIZE at the bottom of VM space.

for gfx/sdma mcbp feature,
reserve AMDGPU_VA_RESERVED_SIZ * AMDGPU_VM_MAX_NUM_CTX at

the top of

Quoted 22 lines

VM space.
For sriov, only need to reserve AMDGPU_VA_RESERVED_SIZE at the top.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c |  8 ++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 10 ++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  3 +--
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c  |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h  |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   |  2 +-
  9 files changed, 25 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +0 -0
index 44b046f..caa71c7 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c line 31

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +5 -0
@@ -24,6 +24,14 @@
 
  #include "amdgpu.h"
 
+uint64_t amdgpu_get_reserved_csa_size(struct amdgpu_device *adev) {
+	if (amdgpu_sriov_vf(adev))
+		return AMDGPU_VA_RESERVED_SIZE;
+	else
+		return AMDGPU_VA_RESERVED_SIZE *

AMDGPU_VM_MAX_NUM_CTX;

Quoted 5 lines

Do we really want AMDGPU_VA_RESERVED_SIZE *
AMDGPU_VM_MAX_NUM_CTX here?

AMDGPU_CSA_SIZE * AMDGPU_VM_MAX_NUM_CTX should be sufficient I think.

Yes, You are right. I will fix this error.
Thanks.

Quoted 90 lines

And we should name the function to amdgpu_csa_get_reserved_vm_space().

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

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +2 -0
+}
+
  uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id)
  {
  	uint64_t addr = adev->vm_manager.max_pfn <<

AMDGPU_GPU_PAGE_SHIFT;

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h +1 -0
index aaf1fba..7159d6d 100644
@@ -27,6 +27,7 @@
 
  #define AMDGPU_CSA_SIZE		(128 * 1024)
 
+uint64_t amdgpu_get_reserved_csa_size(struct amdgpu_device *adev);
  uint32_t amdgpu_get_total_csa_size(struct amdgpu_device *adev);
  uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id);
  int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct
Quoted 1 line

amdgpu_bo **bo, diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev,

Quoted 5 lines

b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 7b3d1eb..4c12de8 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +0 -0
@@ -557,6 +557,7 @@ int amdgpu_gem_va_ioctl(struct drm_device *dev,

void *data,

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +1 -0
  	struct ww_acquire_ctx ticket;
  	struct list_head list, duplicates;
  	uint64_t va_flags;
+	uint64_t va_reserved, va_top;
  	int r = 0;
 
  	if (args->va_address < AMDGPU_VA_RESERVED_SIZE) { @@ -565,6

+566,15

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c static int amdgpu_info_ioctl(struct drm_device

Quoted 23 lines

@@ int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
args->va_address, AMDGPU_VA_RESERVED_SIZE);
return -EINVAL;
}

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +7 -0
+	va_top = adev->vm_manager.max_pfn * AMDGPU_GPU_PAGE_SIZE;
+	va_reserved = va_top - adev->vm_manager.reserved_vm_size;
+
+	if (args->va_address > va_reserved && args->va_address < va_top) {
+		dev_dbg(&dev->pdev->dev,
+			"va_address 0x%LX is in reserved area 0x%LX\n",
+			args->va_address, adev-

vm_manager.reserved_vm_size);

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c +2 -0
+		return -EINVAL;
+	}
 
  	if (args->va_address >= AMDGPU_GMC_HOLE_START &&
  	    args->va_address < AMDGPU_GMC_HOLE_END) { diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index f736bda..52e4e90 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -702,7 +702,7 @@ static int amdgpu_info_ioctl(struct drm_device

*dev, void *data, struct drm_file

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c static int amdgpu_info_ioctl(struct drm_device · line 702

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
  			dev_info.ids_flags |=

AMDGPU_IDS_FLAGS_PREEMPTION;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c static int amdgpu_info_ioctl(struct drm_device · line 703

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
  		vm_size = adev->vm_manager.max_pfn *

AMDGPU_GPU_PAGE_SIZE;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
-		vm_size -= AMDGPU_VA_RESERVED_SIZE;
+		vm_size -= adev->vm_manager.reserved_vm_size;
 
  		/* Older VCE FW versions are buggy and can handle only

40bits */

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
  		if (adev->vce.fw_version &&
@@ -977,7 +977,6 @@ int amdgpu_driver_open_kms(struct drm_device

*dev, struct drm_file *file_priv)

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -1
  		goto error_vm;
  	}
 
-
  	if (amdgpu_sriov_vf(adev)) {
  		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) &

AMDGPU_GMC_HOLE_MASK;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_adjust_size(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
  		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev-

virt.csa_obj,

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 352b304..2f2b9f4 100644
@@ -2901,6 +2901,7 @@ void amdgpu_vm_adjust_size(struct

amdgpu_device *adev, uint32_t min_vm_size,

Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -0
  	}
 
  	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
+	adev->vm_manager.reserved_vm_size =
+amdgpu_get_reserved_csa_size(adev);

Maybe calculate that directly as max_pfn - reserved and name it something like max_user_pfn.

Good suggestion.
Thanks

Regards
Rex

Quoted 65 lines

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_vm_manager { · line 260

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
  	tmp = roundup_pow_of_two(adev->vm_manager.max_pfn);
  	if (amdgpu_vm_block_size != -1)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 2a8898d..ec650ac 100644
@@ -260,6 +260,7 @@ struct amdgpu_vm_manager {
  	unsigned
	seqno[AMDGPU_MAX_RINGS];

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c static void gmc_v6_0_set_prt(struct

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
  	uint64_t				max_pfn;
+	uint64_t				reserved_vm_size;
  	uint32_t				num_level;
  	uint32_t				block_size;
  	uint32_t				fragment_size;
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +0 -0
index 2821d1d..3351b56 100644
@@ -471,7 +471,7 @@ static void gmc_v6_0_set_prt(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c static void gmc_v6_0_set_prt(struct · line 472

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +0 -0
  	if (enable) {
  		uint32_t low = AMDGPU_VA_RESERVED_SIZE >>

AMDGPU_GPU_PAGE_SHIFT;

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c static void gmc_v6_0_set_prt(struct · line 474

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +0 -1
  		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >>

AMDGPU_GPU_PAGE_SHIFT);

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c static void gmc_v6_0_set_prt(struct · line 474

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +1 -0
+				(adev->vm_manager.reserved_vm_size >>

AMDGPU_GPU_PAGE_SHIFT);

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c static void gmc_v6_0_set_prt(struct · line 476

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +0 -0
  		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
  		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low); diff --

git

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static void gmc_v7_0_set_prt(struct

Quoted 6 lines

a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index 761dcfb..92bd175 100644

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
@@ -568,7 +568,7 @@ static void gmc_v7_0_set_prt(struct

amdgpu_device *adev, bool enable)

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static void gmc_v7_0_set_prt(struct · line 569

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
  	if (enable) {
  		uint32_t low = AMDGPU_VA_RESERVED_SIZE >>

AMDGPU_GPU_PAGE_SHIFT;

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static void gmc_v7_0_set_prt(struct · line 571

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -1
  		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >>

AMDGPU_GPU_PAGE_SHIFT);

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static void gmc_v7_0_set_prt(struct · line 571

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +1 -0
+				(adev->vm_manager.reserved_vm_size >>

AMDGPU_GPU_PAGE_SHIFT);

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c static void gmc_v7_0_set_prt(struct · line 573

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +0 -0
  		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
  		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low); diff --

git

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static void gmc_v8_0_set_prt(struct

Quoted 6 lines

a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index 531aaf3..d909ddf 100644

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
@@ -772,7 +772,7 @@ static void gmc_v8_0_set_prt(struct

amdgpu_device *adev, bool enable)

Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static void gmc_v8_0_set_prt(struct · line 773

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
  	if (enable) {
  		uint32_t low = AMDGPU_VA_RESERVED_SIZE >>

AMDGPU_GPU_PAGE_SHIFT;

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static void gmc_v8_0_set_prt(struct · line 775

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -1
  		uint32_t high = adev->vm_manager.max_pfn -
-			(AMDGPU_VA_RESERVED_SIZE >>

AMDGPU_GPU_PAGE_SHIFT);

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static void gmc_v8_0_set_prt(struct · line 775

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -0
+				(adev->vm_manager.reserved_vm_size >>

AMDGPU_GPU_PAGE_SHIFT);

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0 -0
  		WREG32(mmVM_PRT_APERTURE0_LOW_ADDR, low);
  		WREG32(mmVM_PRT_APERTURE1_LOW_ADDR, low);

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

author
#7 lore raw

PATCH 4/9 drm/amdgpu: Add a bitmask in amdgpu_ctx_mgr

In reply to a message not in the archive

used to manager the reserverd vm space.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 ++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 4 +++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-
 3 files changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -2
index 8edf54b..8802ff2 100644
@@ -529,10 +529,14 @@ int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,
 	return 0;
 }
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
 {
 	mutex_init(&mgr->lock);
 	idr_init(&mgr->ctx_handles);
+	mgr->resv_vm_bitmap = kzalloc(DIV_ROUND_UP(AMDGPU_VM_MAX_NUM_CTX, BITS_PER_BYTE), GFP_KERNEL);
+	if (unlikely(!mgr->resv_vm_bitmap))
+		return -ENOMEM;
+	return 0;
 }
 
 void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr)
@@ -601,7 +605,7 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
 		if (kref_put(&ctx->refcount, amdgpu_ctx_fini) != 1)
 			DRM_ERROR("ctx %p is still alive\n", ctx);
 	}
-
+	kfree(mgr->resv_vm_bitmap);
 	idr_destroy(&mgr->ctx_handles);
 	mutex_destroy(&mgr->lock);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +3 -1
index b3b012c..94ac951 100644
@@ -38,6 +38,7 @@ struct amdgpu_ctx_entity {
 struct amdgpu_ctx {
 	struct kref			refcount;
 	struct amdgpu_device		*adev;
+
 	unsigned			reset_counter;
 	unsigned			reset_counter_query;
 	uint32_t			vram_lost_counter;
@@ -56,6 +57,7 @@ struct amdgpu_ctx_mgr {
 	struct mutex		lock;
 	/* protected by lock */
 	struct idr		ctx_handles;
+	unsigned long		*resv_vm_bitmap;
 };
 
 extern const unsigned int amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM];
@@ -80,7 +82,7 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
 int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,
 			       struct drm_sched_entity *entity);
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
 void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);
 void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr);
 void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -1
index 52e4e90..338a091 100644
@@ -988,11 +988,15 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 	mutex_init(&fpriv->bo_list_lock);
 	idr_init(&fpriv->bo_list_handles);
 
-	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
+	if (amdgpu_ctx_mgr_init(&fpriv->ctx_mgr))
+		goto error_ctx_mgr;
 
 	file_priv->driver_priv = fpriv;
 	goto out_suspend;
 
+error_ctx_mgr:
+	idr_destroy(&fpriv->bo_list_handles);
+	mutex_destroy(&fpriv->bo_list_lock);
 error_vm:
 	amdgpu_vm_fini(adev, &fpriv->vm);
 
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-3-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

#9 lore raw

Re: [PATCH 4/9] drm/amdgpu: Add a bitmask in amdgpu_ctx_mgr

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 1 line

used to manager the reserverd vm space.

Why do we need that?

Christian.

Quoted 77 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 ++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 4 +++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-
  3 files changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +6 -2
index 8edf54b..8802ff2 100644
@@ -529,10 +529,14 @@ int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,
  	return 0;
  }
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
  {
  	mutex_init(&mgr->lock);
  	idr_init(&mgr->ctx_handles);
+	mgr->resv_vm_bitmap = kzalloc(DIV_ROUND_UP(AMDGPU_VM_MAX_NUM_CTX, BITS_PER_BYTE), GFP_KERNEL);
+	if (unlikely(!mgr->resv_vm_bitmap))
+		return -ENOMEM;
+	return 0;
  }
 
  void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr)
@@ -601,7 +605,7 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr)
  		if (kref_put(&ctx->refcount, amdgpu_ctx_fini) != 1)
  			DRM_ERROR("ctx %p is still alive\n", ctx);
  	}
-
+	kfree(mgr->resv_vm_bitmap);
  	idr_destroy(&mgr->ctx_handles);
  	mutex_destroy(&mgr->lock);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +3 -1
index b3b012c..94ac951 100644
@@ -38,6 +38,7 @@ struct amdgpu_ctx_entity {
  struct amdgpu_ctx {
  	struct kref			refcount;
  	struct amdgpu_device		*adev;
+
  	unsigned			reset_counter;
  	unsigned			reset_counter_query;
  	uint32_t			vram_lost_counter;
@@ -56,6 +57,7 @@ struct amdgpu_ctx_mgr {
  	struct mutex		lock;
  	/* protected by lock */
  	struct idr		ctx_handles;
+	unsigned long		*resv_vm_bitmap;
  };
 
  extern const unsigned int amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM];
@@ -80,7 +82,7 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
  int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,
  			       struct drm_sched_entity *entity);
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
  void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);
  void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr);
  void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -1
index 52e4e90..338a091 100644
@@ -988,11 +988,15 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  	mutex_init(&fpriv->bo_list_lock);
  	idr_init(&fpriv->bo_list_handles);
 
-	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
+	if (amdgpu_ctx_mgr_init(&fpriv->ctx_mgr))
+		goto error_ctx_mgr;

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) · line 1002

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -0
 
  	file_priv->driver_priv = fpriv;
  	goto out_suspend;
 
+error_ctx_mgr:
+	idr_destroy(&fpriv->bo_list_handles);
+	mutex_destroy(&fpriv->bo_list_lock);
  error_vm:
  	amdgpu_vm_fini(adev, &fpriv->vm);
 

_______________________________________________
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): ab6bcc8e-8f88-5cb9-c2e8-5322a907bdac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

author
#11 lore raw

RE: [PATCH 4/9] drm/amdgpu: Add a bitmask in amdgpu_ctx_mgr

Hi Christian,

We allocate and map csa per ctx, need to record the used/free vm space. So use bitmap to manager the reserved vm space.

Also add resv_space_id in ctx.
When amdgpu_ctx_fini, we can clear the bit in the bitmap.

Best Regards
Rex

Quoted 104 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, December 6, 2018 8:34 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH 4/9] drm/amdgpu: Add a bitmask in amdgpu_ctx_mgr

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 1 line

used to manager the reserverd vm space.

Why do we need that?

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c int amdgpu_ctx_wait_prev_fence(struct

Quoted 14 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 ++++++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 4 +++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-
  3 files changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
index 8edf54b..8802ff2 100644
@@ -529,10 +529,14 @@ int amdgpu_ctx_wait_prev_fence(struct

amdgpu_ctx *ctx,

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -1
  	return 0;
  }
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
  {
  	mutex_init(&mgr->lock);
  	idr_init(&mgr->ctx_handles);
+	mgr->resv_vm_bitmap =

kzalloc(DIV_ROUND_UP(AMDGPU_VM_MAX_NUM_CTX, BITS_PER_BYTE), GFP_KERNEL);

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3 -1
+	if (unlikely(!mgr->resv_vm_bitmap))
+		return -ENOMEM;
+	return 0;
  }
 
  void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr) @@
-601,7 +605,7 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr

*mgr)

Quoted 22 lines
  		if (kref_put(&ctx->refcount, amdgpu_ctx_fini) != 1)
  			DRM_ERROR("ctx %p is still alive\n", ctx);
  	}
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -1
-
+	kfree(mgr->resv_vm_bitmap);
  	idr_destroy(&mgr->ctx_handles);
  	mutex_destroy(&mgr->lock);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
index b3b012c..94ac951 100644
@@ -38,6 +38,7 @@ struct amdgpu_ctx_entity {
  struct amdgpu_ctx {
  	struct kref			refcount;
  	struct amdgpu_device		*adev;
+
  	unsigned			reset_counter;
  	unsigned			reset_counter_query;
  	uint32_t			vram_lost_counter;

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h struct amdgpu_ctx_mgr { · line 63

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
@@ -56,6 +57,7 @@ struct amdgpu_ctx_mgr {
  	struct mutex		lock;
  	/* protected by lock */
  	struct idr		ctx_handles;
+	unsigned long		*resv_vm_bitmap;
  };
 
  extern const unsigned int

amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM];

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h int amdgpu_ctx_ioctl(struct drm_device *dev, void

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +0 -0
@@ -80,7 +82,7 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -1
  int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,
  			       struct drm_sched_entity *entity);
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
  void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);
  void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr);
  void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 52e4e90..338a091 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -988,11 +988,15 @@ int amdgpu_driver_open_kms(struct drm_device

*dev, struct drm_file *file_priv)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -1
  	mutex_init(&fpriv->bo_list_lock);
  	idr_init(&fpriv->bo_list_handles);
 
-	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
+	if (amdgpu_ctx_mgr_init(&fpriv->ctx_mgr))
+		goto error_ctx_mgr;
 
  	file_priv->driver_priv = fpriv;
  	goto out_suspend;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) · line 1002

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -0
+error_ctx_mgr:
+	idr_destroy(&fpriv->bo_list_handles);
+	mutex_destroy(&fpriv->bo_list_lock);
  error_vm:
  	amdgpu_vm_fini(adev, &fpriv->vm);
 

_______________________________________________
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): BYAPR12MB2775D509B792B3D869B1BC8EFBA90-ZGDeBxoHBPmJeBUhB162ZQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#13 lore raw

Re: [PATCH 4/9] drm/amdgpu: Add a bitmask in amdgpu_ctx_mgr

Hi Rex,

ok still doesn't make sense to me. VM updates are pipelined with command submissions.

So you just need to create the mapping for the specific ID when the CTX is created.

And when the CTX is destroyed you unmap the CSA again.

Or is that for each queue inside the context? Please clarify.

Thanks,
Christian.

Am 06.12.18 um 15:48 schrieb Zhu, Rex:

Quoted 113 lines

Hi Christian,

We allocate and map csa per ctx, need to record the used/free vm space. So use bitmap to manager the reserved vm space.

Also add resv_space_id in ctx.
When amdgpu_ctx_fini, we can clear the bit in the bitmap.

Best Regards
Rex

Quoted 102 lines

-----Original Message-----
From: Christian König <[email protected]>
Sent: Thursday, December 6, 2018 8:34 PM
To: Zhu, Rex <[email protected]>; [email protected]
Subject: Re: [PATCH 4/9] drm/amdgpu: Add a bitmask in amdgpu_ctx_mgr

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 1 line

used to manager the reserverd vm space.

Why do we need that?

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c int amdgpu_ctx_wait_prev_fence(struct

Quoted 13 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 8 ++++++--
   drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 4 +++-
   drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++++-
   3 files changed, 14 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -0
index 8edf54b..8802ff2 100644
@@ -529,10 +529,14 @@ int amdgpu_ctx_wait_prev_fence(struct

amdgpu_ctx *ctx,

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -1
   	return 0;
   }
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr)
   {
   	mutex_init(&mgr->lock);
   	idr_init(&mgr->ctx_handles);
+	mgr->resv_vm_bitmap =

kzalloc(DIV_ROUND_UP(AMDGPU_VM_MAX_NUM_CTX, BITS_PER_BYTE), GFP_KERNEL);

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +3 -1
+	if (unlikely(!mgr->resv_vm_bitmap))
+		return -ENOMEM;
+	return 0;
   }
 
   void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr) @@
-601,7 +605,7 @@ void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr

*mgr)

Quoted 22 lines
   		if (kref_put(&ctx->refcount, amdgpu_ctx_fini) != 1)
   			DRM_ERROR("ctx %p is still alive\n", ctx);
   	}
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -1
-
+	kfree(mgr->resv_vm_bitmap);
   	idr_destroy(&mgr->ctx_handles);
   	mutex_destroy(&mgr->lock);
   }
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
index b3b012c..94ac951 100644
@@ -38,6 +38,7 @@ struct amdgpu_ctx_entity {
   struct amdgpu_ctx {
   	struct kref			refcount;
   	struct amdgpu_device		*adev;
+
   	unsigned			reset_counter;
   	unsigned			reset_counter_query;
   	uint32_t			vram_lost_counter;

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h struct amdgpu_ctx_mgr { · line 63

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
@@ -56,6 +57,7 @@ struct amdgpu_ctx_mgr {
   	struct mutex		lock;
   	/* protected by lock */
   	struct idr		ctx_handles;
+	unsigned long		*resv_vm_bitmap;
   };
 
   extern const unsigned int

amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM];

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h int amdgpu_ctx_ioctl(struct drm_device *dev, void

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +0 -0
@@ -80,7 +82,7 @@ int amdgpu_ctx_ioctl(struct drm_device *dev, void

*data,

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device

Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -1
   int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,
   			       struct drm_sched_entity *entity);
 
-void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
+int amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
   void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);
   void amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr);
   void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr); diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index 52e4e90..338a091 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
@@ -988,11 +988,15 @@ int amdgpu_driver_open_kms(struct drm_device

*dev, struct drm_file *file_priv)

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -1
   	mutex_init(&fpriv->bo_list_lock);
   	idr_init(&fpriv->bo_list_handles);
 
-	amdgpu_ctx_mgr_init(&fpriv->ctx_mgr);
+	if (amdgpu_ctx_mgr_init(&fpriv->ctx_mgr))
+		goto error_ctx_mgr;
 
   	file_priv->driver_priv = fpriv;
   	goto out_suspend;
 
Quoted 6 lines
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) · line 1002

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -0
+error_ctx_mgr:
+	idr_destroy(&fpriv->bo_list_handles);
+	mutex_destroy(&fpriv->bo_list_lock);
   error_vm:
   	amdgpu_vm_fini(adev, &fpriv->vm);
 

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

author
#14 lore raw

PATCH 5/9 drm/amdgpu: Delay map sriov csa addr to ctx init

In reply to a message not in the archive

1. meet kfd request
2. align with baremetal, in baremetal, driver map csa per ctx.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 19 ++++++++++++++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  8 --------
 2 files changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +18 -1
index 8802ff2..3ab7262 100644
@@ -68,11 +68,13 @@ static int amdgpu_ctx_priority_permit(struct drm_file *filp,
 }
 
 static int amdgpu_ctx_init(struct amdgpu_device *adev,
+			   struct amdgpu_fpriv *fpriv,
 			   enum drm_sched_priority priority,
 			   struct drm_file *filp,
 			   struct amdgpu_ctx *ctx)
 {
 	unsigned num_entities = amdgput_ctx_total_num_entities();
+	uint64_t csa_addr;
 	unsigned i, j;
 	int r;
 
@@ -86,6 +88,21 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev,
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->adev = adev;
 
+	if (amdgpu_sriov_vf(adev)) {
+		if (!fpriv->csa_va) {
+			csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
+			r = amdgpu_map_static_csa(adev, &fpriv->vm,
+						adev->virt.csa_obj,
+						&fpriv->csa_va,
+						csa_addr,
+						AMDGPU_CSA_SIZE);
+			if (r) {
+				amdgpu_free_static_csa(&adev->virt.csa_obj);
+				return -EINVAL;
+			}
+		}
+	}
+
 	ctx->fences = kcalloc(amdgpu_sched_jobs * num_entities,
 			      sizeof(struct dma_fence*), GFP_KERNEL);
 	if (!ctx->fences)
@@ -255,7 +272,7 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
 	}
 
 	*id = (uint32_t)r;
-	r = amdgpu_ctx_init(adev, priority, filp, ctx);
+	r = amdgpu_ctx_init(adev, fpriv, priority, filp, ctx);
 	if (r) {
 		idr_remove(&mgr->ctx_handles, *id);
 		*id = 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -8
index 338a091..34d000a 100644
@@ -977,14 +977,6 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 		goto error_vm;
 	}
 
-	if (amdgpu_sriov_vf(adev)) {
-		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
-		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
-						&fpriv->csa_va, csa_addr, AMDGPU_CSA_SIZE);
-		if (r)
-			goto error_vm;
-	}
-
 	mutex_init(&fpriv->bo_list_lock);
 	idr_init(&fpriv->bo_list_handles);
 
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-4-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

#16 lore raw

Re: [PATCH 5/9] drm/amdgpu: Delay map sriov csa addr to ctx init

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 34 lines

1. meet kfd request
2. align with baremetal, in baremetal, driver map csa per ctx.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 19 ++++++++++++++++++-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c |  8 --------
  2 files changed, 18 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +4 -0
index 8802ff2..3ab7262 100644
@@ -68,11 +68,13 @@ static int amdgpu_ctx_priority_permit(struct drm_file *filp,
  }
 
  static int amdgpu_ctx_init(struct amdgpu_device *adev,
+			   struct amdgpu_fpriv *fpriv,
  			   enum drm_sched_priority priority,
  			   struct drm_file *filp,
  			   struct amdgpu_ctx *ctx)
  {
  	unsigned num_entities = amdgput_ctx_total_num_entities();
+	uint64_t csa_addr;
  	unsigned i, j;
  	int r;
 
@@ -86,6 +88,21 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev,
  	memset(ctx, 0, sizeof(*ctx));
  	ctx->adev = adev;
 
+	if (amdgpu_sriov_vf(adev)) {
+		if (!fpriv->csa_va) {

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init(struct amdgpu_device *adev, · line 102

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +10 -0
+			csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
+			r = amdgpu_map_static_csa(adev, &fpriv->vm,
+						adev->virt.csa_obj,
+						&fpriv->csa_va,
+						csa_addr,
+						AMDGPU_CSA_SIZE);
+			if (r) {
+				amdgpu_free_static_csa(&adev->virt.csa_obj);
+				return -EINVAL;
+			}

Please double check that this is protected by some lock.

Christian.

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +4 -1
+		}
+	}
+
  	ctx->fences = kcalloc(amdgpu_sched_jobs * num_entities,
  			      sizeof(struct dma_fence*), GFP_KERNEL);
  	if (!ctx->fences)
@@ -255,7 +272,7 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
  	}
 
  	*id = (uint32_t)r;
-	r = amdgpu_ctx_init(adev, priority, filp, ctx);
+	r = amdgpu_ctx_init(adev, fpriv, priority, filp, ctx);
  	if (r) {
  		idr_remove(&mgr->ctx_handles, *id);
  		*id = 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -1
index 338a091..34d000a 100644
@@ -977,14 +977,6 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  		goto error_vm;
  	}
 
-	if (amdgpu_sriov_vf(adev)) {

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) · line 982

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -7
-		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
-		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
-						&fpriv->csa_va, csa_addr, AMDGPU_CSA_SIZE);
-		if (r)
-			goto error_vm;
-	}
-
  	mutex_init(&fpriv->bo_list_lock);
  	idr_init(&fpriv->bo_list_handles);
 

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

author
#17 lore raw

PATCH 6/9 drm/amdgpu: Create csa per ctx

In reply to a message not in the archive

create and map csa for gfx/sdma engine to save the middle command buffer when gpu preemption triggered.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |  9 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 55 ++++++++++++++++++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h |  4 +++
 3 files changed, 56 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -4
index 2f189c5c..6f7a2dd 100644
@@ -824,8 +824,9 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
 	struct amdgpu_device *adev = p->adev;
 	struct amdgpu_vm *vm = &fpriv->vm;
 	struct amdgpu_bo_list_entry *e;
-	struct amdgpu_bo_va *bo_va;
+	struct amdgpu_bo_va *bo_va = NULL;
 	struct amdgpu_bo *bo;
+	struct amdgpu_ctx *ctx = p->ctx;
 	int r;
 
 	/* Only for UVD/VCE VM emulation */
@@ -906,11 +907,11 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
 	if (r)
 		return r;
 
-	if (amdgpu_sriov_vf(adev)) {
+	bo_va = amdgpu_sriov_vf(adev) ? fpriv->csa_va : ctx->csa_va;
+
+	if (bo_va) {
 		struct dma_fence *f;
 
-		bo_va = fpriv->csa_va;
-		BUG_ON(!bo_va);
 		r = amdgpu_vm_bo_update(adev, bo_va, false);
 		if (r)
 			return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +47 -8

100 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +4 -0
index 94ac951..e434a6c 100644
@@ -38,6 +38,9 @@ struct amdgpu_ctx_entity {
 struct amdgpu_ctx {
 	struct kref			refcount;
 	struct amdgpu_device		*adev;
+	struct amdgpu_ctx_mgr		*ctx_mgr;
+	struct amdgpu_bo		*csa_bo;
+	struct amdgpu_bo_va		*csa_va;
 
 	unsigned			reset_counter;
 	unsigned			reset_counter_query;
@@ -50,6 +53,7 @@ struct amdgpu_ctx {
 	enum drm_sched_priority		override_priority;
 	struct mutex			lock;
 	atomic_t			guilty;
+	u32				resv_space_id;
 };
 
 struct amdgpu_ctx_mgr {
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-5-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

#19 lore raw

Re: [PATCH 6/9] drm/amdgpu: Create csa per ctx

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 54 lines

create and map csa for gfx/sdma engine to save the middle command buffer when gpu preemption triggered.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  |  9 +++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 55 ++++++++++++++++++++++++++++-----
  drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h |  4 +++
  3 files changed, 56 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +5 -4
index 2f189c5c..6f7a2dd 100644
@@ -824,8 +824,9 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
  	struct amdgpu_device *adev = p->adev;
  	struct amdgpu_vm *vm = &fpriv->vm;
  	struct amdgpu_bo_list_entry *e;
-	struct amdgpu_bo_va *bo_va;
+	struct amdgpu_bo_va *bo_va = NULL;
  	struct amdgpu_bo *bo;
+	struct amdgpu_ctx *ctx = p->ctx;
  	int r;
 
  	/* Only for UVD/VCE VM emulation */
@@ -906,11 +907,11 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)
  	if (r)
  		return r;
 
-	if (amdgpu_sriov_vf(adev)) {
+	bo_va = amdgpu_sriov_vf(adev) ? fpriv->csa_va : ctx->csa_va;
+
+	if (bo_va) {
  		struct dma_fence *f;
 
-		bo_va = fpriv->csa_va;
-		BUG_ON(!bo_va);
  		r = amdgpu_vm_bo_update(adev, bo_va, false);
  		if (r)
  			return r;
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +1 -1
index 3ab7262..71831aa 100644
@@ -71,7 +71,7 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev,
  			   struct amdgpu_fpriv *fpriv,
  			   enum drm_sched_priority priority,
  			   struct drm_file *filp,
-			   struct amdgpu_ctx *ctx)
+			   struct amdgpu_ctx *ctx, uint32_t id)
  {
  	unsigned num_entities = amdgput_ctx_total_num_entities();
  	uint64_t csa_addr;

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c static int amdgpu_ctx_init(struct amdgpu_device *adev, · line 91

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +2 -0
@@ -87,20 +87,36 @@ static int amdgpu_ctx_init(struct amdgpu_device *adev,
 
  	memset(ctx, 0, sizeof(*ctx));
  	ctx->adev = adev;
+	csa_addr = amdgpu_csa_vaddr(adev, id) & AMDGPU_GMC_HOLE_MASK;
+	ctx->resv_space_id = id;

Do we really need resv_space_id? I mean during command submission we should have that anyway.

Christian.

Quoted 105 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +44 -7
  	if (amdgpu_sriov_vf(adev)) {
  		if (!fpriv->csa_va) {
-			csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
  			r = amdgpu_map_static_csa(adev, &fpriv->vm,
-						adev->virt.csa_obj,
-						&fpriv->csa_va,
-						csa_addr,
-						AMDGPU_CSA_SIZE);
+							adev->virt.csa_obj,
+							&fpriv->csa_va,
+							csa_addr,
+							AMDGPU_CSA_SIZE);
  			if (r) {
  				amdgpu_free_static_csa(&adev->virt.csa_obj);
  				return -EINVAL;
  			}
  		}
+	} else {
+		r = amdgpu_allocate_static_csa(adev, &ctx->csa_bo,
+						AMDGPU_GEM_DOMAIN_GTT,
+						AMDGPU_CSA_SIZE);
+		if (r) {
+			DRM_ERROR("allocate CSA failed %d\n", r);
+			return r;
+		}
+		r = amdgpu_map_static_csa(adev, &fpriv->vm, ctx->csa_bo,
+						&ctx->csa_va, csa_addr,
+						AMDGPU_CSA_SIZE);
+		if (r) {
+			amdgpu_free_static_csa(&ctx->csa_bo);
+			return -EINVAL;
+		}
  	}
 
  	ctx->fences = kcalloc(amdgpu_sched_jobs * num_entities,
@@ -221,6 +237,16 @@ static void amdgpu_ctx_fini(struct kref *ref)
  	kfree(ctx->fences);
  	kfree(ctx->entities[0]);
 
+	if (!amdgpu_sriov_vf(adev) && ctx->csa_bo) {
+		BUG_ON(amdgpu_bo_reserve(ctx->csa_bo, true));
+		amdgpu_vm_bo_rmv(adev, ctx->csa_va);
+		ctx->csa_va = NULL;
+		amdgpu_bo_unreserve(ctx->csa_bo);
+		amdgpu_free_static_csa(&ctx->csa_bo);
+		if (ctx->ctx_mgr)
+			__clear_bit(ctx->resv_space_id - 1, ctx->ctx_mgr->resv_vm_bitmap);
+	}
+
  	mutex_destroy(&ctx->lock);
 
  	kfree(ctx);
@@ -258,6 +284,7 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
  	struct amdgpu_ctx_mgr *mgr = &fpriv->ctx_mgr;
  	struct amdgpu_ctx *ctx;
  	int r;
+	u32 resv_space_id = 1;
 
  	ctx = kmalloc(sizeof(*ctx), GFP_KERNEL);
  	if (!ctx)
@@ -270,14 +297,26 @@ static int amdgpu_ctx_alloc(struct amdgpu_device *adev,
  		kfree(ctx);
  		return r;
  	}
-
  	*id = (uint32_t)r;
-	r = amdgpu_ctx_init(adev, fpriv, priority, filp, ctx);
+
+	if (!amdgpu_sriov_vf(adev)) {
+		resv_space_id = find_first_zero_bit(mgr->resv_vm_bitmap, AMDGPU_VM_MAX_NUM_CTX);
+		if (resv_space_id < AMDGPU_VM_MAX_NUM_CTX)
+			__set_bit(resv_space_id, mgr->resv_vm_bitmap);
+		else
+			return -ENOMEM;
+		resv_space_id += 1;
+	}
+
+	r = amdgpu_ctx_init(adev, fpriv, priority, filp, ctx, resv_space_id);
  	if (r) {
  		idr_remove(&mgr->ctx_handles, *id);
  		*id = 0;
  		kfree(ctx);
+		mutex_unlock(&mgr->lock);
+		return r;
  	}
+	ctx->ctx_mgr = mgr;
  	mutex_unlock(&mgr->lock);
  	return r;
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +3 -0
index 94ac951..e434a6c 100644
@@ -38,6 +38,9 @@ struct amdgpu_ctx_entity {
  struct amdgpu_ctx {
  	struct kref			refcount;
  	struct amdgpu_device		*adev;
+	struct amdgpu_ctx_mgr		*ctx_mgr;
+	struct amdgpu_bo		*csa_bo;
+	struct amdgpu_bo_va		*csa_va;
 
  	unsigned			reset_counter;
  	unsigned			reset_counter_query;

drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h struct amdgpu_ctx { · line 59

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +1 -0
@@ -50,6 +53,7 @@ struct amdgpu_ctx {
  	enum drm_sched_priority		override_priority;
  	struct mutex			lock;
  	atomic_t			guilty;
+	u32				resv_space_id;
  };
 
  struct amdgpu_ctx_mgr {

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

author
#20 lore raw

PATCH 7/9 drm/amdgpu: Add csa mc address into job structure

In reply to a message not in the archive

save csa mc address in the job, so can patch the address to pm4 when emit_ib even the ctx was freed.

suggested by Christian.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -0
index 6f7a2dd..13f0d7c 100644
@@ -230,6 +230,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
 		goto free_all_kdata;
 	}
 
+	p->job->csa_mc_addr = amdgpu_csa_vaddr(p->adev, p->ctx->resv_space_id) & AMDGPU_GMC_HOLE_MASK;
+
 	if (p->uf_entry.tv.bo)
 		p->job->uf_addr = uf_offset;
 	kfree(chunk_array);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +3 -1
index e1b46a6..42c959d 100644
@@ -34,6 +34,7 @@
 		container_of((sched_job), struct amdgpu_job, base)
 
 #define AMDGPU_JOB_GET_VMID(job) ((job) ? (job)->vmid : 0)
+#define AMDGPU_JOB_GET_CSA_MC_ADDR(job) ((job) ? (job)->csa_mc_addr : 0)
 
 struct amdgpu_fence;
 
@@ -56,10 +57,11 @@ struct amdgpu_job {
 	uint32_t		oa_base, oa_size;
 	uint32_t		vram_lost_counter;
 
+	/* csa buffer mc address */
+	uint64_t		csa_mc_addr;
 	/* user fence handling */
 	uint64_t		uf_addr;
 	uint64_t		uf_sequence;
-
 };
 
 int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-6-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#22 lore raw

Re: [PATCH 7/9] drm/amdgpu: Add csa mc address into job structure

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 6 lines

save csa mc address in the job, so can patch the address to pm4 when emit_ib even the ctx was freed.

suggested by Christian.

Quoted 33 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c  | 2 ++
  drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 4 +++-
  2 files changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -0
index 6f7a2dd..13f0d7c 100644
@@ -230,6 +230,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs
  		goto free_all_kdata;
  	}
 
+	p->job->csa_mc_addr = amdgpu_csa_vaddr(p->adev, p->ctx->resv_space_id) & AMDGPU_GMC_HOLE_MASK;
+
  	if (p->uf_entry.tv.bo)
  		p->job->uf_addr = uf_offset;
  	kfree(chunk_array);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +1 -0
index e1b46a6..42c959d 100644
@@ -34,6 +34,7 @@
  		container_of((sched_job), struct amdgpu_job, base)
 
  #define AMDGPU_JOB_GET_VMID(job) ((job) ? (job)->vmid : 0)
+#define AMDGPU_JOB_GET_CSA_MC_ADDR(job) ((job) ? (job)->csa_mc_addr : 0)
 
  struct amdgpu_fence;
 
@@ -56,10 +57,11 @@ struct amdgpu_job {
  	uint32_t		oa_base, oa_size;
  	uint32_t		vram_lost_counter;

drivers/gpu/drm/amd/amdgpu/amdgpu_job.h struct amdgpu_job { · line 67

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -1
 
+	/* csa buffer mc address */
+	uint64_t		csa_mc_addr;
  	/* user fence handling */
  	uint64_t		uf_addr;
  	uint64_t		uf_sequence;
-
  };
 
  int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,

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

author
#23 lore raw

PATCH 8/9 drm/amdgpu: Add a argument in emit_cntxcntl interface

In reply to a message not in the archive

add a point of struct amdgpu_job in emit_cntxcntl interface in order to get the csa mc address per ctx when emit ce metadata in baremetal.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c   |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c    |  4 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c    |  4 +++-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 20 ++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 16 ++++++++++------
 6 files changed, 31 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +1 -1
index c48207b3..5329044 100644
@@ -208,7 +208,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
 			status |= AMDGPU_HAVE_CTX_SWITCH;
 		status |= job->preamble_status;
 
-		amdgpu_ring_emit_cntxcntl(ring, status);
+		amdgpu_ring_emit_cntxcntl(ring, job, status);
 	}
 
 	for (i = 0; i < num_ibs; ++i) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -2
index 0beb01f..7aa46cc 100644
@@ -157,7 +157,7 @@ struct amdgpu_ring_funcs {
 	void (*begin_use)(struct amdgpu_ring *ring);
 	void (*end_use)(struct amdgpu_ring *ring);
 	void (*emit_switch_buffer) (struct amdgpu_ring *ring);
-	void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
+	void (*emit_cntxcntl) (struct amdgpu_ring *ring, struct amdgpu_job *job, uint32_t flags);
 	void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
 	void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
 	void (*emit_reg_wait)(struct amdgpu_ring *ring, uint32_t reg,
@@ -236,7 +236,7 @@ struct amdgpu_ring {
 #define amdgpu_ring_emit_gds_switch(r, v, db, ds, wb, ws, ab, as) (r)->funcs->emit_gds_switch((r), (v), (db), (ds), (wb), (ws), (ab), (as))
 #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
 #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
-#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
+#define amdgpu_ring_emit_cntxcntl(r, job, d) (r)->funcs->emit_cntxcntl((r), (job), (d))
 #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
 #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
 #define amdgpu_ring_emit_reg_wait(r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m))
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +3 -1
index 5b25c26..976f94a 100644
@@ -2976,7 +2976,9 @@ static uint64_t gfx_v6_0_get_gpu_clock_counter(struct amdgpu_device *adev)
 	return clock;
 }
 
-static void gfx_v6_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v6_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,
+					uint32_t flags)
 {
 	if (flags & AMDGPU_HAVE_CTX_SWITCH)
 		gfx_v6_0_ring_emit_vgt_flush(ring);
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +3 -1
index 243b8c5..ab62117 100644
@@ -2275,7 +2275,9 @@ static void gfx_v7_0_ring_emit_ib_compute(struct amdgpu_ring *ring,
 	amdgpu_ring_write(ring, control);
 }
 
-static void gfx_v7_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v7_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,
+					uint32_t flags)
 {
 	uint32_t dw2 = 0;
 
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +12 -8
index d529cef..3ac2d8f 100644
@@ -723,8 +723,8 @@ enum {
 static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev);
 static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev);
 static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev);
-static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring);
-static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring);
+static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring, struct amdgpu_job *job);
+static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring, struct amdgpu_job *job);
 
 static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
 {
@@ -6127,7 +6127,7 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
-			gfx_v8_0_ring_emit_de_meta(ring);
+			gfx_v8_0_ring_emit_de_meta(ring, job);
 	}
 
 	amdgpu_ring_write(ring, header);
@@ -6386,12 +6386,14 @@ static void gfx_v8_ring_emit_sb(struct amdgpu_ring *ring)
 	amdgpu_ring_write(ring, 0);
 }
 
-static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,
+					uint32_t flags)
 {
 	uint32_t dw2 = 0;
 
 	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v8_0_ring_emit_ce_meta(ring);
+		gfx_v8_0_ring_emit_ce_meta(ring, job);
 
 	dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
 	if (flags & AMDGPU_HAVE_CTX_SWITCH) {
@@ -7182,7 +7184,8 @@ static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
 	.funcs = &gfx_v8_0_ip_funcs,
 };
 
-static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
+static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
 {
 	uint64_t ce_payload_addr;
 	int cnt_ce;
@@ -7196,7 +7199,7 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
 			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
 		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
 	} else {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
+		ce_payload_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job) +
 			offsetof(struct vi_gfx_meta_data, ce_payload);
 		cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
 	}
@@ -7211,7 +7214,8 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
 	amdgpu_ring_write_multiple(ring, (void *)&ce_payload, cnt_ce - 2);
 }
 
-static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
+static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
 {
 	uint64_t de_payload_addr, gds_addr, csa_addr;
 	int cnt_de;
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -6
index 81c1578..dd2d535 100644
@@ -297,7 +297,7 @@ static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,
                                  struct amdgpu_cu_info *cu_info);
 static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device *adev);
 static void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
-static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring);
+static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring, struct amdgpu_job *job);
 
 static void gfx_v9_0_init_golden_registers(struct amdgpu_device *adev)
 {
@@ -4067,7 +4067,7 @@ static void gfx_v9_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
-			gfx_v9_0_ring_emit_de_meta(ring);
+			gfx_v9_0_ring_emit_de_meta(ring, job);
 	}
 
 	amdgpu_ring_write(ring, header);
@@ -4320,7 +4320,8 @@ static void gfx_v9_ring_emit_sb(struct amdgpu_ring *ring)
 	amdgpu_ring_write(ring, 0);
 }
 
-static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
+static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
 {
 	struct v9_ce_ib_state ce_payload = {0};
 	uint64_t csa_addr;
@@ -4339,7 +4340,8 @@ static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
 	amdgpu_ring_write_multiple(ring, (void *)&ce_payload, sizeof(ce_payload) >> 2);
 }
 
-static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring)
+static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
 {
 	struct v9_de_ib_state de_payload = {0};
 	uint64_t csa_addr, gds_addr;
@@ -4367,12 +4369,14 @@ static void gfx_v9_0_ring_emit_tmz(struct amdgpu_ring *ring, bool start)
 	amdgpu_ring_write(ring, FRAME_CMD(start ? 0 : 1)); /* frame_end */
 }
 
-static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,
+					uint32_t flags)
 {
 	uint32_t dw2 = 0;
 
 	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v9_0_ring_emit_ce_meta(ring);
+		gfx_v9_0_ring_emit_ce_meta(ring, job);
 
 	gfx_v9_0_ring_emit_tmz(ring, true);
 
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-7-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#25 lore raw

Re: [PATCH 8/9] drm/amdgpu: Add a argument in emit_cntxcntl interface

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 5 lines

add a point of struct amdgpu_job in emit_cntxcntl interface in order to get the csa mc address per ctx when emit ce metadata in baremetal.

Quoted 193 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c   |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h |  4 ++--
  drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c    |  4 +++-
  drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c    |  4 +++-
  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c    | 20 ++++++++++++--------
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c    | 16 ++++++++++------
  6 files changed, 31 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +1 -1
index c48207b3..5329044 100644
@@ -208,7 +208,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
  			status |= AMDGPU_HAVE_CTX_SWITCH;
  		status |= job->preamble_status;
 
-		amdgpu_ring_emit_cntxcntl(ring, status);
+		amdgpu_ring_emit_cntxcntl(ring, job, status);
  	}
 
  	for (i = 0; i < num_ibs; ++i) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +2 -2
index 0beb01f..7aa46cc 100644
@@ -157,7 +157,7 @@ struct amdgpu_ring_funcs {
  	void (*begin_use)(struct amdgpu_ring *ring);
  	void (*end_use)(struct amdgpu_ring *ring);
  	void (*emit_switch_buffer) (struct amdgpu_ring *ring);
-	void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
+	void (*emit_cntxcntl) (struct amdgpu_ring *ring, struct amdgpu_job *job, uint32_t flags);
  	void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
  	void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
  	void (*emit_reg_wait)(struct amdgpu_ring *ring, uint32_t reg,
@@ -236,7 +236,7 @@ struct amdgpu_ring {
  #define amdgpu_ring_emit_gds_switch(r, v, db, ds, wb, ws, ab, as) (r)->funcs->emit_gds_switch((r), (v), (db), (ds), (wb), (ws), (ab), (as))
  #define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
  #define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
-#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
+#define amdgpu_ring_emit_cntxcntl(r, job, d) (r)->funcs->emit_cntxcntl((r), (job), (d))
  #define amdgpu_ring_emit_rreg(r, d) (r)->funcs->emit_rreg((r), (d))
  #define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
  #define amdgpu_ring_emit_reg_wait(r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m))
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +3 -1
index 5b25c26..976f94a 100644
@@ -2976,7 +2976,9 @@ static uint64_t gfx_v6_0_get_gpu_clock_counter(struct amdgpu_device *adev)
  	return clock;
  }
 
-static void gfx_v6_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v6_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,
+					uint32_t flags)
  {
  	if (flags & AMDGPU_HAVE_CTX_SWITCH)
  		gfx_v6_0_ring_emit_vgt_flush(ring);
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +3 -1
index 243b8c5..ab62117 100644
@@ -2275,7 +2275,9 @@ static void gfx_v7_0_ring_emit_ib_compute(struct amdgpu_ring *ring,
  	amdgpu_ring_write(ring, control);
  }
 
-static void gfx_v7_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v7_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,
+					uint32_t flags)
  {
  	uint32_t dw2 = 0;
 
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +12 -8
index d529cef..3ac2d8f 100644
@@ -723,8 +723,8 @@ enum {
  static void gfx_v8_0_set_rlc_funcs(struct amdgpu_device *adev);
  static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev);
  static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev);
-static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring);
-static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring);
+static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring, struct amdgpu_job *job);
+static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring, struct amdgpu_job *job);
 
  static void gfx_v8_0_init_golden_registers(struct amdgpu_device *adev)
  {
@@ -6127,7 +6127,7 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
  		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
  		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
-			gfx_v8_0_ring_emit_de_meta(ring);
+			gfx_v8_0_ring_emit_de_meta(ring, job);
  	}
 
  	amdgpu_ring_write(ring, header);
@@ -6386,12 +6386,14 @@ static void gfx_v8_ring_emit_sb(struct amdgpu_ring *ring)
  	amdgpu_ring_write(ring, 0);
  }
 
-static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,
+					uint32_t flags)
  {
  	uint32_t dw2 = 0;
 
  	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v8_0_ring_emit_ce_meta(ring);
+		gfx_v8_0_ring_emit_ce_meta(ring, job);
 
  	dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
  	if (flags & AMDGPU_HAVE_CTX_SWITCH) {
@@ -7182,7 +7184,8 @@ static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
  	.funcs = &gfx_v8_0_ip_funcs,
  };
 
-static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
+static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
  {
  	uint64_t ce_payload_addr;
  	int cnt_ce;
@@ -7196,7 +7199,7 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
  			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
  		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
  	} else {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
+		ce_payload_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job) +
  			offsetof(struct vi_gfx_meta_data, ce_payload);
  		cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
  	}
@@ -7211,7 +7214,8 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
  	amdgpu_ring_write_multiple(ring, (void *)&ce_payload, cnt_ce - 2);
  }
 
-static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
+static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
  {
  	uint64_t de_payload_addr, gds_addr, csa_addr;
  	int cnt_de;
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +8 -5
index 81c1578..dd2d535 100644
@@ -297,7 +297,7 @@ static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,
                                   struct amdgpu_cu_info *cu_info);
  static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device *adev);
  static void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
-static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring);
+static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring, struct amdgpu_job *job);
 
  static void gfx_v9_0_init_golden_registers(struct amdgpu_device *adev)
  {
@@ -4067,7 +4067,7 @@ static void gfx_v9_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
  		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
  		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
-			gfx_v9_0_ring_emit_de_meta(ring);
+			gfx_v9_0_ring_emit_de_meta(ring, job);
  	}
 
  	amdgpu_ring_write(ring, header);
@@ -4320,7 +4320,8 @@ static void gfx_v9_ring_emit_sb(struct amdgpu_ring *ring)
  	amdgpu_ring_write(ring, 0);
  }
 
-static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
+static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
  {
  	struct v9_ce_ib_state ce_payload = {0};
  	uint64_t csa_addr;
@@ -4339,7 +4340,8 @@ static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
  	amdgpu_ring_write_multiple(ring, (void *)&ce_payload, sizeof(ce_payload) >> 2);
  }
 
-static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring)
+static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring,
+					struct amdgpu_job *job)
  {
  	struct v9_de_ib_state de_payload = {0};
  	uint64_t csa_addr, gds_addr;
@@ -4367,12 +4369,14 @@ static void gfx_v9_0_ring_emit_tmz(struct amdgpu_ring *ring, bool start)
  	amdgpu_ring_write(ring, FRAME_CMD(start ? 0 : 1)); /* frame_end */
  }
 
-static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring, uint32_t flags)
+static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring,
+					struct amdgpu_job *job,

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_tmz(struct amdgpu_ring *ring, bool start) · line 4382

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -1
+					uint32_t flags)
  {
  	uint32_t dw2 = 0;
 
  	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v9_0_ring_emit_ce_meta(ring);
+		gfx_v9_0_ring_emit_ce_meta(ring, job);
 
  	gfx_v9_0_ring_emit_tmz(ring, true);
 

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

author
#26 lore raw

PATCH 9/9 drm/amdgpu: Remove sriov check when insert ce/de meta_data

In reply to a message not in the archive

to support cp gfx mid-command buffer preemption in baremetal

---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 15 ++++++++++-----
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 15 ++++++++++-----
 2 files changed, 20 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +10 -5
index 3ac2d8f..ccc461f 100644
@@ -6123,7 +6123,7 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ib->flags & AMDGPU_IB_FLAG_PREEMPT) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
@@ -6392,8 +6392,7 @@ static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring,
 {
 	uint32_t dw2 = 0;
 
-	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v8_0_ring_emit_ce_meta(ring, job);
+	gfx_v8_0_ring_emit_ce_meta(ring, job);
 
 	dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
 	if (flags & AMDGPU_HAVE_CTX_SWITCH) {
@@ -7194,8 +7193,11 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
 		struct vi_ce_ib_state_chained_ib chained;
 	} ce_payload = {};
 
+	if (!job)
+		return;
+
 	if (ring->adev->virt.chained_ib_support) {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
+		ce_payload_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job) +
 			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
 		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
 	} else {
@@ -7224,7 +7226,10 @@ static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring,
 		struct vi_de_ib_state_chained_ib chained;
 	} de_payload = {};
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
+	if (!job)
+		return;
+
+	csa_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job);
 	gds_addr = csa_addr + 4096;
 	if (ring->adev->virt.chained_ib_support) {
 		de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +10 -5
index dd2d535..6d38834 100644
@@ -4063,7 +4063,7 @@ static void gfx_v9_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
 	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ib->flags & AMDGPU_IB_FLAG_PREEMPT) {
 		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
 		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
@@ -4327,8 +4327,11 @@ static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
 	uint64_t csa_addr;
 	int cnt;
 
+	if (!job)
+		return;
+
 	cnt = (sizeof(ce_payload) >> 2) + 4 - 2;
-	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
+	csa_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job);
 
 	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt));
 	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |
@@ -4347,7 +4350,10 @@ static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring,
 	uint64_t csa_addr, gds_addr;
 	int cnt;
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
+	if (!job)
+		return;
+
+	csa_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job);
 	gds_addr = csa_addr + 4096;
 	de_payload.gds_backup_addrlo = lower_32_bits(gds_addr);
 	de_payload.gds_backup_addrhi = upper_32_bits(gds_addr);
@@ -4375,8 +4381,7 @@ static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring,
 {
 	uint32_t dw2 = 0;
 
-	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v9_0_ring_emit_ce_meta(ring, job);
+	gfx_v9_0_ring_emit_ce_meta(ring, job);
 
 	gfx_v9_0_ring_emit_tmz(ring, true);
 
Signature · 6 lines
1.9.1

_______________________________________________
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): 1544098447-21648-8-git-send-email-Rex.Zhu-5C7GfCeVMHo@public.gmane.org

#28 lore raw

Re: [PATCH 9/9] drm/amdgpu: Remove sriov check when insert ce/de meta_data

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 3 lines

to support cp gfx mid-command buffer preemption in baremetal

Quoted 92 lines
---
  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 15 ++++++++++-----
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 15 ++++++++++-----
  2 files changed, 20 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +10 -5
index 3ac2d8f..ccc461f 100644
@@ -6123,7 +6123,7 @@ static void gfx_v8_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
  	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ib->flags & AMDGPU_IB_FLAG_PREEMPT) {
  		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
  		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
@@ -6392,8 +6392,7 @@ static void gfx_v8_ring_emit_cntxcntl(struct amdgpu_ring *ring,
  {
  	uint32_t dw2 = 0;
 
-	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v8_0_ring_emit_ce_meta(ring, job);
+	gfx_v8_0_ring_emit_ce_meta(ring, job);
 
  	dw2 |= 0x80000000; /* set load_enable otherwise this package is just NOPs */
  	if (flags & AMDGPU_HAVE_CTX_SWITCH) {
@@ -7194,8 +7193,11 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
  		struct vi_ce_ib_state_chained_ib chained;
  	} ce_payload = {};
 
+	if (!job)
+		return;
+
  	if (ring->adev->virt.chained_ib_support) {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
+		ce_payload_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job) +
  			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
  		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
  	} else {
@@ -7224,7 +7226,10 @@ static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring,
  		struct vi_de_ib_state_chained_ib chained;
  	} de_payload = {};
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
+	if (!job)
+		return;
+
+	csa_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job);
  	gds_addr = csa_addr + 4096;
  	if (ring->adev->virt.chained_ib_support) {
  		de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +9 -3
index dd2d535..6d38834 100644
@@ -4063,7 +4063,7 @@ static void gfx_v9_0_ring_emit_ib_gfx(struct amdgpu_ring *ring,
 
  	control |= ib->length_dw | (vmid << 24);
 
-	if (amdgpu_sriov_vf(ring->adev) && (ib->flags & AMDGPU_IB_FLAG_PREEMPT)) {
+	if (ib->flags & AMDGPU_IB_FLAG_PREEMPT) {
  		control |= INDIRECT_BUFFER_PRE_ENB(1);
 
  		if (!(ib->flags & AMDGPU_IB_FLAG_CE))
@@ -4327,8 +4327,11 @@ static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring,
  	uint64_t csa_addr;
  	int cnt;
 
+	if (!job)
+		return;
+
  	cnt = (sizeof(ce_payload) >> 2) + 4 - 2;
-	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
+	csa_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job);
 
  	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt));
  	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |
@@ -4347,7 +4350,10 @@ static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring,
  	uint64_t csa_addr, gds_addr;
  	int cnt;
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
+	if (!job)
+		return;
+
+	csa_addr = AMDGPU_JOB_GET_CSA_MC_ADDR(job);
  	gds_addr = csa_addr + 4096;
  	de_payload.gds_backup_addrlo = lower_32_bits(gds_addr);
  	de_payload.gds_backup_addrhi = upper_32_bits(gds_addr);

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring, · line 4387

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -2
@@ -4375,8 +4381,7 @@ static void gfx_v9_ring_emit_cntxcntl(struct amdgpu_ring *ring,
  {
  	uint32_t dw2 = 0;
 
-	if (amdgpu_sriov_vf(ring->adev))
-		gfx_v9_0_ring_emit_ce_meta(ring, job);
+	gfx_v9_0_ring_emit_ce_meta(ring, job);
 
  	gfx_v9_0_ring_emit_tmz(ring, true);
 

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

#29 lore raw
In reply to a message not in the archive

Am 06.12.18 um 13:14 schrieb Rex Zhu:

Quoted 21 lines

on baremetal, driver create csa per ctx. So add a function argument: ctx_id to get csa gpu addr.
In Sriov, driver create csa per process, so ctx id always 1.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c | 5 +++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ++--
  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 6 +++---
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 4 ++--
  5 files changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +0 -0
index 0c590dd..44b046f 100644
@@ -24,11 +24,12 @@
 

drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c line 32

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +3 -2
  #include "amdgpu.h"
 
-uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
+uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id)
  {
  	uint64_t addr = adev->vm_manager.max_pfn << AMDGPU_GPU_PAGE_SHIFT;
 
-	addr -= AMDGPU_VA_RESERVED_SIZE;
+	addr -= AMDGPU_VA_RESERVED_SIZE * id;
+

It might be better to add the SRIOV handling here instead. E.g. like the following:

if (amdgpu_sriov_vf(adev))
    addr -= AMDGPU_VA_RESERVED_SIZE;
else
    addr -= AMDGPU_CSA_SIZE * id;

Apart from that looks good to me, but might be better to re-order the patches.

Regards,
Christian.

Quoted 73 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +0 -0
  	addr = amdgpu_gmc_sign_extend(addr);
 
  	return addr;
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h +1 -1
index 524b443..aaf1fba 100644
@@ -28,7 +28,7 @@
  #define AMDGPU_CSA_SIZE		(128 * 1024)
 
  uint32_t amdgpu_get_total_csa_size(struct amdgpu_device *adev);
-uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev);
+uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev, uint32_t id);
  int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo **bo,
  				u32 domain, uint32_t size);
  int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +2 -2
index 08d04f6..f736bda 100644
@@ -977,9 +977,9 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
  		goto error_vm;
  	}
 
-	if (amdgpu_sriov_vf(adev)) {
-		uint64_t csa_addr = amdgpu_csa_vaddr(adev) & AMDGPU_GMC_HOLE_MASK;
 
+	if (amdgpu_sriov_vf(adev)) {
+		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
  		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
  						&fpriv->csa_va, csa_addr, AMDGPU_CSA_SIZE);
  		if (r)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +3 -3
index bdae563..d529cef 100644
@@ -7192,11 +7192,11 @@ static void gfx_v8_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
  	} ce_payload = {};
 
  	if (ring->adev->virt.chained_ib_support) {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
+		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
  			offsetof(struct vi_gfx_meta_data_chained_ib, ce_payload);
  		cnt_ce = (sizeof(ce_payload.chained) >> 2) + 4 - 2;
  	} else {
-		ce_payload_addr = amdgpu_csa_vaddr(ring->adev) +
+		ce_payload_addr = amdgpu_csa_vaddr(ring->adev, 1) +
  			offsetof(struct vi_gfx_meta_data, ce_payload);
  		cnt_ce = (sizeof(ce_payload.regular) >> 2) + 4 - 2;
  	}
@@ -7220,7 +7220,7 @@ static void gfx_v8_0_ring_emit_de_meta(struct amdgpu_ring *ring)
  		struct vi_de_ib_state_chained_ib chained;
  	} de_payload = {};
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev);
+	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
  	gds_addr = csa_addr + 4096;
  	if (ring->adev->virt.chained_ib_support) {
  		de_payload.chained.gds_backup_addrlo = lower_32_bits(gds_addr);
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 928034c..81c1578 100644
@@ -4327,7 +4327,7 @@ static void gfx_v9_0_ring_emit_ce_meta(struct amdgpu_ring *ring)
  	int cnt;
 
  	cnt = (sizeof(ce_payload) >> 2) + 4 - 2;
-	csa_addr = amdgpu_csa_vaddr(ring->adev);
+	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
 
  	amdgpu_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, cnt));
  	amdgpu_ring_write(ring, (WRITE_DATA_ENGINE_SEL(2) |

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring) · line 4351

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
@@ -4345,7 +4345,7 @@ static void gfx_v9_0_ring_emit_de_meta(struct amdgpu_ring *ring)
  	uint64_t csa_addr, gds_addr;
  	int cnt;
 
-	csa_addr = amdgpu_csa_vaddr(ring->adev);
+	csa_addr = amdgpu_csa_vaddr(ring->adev, 1);
  	gds_addr = csa_addr + 4096;
  	de_payload.gds_backup_addrlo = lower_32_bits(gds_addr);
  	de_payload.gds_backup_addrhi = upper_32_bits(gds_addr);

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