[PATCH 1/4] drm/amdgpu: Macros for vram physical addr calculation

Christian König christian.koenig at amd.com
Fri Mar 26 09:12:43 UTC 2021


Am 25.03.21 um 17:38 schrieb Oak Zeng:
> Add one macro to calculate BO's GPU physical address.
> And another one to calculate BO's CPU physical address.
>
> Signed-off-by: Oak Zeng <Oak.Zeng at amd.com>
> Suggested-by: Lijo Lazar <lijo.lazar at amd.com>

Yeah, I though about doing that as well for a while.

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
> index 2ee8d1b..7cd9d34 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h
> @@ -283,6 +283,9 @@ struct amdgpu_gmc {
>   #define amdgpu_gmc_get_vm_pde(adev, level, dst, flags) (adev)->gmc.gmc_funcs->get_vm_pde((adev), (level), (dst), (flags))
>   #define amdgpu_gmc_get_vm_pte(adev, mapping, flags) (adev)->gmc.gmc_funcs->get_vm_pte((adev), (mapping), (flags))
>   #define amdgpu_gmc_get_vbios_fb_size(adev) (adev)->gmc.gmc_funcs->get_vbios_fb_size((adev))
> +#define amdgpu_gmc_gpu_va2pa(adev, va) (va - (adev)->gmc.vram_start + (adev)->vm_manager.vram_base_offset)
> +#define amdgpu_gmc_gpu_pa(adev, bo) amdgpu_gmc_gpu_va2pa(adev, amdgpu_bo_gpu_offset(bo))
> +#define amdgpu_gmc_cpu_pa(adev, bo) (amdgpu_bo_gpu_offset(bo) - (adev)->gmc.vram_start + (adev)->gmc.aper_base)

Well multiple problems here. First of all I suggest to use inline 
functions instead, there shouldn't really be a need for macros.

Then the term va is used misleading here. A va (virtual address) is 
usually together with the VM code as virtual address on an userspace 
application. But here the virtual address in VMID0 is meant which is 
usually called mc address or just gpu address.

Then we should somehow make it clear that this is about VRAM and doesn't 
work for GTT or the AGP window.

So I rather suggest to name those amdgpu_gmc_vram_mc2pa(), 
amdgpu_gmc_vram_pa() and amdgpu_gmc_vram_cpu_addr().

Regards,
Christian.

>   
>   /**
>    * amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR



More information about the amd-gfx mailing list