diff options
Diffstat (limited to 'include/drm/ttm')
-rw-r--r-- | include/drm/ttm/ttm_bo_api.h | 115 | ||||
-rw-r--r-- | include/drm/ttm/ttm_bo_driver.h | 42 | ||||
-rw-r--r-- | include/drm/ttm/ttm_execbuf_util.h | 107 | ||||
-rw-r--r-- | include/drm/ttm/ttm_lock.h | 247 | ||||
-rw-r--r-- | include/drm/ttm/ttm_memory.h | 1 | ||||
-rw-r--r-- | include/drm/ttm/ttm_object.h | 271 |
6 files changed, 714 insertions, 69 deletions
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h index 491146170522..81eb9f45883c 100644 --- a/include/drm/ttm/ttm_bo_api.h +++ b/include/drm/ttm/ttm_bo_api.h | |||
@@ -44,6 +44,29 @@ struct ttm_bo_device; | |||
44 | 44 | ||
45 | struct drm_mm_node; | 45 | struct drm_mm_node; |
46 | 46 | ||
47 | |||
48 | /** | ||
49 | * struct ttm_placement | ||
50 | * | ||
51 | * @fpfn: first valid page frame number to put the object | ||
52 | * @lpfn: last valid page frame number to put the object | ||
53 | * @num_placement: number of prefered placements | ||
54 | * @placement: prefered placements | ||
55 | * @num_busy_placement: number of prefered placements when need to evict buffer | ||
56 | * @busy_placement: prefered placements when need to evict buffer | ||
57 | * | ||
58 | * Structure indicating the placement you request for an object. | ||
59 | */ | ||
60 | struct ttm_placement { | ||
61 | unsigned fpfn; | ||
62 | unsigned lpfn; | ||
63 | unsigned num_placement; | ||
64 | const uint32_t *placement; | ||
65 | unsigned num_busy_placement; | ||
66 | const uint32_t *busy_placement; | ||
67 | }; | ||
68 | |||
69 | |||
47 | /** | 70 | /** |
48 | * struct ttm_mem_reg | 71 | * struct ttm_mem_reg |
49 | * | 72 | * |
@@ -109,10 +132,6 @@ struct ttm_tt; | |||
109 | * the object is destroyed. | 132 | * the object is destroyed. |
110 | * @event_queue: Queue for processes waiting on buffer object status change. | 133 | * @event_queue: Queue for processes waiting on buffer object status change. |
111 | * @lock: spinlock protecting mostly synchronization members. | 134 | * @lock: spinlock protecting mostly synchronization members. |
112 | * @proposed_placement: Proposed placement for the buffer. Changed only by the | ||
113 | * creator prior to validation as opposed to bo->mem.proposed_flags which is | ||
114 | * changed by the implementation prior to a buffer move if it wants to outsmart | ||
115 | * the buffer creator / user. This latter happens, for example, at eviction. | ||
116 | * @mem: structure describing current placement. | 135 | * @mem: structure describing current placement. |
117 | * @persistant_swap_storage: Usually the swap storage is deleted for buffers | 136 | * @persistant_swap_storage: Usually the swap storage is deleted for buffers |
118 | * pinned in physical memory. If this behaviour is not desired, this member | 137 | * pinned in physical memory. If this behaviour is not desired, this member |
@@ -177,7 +196,6 @@ struct ttm_buffer_object { | |||
177 | * Members protected by the bo::reserved lock. | 196 | * Members protected by the bo::reserved lock. |
178 | */ | 197 | */ |
179 | 198 | ||
180 | uint32_t proposed_placement; | ||
181 | struct ttm_mem_reg mem; | 199 | struct ttm_mem_reg mem; |
182 | struct file *persistant_swap_storage; | 200 | struct file *persistant_swap_storage; |
183 | struct ttm_tt *ttm; | 201 | struct ttm_tt *ttm; |
@@ -285,29 +303,30 @@ ttm_bo_reference(struct ttm_buffer_object *bo) | |||
285 | * Note: It might be necessary to block validations before the | 303 | * Note: It might be necessary to block validations before the |
286 | * wait by reserving the buffer. | 304 | * wait by reserving the buffer. |
287 | * Returns -EBUSY if no_wait is true and the buffer is busy. | 305 | * Returns -EBUSY if no_wait is true and the buffer is busy. |
288 | * Returns -ERESTART if interrupted by a signal. | 306 | * Returns -ERESTARTSYS if interrupted by a signal. |
289 | */ | 307 | */ |
290 | extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy, | 308 | extern int ttm_bo_wait(struct ttm_buffer_object *bo, bool lazy, |
291 | bool interruptible, bool no_wait); | 309 | bool interruptible, bool no_wait); |
292 | /** | 310 | /** |
293 | * ttm_buffer_object_validate | 311 | * ttm_bo_validate |
294 | * | 312 | * |
295 | * @bo: The buffer object. | 313 | * @bo: The buffer object. |
296 | * @proposed_placement: Proposed_placement for the buffer object. | 314 | * @placement: Proposed placement for the buffer object. |
297 | * @interruptible: Sleep interruptible if sleeping. | 315 | * @interruptible: Sleep interruptible if sleeping. |
298 | * @no_wait: Return immediately if the buffer is busy. | 316 | * @no_wait: Return immediately if the buffer is busy. |
299 | * | 317 | * |
300 | * Changes placement and caching policy of the buffer object | 318 | * Changes placement and caching policy of the buffer object |
301 | * according to bo::proposed_flags. | 319 | * according proposed placement. |
302 | * Returns | 320 | * Returns |
303 | * -EINVAL on invalid proposed_flags. | 321 | * -EINVAL on invalid proposed placement. |
304 | * -ENOMEM on out-of-memory condition. | 322 | * -ENOMEM on out-of-memory condition. |
305 | * -EBUSY if no_wait is true and buffer busy. | 323 | * -EBUSY if no_wait is true and buffer busy. |
306 | * -ERESTART if interrupted by a signal. | 324 | * -ERESTARTSYS if interrupted by a signal. |
307 | */ | 325 | */ |
308 | extern int ttm_buffer_object_validate(struct ttm_buffer_object *bo, | 326 | extern int ttm_bo_validate(struct ttm_buffer_object *bo, |
309 | uint32_t proposed_placement, | 327 | struct ttm_placement *placement, |
310 | bool interruptible, bool no_wait); | 328 | bool interruptible, bool no_wait); |
329 | |||
311 | /** | 330 | /** |
312 | * ttm_bo_unref | 331 | * ttm_bo_unref |
313 | * | 332 | * |
@@ -328,7 +347,7 @@ extern void ttm_bo_unref(struct ttm_buffer_object **bo); | |||
328 | * waiting for buffer idle. This lock is recursive. | 347 | * waiting for buffer idle. This lock is recursive. |
329 | * Returns | 348 | * Returns |
330 | * -EBUSY if the buffer is busy and no_wait is true. | 349 | * -EBUSY if the buffer is busy and no_wait is true. |
331 | * -ERESTART if interrupted by a signal. | 350 | * -ERESTARTSYS if interrupted by a signal. |
332 | */ | 351 | */ |
333 | 352 | ||
334 | extern int | 353 | extern int |
@@ -343,7 +362,7 @@ ttm_bo_synccpu_write_grab(struct ttm_buffer_object *bo, bool no_wait); | |||
343 | extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo); | 362 | extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo); |
344 | 363 | ||
345 | /** | 364 | /** |
346 | * ttm_buffer_object_init | 365 | * ttm_bo_init |
347 | * | 366 | * |
348 | * @bdev: Pointer to a ttm_bo_device struct. | 367 | * @bdev: Pointer to a ttm_bo_device struct. |
349 | * @bo: Pointer to a ttm_buffer_object to be initialized. | 368 | * @bo: Pointer to a ttm_buffer_object to be initialized. |
@@ -371,20 +390,20 @@ extern void ttm_bo_synccpu_write_release(struct ttm_buffer_object *bo); | |||
371 | * Returns | 390 | * Returns |
372 | * -ENOMEM: Out of memory. | 391 | * -ENOMEM: Out of memory. |
373 | * -EINVAL: Invalid placement flags. | 392 | * -EINVAL: Invalid placement flags. |
374 | * -ERESTART: Interrupted by signal while sleeping waiting for resources. | 393 | * -ERESTARTSYS: Interrupted by signal while sleeping waiting for resources. |
375 | */ | 394 | */ |
376 | 395 | ||
377 | extern int ttm_buffer_object_init(struct ttm_bo_device *bdev, | 396 | extern int ttm_bo_init(struct ttm_bo_device *bdev, |
378 | struct ttm_buffer_object *bo, | 397 | struct ttm_buffer_object *bo, |
379 | unsigned long size, | 398 | unsigned long size, |
380 | enum ttm_bo_type type, | 399 | enum ttm_bo_type type, |
381 | uint32_t flags, | 400 | struct ttm_placement *placement, |
382 | uint32_t page_alignment, | 401 | uint32_t page_alignment, |
383 | unsigned long buffer_start, | 402 | unsigned long buffer_start, |
384 | bool interrubtible, | 403 | bool interrubtible, |
385 | struct file *persistant_swap_storage, | 404 | struct file *persistant_swap_storage, |
386 | size_t acc_size, | 405 | size_t acc_size, |
387 | void (*destroy) (struct ttm_buffer_object *)); | 406 | void (*destroy) (struct ttm_buffer_object *)); |
388 | /** | 407 | /** |
389 | * ttm_bo_synccpu_object_init | 408 | * ttm_bo_synccpu_object_init |
390 | * | 409 | * |
@@ -405,47 +424,43 @@ extern int ttm_buffer_object_init(struct ttm_bo_device *bdev, | |||
405 | * GEM user interface. | 424 | * GEM user interface. |
406 | * @p_bo: On successful completion *p_bo points to the created object. | 425 | * @p_bo: On successful completion *p_bo points to the created object. |
407 | * | 426 | * |
408 | * This function allocates a ttm_buffer_object, and then calls | 427 | * This function allocates a ttm_buffer_object, and then calls ttm_bo_init |
409 | * ttm_buffer_object_init on that object. | 428 | * on that object. The destroy function is set to kfree(). |
410 | * The destroy function is set to kfree(). | ||
411 | * Returns | 429 | * Returns |
412 | * -ENOMEM: Out of memory. | 430 | * -ENOMEM: Out of memory. |
413 | * -EINVAL: Invalid placement flags. | 431 | * -EINVAL: Invalid placement flags. |
414 | * -ERESTART: Interrupted by signal while waiting for resources. | 432 | * -ERESTARTSYS: Interrupted by signal while waiting for resources. |
415 | */ | 433 | */ |
416 | 434 | ||
417 | extern int ttm_buffer_object_create(struct ttm_bo_device *bdev, | 435 | extern int ttm_bo_create(struct ttm_bo_device *bdev, |
418 | unsigned long size, | 436 | unsigned long size, |
419 | enum ttm_bo_type type, | 437 | enum ttm_bo_type type, |
420 | uint32_t flags, | 438 | struct ttm_placement *placement, |
421 | uint32_t page_alignment, | 439 | uint32_t page_alignment, |
422 | unsigned long buffer_start, | 440 | unsigned long buffer_start, |
423 | bool interruptible, | 441 | bool interruptible, |
424 | struct file *persistant_swap_storage, | 442 | struct file *persistant_swap_storage, |
425 | struct ttm_buffer_object **p_bo); | 443 | struct ttm_buffer_object **p_bo); |
426 | 444 | ||
427 | /** | 445 | /** |
428 | * ttm_bo_check_placement | 446 | * ttm_bo_check_placement |
429 | * | 447 | * |
430 | * @bo: the buffer object. | 448 | * @bo: the buffer object. |
431 | * @set_flags: placement flags to set. | 449 | * @placement: placements |
432 | * @clr_flags: placement flags to clear. | ||
433 | * | 450 | * |
434 | * Performs minimal validity checking on an intended change of | 451 | * Performs minimal validity checking on an intended change of |
435 | * placement flags. | 452 | * placement flags. |
436 | * Returns | 453 | * Returns |
437 | * -EINVAL: Intended change is invalid or not allowed. | 454 | * -EINVAL: Intended change is invalid or not allowed. |
438 | */ | 455 | */ |
439 | |||
440 | extern int ttm_bo_check_placement(struct ttm_buffer_object *bo, | 456 | extern int ttm_bo_check_placement(struct ttm_buffer_object *bo, |
441 | uint32_t set_flags, uint32_t clr_flags); | 457 | struct ttm_placement *placement); |
442 | 458 | ||
443 | /** | 459 | /** |
444 | * ttm_bo_init_mm | 460 | * ttm_bo_init_mm |
445 | * | 461 | * |
446 | * @bdev: Pointer to a ttm_bo_device struct. | 462 | * @bdev: Pointer to a ttm_bo_device struct. |
447 | * @mem_type: The memory type. | 463 | * @mem_type: The memory type. |
448 | * @p_offset: offset for managed area in pages. | ||
449 | * @p_size: size managed area in pages. | 464 | * @p_size: size managed area in pages. |
450 | * | 465 | * |
451 | * Initialize a manager for a given memory type. | 466 | * Initialize a manager for a given memory type. |
@@ -458,7 +473,7 @@ extern int ttm_bo_check_placement(struct ttm_buffer_object *bo, | |||
458 | */ | 473 | */ |
459 | 474 | ||
460 | extern int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, | 475 | extern int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type, |
461 | unsigned long p_offset, unsigned long p_size); | 476 | unsigned long p_size); |
462 | /** | 477 | /** |
463 | * ttm_bo_clean_mm | 478 | * ttm_bo_clean_mm |
464 | * | 479 | * |
@@ -503,7 +518,7 @@ extern int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type); | |||
503 | * | 518 | * |
504 | * Returns: | 519 | * Returns: |
505 | * -EINVAL: Invalid or uninitialized memory type. | 520 | * -EINVAL: Invalid or uninitialized memory type. |
506 | * -ERESTART: The call was interrupted by a signal while waiting to | 521 | * -ERESTARTSYS: The call was interrupted by a signal while waiting to |
507 | * evict a buffer. | 522 | * evict a buffer. |
508 | */ | 523 | */ |
509 | 524 | ||
@@ -606,7 +621,7 @@ extern int ttm_bo_mmap(struct file *filp, struct vm_area_struct *vma, | |||
606 | * be called from the fops::read and fops::write method. | 621 | * be called from the fops::read and fops::write method. |
607 | * Returns: | 622 | * Returns: |
608 | * See man (2) write, man(2) read. In particular, | 623 | * See man (2) write, man(2) read. In particular, |
609 | * the function may return -EINTR if | 624 | * the function may return -ERESTARTSYS if |
610 | * interrupted by a signal. | 625 | * interrupted by a signal. |
611 | */ | 626 | */ |
612 | 627 | ||
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h index e8cd6d20aed2..4c4e0f8375b3 100644 --- a/include/drm/ttm/ttm_bo_driver.h +++ b/include/drm/ttm/ttm_bo_driver.h | |||
@@ -242,12 +242,6 @@ struct ttm_mem_type_manager { | |||
242 | /** | 242 | /** |
243 | * struct ttm_bo_driver | 243 | * struct ttm_bo_driver |
244 | * | 244 | * |
245 | * @mem_type_prio: Priority array of memory types to place a buffer object in | ||
246 | * if it fits without evicting buffers from any of these memory types. | ||
247 | * @mem_busy_prio: Priority array of memory types to place a buffer object in | ||
248 | * if it needs to evict buffers to make room. | ||
249 | * @num_mem_type_prio: Number of elements in the @mem_type_prio array. | ||
250 | * @num_mem_busy_prio: Number of elements in the @num_mem_busy_prio array. | ||
251 | * @create_ttm_backend_entry: Callback to create a struct ttm_backend. | 245 | * @create_ttm_backend_entry: Callback to create a struct ttm_backend. |
252 | * @invalidate_caches: Callback to invalidate read caches when a buffer object | 246 | * @invalidate_caches: Callback to invalidate read caches when a buffer object |
253 | * has been evicted. | 247 | * has been evicted. |
@@ -265,11 +259,6 @@ struct ttm_mem_type_manager { | |||
265 | */ | 259 | */ |
266 | 260 | ||
267 | struct ttm_bo_driver { | 261 | struct ttm_bo_driver { |
268 | const uint32_t *mem_type_prio; | ||
269 | const uint32_t *mem_busy_prio; | ||
270 | uint32_t num_mem_type_prio; | ||
271 | uint32_t num_mem_busy_prio; | ||
272 | |||
273 | /** | 262 | /** |
274 | * struct ttm_bo_driver member create_ttm_backend_entry | 263 | * struct ttm_bo_driver member create_ttm_backend_entry |
275 | * | 264 | * |
@@ -306,7 +295,8 @@ struct ttm_bo_driver { | |||
306 | * finished, they'll end up in bo->mem.flags | 295 | * finished, they'll end up in bo->mem.flags |
307 | */ | 296 | */ |
308 | 297 | ||
309 | uint32_t(*evict_flags) (struct ttm_buffer_object *bo); | 298 | void(*evict_flags) (struct ttm_buffer_object *bo, |
299 | struct ttm_placement *placement); | ||
310 | /** | 300 | /** |
311 | * struct ttm_bo_driver member move: | 301 | * struct ttm_bo_driver member move: |
312 | * | 302 | * |
@@ -363,6 +353,11 @@ struct ttm_bo_driver { | |||
363 | /* notify the driver we are taking a fault on this BO | 353 | /* notify the driver we are taking a fault on this BO |
364 | * and have reserved it */ | 354 | * and have reserved it */ |
365 | void (*fault_reserve_notify)(struct ttm_buffer_object *bo); | 355 | void (*fault_reserve_notify)(struct ttm_buffer_object *bo); |
356 | |||
357 | /** | ||
358 | * notify the driver that we're about to swap out this bo | ||
359 | */ | ||
360 | void (*swap_notify) (struct ttm_buffer_object *bo); | ||
366 | }; | 361 | }; |
367 | 362 | ||
368 | /** | 363 | /** |
@@ -545,6 +540,15 @@ extern int ttm_tt_set_user(struct ttm_tt *ttm, | |||
545 | extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem); | 540 | extern int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_mem_reg *bo_mem); |
546 | 541 | ||
547 | /** | 542 | /** |
543 | * ttm_tt_populate: | ||
544 | * | ||
545 | * @ttm: The struct ttm_tt to contain the backing pages. | ||
546 | * | ||
547 | * Add backing pages to all of @ttm | ||
548 | */ | ||
549 | extern int ttm_tt_populate(struct ttm_tt *ttm); | ||
550 | |||
551 | /** | ||
548 | * ttm_ttm_destroy: | 552 | * ttm_ttm_destroy: |
549 | * | 553 | * |
550 | * @ttm: The struct ttm_tt. | 554 | * @ttm: The struct ttm_tt. |
@@ -639,12 +643,12 @@ extern bool ttm_mem_reg_is_pci(struct ttm_bo_device *bdev, | |||
639 | * -EBUSY: No space available (only if no_wait == 1). | 643 | * -EBUSY: No space available (only if no_wait == 1). |
640 | * -ENOMEM: Could not allocate memory for the buffer object, either due to | 644 | * -ENOMEM: Could not allocate memory for the buffer object, either due to |
641 | * fragmentation or concurrent allocators. | 645 | * fragmentation or concurrent allocators. |
642 | * -ERESTART: An interruptible sleep was interrupted by a signal. | 646 | * -ERESTARTSYS: An interruptible sleep was interrupted by a signal. |
643 | */ | 647 | */ |
644 | extern int ttm_bo_mem_space(struct ttm_buffer_object *bo, | 648 | extern int ttm_bo_mem_space(struct ttm_buffer_object *bo, |
645 | uint32_t proposed_placement, | 649 | struct ttm_placement *placement, |
646 | struct ttm_mem_reg *mem, | 650 | struct ttm_mem_reg *mem, |
647 | bool interruptible, bool no_wait); | 651 | bool interruptible, bool no_wait); |
648 | /** | 652 | /** |
649 | * ttm_bo_wait_for_cpu | 653 | * ttm_bo_wait_for_cpu |
650 | * | 654 | * |
@@ -654,7 +658,7 @@ extern int ttm_bo_mem_space(struct ttm_buffer_object *bo, | |||
654 | * Wait until a buffer object is no longer sync'ed for CPU access. | 658 | * Wait until a buffer object is no longer sync'ed for CPU access. |
655 | * Returns: | 659 | * Returns: |
656 | * -EBUSY: Buffer object was sync'ed for CPU access. (only if no_wait == 1). | 660 | * -EBUSY: Buffer object was sync'ed for CPU access. (only if no_wait == 1). |
657 | * -ERESTART: An interruptible sleep was interrupted by a signal. | 661 | * -ERESTARTSYS: An interruptible sleep was interrupted by a signal. |
658 | */ | 662 | */ |
659 | 663 | ||
660 | extern int ttm_bo_wait_cpu(struct ttm_buffer_object *bo, bool no_wait); | 664 | extern int ttm_bo_wait_cpu(struct ttm_buffer_object *bo, bool no_wait); |
@@ -758,7 +762,7 @@ extern void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo); | |||
758 | * -EAGAIN: The reservation may cause a deadlock. | 762 | * -EAGAIN: The reservation may cause a deadlock. |
759 | * Release all buffer reservations, wait for @bo to become unreserved and | 763 | * Release all buffer reservations, wait for @bo to become unreserved and |
760 | * try again. (only if use_sequence == 1). | 764 | * try again. (only if use_sequence == 1). |
761 | * -ERESTART: A wait for the buffer to become unreserved was interrupted by | 765 | * -ERESTARTSYS: A wait for the buffer to become unreserved was interrupted by |
762 | * a signal. Release all buffer reservations and return to user-space. | 766 | * a signal. Release all buffer reservations and return to user-space. |
763 | */ | 767 | */ |
764 | extern int ttm_bo_reserve(struct ttm_buffer_object *bo, | 768 | extern int ttm_bo_reserve(struct ttm_buffer_object *bo, |
@@ -799,7 +803,7 @@ extern int ttm_bo_wait_unreserved(struct ttm_buffer_object *bo, | |||
799 | * | 803 | * |
800 | * Returns: | 804 | * Returns: |
801 | * -EBUSY: If no_wait == 1 and the buffer is already reserved. | 805 | * -EBUSY: If no_wait == 1 and the buffer is already reserved. |
802 | * -ERESTART: If interruptible == 1 and the process received a signal | 806 | * -ERESTARTSYS: If interruptible == 1 and the process received a signal |
803 | * while sleeping. | 807 | * while sleeping. |
804 | */ | 808 | */ |
805 | extern int ttm_bo_block_reservation(struct ttm_buffer_object *bo, | 809 | extern int ttm_bo_block_reservation(struct ttm_buffer_object *bo, |
diff --git a/include/drm/ttm/ttm_execbuf_util.h b/include/drm/ttm/ttm_execbuf_util.h new file mode 100644 index 000000000000..cd2c475da9ea --- /dev/null +++ b/include/drm/ttm/ttm_execbuf_util.h | |||
@@ -0,0 +1,107 @@ | |||
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 | |||
31 | #ifndef _TTM_EXECBUF_UTIL_H_ | ||
32 | #define _TTM_EXECBUF_UTIL_H_ | ||
33 | |||
34 | #include "ttm/ttm_bo_api.h" | ||
35 | #include <linux/list.h> | ||
36 | |||
37 | /** | ||
38 | * struct ttm_validate_buffer | ||
39 | * | ||
40 | * @head: list head for thread-private list. | ||
41 | * @bo: refcounted buffer object pointer. | ||
42 | * @new_sync_obj_arg: New sync_obj_arg for @bo, to be used once | ||
43 | * adding a new sync object. | ||
44 | * @reservied: Indicates whether @bo has been reserved for validation. | ||
45 | */ | ||
46 | |||
47 | struct ttm_validate_buffer { | ||
48 | struct list_head head; | ||
49 | struct ttm_buffer_object *bo; | ||
50 | void *new_sync_obj_arg; | ||
51 | bool reserved; | ||
52 | }; | ||
53 | |||
54 | /** | ||
55 | * function ttm_eu_backoff_reservation | ||
56 | * | ||
57 | * @list: thread private list of ttm_validate_buffer structs. | ||
58 | * | ||
59 | * Undoes all buffer validation reservations for bos pointed to by | ||
60 | * the list entries. | ||
61 | */ | ||
62 | |||
63 | extern void ttm_eu_backoff_reservation(struct list_head *list); | ||
64 | |||
65 | /** | ||
66 | * function ttm_eu_reserve_buffers | ||
67 | * | ||
68 | * @list: thread private list of ttm_validate_buffer structs. | ||
69 | * @val_seq: A unique sequence number. | ||
70 | * | ||
71 | * Tries to reserve bos pointed to by the list entries for validation. | ||
72 | * If the function returns 0, all buffers are marked as "unfenced", | ||
73 | * taken off the lru lists and are not synced for write CPU usage. | ||
74 | * | ||
75 | * If the function detects a deadlock due to multiple threads trying to | ||
76 | * reserve the same buffers in reverse order, all threads except one will | ||
77 | * back off and retry. This function may sleep while waiting for | ||
78 | * CPU write reservations to be cleared, and for other threads to | ||
79 | * unreserve their buffers. | ||
80 | * | ||
81 | * This function may return -ERESTART or -EAGAIN if the calling process | ||
82 | * receives a signal while waiting. In that case, no buffers on the list | ||
83 | * will be reserved upon return. | ||
84 | * | ||
85 | * Buffers reserved by this function should be unreserved by | ||
86 | * a call to either ttm_eu_backoff_reservation() or | ||
87 | * ttm_eu_fence_buffer_objects() when command submission is complete or | ||
88 | * has failed. | ||
89 | */ | ||
90 | |||
91 | extern int ttm_eu_reserve_buffers(struct list_head *list, uint32_t val_seq); | ||
92 | |||
93 | /** | ||
94 | * function ttm_eu_fence_buffer_objects. | ||
95 | * | ||
96 | * @list: thread private list of ttm_validate_buffer structs. | ||
97 | * @sync_obj: The new sync object for the buffers. | ||
98 | * | ||
99 | * This function should be called when command submission is complete, and | ||
100 | * it will add a new sync object to bos pointed to by entries on @list. | ||
101 | * It also unreserves all buffers, putting them on lru lists. | ||
102 | * | ||
103 | */ | ||
104 | |||
105 | extern void ttm_eu_fence_buffer_objects(struct list_head *list, void *sync_obj); | ||
106 | |||
107 | #endif | ||
diff --git a/include/drm/ttm/ttm_lock.h b/include/drm/ttm/ttm_lock.h new file mode 100644 index 000000000000..81ba0b0b891a --- /dev/null +++ b/include/drm/ttm/ttm_lock.h | |||
@@ -0,0 +1,247 @@ | |||
1 | /************************************************************************** | ||
2 | * | ||
3 | * Copyright (c) 2007-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 | |||
31 | /** @file ttm_lock.h | ||
32 | * This file implements a simple replacement for the buffer manager use | ||
33 | * of the DRM heavyweight hardware lock. | ||
34 | * The lock is a read-write lock. Taking it in read mode and write mode | ||
35 | * is relatively fast, and intended for in-kernel use only. | ||
36 | * | ||
37 | * The vt mode is used only when there is a need to block all | ||
38 | * user-space processes from validating buffers. | ||
39 | * It's allowed to leave kernel space with the vt lock held. | ||
40 | * If a user-space process dies while having the vt-lock, | ||
41 | * it will be released during the file descriptor release. The vt lock | ||
42 | * excludes write lock and read lock. | ||
43 | * | ||
44 | * The suspend mode is used to lock out all TTM users when preparing for | ||
45 | * and executing suspend operations. | ||
46 | * | ||
47 | */ | ||
48 | |||
49 | #ifndef _TTM_LOCK_H_ | ||
50 | #define _TTM_LOCK_H_ | ||
51 | |||
52 | #include "ttm/ttm_object.h" | ||
53 | #include <linux/wait.h> | ||
54 | #include <asm/atomic.h> | ||
55 | |||
56 | /** | ||
57 | * struct ttm_lock | ||
58 | * | ||
59 | * @base: ttm base object used solely to release the lock if the client | ||
60 | * holding the lock dies. | ||
61 | * @queue: Queue for processes waiting for lock change-of-status. | ||
62 | * @lock: Spinlock protecting some lock members. | ||
63 | * @rw: Read-write lock counter. Protected by @lock. | ||
64 | * @flags: Lock state. Protected by @lock. | ||
65 | * @kill_takers: Boolean whether to kill takers of the lock. | ||
66 | * @signal: Signal to send when kill_takers is true. | ||
67 | */ | ||
68 | |||
69 | struct ttm_lock { | ||
70 | struct ttm_base_object base; | ||
71 | wait_queue_head_t queue; | ||
72 | spinlock_t lock; | ||
73 | int32_t rw; | ||
74 | uint32_t flags; | ||
75 | bool kill_takers; | ||
76 | int signal; | ||
77 | struct ttm_object_file *vt_holder; | ||
78 | }; | ||
79 | |||
80 | |||
81 | /** | ||
82 | * ttm_lock_init | ||
83 | * | ||
84 | * @lock: Pointer to a struct ttm_lock | ||
85 | * Initializes the lock. | ||
86 | */ | ||
87 | extern void ttm_lock_init(struct ttm_lock *lock); | ||
88 | |||
89 | /** | ||
90 | * ttm_read_unlock | ||
91 | * | ||
92 | * @lock: Pointer to a struct ttm_lock | ||
93 | * | ||
94 | * Releases a read lock. | ||
95 | */ | ||
96 | extern void ttm_read_unlock(struct ttm_lock *lock); | ||
97 | |||
98 | /** | ||
99 | * ttm_read_lock | ||
100 | * | ||
101 | * @lock: Pointer to a struct ttm_lock | ||
102 | * @interruptible: Interruptible sleeping while waiting for a lock. | ||
103 | * | ||
104 | * Takes the lock in read mode. | ||
105 | * Returns: | ||
106 | * -ERESTARTSYS If interrupted by a signal and interruptible is true. | ||
107 | */ | ||
108 | extern int ttm_read_lock(struct ttm_lock *lock, bool interruptible); | ||
109 | |||
110 | /** | ||
111 | * ttm_read_trylock | ||
112 | * | ||
113 | * @lock: Pointer to a struct ttm_lock | ||
114 | * @interruptible: Interruptible sleeping while waiting for a lock. | ||
115 | * | ||
116 | * Tries to take the lock in read mode. If the lock is already held | ||
117 | * in write mode, the function will return -EBUSY. If the lock is held | ||
118 | * in vt or suspend mode, the function will sleep until these modes | ||
119 | * are unlocked. | ||
120 | * | ||
121 | * Returns: | ||
122 | * -EBUSY The lock was already held in write mode. | ||
123 | * -ERESTARTSYS If interrupted by a signal and interruptible is true. | ||
124 | */ | ||
125 | extern int ttm_read_trylock(struct ttm_lock *lock, bool interruptible); | ||
126 | |||
127 | /** | ||
128 | * ttm_write_unlock | ||
129 | * | ||
130 | * @lock: Pointer to a struct ttm_lock | ||
131 | * | ||
132 | * Releases a write lock. | ||
133 | */ | ||
134 | extern void ttm_write_unlock(struct ttm_lock *lock); | ||
135 | |||
136 | /** | ||
137 | * ttm_write_lock | ||
138 | * | ||
139 | * @lock: Pointer to a struct ttm_lock | ||
140 | * @interruptible: Interruptible sleeping while waiting for a lock. | ||
141 | * | ||
142 | * Takes the lock in write mode. | ||
143 | * Returns: | ||
144 | * -ERESTARTSYS If interrupted by a signal and interruptible is true. | ||
145 | */ | ||
146 | extern int ttm_write_lock(struct ttm_lock *lock, bool interruptible); | ||
147 | |||
148 | /** | ||
149 | * ttm_lock_downgrade | ||
150 | * | ||
151 | * @lock: Pointer to a struct ttm_lock | ||
152 | * | ||
153 | * Downgrades a write lock to a read lock. | ||
154 | */ | ||
155 | extern void ttm_lock_downgrade(struct ttm_lock *lock); | ||
156 | |||
157 | /** | ||
158 | * ttm_suspend_lock | ||
159 | * | ||
160 | * @lock: Pointer to a struct ttm_lock | ||
161 | * | ||
162 | * Takes the lock in suspend mode. Excludes read and write mode. | ||
163 | */ | ||
164 | extern void ttm_suspend_lock(struct ttm_lock *lock); | ||
165 | |||
166 | /** | ||
167 | * ttm_suspend_unlock | ||
168 | * | ||
169 | * @lock: Pointer to a struct ttm_lock | ||
170 | * | ||
171 | * Releases a suspend lock | ||
172 | */ | ||
173 | extern void ttm_suspend_unlock(struct ttm_lock *lock); | ||
174 | |||
175 | /** | ||
176 | * ttm_vt_lock | ||
177 | * | ||
178 | * @lock: Pointer to a struct ttm_lock | ||
179 | * @interruptible: Interruptible sleeping while waiting for a lock. | ||
180 | * @tfile: Pointer to a struct ttm_object_file to register the lock with. | ||
181 | * | ||
182 | * Takes the lock in vt mode. | ||
183 | * Returns: | ||
184 | * -ERESTARTSYS If interrupted by a signal and interruptible is true. | ||
185 | * -ENOMEM: Out of memory when locking. | ||
186 | */ | ||
187 | extern int ttm_vt_lock(struct ttm_lock *lock, bool interruptible, | ||
188 | struct ttm_object_file *tfile); | ||
189 | |||
190 | /** | ||
191 | * ttm_vt_unlock | ||
192 | * | ||
193 | * @lock: Pointer to a struct ttm_lock | ||
194 | * | ||
195 | * Releases a vt lock. | ||
196 | * Returns: | ||
197 | * -EINVAL If the lock was not held. | ||
198 | */ | ||
199 | extern int ttm_vt_unlock(struct ttm_lock *lock); | ||
200 | |||
201 | /** | ||
202 | * ttm_write_unlock | ||
203 | * | ||
204 | * @lock: Pointer to a struct ttm_lock | ||
205 | * | ||
206 | * Releases a write lock. | ||
207 | */ | ||
208 | extern void ttm_write_unlock(struct ttm_lock *lock); | ||
209 | |||
210 | /** | ||
211 | * ttm_write_lock | ||
212 | * | ||
213 | * @lock: Pointer to a struct ttm_lock | ||
214 | * @interruptible: Interruptible sleeping while waiting for a lock. | ||
215 | * | ||
216 | * Takes the lock in write mode. | ||
217 | * Returns: | ||
218 | * -ERESTARTSYS If interrupted by a signal and interruptible is true. | ||
219 | */ | ||
220 | extern int ttm_write_lock(struct ttm_lock *lock, bool interruptible); | ||
221 | |||
222 | /** | ||
223 | * ttm_lock_set_kill | ||
224 | * | ||
225 | * @lock: Pointer to a struct ttm_lock | ||
226 | * @val: Boolean whether to kill processes taking the lock. | ||
227 | * @signal: Signal to send to the process taking the lock. | ||
228 | * | ||
229 | * The kill-when-taking-lock functionality is used to kill processes that keep | ||
230 | * on using the TTM functionality when its resources has been taken down, for | ||
231 | * example when the X server exits. A typical sequence would look like this: | ||
232 | * - X server takes lock in write mode. | ||
233 | * - ttm_lock_set_kill() is called with @val set to true. | ||
234 | * - As part of X server exit, TTM resources are taken down. | ||
235 | * - X server releases the lock on file release. | ||
236 | * - Another dri client wants to render, takes the lock and is killed. | ||
237 | * | ||
238 | */ | ||
239 | static inline void ttm_lock_set_kill(struct ttm_lock *lock, bool val, | ||
240 | int signal) | ||
241 | { | ||
242 | lock->kill_takers = val; | ||
243 | if (val) | ||
244 | lock->signal = signal; | ||
245 | } | ||
246 | |||
247 | #endif | ||
diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h index 6983a7cf4da4..b199170b3c2c 100644 --- a/include/drm/ttm/ttm_memory.h +++ b/include/drm/ttm/ttm_memory.h | |||
@@ -33,6 +33,7 @@ | |||
33 | #include <linux/wait.h> | 33 | #include <linux/wait.h> |
34 | #include <linux/errno.h> | 34 | #include <linux/errno.h> |
35 | #include <linux/kobject.h> | 35 | #include <linux/kobject.h> |
36 | #include <linux/mm.h> | ||
36 | 37 | ||
37 | /** | 38 | /** |
38 | * struct ttm_mem_shrink - callback to shrink TTM memory usage. | 39 | * struct ttm_mem_shrink - callback to shrink TTM memory usage. |
diff --git a/include/drm/ttm/ttm_object.h b/include/drm/ttm/ttm_object.h new file mode 100644 index 000000000000..0d9db099978b --- /dev/null +++ b/include/drm/ttm/ttm_object.h | |||
@@ -0,0 +1,271 @@ | |||
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 | ttm_driver_type2, | ||
82 | ttm_driver_type3, | ||
83 | ttm_driver_type4, | ||
84 | ttm_driver_type5 | ||
85 | }; | ||
86 | |||
87 | struct ttm_object_file; | ||
88 | struct ttm_object_device; | ||
89 | |||
90 | /** | ||
91 | * struct ttm_base_object | ||
92 | * | ||
93 | * @hash: hash entry for the per-device object hash. | ||
94 | * @type: derived type this object is base class for. | ||
95 | * @shareable: Other ttm_object_files can access this object. | ||
96 | * | ||
97 | * @tfile: Pointer to ttm_object_file of the creator. | ||
98 | * NULL if the object was not created by a user request. | ||
99 | * (kernel object). | ||
100 | * | ||
101 | * @refcount: Number of references to this object, not | ||
102 | * including the hash entry. A reference to a base object can | ||
103 | * only be held by a ref object. | ||
104 | * | ||
105 | * @refcount_release: A function to be called when there are | ||
106 | * no more references to this object. This function should | ||
107 | * destroy the object (or make sure destruction eventually happens), | ||
108 | * and when it is called, the object has | ||
109 | * already been taken out of the per-device hash. The parameter | ||
110 | * "base" should be set to NULL by the function. | ||
111 | * | ||
112 | * @ref_obj_release: A function to be called when a reference object | ||
113 | * with another ttm_ref_type than TTM_REF_USAGE is deleted. | ||
114 | * this function may, for example, release a lock held by a user-space | ||
115 | * process. | ||
116 | * | ||
117 | * This struct is intended to be used as a base struct for objects that | ||
118 | * are visible to user-space. It provides a global name, race-safe | ||
119 | * access and refcounting, minimal access contol and hooks for unref actions. | ||
120 | */ | ||
121 | |||
122 | struct ttm_base_object { | ||
123 | struct drm_hash_item hash; | ||
124 | enum ttm_object_type object_type; | ||
125 | bool shareable; | ||
126 | struct ttm_object_file *tfile; | ||
127 | struct kref refcount; | ||
128 | void (*refcount_release) (struct ttm_base_object **base); | ||
129 | void (*ref_obj_release) (struct ttm_base_object *base, | ||
130 | enum ttm_ref_type ref_type); | ||
131 | }; | ||
132 | |||
133 | /** | ||
134 | * ttm_base_object_init | ||
135 | * | ||
136 | * @tfile: Pointer to a struct ttm_object_file. | ||
137 | * @base: The struct ttm_base_object to initialize. | ||
138 | * @shareable: This object is shareable with other applcations. | ||
139 | * (different @tfile pointers.) | ||
140 | * @type: The object type. | ||
141 | * @refcount_release: See the struct ttm_base_object description. | ||
142 | * @ref_obj_release: See the struct ttm_base_object description. | ||
143 | * | ||
144 | * Initializes a struct ttm_base_object. | ||
145 | */ | ||
146 | |||
147 | extern int ttm_base_object_init(struct ttm_object_file *tfile, | ||
148 | struct ttm_base_object *base, | ||
149 | bool shareable, | ||
150 | enum ttm_object_type type, | ||
151 | void (*refcount_release) (struct ttm_base_object | ||
152 | **), | ||
153 | void (*ref_obj_release) (struct ttm_base_object | ||
154 | *, | ||
155 | enum ttm_ref_type | ||
156 | ref_type)); | ||
157 | |||
158 | /** | ||
159 | * ttm_base_object_lookup | ||
160 | * | ||
161 | * @tfile: Pointer to a struct ttm_object_file. | ||
162 | * @key: Hash key | ||
163 | * | ||
164 | * Looks up a struct ttm_base_object with the key @key. | ||
165 | * Also verifies that the object is visible to the application, by | ||
166 | * comparing the @tfile argument and checking the object shareable flag. | ||
167 | */ | ||
168 | |||
169 | extern struct ttm_base_object *ttm_base_object_lookup(struct ttm_object_file | ||
170 | *tfile, uint32_t key); | ||
171 | |||
172 | /** | ||
173 | * ttm_base_object_unref | ||
174 | * | ||
175 | * @p_base: Pointer to a pointer referncing a struct ttm_base_object. | ||
176 | * | ||
177 | * Decrements the base object refcount and clears the pointer pointed to by | ||
178 | * p_base. | ||
179 | */ | ||
180 | |||
181 | extern void ttm_base_object_unref(struct ttm_base_object **p_base); | ||
182 | |||
183 | /** | ||
184 | * ttm_ref_object_add. | ||
185 | * | ||
186 | * @tfile: A struct ttm_object_file representing the application owning the | ||
187 | * ref_object. | ||
188 | * @base: The base object to reference. | ||
189 | * @ref_type: The type of reference. | ||
190 | * @existed: Upon completion, indicates that an identical reference object | ||
191 | * already existed, and the refcount was upped on that object instead. | ||
192 | * | ||
193 | * Adding a ref object to a base object is basically like referencing the | ||
194 | * base object, but a user-space application holds the reference. When the | ||
195 | * file corresponding to @tfile is closed, all its reference objects are | ||
196 | * deleted. A reference object can have different types depending on what | ||
197 | * it's intended for. It can be refcounting to prevent object destruction, | ||
198 | * When user-space takes a lock, it can add a ref object to that lock to | ||
199 | * make sure the lock is released if the application dies. A ref object | ||
200 | * will hold a single reference on a base object. | ||
201 | */ | ||
202 | extern int ttm_ref_object_add(struct ttm_object_file *tfile, | ||
203 | struct ttm_base_object *base, | ||
204 | enum ttm_ref_type ref_type, bool *existed); | ||
205 | /** | ||
206 | * ttm_ref_object_base_unref | ||
207 | * | ||
208 | * @key: Key representing the base object. | ||
209 | * @ref_type: Ref type of the ref object to be dereferenced. | ||
210 | * | ||
211 | * Unreference a ref object with type @ref_type | ||
212 | * on the base object identified by @key. If there are no duplicate | ||
213 | * references, the ref object will be destroyed and the base object | ||
214 | * will be unreferenced. | ||
215 | */ | ||
216 | extern int ttm_ref_object_base_unref(struct ttm_object_file *tfile, | ||
217 | unsigned long key, | ||
218 | enum ttm_ref_type ref_type); | ||
219 | |||
220 | /** | ||
221 | * ttm_object_file_init - initialize a struct ttm_object file | ||
222 | * | ||
223 | * @tdev: A struct ttm_object device this file is initialized on. | ||
224 | * @hash_order: Order of the hash table used to hold the reference objects. | ||
225 | * | ||
226 | * This is typically called by the file_ops::open function. | ||
227 | */ | ||
228 | |||
229 | extern struct ttm_object_file *ttm_object_file_init(struct ttm_object_device | ||
230 | *tdev, | ||
231 | unsigned int hash_order); | ||
232 | |||
233 | /** | ||
234 | * ttm_object_file_release - release data held by a ttm_object_file | ||
235 | * | ||
236 | * @p_tfile: Pointer to pointer to the ttm_object_file object to release. | ||
237 | * *p_tfile will be set to NULL by this function. | ||
238 | * | ||
239 | * Releases all data associated by a ttm_object_file. | ||
240 | * Typically called from file_ops::release. The caller must | ||
241 | * ensure that there are no concurrent users of tfile. | ||
242 | */ | ||
243 | |||
244 | extern void ttm_object_file_release(struct ttm_object_file **p_tfile); | ||
245 | |||
246 | /** | ||
247 | * ttm_object device init - initialize a struct ttm_object_device | ||
248 | * | ||
249 | * @hash_order: Order of hash table used to hash the base objects. | ||
250 | * | ||
251 | * This function is typically called on device initialization to prepare | ||
252 | * data structures needed for ttm base and ref objects. | ||
253 | */ | ||
254 | |||
255 | extern struct ttm_object_device *ttm_object_device_init | ||
256 | (struct ttm_mem_global *mem_glob, unsigned int hash_order); | ||
257 | |||
258 | /** | ||
259 | * ttm_object_device_release - release data held by a ttm_object_device | ||
260 | * | ||
261 | * @p_tdev: Pointer to pointer to the ttm_object_device object to release. | ||
262 | * *p_tdev will be set to NULL by this function. | ||
263 | * | ||
264 | * Releases all data associated by a ttm_object_device. | ||
265 | * Typically called from driver::unload before the destruction of the | ||
266 | * device private data structure. | ||
267 | */ | ||
268 | |||
269 | extern void ttm_object_device_release(struct ttm_object_device **p_tdev); | ||
270 | |||
271 | #endif | ||