1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Tx., USA
5 * Copyright 2009 VMware, Inc., Palo Alto, CA., USA
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
24 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26 * USE OR OTHER DEALINGS IN THE SOFTWARE.
28 **************************************************************************/
30 * Authors: Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
33 #ifndef WSBM_FENCEMGR_H
34 #define WSBM_FENCEMGR_H
39 struct _WsbmFenceObject;
43 * Do a quick check to see if the fence manager has registered the fence
44 * object as signaled. Note that this function may return a false negative
47 extern uint32_t wsbmFenceSignaledTypeCached(struct _WsbmFenceObject *fence);
50 * Check if the fence object is signaled. This function can be substantially
51 * more expensive to call than the above function, but will not return a false
52 * negative answer. The argument "flush_type" sets the types that the
53 * underlying mechanism must make sure will eventually signal.
55 extern int wsbmFenceSignaledType(struct _WsbmFenceObject *fence,
56 uint32_t flush_type, uint32_t * signaled);
59 * Convenience functions.
63 wsbmFenceSignaled(struct _WsbmFenceObject *fence, uint32_t flush_type)
65 uint32_t signaled_types;
66 int ret = wsbmFenceSignaledType(fence, flush_type, &signaled_types);
70 return ((signaled_types & flush_type) == flush_type);
74 wsbmFenceSignaledCached(struct _WsbmFenceObject *fence, uint32_t flush_type)
76 uint32_t signaled_types = wsbmFenceSignaledTypeCached(fence);
78 return ((signaled_types & flush_type) == flush_type);
82 * Reference a fence object.
84 extern struct _WsbmFenceObject *wsbmFenceReference(struct _WsbmFenceObject
88 * Unreference a fence object. The fence object pointer will be reset to NULL.
91 extern void wsbmFenceUnreference(struct _WsbmFenceObject **pFence);
94 * Wait for a fence to signal the indicated fence_type.
95 * If "lazy_hint" is true, it indicates that the wait may sleep to avoid
98 extern int wsbmFenceFinish(struct _WsbmFenceObject *fence,
99 uint32_t fence_type, int lazy_hint);
102 * Create a WsbmFenceObject for manager "mgr".
104 * "private" is a pointer that should be used for the callbacks in
105 * struct _WsbmFenceMgrCreateInfo.
107 * if private_size is nonzero, then the info stored at *private, with size
108 * private size will be copied and the fence manager will instead use a
109 * pointer to the copied data for the callbacks in
110 * struct _WsbmFenceMgrCreateInfo. In that case, the object pointed to by
111 * "private" may be destroyed after the call to wsbmFenceCreate.
113 extern struct _WsbmFenceObject *wsbmFenceCreate(struct _WsbmFenceMgr *mgr,
114 uint32_t fence_class,
117 size_t private_size);
120 extern struct _WsbmFenceObject *wsbmFenceCreateSig(struct _WsbmFenceMgr *mgr,
121 uint32_t fence_class,
123 uint32_t signaled_types,
125 size_t private_size);
127 extern uint32_t wsbmFenceType(struct _WsbmFenceObject *fence);
130 * Fence creations are ordered. If a fence signals a fence_type,
131 * it is safe to assume that all fences of the same class that was
132 * created before that fence has signaled the same type.
135 #define WSBM_FENCE_CLASS_ORDERED (1 << 0)
137 struct _WsbmFenceMgrCreateInfo
140 uint32_t num_classes;
141 int (*signaled) (struct _WsbmFenceMgr * mgr, void *private,
142 uint32_t flush_type, uint32_t * signaled_type);
143 int (*finish) (struct _WsbmFenceMgr * mgr, void *private,
144 uint32_t fence_type, int lazy_hint);
145 int (*unreference) (struct _WsbmFenceMgr * mgr, void **private);
148 extern struct _WsbmFenceMgr *wsbmFenceMgrCreate(const struct
149 _WsbmFenceMgrCreateInfo
151 extern void wsbmFenceCmdLock(struct _WsbmFenceMgr *mgr, uint32_t fence_class);
152 extern void wsbmFenceCmdUnlock(struct _WsbmFenceMgr *mgr,
153 uint32_t fence_class);
158 extern struct _WsbmFenceMgr *wsbmFenceMgrTTMInit(int fd,
159 unsigned int numClass,
160 unsigned int devOffset);
161 extern void wsbmFenceMgrTTMTakedown(struct _WsbmFenceMgr *mgr);