drm/amdgpu: add vram check function for GMC
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: add vram check function for GMC
This will add vram check function for GMC, it will cover gmc v6/7/8/9/10
Signed-off-by Xiaojian Du <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 46 +++++++++++++++++++++++++ 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_v6_0.c | 6 +++- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 6 +++- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 6 +++- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 8 ++++- 7 files changed, 73 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +46 -0
@@ -833,3 +833,49 @@ void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)break ; } } + +int amdgpu_gmc_vram_checking (struct amdgpu_device *adev) +{ +struct amdgpu_bo *vram_bo; +uint64_t vram_gpu; +void *vram_ptr; + +int ret, size =0x100000 ; +uint8_t cptr[10 ]; + + ret =amdgpu_bo_create_kernel (adev, size,PAGE_SIZE , +AMDGPU_GEM_DOMAIN_VRAM , + &vram_bo, + &vram_gpu, + &vram_ptr); +if (ret) +return ret; + +memset (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 (vram_ptr, cptr,10 ); +if (ret) +return ret; + + ret =memcmp (vram_ptr + (size /2 ), cptr,10 ); +if (ret) +return ret; + + ret =memcmp (vram_ptr + size -10 , cptr,10 ); +if (ret) +return ret; + +amdgpu_bo_free_kernel (&vram_bo, &vram_gpu, + &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_v6_0.c +5 -1
@@ -923,7 +923,11 @@ static int gmc_v6_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_v6_0_hw_fini (void *handle)
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +5 -1
@@ -1112,7 +1112,11 @@ static int gmc_v7_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_v7_0_hw_fini (void *handle)
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
Quoted 3 lines · Xiaojian Du
This will add vram check function for GMC, it will cover gmc v6/7/8/9/10
Please provide a better description.
Also, we should either protect the calls to this function with:
if (amdgpu_emu_mode == 1)
or return early in the function if amdgpu_emu_mode != 1.
Alex
Quoted 164 lines
Signed-off-by Xiaojian Du <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 46 +++++++++++++++++++++++++ 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_v6_0.c | 6 +++- drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 6 +++- drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 6 +++- drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 8 ++++- 7 files changed, 73 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +46
-0@@ -833,3 +833,49 @@ void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)break ; } } + +int amdgpu_gmc_vram_checking (struct amdgpu_device *adev) +{ +struct amdgpu_bo *vram_bo; +uint64_t vram_gpu; +void *vram_ptr; + +int ret, size =0x100000 ; +uint8_t cptr[10 ]; + + ret =amdgpu_bo_create_kernel (adev, size,PAGE_SIZE , +AMDGPU_GEM_DOMAIN_VRAM , + &vram_bo, + &vram_gpu, + &vram_ptr); +if (ret) +return ret; + +memset (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 (vram_ptr, cptr,10 ); +if (ret) +return ret; + + ret =memcmp (vram_ptr + (size /2 ), cptr,10 ); +if (ret) +return ret; + + ret =memcmp (vram_ptr + size -10 , cptr,10 ); +if (ret) +return ret; + +amdgpu_bo_free_kernel (&vram_bo, &vram_gpu, + &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_v6_0.c +5
-1@@ -923,7 +923,11 @@ static int gmc_v6_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_v6_0_hw_fini (void *handle)drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +5
-1@@ -1112,7 +1112,11 @@ static int gmc_v7_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_v7_0_hw_fini (void *handle)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
-2@@ -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