xref: /OK3568_Linux_fs/kernel/drivers/gpu/drm/vmwgfx/vmwgfx_binding.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2*4882a593Smuzhiyun /**************************************************************************
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright 2015 VMware, Inc., Palo Alto, CA., USA
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
7*4882a593Smuzhiyun  * copy of this software and associated documentation files (the
8*4882a593Smuzhiyun  * "Software"), to deal in the Software without restriction, including
9*4882a593Smuzhiyun  * without limitation the rights to use, copy, modify, merge, publish,
10*4882a593Smuzhiyun  * distribute, sub license, and/or sell copies of the Software, and to
11*4882a593Smuzhiyun  * permit persons to whom the Software is furnished to do so, subject to
12*4882a593Smuzhiyun  * the following conditions:
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the
15*4882a593Smuzhiyun  * next paragraph) shall be included in all copies or substantial portions
16*4882a593Smuzhiyun  * of the Software.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21*4882a593Smuzhiyun  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22*4882a593Smuzhiyun  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23*4882a593Smuzhiyun  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24*4882a593Smuzhiyun  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  **************************************************************************/
27*4882a593Smuzhiyun #ifndef _VMWGFX_BINDING_H_
28*4882a593Smuzhiyun #define _VMWGFX_BINDING_H_
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include <linux/list.h>
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #include "device_include/svga3d_reg.h"
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #define VMW_MAX_VIEW_BINDINGS 128
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define VMW_MAX_UAV_BIND_TYPE 2
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun struct vmw_private;
39*4882a593Smuzhiyun struct vmw_ctx_binding_state;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /*
42*4882a593Smuzhiyun  * enum vmw_ctx_binding_type - abstract resource to context binding types
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun enum vmw_ctx_binding_type {
45*4882a593Smuzhiyun 	vmw_ctx_binding_shader,
46*4882a593Smuzhiyun 	vmw_ctx_binding_rt,
47*4882a593Smuzhiyun 	vmw_ctx_binding_tex,
48*4882a593Smuzhiyun 	vmw_ctx_binding_cb,
49*4882a593Smuzhiyun 	vmw_ctx_binding_dx_shader,
50*4882a593Smuzhiyun 	vmw_ctx_binding_dx_rt,
51*4882a593Smuzhiyun 	vmw_ctx_binding_sr,
52*4882a593Smuzhiyun 	vmw_ctx_binding_ds,
53*4882a593Smuzhiyun 	vmw_ctx_binding_so_target,
54*4882a593Smuzhiyun 	vmw_ctx_binding_vb,
55*4882a593Smuzhiyun 	vmw_ctx_binding_ib,
56*4882a593Smuzhiyun 	vmw_ctx_binding_uav,
57*4882a593Smuzhiyun 	vmw_ctx_binding_cs_uav,
58*4882a593Smuzhiyun 	vmw_ctx_binding_so,
59*4882a593Smuzhiyun 	vmw_ctx_binding_max
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /**
63*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo - single binding metadata
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  * @ctx_list: List head for the context's list of bindings.
66*4882a593Smuzhiyun  * @res_list: List head for a resource's list of bindings.
67*4882a593Smuzhiyun  * @ctx: Non-refcounted pointer to the context that owns the binding. NULL
68*4882a593Smuzhiyun  * indicates no binding present.
69*4882a593Smuzhiyun  * @res: Non-refcounted pointer to the resource the binding points to. This
70*4882a593Smuzhiyun  * is typically a surface or a view.
71*4882a593Smuzhiyun  * @bt: Binding type.
72*4882a593Smuzhiyun  * @scrubbed: Whether the binding has been scrubbed from the context.
73*4882a593Smuzhiyun  */
74*4882a593Smuzhiyun struct vmw_ctx_bindinfo {
75*4882a593Smuzhiyun 	struct list_head ctx_list;
76*4882a593Smuzhiyun 	struct list_head res_list;
77*4882a593Smuzhiyun 	struct vmw_resource *ctx;
78*4882a593Smuzhiyun 	struct vmw_resource *res;
79*4882a593Smuzhiyun 	enum vmw_ctx_binding_type bt;
80*4882a593Smuzhiyun 	bool scrubbed;
81*4882a593Smuzhiyun };
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun /**
84*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_tex - texture stage binding metadata
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
87*4882a593Smuzhiyun  * @texture_stage: Device data used to reconstruct binding command.
88*4882a593Smuzhiyun  */
89*4882a593Smuzhiyun struct vmw_ctx_bindinfo_tex {
90*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
91*4882a593Smuzhiyun 	uint32 texture_stage;
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun /**
95*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_shader - Shader binding metadata
96*4882a593Smuzhiyun  *
97*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
98*4882a593Smuzhiyun  * @shader_slot: Device data used to reconstruct binding command.
99*4882a593Smuzhiyun  */
100*4882a593Smuzhiyun struct vmw_ctx_bindinfo_shader {
101*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
102*4882a593Smuzhiyun 	SVGA3dShaderType shader_slot;
103*4882a593Smuzhiyun };
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /**
106*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_cb - Constant buffer binding metadata
107*4882a593Smuzhiyun  *
108*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
109*4882a593Smuzhiyun  * @shader_slot: Device data used to reconstruct binding command.
110*4882a593Smuzhiyun  * @offset: Device data used to reconstruct binding command.
111*4882a593Smuzhiyun  * @size: Device data used to reconstruct binding command.
112*4882a593Smuzhiyun  * @slot: Device data used to reconstruct binding command.
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun struct vmw_ctx_bindinfo_cb {
115*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
116*4882a593Smuzhiyun 	SVGA3dShaderType shader_slot;
117*4882a593Smuzhiyun 	uint32 offset;
118*4882a593Smuzhiyun 	uint32 size;
119*4882a593Smuzhiyun 	uint32 slot;
120*4882a593Smuzhiyun };
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /**
123*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_view - View binding metadata
124*4882a593Smuzhiyun  *
125*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
126*4882a593Smuzhiyun  * @shader_slot: Device data used to reconstruct binding command.
127*4882a593Smuzhiyun  * @slot: Device data used to reconstruct binding command.
128*4882a593Smuzhiyun  */
129*4882a593Smuzhiyun struct vmw_ctx_bindinfo_view {
130*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
131*4882a593Smuzhiyun 	SVGA3dShaderType shader_slot;
132*4882a593Smuzhiyun 	uint32 slot;
133*4882a593Smuzhiyun };
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun /**
136*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_so_target - StreamOutput binding metadata
137*4882a593Smuzhiyun  *
138*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
139*4882a593Smuzhiyun  * @offset: Device data used to reconstruct binding command.
140*4882a593Smuzhiyun  * @size: Device data used to reconstruct binding command.
141*4882a593Smuzhiyun  * @slot: Device data used to reconstruct binding command.
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun struct vmw_ctx_bindinfo_so_target {
144*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
145*4882a593Smuzhiyun 	uint32 offset;
146*4882a593Smuzhiyun 	uint32 size;
147*4882a593Smuzhiyun 	uint32 slot;
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /**
151*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_vb - Vertex buffer binding metadata
152*4882a593Smuzhiyun  *
153*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
154*4882a593Smuzhiyun  * @offset: Device data used to reconstruct binding command.
155*4882a593Smuzhiyun  * @stride: Device data used to reconstruct binding command.
156*4882a593Smuzhiyun  * @slot: Device data used to reconstruct binding command.
157*4882a593Smuzhiyun  */
158*4882a593Smuzhiyun struct vmw_ctx_bindinfo_vb {
159*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
160*4882a593Smuzhiyun 	uint32 offset;
161*4882a593Smuzhiyun 	uint32 stride;
162*4882a593Smuzhiyun 	uint32 slot;
163*4882a593Smuzhiyun };
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun /**
166*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_ib - StreamOutput binding metadata
167*4882a593Smuzhiyun  *
168*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
169*4882a593Smuzhiyun  * @offset: Device data used to reconstruct binding command.
170*4882a593Smuzhiyun  * @format: Device data used to reconstruct binding command.
171*4882a593Smuzhiyun  */
172*4882a593Smuzhiyun struct vmw_ctx_bindinfo_ib {
173*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
174*4882a593Smuzhiyun 	uint32 offset;
175*4882a593Smuzhiyun 	uint32 format;
176*4882a593Smuzhiyun };
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun /**
179*4882a593Smuzhiyun  * struct vmw_dx_shader_bindings - per shader type context binding state
180*4882a593Smuzhiyun  *
181*4882a593Smuzhiyun  * @shader: The shader binding for this shader type
182*4882a593Smuzhiyun  * @const_buffer: Const buffer bindings for this shader type.
183*4882a593Smuzhiyun  * @shader_res: Shader resource view bindings for this shader type.
184*4882a593Smuzhiyun  * @dirty_sr: Bitmap tracking individual shader resource bindings changes
185*4882a593Smuzhiyun  * that have not yet been emitted to the device.
186*4882a593Smuzhiyun  * @dirty: Bitmap tracking per-binding type binding changes that have not
187*4882a593Smuzhiyun  * yet been emitted to the device.
188*4882a593Smuzhiyun  */
189*4882a593Smuzhiyun struct vmw_dx_shader_bindings {
190*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo_shader shader;
191*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo_cb const_buffers[SVGA3D_DX_MAX_CONSTBUFFERS];
192*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo_view shader_res[SVGA3D_DX_MAX_SRVIEWS];
193*4882a593Smuzhiyun 	DECLARE_BITMAP(dirty_sr, SVGA3D_DX_MAX_SRVIEWS);
194*4882a593Smuzhiyun 	unsigned long dirty;
195*4882a593Smuzhiyun };
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun /**
198*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_uav - UAV context binding state.
199*4882a593Smuzhiyun  * @views: UAV view bindings.
200*4882a593Smuzhiyun  * @splice_index: The device splice index set by user-space.
201*4882a593Smuzhiyun  */
202*4882a593Smuzhiyun struct vmw_ctx_bindinfo_uav {
203*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo_view views[SVGA3D_MAX_UAVIEWS];
204*4882a593Smuzhiyun 	uint32 index;
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun /**
208*4882a593Smuzhiyun  * struct vmw_ctx_bindinfo_so - Stream output binding metadata.
209*4882a593Smuzhiyun  * @bi: struct vmw_ctx_bindinfo we derive from.
210*4882a593Smuzhiyun  * @slot: Device data used to reconstruct binding command.
211*4882a593Smuzhiyun  */
212*4882a593Smuzhiyun struct vmw_ctx_bindinfo_so {
213*4882a593Smuzhiyun 	struct vmw_ctx_bindinfo bi;
214*4882a593Smuzhiyun 	uint32 slot;
215*4882a593Smuzhiyun };
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun extern void vmw_binding_add(struct vmw_ctx_binding_state *cbs,
218*4882a593Smuzhiyun 			    const struct vmw_ctx_bindinfo *ci,
219*4882a593Smuzhiyun 			    u32 shader_slot, u32 slot);
220*4882a593Smuzhiyun extern void vmw_binding_add_uav_index(struct vmw_ctx_binding_state *cbs,
221*4882a593Smuzhiyun 				      uint32 slot, uint32 splice_index);
222*4882a593Smuzhiyun extern void
223*4882a593Smuzhiyun vmw_binding_state_commit(struct vmw_ctx_binding_state *to,
224*4882a593Smuzhiyun 			 struct vmw_ctx_binding_state *from);
225*4882a593Smuzhiyun extern void vmw_binding_res_list_kill(struct list_head *head);
226*4882a593Smuzhiyun extern void vmw_binding_res_list_scrub(struct list_head *head);
227*4882a593Smuzhiyun extern int vmw_binding_rebind_all(struct vmw_ctx_binding_state *cbs);
228*4882a593Smuzhiyun extern void vmw_binding_state_kill(struct vmw_ctx_binding_state *cbs);
229*4882a593Smuzhiyun extern void vmw_binding_state_scrub(struct vmw_ctx_binding_state *cbs);
230*4882a593Smuzhiyun extern struct vmw_ctx_binding_state *
231*4882a593Smuzhiyun vmw_binding_state_alloc(struct vmw_private *dev_priv);
232*4882a593Smuzhiyun extern void vmw_binding_state_free(struct vmw_ctx_binding_state *cbs);
233*4882a593Smuzhiyun extern struct list_head *
234*4882a593Smuzhiyun vmw_binding_state_list(struct vmw_ctx_binding_state *cbs);
235*4882a593Smuzhiyun extern void vmw_binding_state_reset(struct vmw_ctx_binding_state *cbs);
236*4882a593Smuzhiyun extern u32 vmw_binding_dirtying(enum vmw_ctx_binding_type binding_type);
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun #endif
240