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

drm/amdgpu: add a new helper to free a BO in kernel allocations

Free the BO allocated by amdgpu_bo_create_kernel()

Signed-off-by: Junwei Zhang <Jerry.Zhang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Junwei Zhang and committed by
Alex Deucher
aa1d562e ad2473af

+31
+29
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
··· 287 287 return r; 288 288 } 289 289 290 + /** 291 + * amdgpu_bo_free_kernel - free BO for kernel use 292 + * 293 + * @bo: amdgpu BO to free 294 + * 295 + * unmaps and unpin a BO for kernel internal use. 296 + */ 297 + void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, 298 + void **cpu_addr) 299 + { 300 + if (*bo == NULL) 301 + return; 302 + 303 + if (likely(amdgpu_bo_reserve(*bo, false) == 0)) { 304 + if (cpu_addr) 305 + amdgpu_bo_kunmap(*bo); 306 + 307 + amdgpu_bo_unpin(*bo); 308 + amdgpu_bo_unreserve(*bo); 309 + } 310 + amdgpu_bo_unref(bo); 311 + 312 + if (gpu_addr) 313 + *gpu_addr = 0; 314 + 315 + if (cpu_addr) 316 + *cpu_addr = NULL; 317 + } 318 + 290 319 int amdgpu_bo_create_restricted(struct amdgpu_device *adev, 291 320 unsigned long size, int byte_align, 292 321 bool kernel, u32 domain, u64 flags,
+2
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h
··· 128 128 unsigned long size, int align, 129 129 u32 domain, struct amdgpu_bo **bo_ptr, 130 130 u64 *gpu_addr, void **cpu_addr); 131 + void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr, 132 + void **cpu_addr); 131 133 int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr); 132 134 void amdgpu_bo_kunmap(struct amdgpu_bo *bo); 133 135 struct amdgpu_bo *amdgpu_bo_ref(struct amdgpu_bo *bo);