xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/vmwgfx/vmwgfx_fence.h (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: vmwgfx_fence.h,v 1.3 2021/12/18 23:45:45 riastradh Exp $	*/
2 
3 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
4 /**************************************************************************
5  *
6  * Copyright 2011-2012 VMware, Inc., Palo Alto, CA., USA
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/dma-fence.h>
33 #include <linux/dma-fence-array.h>
34 
35 #define VMW_FENCE_WAIT_TIMEOUT (5*HZ)
36 
37 struct drm_device;
38 struct drm_file;
39 struct drm_pending_event;
40 
41 struct vmw_private;
42 struct vmw_fence_manager;
43 
44 /**
45  *
46  *
47  */
48 enum vmw_action_type {
49 	VMW_ACTION_EVENT = 0,
50 	VMW_ACTION_MAX
51 };
52 
53 struct vmw_fence_action {
54 	struct list_head head;
55 	enum vmw_action_type type;
56 	void (*seq_passed) (struct vmw_fence_action *action);
57 	void (*cleanup) (struct vmw_fence_action *action);
58 };
59 
60 struct vmw_fence_obj {
61 	struct dma_fence base;
62 
63 	struct list_head head;
64 	struct list_head seq_passed_actions;
65 	void (*destroy)(struct vmw_fence_obj *fence);
66 };
67 
68 extern struct vmw_fence_manager *
69 vmw_fence_manager_init(struct vmw_private *dev_priv);
70 
71 extern void vmw_fence_manager_takedown(struct vmw_fence_manager *fman);
72 
73 static inline void
vmw_fence_obj_unreference(struct vmw_fence_obj ** fence_p)74 vmw_fence_obj_unreference(struct vmw_fence_obj **fence_p)
75 {
76 	struct vmw_fence_obj *fence = *fence_p;
77 
78 	*fence_p = NULL;
79 	if (fence)
80 		dma_fence_put(&fence->base);
81 }
82 
83 static inline struct vmw_fence_obj *
vmw_fence_obj_reference(struct vmw_fence_obj * fence)84 vmw_fence_obj_reference(struct vmw_fence_obj *fence)
85 {
86 	if (fence)
87 		dma_fence_get(&fence->base);
88 	return fence;
89 }
90 
91 extern void vmw_fences_update(struct vmw_fence_manager *fman);
92 
93 extern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence);
94 
95 extern int vmw_fence_obj_wait(struct vmw_fence_obj *fence,
96 			      bool lazy,
97 			      bool interruptible, unsigned long timeout);
98 
99 extern void vmw_fence_obj_flush(struct vmw_fence_obj *fence);
100 
101 extern int vmw_fence_create(struct vmw_fence_manager *fman,
102 			    uint32_t seqno,
103 			    struct vmw_fence_obj **p_fence);
104 
105 extern int vmw_user_fence_create(struct drm_file *file_priv,
106 				 struct vmw_fence_manager *fman,
107 				 uint32_t sequence,
108 				 struct vmw_fence_obj **p_fence,
109 				 uint32_t *p_handle);
110 
111 extern int vmw_wait_dma_fence(struct vmw_fence_manager *fman,
112 			      struct dma_fence *fence);
113 
114 extern void vmw_fence_fifo_up(struct vmw_fence_manager *fman);
115 
116 extern void vmw_fence_fifo_down(struct vmw_fence_manager *fman);
117 
118 extern int vmw_fence_obj_wait_ioctl(struct drm_device *dev, void *data,
119 				    struct drm_file *file_priv);
120 
121 extern int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
122 					struct drm_file *file_priv);
123 
124 extern int vmw_fence_obj_unref_ioctl(struct drm_device *dev, void *data,
125 				     struct drm_file *file_priv);
126 extern int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
127 				 struct drm_file *file_priv);
128 extern int vmw_event_fence_action_queue(struct drm_file *filee_priv,
129 					struct vmw_fence_obj *fence,
130 					struct drm_pending_event *event,
131 					uint32_t *tv_sec,
132 					uint32_t *tv_usec,
133 					bool interruptible);
134 #endif /* _VMWGFX_FENCE_H_ */
135