Commit 479e3b02 authored by Xiaojian Du's avatar Xiaojian Du Committed by Alex Deucher

drm/amdgpu: add vram check function for GMC

This patch will add vram check function for GMC block.
It will write pattern data to the vram and then read back from the vram,
so that to verify the work status of vram.
This patch  will cover gmc v6/7/8/9/10.
Signed-off-by: default avatarXiaojian Du <Xiaojian.Du@amd.com>
Reviewed-by: default avatarHuang Rui <ray.huang@amd.com>
Acked-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent a5e7ffa1
...@@ -822,3 +822,49 @@ void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev) ...@@ -822,3 +822,49 @@ void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)
break; 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;
}
...@@ -336,4 +336,5 @@ void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev); ...@@ -336,4 +336,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_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_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo);
uint64_t amdgpu_gmc_vram_cpu_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 #endif
...@@ -1057,6 +1057,12 @@ static int gmc_v10_0_hw_init(void *handle) ...@@ -1057,6 +1057,12 @@ static int gmc_v10_0_hw_init(void *handle)
if (r) if (r)
return r; return r;
if (amdgpu_emu_mode == 1) {
r = amdgpu_gmc_vram_checking(adev);
if (r)
return r;
}
if (adev->umc.funcs && adev->umc.funcs->init_registers) if (adev->umc.funcs && adev->umc.funcs->init_registers)
adev->umc.funcs->init_registers(adev); adev->umc.funcs->init_registers(adev);
......
...@@ -922,6 +922,9 @@ static int gmc_v6_0_hw_init(void *handle) ...@@ -922,6 +922,9 @@ static int gmc_v6_0_hw_init(void *handle)
if (r) if (r)
return r; return r;
if (amdgpu_emu_mode == 1)
return amdgpu_gmc_vram_checking(adev);
else
return r; return r;
} }
......
...@@ -1111,6 +1111,9 @@ static int gmc_v7_0_hw_init(void *handle) ...@@ -1111,6 +1111,9 @@ static int gmc_v7_0_hw_init(void *handle)
if (r) if (r)
return r; return r;
if (amdgpu_emu_mode == 1)
return amdgpu_gmc_vram_checking(adev);
else
return r; return r;
} }
......
...@@ -1242,6 +1242,9 @@ static int gmc_v8_0_hw_init(void *handle) ...@@ -1242,6 +1242,9 @@ static int gmc_v8_0_hw_init(void *handle)
if (r) if (r)
return r; return r;
if (amdgpu_emu_mode == 1)
return amdgpu_gmc_vram_checking(adev);
else
return r; return r;
} }
......
...@@ -1815,7 +1815,7 @@ static int gmc_v9_0_hw_init(void *handle) ...@@ -1815,7 +1815,7 @@ static int gmc_v9_0_hw_init(void *handle)
{ {
struct amdgpu_device *adev = (struct amdgpu_device *)handle; struct amdgpu_device *adev = (struct amdgpu_device *)handle;
bool value; bool value;
int i; int i, r;
/* The sequence of these two function calls matters.*/ /* The sequence of these two function calls matters.*/
gmc_v9_0_init_golden_registers(adev); gmc_v9_0_init_golden_registers(adev);
...@@ -1850,7 +1850,14 @@ static int gmc_v9_0_hw_init(void *handle) ...@@ -1850,7 +1850,14 @@ static int gmc_v9_0_hw_init(void *handle)
if (adev->umc.funcs && adev->umc.funcs->init_registers) if (adev->umc.funcs && adev->umc.funcs->init_registers)
adev->umc.funcs->init_registers(adev); adev->umc.funcs->init_registers(adev);
return gmc_v9_0_gart_enable(adev); r = gmc_v9_0_gart_enable(adev);
if (r)
return r;
if (amdgpu_emu_mode == 1)
return amdgpu_gmc_vram_checking(adev);
else
return r;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment