Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / vmwgfx / vmwgfx_resource_priv.h
blob3b7438b2d289fdd2100db8c89cb6ae886426f5aa
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /**************************************************************************
4 * Copyright 2012-2014 VMware, Inc., Palo Alto, CA., USA
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:
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.
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.
26 **************************************************************************/
28 #ifndef _VMWGFX_RESOURCE_PRIV_H_
29 #define _VMWGFX_RESOURCE_PRIV_H_
31 #include "vmwgfx_drv.h"
34 * Extra memory required by the resource id's ida storage, which is allocated
35 * separately from the base object itself. We estimate an on-average 128 bytes
36 * per ida.
38 #define VMW_IDA_ACC_SIZE 128
40 enum vmw_cmdbuf_res_state {
41 VMW_CMDBUF_RES_COMMITTED,
42 VMW_CMDBUF_RES_ADD,
43 VMW_CMDBUF_RES_DEL
46 /**
47 * struct vmw_user_resource_conv - Identify a derived user-exported resource
48 * type and provide a function to convert its ttm_base_object pointer to
49 * a struct vmw_resource
51 struct vmw_user_resource_conv {
52 enum ttm_object_type object_type;
53 struct vmw_resource *(*base_obj_to_res)(struct ttm_base_object *base);
54 void (*res_free) (struct vmw_resource *res);
57 /**
58 * struct vmw_res_func - members and functions common for a resource type
60 * @res_type: Enum that identifies the lru list to use for eviction.
61 * @needs_backup: Whether the resource is guest-backed and needs
62 * persistent buffer storage.
63 * @type_name: String that identifies the resource type.
64 * @backup_placement: TTM placement for backup buffers.
65 * @may_evict Whether the resource may be evicted.
66 * @create: Create a hardware resource.
67 * @destroy: Destroy a hardware resource.
68 * @bind: Bind a hardware resource to persistent buffer storage.
69 * @unbind: Unbind a hardware resource from persistent
70 * buffer storage.
71 * @commit_notify: If the resource is a command buffer managed resource,
72 * callback to notify that a define or remove command
73 * has been committed to the device.
74 * @dirty_alloc: Allocate a dirty tracker. NULL if dirty-tracking is not
75 * supported.
76 * @dirty_free: Free the dirty tracker.
77 * @dirty_sync: Upload the dirty mob contents to the resource.
78 * @dirty_add_range: Add a sequential dirty range to the resource
79 * dirty tracker.
80 * @clean: Clean the resource.
82 struct vmw_res_func {
83 enum vmw_res_type res_type;
84 bool needs_backup;
85 const char *type_name;
86 struct ttm_placement *backup_placement;
87 bool may_evict;
88 u32 prio;
89 u32 dirty_prio;
91 int (*create) (struct vmw_resource *res);
92 int (*destroy) (struct vmw_resource *res);
93 int (*bind) (struct vmw_resource *res,
94 struct ttm_validate_buffer *val_buf);
95 int (*unbind) (struct vmw_resource *res,
96 bool readback,
97 struct ttm_validate_buffer *val_buf);
98 void (*commit_notify)(struct vmw_resource *res,
99 enum vmw_cmdbuf_res_state state);
100 int (*dirty_alloc)(struct vmw_resource *res);
101 void (*dirty_free)(struct vmw_resource *res);
102 int (*dirty_sync)(struct vmw_resource *res);
103 void (*dirty_range_add)(struct vmw_resource *res, size_t start,
104 size_t end);
105 int (*clean)(struct vmw_resource *res);
109 * struct vmw_simple_resource_func - members and functions common for the
110 * simple resource helpers.
111 * @res_func: struct vmw_res_func as described above.
112 * @ttm_res_type: TTM resource type used for handle recognition.
113 * @size: Size of the simple resource information struct.
114 * @init: Initialize the simple resource information.
115 * @hw_destroy: A resource hw_destroy function.
116 * @set_arg_handle: Set the handle output argument of the ioctl create struct.
118 struct vmw_simple_resource_func {
119 const struct vmw_res_func res_func;
120 int ttm_res_type;
121 size_t size;
122 int (*init)(struct vmw_resource *res, void *data);
123 void (*hw_destroy)(struct vmw_resource *res);
124 void (*set_arg_handle)(void *data, u32 handle);
128 * struct vmw_simple_resource - Kernel only side simple resource
129 * @res: The resource we derive from.
130 * @func: The method and member virtual table.
132 struct vmw_simple_resource {
133 struct vmw_resource res;
134 const struct vmw_simple_resource_func *func;
137 int vmw_resource_alloc_id(struct vmw_resource *res);
138 void vmw_resource_release_id(struct vmw_resource *res);
139 int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,
140 bool delay_id,
141 void (*res_free) (struct vmw_resource *res),
142 const struct vmw_res_func *func);
144 vmw_simple_resource_create_ioctl(struct drm_device *dev,
145 void *data,
146 struct drm_file *file_priv,
147 const struct vmw_simple_resource_func *func);
148 struct vmw_resource *
149 vmw_simple_resource_lookup(struct ttm_object_file *tfile,
150 uint32_t handle,
151 const struct vmw_simple_resource_func *func);
152 #endif