1dff96888SDirk Hohndel (VMware) /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2ae2a1040SThomas Hellstrom /**************************************************************************
3ae2a1040SThomas Hellstrom  *
4dff96888SDirk Hohndel (VMware)  * Copyright 2011-2012 VMware, Inc., Palo Alto, CA., USA
5ae2a1040SThomas Hellstrom  *
6ae2a1040SThomas Hellstrom  * Permission is hereby granted, free of charge, to any person obtaining a
7ae2a1040SThomas Hellstrom  * copy of this software and associated documentation files (the
8ae2a1040SThomas Hellstrom  * "Software"), to deal in the Software without restriction, including
9ae2a1040SThomas Hellstrom  * without limitation the rights to use, copy, modify, merge, publish,
10ae2a1040SThomas Hellstrom  * distribute, sub license, and/or sell copies of the Software, and to
11ae2a1040SThomas Hellstrom  * permit persons to whom the Software is furnished to do so, subject to
12ae2a1040SThomas Hellstrom  * the following conditions:
13ae2a1040SThomas Hellstrom  *
14ae2a1040SThomas Hellstrom  * The above copyright notice and this permission notice (including the
15ae2a1040SThomas Hellstrom  * next paragraph) shall be included in all copies or substantial portions
16ae2a1040SThomas Hellstrom  * of the Software.
17ae2a1040SThomas Hellstrom  *
18ae2a1040SThomas Hellstrom  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19ae2a1040SThomas Hellstrom  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20ae2a1040SThomas Hellstrom  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21ae2a1040SThomas Hellstrom  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22ae2a1040SThomas Hellstrom  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23ae2a1040SThomas Hellstrom  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24ae2a1040SThomas Hellstrom  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25ae2a1040SThomas Hellstrom  *
26ae2a1040SThomas Hellstrom  **************************************************************************/
27ae2a1040SThomas Hellstrom 
28ae2a1040SThomas Hellstrom #ifndef _VMWGFX_FENCE_H_
29ae2a1040SThomas Hellstrom 
30f54d1867SChris Wilson #include <linux/dma-fence.h>
3158585116SSinclair Yeh #include <linux/dma-fence-array.h>
322298e804SMaarten Lankhorst 
33ae2a1040SThomas Hellstrom #define VMW_FENCE_WAIT_TIMEOUT (5*HZ)
34ae2a1040SThomas Hellstrom 
35d5c1f011SSam Ravnborg struct drm_device;
36d5c1f011SSam Ravnborg struct drm_file;
37d5c1f011SSam Ravnborg struct drm_pending_event;
38ae2a1040SThomas Hellstrom 
39d5c1f011SSam Ravnborg struct vmw_private;
40ae2a1040SThomas Hellstrom struct vmw_fence_manager;
41ae2a1040SThomas Hellstrom 
42ae2a1040SThomas Hellstrom /**
43ae2a1040SThomas Hellstrom  *
44ae2a1040SThomas Hellstrom  *
45ae2a1040SThomas Hellstrom  */
4657c5ee79SThomas Hellstrom enum vmw_action_type {
4757c5ee79SThomas Hellstrom 	VMW_ACTION_EVENT = 0,
4857c5ee79SThomas Hellstrom 	VMW_ACTION_MAX
4957c5ee79SThomas Hellstrom };
5057c5ee79SThomas Hellstrom 
51ae2a1040SThomas Hellstrom struct vmw_fence_action {
52ae2a1040SThomas Hellstrom 	struct list_head head;
5357c5ee79SThomas Hellstrom 	enum vmw_action_type type;
54ae2a1040SThomas Hellstrom 	void (*seq_passed) (struct vmw_fence_action *action);
55ae2a1040SThomas Hellstrom 	void (*cleanup) (struct vmw_fence_action *action);
56ae2a1040SThomas Hellstrom };
57ae2a1040SThomas Hellstrom 
58ae2a1040SThomas Hellstrom struct vmw_fence_obj {
59f54d1867SChris Wilson 	struct dma_fence base;
60ae2a1040SThomas Hellstrom 
61ae2a1040SThomas Hellstrom 	struct list_head head;
62ae2a1040SThomas Hellstrom 	struct list_head seq_passed_actions;
63ae2a1040SThomas Hellstrom 	void (*destroy)(struct vmw_fence_obj *fence);
64ae2a1040SThomas Hellstrom };
65ae2a1040SThomas Hellstrom 
66ae2a1040SThomas Hellstrom extern struct vmw_fence_manager *
67ae2a1040SThomas Hellstrom vmw_fence_manager_init(struct vmw_private *dev_priv);
68ae2a1040SThomas Hellstrom 
69ae2a1040SThomas Hellstrom extern void vmw_fence_manager_takedown(struct vmw_fence_manager *fman);
70ae2a1040SThomas Hellstrom 
712298e804SMaarten Lankhorst static inline void
vmw_fence_obj_unreference(struct vmw_fence_obj ** fence_p)722298e804SMaarten Lankhorst vmw_fence_obj_unreference(struct vmw_fence_obj **fence_p)
732298e804SMaarten Lankhorst {
742298e804SMaarten Lankhorst 	struct vmw_fence_obj *fence = *fence_p;
75ae2a1040SThomas Hellstrom 
762298e804SMaarten Lankhorst 	*fence_p = NULL;
772298e804SMaarten Lankhorst 	if (fence)
78f54d1867SChris Wilson 		dma_fence_put(&fence->base);
792298e804SMaarten Lankhorst }
802298e804SMaarten Lankhorst 
812298e804SMaarten Lankhorst static inline struct vmw_fence_obj *
vmw_fence_obj_reference(struct vmw_fence_obj * fence)822298e804SMaarten Lankhorst vmw_fence_obj_reference(struct vmw_fence_obj *fence)
832298e804SMaarten Lankhorst {
842298e804SMaarten Lankhorst 	if (fence)
85f54d1867SChris Wilson 		dma_fence_get(&fence->base);
862298e804SMaarten Lankhorst 	return fence;
872298e804SMaarten Lankhorst }
88ae2a1040SThomas Hellstrom 
8957c5ee79SThomas Hellstrom extern void vmw_fences_update(struct vmw_fence_manager *fman);
90ae2a1040SThomas Hellstrom 
91c060a4e1SMaarten Lankhorst extern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence);
92ae2a1040SThomas Hellstrom 
93c060a4e1SMaarten Lankhorst extern int vmw_fence_obj_wait(struct vmw_fence_obj *fence,
94ae2a1040SThomas Hellstrom 			      bool lazy,
95ae2a1040SThomas Hellstrom 			      bool interruptible, unsigned long timeout);
96ae2a1040SThomas Hellstrom 
97ae2a1040SThomas Hellstrom extern int vmw_fence_create(struct vmw_fence_manager *fman,
98ae2a1040SThomas Hellstrom 			    uint32_t seqno,
99ae2a1040SThomas Hellstrom 			    struct vmw_fence_obj **p_fence);
100ae2a1040SThomas Hellstrom 
101ae2a1040SThomas Hellstrom extern int vmw_user_fence_create(struct drm_file *file_priv,
102ae2a1040SThomas Hellstrom 				 struct vmw_fence_manager *fman,
103ae2a1040SThomas Hellstrom 				 uint32_t sequence,
104ae2a1040SThomas Hellstrom 				 struct vmw_fence_obj **p_fence,
105ae2a1040SThomas Hellstrom 				 uint32_t *p_handle);
106ae2a1040SThomas Hellstrom 
107ae2a1040SThomas Hellstrom extern void vmw_fence_fifo_up(struct vmw_fence_manager *fman);
108ae2a1040SThomas Hellstrom 
109ae2a1040SThomas Hellstrom extern void vmw_fence_fifo_down(struct vmw_fence_manager *fman);
110ae2a1040SThomas Hellstrom 
111ae2a1040SThomas Hellstrom extern int vmw_fence_obj_wait_ioctl(struct drm_device *dev, void *data,
112ae2a1040SThomas Hellstrom 				    struct drm_file *file_priv);
113ae2a1040SThomas Hellstrom 
114ae2a1040SThomas Hellstrom extern int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data,
115ae2a1040SThomas Hellstrom 					struct drm_file *file_priv);
116ae2a1040SThomas Hellstrom 
117ae2a1040SThomas Hellstrom extern int vmw_fence_obj_unref_ioctl(struct drm_device *dev, void *data,
118ae2a1040SThomas Hellstrom 				     struct drm_file *file_priv);
11957c5ee79SThomas Hellstrom extern int vmw_fence_event_ioctl(struct drm_device *dev, void *data,
12057c5ee79SThomas Hellstrom 				 struct drm_file *file_priv);
121f9cd8ec3SThomas Hellstrom extern int vmw_event_fence_action_queue(struct drm_file *filee_priv,
122f9cd8ec3SThomas Hellstrom 					struct vmw_fence_obj *fence,
123f9cd8ec3SThomas Hellstrom 					struct drm_pending_event *event,
124f9cd8ec3SThomas Hellstrom 					uint32_t *tv_sec,
125f9cd8ec3SThomas Hellstrom 					uint32_t *tv_usec,
126f9cd8ec3SThomas Hellstrom 					bool interruptible);
127ae2a1040SThomas Hellstrom #endif /* _VMWGFX_FENCE_H_ */
128