xref: /freebsd/sys/dev/drm2/ttm/ttm_execbuf_util.h (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1*592ffb21SWarner Losh /**************************************************************************
2*592ffb21SWarner Losh  *
3*592ffb21SWarner Losh  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
4*592ffb21SWarner Losh  * All Rights Reserved.
5*592ffb21SWarner Losh  *
6*592ffb21SWarner Losh  * Permission is hereby granted, free of charge, to any person obtaining a
7*592ffb21SWarner Losh  * copy of this software and associated documentation files (the
8*592ffb21SWarner Losh  * "Software"), to deal in the Software without restriction, including
9*592ffb21SWarner Losh  * without limitation the rights to use, copy, modify, merge, publish,
10*592ffb21SWarner Losh  * distribute, sub license, and/or sell copies of the Software, and to
11*592ffb21SWarner Losh  * permit persons to whom the Software is furnished to do so, subject to
12*592ffb21SWarner Losh  * the following conditions:
13*592ffb21SWarner Losh  *
14*592ffb21SWarner Losh  * The above copyright notice and this permission notice (including the
15*592ffb21SWarner Losh  * next paragraph) shall be included in all copies or substantial portions
16*592ffb21SWarner Losh  * of the Software.
17*592ffb21SWarner Losh  *
18*592ffb21SWarner Losh  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19*592ffb21SWarner Losh  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20*592ffb21SWarner Losh  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21*592ffb21SWarner Losh  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22*592ffb21SWarner Losh  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23*592ffb21SWarner Losh  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24*592ffb21SWarner Losh  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25*592ffb21SWarner Losh  *
26*592ffb21SWarner Losh  **************************************************************************/
27*592ffb21SWarner Losh /*
28*592ffb21SWarner Losh  * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com>
29*592ffb21SWarner Losh  */
30*592ffb21SWarner Losh 
31*592ffb21SWarner Losh #ifndef _TTM_EXECBUF_UTIL_H_
32*592ffb21SWarner Losh #define _TTM_EXECBUF_UTIL_H_
33*592ffb21SWarner Losh 
34*592ffb21SWarner Losh #include <dev/drm2/ttm/ttm_bo_api.h>
35*592ffb21SWarner Losh 
36*592ffb21SWarner Losh /**
37*592ffb21SWarner Losh  * struct ttm_validate_buffer
38*592ffb21SWarner Losh  *
39*592ffb21SWarner Losh  * @head:           list head for thread-private list.
40*592ffb21SWarner Losh  * @bo:             refcounted buffer object pointer.
41*592ffb21SWarner Losh  * @reserved:       Indicates whether @bo has been reserved for validation.
42*592ffb21SWarner Losh  * @removed:        Indicates whether @bo has been removed from lru lists.
43*592ffb21SWarner Losh  * @put_count:      Number of outstanding references on bo::list_kref.
44*592ffb21SWarner Losh  * @old_sync_obj:   Pointer to a sync object about to be unreferenced
45*592ffb21SWarner Losh  */
46*592ffb21SWarner Losh 
47*592ffb21SWarner Losh struct ttm_validate_buffer {
48*592ffb21SWarner Losh 	struct list_head head;
49*592ffb21SWarner Losh 	struct ttm_buffer_object *bo;
50*592ffb21SWarner Losh 	bool reserved;
51*592ffb21SWarner Losh 	bool removed;
52*592ffb21SWarner Losh 	int put_count;
53*592ffb21SWarner Losh 	void *old_sync_obj;
54*592ffb21SWarner Losh };
55*592ffb21SWarner Losh 
56*592ffb21SWarner Losh /**
57*592ffb21SWarner Losh  * function ttm_eu_backoff_reservation
58*592ffb21SWarner Losh  *
59*592ffb21SWarner Losh  * @list:     thread private list of ttm_validate_buffer structs.
60*592ffb21SWarner Losh  *
61*592ffb21SWarner Losh  * Undoes all buffer validation reservations for bos pointed to by
62*592ffb21SWarner Losh  * the list entries.
63*592ffb21SWarner Losh  */
64*592ffb21SWarner Losh 
65*592ffb21SWarner Losh extern void ttm_eu_backoff_reservation(struct list_head *list);
66*592ffb21SWarner Losh 
67*592ffb21SWarner Losh /**
68*592ffb21SWarner Losh  * function ttm_eu_reserve_buffers
69*592ffb21SWarner Losh  *
70*592ffb21SWarner Losh  * @list:    thread private list of ttm_validate_buffer structs.
71*592ffb21SWarner Losh  *
72*592ffb21SWarner Losh  * Tries to reserve bos pointed to by the list entries for validation.
73*592ffb21SWarner Losh  * If the function returns 0, all buffers are marked as "unfenced",
74*592ffb21SWarner Losh  * taken off the lru lists and are not synced for write CPU usage.
75*592ffb21SWarner Losh  *
76*592ffb21SWarner Losh  * If the function detects a deadlock due to multiple threads trying to
77*592ffb21SWarner Losh  * reserve the same buffers in reverse order, all threads except one will
78*592ffb21SWarner Losh  * back off and retry. This function may sleep while waiting for
79*592ffb21SWarner Losh  * CPU write reservations to be cleared, and for other threads to
80*592ffb21SWarner Losh  * unreserve their buffers.
81*592ffb21SWarner Losh  *
82*592ffb21SWarner Losh  * This function may return -ERESTART or -EAGAIN if the calling process
83*592ffb21SWarner Losh  * receives a signal while waiting. In that case, no buffers on the list
84*592ffb21SWarner Losh  * will be reserved upon return.
85*592ffb21SWarner Losh  *
86*592ffb21SWarner Losh  * Buffers reserved by this function should be unreserved by
87*592ffb21SWarner Losh  * a call to either ttm_eu_backoff_reservation() or
88*592ffb21SWarner Losh  * ttm_eu_fence_buffer_objects() when command submission is complete or
89*592ffb21SWarner Losh  * has failed.
90*592ffb21SWarner Losh  */
91*592ffb21SWarner Losh 
92*592ffb21SWarner Losh extern int ttm_eu_reserve_buffers(struct list_head *list);
93*592ffb21SWarner Losh 
94*592ffb21SWarner Losh /**
95*592ffb21SWarner Losh  * function ttm_eu_fence_buffer_objects.
96*592ffb21SWarner Losh  *
97*592ffb21SWarner Losh  * @list:        thread private list of ttm_validate_buffer structs.
98*592ffb21SWarner Losh  * @sync_obj:    The new sync object for the buffers.
99*592ffb21SWarner Losh  *
100*592ffb21SWarner Losh  * This function should be called when command submission is complete, and
101*592ffb21SWarner Losh  * it will add a new sync object to bos pointed to by entries on @list.
102*592ffb21SWarner Losh  * It also unreserves all buffers, putting them on lru lists.
103*592ffb21SWarner Losh  *
104*592ffb21SWarner Losh  */
105*592ffb21SWarner Losh 
106*592ffb21SWarner Losh extern void ttm_eu_fence_buffer_objects(struct list_head *list, void *sync_obj);
107*592ffb21SWarner Losh 
108*592ffb21SWarner Losh #endif
109