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