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