18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */ 28c2ecf20Sopenharmony_ci/************************************************************************** 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright 2012-2014 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 288c2ecf20Sopenharmony_ci#ifndef _VMWGFX_RESOURCE_PRIV_H_ 298c2ecf20Sopenharmony_ci#define _VMWGFX_RESOURCE_PRIV_H_ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include "vmwgfx_drv.h" 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci/* 348c2ecf20Sopenharmony_ci * Extra memory required by the resource id's ida storage, which is allocated 358c2ecf20Sopenharmony_ci * separately from the base object itself. We estimate an on-average 128 bytes 368c2ecf20Sopenharmony_ci * per ida. 378c2ecf20Sopenharmony_ci */ 388c2ecf20Sopenharmony_ci#define VMW_IDA_ACC_SIZE 128 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cienum vmw_cmdbuf_res_state { 418c2ecf20Sopenharmony_ci VMW_CMDBUF_RES_COMMITTED, 428c2ecf20Sopenharmony_ci VMW_CMDBUF_RES_ADD, 438c2ecf20Sopenharmony_ci VMW_CMDBUF_RES_DEL 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci/** 478c2ecf20Sopenharmony_ci * struct vmw_user_resource_conv - Identify a derived user-exported resource 488c2ecf20Sopenharmony_ci * type and provide a function to convert its ttm_base_object pointer to 498c2ecf20Sopenharmony_ci * a struct vmw_resource 508c2ecf20Sopenharmony_ci */ 518c2ecf20Sopenharmony_cistruct vmw_user_resource_conv { 528c2ecf20Sopenharmony_ci enum ttm_object_type object_type; 538c2ecf20Sopenharmony_ci struct vmw_resource *(*base_obj_to_res)(struct ttm_base_object *base); 548c2ecf20Sopenharmony_ci void (*res_free) (struct vmw_resource *res); 558c2ecf20Sopenharmony_ci}; 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/** 588c2ecf20Sopenharmony_ci * struct vmw_res_func - members and functions common for a resource type 598c2ecf20Sopenharmony_ci * 608c2ecf20Sopenharmony_ci * @res_type: Enum that identifies the lru list to use for eviction. 618c2ecf20Sopenharmony_ci * @needs_backup: Whether the resource is guest-backed and needs 628c2ecf20Sopenharmony_ci * persistent buffer storage. 638c2ecf20Sopenharmony_ci * @type_name: String that identifies the resource type. 648c2ecf20Sopenharmony_ci * @backup_placement: TTM placement for backup buffers. 658c2ecf20Sopenharmony_ci * @may_evict Whether the resource may be evicted. 668c2ecf20Sopenharmony_ci * @create: Create a hardware resource. 678c2ecf20Sopenharmony_ci * @destroy: Destroy a hardware resource. 688c2ecf20Sopenharmony_ci * @bind: Bind a hardware resource to persistent buffer storage. 698c2ecf20Sopenharmony_ci * @unbind: Unbind a hardware resource from persistent 708c2ecf20Sopenharmony_ci * buffer storage. 718c2ecf20Sopenharmony_ci * @commit_notify: If the resource is a command buffer managed resource, 728c2ecf20Sopenharmony_ci * callback to notify that a define or remove command 738c2ecf20Sopenharmony_ci * has been committed to the device. 748c2ecf20Sopenharmony_ci * @dirty_alloc: Allocate a dirty tracker. NULL if dirty-tracking is not 758c2ecf20Sopenharmony_ci * supported. 768c2ecf20Sopenharmony_ci * @dirty_free: Free the dirty tracker. 778c2ecf20Sopenharmony_ci * @dirty_sync: Upload the dirty mob contents to the resource. 788c2ecf20Sopenharmony_ci * @dirty_add_range: Add a sequential dirty range to the resource 798c2ecf20Sopenharmony_ci * dirty tracker. 808c2ecf20Sopenharmony_ci * @clean: Clean the resource. 818c2ecf20Sopenharmony_ci */ 828c2ecf20Sopenharmony_cistruct vmw_res_func { 838c2ecf20Sopenharmony_ci enum vmw_res_type res_type; 848c2ecf20Sopenharmony_ci bool needs_backup; 858c2ecf20Sopenharmony_ci const char *type_name; 868c2ecf20Sopenharmony_ci struct ttm_placement *backup_placement; 878c2ecf20Sopenharmony_ci bool may_evict; 888c2ecf20Sopenharmony_ci u32 prio; 898c2ecf20Sopenharmony_ci u32 dirty_prio; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci int (*create) (struct vmw_resource *res); 928c2ecf20Sopenharmony_ci int (*destroy) (struct vmw_resource *res); 938c2ecf20Sopenharmony_ci int (*bind) (struct vmw_resource *res, 948c2ecf20Sopenharmony_ci struct ttm_validate_buffer *val_buf); 958c2ecf20Sopenharmony_ci int (*unbind) (struct vmw_resource *res, 968c2ecf20Sopenharmony_ci bool readback, 978c2ecf20Sopenharmony_ci struct ttm_validate_buffer *val_buf); 988c2ecf20Sopenharmony_ci void (*commit_notify)(struct vmw_resource *res, 998c2ecf20Sopenharmony_ci enum vmw_cmdbuf_res_state state); 1008c2ecf20Sopenharmony_ci int (*dirty_alloc)(struct vmw_resource *res); 1018c2ecf20Sopenharmony_ci void (*dirty_free)(struct vmw_resource *res); 1028c2ecf20Sopenharmony_ci int (*dirty_sync)(struct vmw_resource *res); 1038c2ecf20Sopenharmony_ci void (*dirty_range_add)(struct vmw_resource *res, size_t start, 1048c2ecf20Sopenharmony_ci size_t end); 1058c2ecf20Sopenharmony_ci int (*clean)(struct vmw_resource *res); 1068c2ecf20Sopenharmony_ci}; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/** 1098c2ecf20Sopenharmony_ci * struct vmw_simple_resource_func - members and functions common for the 1108c2ecf20Sopenharmony_ci * simple resource helpers. 1118c2ecf20Sopenharmony_ci * @res_func: struct vmw_res_func as described above. 1128c2ecf20Sopenharmony_ci * @ttm_res_type: TTM resource type used for handle recognition. 1138c2ecf20Sopenharmony_ci * @size: Size of the simple resource information struct. 1148c2ecf20Sopenharmony_ci * @init: Initialize the simple resource information. 1158c2ecf20Sopenharmony_ci * @hw_destroy: A resource hw_destroy function. 1168c2ecf20Sopenharmony_ci * @set_arg_handle: Set the handle output argument of the ioctl create struct. 1178c2ecf20Sopenharmony_ci */ 1188c2ecf20Sopenharmony_cistruct vmw_simple_resource_func { 1198c2ecf20Sopenharmony_ci const struct vmw_res_func res_func; 1208c2ecf20Sopenharmony_ci int ttm_res_type; 1218c2ecf20Sopenharmony_ci size_t size; 1228c2ecf20Sopenharmony_ci int (*init)(struct vmw_resource *res, void *data); 1238c2ecf20Sopenharmony_ci void (*hw_destroy)(struct vmw_resource *res); 1248c2ecf20Sopenharmony_ci void (*set_arg_handle)(void *data, u32 handle); 1258c2ecf20Sopenharmony_ci}; 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/** 1288c2ecf20Sopenharmony_ci * struct vmw_simple_resource - Kernel only side simple resource 1298c2ecf20Sopenharmony_ci * @res: The resource we derive from. 1308c2ecf20Sopenharmony_ci * @func: The method and member virtual table. 1318c2ecf20Sopenharmony_ci */ 1328c2ecf20Sopenharmony_cistruct vmw_simple_resource { 1338c2ecf20Sopenharmony_ci struct vmw_resource res; 1348c2ecf20Sopenharmony_ci const struct vmw_simple_resource_func *func; 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ciint vmw_resource_alloc_id(struct vmw_resource *res); 1388c2ecf20Sopenharmony_civoid vmw_resource_release_id(struct vmw_resource *res); 1398c2ecf20Sopenharmony_ciint vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res, 1408c2ecf20Sopenharmony_ci bool delay_id, 1418c2ecf20Sopenharmony_ci void (*res_free) (struct vmw_resource *res), 1428c2ecf20Sopenharmony_ci const struct vmw_res_func *func); 1438c2ecf20Sopenharmony_ciint 1448c2ecf20Sopenharmony_civmw_simple_resource_create_ioctl(struct drm_device *dev, 1458c2ecf20Sopenharmony_ci void *data, 1468c2ecf20Sopenharmony_ci struct drm_file *file_priv, 1478c2ecf20Sopenharmony_ci const struct vmw_simple_resource_func *func); 1488c2ecf20Sopenharmony_cistruct vmw_resource * 1498c2ecf20Sopenharmony_civmw_simple_resource_lookup(struct ttm_object_file *tfile, 1508c2ecf20Sopenharmony_ci uint32_t handle, 1518c2ecf20Sopenharmony_ci const struct vmw_simple_resource_func *func); 1528c2ecf20Sopenharmony_ci#endif 153