18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */ 28c2ecf20Sopenharmony_ci/************************************************************************** 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright 2015 VMware, Inc., Palo Alto, CA., USA 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the 88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 128c2ecf20Sopenharmony_ci * the following conditions: 138c2ecf20Sopenharmony_ci * 148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the 158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 168c2ecf20Sopenharmony_ci * of the Software. 178c2ecf20Sopenharmony_ci * 188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 258c2ecf20Sopenharmony_ci * 268c2ecf20Sopenharmony_ci **************************************************************************/ 278c2ecf20Sopenharmony_ci#ifndef _VMWGFX_BINDING_H_ 288c2ecf20Sopenharmony_ci#define _VMWGFX_BINDING_H_ 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#include <linux/list.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include "device_include/svga3d_reg.h" 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define VMW_MAX_VIEW_BINDINGS 128 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define VMW_MAX_UAV_BIND_TYPE 2 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_cistruct vmw_private; 398c2ecf20Sopenharmony_cistruct vmw_ctx_binding_state; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* 428c2ecf20Sopenharmony_ci * enum vmw_ctx_binding_type - abstract resource to context binding types 438c2ecf20Sopenharmony_ci */ 448c2ecf20Sopenharmony_cienum vmw_ctx_binding_type { 458c2ecf20Sopenharmony_ci vmw_ctx_binding_shader, 468c2ecf20Sopenharmony_ci vmw_ctx_binding_rt, 478c2ecf20Sopenharmony_ci vmw_ctx_binding_tex, 488c2ecf20Sopenharmony_ci vmw_ctx_binding_cb, 498c2ecf20Sopenharmony_ci vmw_ctx_binding_dx_shader, 508c2ecf20Sopenharmony_ci vmw_ctx_binding_dx_rt, 518c2ecf20Sopenharmony_ci vmw_ctx_binding_sr, 528c2ecf20Sopenharmony_ci vmw_ctx_binding_ds, 538c2ecf20Sopenharmony_ci vmw_ctx_binding_so_target, 548c2ecf20Sopenharmony_ci vmw_ctx_binding_vb, 558c2ecf20Sopenharmony_ci vmw_ctx_binding_ib, 568c2ecf20Sopenharmony_ci vmw_ctx_binding_uav, 578c2ecf20Sopenharmony_ci vmw_ctx_binding_cs_uav, 588c2ecf20Sopenharmony_ci vmw_ctx_binding_so, 598c2ecf20Sopenharmony_ci vmw_ctx_binding_max 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/** 638c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo - single binding metadata 648c2ecf20Sopenharmony_ci * 658c2ecf20Sopenharmony_ci * @ctx_list: List head for the context's list of bindings. 668c2ecf20Sopenharmony_ci * @res_list: List head for a resource's list of bindings. 678c2ecf20Sopenharmony_ci * @ctx: Non-refcounted pointer to the context that owns the binding. NULL 688c2ecf20Sopenharmony_ci * indicates no binding present. 698c2ecf20Sopenharmony_ci * @res: Non-refcounted pointer to the resource the binding points to. This 708c2ecf20Sopenharmony_ci * is typically a surface or a view. 718c2ecf20Sopenharmony_ci * @bt: Binding type. 728c2ecf20Sopenharmony_ci * @scrubbed: Whether the binding has been scrubbed from the context. 738c2ecf20Sopenharmony_ci */ 748c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo { 758c2ecf20Sopenharmony_ci struct list_head ctx_list; 768c2ecf20Sopenharmony_ci struct list_head res_list; 778c2ecf20Sopenharmony_ci struct vmw_resource *ctx; 788c2ecf20Sopenharmony_ci struct vmw_resource *res; 798c2ecf20Sopenharmony_ci enum vmw_ctx_binding_type bt; 808c2ecf20Sopenharmony_ci bool scrubbed; 818c2ecf20Sopenharmony_ci}; 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci/** 848c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_tex - texture stage binding metadata 858c2ecf20Sopenharmony_ci * 868c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 878c2ecf20Sopenharmony_ci * @texture_stage: Device data used to reconstruct binding command. 888c2ecf20Sopenharmony_ci */ 898c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_tex { 908c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 918c2ecf20Sopenharmony_ci uint32 texture_stage; 928c2ecf20Sopenharmony_ci}; 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci/** 958c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_shader - Shader binding metadata 968c2ecf20Sopenharmony_ci * 978c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 988c2ecf20Sopenharmony_ci * @shader_slot: Device data used to reconstruct binding command. 998c2ecf20Sopenharmony_ci */ 1008c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_shader { 1018c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 1028c2ecf20Sopenharmony_ci SVGA3dShaderType shader_slot; 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/** 1068c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_cb - Constant buffer binding metadata 1078c2ecf20Sopenharmony_ci * 1088c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 1098c2ecf20Sopenharmony_ci * @shader_slot: Device data used to reconstruct binding command. 1108c2ecf20Sopenharmony_ci * @offset: Device data used to reconstruct binding command. 1118c2ecf20Sopenharmony_ci * @size: Device data used to reconstruct binding command. 1128c2ecf20Sopenharmony_ci * @slot: Device data used to reconstruct binding command. 1138c2ecf20Sopenharmony_ci */ 1148c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_cb { 1158c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 1168c2ecf20Sopenharmony_ci SVGA3dShaderType shader_slot; 1178c2ecf20Sopenharmony_ci uint32 offset; 1188c2ecf20Sopenharmony_ci uint32 size; 1198c2ecf20Sopenharmony_ci uint32 slot; 1208c2ecf20Sopenharmony_ci}; 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/** 1238c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_view - View binding metadata 1248c2ecf20Sopenharmony_ci * 1258c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 1268c2ecf20Sopenharmony_ci * @shader_slot: Device data used to reconstruct binding command. 1278c2ecf20Sopenharmony_ci * @slot: Device data used to reconstruct binding command. 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_view { 1308c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 1318c2ecf20Sopenharmony_ci SVGA3dShaderType shader_slot; 1328c2ecf20Sopenharmony_ci uint32 slot; 1338c2ecf20Sopenharmony_ci}; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci/** 1368c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_so_target - StreamOutput binding metadata 1378c2ecf20Sopenharmony_ci * 1388c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 1398c2ecf20Sopenharmony_ci * @offset: Device data used to reconstruct binding command. 1408c2ecf20Sopenharmony_ci * @size: Device data used to reconstruct binding command. 1418c2ecf20Sopenharmony_ci * @slot: Device data used to reconstruct binding command. 1428c2ecf20Sopenharmony_ci */ 1438c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_so_target { 1448c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 1458c2ecf20Sopenharmony_ci uint32 offset; 1468c2ecf20Sopenharmony_ci uint32 size; 1478c2ecf20Sopenharmony_ci uint32 slot; 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci/** 1518c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_vb - Vertex buffer binding metadata 1528c2ecf20Sopenharmony_ci * 1538c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 1548c2ecf20Sopenharmony_ci * @offset: Device data used to reconstruct binding command. 1558c2ecf20Sopenharmony_ci * @stride: Device data used to reconstruct binding command. 1568c2ecf20Sopenharmony_ci * @slot: Device data used to reconstruct binding command. 1578c2ecf20Sopenharmony_ci */ 1588c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_vb { 1598c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 1608c2ecf20Sopenharmony_ci uint32 offset; 1618c2ecf20Sopenharmony_ci uint32 stride; 1628c2ecf20Sopenharmony_ci uint32 slot; 1638c2ecf20Sopenharmony_ci}; 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci/** 1668c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_ib - StreamOutput binding metadata 1678c2ecf20Sopenharmony_ci * 1688c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 1698c2ecf20Sopenharmony_ci * @offset: Device data used to reconstruct binding command. 1708c2ecf20Sopenharmony_ci * @format: Device data used to reconstruct binding command. 1718c2ecf20Sopenharmony_ci */ 1728c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_ib { 1738c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 1748c2ecf20Sopenharmony_ci uint32 offset; 1758c2ecf20Sopenharmony_ci uint32 format; 1768c2ecf20Sopenharmony_ci}; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci/** 1798c2ecf20Sopenharmony_ci * struct vmw_dx_shader_bindings - per shader type context binding state 1808c2ecf20Sopenharmony_ci * 1818c2ecf20Sopenharmony_ci * @shader: The shader binding for this shader type 1828c2ecf20Sopenharmony_ci * @const_buffer: Const buffer bindings for this shader type. 1838c2ecf20Sopenharmony_ci * @shader_res: Shader resource view bindings for this shader type. 1848c2ecf20Sopenharmony_ci * @dirty_sr: Bitmap tracking individual shader resource bindings changes 1858c2ecf20Sopenharmony_ci * that have not yet been emitted to the device. 1868c2ecf20Sopenharmony_ci * @dirty: Bitmap tracking per-binding type binding changes that have not 1878c2ecf20Sopenharmony_ci * yet been emitted to the device. 1888c2ecf20Sopenharmony_ci */ 1898c2ecf20Sopenharmony_cistruct vmw_dx_shader_bindings { 1908c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo_shader shader; 1918c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo_cb const_buffers[SVGA3D_DX_MAX_CONSTBUFFERS]; 1928c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo_view shader_res[SVGA3D_DX_MAX_SRVIEWS]; 1938c2ecf20Sopenharmony_ci DECLARE_BITMAP(dirty_sr, SVGA3D_DX_MAX_SRVIEWS); 1948c2ecf20Sopenharmony_ci unsigned long dirty; 1958c2ecf20Sopenharmony_ci}; 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci/** 1988c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_uav - UAV context binding state. 1998c2ecf20Sopenharmony_ci * @views: UAV view bindings. 2008c2ecf20Sopenharmony_ci * @splice_index: The device splice index set by user-space. 2018c2ecf20Sopenharmony_ci */ 2028c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_uav { 2038c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo_view views[SVGA3D_MAX_UAVIEWS]; 2048c2ecf20Sopenharmony_ci uint32 index; 2058c2ecf20Sopenharmony_ci}; 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/** 2088c2ecf20Sopenharmony_ci * struct vmw_ctx_bindinfo_so - Stream output binding metadata. 2098c2ecf20Sopenharmony_ci * @bi: struct vmw_ctx_bindinfo we derive from. 2108c2ecf20Sopenharmony_ci * @slot: Device data used to reconstruct binding command. 2118c2ecf20Sopenharmony_ci */ 2128c2ecf20Sopenharmony_cistruct vmw_ctx_bindinfo_so { 2138c2ecf20Sopenharmony_ci struct vmw_ctx_bindinfo bi; 2148c2ecf20Sopenharmony_ci uint32 slot; 2158c2ecf20Sopenharmony_ci}; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ciextern void vmw_binding_add(struct vmw_ctx_binding_state *cbs, 2188c2ecf20Sopenharmony_ci const struct vmw_ctx_bindinfo *ci, 2198c2ecf20Sopenharmony_ci u32 shader_slot, u32 slot); 2208c2ecf20Sopenharmony_ciextern void vmw_binding_add_uav_index(struct vmw_ctx_binding_state *cbs, 2218c2ecf20Sopenharmony_ci uint32 slot, uint32 splice_index); 2228c2ecf20Sopenharmony_ciextern void 2238c2ecf20Sopenharmony_civmw_binding_state_commit(struct vmw_ctx_binding_state *to, 2248c2ecf20Sopenharmony_ci struct vmw_ctx_binding_state *from); 2258c2ecf20Sopenharmony_ciextern void vmw_binding_res_list_kill(struct list_head *head); 2268c2ecf20Sopenharmony_ciextern void vmw_binding_res_list_scrub(struct list_head *head); 2278c2ecf20Sopenharmony_ciextern int vmw_binding_rebind_all(struct vmw_ctx_binding_state *cbs); 2288c2ecf20Sopenharmony_ciextern void vmw_binding_state_kill(struct vmw_ctx_binding_state *cbs); 2298c2ecf20Sopenharmony_ciextern void vmw_binding_state_scrub(struct vmw_ctx_binding_state *cbs); 2308c2ecf20Sopenharmony_ciextern struct vmw_ctx_binding_state * 2318c2ecf20Sopenharmony_civmw_binding_state_alloc(struct vmw_private *dev_priv); 2328c2ecf20Sopenharmony_ciextern void vmw_binding_state_free(struct vmw_ctx_binding_state *cbs); 2338c2ecf20Sopenharmony_ciextern struct list_head * 2348c2ecf20Sopenharmony_civmw_binding_state_list(struct vmw_ctx_binding_state *cbs); 2358c2ecf20Sopenharmony_ciextern void vmw_binding_state_reset(struct vmw_ctx_binding_state *cbs); 2368c2ecf20Sopenharmony_ciextern u32 vmw_binding_dirtying(enum vmw_ctx_binding_type binding_type); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci#endif 240