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

dma-buf: drop excl_fence parameter from dma_resv_get_fences

Returning the exclusive fence separately is no longer used.

Instead add a write parameter to indicate the use case.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20211207123411.167006-4-christian.koenig@amd.com

+30 -57
+17 -29
drivers/dma-buf/dma-resv.c
··· 542 542 * dma_resv_get_fences - Get an object's shared and exclusive 543 543 * fences without update side lock held 544 544 * @obj: the reservation object 545 - * @fence_excl: the returned exclusive fence (or NULL) 546 - * @shared_count: the number of shared fences returned 547 - * @shared: the array of shared fence ptrs returned (array is krealloc'd to 548 - * the required size, and must be freed by caller) 545 + * @write: true if we should return all fences 546 + * @num_fences: the number of fences returned 547 + * @fences: the array of fence ptrs returned (array is krealloc'd to the 548 + * required size, and must be freed by caller) 549 549 * 550 - * Retrieve all fences from the reservation object. If the pointer for the 551 - * exclusive fence is not specified the fence is put into the array of the 552 - * shared fences as well. Returns either zero or -ENOMEM. 550 + * Retrieve all fences from the reservation object. 551 + * Returns either zero or -ENOMEM. 553 552 */ 554 - int dma_resv_get_fences(struct dma_resv *obj, struct dma_fence **fence_excl, 555 - unsigned int *shared_count, struct dma_fence ***shared) 553 + int dma_resv_get_fences(struct dma_resv *obj, bool write, 554 + unsigned int *num_fences, struct dma_fence ***fences) 556 555 { 557 556 struct dma_resv_iter cursor; 558 557 struct dma_fence *fence; 559 558 560 - *shared_count = 0; 561 - *shared = NULL; 559 + *num_fences = 0; 560 + *fences = NULL; 562 561 563 - if (fence_excl) 564 - *fence_excl = NULL; 565 - 566 - dma_resv_iter_begin(&cursor, obj, true); 562 + dma_resv_iter_begin(&cursor, obj, write); 567 563 dma_resv_for_each_fence_unlocked(&cursor, fence) { 568 564 569 565 if (dma_resv_iter_is_restarted(&cursor)) { 570 566 unsigned int count; 571 567 572 - while (*shared_count) 573 - dma_fence_put((*shared)[--(*shared_count)]); 568 + while (*num_fences) 569 + dma_fence_put((*fences)[--(*num_fences)]); 574 570 575 - if (fence_excl) 576 - dma_fence_put(*fence_excl); 577 - 578 - count = cursor.shared_count; 579 - count += fence_excl ? 0 : 1; 571 + count = cursor.shared_count + 1; 580 572 581 573 /* Eventually re-allocate the array */ 582 - *shared = krealloc_array(*shared, count, 574 + *fences = krealloc_array(*fences, count, 583 575 sizeof(void *), 584 576 GFP_KERNEL); 585 - if (count && !*shared) { 577 + if (count && !*fences) { 586 578 dma_resv_iter_end(&cursor); 587 579 return -ENOMEM; 588 580 } 589 581 } 590 582 591 - dma_fence_get(fence); 592 - if (dma_resv_iter_is_exclusive(&cursor) && fence_excl) 593 - *fence_excl = fence; 594 - else 595 - (*shared)[(*shared_count)++] = fence; 583 + (*fences)[(*num_fences)++] = dma_fence_get(fence); 596 584 } 597 585 dma_resv_iter_end(&cursor); 598 586
+5 -21
drivers/dma-buf/st-dma-resv.c
··· 275 275 276 276 static int test_get_fences(void *arg, bool shared) 277 277 { 278 - struct dma_fence *f, *excl = NULL, **fences = NULL; 278 + struct dma_fence *f, **fences = NULL; 279 279 struct dma_resv resv; 280 280 int r, i; 281 281 ··· 304 304 } 305 305 dma_resv_unlock(&resv); 306 306 307 - r = dma_resv_get_fences(&resv, &excl, &i, &fences); 307 + r = dma_resv_get_fences(&resv, shared, &i, &fences); 308 308 if (r) { 309 309 pr_err("get_fences failed\n"); 310 310 goto err_free; 311 311 } 312 312 313 - if (shared) { 314 - if (excl != NULL) { 315 - pr_err("get_fences returned unexpected excl fence\n"); 316 - goto err_free; 317 - } 318 - if (i != 1 || fences[0] != f) { 319 - pr_err("get_fences returned unexpected shared fence\n"); 320 - goto err_free; 321 - } 322 - } else { 323 - if (excl != f) { 324 - pr_err("get_fences returned unexpected excl fence\n"); 325 - goto err_free; 326 - } 327 - if (i != 0) { 328 - pr_err("get_fences returned unexpected shared fence\n"); 329 - goto err_free; 330 - } 313 + if (i != 1 || fences[0] != f) { 314 + pr_err("get_fences returned unexpected fence\n"); 315 + goto err_free; 331 316 } 332 317 333 318 dma_fence_signal(f); 334 319 err_free: 335 - dma_fence_put(excl); 336 320 while (i--) 337 321 dma_fence_put(fences[i]); 338 322 kfree(fences);
+4 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
··· 200 200 goto unpin; 201 201 } 202 202 203 - r = dma_resv_get_fences(new_abo->tbo.base.resv, NULL, 204 - &work->shared_count, &work->shared); 203 + /* TODO: Unify this with other drivers */ 204 + r = dma_resv_get_fences(new_abo->tbo.base.resv, true, 205 + &work->shared_count, 206 + &work->shared); 205 207 if (unlikely(r != 0)) { 206 208 DRM_ERROR("failed to get fences for buffer\n"); 207 209 goto unpin;
+1 -1
drivers/gpu/drm/amd/amdgpu/amdgpu_ids.c
··· 112 112 unsigned count; 113 113 int r; 114 114 115 - r = dma_resv_get_fences(resv, NULL, &count, &fences); 115 + r = dma_resv_get_fences(resv, true, &count, &fences); 116 116 if (r) 117 117 goto fallback; 118 118
+1 -2
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c
··· 189 189 continue; 190 190 191 191 if (bo->flags & ETNA_SUBMIT_BO_WRITE) { 192 - ret = dma_resv_get_fences(robj, NULL, 193 - &bo->nr_shared, 192 + ret = dma_resv_get_fences(robj, true, &bo->nr_shared, 194 193 &bo->shared); 195 194 if (ret) 196 195 return ret;
+2 -2
include/linux/dma-resv.h
··· 458 458 int dma_resv_reserve_shared(struct dma_resv *obj, unsigned int num_fences); 459 459 void dma_resv_add_shared_fence(struct dma_resv *obj, struct dma_fence *fence); 460 460 void dma_resv_add_excl_fence(struct dma_resv *obj, struct dma_fence *fence); 461 - int dma_resv_get_fences(struct dma_resv *obj, struct dma_fence **pfence_excl, 462 - unsigned *pshared_count, struct dma_fence ***pshared); 461 + int dma_resv_get_fences(struct dma_resv *obj, bool write, 462 + unsigned int *num_fences, struct dma_fence ***fences); 463 463 int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src); 464 464 long dma_resv_wait_timeout(struct dma_resv *obj, bool wait_all, bool intr, 465 465 unsigned long timeout);