18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */
28c2ecf20Sopenharmony_ci/**************************************************************************
38c2ecf20Sopenharmony_ci * Copyright 2014-2015 VMware, Inc., Palo Alto, CA., USA
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
68c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
78c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
88c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
98c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
108c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
118c2ecf20Sopenharmony_ci * the following conditions:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
148c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
158c2ecf20Sopenharmony_ci * of the Software.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
188c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
198c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
208c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
218c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
228c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
238c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci **************************************************************************/
268c2ecf20Sopenharmony_ci#ifndef VMW_SO_H
278c2ecf20Sopenharmony_ci#define VMW_SO_H
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cienum vmw_view_type {
308c2ecf20Sopenharmony_ci	vmw_view_sr,
318c2ecf20Sopenharmony_ci	vmw_view_rt,
328c2ecf20Sopenharmony_ci	vmw_view_ds,
338c2ecf20Sopenharmony_ci	vmw_view_ua,
348c2ecf20Sopenharmony_ci	vmw_view_max,
358c2ecf20Sopenharmony_ci};
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cienum vmw_so_type {
388c2ecf20Sopenharmony_ci	vmw_so_el,
398c2ecf20Sopenharmony_ci	vmw_so_bs,
408c2ecf20Sopenharmony_ci	vmw_so_ds,
418c2ecf20Sopenharmony_ci	vmw_so_rs,
428c2ecf20Sopenharmony_ci	vmw_so_ss,
438c2ecf20Sopenharmony_ci	vmw_so_so,
448c2ecf20Sopenharmony_ci	vmw_so_max,
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/**
488c2ecf20Sopenharmony_ci * union vmw_view_destroy - view destruction command body
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * @rtv: RenderTarget view destruction command body
518c2ecf20Sopenharmony_ci * @srv: ShaderResource view destruction command body
528c2ecf20Sopenharmony_ci * @dsv: DepthStencil view destruction command body
538c2ecf20Sopenharmony_ci * @view_id: A single u32 view id.
548c2ecf20Sopenharmony_ci *
558c2ecf20Sopenharmony_ci * The assumption here is that all union members are really represented by a
568c2ecf20Sopenharmony_ci * single u32 in the command stream. If that's not the case,
578c2ecf20Sopenharmony_ci * the size of this union will not equal the size of an u32, and the
588c2ecf20Sopenharmony_ci * assumption is invalid, and we detect that at compile time in the
598c2ecf20Sopenharmony_ci * vmw_so_build_asserts() function.
608c2ecf20Sopenharmony_ci */
618c2ecf20Sopenharmony_ciunion vmw_view_destroy {
628c2ecf20Sopenharmony_ci	struct SVGA3dCmdDXDestroyRenderTargetView rtv;
638c2ecf20Sopenharmony_ci	struct SVGA3dCmdDXDestroyShaderResourceView srv;
648c2ecf20Sopenharmony_ci	struct SVGA3dCmdDXDestroyDepthStencilView dsv;
658c2ecf20Sopenharmony_ci	struct SVGA3dCmdDXDestroyUAView uav;
668c2ecf20Sopenharmony_ci	u32 view_id;
678c2ecf20Sopenharmony_ci};
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* Map enum vmw_view_type to view destroy command ids*/
708c2ecf20Sopenharmony_ciextern const u32 vmw_view_destroy_cmds[];
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci/* Map enum vmw_view_type to SVGACOTableType */
738c2ecf20Sopenharmony_ciextern const SVGACOTableType vmw_view_cotables[];
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* Map enum vmw_so_type to SVGACOTableType */
768c2ecf20Sopenharmony_ciextern const SVGACOTableType vmw_so_cotables[];
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/*
798c2ecf20Sopenharmony_ci * vmw_view_cmd_to_type - Return the view type for a create or destroy command
808c2ecf20Sopenharmony_ci *
818c2ecf20Sopenharmony_ci * @id: The SVGA3D command id.
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * For a given view create or destroy command id, return the corresponding
848c2ecf20Sopenharmony_ci * enum vmw_view_type. If the command is unknown, return vmw_view_max.
858c2ecf20Sopenharmony_ci * The validity of the simplified calculation is verified in the
868c2ecf20Sopenharmony_ci * vmw_so_build_asserts() function.
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_cistatic inline enum vmw_view_type vmw_view_cmd_to_type(u32 id)
898c2ecf20Sopenharmony_ci{
908c2ecf20Sopenharmony_ci	u32 tmp = (id - SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW) / 2;
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	if (id == SVGA_3D_CMD_DX_DEFINE_UA_VIEW ||
938c2ecf20Sopenharmony_ci	    id == SVGA_3D_CMD_DX_DESTROY_UA_VIEW)
948c2ecf20Sopenharmony_ci		return vmw_view_ua;
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	if (tmp > (u32)vmw_view_max)
978c2ecf20Sopenharmony_ci		return vmw_view_max;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	return (enum vmw_view_type) tmp;
1008c2ecf20Sopenharmony_ci}
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci/*
1038c2ecf20Sopenharmony_ci * vmw_so_cmd_to_type - Return the state object type for a
1048c2ecf20Sopenharmony_ci * create or destroy command
1058c2ecf20Sopenharmony_ci *
1068c2ecf20Sopenharmony_ci * @id: The SVGA3D command id.
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci * For a given state object create or destroy command id,
1098c2ecf20Sopenharmony_ci * return the corresponding enum vmw_so_type. If the command is uknown,
1108c2ecf20Sopenharmony_ci * return vmw_so_max. We should perhaps optimize this function using
1118c2ecf20Sopenharmony_ci * a similar strategy as vmw_view_cmd_to_type().
1128c2ecf20Sopenharmony_ci */
1138c2ecf20Sopenharmony_cistatic inline enum vmw_so_type vmw_so_cmd_to_type(u32 id)
1148c2ecf20Sopenharmony_ci{
1158c2ecf20Sopenharmony_ci	switch (id) {
1168c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT:
1178c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT:
1188c2ecf20Sopenharmony_ci		return vmw_so_el;
1198c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE:
1208c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE:
1218c2ecf20Sopenharmony_ci		return vmw_so_bs;
1228c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE:
1238c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE:
1248c2ecf20Sopenharmony_ci		return vmw_so_ds;
1258c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE:
1268c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE:
1278c2ecf20Sopenharmony_ci		return vmw_so_rs;
1288c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE:
1298c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE:
1308c2ecf20Sopenharmony_ci		return vmw_so_ss;
1318c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT:
1328c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT_WITH_MOB:
1338c2ecf20Sopenharmony_ci	case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT:
1348c2ecf20Sopenharmony_ci		return vmw_so_so;
1358c2ecf20Sopenharmony_ci	default:
1368c2ecf20Sopenharmony_ci		break;
1378c2ecf20Sopenharmony_ci	}
1388c2ecf20Sopenharmony_ci	return vmw_so_max;
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci/*
1428c2ecf20Sopenharmony_ci * View management - vmwgfx_so.c
1438c2ecf20Sopenharmony_ci */
1448c2ecf20Sopenharmony_ciextern int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
1458c2ecf20Sopenharmony_ci			struct vmw_resource *ctx,
1468c2ecf20Sopenharmony_ci			struct vmw_resource *srf,
1478c2ecf20Sopenharmony_ci			enum vmw_view_type view_type,
1488c2ecf20Sopenharmony_ci			u32 user_key,
1498c2ecf20Sopenharmony_ci			const void *cmd,
1508c2ecf20Sopenharmony_ci			size_t cmd_size,
1518c2ecf20Sopenharmony_ci			struct list_head *list);
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ciextern int vmw_view_remove(struct vmw_cmdbuf_res_manager *man,
1548c2ecf20Sopenharmony_ci			   u32 user_key, enum vmw_view_type view_type,
1558c2ecf20Sopenharmony_ci			   struct list_head *list,
1568c2ecf20Sopenharmony_ci			   struct vmw_resource **res_p);
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciextern void vmw_view_surface_list_destroy(struct vmw_private *dev_priv,
1598c2ecf20Sopenharmony_ci					  struct list_head *view_list);
1608c2ecf20Sopenharmony_ciextern void vmw_view_cotable_list_destroy(struct vmw_private *dev_priv,
1618c2ecf20Sopenharmony_ci					  struct list_head *list,
1628c2ecf20Sopenharmony_ci					  bool readback);
1638c2ecf20Sopenharmony_ciextern struct vmw_resource *vmw_view_srf(struct vmw_resource *res);
1648c2ecf20Sopenharmony_ciextern struct vmw_resource *vmw_view_lookup(struct vmw_cmdbuf_res_manager *man,
1658c2ecf20Sopenharmony_ci					    enum vmw_view_type view_type,
1668c2ecf20Sopenharmony_ci					    u32 user_key);
1678c2ecf20Sopenharmony_ciextern u32 vmw_view_dirtying(struct vmw_resource *res);
1688c2ecf20Sopenharmony_ci#endif
169