18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 OR MIT 28c2ecf20Sopenharmony_ci/************************************************************************** 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright 2012-2016 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#include "vmwgfx_drv.h" 298c2ecf20Sopenharmony_ci#include "vmwgfx_resource_priv.h" 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci/** 328c2ecf20Sopenharmony_ci * struct vmw_stream - Overlay stream simple resource. 338c2ecf20Sopenharmony_ci * @sres: The simple resource we derive from. 348c2ecf20Sopenharmony_ci * @stream_id: The overlay stream id. 358c2ecf20Sopenharmony_ci */ 368c2ecf20Sopenharmony_cistruct vmw_stream { 378c2ecf20Sopenharmony_ci struct vmw_simple_resource sres; 388c2ecf20Sopenharmony_ci u32 stream_id; 398c2ecf20Sopenharmony_ci}; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/** 428c2ecf20Sopenharmony_ci * vmw_stream - Typecast a struct vmw_resource to a struct vmw_stream. 438c2ecf20Sopenharmony_ci * @res: Pointer to the struct vmw_resource. 448c2ecf20Sopenharmony_ci * 458c2ecf20Sopenharmony_ci * Returns: Returns a pointer to the struct vmw_stream. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_cistatic struct vmw_stream * 488c2ecf20Sopenharmony_civmw_stream(struct vmw_resource *res) 498c2ecf20Sopenharmony_ci{ 508c2ecf20Sopenharmony_ci return container_of(res, struct vmw_stream, sres.res); 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/*************************************************************************** 548c2ecf20Sopenharmony_ci * Simple resource callbacks for struct vmw_stream 558c2ecf20Sopenharmony_ci **************************************************************************/ 568c2ecf20Sopenharmony_cistatic void vmw_stream_hw_destroy(struct vmw_resource *res) 578c2ecf20Sopenharmony_ci{ 588c2ecf20Sopenharmony_ci struct vmw_private *dev_priv = res->dev_priv; 598c2ecf20Sopenharmony_ci struct vmw_stream *stream = vmw_stream(res); 608c2ecf20Sopenharmony_ci int ret; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci ret = vmw_overlay_unref(dev_priv, stream->stream_id); 638c2ecf20Sopenharmony_ci WARN_ON_ONCE(ret != 0); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic int vmw_stream_init(struct vmw_resource *res, void *data) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci struct vmw_stream *stream = vmw_stream(res); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci return vmw_overlay_claim(res->dev_priv, &stream->stream_id); 718c2ecf20Sopenharmony_ci} 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cistatic void vmw_stream_set_arg_handle(void *data, u32 handle) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci arg->stream_id = handle; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_cistatic const struct vmw_simple_resource_func va_stream_func = { 818c2ecf20Sopenharmony_ci .res_func = { 828c2ecf20Sopenharmony_ci .res_type = vmw_res_stream, 838c2ecf20Sopenharmony_ci .needs_backup = false, 848c2ecf20Sopenharmony_ci .may_evict = false, 858c2ecf20Sopenharmony_ci .type_name = "overlay stream", 868c2ecf20Sopenharmony_ci .backup_placement = NULL, 878c2ecf20Sopenharmony_ci .create = NULL, 888c2ecf20Sopenharmony_ci .destroy = NULL, 898c2ecf20Sopenharmony_ci .bind = NULL, 908c2ecf20Sopenharmony_ci .unbind = NULL 918c2ecf20Sopenharmony_ci }, 928c2ecf20Sopenharmony_ci .ttm_res_type = VMW_RES_STREAM, 938c2ecf20Sopenharmony_ci .size = sizeof(struct vmw_stream), 948c2ecf20Sopenharmony_ci .init = vmw_stream_init, 958c2ecf20Sopenharmony_ci .hw_destroy = vmw_stream_hw_destroy, 968c2ecf20Sopenharmony_ci .set_arg_handle = vmw_stream_set_arg_handle, 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci/*************************************************************************** 1008c2ecf20Sopenharmony_ci * End simple resource callbacks for struct vmw_stream 1018c2ecf20Sopenharmony_ci **************************************************************************/ 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/** 1048c2ecf20Sopenharmony_ci * vmw_stream_unref_ioctl - Ioctl to unreference a user-space handle to 1058c2ecf20Sopenharmony_ci * a struct vmw_stream. 1068c2ecf20Sopenharmony_ci * @dev: Pointer to the drm device. 1078c2ecf20Sopenharmony_ci * @data: The ioctl argument 1088c2ecf20Sopenharmony_ci * @file_priv: Pointer to a struct drm_file identifying the caller. 1098c2ecf20Sopenharmony_ci * 1108c2ecf20Sopenharmony_ci * Return: 1118c2ecf20Sopenharmony_ci * 0 if successful. 1128c2ecf20Sopenharmony_ci * Negative error value on failure. 1138c2ecf20Sopenharmony_ci */ 1148c2ecf20Sopenharmony_ciint vmw_stream_unref_ioctl(struct drm_device *dev, void *data, 1158c2ecf20Sopenharmony_ci struct drm_file *file_priv) 1168c2ecf20Sopenharmony_ci{ 1178c2ecf20Sopenharmony_ci struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile, 1208c2ecf20Sopenharmony_ci arg->stream_id, TTM_REF_USAGE); 1218c2ecf20Sopenharmony_ci} 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/** 1248c2ecf20Sopenharmony_ci * vmw_stream_claim_ioctl - Ioctl to claim a struct vmw_stream overlay. 1258c2ecf20Sopenharmony_ci * @dev: Pointer to the drm device. 1268c2ecf20Sopenharmony_ci * @data: The ioctl argument 1278c2ecf20Sopenharmony_ci * @file_priv: Pointer to a struct drm_file identifying the caller. 1288c2ecf20Sopenharmony_ci * 1298c2ecf20Sopenharmony_ci * Return: 1308c2ecf20Sopenharmony_ci * 0 if successful. 1318c2ecf20Sopenharmony_ci * Negative error value on failure. 1328c2ecf20Sopenharmony_ci */ 1338c2ecf20Sopenharmony_ciint vmw_stream_claim_ioctl(struct drm_device *dev, void *data, 1348c2ecf20Sopenharmony_ci struct drm_file *file_priv) 1358c2ecf20Sopenharmony_ci{ 1368c2ecf20Sopenharmony_ci return vmw_simple_resource_create_ioctl(dev, data, file_priv, 1378c2ecf20Sopenharmony_ci &va_stream_func); 1388c2ecf20Sopenharmony_ci} 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci/** 1418c2ecf20Sopenharmony_ci * vmw_user_stream_lookup - Look up a struct vmw_user_stream from a handle. 1428c2ecf20Sopenharmony_ci * @dev_priv: Pointer to a struct vmw_private. 1438c2ecf20Sopenharmony_ci * @tfile: struct ttm_object_file identifying the caller. 1448c2ecf20Sopenharmony_ci * @inout_id: In: The user-space handle. Out: The stream id. 1458c2ecf20Sopenharmony_ci * @out: On output contains a refcounted pointer to the embedded 1468c2ecf20Sopenharmony_ci * struct vmw_resource. 1478c2ecf20Sopenharmony_ci * 1488c2ecf20Sopenharmony_ci * Return: 1498c2ecf20Sopenharmony_ci * 0 if successful. 1508c2ecf20Sopenharmony_ci * Negative error value on failure. 1518c2ecf20Sopenharmony_ci */ 1528c2ecf20Sopenharmony_ciint vmw_user_stream_lookup(struct vmw_private *dev_priv, 1538c2ecf20Sopenharmony_ci struct ttm_object_file *tfile, 1548c2ecf20Sopenharmony_ci uint32_t *inout_id, struct vmw_resource **out) 1558c2ecf20Sopenharmony_ci{ 1568c2ecf20Sopenharmony_ci struct vmw_stream *stream; 1578c2ecf20Sopenharmony_ci struct vmw_resource *res = 1588c2ecf20Sopenharmony_ci vmw_simple_resource_lookup(tfile, *inout_id, &va_stream_func); 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci if (IS_ERR(res)) 1618c2ecf20Sopenharmony_ci return PTR_ERR(res); 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci stream = vmw_stream(res); 1648c2ecf20Sopenharmony_ci *inout_id = stream->stream_id; 1658c2ecf20Sopenharmony_ci *out = res; 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci return 0; 1688c2ecf20Sopenharmony_ci} 169