Skip to contentSkip to conversation

drm/amdgpu: only enable swiotlb alloc when need

PATCH In review Chunming Zhou 2 participants 2 messages Feb 7, 2018 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: only enable swiotlb alloc when need

get the max io mapping address of system memory to see if it is over our card accessing range.

Change-Id Ibc38dbd34a20af5b4a4b1ed154c14e1c58aa4c55
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 ++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  6 +++---
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c      |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c      |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c      |  1 +
 7 files changed, 24 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index 257424dd8a52..34a6814e94f9 100644
@@ -1437,6 +1437,7 @@ struct amdgpu_device {
 	const struct amdgpu_asic_funcs	*asic_funcs;
 	bool				shutdown;
 	bool				need_dma32;
+	bool				need_swiotlb;
 	bool				accel_working;
 	struct work_struct		reset_work;
 	struct notifier_block		acpi_nb;
@@ -1629,6 +1630,8 @@ struct amdgpu_device {
 	unsigned long last_mm_index;
 	bool                            in_gpu_reset;
 	struct mutex  lock_reset;
+
+	u64				sysmem_max_io;
 };
 
 static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +14 -0
index 850453e897f9..c4bca62eeff1 100644
@@ -1742,6 +1742,19 @@ bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)
 	return amdgpu_device_asic_has_dc_support(adev->asic_type);
 }
 
