diff options
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c index e06d7919747a..141d11dfede0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | |||
@@ -209,15 +209,13 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size, | |||
209 | void **cpu_ptr) | 209 | void **cpu_ptr) |
210 | { | 210 | { |
211 | struct amdgpu_device *adev = (struct amdgpu_device *)kgd; | 211 | struct amdgpu_device *adev = (struct amdgpu_device *)kgd; |
212 | struct kgd_mem **mem = (struct kgd_mem **) mem_obj; | 212 | struct amdgpu_bo *bo = NULL; |
213 | int r; | 213 | int r; |
214 | 214 | uint64_t gpu_addr_tmp = 0; | |
215 | *mem = kmalloc(sizeof(struct kgd_mem), GFP_KERNEL); | 215 | void *cpu_ptr_tmp = NULL; |
216 | if ((*mem) == NULL) | ||
217 | return -ENOMEM; | ||
218 | 216 | ||
219 | r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_GTT, | 217 | r = amdgpu_bo_create(adev, size, PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_GTT, |
220 | AMDGPU_GEM_CREATE_CPU_GTT_USWC, NULL, NULL, &(*mem)->bo); | 218 | AMDGPU_GEM_CREATE_CPU_GTT_USWC, NULL, NULL, &bo); |
221 | if (r) { | 219 | if (r) { |
222 | dev_err(adev->dev, | 220 | dev_err(adev->dev, |
223 | "failed to allocate BO for amdkfd (%d)\n", r); | 221 | "failed to allocate BO for amdkfd (%d)\n", r); |
@@ -225,52 +223,53 @@ int alloc_gtt_mem(struct kgd_dev *kgd, size_t size, | |||
225 | } | 223 | } |
226 | 224 | ||
227 | /* map the buffer */ | 225 | /* map the buffer */ |
228 | r = amdgpu_bo_reserve((*mem)->bo, true); | 226 | r = amdgpu_bo_reserve(bo, true); |
229 | if (r) { | 227 | if (r) { |
230 | dev_err(adev->dev, "(%d) failed to reserve bo for amdkfd\n", r); | 228 | dev_err(adev->dev, "(%d) failed to reserve bo for amdkfd\n", r); |
231 | goto allocate_mem_reserve_bo_failed; | 229 | goto allocate_mem_reserve_bo_failed; |
232 | } | 230 | } |
233 | 231 | ||
234 | r = amdgpu_bo_pin((*mem)->bo, AMDGPU_GEM_DOMAIN_GTT, | 232 | r = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT, |
235 | &(*mem)->gpu_addr); | 233 | &gpu_addr_tmp); |
236 | if (r) { | 234 | if (r) { |
237 | dev_err(adev->dev, "(%d) failed to pin bo for amdkfd\n", r); | 235 | dev_err(adev->dev, "(%d) failed to pin bo for amdkfd\n", r); |
238 | goto allocate_mem_pin_bo_failed; | 236 | goto allocate_mem_pin_bo_failed; |
239 | } | 237 | } |
240 | *gpu_addr = (*mem)->gpu_addr; | ||
241 | 238 | ||
242 | r = amdgpu_bo_kmap((*mem)->bo, &(*mem)->cpu_ptr); | 239 | r = amdgpu_bo_kmap(bo, &cpu_ptr_tmp); |
243 | if (r) { | 240 | if (r) { |
244 | dev_err(adev->dev, | 241 | dev_err(adev->dev, |
245 | "(%d) failed to map bo to kernel for amdkfd\n", r); | 242 | "(%d) failed to map bo to kernel for amdkfd\n", r); |
246 | goto allocate_mem_kmap_bo_failed; | 243 | goto allocate_mem_kmap_bo_failed; |
247 | } | 244 | } |
248 | *cpu_ptr = (*mem)->cpu_ptr; | ||
249 | 245 | ||
250 | amdgpu_bo_unreserve((*mem)->bo); | 246 | *mem_obj = bo; |
247 | *gpu_addr = gpu_addr_tmp; | ||
248 | *cpu_ptr = cpu_ptr_tmp; | ||
249 | |||
250 | amdgpu_bo_unreserve(bo); | ||
251 | 251 | ||
252 | return 0; | 252 | return 0; |
253 | 253 | ||
254 | allocate_mem_kmap_bo_failed: | 254 | allocate_mem_kmap_bo_failed: |
255 | amdgpu_bo_unpin((*mem)->bo); | 255 | amdgpu_bo_unpin(bo); |
256 | allocate_mem_pin_bo_failed: | 256 | allocate_mem_pin_bo_failed: |
257 | amdgpu_bo_unreserve((*mem)->bo); | 257 | amdgpu_bo_unreserve(bo); |
258 | allocate_mem_reserve_bo_failed: | 258 | allocate_mem_reserve_bo_failed: |
259 | amdgpu_bo_unref(&(*mem)->bo); | 259 | amdgpu_bo_unref(&bo); |
260 | 260 | ||
261 | return r; | 261 | return r; |
262 | } | 262 | } |
263 | 263 | ||
264 | void free_gtt_mem(struct kgd_dev *kgd, void *mem_obj) | 264 | void free_gtt_mem(struct kgd_dev *kgd, void *mem_obj) |
265 | { | 265 | { |
266 | struct kgd_mem *mem = (struct kgd_mem *) mem_obj; | 266 | struct amdgpu_bo *bo = (struct amdgpu_bo *) mem_obj; |
267 | 267 | ||
268 | amdgpu_bo_reserve(mem->bo, true); | 268 | amdgpu_bo_reserve(bo, true); |
269 | amdgpu_bo_kunmap(mem->bo); | 269 | amdgpu_bo_kunmap(bo); |
270 | amdgpu_bo_unpin(mem->bo); | 270 | amdgpu_bo_unpin(bo); |
271 | amdgpu_bo_unreserve(mem->bo); | 271 | amdgpu_bo_unreserve(bo); |
272 | amdgpu_bo_unref(&(mem->bo)); | 272 | amdgpu_bo_unref(&(bo)); |
273 | kfree(mem); | ||
274 | } | 273 | } |
275 | 274 | ||
276 | void get_local_mem_info(struct kgd_dev *kgd, | 275 | void get_local_mem_info(struct kgd_dev *kgd, |