Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu/virt: add two functions for MM table

Add two functions to allocate & free MM table memory.

Signed-off-by: Xiangliang Yu <Xiangliang.Yu@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Xiangliang Yu and committed by
Alex Deucher
904cd389 a92f5ec0

+48
+46
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
··· 225 225 226 226 return 0; 227 227 } 228 + 229 + /** 230 + * amdgpu_virt_alloc_mm_table() - alloc memory for mm table 231 + * @amdgpu: amdgpu device. 232 + * MM table is used by UVD and VCE for its initialization 233 + * Return: Zero if allocate success. 234 + */ 235 + int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev) 236 + { 237 + int r; 238 + 239 + if (!amdgpu_sriov_vf(adev) || adev->virt.mm_table.gpu_addr) 240 + return 0; 241 + 242 + r = amdgpu_bo_create_kernel(adev, PAGE_SIZE, PAGE_SIZE, 243 + AMDGPU_GEM_DOMAIN_VRAM, 244 + &adev->virt.mm_table.bo, 245 + &adev->virt.mm_table.gpu_addr, 246 + (void *)&adev->virt.mm_table.cpu_addr); 247 + if (r) { 248 + DRM_ERROR("failed to alloc mm table and error = %d.\n", r); 249 + return r; 250 + } 251 + 252 + memset((void *)adev->virt.mm_table.cpu_addr, 0, PAGE_SIZE); 253 + DRM_INFO("MM table gpu addr = 0x%llx, cpu addr = %p.\n", 254 + adev->virt.mm_table.gpu_addr, 255 + adev->virt.mm_table.cpu_addr); 256 + return 0; 257 + } 258 + 259 + /** 260 + * amdgpu_virt_free_mm_table() - free mm table memory 261 + * @amdgpu: amdgpu device. 262 + * Free MM table memory 263 + */ 264 + void amdgpu_virt_free_mm_table(struct amdgpu_device *adev) 265 + { 266 + if (!amdgpu_sriov_vf(adev) || !adev->virt.mm_table.gpu_addr) 267 + return; 268 + 269 + amdgpu_bo_free_kernel(&adev->virt.mm_table.bo, 270 + &adev->virt.mm_table.gpu_addr, 271 + (void *)&adev->virt.mm_table.cpu_addr); 272 + adev->virt.mm_table.gpu_addr = 0; 273 + }
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
··· 98 98 int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init); 99 99 int amdgpu_virt_reset_gpu(struct amdgpu_device *adev); 100 100 int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, bool voluntary); 101 + int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev); 102 + void amdgpu_virt_free_mm_table(struct amdgpu_device *adev); 101 103 102 104 #endif