xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fence.h (revision b5c47949a45ac972130c38cf13dfd8afb1f09285)
1 /*	$NetBSD: vmwgfx_fence.h,v 1.2 2018/08/27 04:58:37 riastradh Exp $	*/
2 
3 /**************************************************************************
4  *
5  * Copyright © 2011-2012 VMware, Inc., Palo Alto, CA., USA
6  * All Rights Reserved.
7  *
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:
15  *
16  * The above copyright notice and this permission notice (including the
17  * next paragraph) shall be included in all copies or substantial portions
18  * of the Software.
19  *
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.
27  *
28  **************************************************************************/
29 
30 #ifndef _VMWGFX_FENCE_H_
31 
32 #include <linux/fence.h>
33 
34 #define VMW_FENCE_WAIT_TIMEOUT (5*HZ)
35 
36 struct vmw_private;
37 
38 struct vmw_fence_manager;
39 
40 /**
41  *
42  *
43  */
44 enum vmw_action_type {
45 	VMW_ACTION_EVENT = 0,
46 	VMW_ACTION_MAX
47 };
48 
49 struct vmw_fence_action {
50 	struct list_head head;
51 	enum vmw_action_type type;
52 	void (*seq_passed) (struct vmw_fence_action *action);
53 	void (*cleanup) (struct vmw_fence_action *action);
54 };
55 
56 struct vmw_fence_obj {
57 	struct fence base;
58 
59 	struct list_head head;
60 	struct list_head seq_passed_actions;
61 	void (*destroy)(struct vmw_fence_obj *fence);
62 };
63 
64 extern struct vmw_fence_manager *
65 vmw_fence_manager_init(struct vmw_private *dev_priv);
66 
67 extern void vmw_fence_manager_takedown(struct vmw_fence_manager *fman);
68 
69 static inline void
70 vmw_fence_obj_unreference(struct vmw_fence_obj **fence_p)
71 {
72 	struct vmw_fence_obj *fence = *fence_p;
73 
74 	*fence_p = NULL;
75 	if (fence)
76 		fence_put(&fence->base);
77 }
78 
79 static inline struct vmw_fence_obj *
80 vmw_fence_obj_reference(struct vmw_fence_obj *fence)
81 {
82 	if (fence)
83 		fence_get(&fence->base);
84 	return fence;
85 }
86 
87 extern void vmw_fences_update(struct vmw_fence_manager *fman);
88 
89 extern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence);
90 
91 extern int vmw_fence_obj_wait(struct vmw_fence_obj *fence,
92 			      bool lazy,
93 			      bool interruptible, unsigned long timeout);
94 
95 extern void vmw_fence_obj_flush(struct vmw_fence_obj *fence);
96 
97 extern int vmw_fence_create(struct vmw_fence_manager *fman,
98 			    uint32_t seqno,
99 			    struct vmw_fence_obj **p_fence);
100 
101 extern int vmw_user_fence_create(struct drm_file *file_priv,
102 				 struct vmw_fence_manager *fman,
103 				 uint32_t sequence,
104 				 struct vmw_fence_obj **p_fence,
105 				 uint32_t *p_handle);
106 
107 extern void vmw_fence_fifo_up(struct vmw_fence_manager *fman);
108 
109 extern void vmw_fence_fifo_down(struct vmw_fence_manager *fman);
110 
111 extern int vmw_fence_obj_wait_ioctl(struct drm_device *dev, void *data,
112 				    struct drm_file *file_priv);
113 
114 extern int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
115 					struct drm_file *file_priv);
116 
117 extern int vmw_fence_obj_unref_ioctl(struct drm_device *dev, void *data,
118 				     struct drm_file *file_priv);
119 extern int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
120 				 struct drm_file *file_priv);
121 extern void vmw_event_fence_fpriv_gone(struct vmw_fence_manager *fman,
122 				       struct list_head *event_list);
123 extern int vmw_event_fence_action_queue(struct drm_file *filee_priv,
124 					struct vmw_fence_obj *fence,
125 					struct drm_pending_event *event,
126 					uint32_t *tv_sec,
127 					uint32_t *tv_usec,
128 					bool interruptible);
129 #endif /* _VMWGFX_FENCE_H_ */
130