1247835Skib/**************************************************************************
2247835Skib *
3247835Skib * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4247835Skib * All Rights Reserved.
5247835Skib *
6247835Skib * Permission is hereby granted, free of charge, to any person obtaining a
7247835Skib * copy of this software and associated documentation files (the
8247835Skib * "Software"), to deal in the Software without restriction, including
9247835Skib * without limitation the rights to use, copy, modify, merge, publish,
10247835Skib * distribute, sub license, and/or sell copies of the Software, and to
11247835Skib * permit persons to whom the Software is furnished to do so, subject to
12247835Skib * the following conditions:
13247835Skib *
14247835Skib * The above copyright notice and this permission notice (including the
15247835Skib * next paragraph) shall be included in all copies or substantial portions
16247835Skib * of the Software.
17247835Skib *
18247835Skib * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19247835Skib * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20247835Skib * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21247835Skib * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22247835Skib * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23247835Skib * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24247835Skib * USE OR OTHER DEALINGS IN THE SOFTWARE.
25247835Skib *
26247835Skib **************************************************************************/
27247835Skib/*
28247835Skib * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29247835Skib */
30247835Skib/* $FreeBSD$ */
31247835Skib
32247835Skib#ifndef _TTM_EXECBUF_UTIL_H_
33247835Skib#define _TTM_EXECBUF_UTIL_H_
34247835Skib
35247835Skib#include <dev/drm2/ttm/ttm_bo_api.h>
36247835Skib
37247835Skib/**
38247835Skib * struct ttm_validate_buffer
39247835Skib *
40247835Skib * @head:           list head for thread-private list.
41247835Skib * @bo:             refcounted buffer object pointer.
42247835Skib * @reserved:       Indicates whether @bo has been reserved for validation.
43247835Skib * @removed:        Indicates whether @bo has been removed from lru lists.
44247835Skib * @put_count:      Number of outstanding references on bo::list_kref.
45247835Skib * @old_sync_obj:   Pointer to a sync object about to be unreferenced
46247835Skib */
47247835Skib
48247835Skibstruct ttm_validate_buffer {
49247835Skib	struct list_head head;
50247835Skib	struct ttm_buffer_object *bo;
51247835Skib	bool reserved;
52247835Skib	bool removed;
53247835Skib	int put_count;
54247835Skib	void *old_sync_obj;
55247835Skib};
56247835Skib
57247835Skib/**
58247835Skib * function ttm_eu_backoff_reservation
59247835Skib *
60247835Skib * @list:     thread private list of ttm_validate_buffer structs.
61247835Skib *
62247835Skib * Undoes all buffer validation reservations for bos pointed to by
63247835Skib * the list entries.
64247835Skib */
65247835Skib
66247835Skibextern void ttm_eu_backoff_reservation(struct list_head *list);
67247835Skib
68247835Skib/**
69247835Skib * function ttm_eu_reserve_buffers
70247835Skib *
71247835Skib * @list:    thread private list of ttm_validate_buffer structs.
72247835Skib *
73247835Skib * Tries to reserve bos pointed to by the list entries for validation.
74247835Skib * If the function returns 0, all buffers are marked as "unfenced",
75247835Skib * taken off the lru lists and are not synced for write CPU usage.
76247835Skib *
77247835Skib * If the function detects a deadlock due to multiple threads trying to
78247835Skib * reserve the same buffers in reverse order, all threads except one will
79247835Skib * back off and retry. This function may sleep while waiting for
80247835Skib * CPU write reservations to be cleared, and for other threads to
81247835Skib * unreserve their buffers.
82247835Skib *
83247835Skib * This function may return -ERESTART or -EAGAIN if the calling process
84247835Skib * receives a signal while waiting. In that case, no buffers on the list
85247835Skib * will be reserved upon return.
86247835Skib *
87247835Skib * Buffers reserved by this function should be unreserved by
88247835Skib * a call to either ttm_eu_backoff_reservation() or
89247835Skib * ttm_eu_fence_buffer_objects() when command submission is complete or
90247835Skib * has failed.
91247835Skib */
92247835Skib
93247835Skibextern int ttm_eu_reserve_buffers(struct list_head *list);
94247835Skib
95247835Skib/**
96247835Skib * function ttm_eu_fence_buffer_objects.
97247835Skib *
98247835Skib * @list:        thread private list of ttm_validate_buffer structs.
99247835Skib * @sync_obj:    The new sync object for the buffers.
100247835Skib *
101247835Skib * This function should be called when command submission is complete, and
102247835Skib * it will add a new sync object to bos pointed to by entries on @list.
103247835Skib * It also unreserves all buffers, putting them on lru lists.
104247835Skib *
105247835Skib */
106247835Skib
107247835Skibextern void ttm_eu_fence_buffer_objects(struct list_head *list, void *sync_obj);
108247835Skib
109247835Skib#endif
110