+static void amdgpu_device_get_max_io_of_sysmem(struct amdgpu_device *adev)
+{
+	struct resource *tmp;
+
+	for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) {
+		if (tmp->flags == (IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY))
+			adev->sysmem_max_io = max(adev->sysmem_max_io,
+						  tmp->end);
+	}
+	DRM_INFO("System Ram max io address is 0x%llx\n", adev->sysmem_max_io);
+}
+
+
 /**
  * amdgpu_device_init - initialize the driver
  *
@@ -1795,6 +1808,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 	adev->gc_cac_wreg = &amdgpu_invalid_wreg;
 	adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
 	adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
+	amdgpu_device_get_max_io_of_sysmem(adev);
 
 	DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
 		 amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
index 95f990140f2a..a021de9629ad 100644
@@ -1018,7 +1018,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
 	}
 
 #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
+	if (adev->need_swiotlb && swiotlb_nr_tbl()) {
 		return ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
 	}
 #endif
@@ -1045,7 +1045,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	adev = amdgpu_ttm_adev(ttm->bdev);
 
 #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
+	if (adev->need_swiotlb && swiotlb_nr_tbl()) {
 		ttm_dma_unpopulate(&gtt->ttm, adev->dev);
 		return;
 	}
@@ -2007,7 +2007,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
 	count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
 
 #ifdef CONFIG_SWIOTLB
-	if (!swiotlb_nr_tbl())
+	if (!(adev->need_swiotlb && swiotlb_nr_tbl()))
 		--count;
 #endif
 
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +1 -0
index 5eacc0819b66..588c900075da 100644
@@ -855,6 +855,7 @@ static int gmc_v6_0_sw_init(void *handle)
 
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = adev->sysmem_max_io > (1 << dma_bits);
 	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
 	if (r) {
 		adev->need_dma32 = true;
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +1 -0
index ce7f484f86f9..1723d2151f0b 100644
@@ -1003,6 +1003,7 @@ static int gmc_v7_0_sw_init(void *handle)
 	 */
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = adev->sysmem_max_io > (1 << dma_bits);
 	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
 	if (r) {
 		adev->need_dma32 = true;
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -0
index f53f3936fd4f..1f209f92a2fd 100644
@@ -1101,6 +1101,7 @@ static int gmc_v8_0_sw_init(void *handle)
 	 */
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = adev->sysmem_max_io > ((u64)1 << dma_bits);
 	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
 	if (r) {
 		adev->need_dma32 = true;
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
index 2c60981d2eec..da7ab46c4cbb 100644
@@ -879,6 +879,7 @@ static int gmc_v9_0_sw_init(void *handle)
 	 */
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 44;
+	adev->need_swiotlb = adev->sysmem_max_io > (1 << dma_bits);
 	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
 	if (r) {
 		adev->need_dma32 = true;
Signature · 6 lines
2.14.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): [email protected]

#2 lore raw

Am 07.02.2018 um 12:04 schrieb Chunming Zhou:

Quoted 42 lines

get the max io mapping address of system memory to see if it is over our card accessing range.

Change-Id Ibc38dbd34a20af5b4a4b1ed154c14e1c58aa4c55
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        |  3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 14 ++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  6 +++---
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c      |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c      |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      |  1 +
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c      |  1 +
  7 files changed, 24 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index 257424dd8a52..34a6814e94f9 100644
@@ -1437,6 +1437,7 @@ struct amdgpu_device {
  	const struct amdgpu_asic_funcs	*asic_funcs;
  	bool				shutdown;
  	bool				need_dma32;
+	bool				need_swiotlb;
  	bool				accel_working;
  	struct work_struct		reset_work;
  	struct notifier_block		acpi_nb;
@@ -1629,6 +1630,8 @@ struct amdgpu_device {
  	unsigned long last_mm_index;
  	bool                            in_gpu_reset;
  	struct mutex  lock_reset;
+
+	u64				sysmem_max_io;
  };
 
  static inline struct amdgpu_device *amdgpu_ttm_adev(struct ttm_bo_device *bdev)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0 -0
index 850453e897f9..c4bca62eeff1 100644
@@ -1742,6 +1742,19 @@ bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)
  	return amdgpu_device_asic_has_dc_support(adev->asic_type);

drivers/gpu/drm/amd/amdgpu/amdgpu_device.c bool amdgpu_device_has_dc_support(struct amdgpu_device *adev) · line 1752

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8 -0
  }
 
+static void amdgpu_device_get_max_io_of_sysmem(struct amdgpu_device *adev)
+{
+	struct resource *tmp;
+
+	for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) {
+		if (tmp->flags == (IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY))
+			adev->sysmem_max_io = max(adev->sysmem_max_io,
+						  tmp->end);

Nifty idea. I was thinking about using max_pfn, but taking a look at iomem_resource is indeed much better.

But please drop the tmp->flags check, we need to make sure that we handle hot plugged memory and maybe other IO resources in the future as well.

Might be a good idea to make that a general drm function and fix radeon as well, see drm_arch_can_wc_memory() as well. At minimum I would send it to dri-devel for review as well.

Regards,
Christian.

Quoted 88 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6 -0
+	}
+	DRM_INFO("System Ram max io address is 0x%llx\n", adev->sysmem_max_io);
+}
+
+
  /**
   * amdgpu_device_init - initialize the driver
   *
@@ -1795,6 +1808,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
  	adev->gc_cac_wreg = &amdgpu_invalid_wreg;
  	adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
  	adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
+	amdgpu_device_get_max_io_of_sysmem(adev);
 
  	DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
  		 amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -3
index 95f990140f2a..a021de9629ad 100644
@@ -1018,7 +1018,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
  	}
 
  #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
+	if (adev->need_swiotlb && swiotlb_nr_tbl()) {
  		return ttm_dma_populate(&gtt->ttm, adev->dev, ctx);
  	}
  #endif
@@ -1045,7 +1045,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
  	adev = amdgpu_ttm_adev(ttm->bdev);
 
  #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
+	if (adev->need_swiotlb && swiotlb_nr_tbl()) {
  		ttm_dma_unpopulate(&gtt->ttm, adev->dev);
  		return;
  	}
@@ -2007,7 +2007,7 @@ static int amdgpu_ttm_debugfs_init(struct amdgpu_device *adev)
  	count = ARRAY_SIZE(amdgpu_ttm_debugfs_list);
 
  #ifdef CONFIG_SWIOTLB
-	if (!swiotlb_nr_tbl())
+	if (!(adev->need_swiotlb && swiotlb_nr_tbl()))
  		--count;
  #endif
 
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +1 -0
index 5eacc0819b66..588c900075da 100644
@@ -855,6 +855,7 @@ static int gmc_v6_0_sw_init(void *handle)
 
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = adev->sysmem_max_io > (1 << dma_bits);
  	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
  	if (r) {
  		adev->need_dma32 = true;
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +1 -0
index ce7f484f86f9..1723d2151f0b 100644
@@ -1003,6 +1003,7 @@ static int gmc_v7_0_sw_init(void *handle)
  	 */
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = adev->sysmem_max_io > (1 << dma_bits);
  	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
  	if (r) {
  		adev->need_dma32 = true;
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +1 -0
index f53f3936fd4f..1f209f92a2fd 100644
@@ -1101,6 +1101,7 @@ static int gmc_v8_0_sw_init(void *handle)
  	 */
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = adev->sysmem_max_io > ((u64)1 << dma_bits);
  	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
  	if (r) {
  		adev->need_dma32 = true;
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index 2c60981d2eec..da7ab46c4cbb 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 885

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
@@ -879,6 +879,7 @@ static int gmc_v9_0_sw_init(void *handle)
  	 */
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 44;
+	adev->need_swiotlb = adev->sysmem_max_io > (1 << dma_bits);
  	r = pci_set_dma_mask(adev->pdev, DMA_BIT_MASK(dma_bits));
  	if (r) {
  		adev->need_dma32 = true;

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