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