aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2015-10-22 13:11:27 -0400
committerDaniel Vetter <daniel.vetter@ffwll.ch>2015-11-24 05:41:49 -0500
commitdecc60bf49b5e514ef60fe9dd4b2517328b27e15 (patch)
treeaf244481796cc138714449757ebccd1a065f0423
parent1ec218373b8ebda821aec00bb156a9c94fad9cd4 (diff)
drm: Update GEM refcounting docs
I just realized that I've forgotten to update all the gem refcounting docs. For pennance also add pretty docs for the overall drm_gem_object structure, with a few links thrown in fore good. As usually we need to make sure the kerneldoc reference is at most a sect2 for otherwise it won't be listed. Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/1445533889-7661-1-git-send-email-daniel.vetter@ffwll.ch Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
-rw-r--r--Documentation/DocBook/gpu.tmpl15
-rw-r--r--include/drm/drm_gem.h106
2 files changed, 100 insertions, 21 deletions
diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index 201dcd3c2e9d..47b06dfa454d 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -635,10 +635,10 @@ char *date;</synopsis>
635 acquired and release by <function>calling drm_gem_object_reference</function> 635 acquired and release by <function>calling drm_gem_object_reference</function>
636 and <function>drm_gem_object_unreference</function> respectively. The 636 and <function>drm_gem_object_unreference</function> respectively. The
637 caller must hold the <structname>drm_device</structname> 637 caller must hold the <structname>drm_device</structname>
638 <structfield>struct_mutex</structfield> lock. As a convenience, GEM 638 <structfield>struct_mutex</structfield> lock when calling
639 provides the <function>drm_gem_object_reference_unlocked</function> and 639 <function>drm_gem_object_reference</function>. As a convenience, GEM
640 <function>drm_gem_object_unreference_unlocked</function> functions that 640 provides <function>drm_gem_object_unreference_unlocked</function>
641 can be called without holding the lock. 641 functions that can be called without holding the lock.
642 </para> 642 </para>
643 <para> 643 <para>
644 When the last reference to a GEM object is released the GEM core calls 644 When the last reference to a GEM object is released the GEM core calls
@@ -836,10 +836,11 @@ char *date;</synopsis>
836 abstracted from the client in libdrm. 836 abstracted from the client in libdrm.
837 </para> 837 </para>
838 </sect3> 838 </sect3>
839 <sect3> 839 </sect2>
840 <title>GEM Function Reference</title> 840 <sect2>
841 <title>GEM Function Reference</title>
841!Edrivers/gpu/drm/drm_gem.c 842!Edrivers/gpu/drm/drm_gem.c
842 </sect3> 843!Iinclude/drm/drm_gem.h
843 </sect2> 844 </sect2>
844 <sect2> 845 <sect2>
845 <title>VMA Offset Manager</title> 846 <title>VMA Offset Manager</title>
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
index 15e7f007380f..0b3e11ab8757 100644
--- a/include/drm/drm_gem.h
+++ b/include/drm/drm_gem.h
@@ -35,76 +35,129 @@
35 */ 35 */
36 36
37/** 37/**
38 * This structure defines the drm_mm memory object, which will be used by the 38 * struct drm_gem_object - GEM buffer object
39 * DRM for its buffer objects. 39 *
40 * This structure defines the generic parts for GEM buffer objects, which are
41 * mostly around handling mmap and userspace handles.
42 *
43 * Buffer objects are often abbreviated to BO.
40 */ 44 */
41struct drm_gem_object { 45struct drm_gem_object {
42 /** Reference count of this object */ 46 /**
47 * @refcount:
48 *
49 * Reference count of this object
50 *
51 * Please use drm_gem_object_reference() to acquire and
52 * drm_gem_object_unreference() or drm_gem_object_unreference_unlocked()
53 * to release a reference to a GEM buffer object.
54 */
43 struct kref refcount; 55 struct kref refcount;
44 56
45 /** 57 /**
46 * handle_count - gem file_priv handle count of this object 58 * @handle_count:
59 *
60 * This is the GEM file_priv handle count of this object.
47 * 61 *
48 * Each handle also holds a reference. Note that when the handle_count 62 * Each handle also holds a reference. Note that when the handle_count
49 * drops to 0 any global names (e.g. the id in the flink namespace) will 63 * drops to 0 any global names (e.g. the id in the flink namespace) will
50 * be cleared. 64 * be cleared.
51 * 65 *
52 * Protected by dev->object_name_lock. 66 * Protected by dev->object_name_lock.
53 * */ 67 */
54 unsigned handle_count; 68 unsigned handle_count;
55 69
56 /** Related drm device */ 70 /**
71 * @dev: DRM dev this object belongs to.
72 */
57 struct drm_device *dev; 73 struct drm_device *dev;
58 74
59 /** File representing the shmem storage */ 75 /**
76 * @filp:
77 *
78 * SHMEM file node used as backing storage for swappable buffer objects.
79 * GEM also supports driver private objects with driver-specific backing
80 * storage (contiguous CMA memory, special reserved blocks). In this
81 * case @filp is NULL.
82 */
60 struct file *filp; 83 struct file *filp;
61 84
62 /* Mapping info for this object */ 85 /**
86 * @vma_node:
87 *
88 * Mapping info for this object to support mmap. Drivers are supposed to
89 * allocate the mmap offset using drm_gem_create_mmap_offset(). The
90 * offset itself can be retrieved using drm_vma_node_offset_addr().
91 *
92 * Memory mapping itself is handled by drm_gem_mmap(), which also checks
93 * that userspace is allowed to access the object.
94 */
63 struct drm_vma_offset_node vma_node; 95 struct drm_vma_offset_node vma_node;
64 96
65 /** 97 /**
98 * @size:
99 *
66 * Size of the object, in bytes. Immutable over the object's 100 * Size of the object, in bytes. Immutable over the object's
67 * lifetime. 101 * lifetime.
68 */ 102 */
69 size_t size; 103 size_t size;
70 104
71 /** 105 /**
106 * @name:
107 *
72 * Global name for this object, starts at 1. 0 means unnamed. 108 * Global name for this object, starts at 1. 0 means unnamed.
73 * Access is covered by the object_name_lock in the related drm_device 109 * Access is covered by dev->object_name_lock. This is used by the GEM_FLINK
110 * and GEM_OPEN ioctls.
74 */ 111 */
75 int name; 112 int name;
76 113
77 /** 114 /**
78 * Memory domains. These monitor which caches contain read/write data 115 * @read_domains:
116 *
117 * Read memory domains. These monitor which caches contain read/write data
79 * related to the object. When transitioning from one set of domains 118 * related to the object. When transitioning from one set of domains
80 * to another, the driver is called to ensure that caches are suitably 119 * to another, the driver is called to ensure that caches are suitably
81 * flushed and invalidated 120 * flushed and invalidated.
82 */ 121 */
83 uint32_t read_domains; 122 uint32_t read_domains;
123
124 /**
125 * @write_domain: Corresponding unique write memory domain.
126 */
84 uint32_t write_domain; 127 uint32_t write_domain;
85 128
86 /** 129 /**
130 * @pending_read_domains:
131 *
87 * While validating an exec operation, the 132 * While validating an exec operation, the
88 * new read/write domain values are computed here. 133 * new read/write domain values are computed here.
89 * They will be transferred to the above values 134 * They will be transferred to the above values
90 * at the point that any cache flushing occurs 135 * at the point that any cache flushing occurs
91 */ 136 */
92 uint32_t pending_read_domains; 137 uint32_t pending_read_domains;
138
139 /**
140 * @pending_write_domain: Write domain similar to @pending_read_domains.
141 */
93 uint32_t pending_write_domain; 142 uint32_t pending_write_domain;
94 143
95 /** 144 /**
96 * dma_buf - dma buf associated with this GEM object 145 * @dma_buf:
146 *
147 * dma-buf associated with this GEM object.
97 * 148 *
98 * Pointer to the dma-buf associated with this gem object (either 149 * Pointer to the dma-buf associated with this gem object (either
99 * through importing or exporting). We break the resulting reference 150 * through importing or exporting). We break the resulting reference
100 * loop when the last gem handle for this object is released. 151 * loop when the last gem handle for this object is released.
101 * 152 *
102 * Protected by obj->object_name_lock 153 * Protected by obj->object_name_lock.
103 */ 154 */
104 struct dma_buf *dma_buf; 155 struct dma_buf *dma_buf;
105 156
106 /** 157 /**
107 * import_attach - dma buf attachment backing this object 158 * @import_attach:
159 *
160 * dma-buf attachment backing this object.
108 * 161 *
109 * Any foreign dma_buf imported as a gem object has this set to the 162 * Any foreign dma_buf imported as a gem object has this set to the
110 * attachment point for the device. This is invariant over the lifetime 163 * attachment point for the device. This is invariant over the lifetime
@@ -133,12 +186,30 @@ int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
133 struct vm_area_struct *vma); 186 struct vm_area_struct *vma);
134int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma); 187int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
135 188
189/**
190 * drm_gem_object_reference - acquire a GEM BO reference
191 * @obj: GEM buffer object
192 *
193 * This acquires additional reference to @obj. It is illegal to call this
194 * without already holding a reference. No locks required.
195 */
136static inline void 196static inline void
137drm_gem_object_reference(struct drm_gem_object *obj) 197drm_gem_object_reference(struct drm_gem_object *obj)
138{ 198{
139 kref_get(&obj->refcount); 199 kref_get(&obj->refcount);
140} 200}
141 201
202/**
203 * drm_gem_object_unreference - release a GEM BO reference
204 * @obj: GEM buffer object
205 *
206 * This releases a reference to @obj. Callers must hold the dev->struct_mutex
207 * lock when calling this function, even when the driver doesn't use
208 * dev->struct_mutex for anything.
209 *
210 * For drivers not encumbered with legacy locking use
211 * drm_gem_object_unreference_unlocked() instead.
212 */
142static inline void 213static inline void
143drm_gem_object_unreference(struct drm_gem_object *obj) 214drm_gem_object_unreference(struct drm_gem_object *obj)
144{ 215{
@@ -149,6 +220,13 @@ drm_gem_object_unreference(struct drm_gem_object *obj)
149 } 220 }
150} 221}
151 222
223/**
224 * drm_gem_object_unreference_unlocked - release a GEM BO reference
225 * @obj: GEM buffer object
226 *
227 * This releases a reference to @obj. Callers must not hold the
228 * dev->struct_mutex lock when calling this function.
229 */
152static inline void 230static inline void
153drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) 231drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
154{ 232{