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