1 1.1 riastrad /* $NetBSD: vmwgfx_va.c,v 1.2 2021/12/18 23:45:45 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad // SPDX-License-Identifier: GPL-2.0 OR MIT 4 1.1 riastrad /************************************************************************** 5 1.1 riastrad * 6 1.1 riastrad * Copyright 2012-2016 VMware, Inc., Palo Alto, CA., USA 7 1.1 riastrad * 8 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 9 1.1 riastrad * copy of this software and associated documentation files (the 10 1.1 riastrad * "Software"), to deal in the Software without restriction, including 11 1.1 riastrad * without limitation the rights to use, copy, modify, merge, publish, 12 1.1 riastrad * distribute, sub license, and/or sell copies of the Software, and to 13 1.1 riastrad * permit persons to whom the Software is furnished to do so, subject to 14 1.1 riastrad * the following conditions: 15 1.1 riastrad * 16 1.1 riastrad * The above copyright notice and this permission notice (including the 17 1.1 riastrad * next paragraph) shall be included in all copies or substantial portions 18 1.1 riastrad * of the Software. 19 1.1 riastrad * 20 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 21 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 23 1.1 riastrad * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 24 1.1 riastrad * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 25 1.1 riastrad * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 26 1.1 riastrad * USE OR OTHER DEALINGS IN THE SOFTWARE. 27 1.1 riastrad * 28 1.1 riastrad **************************************************************************/ 29 1.1 riastrad 30 1.1 riastrad #include <sys/cdefs.h> 31 1.1 riastrad __KERNEL_RCSID(0, "$NetBSD: vmwgfx_va.c,v 1.2 2021/12/18 23:45:45 riastradh Exp $"); 32 1.1 riastrad 33 1.1 riastrad #include "vmwgfx_drv.h" 34 1.1 riastrad #include "vmwgfx_resource_priv.h" 35 1.1 riastrad 36 1.1 riastrad /** 37 1.1 riastrad * struct vmw_stream - Overlay stream simple resource. 38 1.1 riastrad * @sres: The simple resource we derive from. 39 1.1 riastrad * @stream_id: The overlay stream id. 40 1.1 riastrad */ 41 1.1 riastrad struct vmw_stream { 42 1.1 riastrad struct vmw_simple_resource sres; 43 1.1 riastrad u32 stream_id; 44 1.1 riastrad }; 45 1.1 riastrad 46 1.1 riastrad /** 47 1.1 riastrad * vmw_stream - Typecast a struct vmw_resource to a struct vmw_stream. 48 1.1 riastrad * @res: Pointer to the struct vmw_resource. 49 1.1 riastrad * 50 1.1 riastrad * Returns: Returns a pointer to the struct vmw_stream. 51 1.1 riastrad */ 52 1.1 riastrad static struct vmw_stream * 53 1.1 riastrad vmw_stream(struct vmw_resource *res) 54 1.1 riastrad { 55 1.1 riastrad return container_of(res, struct vmw_stream, sres.res); 56 1.1 riastrad } 57 1.1 riastrad 58 1.1 riastrad /*************************************************************************** 59 1.1 riastrad * Simple resource callbacks for struct vmw_stream 60 1.1 riastrad **************************************************************************/ 61 1.1 riastrad static void vmw_stream_hw_destroy(struct vmw_resource *res) 62 1.1 riastrad { 63 1.1 riastrad struct vmw_private *dev_priv = res->dev_priv; 64 1.1 riastrad struct vmw_stream *stream = vmw_stream(res); 65 1.1 riastrad int ret; 66 1.1 riastrad 67 1.1 riastrad ret = vmw_overlay_unref(dev_priv, stream->stream_id); 68 1.1 riastrad WARN_ON_ONCE(ret != 0); 69 1.1 riastrad } 70 1.1 riastrad 71 1.1 riastrad static int vmw_stream_init(struct vmw_resource *res, void *data) 72 1.1 riastrad { 73 1.1 riastrad struct vmw_stream *stream = vmw_stream(res); 74 1.1 riastrad 75 1.1 riastrad return vmw_overlay_claim(res->dev_priv, &stream->stream_id); 76 1.1 riastrad } 77 1.1 riastrad 78 1.1 riastrad static void vmw_stream_set_arg_handle(void *data, u32 handle) 79 1.1 riastrad { 80 1.1 riastrad struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data; 81 1.1 riastrad 82 1.1 riastrad arg->stream_id = handle; 83 1.1 riastrad } 84 1.1 riastrad 85 1.1 riastrad static const struct vmw_simple_resource_func va_stream_func = { 86 1.1 riastrad .res_func = { 87 1.1 riastrad .res_type = vmw_res_stream, 88 1.1 riastrad .needs_backup = false, 89 1.1 riastrad .may_evict = false, 90 1.1 riastrad .type_name = "overlay stream", 91 1.1 riastrad .backup_placement = NULL, 92 1.1 riastrad .create = NULL, 93 1.1 riastrad .destroy = NULL, 94 1.1 riastrad .bind = NULL, 95 1.1 riastrad .unbind = NULL 96 1.1 riastrad }, 97 1.1 riastrad .ttm_res_type = VMW_RES_STREAM, 98 1.1 riastrad .size = sizeof(struct vmw_stream), 99 1.1 riastrad .init = vmw_stream_init, 100 1.1 riastrad .hw_destroy = vmw_stream_hw_destroy, 101 1.1 riastrad .set_arg_handle = vmw_stream_set_arg_handle, 102 1.1 riastrad }; 103 1.1 riastrad 104 1.1 riastrad /*************************************************************************** 105 1.1 riastrad * End simple resource callbacks for struct vmw_stream 106 1.1 riastrad **************************************************************************/ 107 1.1 riastrad 108 1.1 riastrad /** 109 1.1 riastrad * vmw_stream_unref_ioctl - Ioctl to unreference a user-space handle to 110 1.1 riastrad * a struct vmw_stream. 111 1.1 riastrad * @dev: Pointer to the drm device. 112 1.1 riastrad * @data: The ioctl argument 113 1.1 riastrad * @file_priv: Pointer to a struct drm_file identifying the caller. 114 1.1 riastrad * 115 1.1 riastrad * Return: 116 1.1 riastrad * 0 if successful. 117 1.1 riastrad * Negative error value on failure. 118 1.1 riastrad */ 119 1.1 riastrad int vmw_stream_unref_ioctl(struct drm_device *dev, void *data, 120 1.1 riastrad struct drm_file *file_priv) 121 1.1 riastrad { 122 1.1 riastrad struct drm_vmw_stream_arg *arg = (struct drm_vmw_stream_arg *)data; 123 1.1 riastrad 124 1.1 riastrad return ttm_ref_object_base_unref(vmw_fpriv(file_priv)->tfile, 125 1.1 riastrad arg->stream_id, TTM_REF_USAGE); 126 1.1 riastrad } 127 1.1 riastrad 128 1.1 riastrad /** 129 1.1 riastrad * vmw_stream_claim_ioctl - Ioctl to claim a struct vmw_stream overlay. 130 1.1 riastrad * @dev: Pointer to the drm device. 131 1.1 riastrad * @data: The ioctl argument 132 1.1 riastrad * @file_priv: Pointer to a struct drm_file identifying the caller. 133 1.1 riastrad * 134 1.1 riastrad * Return: 135 1.1 riastrad * 0 if successful. 136 1.1 riastrad * Negative error value on failure. 137 1.1 riastrad */ 138 1.1 riastrad int vmw_stream_claim_ioctl(struct drm_device *dev, void *data, 139 1.1 riastrad struct drm_file *file_priv) 140 1.1 riastrad { 141 1.1 riastrad return vmw_simple_resource_create_ioctl(dev, data, file_priv, 142 1.1 riastrad &va_stream_func); 143 1.1 riastrad } 144 1.1 riastrad 145 1.1 riastrad /** 146 1.1 riastrad * vmw_user_stream_lookup - Look up a struct vmw_user_stream from a handle. 147 1.1 riastrad * @dev_priv: Pointer to a struct vmw_private. 148 1.1 riastrad * @tfile: struct ttm_object_file identifying the caller. 149 1.1 riastrad * @inout_id: In: The user-space handle. Out: The stream id. 150 1.1 riastrad * @out: On output contains a refcounted pointer to the embedded 151 1.1 riastrad * struct vmw_resource. 152 1.1 riastrad * 153 1.1 riastrad * Return: 154 1.1 riastrad * 0 if successful. 155 1.1 riastrad * Negative error value on failure. 156 1.1 riastrad */ 157 1.1 riastrad int vmw_user_stream_lookup(struct vmw_private *dev_priv, 158 1.1 riastrad struct ttm_object_file *tfile, 159 1.1 riastrad uint32_t *inout_id, struct vmw_resource **out) 160 1.1 riastrad { 161 1.1 riastrad struct vmw_stream *stream; 162 1.1 riastrad struct vmw_resource *res = 163 1.1 riastrad vmw_simple_resource_lookup(tfile, *inout_id, &va_stream_func); 164 1.1 riastrad 165 1.1 riastrad if (IS_ERR(res)) 166 1.1 riastrad return PTR_ERR(res); 167 1.1 riastrad 168 1.1 riastrad stream = vmw_stream(res); 169 1.1 riastrad *inout_id = stream->stream_id; 170 1.1 riastrad *out = res; 171 1.1 riastrad 172 1.1 riastrad return 0; 173 1.1 riastrad } 174