Skip to contentSkip to conversation

drm: add func to get max iomem address

PATCH In review Chunming Zhou 3 participants 5 messages Feb 8, 2018 – Feb 19, 2018

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

PATCH 1/3 drm: add func to get max iomem address

it will be used to check if the driver needs swiotlb

Change-Id Idbe47af8f12032d4803bb3d47273e807f19169c3
---
 include/drm/drm_cache.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/drm/drm_cache.h +13 -0
index beab0f0d0cfb..442c9ba63d03 100644
@@ -39,6 +39,19 @@ void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
 void drm_clflush_sg(struct sg_table *st);
 void drm_clflush_virt_range(void *addr, unsigned long length);
 
+static inline u64 drm_get_max_iomem(void)
+{
+	struct resource *tmp;
+	u64 max_iomem = 0;
+
+	for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) {
+		max_iomem = max(max_iomem,  tmp->end);
+	}
+
+	return max_iomem;
+}
+
+
 static inline bool drm_arch_can_wc_memory(void)
 {
 #if defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
Signature · 6 lines
2.14.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 2/3 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     | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
 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 ++
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 2 ++
 6 files changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 257424dd8a52..627a06185368 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;
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 +2 -0
index 5eacc0819b66..63d0720ac21f 100644
@@ -22,6 +22,7 @@
  */
 #include <linux/firmware.h>
 #include <drm/drmP.h>
+#include <drm/drm_cache.h>
 #include "amdgpu.h"
 #include "gmc_v6_0.h"
 #include "amdgpu_ucode.h"
@@ -855,6 +856,7 @@ static int gmc_v6_0_sw_init(void *handle)
 
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = drm_get_max_iomem() > ((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_v7_0.c +2 -0
index ce7f484f86f9..f70a81fcadec 100644
@@ -22,6 +22,7 @@
  */
 #include <linux/firmware.h>
 #include <drm/drmP.h>
+#include <drm/drm_cache.h>
 #include "amdgpu.h"
 #include "cikd.h"
 #include "cik.h"
@@ -1003,6 +1004,7 @@ static int gmc_v7_0_sw_init(void *handle)
 	 */
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = drm_get_max_iomem() > ((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_v8_0.c +2 -0
index f53f3936fd4f..21fe9afb6e73 100644
@@ -22,6 +22,7 @@
  */
 #include <linux/firmware.h>
 #include <drm/drmP.h>
+#include <drm/drm_cache.h>
 #include "amdgpu.h"
 #include "gmc_v8_0.h"
 #include "amdgpu_ucode.h"
@@ -1101,6 +1102,7 @@ static int gmc_v8_0_sw_init(void *handle)
 	 */
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = drm_get_max_iomem() > ((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 +2 -0
index 2c60981d2eec..8730768efd13 100644
@@ -21,6 +21,7 @@
  *
  */
 #include <linux/firmware.h>
+#include <drm/drm_cache.h>
 #include "amdgpu.h"
 #include "gmc_v9_0.h"
 #include "amdgpu_atomfirmware.h"
@@ -879,6 +880,7 @@ static int gmc_v9_0_sw_init(void *handle)
 	 */
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 44;
+	adev->need_swiotlb = drm_get_max_iomem() > ((u64)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

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#2 lore raw

Re: [PATCH 2/3] drm/amdgpu: only enable swiotlb alloc when need

Am 08.02.2018 um 07:00 schrieb Chunming Zhou:

Quoted 70 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     | 1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 +++---
  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 ++
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 2 ++
  6 files changed, 12 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 257424dd8a52..627a06185368 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;
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..63d0720ac21f 100644
@@ -22,6 +22,7 @@
   */
  #include <linux/firmware.h>
  #include <drm/drmP.h>
+#include <drm/drm_cache.h>
  #include "amdgpu.h"
  #include "gmc_v6_0.h"
  #include "amdgpu_ucode.h"

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c static int gmc_v6_0_sw_init(void *handle) · line 859

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +1 -0
@@ -855,6 +856,7 @@ static int gmc_v6_0_sw_init(void *handle)
 
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);

The code here is mixed up. The check needs to come later, after we tried to set the dma_mask and possible failed.

Same for all other GMC variants as well.

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

Quoted 56 lines
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +0 -0
  	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 +2 -0
index ce7f484f86f9..f70a81fcadec 100644
@@ -22,6 +22,7 @@
   */
  #include <linux/firmware.h>
  #include <drm/drmP.h>
+#include <drm/drm_cache.h>
  #include "amdgpu.h"
  #include "cikd.h"
  #include "cik.h"
@@ -1003,6 +1004,7 @@ static int gmc_v7_0_sw_init(void *handle)
  	 */
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = drm_get_max_iomem() > ((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_v8_0.c +2 -0
index f53f3936fd4f..21fe9afb6e73 100644
@@ -22,6 +22,7 @@
   */
  #include <linux/firmware.h>
  #include <drm/drmP.h>
+#include <drm/drm_cache.h>
  #include "amdgpu.h"
  #include "gmc_v8_0.h"
  #include "amdgpu_ucode.h"
@@ -1101,6 +1102,7 @@ static int gmc_v8_0_sw_init(void *handle)
  	 */
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
+	adev->need_swiotlb = drm_get_max_iomem() > ((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..8730768efd13 100644
@@ -21,6 +21,7 @@
   *
   */
  #include <linux/firmware.h>
+#include <drm/drm_cache.h>
  #include "amdgpu.h"
  #include "gmc_v9_0.h"
  #include "amdgpu_atomfirmware.h"

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

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

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

#3 lore raw

PATCH 3/3 drm/radeon: only enable swiotlb path when need

In reply to Chunming Zhou

swiotlb expands our card accessing range, but its path always is slower than ttm pool allocation.
So add condition to use it.

Change-Id I1802645833155a9cd808913f863981173a82145f
---
 drivers/gpu/drm/radeon/radeon.h        | 1 +
 drivers/gpu/drm/radeon/radeon_device.c | 2 ++
 drivers/gpu/drm/radeon/radeon_ttm.c    | 6 +++---
 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/radeon/radeon.h +1 -0
index d34887873dea..4a2eb409aacc 100644
@@ -2387,6 +2387,7 @@ struct radeon_device {
 	struct radeon_dummy_page	dummy_page;
 	bool				shutdown;
 	bool				need_dma32;
+	bool				need_swiotlb;
 	bool				accel_working;
 	bool				fastfb_working; /* IGP feature*/
 	bool				needs_reset, in_reset;
drivers/gpu/drm/radeon/radeon_device.c +2 -0
index 8d3e3d2e0090..62d8626e1fe8 100644
@@ -29,6 +29,7 @@
 #include <linux/slab.h>
 #include <drm/drmP.h>
 #include <drm/drm_crtc_helper.h>
+#include <drm/drm_cache.h>
 #include <drm/radeon_drm.h>
 #include <linux/pm_runtime.h>
 #include <linux/vgaarb.h>
@@ -1367,6 +1368,7 @@ int radeon_device_init(struct radeon_device *rdev,
 		rdev->need_dma32 = true;
 
 	dma_bits = rdev->need_dma32 ? 32 : 40;
+	rdev->need_swiotlb = drm_get_max_iomem() > ((u64)1 << dma_bits);
 	r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits));
 	if (r) {
 		rdev->need_dma32 = true;
drivers/gpu/drm/radeon/radeon_ttm.c +3 -3
index a0a839bc39bf..c1e3862a48a4 100644
@@ -756,7 +756,7 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
 #endif
 
 #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
+	if (rdev->need_swiotlb && swiotlb_nr_tbl()) {
 		return ttm_dma_populate(&gtt->ttm, rdev->dev, ctx);
 	}
 #endif
@@ -788,7 +788,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
 #endif
 
 #ifdef CONFIG_SWIOTLB
-	if (swiotlb_nr_tbl()) {
+	if (rdev->need_swiotlb && swiotlb_nr_tbl()) {
 		ttm_dma_unpopulate(&gtt->ttm, rdev->dev);
 		return;
 	}
@@ -1155,7 +1155,7 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
 	count = ARRAY_SIZE(radeon_ttm_debugfs_list);
 
 #ifdef CONFIG_SWIOTLB
-	if (!swiotlb_nr_tbl())
+	if (!(rdev->need_swiotlb && swiotlb_nr_tbl()))
 		--count;
 #endif
 
Signature · 6 lines
2.14.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw
In reply to Chunming Zhou
Quoted 17 lines · Chunming Zhou

it will be used to check if the driver needs swiotlb

Change-Id Idbe47af8f12032d4803bb3d47273e807f19169c3
---
 include/drm/drm_cache.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/drm/drm_cache.h +1 -0
index beab0f0d0cfb..442c9ba63d03 100644
@@ -39,6 +39,19 @@ void drm_clflush_pages(struct page *pages[], unsigned long num_pages);
 void drm_clflush_sg(struct sg_table *st);
 void drm_clflush_virt_range(void *addr, unsigned long length);
 
+static inline u64 drm_get_max_iomem(void)

include/drm/drm_cache.h void drm_clflush_pages(struct page *pages[], unsigned long num_pages); · line 52

Quoted 10 lines
include/drm/drm_cache.h +10 -0
+{
+	struct resource *tmp;
+	u64 max_iomem = 0;
+
+	for (tmp = iomem_resource.child; tmp; tmp = tmp->sibling) {
+		max_iomem = max(max_iomem,  tmp->end);
+	}
+
+	return max_iomem;
+}

linux-next noticed a compile warning on this (on some platforms, the max_iomem has the wrong integer size I think). Also, drm_memory.c is a bit a grab-bag of legacy stuff, not sure this is the best place. We're also lacking kerneldoc (plus include stanza) for this new function.

Can you pls fix all that in a follow-up patch?

Thanks, Daniel

Quoted 12 lines
include/drm/drm_cache.h +2 -0
+
+
 static inline bool drm_arch_can_wc_memory(void)
 {
 #if defined(CONFIG_PPC) && !defined(CONFIG_NOT_COHERENT_CACHE)
Signature · 6 lines
2.14.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel