drm/admgpu: add data struct for vram check
Subsystems (2)
PATCH 1/2 drm/admgpu: add data struct for vram check
This patch is to add data struct for vram check.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 +++++ 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +5 -0
@@ -928,6 +928,11 @@ struct amdgpu_device {uint32_t bios_scratch_reg_offset;uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH ]; +/* vram check */ +struct amdgpu_bo *vram_bo; +uint64_t vram_gpu; +void *vram_ptr; +/* Direct GMA */ struct amdgpu_direct_gma direct_gma;/* SSG */
Signature · 1 line
2.25.1
PATCH 2/2 drm/amdgpu: add vram check function for GMC
This will add vram check function for GMC, it will cover gmc v8/9/10
--- 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(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +42 -0
@@ -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); +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 ; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1 -0
@@ -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
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +4 -0
@@ -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);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +5 -1
@@ -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)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -1
@@ -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 ; }/**
Signature · 1 line
2.25.1
Re: [PATCH 2/2] drm/amdgpu: add vram check function for GMC
Quoted 21 lines · Xiaojian
This will add vram check function for GMC, it will cover gmc v8/9/10
Signed-off-by Xiaojian Du <[email protected]>Reviewed-by Huang Rui <[email protected]>--- 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(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1
-0@@ -833,3 +833,45 @@ void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)break ; } } +
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev) · line 846
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +10
-0+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
Quoted 96 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +31
-0+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 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1
-0@@ -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 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +4
-0@@ -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);drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +5
-1@@ -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)drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7
-1@@ -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 ; }/** Signature · 1 line
2.25.1
Re: [PATCH 2/2] drm/amdgpu: add vram check function for GMC
In reply to Xiaojian DuAm 2022-01-13 um 2:45 a.m. schrieb Xiaojian Du:
Quoted 92 lines
This will add vram check function for GMC, it will cover gmc v8/9/10
Signed-off-by Xiaojian Du <[email protected]>Reviewed-by Huang Rui <[email protected]>--- 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(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +42
-0@@ -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); +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 ; +}drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1
-0@@ -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 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +4
-0@@ -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);drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c static int gmc_v8_0_hw_init(void *handle) · line 1248
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +5
-1@@ -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 ;
This could simply be
return amdgpu_gmc_vram_checking(adev);
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +0
-0}static int gmc_v8_0_hw_fini (void *handle)drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0@@ -1771,8 +1771,14 @@ static int gmc_v9_0_hw_init(void *handle) adev->umc.funcs->init_registers (adev);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_hw_init(void *handle) · line 1781
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7
-1r =gmc_v9_0_gart_enable (adev); +if (r) +return r; -return r; + r =amdgpu_gmc_vram_checking (adev); +if (r) +return r; + +return 0 ;
Same as above.
Regards,
Felix
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0
-0}/**
Quoted 2 lines · Xiaojian
This patch is to add data struct for vram check.
The subject has a typo: admgpu -> amdgpu
Quoted 25 lines
Signed-off-by Xiaojian Du <[email protected]>Reviewed-by Huang Rui <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 5 +++++ 1 file changed, 5 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu.h +5
-0@@ -928,6 +928,11 @@ struct amdgpu_device {uint32_t bios_scratch_reg_offset;uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH ]; +/* vram check */ +struct amdgpu_bo *vram_bo; +uint64_t vram_gpu; +void *vram_ptr; +/* Direct GMA */ struct amdgpu_direct_gma direct_gma;/* SSG */ Signature · 1 line
2.25.1