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