18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */ 28c2ecf20Sopenharmony_ci/************************************************************************** 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright 2011-2012 VMware, Inc., Palo Alto, CA., USA 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the 88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 128c2ecf20Sopenharmony_ci * the following conditions: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the 158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 168c2ecf20Sopenharmony_ci * of the Software. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci **************************************************************************/ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#ifndef _VMWGFX_FENCE_H_ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#include <linux/dma-fence.h> 318c2ecf20Sopenharmony_ci#include <linux/dma-fence-array.h> 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define VMW_FENCE_WAIT_TIMEOUT (5*HZ) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistruct drm_device; 368c2ecf20Sopenharmony_cistruct drm_file; 378c2ecf20Sopenharmony_cistruct drm_pending_event; 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_cistruct vmw_private; 408c2ecf20Sopenharmony_cistruct vmw_fence_manager; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci/** 438c2ecf20Sopenharmony_ci * 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_cienum vmw_action_type { 478c2ecf20Sopenharmony_ci VMW_ACTION_EVENT = 0, 488c2ecf20Sopenharmony_ci VMW_ACTION_MAX 498c2ecf20Sopenharmony_ci}; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistruct vmw_fence_action { 528c2ecf20Sopenharmony_ci struct list_head head; 538c2ecf20Sopenharmony_ci enum vmw_action_type type; 548c2ecf20Sopenharmony_ci void (*seq_passed) (struct vmw_fence_action *action); 558c2ecf20Sopenharmony_ci void (*cleanup) (struct vmw_fence_action *action); 568c2ecf20Sopenharmony_ci}; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_cistruct vmw_fence_obj { 598c2ecf20Sopenharmony_ci struct dma_fence base; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci struct list_head head; 628c2ecf20Sopenharmony_ci struct list_head seq_passed_actions; 638c2ecf20Sopenharmony_ci void (*destroy)(struct vmw_fence_obj *fence); 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciextern struct vmw_fence_manager * 678c2ecf20Sopenharmony_civmw_fence_manager_init(struct vmw_private *dev_priv); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ciextern void vmw_fence_manager_takedown(struct vmw_fence_manager *fman); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic inline void 728c2ecf20Sopenharmony_civmw_fence_obj_unreference(struct vmw_fence_obj **fence_p) 738c2ecf20Sopenharmony_ci{ 748c2ecf20Sopenharmony_ci struct vmw_fence_obj *fence = *fence_p; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci *fence_p = NULL; 778c2ecf20Sopenharmony_ci if (fence) 788c2ecf20Sopenharmony_ci dma_fence_put(&fence->base); 798c2ecf20Sopenharmony_ci} 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic inline struct vmw_fence_obj * 828c2ecf20Sopenharmony_civmw_fence_obj_reference(struct vmw_fence_obj *fence) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci if (fence) 858c2ecf20Sopenharmony_ci dma_fence_get(&fence->base); 868c2ecf20Sopenharmony_ci return fence; 878c2ecf20Sopenharmony_ci} 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ciextern void vmw_fences_update(struct vmw_fence_manager *fman); 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ciextern bool vmw_fence_obj_signaled(struct vmw_fence_obj *fence); 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ciextern int vmw_fence_obj_wait(struct vmw_fence_obj *fence, 948c2ecf20Sopenharmony_ci bool lazy, 958c2ecf20Sopenharmony_ci bool interruptible, unsigned long timeout); 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciextern void vmw_fence_obj_flush(struct vmw_fence_obj *fence); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciextern int vmw_fence_create(struct vmw_fence_manager *fman, 1008c2ecf20Sopenharmony_ci uint32_t seqno, 1018c2ecf20Sopenharmony_ci struct vmw_fence_obj **p_fence); 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciextern int vmw_user_fence_create(struct drm_file *file_priv, 1048c2ecf20Sopenharmony_ci struct vmw_fence_manager *fman, 1058c2ecf20Sopenharmony_ci uint32_t sequence, 1068c2ecf20Sopenharmony_ci struct vmw_fence_obj **p_fence, 1078c2ecf20Sopenharmony_ci uint32_t *p_handle); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ciextern int vmw_wait_dma_fence(struct vmw_fence_manager *fman, 1108c2ecf20Sopenharmony_ci struct dma_fence *fence); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciextern void vmw_fence_fifo_up(struct vmw_fence_manager *fman); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ciextern void vmw_fence_fifo_down(struct vmw_fence_manager *fman); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ciextern int vmw_fence_obj_wait_ioctl(struct drm_device *dev, void *data, 1178c2ecf20Sopenharmony_ci struct drm_file *file_priv); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciextern int vmw_fence_obj_signaled_ioctl(struct drm_device *dev, void *data, 1208c2ecf20Sopenharmony_ci struct drm_file *file_priv); 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ciextern int vmw_fence_obj_unref_ioctl(struct drm_device *dev, void *data, 1238c2ecf20Sopenharmony_ci struct drm_file *file_priv); 1248c2ecf20Sopenharmony_ciextern int vmw_fence_event_ioctl(struct drm_device *dev, void *data, 1258c2ecf20Sopenharmony_ci struct drm_file *file_priv); 1268c2ecf20Sopenharmony_ciextern int vmw_event_fence_action_queue(struct drm_file *filee_priv, 1278c2ecf20Sopenharmony_ci struct vmw_fence_obj *fence, 1288c2ecf20Sopenharmony_ci struct drm_pending_event *event, 1298c2ecf20Sopenharmony_ci uint32_t *tv_sec, 1308c2ecf20Sopenharmony_ci uint32_t *tv_usec, 1318c2ecf20Sopenharmony_ci bool interruptible); 1328c2ecf20Sopenharmony_ci#endif /* _VMWGFX_FENCE_H_ */ 133