xref: /openbmc/linux/drivers/gpu/drm/vmwgfx/vmwgfx_so.h (revision a9f58c456e9dde6f272e7be4d6bed607fd7008aa)
1dff96888SDirk Hohndel (VMware) /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2d80efd5cSThomas Hellstrom /**************************************************************************
3dff96888SDirk Hohndel (VMware)  * Copyright 2014-2015 VMware, Inc., Palo Alto, CA., USA
4d80efd5cSThomas Hellstrom  *
5d80efd5cSThomas Hellstrom  * Permission is hereby granted, free of charge, to any person obtaining a
6d80efd5cSThomas Hellstrom  * copy of this software and associated documentation files (the
7d80efd5cSThomas Hellstrom  * "Software"), to deal in the Software without restriction, including
8d80efd5cSThomas Hellstrom  * without limitation the rights to use, copy, modify, merge, publish,
9d80efd5cSThomas Hellstrom  * distribute, sub license, and/or sell copies of the Software, and to
10d80efd5cSThomas Hellstrom  * permit persons to whom the Software is furnished to do so, subject to
11d80efd5cSThomas Hellstrom  * the following conditions:
12d80efd5cSThomas Hellstrom  *
13d80efd5cSThomas Hellstrom  * The above copyright notice and this permission notice (including the
14d80efd5cSThomas Hellstrom  * next paragraph) shall be included in all copies or substantial portions
15d80efd5cSThomas Hellstrom  * of the Software.
16d80efd5cSThomas Hellstrom  *
17d80efd5cSThomas Hellstrom  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18d80efd5cSThomas Hellstrom  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19d80efd5cSThomas Hellstrom  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20d80efd5cSThomas Hellstrom  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
21d80efd5cSThomas Hellstrom  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22d80efd5cSThomas Hellstrom  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23d80efd5cSThomas Hellstrom  * USE OR OTHER DEALINGS IN THE SOFTWARE.
24d80efd5cSThomas Hellstrom  *
25d80efd5cSThomas Hellstrom  **************************************************************************/
26d80efd5cSThomas Hellstrom #ifndef VMW_SO_H
27d80efd5cSThomas Hellstrom #define VMW_SO_H
28d80efd5cSThomas Hellstrom 
29d80efd5cSThomas Hellstrom enum vmw_view_type {
30d80efd5cSThomas Hellstrom 	vmw_view_sr,
31d80efd5cSThomas Hellstrom 	vmw_view_rt,
32d80efd5cSThomas Hellstrom 	vmw_view_ds,
33d80efd5cSThomas Hellstrom 	vmw_view_max,
34d80efd5cSThomas Hellstrom };
35d80efd5cSThomas Hellstrom 
36d80efd5cSThomas Hellstrom enum vmw_so_type {
37d80efd5cSThomas Hellstrom 	vmw_so_el,
38d80efd5cSThomas Hellstrom 	vmw_so_bs,
39d80efd5cSThomas Hellstrom 	vmw_so_ds,
40d80efd5cSThomas Hellstrom 	vmw_so_rs,
41d80efd5cSThomas Hellstrom 	vmw_so_ss,
42d80efd5cSThomas Hellstrom 	vmw_so_so,
43d80efd5cSThomas Hellstrom 	vmw_so_max,
44d80efd5cSThomas Hellstrom };
45d80efd5cSThomas Hellstrom 
46d80efd5cSThomas Hellstrom /**
47d80efd5cSThomas Hellstrom  * union vmw_view_destroy - view destruction command body
48d80efd5cSThomas Hellstrom  *
49d80efd5cSThomas Hellstrom  * @rtv: RenderTarget view destruction command body
50d80efd5cSThomas Hellstrom  * @srv: ShaderResource view destruction command body
51d80efd5cSThomas Hellstrom  * @dsv: DepthStencil view destruction command body
52d80efd5cSThomas Hellstrom  * @view_id: A single u32 view id.
53d80efd5cSThomas Hellstrom  *
54d80efd5cSThomas Hellstrom  * The assumption here is that all union members are really represented by a
55d80efd5cSThomas Hellstrom  * single u32 in the command stream. If that's not the case,
56d80efd5cSThomas Hellstrom  * the size of this union will not equal the size of an u32, and the
57d80efd5cSThomas Hellstrom  * assumption is invalid, and we detect that at compile time in the
58d80efd5cSThomas Hellstrom  * vmw_so_build_asserts() function.
59d80efd5cSThomas Hellstrom  */
60d80efd5cSThomas Hellstrom union vmw_view_destroy {
61d80efd5cSThomas Hellstrom 	struct SVGA3dCmdDXDestroyRenderTargetView rtv;
62d80efd5cSThomas Hellstrom 	struct SVGA3dCmdDXDestroyShaderResourceView srv;
63d80efd5cSThomas Hellstrom 	struct SVGA3dCmdDXDestroyDepthStencilView dsv;
64d80efd5cSThomas Hellstrom 	u32 view_id;
65d80efd5cSThomas Hellstrom };
66d80efd5cSThomas Hellstrom 
67d80efd5cSThomas Hellstrom /* Map enum vmw_view_type to view destroy command ids*/
68d80efd5cSThomas Hellstrom extern const u32 vmw_view_destroy_cmds[];
69d80efd5cSThomas Hellstrom 
70d80efd5cSThomas Hellstrom /* Map enum vmw_view_type to SVGACOTableType */
71d80efd5cSThomas Hellstrom extern const SVGACOTableType vmw_view_cotables[];
72d80efd5cSThomas Hellstrom 
73d80efd5cSThomas Hellstrom /* Map enum vmw_so_type to SVGACOTableType */
74d80efd5cSThomas Hellstrom extern const SVGACOTableType vmw_so_cotables[];
75d80efd5cSThomas Hellstrom 
76d80efd5cSThomas Hellstrom /*
77d80efd5cSThomas Hellstrom  * vmw_view_cmd_to_type - Return the view type for a create or destroy command
78d80efd5cSThomas Hellstrom  *
79d80efd5cSThomas Hellstrom  * @id: The SVGA3D command id.
80d80efd5cSThomas Hellstrom  *
81d80efd5cSThomas Hellstrom  * For a given view create or destroy command id, return the corresponding
82d80efd5cSThomas Hellstrom  * enum vmw_view_type. If the command is unknown, return vmw_view_max.
83d80efd5cSThomas Hellstrom  * The validity of the simplified calculation is verified in the
84d80efd5cSThomas Hellstrom  * vmw_so_build_asserts() function.
85d80efd5cSThomas Hellstrom  */
86d80efd5cSThomas Hellstrom static inline enum vmw_view_type vmw_view_cmd_to_type(u32 id)
87d80efd5cSThomas Hellstrom {
88d80efd5cSThomas Hellstrom 	u32 tmp = (id - SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW) / 2;
89d80efd5cSThomas Hellstrom 
90d80efd5cSThomas Hellstrom 	if (tmp > (u32)vmw_view_max)
91d80efd5cSThomas Hellstrom 		return vmw_view_max;
92d80efd5cSThomas Hellstrom 
93d80efd5cSThomas Hellstrom 	return (enum vmw_view_type) tmp;
94d80efd5cSThomas Hellstrom }
95d80efd5cSThomas Hellstrom 
96d80efd5cSThomas Hellstrom /*
97d80efd5cSThomas Hellstrom  * vmw_so_cmd_to_type - Return the state object type for a
98d80efd5cSThomas Hellstrom  * create or destroy command
99d80efd5cSThomas Hellstrom  *
100d80efd5cSThomas Hellstrom  * @id: The SVGA3D command id.
101d80efd5cSThomas Hellstrom  *
102d80efd5cSThomas Hellstrom  * For a given state object create or destroy command id,
103d80efd5cSThomas Hellstrom  * return the corresponding enum vmw_so_type. If the command is uknown,
104d80efd5cSThomas Hellstrom  * return vmw_so_max. We should perhaps optimize this function using
105d80efd5cSThomas Hellstrom  * a similar strategy as vmw_view_cmd_to_type().
106d80efd5cSThomas Hellstrom  */
107d80efd5cSThomas Hellstrom static inline enum vmw_so_type vmw_so_cmd_to_type(u32 id)
108d80efd5cSThomas Hellstrom {
109d80efd5cSThomas Hellstrom 	switch (id) {
110d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT:
111d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT:
112d80efd5cSThomas Hellstrom 		return vmw_so_el;
113d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DEFINE_BLEND_STATE:
114d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DESTROY_BLEND_STATE:
115d80efd5cSThomas Hellstrom 		return vmw_so_bs;
116d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE:
117d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE:
118d80efd5cSThomas Hellstrom 		return vmw_so_ds;
119d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE:
120d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE:
121d80efd5cSThomas Hellstrom 		return vmw_so_rs;
122d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE:
123d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE:
124d80efd5cSThomas Hellstrom 		return vmw_so_ss;
125d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT:
126d80efd5cSThomas Hellstrom 	case SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT:
127d80efd5cSThomas Hellstrom 		return vmw_so_so;
128d80efd5cSThomas Hellstrom 	default:
129d80efd5cSThomas Hellstrom 		break;
130d80efd5cSThomas Hellstrom 	}
131d80efd5cSThomas Hellstrom 	return vmw_so_max;
132d80efd5cSThomas Hellstrom }
133d80efd5cSThomas Hellstrom 
134d80efd5cSThomas Hellstrom /*
135d80efd5cSThomas Hellstrom  * View management - vmwgfx_so.c
136d80efd5cSThomas Hellstrom  */
137d80efd5cSThomas Hellstrom extern int vmw_view_add(struct vmw_cmdbuf_res_manager *man,
138d80efd5cSThomas Hellstrom 			struct vmw_resource *ctx,
139d80efd5cSThomas Hellstrom 			struct vmw_resource *srf,
140d80efd5cSThomas Hellstrom 			enum vmw_view_type view_type,
141d80efd5cSThomas Hellstrom 			u32 user_key,
142d80efd5cSThomas Hellstrom 			const void *cmd,
143d80efd5cSThomas Hellstrom 			size_t cmd_size,
144d80efd5cSThomas Hellstrom 			struct list_head *list);
145d80efd5cSThomas Hellstrom 
146d80efd5cSThomas Hellstrom extern int vmw_view_remove(struct vmw_cmdbuf_res_manager *man,
147d80efd5cSThomas Hellstrom 			   u32 user_key, enum vmw_view_type view_type,
148d80efd5cSThomas Hellstrom 			   struct list_head *list,
149d80efd5cSThomas Hellstrom 			   struct vmw_resource **res_p);
150d80efd5cSThomas Hellstrom 
151d80efd5cSThomas Hellstrom extern void vmw_view_surface_list_destroy(struct vmw_private *dev_priv,
152d80efd5cSThomas Hellstrom 					  struct list_head *view_list);
153d80efd5cSThomas Hellstrom extern void vmw_view_cotable_list_destroy(struct vmw_private *dev_priv,
154d80efd5cSThomas Hellstrom 					  struct list_head *list,
155d80efd5cSThomas Hellstrom 					  bool readback);
156d80efd5cSThomas Hellstrom extern struct vmw_resource *vmw_view_srf(struct vmw_resource *res);
157d80efd5cSThomas Hellstrom extern struct vmw_resource *vmw_view_lookup(struct vmw_cmdbuf_res_manager *man,
158d80efd5cSThomas Hellstrom 					    enum vmw_view_type view_type,
159d80efd5cSThomas Hellstrom 					    u32 user_key);
160*a9f58c45SThomas Hellstrom extern u32 vmw_view_dirtying(struct vmw_resource *res);
161d80efd5cSThomas Hellstrom #endif
162