Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) #ifndef __DRM_GEM_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #define __DRM_GEM_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * GEM Graphics Execution Manager Driver Interfaces
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Copyright (c) 2009-2010, Code Aurora Forum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Copyright © 2014 Intel Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   Daniel Vetter <daniel.vetter@ffwll.ch>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * Author: Gareth Hughes <gareth@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * Permission is hereby granted, free of charge, to any person obtaining a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * copy of this software and associated documentation files (the "Software"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * to deal in the Software without restriction, including without limitation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * and/or sell copies of the Software, and to permit persons to whom the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * Software is furnished to do so, subject to the following conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * The above copyright notice and this permission notice (including the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * paragraph) shall be included in all copies or substantial portions of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * OTHER DEALINGS IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/dma-resv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <drm/drm_vma_manager.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) struct drm_gem_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * struct drm_gem_object_funcs - GEM object functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) struct drm_gem_object_funcs {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	 * @free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	 * Deconstructor for drm_gem_objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 * This callback is mandatory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	void (*free)(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	 * @open:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	 * Called upon GEM handle creation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	int (*open)(struct drm_gem_object *obj, struct drm_file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * @close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * Called upon GEM handle release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	void (*close)(struct drm_gem_object *obj, struct drm_file *file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 * @print_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	 * If driver subclasses struct &drm_gem_object, it can implement this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	 * optional hook for printing additional driver specific info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * drm_printf_indent() should be used in the callback passing it the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * indent argument.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * This callback is called from drm_gem_print_info().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	void (*print_info)(struct drm_printer *p, unsigned int indent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			   const struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	 * @export:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	 * Export backing buffer as a &dma_buf.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	 * If this is not set drm_gem_prime_export() is used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct dma_buf *(*export)(struct drm_gem_object *obj, int flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	 * @pin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	 * Pin backing buffer in memory. Used by the drm_gem_map_attach() helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int (*pin)(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	 * @unpin:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	 * Unpin backing buffer. Used by the drm_gem_map_detach() helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	void (*unpin)(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * @get_sg_table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 * Returns a Scatter-Gather table representation of the buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	 * Used when exporting a buffer by the drm_gem_map_dma_buf() helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	 * Releasing is done by calling dma_unmap_sg_attrs() and sg_free_table()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	 * in drm_gem_unmap_buf(), therefore these helpers and this callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * here cannot be used for sg tables pointing at driver private memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * ranges.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	 * See also drm_prime_pages_to_sg().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct sg_table *(*get_sg_table)(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	 * @vmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	 * Returns a virtual address for the buffer. Used by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	 * drm_gem_dmabuf_vmap() helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	void *(*vmap)(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	 * @vunmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 * Releases the address previously returned by @vmap. Used by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	 * drm_gem_dmabuf_vunmap() helper.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	void (*vunmap)(struct drm_gem_object *obj, void *vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 * @mmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	 * Handle mmap() of the gem object, setup vma accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * This callback is optional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 * The callback is used by both drm_gem_mmap_obj() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	 * drm_gem_prime_mmap().  When @mmap is present @vm_ops is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	 * used, the @mmap callback must set vma->vm_ops instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int (*mmap)(struct drm_gem_object *obj, struct vm_area_struct *vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	 * @vm_ops:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	 * Virtual memory operations used with mmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	 * This is optional but necessary for mmap support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	const struct vm_operations_struct *vm_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  * struct drm_gem_object - GEM buffer object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * This structure defines the generic parts for GEM buffer objects, which are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * mostly around handling mmap and userspace handles.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * Buffer objects are often abbreviated to BO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct drm_gem_object {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * @refcount:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	 * Reference count of this object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	 * Please use drm_gem_object_get() to acquire and drm_gem_object_put_locked()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	 * or drm_gem_object_put() to release a reference to a GEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	 * buffer object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct kref refcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	 * @handle_count:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	 * This is the GEM file_priv handle count of this object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	 * Each handle also holds a reference. Note that when the handle_count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	 * drops to 0 any global names (e.g. the id in the flink namespace) will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	 * be cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	 * Protected by &drm_device.object_name_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	unsigned handle_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	 * @dev: DRM dev this object belongs to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct drm_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	 * @filp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	 * SHMEM file node used as backing storage for swappable buffer objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	 * GEM also supports driver private objects with driver-specific backing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	 * storage (contiguous CMA memory, special reserved blocks). In this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	 * case @filp is NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct file *filp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	 * @vma_node:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	 * Mapping info for this object to support mmap. Drivers are supposed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	 * allocate the mmap offset using drm_gem_create_mmap_offset(). The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	 * offset itself can be retrieved using drm_vma_node_offset_addr().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 * Memory mapping itself is handled by drm_gem_mmap(), which also checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	 * that userspace is allowed to access the object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct drm_vma_offset_node vma_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	 * @size:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	 * Size of the object, in bytes.  Immutable over the object's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	 * lifetime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	size_t size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * @name:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * Global name for this object, starts at 1. 0 means unnamed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * Access is covered by &drm_device.object_name_lock. This is used by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * the GEM_FLINK and GEM_OPEN ioctls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	int name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	 * @dma_buf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	 * dma-buf associated with this GEM object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	 * Pointer to the dma-buf associated with this gem object (either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	 * through importing or exporting). We break the resulting reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	 * loop when the last gem handle for this object is released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	 * Protected by &drm_device.object_name_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	struct dma_buf *dma_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	 * @import_attach:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	 * dma-buf attachment backing this object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	 * Any foreign dma_buf imported as a gem object has this set to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	 * attachment point for the device. This is invariant over the lifetime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	 * of a gem object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	 * The &drm_driver.gem_free_object_unlocked callback is responsible for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	 * cleaning up the dma_buf attachment and references acquired at import
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	 * Note that the drm gem/prime core does not depend upon drivers setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	 * this field any more. So for drivers where this doesn't make sense
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	 * (e.g. virtual devices or a displaylink behind an usb bus) they can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 * simply leave it as NULL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct dma_buf_attachment *import_attach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	 * @resv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	 * Pointer to reservation object associated with the this GEM object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	 * Normally (@resv == &@_resv) except for imported GEM objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct dma_resv *resv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 * @_resv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	 * A reservation object for this GEM object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	 * This is unused for imported GEM objects.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct dma_resv _resv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	/**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	 * @funcs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 * Optional GEM object functions. If this is set, it will be used instead of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 * corresponding &drm_driver GEM callbacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	 * New drivers should use this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	const struct drm_gem_object_funcs *funcs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)  * DEFINE_DRM_GEM_FOPS() - macro to generate file operations for GEM drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)  * @name: name for the generated structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * This macro autogenerates a suitable &struct file_operations for GEM based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * drivers, which can be assigned to &drm_driver.fops. Note that this structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * cannot be shared between drivers, because it contains a reference to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * current module using THIS_MODULE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * Note that the declaration is already marked as static - if you need a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * non-static version of this you're probably doing it wrong and will break the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * THIS_MODULE reference by accident.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #define DEFINE_DRM_GEM_FOPS(name) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	static const struct file_operations name = {\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		.owner		= THIS_MODULE,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		.open		= drm_open,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		.release	= drm_release,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		.unlocked_ioctl	= drm_ioctl,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		.compat_ioctl	= drm_compat_ioctl,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		.poll		= drm_poll,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		.read		= drm_read,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		.llseek		= noop_llseek,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		.mmap		= drm_gem_mmap,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) void drm_gem_object_release(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) void drm_gem_object_free(struct kref *kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) int drm_gem_object_init(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			struct drm_gem_object *obj, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) void drm_gem_private_object_init(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 				 struct drm_gem_object *obj, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) void drm_gem_vm_open(struct vm_area_struct *vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) void drm_gem_vm_close(struct vm_area_struct *vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		     struct vm_area_struct *vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)  * drm_gem_object_get - acquire a GEM buffer object reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)  * @obj: GEM buffer object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)  * This function acquires an additional reference to @obj. It is illegal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)  * call this without already holding a reference. No locks required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) static inline void drm_gem_object_get(struct drm_gem_object *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	kref_get(&obj->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) __attribute__((nonnull))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) __drm_gem_object_put(struct drm_gem_object *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	kref_put(&obj->refcount, drm_gem_object_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  * drm_gem_object_put - drop a GEM buffer object reference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)  * @obj: GEM buffer object
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * This releases a reference to @obj.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) drm_gem_object_put(struct drm_gem_object *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	if (obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		__drm_gem_object_put(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) void drm_gem_object_put_locked(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int drm_gem_handle_create(struct drm_file *file_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 			  struct drm_gem_object *obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 			  u32 *handlep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct page **drm_gem_get_pages(struct drm_gem_object *obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		bool dirty, bool accessed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 			   int count, struct drm_gem_object ***objs_out);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) struct drm_gem_object *drm_gem_object_lookup(struct drm_file *filp, u32 handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) long drm_gem_dma_resv_wait(struct drm_file *filep, u32 handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 				    bool wait_all, unsigned long timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) int drm_gem_lock_reservations(struct drm_gem_object **objs, int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			      struct ww_acquire_ctx *acquire_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) void drm_gem_unlock_reservations(struct drm_gem_object **objs, int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 				 struct ww_acquire_ctx *acquire_ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) int drm_gem_fence_array_add(struct xarray *fence_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 			    struct dma_fence *fence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) int drm_gem_fence_array_add_implicit(struct xarray *fence_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 				     struct drm_gem_object *obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 				     bool write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int drm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			    u32 handle, u64 *offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) int drm_gem_dumb_destroy(struct drm_file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 			 struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			 uint32_t handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) #endif /* __DRM_GEM_H__ */