18c2ecf20Sopenharmony_ci/**************************************************************************
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci **************************************************************************/
278c2ecf20Sopenharmony_ci/*
288c2ecf20Sopenharmony_ci * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#ifndef _TTM_EXECBUF_UTIL_H_
328c2ecf20Sopenharmony_ci#define _TTM_EXECBUF_UTIL_H_
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#include <linux/list.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include "ttm_bo_api.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/**
398c2ecf20Sopenharmony_ci * struct ttm_validate_buffer
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci * @head:           list head for thread-private list.
428c2ecf20Sopenharmony_ci * @bo:             refcounted buffer object pointer.
438c2ecf20Sopenharmony_ci * @num_shared:     How many shared fences we want to add.
448c2ecf20Sopenharmony_ci */
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct ttm_validate_buffer {
478c2ecf20Sopenharmony_ci	struct list_head head;
488c2ecf20Sopenharmony_ci	struct ttm_buffer_object *bo;
498c2ecf20Sopenharmony_ci	unsigned int num_shared;
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/**
538c2ecf20Sopenharmony_ci * function ttm_eu_backoff_reservation
548c2ecf20Sopenharmony_ci *
558c2ecf20Sopenharmony_ci * @ticket:   ww_acquire_ctx from reserve call
568c2ecf20Sopenharmony_ci * @list:     thread private list of ttm_validate_buffer structs.
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci * Undoes all buffer validation reservations for bos pointed to by
598c2ecf20Sopenharmony_ci * the list entries.
608c2ecf20Sopenharmony_ci */
618c2ecf20Sopenharmony_civoid ttm_eu_backoff_reservation(struct ww_acquire_ctx *ticket,
628c2ecf20Sopenharmony_ci				struct list_head *list);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/**
658c2ecf20Sopenharmony_ci * function ttm_eu_reserve_buffers
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci * @ticket:  [out] ww_acquire_ctx filled in by call, or NULL if only
688c2ecf20Sopenharmony_ci *           non-blocking reserves should be tried.
698c2ecf20Sopenharmony_ci * @list:    thread private list of ttm_validate_buffer structs.
708c2ecf20Sopenharmony_ci * @intr:    should the wait be interruptible
718c2ecf20Sopenharmony_ci * @dups:    [out] optional list of duplicates.
728c2ecf20Sopenharmony_ci * @del_lru: true if BOs should be removed from the LRU.
738c2ecf20Sopenharmony_ci *
748c2ecf20Sopenharmony_ci * Tries to reserve bos pointed to by the list entries for validation.
758c2ecf20Sopenharmony_ci * If the function returns 0, all buffers are marked as "unfenced",
768c2ecf20Sopenharmony_ci * taken off the lru lists and are not synced for write CPU usage.
778c2ecf20Sopenharmony_ci *
788c2ecf20Sopenharmony_ci * If the function detects a deadlock due to multiple threads trying to
798c2ecf20Sopenharmony_ci * reserve the same buffers in reverse order, all threads except one will
808c2ecf20Sopenharmony_ci * back off and retry. This function may sleep while waiting for
818c2ecf20Sopenharmony_ci * CPU write reservations to be cleared, and for other threads to
828c2ecf20Sopenharmony_ci * unreserve their buffers.
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * If intr is set to true, this function may return -ERESTARTSYS if the
858c2ecf20Sopenharmony_ci * calling process receives a signal while waiting. In that case, no
868c2ecf20Sopenharmony_ci * buffers on the list will be reserved upon return.
878c2ecf20Sopenharmony_ci *
888c2ecf20Sopenharmony_ci * If dups is non NULL all buffers already reserved by the current thread
898c2ecf20Sopenharmony_ci * (e.g. duplicates) are added to this list, otherwise -EALREADY is returned
908c2ecf20Sopenharmony_ci * on the first already reserved buffer and all buffers from the list are
918c2ecf20Sopenharmony_ci * unreserved again.
928c2ecf20Sopenharmony_ci *
938c2ecf20Sopenharmony_ci * Buffers reserved by this function should be unreserved by
948c2ecf20Sopenharmony_ci * a call to either ttm_eu_backoff_reservation() or
958c2ecf20Sopenharmony_ci * ttm_eu_fence_buffer_objects() when command submission is complete or
968c2ecf20Sopenharmony_ci * has failed.
978c2ecf20Sopenharmony_ci */
988c2ecf20Sopenharmony_ciint ttm_eu_reserve_buffers(struct ww_acquire_ctx *ticket,
998c2ecf20Sopenharmony_ci			   struct list_head *list, bool intr,
1008c2ecf20Sopenharmony_ci			   struct list_head *dups);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/**
1038c2ecf20Sopenharmony_ci * function ttm_eu_fence_buffer_objects.
1048c2ecf20Sopenharmony_ci *
1058c2ecf20Sopenharmony_ci * @ticket:      ww_acquire_ctx from reserve call
1068c2ecf20Sopenharmony_ci * @list:        thread private list of ttm_validate_buffer structs.
1078c2ecf20Sopenharmony_ci * @fence:       The new exclusive fence for the buffers.
1088c2ecf20Sopenharmony_ci *
1098c2ecf20Sopenharmony_ci * This function should be called when command submission is complete, and
1108c2ecf20Sopenharmony_ci * it will add a new sync object to bos pointed to by entries on @list.
1118c2ecf20Sopenharmony_ci * It also unreserves all buffers, putting them on lru lists.
1128c2ecf20Sopenharmony_ci *
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_civoid ttm_eu_fence_buffer_objects(struct ww_acquire_ctx *ticket,
1158c2ecf20Sopenharmony_ci				 struct list_head *list,
1168c2ecf20Sopenharmony_ci				 struct dma_fence *fence);
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#endif
119