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

Christian König ckoenig.leichtzumerken at gmail.com
Wed Feb 7 12:21:44 UTC 2018


Am 07.02.2018 um 12:04 schrieb Chunming Zhou:
> get the max io mapping address of system memory to see if it is over
> our card accessing range.
>
> Change-Id: Ibc38dbd34a20af5b4a4b1ed154c14e1c58aa4c55
> Signed-off-by: Chunming Zhou <david1.zhou at amd.com>
> ---
>   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(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> index 257424dd8a52..34a6814e94f9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
> @@ -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)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 850453e897f9..c4bca62eeff1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -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);

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.

> +	}
> +	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,
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 95f990140f2a..a021de9629ad 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -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
>   
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> index 5eacc0819b66..588c900075da 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
> @@ -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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> index ce7f484f86f9..1723d2151f0b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
> @@ -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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> index f53f3936fd4f..1f209f92a2fd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> @@ -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;
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> index 2c60981d2eec..da7ab46c4cbb 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> @@ -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;



More information about the amd-gfx mailing list