diff options
author | Thomas Hellstrom <thellstrom@vmware.com> | 2009-12-06 15:46:24 -0500 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2009-12-07 00:22:01 -0500 |
commit | 88071539a3f5195f9e9dae38a3e35b3ce4b9f9fc (patch) | |
tree | a0be303c46b4cfa28b8357cf27ab6fae666fe470 /include/drm/ttm | |
parent | 01d01ba947670cf58f22119fc126fdf39078f6ba (diff) |
drm/ttm: Add user-space objects.
Add objects needed for user-space to maintain reference counts on ttm objects.
This is used by the vmwgfx driver which allows user-space to maintain
map-counts on dma buffers, lock-counts on the ttm lock and ref-counts on
gpu surfaces, gpu contexts and dma buffer.
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'include/drm/ttm')
-rw-r--r-- | include/drm/ttm/ttm_object.h | 267 |
1 files changed, 267 insertions, 0 deletions
diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h new file mode 100644 index 000000000000..703ca4db0a29 --- /dev/null +++ b/include/drm/ttm/ttm_object.h | |||
@@ -0,0 +1,267 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA | ||
4 | * All Rights Reserved. | ||
5 | * | ||
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: | ||
13 | * | ||
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. | ||
17 | * | ||
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. | ||
25 | * | ||
26 | **************************************************************************/ | ||
27 | /* | ||
28 | * Authors: Thomas Hellstrom <thellstrom-at-vmware-dot-com> | ||
29 | */ | ||
30 | /** @file ttm_object.h | ||
31 | * | ||
32 | * Base- and reference object implementation for the various | ||
33 | * ttm objects. Implements reference counting, minimal security checks | ||
34 | * and release on file close. | ||
35 | */ | ||
36 | |||
37 | #ifndef _TTM_OBJECT_H_ | ||
38 | #define _TTM_OBJECT_H_ | ||
39 | |||
40 | #include <linux/list.h> | ||
41 | #include "drm_hashtab.h" | ||
42 | #include <linux/kref.h> | ||
43 | #include <ttm/ttm_memory.h> | ||
44 | |||
45 | /** | ||
46 | * enum ttm_ref_type | ||
47 | * | ||
48 | * Describes what type of reference a ref object holds. | ||
49 | * | ||
50 | * TTM_REF_USAGE is a simple refcount on a base object. | ||
51 | * | ||
52 | * TTM_REF_SYNCCPU_READ is a SYNCCPU_READ reference on a | ||
53 | * buffer object. | ||
54 | * | ||
55 | * TTM_REF_SYNCCPU_WRITE is a SYNCCPU_WRITE reference on a | ||
56 | * buffer object. | ||
57 | * | ||
58 | */ | ||
59 | |||
60 | enum ttm_ref_type { | ||
61 | TTM_REF_USAGE, | ||
62 | TTM_REF_SYNCCPU_READ, | ||
63 | TTM_REF_SYNCCPU_WRITE, | ||
64 | TTM_REF_NUM | ||
65 | }; | ||
66 | |||
67 | /** | ||
68 | * enum ttm_object_type | ||
69 | * | ||
70 | * One entry per ttm object type. | ||
71 | * Device-specific types should use the | ||
72 | * ttm_driver_typex types. | ||
73 | */ | ||
74 | |||
75 | enum ttm_object_type { | ||
76 | ttm_fence_type, | ||
77 | ttm_buffer_type, | ||
78 | ttm_lock_type, | ||
79 | ttm_driver_type0 = 256, | ||
80 | ttm_driver_type1 | ||
81 | }; | ||
82 | |||
83 | struct ttm_object_file; | ||
84 | struct ttm_object_device; | ||
85 | |||
86 | /** | ||
87 | * struct ttm_base_object | ||
88 | * | ||
89 | * @hash: hash entry for the per-device object hash. | ||
90 | * @type: derived type this object is base class for. | ||
91 | * @shareable: Other ttm_object_files can access this object. | ||
92 | * | ||
93 | * @tfile: Pointer to ttm_object_file of the creator. | ||
94 | * NULL if the object was not created by a user request. | ||
95 | * (kernel object). | ||
96 | * | ||
97 | * @refcount: Number of references to this object, not | ||
98 | * including the hash entry. A reference to a base object can | ||
99 | * only be held by a ref object. | ||
100 | * | ||
101 | * @refcount_release: A function to be called when there are | ||
102 | * no more references to this object. This function should | ||
103 | * destroy the object (or make sure destruction eventually happens), | ||
104 | * and when it is called, the object has | ||
105 | * already been taken out of the per-device hash. The parameter | ||
106 | * "base" should be set to NULL by the function. | ||
107 | * | ||
108 | * @ref_obj_release: A function to be called when a reference object | ||
109 | * with another ttm_ref_type than TTM_REF_USAGE is deleted. | ||
110 | * this function may, for example, release a lock held by a user-space | ||
111 | * process. | ||
112 | * | ||
113 | * This struct is intended to be used as a base struct for objects that | ||
114 | * are visible to user-space. It provides a global name, race-safe | ||
115 | * access and refcounting, minimal access contol and hooks for unref actions. | ||
116 | */ | ||
117 | |||
118 | struct ttm_base_object { | ||
119 | struct drm_hash_item hash; | ||
120 | enum ttm_object_type object_type; | ||
121 | bool shareable; | ||
122 | struct ttm_object_file *tfile; | ||
123 | struct kref refcount; | ||
124 | void (*refcount_release) (struct ttm_base_object **base); | ||
125 | void (*ref_obj_release) (struct ttm_base_object *base, | ||
126 | enum ttm_ref_type ref_type); | ||
127 | }; | ||
128 | |||
129 | /** | ||
130 | * ttm_base_object_init | ||
131 | * | ||
132 | * @tfile: Pointer to a struct ttm_object_file. | ||
133 | * @base: The struct ttm_base_object to initialize. | ||
134 | * @shareable: This object is shareable with other applcations. | ||
135 | * (different @tfile pointers.) | ||
136 | * @type: The object type. | ||
137 | * @refcount_release: See the struct ttm_base_object description. | ||
138 | * @ref_obj_release: See the struct ttm_base_object description. | ||
139 | * | ||
140 | * Initializes a struct ttm_base_object. | ||
141 | */ | ||
142 | |||
143 | extern int ttm_base_object_init(struct ttm_object_file *tfile, | ||
144 | struct ttm_base_object *base, | ||
145 | bool shareable, | ||
146 | enum ttm_object_type type, | ||
147 | void (*refcount_release) (struct ttm_base_object | ||
148 | **), | ||
149 | void (*ref_obj_release) (struct ttm_base_object | ||
150 | *, | ||
151 | enum ttm_ref_type | ||
152 | ref_type)); | ||
153 | |||
154 | /** | ||
155 | * ttm_base_object_lookup | ||
156 | * | ||
157 | * @tfile: Pointer to a struct ttm_object_file. | ||
158 | * @key: Hash key | ||
159 | * | ||
160 | * Looks up a struct ttm_base_object with the key @key. | ||
161 | * Also verifies that the object is visible to the application, by | ||
162 | * comparing the @tfile argument and checking the object shareable flag. | ||
163 | */ | ||
164 | |||
165 | extern struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file | ||
166 | *tfile, uint32_t key); | ||
167 | |||
168 | /** | ||
169 | * ttm_base_object_unref | ||
170 | * | ||
171 | * @p_base: Pointer to a pointer referncing a struct ttm_base_object. | ||
172 | * | ||
173 | * Decrements the base object refcount and clears the pointer pointed to by | ||
174 | * p_base. | ||
175 | */ | ||
176 | |||
177 | extern void ttm_base_object_unref(struct ttm_base_object **p_base); | ||
178 | |||
179 | /** | ||
180 | * ttm_ref_object_add. | ||
181 | * | ||
182 | * @tfile: A struct ttm_object_file representing the application owning the | ||
183 | * ref_object. | ||
184 | * @base: The base object to reference. | ||
185 | * @ref_type: The type of reference. | ||
186 | * @existed: Upon completion, indicates that an identical reference object | ||
187 | * already existed, and the refcount was upped on that object instead. | ||
188 | * | ||
189 | * Adding a ref object to a base object is basically like referencing the | ||
190 | * base object, but a user-space application holds the reference. When the | ||
191 | * file corresponding to @tfile is closed, all its reference objects are | ||
192 | * deleted. A reference object can have different types depending on what | ||
193 | * it's intended for. It can be refcounting to prevent object destruction, | ||
194 | * When user-space takes a lock, it can add a ref object to that lock to | ||
195 | * make sure the lock is released if the application dies. A ref object | ||
196 | * will hold a single reference on a base object. | ||
197 | */ | ||
198 | extern int ttm_ref_object_add(struct ttm_object_file *tfile, | ||
199 | struct ttm_base_object *base, | ||
200 | enum ttm_ref_type ref_type, bool *existed); | ||
201 | /** | ||
202 | * ttm_ref_object_base_unref | ||
203 | * | ||
204 | * @key: Key representing the base object. | ||
205 | * @ref_type: Ref type of the ref object to be dereferenced. | ||
206 | * | ||
207 | * Unreference a ref object with type @ref_type | ||
208 | * on the base object identified by @key. If there are no duplicate | ||
209 | * references, the ref object will be destroyed and the base object | ||
210 | * will be unreferenced. | ||
211 | */ | ||
212 | extern int ttm_ref_object_base_unref(struct ttm_object_file *tfile, | ||
213 | unsigned long key, | ||
214 | enum ttm_ref_type ref_type); | ||
215 | |||
216 | /** | ||
217 | * ttm_object_file_init - initialize a struct ttm_object file | ||
218 | * | ||
219 | * @tdev: A struct ttm_object device this file is initialized on. | ||
220 | * @hash_order: Order of the hash table used to hold the reference objects. | ||
221 | * | ||
222 | * This is typically called by the file_ops::open function. | ||
223 | */ | ||
224 | |||
225 | extern struct ttm_object_file *ttm_object_file_init(struct ttm_object_device | ||
226 | *tdev, | ||
227 | unsigned int hash_order); | ||
228 | |||
229 | /** | ||
230 | * ttm_object_file_release - release data held by a ttm_object_file | ||
231 | * | ||
232 | * @p_tfile: Pointer to pointer to the ttm_object_file object to release. | ||
233 | * *p_tfile will be set to NULL by this function. | ||
234 | * | ||
235 | * Releases all data associated by a ttm_object_file. | ||
236 | * Typically called from file_ops::release. The caller must | ||
237 | * ensure that there are no concurrent users of tfile. | ||
238 | */ | ||
239 | |||
240 | extern void ttm_object_file_release(struct ttm_object_file **p_tfile); | ||
241 | |||
242 | /** | ||
243 | * ttm_object device init - initialize a struct ttm_object_device | ||
244 | * | ||
245 | * @hash_order: Order of hash table used to hash the base objects. | ||
246 | * | ||
247 | * This function is typically called on device initialization to prepare | ||
248 | * data structures needed for ttm base and ref objects. | ||
249 | */ | ||
250 | |||
251 | extern struct ttm_object_device *ttm_object_device_init | ||
252 | (struct ttm_mem_global *mem_glob, unsigned int hash_order); | ||
253 | |||
254 | /** | ||
255 | * ttm_object_device_release - release data held by a ttm_object_device | ||
256 | * | ||
257 | * @p_tdev: Pointer to pointer to the ttm_object_device object to release. | ||
258 | * *p_tdev will be set to NULL by this function. | ||
259 | * | ||
260 | * Releases all data associated by a ttm_object_device. | ||
261 | * Typically called from driver::unload before the destruction of the | ||
262 | * device private data structure. | ||
263 | */ | ||
264 | |||
265 | extern void ttm_object_device_release(struct ttm_object_device **p_tdev); | ||
266 | |||
267 | #endif | ||