162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR MIT */ 262306a36Sopenharmony_ci/************************************************************************** 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright 2012-2014 VMware, Inc., Palo Alto, CA., USA 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 762306a36Sopenharmony_ci * copy of this software and associated documentation files (the 862306a36Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 962306a36Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 1062306a36Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to 1162306a36Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 1262306a36Sopenharmony_ci * the following conditions: 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the 1562306a36Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions 1662306a36Sopenharmony_ci * of the Software. 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1962306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2062306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 2162306a36Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 2262306a36Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2362306a36Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2462306a36Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 2562306a36Sopenharmony_ci * 2662306a36Sopenharmony_ci **************************************************************************/ 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci#ifndef _VMWGFX_RESOURCE_PRIV_H_ 2962306a36Sopenharmony_ci#define _VMWGFX_RESOURCE_PRIV_H_ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include "vmwgfx_drv.h" 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci/* 3462306a36Sopenharmony_ci * Extra memory required by the resource id's ida storage, which is allocated 3562306a36Sopenharmony_ci * separately from the base object itself. We estimate an on-average 128 bytes 3662306a36Sopenharmony_ci * per ida. 3762306a36Sopenharmony_ci */ 3862306a36Sopenharmony_ci#define VMW_IDA_ACC_SIZE 128 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_cienum vmw_cmdbuf_res_state { 4162306a36Sopenharmony_ci VMW_CMDBUF_RES_COMMITTED, 4262306a36Sopenharmony_ci VMW_CMDBUF_RES_ADD, 4362306a36Sopenharmony_ci VMW_CMDBUF_RES_DEL 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci/** 4762306a36Sopenharmony_ci * struct vmw_user_resource_conv - Identify a derived user-exported resource 4862306a36Sopenharmony_ci * type and provide a function to convert its ttm_base_object pointer to 4962306a36Sopenharmony_ci * a struct vmw_resource 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_cistruct vmw_user_resource_conv { 5262306a36Sopenharmony_ci enum ttm_object_type object_type; 5362306a36Sopenharmony_ci struct vmw_resource *(*base_obj_to_res)(struct ttm_base_object *base); 5462306a36Sopenharmony_ci void (*res_free) (struct vmw_resource *res); 5562306a36Sopenharmony_ci}; 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/** 5862306a36Sopenharmony_ci * struct vmw_res_func - members and functions common for a resource type 5962306a36Sopenharmony_ci * 6062306a36Sopenharmony_ci * @res_type: Enum that identifies the lru list to use for eviction. 6162306a36Sopenharmony_ci * @needs_guest_memory:Whether the resource is guest-backed and needs 6262306a36Sopenharmony_ci * persistent buffer storage. 6362306a36Sopenharmony_ci * @type_name: String that identifies the resource type. 6462306a36Sopenharmony_ci * @domain: TTM placement for guest memory buffers. 6562306a36Sopenharmony_ci * @busy_domain: TTM busy placement for guest memory buffers. 6662306a36Sopenharmony_ci * @may_evict Whether the resource may be evicted. 6762306a36Sopenharmony_ci * @create: Create a hardware resource. 6862306a36Sopenharmony_ci * @destroy: Destroy a hardware resource. 6962306a36Sopenharmony_ci * @bind: Bind a hardware resource to persistent buffer storage. 7062306a36Sopenharmony_ci * @unbind: Unbind a hardware resource from persistent 7162306a36Sopenharmony_ci * buffer storage. 7262306a36Sopenharmony_ci * @commit_notify: If the resource is a command buffer managed resource, 7362306a36Sopenharmony_ci * callback to notify that a define or remove command 7462306a36Sopenharmony_ci * has been committed to the device. 7562306a36Sopenharmony_ci * @dirty_alloc: Allocate a dirty tracker. NULL if dirty-tracking is not 7662306a36Sopenharmony_ci * supported. 7762306a36Sopenharmony_ci * @dirty_free: Free the dirty tracker. 7862306a36Sopenharmony_ci * @dirty_sync: Upload the dirty mob contents to the resource. 7962306a36Sopenharmony_ci * @dirty_add_range: Add a sequential dirty range to the resource 8062306a36Sopenharmony_ci * dirty tracker. 8162306a36Sopenharmony_ci * @clean: Clean the resource. 8262306a36Sopenharmony_ci */ 8362306a36Sopenharmony_cistruct vmw_res_func { 8462306a36Sopenharmony_ci enum vmw_res_type res_type; 8562306a36Sopenharmony_ci bool needs_guest_memory; 8662306a36Sopenharmony_ci const char *type_name; 8762306a36Sopenharmony_ci u32 domain; 8862306a36Sopenharmony_ci u32 busy_domain; 8962306a36Sopenharmony_ci bool may_evict; 9062306a36Sopenharmony_ci u32 prio; 9162306a36Sopenharmony_ci u32 dirty_prio; 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci int (*create) (struct vmw_resource *res); 9462306a36Sopenharmony_ci int (*destroy) (struct vmw_resource *res); 9562306a36Sopenharmony_ci int (*bind) (struct vmw_resource *res, 9662306a36Sopenharmony_ci struct ttm_validate_buffer *val_buf); 9762306a36Sopenharmony_ci int (*unbind) (struct vmw_resource *res, 9862306a36Sopenharmony_ci bool readback, 9962306a36Sopenharmony_ci struct ttm_validate_buffer *val_buf); 10062306a36Sopenharmony_ci void (*commit_notify)(struct vmw_resource *res, 10162306a36Sopenharmony_ci enum vmw_cmdbuf_res_state state); 10262306a36Sopenharmony_ci int (*dirty_alloc)(struct vmw_resource *res); 10362306a36Sopenharmony_ci void (*dirty_free)(struct vmw_resource *res); 10462306a36Sopenharmony_ci int (*dirty_sync)(struct vmw_resource *res); 10562306a36Sopenharmony_ci void (*dirty_range_add)(struct vmw_resource *res, size_t start, 10662306a36Sopenharmony_ci size_t end); 10762306a36Sopenharmony_ci int (*clean)(struct vmw_resource *res); 10862306a36Sopenharmony_ci}; 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/** 11162306a36Sopenharmony_ci * struct vmw_simple_resource_func - members and functions common for the 11262306a36Sopenharmony_ci * simple resource helpers. 11362306a36Sopenharmony_ci * @res_func: struct vmw_res_func as described above. 11462306a36Sopenharmony_ci * @ttm_res_type: TTM resource type used for handle recognition. 11562306a36Sopenharmony_ci * @size: Size of the simple resource information struct. 11662306a36Sopenharmony_ci * @init: Initialize the simple resource information. 11762306a36Sopenharmony_ci * @hw_destroy: A resource hw_destroy function. 11862306a36Sopenharmony_ci * @set_arg_handle: Set the handle output argument of the ioctl create struct. 11962306a36Sopenharmony_ci */ 12062306a36Sopenharmony_cistruct vmw_simple_resource_func { 12162306a36Sopenharmony_ci const struct vmw_res_func res_func; 12262306a36Sopenharmony_ci int ttm_res_type; 12362306a36Sopenharmony_ci size_t size; 12462306a36Sopenharmony_ci int (*init)(struct vmw_resource *res, void *data); 12562306a36Sopenharmony_ci void (*hw_destroy)(struct vmw_resource *res); 12662306a36Sopenharmony_ci void (*set_arg_handle)(void *data, u32 handle); 12762306a36Sopenharmony_ci}; 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci/** 13062306a36Sopenharmony_ci * struct vmw_simple_resource - Kernel only side simple resource 13162306a36Sopenharmony_ci * @res: The resource we derive from. 13262306a36Sopenharmony_ci * @func: The method and member virtual table. 13362306a36Sopenharmony_ci */ 13462306a36Sopenharmony_cistruct vmw_simple_resource { 13562306a36Sopenharmony_ci struct vmw_resource res; 13662306a36Sopenharmony_ci const struct vmw_simple_resource_func *func; 13762306a36Sopenharmony_ci}; 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciint vmw_resource_alloc_id(struct vmw_resource *res); 14062306a36Sopenharmony_civoid vmw_resource_release_id(struct vmw_resource *res); 14162306a36Sopenharmony_ciint vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res, 14262306a36Sopenharmony_ci bool delay_id, 14362306a36Sopenharmony_ci void (*res_free) (struct vmw_resource *res), 14462306a36Sopenharmony_ci const struct vmw_res_func *func); 14562306a36Sopenharmony_ciint 14662306a36Sopenharmony_civmw_simple_resource_create_ioctl(struct drm_device *dev, 14762306a36Sopenharmony_ci void *data, 14862306a36Sopenharmony_ci struct drm_file *file_priv, 14962306a36Sopenharmony_ci const struct vmw_simple_resource_func *func); 15062306a36Sopenharmony_cistruct vmw_resource * 15162306a36Sopenharmony_civmw_simple_resource_lookup(struct ttm_object_file *tfile, 15262306a36Sopenharmony_ci uint32_t handle, 15362306a36Sopenharmony_ci const struct vmw_simple_resource_func *func); 15462306a36Sopenharmony_ci#endif 155