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