1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2 /************************************************************************** 3 * 4 * Copyright 2012-2014 VMware, Inc., Palo Alto, CA., USA 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 24 * USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 #ifndef _VMWGFX_RESOURCE_PRIV_H_ 29 #define _VMWGFX_RESOURCE_PRIV_H_ 30 31 #include "vmwgfx_drv.h" 32 33 #define VMW_IDA_ACC_SIZE 128 34 35 enum vmw_cmdbuf_res_state { 36 VMW_CMDBUF_RES_COMMITTED, 37 VMW_CMDBUF_RES_ADD, 38 VMW_CMDBUF_RES_DEL 39 }; 40 41 /** 42 * struct vmw_user_resource_conv - Identify a derived user-exported resource 43 * type and provide a function to convert its ttm_base_object pointer to 44 * a struct vmw_resource 45 */ 46 struct vmw_user_resource_conv { 47 enum ttm_object_type object_type; 48 struct vmw_resource *(*base_obj_to_res)(struct ttm_base_object *base); 49 void (*res_free) (struct vmw_resource *res); 50 }; 51 52 /** 53 * struct vmw_res_func - members and functions common for a resource type 54 * 55 * @res_type: Enum that identifies the lru list to use for eviction. 56 * @needs_backup: Whether the resource is guest-backed and needs 57 * persistent buffer storage. 58 * @type_name: String that identifies the resource type. 59 * @backup_placement: TTM placement for backup buffers. 60 * @may_evict Whether the resource may be evicted. 61 * @create: Create a hardware resource. 62 * @destroy: Destroy a hardware resource. 63 * @bind: Bind a hardware resource to persistent buffer storage. 64 * @unbind: Unbind a hardware resource from persistent 65 * buffer storage. 66 * @commit_notify: If the resource is a command buffer managed resource, 67 * callback to notify that a define or remove command 68 * has been committed to the device. 69 */ 70 struct vmw_res_func { 71 enum vmw_res_type res_type; 72 bool needs_backup; 73 const char *type_name; 74 struct ttm_placement *backup_placement; 75 bool may_evict; 76 77 int (*create) (struct vmw_resource *res); 78 int (*destroy) (struct vmw_resource *res); 79 int (*bind) (struct vmw_resource *res, 80 struct ttm_validate_buffer *val_buf); 81 int (*unbind) (struct vmw_resource *res, 82 bool readback, 83 struct ttm_validate_buffer *val_buf); 84 void (*commit_notify)(struct vmw_resource *res, 85 enum vmw_cmdbuf_res_state state); 86 }; 87 88 /** 89 * struct vmw_simple_resource_func - members and functions common for the 90 * simple resource helpers. 91 * @res_func: struct vmw_res_func as described above. 92 * @ttm_res_type: TTM resource type used for handle recognition. 93 * @size: Size of the simple resource information struct. 94 * @init: Initialize the simple resource information. 95 * @hw_destroy: A resource hw_destroy function. 96 * @set_arg_handle: Set the handle output argument of the ioctl create struct. 97 */ 98 struct vmw_simple_resource_func { 99 const struct vmw_res_func res_func; 100 int ttm_res_type; 101 size_t size; 102 int (*init)(struct vmw_resource *res, void *data); 103 void (*hw_destroy)(struct vmw_resource *res); 104 void (*set_arg_handle)(void *data, u32 handle); 105 }; 106 107 /** 108 * struct vmw_simple_resource - Kernel only side simple resource 109 * @res: The resource we derive from. 110 * @func: The method and member virtual table. 111 */ 112 struct vmw_simple_resource { 113 struct vmw_resource res; 114 const struct vmw_simple_resource_func *func; 115 }; 116 117 int vmw_resource_alloc_id(struct vmw_resource *res); 118 void vmw_resource_release_id(struct vmw_resource *res); 119 int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res, 120 bool delay_id, 121 void (*res_free) (struct vmw_resource *res), 122 const struct vmw_res_func *func); 123 void vmw_resource_activate(struct vmw_resource *res, 124 void (*hw_destroy) (struct vmw_resource *)); 125 int 126 vmw_simple_resource_create_ioctl(struct drm_device *dev, 127 void *data, 128 struct drm_file *file_priv, 129 const struct vmw_simple_resource_func *func); 130 struct vmw_resource * 131 vmw_simple_resource_lookup(struct ttm_object_file *tfile, 132 uint32_t handle, 133 const struct vmw_simple_resource_func *func); 134 #endif 135