diff options
Diffstat (limited to 'include/drm/ttm/ttm_object.h')
-rw-r--r-- | include/drm/ttm/ttm_object.h | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h index fc0cf0649901..58b029894eb3 100644 --- a/include/drm/ttm/ttm_object.h +++ b/include/drm/ttm/ttm_object.h | |||
@@ -41,6 +41,7 @@ | |||
41 | #include <drm/drm_hashtab.h> | 41 | #include <drm/drm_hashtab.h> |
42 | #include <linux/kref.h> | 42 | #include <linux/kref.h> |
43 | #include <linux/rcupdate.h> | 43 | #include <linux/rcupdate.h> |
44 | #include <linux/dma-buf.h> | ||
44 | #include <ttm/ttm_memory.h> | 45 | #include <ttm/ttm_memory.h> |
45 | 46 | ||
46 | /** | 47 | /** |
@@ -77,6 +78,7 @@ enum ttm_object_type { | |||
77 | ttm_fence_type, | 78 | ttm_fence_type, |
78 | ttm_buffer_type, | 79 | ttm_buffer_type, |
79 | ttm_lock_type, | 80 | ttm_lock_type, |
81 | ttm_prime_type, | ||
80 | ttm_driver_type0 = 256, | 82 | ttm_driver_type0 = 256, |
81 | ttm_driver_type1, | 83 | ttm_driver_type1, |
82 | ttm_driver_type2, | 84 | ttm_driver_type2, |
@@ -132,6 +134,30 @@ struct ttm_base_object { | |||
132 | enum ttm_ref_type ref_type); | 134 | enum ttm_ref_type ref_type); |
133 | }; | 135 | }; |
134 | 136 | ||
137 | |||
138 | /** | ||
139 | * struct ttm_prime_object - Modified base object that is prime-aware | ||
140 | * | ||
141 | * @base: struct ttm_base_object that we derive from | ||
142 | * @mutex: Mutex protecting the @dma_buf member. | ||
143 | * @size: Size of the dma_buf associated with this object | ||
144 | * @real_type: Type of the underlying object. Needed since we're setting | ||
145 | * the value of @base::object_type to ttm_prime_type | ||
146 | * @dma_buf: Non ref-coutned pointer to a struct dma_buf created from this | ||
147 | * object. | ||
148 | * @refcount_release: The underlying object's release method. Needed since | ||
149 | * we set @base::refcount_release to our own release method. | ||
150 | */ | ||
151 | |||
152 | struct ttm_prime_object { | ||
153 | struct ttm_base_object base; | ||
154 | struct mutex mutex; | ||
155 | size_t size; | ||
156 | enum ttm_object_type real_type; | ||
157 | struct dma_buf *dma_buf; | ||
158 | void (*refcount_release) (struct ttm_base_object **); | ||
159 | }; | ||
160 | |||
135 | /** | 161 | /** |
136 | * ttm_base_object_init | 162 | * ttm_base_object_init |
137 | * | 163 | * |
@@ -248,14 +274,18 @@ extern void ttm_object_file_release(struct ttm_object_file **p_tfile); | |||
248 | /** | 274 | /** |
249 | * ttm_object device init - initialize a struct ttm_object_device | 275 | * ttm_object device init - initialize a struct ttm_object_device |
250 | * | 276 | * |
277 | * @mem_glob: struct ttm_mem_global for memory accounting. | ||
251 | * @hash_order: Order of hash table used to hash the base objects. | 278 | * @hash_order: Order of hash table used to hash the base objects. |
279 | * @ops: DMA buf ops for prime objects of this device. | ||
252 | * | 280 | * |
253 | * This function is typically called on device initialization to prepare | 281 | * This function is typically called on device initialization to prepare |
254 | * data structures needed for ttm base and ref objects. | 282 | * data structures needed for ttm base and ref objects. |
255 | */ | 283 | */ |
256 | 284 | ||
257 | extern struct ttm_object_device *ttm_object_device_init | 285 | extern struct ttm_object_device * |
258 | (struct ttm_mem_global *mem_glob, unsigned int hash_order); | 286 | ttm_object_device_init(struct ttm_mem_global *mem_glob, |
287 | unsigned int hash_order, | ||
288 | const struct dma_buf_ops *ops); | ||
259 | 289 | ||
260 | /** | 290 | /** |
261 | * ttm_object_device_release - release data held by a ttm_object_device | 291 | * ttm_object_device_release - release data held by a ttm_object_device |
@@ -272,4 +302,31 @@ extern void ttm_object_device_release(struct ttm_object_device **p_tdev); | |||
272 | 302 | ||
273 | #define ttm_base_object_kfree(__object, __base)\ | 303 | #define ttm_base_object_kfree(__object, __base)\ |
274 | kfree_rcu(__object, __base.rhead) | 304 | kfree_rcu(__object, __base.rhead) |
305 | |||
306 | extern int ttm_prime_object_init(struct ttm_object_file *tfile, | ||
307 | size_t size, | ||
308 | struct ttm_prime_object *prime, | ||
309 | bool shareable, | ||
310 | enum ttm_object_type type, | ||
311 | void (*refcount_release) | ||
312 | (struct ttm_base_object **), | ||
313 | void (*ref_obj_release) | ||
314 | (struct ttm_base_object *, | ||
315 | enum ttm_ref_type ref_type)); | ||
316 | |||
317 | static inline enum ttm_object_type | ||
318 | ttm_base_object_type(struct ttm_base_object *base) | ||
319 | { | ||
320 | return (base->object_type == ttm_prime_type) ? | ||
321 | container_of(base, struct ttm_prime_object, base)->real_type : | ||
322 | base->object_type; | ||
323 | } | ||
324 | extern int ttm_prime_fd_to_handle(struct ttm_object_file *tfile, | ||
325 | int fd, u32 *handle); | ||
326 | extern int ttm_prime_handle_to_fd(struct ttm_object_file *tfile, | ||
327 | uint32_t handle, uint32_t flags, | ||
328 | int *prime_fd); | ||
329 | |||
330 | #define ttm_prime_object_kfree(__obj, __prime) \ | ||
331 | kfree_rcu(__obj, __prime.base.rhead) | ||
275 | #endif | 332 | #endif |