All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: "Du, Xiaojian" <Xiaojian.Du@amd.com>
Cc: "Deucher, Alexander" <Alexander.Deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"amd-gfx@lists.freedesktop.org" <amd-gfx@lists.freedesktop.org>
Subject: Re: [PATCH 2/2] drm/amdgpu: add vram check function for GMC
Date: Thu, 13 Jan 2022 16:02:49 +0800	[thread overview]
Message-ID: <Yd/cqSyOWt8Ye7UL@amd.com> (raw)
In-Reply-To: <20220113074526.29827-2-Xiaojian.Du@amd.com>

On Thu, Jan 13, 2022 at 03:45:26PM +0800, Du, Xiaojian wrote:
> This will add vram check function for GMC, it will cover gmc v8/9/10
> 
> Signed-off-by: Xiaojian Du <Xiaojian.Du@amd.com>
> Reviewed-by: Huang Rui <ray.huang@amd.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 42 +++++++++++++++++++++++++
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  1 +
>  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c  |  4 +++
>  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   |  6 +++-
>  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   |  8 ++++-
>  5 files changed, 59 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> index 83f26bca7dac..dbc0de89d7e4 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
> @@ -833,3 +833,45 @@ void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)
>  		break;
>  	}
>  }
> +
> +int amdgpu_gmc_vram_checking(struct amdgpu_device *adev)
> +{
> +	int ret, size = 0x100000;
> +	uint8_t cptr[10];
> +
> +	ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
> +				AMDGPU_GEM_DOMAIN_VRAM,
> +				&adev->vram_bo,
> +				&adev->vram_gpu,
> +				&adev->vram_ptr);

Since we only use vram_bo/vram_gpu/vram_ptr only one time in this function,
we won't need add them into global adev structure.

We can define them as local variables in this function, after finish the
vram verification, the buffer and local variables will be freed as well.

Thanks,
Ray

> +	if (ret)
> +		return ret;
> +
> +	memset(adev->vram_ptr, 0x86, size);
> +	memset(cptr, 0x86, 10);
> +
> +	/**
> +	* Check the start, the mid, and the end of the memory if the content of
> +	* each byte is the pattern "0x86". If yes, we suppose the vram bo is
> +	* workable.
> +	*
> +	* Note: If check the each byte of whole 1M bo, it will cost too many
> +	* seconds, so here, we just pick up three parts for emulation.
> +	*/
> +	ret = memcmp(adev->vram_ptr, cptr, 10);
> +	if (ret)
> +		return ret;
> +
> +	ret = memcmp(adev->vram_ptr + (size / 2), cptr, 10);
> +	if (ret)
> +		return ret;
> +
> +	ret = memcmp(adev->vram_ptr + size - 10, cptr, 10);
> +	if (ret)
> +		return ret;
> +
> +	amdgpu_bo_free_kernel(&adev->vram_bo, &adev->vram_gpu,
> +			&adev->vram_ptr);
> +
> +	return 0;
> +}
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
> index 82ec665b366c..f06af61378ef 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
> @@ -343,4 +343,5 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev);
>  uint64_t amdgpu_gmc_vram_mc2pa(struct amdgpu_device *adev, uint64_t mc_addr);
>  uint64_t amdgpu_gmc_vram_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo);
>  uint64_t amdgpu_gmc_vram_cpu_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo);
> +int amdgpu_gmc_vram_checking(struct amdgpu_device *adev);
>  #endif
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
> index 3915ba837596..5e407c88c8d0 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c
> @@ -1048,6 +1048,10 @@ static int gmc_v10_0_hw_init(void *handle)
>  	if (r)
>  		return r;
>  
> +	r = amdgpu_gmc_vram_checking(adev);
> +	if (r)
> +		return r;
> +
>  	if (adev->umc.funcs && adev->umc.funcs->init_registers)
>  		adev->umc.funcs->init_registers(adev);
>  
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> index 9a3fc0926903..6c94a9712a3a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
> @@ -1241,7 +1241,11 @@ static int gmc_v8_0_hw_init(void *handle)
>  	if (r)
>  		return r;
>  
> -	return r;
> +	r = amdgpu_gmc_vram_checking(adev);
> +	if (r)
> +		return r;
> +
> +	return 0;
>  }
>  
>  static int gmc_v8_0_hw_fini(void *handle)
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> index ce7d438eeabe..1ea18b4ff63f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> @@ -1771,8 +1771,14 @@ static int gmc_v9_0_hw_init(void *handle)
>  		adev->umc.funcs->init_registers(adev);
>  
>  	r = gmc_v9_0_gart_enable(adev);
> +	if (r)
> +		return r;
>  
> -	return r;
> +	r = amdgpu_gmc_vram_checking(adev);
> +	if (r)
> +		return r;
> +
> +	return 0;
>  }
>  
>  /**
> -- 
> 2.25.1
> 

  reply	other threads:[~2022-01-13  8:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13  7:45 [PATCH 1/2] drm/admgpu: add data struct for vram check Xiaojian Du
2022-01-13  7:45 ` [PATCH 2/2] drm/amdgpu: add vram check function for GMC Xiaojian Du
2022-01-13  8:02   ` Huang Rui [this message]
2022-01-13 16:03   ` Felix Kuehling
2022-01-13  7:55 ` [PATCH 1/2] drm/admgpu: add data struct for vram check Huang Rui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yd/cqSyOWt8Ye7UL@amd.com \
    --to=ray.huang@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Xiaojian.Du@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.