1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /**************************************************************************
4 * Copyright © 2018 VMware, Inc., Palo Alto, CA., USA
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
23 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
28 #include <linux/slab.h>
29 #include "vmwgfx_validation.h"
30 #include "vmwgfx_drv.h"
33 * struct vmw_validation_bo_node - Buffer object validation metadata.
34 * @base: Metadata used for TTM reservation- and validation.
35 * @hash: A hash entry used for the duplicate detection hash table.
36 * @coherent_count: If switching backup buffers, number of new coherent
37 * resources that will have this buffer as a backup buffer.
38 * @as_mob: Validate as mob.
39 * @cpu_blit: Validate for cpu blit access.
41 * Bit fields are used since these structures are allocated and freed in
42 * large numbers and space conservation is desired.
44 struct vmw_validation_bo_node
{
45 struct ttm_validate_buffer base
;
46 struct drm_hash_item hash
;
47 unsigned int coherent_count
;
53 * struct vmw_validation_res_node - Resource validation metadata.
54 * @head: List head for the resource validation list.
55 * @hash: A hash entry used for the duplicate detection hash table.
56 * @res: Reference counted resource pointer.
57 * @new_backup: Non ref-counted pointer to new backup buffer to be assigned
59 * @new_backup_offset: Offset into the new backup mob for resources that can
61 * @no_buffer_needed: Kernel does not need to allocate a MOB during validation,
62 * the command stream provides a mob bind operation.
63 * @switching_backup: The validation process is switching backup MOB.
64 * @first_usage: True iff the resource has been seen only once in the current
66 * @reserved: Whether the resource is currently reserved by this process.
67 * @private: Optionally additional memory for caller-private data.
69 * Bit fields are used since these structures are allocated and freed in
70 * large numbers and space conservation is desired.
72 struct vmw_validation_res_node
{
73 struct list_head head
;
74 struct drm_hash_item hash
;
75 struct vmw_resource
*res
;
76 struct vmw_buffer_object
*new_backup
;
77 unsigned long new_backup_offset
;
78 u32 no_buffer_needed
: 1;
79 u32 switching_backup
: 1;
84 unsigned long private[0];
88 * vmw_validation_mem_alloc - Allocate kernel memory from the validation
89 * context based allocator
90 * @ctx: The validation context
91 * @size: The number of bytes to allocated.
93 * The memory allocated may not exceed PAGE_SIZE, and the returned
94 * address is aligned to sizeof(long). All memory allocated this way is
95 * reclaimed after validation when calling any of the exported functions:
96 * vmw_validation_unref_lists()
97 * vmw_validation_revert()
98 * vmw_validation_done()
100 * Return: Pointer to the allocated memory on success. NULL on failure.
102 void *vmw_validation_mem_alloc(struct vmw_validation_context
*ctx
,
107 size
= vmw_validation_align(size
);
108 if (size
> PAGE_SIZE
)
111 if (ctx
->mem_size_left
< size
) {
114 if (ctx
->vm
&& ctx
->vm_size_left
< PAGE_SIZE
) {
115 int ret
= ctx
->vm
->reserve_mem(ctx
->vm
, ctx
->vm
->gran
);
120 ctx
->vm_size_left
+= ctx
->vm
->gran
;
121 ctx
->total_mem
+= ctx
->vm
->gran
;
124 page
= alloc_page(GFP_KERNEL
| __GFP_ZERO
);
129 ctx
->vm_size_left
-= PAGE_SIZE
;
131 list_add_tail(&page
->lru
, &ctx
->page_list
);
132 ctx
->page_address
= page_address(page
);
133 ctx
->mem_size_left
= PAGE_SIZE
;
136 addr
= (void *) (ctx
->page_address
+ (PAGE_SIZE
- ctx
->mem_size_left
));
137 ctx
->mem_size_left
-= size
;
143 * vmw_validation_mem_free - Free all memory allocated using
144 * vmw_validation_mem_alloc()
145 * @ctx: The validation context
147 * All memory previously allocated for this context using
148 * vmw_validation_mem_alloc() is freed.
150 static void vmw_validation_mem_free(struct vmw_validation_context
*ctx
)
152 struct page
*entry
, *next
;
154 list_for_each_entry_safe(entry
, next
, &ctx
->page_list
, lru
) {
155 list_del_init(&entry
->lru
);
159 ctx
->mem_size_left
= 0;
160 if (ctx
->vm
&& ctx
->total_mem
) {
161 ctx
->vm
->unreserve_mem(ctx
->vm
, ctx
->total_mem
);
163 ctx
->vm_size_left
= 0;
168 * vmw_validation_find_bo_dup - Find a duplicate buffer object entry in the
169 * validation context's lists.
170 * @ctx: The validation context to search.
171 * @vbo: The buffer object to search for.
173 * Return: Pointer to the struct vmw_validation_bo_node referencing the
174 * duplicate, or NULL if none found.
176 static struct vmw_validation_bo_node
*
177 vmw_validation_find_bo_dup(struct vmw_validation_context
*ctx
,
178 struct vmw_buffer_object
*vbo
)
180 struct vmw_validation_bo_node
*bo_node
= NULL
;
182 if (!ctx
->merge_dups
)
186 struct drm_hash_item
*hash
;
188 if (!drm_ht_find_item(ctx
->ht
, (unsigned long) vbo
, &hash
))
189 bo_node
= container_of(hash
, typeof(*bo_node
), hash
);
191 struct vmw_validation_bo_node
*entry
;
193 list_for_each_entry(entry
, &ctx
->bo_list
, base
.head
) {
194 if (entry
->base
.bo
== &vbo
->base
) {
205 * vmw_validation_find_res_dup - Find a duplicate resource entry in the
206 * validation context's lists.
207 * @ctx: The validation context to search.
208 * @vbo: The buffer object to search for.
210 * Return: Pointer to the struct vmw_validation_bo_node referencing the
211 * duplicate, or NULL if none found.
213 static struct vmw_validation_res_node
*
214 vmw_validation_find_res_dup(struct vmw_validation_context
*ctx
,
215 struct vmw_resource
*res
)
217 struct vmw_validation_res_node
*res_node
= NULL
;
219 if (!ctx
->merge_dups
)
223 struct drm_hash_item
*hash
;
225 if (!drm_ht_find_item(ctx
->ht
, (unsigned long) res
, &hash
))
226 res_node
= container_of(hash
, typeof(*res_node
), hash
);
228 struct vmw_validation_res_node
*entry
;
230 list_for_each_entry(entry
, &ctx
->resource_ctx_list
, head
) {
231 if (entry
->res
== res
) {
237 list_for_each_entry(entry
, &ctx
->resource_list
, head
) {
238 if (entry
->res
== res
) {
250 * vmw_validation_add_bo - Add a buffer object to the validation context.
251 * @ctx: The validation context.
252 * @vbo: The buffer object.
253 * @as_mob: Validate as mob, otherwise suitable for GMR operations.
254 * @cpu_blit: Validate in a page-mappable location.
256 * Return: Zero on success, negative error code otherwise.
258 int vmw_validation_add_bo(struct vmw_validation_context
*ctx
,
259 struct vmw_buffer_object
*vbo
,
263 struct vmw_validation_bo_node
*bo_node
;
265 bo_node
= vmw_validation_find_bo_dup(ctx
, vbo
);
267 if (bo_node
->as_mob
!= as_mob
||
268 bo_node
->cpu_blit
!= cpu_blit
) {
269 DRM_ERROR("Inconsistent buffer usage.\n");
273 struct ttm_validate_buffer
*val_buf
;
276 bo_node
= vmw_validation_mem_alloc(ctx
, sizeof(*bo_node
));
281 bo_node
->hash
.key
= (unsigned long) vbo
;
282 ret
= drm_ht_insert_item(ctx
->ht
, &bo_node
->hash
);
284 DRM_ERROR("Failed to initialize a buffer "
285 "validation entry.\n");
289 val_buf
= &bo_node
->base
;
290 val_buf
->bo
= ttm_bo_get_unless_zero(&vbo
->base
);
293 val_buf
->num_shared
= 0;
294 list_add_tail(&val_buf
->head
, &ctx
->bo_list
);
295 bo_node
->as_mob
= as_mob
;
296 bo_node
->cpu_blit
= cpu_blit
;
303 * vmw_validation_add_resource - Add a resource to the validation context.
304 * @ctx: The validation context.
305 * @res: The resource.
306 * @priv_size: Size of private, additional metadata.
307 * @dirty: Whether to change dirty status.
308 * @p_node: Output pointer of additional metadata address.
309 * @first_usage: Whether this was the first time this resource was seen.
311 * Return: Zero on success, negative error code otherwise.
313 int vmw_validation_add_resource(struct vmw_validation_context
*ctx
,
314 struct vmw_resource
*res
,
320 struct vmw_validation_res_node
*node
;
323 node
= vmw_validation_find_res_dup(ctx
, res
);
325 node
->first_usage
= 0;
329 node
= vmw_validation_mem_alloc(ctx
, sizeof(*node
) + priv_size
);
331 VMW_DEBUG_USER("Failed to allocate a resource validation entry.\n");
336 node
->hash
.key
= (unsigned long) res
;
337 ret
= drm_ht_insert_item(ctx
->ht
, &node
->hash
);
339 DRM_ERROR("Failed to initialize a resource validation "
344 node
->res
= vmw_resource_reference_unless_doomed(res
);
348 node
->first_usage
= 1;
349 if (!res
->dev_priv
->has_mob
) {
350 list_add_tail(&node
->head
, &ctx
->resource_list
);
352 switch (vmw_res_type(res
)) {
353 case vmw_res_context
:
354 case vmw_res_dx_context
:
355 list_add(&node
->head
, &ctx
->resource_ctx_list
);
357 case vmw_res_cotable
:
358 list_add_tail(&node
->head
, &ctx
->resource_ctx_list
);
361 list_add_tail(&node
->head
, &ctx
->resource_list
);
369 /* Overwriting previous information here is intentional! */
370 node
->dirty
= (dirty
& VMW_RES_DIRTY_SET
) ? 1 : 0;
373 *first_usage
= node
->first_usage
;
375 *p_node
= &node
->private;
381 * vmw_validation_res_set_dirty - Register a resource dirty set or clear during
383 * @ctx: The validation context.
384 * @val_private: The additional meta-data pointer returned when the
385 * resource was registered with the validation context. Used to identify
387 * @dirty: Dirty information VMW_RES_DIRTY_XX
389 void vmw_validation_res_set_dirty(struct vmw_validation_context
*ctx
,
390 void *val_private
, u32 dirty
)
392 struct vmw_validation_res_node
*val
;
397 val
= container_of(val_private
, typeof(*val
), private);
399 /* Overwriting previous information here is intentional! */
400 val
->dirty
= (dirty
& VMW_RES_DIRTY_SET
) ? 1 : 0;
404 * vmw_validation_res_switch_backup - Register a backup MOB switch during
406 * @ctx: The validation context.
407 * @val_private: The additional meta-data pointer returned when the
408 * resource was registered with the validation context. Used to identify
410 * @vbo: The new backup buffer object MOB. This buffer object needs to have
411 * already been registered with the validation context.
412 * @backup_offset: Offset into the new backup MOB.
414 void vmw_validation_res_switch_backup(struct vmw_validation_context
*ctx
,
416 struct vmw_buffer_object
*vbo
,
417 unsigned long backup_offset
)
419 struct vmw_validation_res_node
*val
;
421 val
= container_of(val_private
, typeof(*val
), private);
423 val
->switching_backup
= 1;
424 if (val
->first_usage
)
425 val
->no_buffer_needed
= 1;
427 val
->new_backup
= vbo
;
428 val
->new_backup_offset
= backup_offset
;
432 * vmw_validation_res_reserve - Reserve all resources registered with this
433 * validation context.
434 * @ctx: The validation context.
435 * @intr: Use interruptible waits when possible.
437 * Return: Zero on success, -ERESTARTSYS if interrupted. Negative error
440 int vmw_validation_res_reserve(struct vmw_validation_context
*ctx
,
443 struct vmw_validation_res_node
*val
;
446 list_splice_init(&ctx
->resource_ctx_list
, &ctx
->resource_list
);
448 list_for_each_entry(val
, &ctx
->resource_list
, head
) {
449 struct vmw_resource
*res
= val
->res
;
451 ret
= vmw_resource_reserve(res
, intr
, val
->no_buffer_needed
);
457 struct vmw_buffer_object
*vbo
= res
->backup
;
459 ret
= vmw_validation_add_bo
460 (ctx
, vbo
, vmw_resource_needs_backup(res
),
466 if (val
->switching_backup
&& val
->new_backup
&&
468 struct vmw_validation_bo_node
*bo_node
=
469 vmw_validation_find_bo_dup(ctx
,
472 if (WARN_ON(!bo_node
)) {
476 bo_node
->coherent_count
++;
483 vmw_validation_res_unreserve(ctx
, true);
488 * vmw_validation_res_unreserve - Unreserve all reserved resources
489 * registered with this validation context.
490 * @ctx: The validation context.
491 * @backoff: Whether this is a backoff- of a commit-type operation. This
492 * is used to determine whether to switch backup MOBs or not.
494 void vmw_validation_res_unreserve(struct vmw_validation_context
*ctx
,
497 struct vmw_validation_res_node
*val
;
499 list_splice_init(&ctx
->resource_ctx_list
, &ctx
->resource_list
);
501 list_for_each_entry(val
, &ctx
->resource_list
, head
) {
503 vmw_resource_unreserve(val
->res
,
508 list_for_each_entry(val
, &ctx
->resource_list
, head
) {
510 vmw_resource_unreserve(val
->res
,
513 val
->switching_backup
,
515 val
->new_backup_offset
);
520 * vmw_validation_bo_validate_single - Validate a single buffer object.
521 * @bo: The TTM buffer object base.
522 * @interruptible: Whether to perform waits interruptible if possible.
523 * @validate_as_mob: Whether to validate in MOB memory.
525 * Return: Zero on success, -ERESTARTSYS if interrupted. Negative error
528 int vmw_validation_bo_validate_single(struct ttm_buffer_object
*bo
,
530 bool validate_as_mob
)
532 struct vmw_buffer_object
*vbo
=
533 container_of(bo
, struct vmw_buffer_object
, base
);
534 struct ttm_operation_ctx ctx
= {
535 .interruptible
= interruptible
,
540 if (atomic_read(&vbo
->cpu_writers
))
543 if (vbo
->base
.pin_count
> 0)
547 return ttm_bo_validate(bo
, &vmw_mob_placement
, &ctx
);
550 * Put BO in VRAM if there is space, otherwise as a GMR.
551 * If there is no space in VRAM and GMR ids are all used up,
552 * start evicting GMRs to make room. If the DMA buffer can't be
553 * used as a GMR, this will return -ENOMEM.
556 ret
= ttm_bo_validate(bo
, &vmw_vram_gmr_placement
, &ctx
);
557 if (ret
== 0 || ret
== -ERESTARTSYS
)
561 * If that failed, try VRAM again, this time evicting
565 ret
= ttm_bo_validate(bo
, &vmw_vram_placement
, &ctx
);
570 * vmw_validation_bo_validate - Validate all buffer objects registered with
571 * the validation context.
572 * @ctx: The validation context.
573 * @intr: Whether to perform waits interruptible if possible.
575 * Return: Zero on success, -ERESTARTSYS if interrupted,
576 * negative error code on failure.
578 int vmw_validation_bo_validate(struct vmw_validation_context
*ctx
, bool intr
)
580 struct vmw_validation_bo_node
*entry
;
583 list_for_each_entry(entry
, &ctx
->bo_list
, base
.head
) {
584 struct vmw_buffer_object
*vbo
=
585 container_of(entry
->base
.bo
, typeof(*vbo
), base
);
587 if (entry
->cpu_blit
) {
588 struct ttm_operation_ctx ctx
= {
589 .interruptible
= intr
,
593 ret
= ttm_bo_validate(entry
->base
.bo
,
594 &vmw_nonfixed_placement
, &ctx
);
596 ret
= vmw_validation_bo_validate_single
597 (entry
->base
.bo
, intr
, entry
->as_mob
);
603 * Rather than having the resource code allocating the bo
604 * dirty tracker in resource_unreserve() where we can't fail,
605 * Do it here when validating the buffer object.
607 if (entry
->coherent_count
) {
608 unsigned int coherent_count
= entry
->coherent_count
;
610 while (coherent_count
) {
611 ret
= vmw_bo_dirty_add(vbo
);
617 entry
->coherent_count
-= coherent_count
;
621 vmw_bo_dirty_scan(vbo
);
627 * vmw_validation_res_validate - Validate all resources registered with the
628 * validation context.
629 * @ctx: The validation context.
630 * @intr: Whether to perform waits interruptible if possible.
632 * Before this function is called, all resource backup buffers must have
635 * Return: Zero on success, -ERESTARTSYS if interrupted,
636 * negative error code on failure.
638 int vmw_validation_res_validate(struct vmw_validation_context
*ctx
, bool intr
)
640 struct vmw_validation_res_node
*val
;
643 list_for_each_entry(val
, &ctx
->resource_list
, head
) {
644 struct vmw_resource
*res
= val
->res
;
645 struct vmw_buffer_object
*backup
= res
->backup
;
647 ret
= vmw_resource_validate(res
, intr
, val
->dirty_set
&&
650 if (ret
!= -ERESTARTSYS
)
651 DRM_ERROR("Failed to validate resource.\n");
655 /* Check if the resource switched backup buffer */
656 if (backup
&& res
->backup
&& (backup
!= res
->backup
)) {
657 struct vmw_buffer_object
*vbo
= res
->backup
;
659 ret
= vmw_validation_add_bo
660 (ctx
, vbo
, vmw_resource_needs_backup(res
),
670 * vmw_validation_drop_ht - Reset the hash table used for duplicate finding
671 * and unregister it from this validation context.
672 * @ctx: The validation context.
674 * The hash table used for duplicate finding is an expensive resource and
675 * may be protected by mutexes that may cause deadlocks during resource
676 * unreferencing if held. After resource- and buffer object registering,
677 * there is no longer any use for this hash table, so allow freeing it
678 * either to shorten any mutex locking time, or before resources- and
679 * buffer objects are freed during validation context cleanup.
681 void vmw_validation_drop_ht(struct vmw_validation_context
*ctx
)
683 struct vmw_validation_bo_node
*entry
;
684 struct vmw_validation_res_node
*val
;
689 list_for_each_entry(entry
, &ctx
->bo_list
, base
.head
)
690 (void) drm_ht_remove_item(ctx
->ht
, &entry
->hash
);
692 list_for_each_entry(val
, &ctx
->resource_list
, head
)
693 (void) drm_ht_remove_item(ctx
->ht
, &val
->hash
);
695 list_for_each_entry(val
, &ctx
->resource_ctx_list
, head
)
696 (void) drm_ht_remove_item(ctx
->ht
, &val
->hash
);
702 * vmw_validation_unref_lists - Unregister previously registered buffer
703 * object and resources.
704 * @ctx: The validation context.
706 * Note that this function may cause buffer object- and resource destructors
709 void vmw_validation_unref_lists(struct vmw_validation_context
*ctx
)
711 struct vmw_validation_bo_node
*entry
;
712 struct vmw_validation_res_node
*val
;
714 list_for_each_entry(entry
, &ctx
->bo_list
, base
.head
) {
715 ttm_bo_put(entry
->base
.bo
);
716 entry
->base
.bo
= NULL
;
719 list_splice_init(&ctx
->resource_ctx_list
, &ctx
->resource_list
);
720 list_for_each_entry(val
, &ctx
->resource_list
, head
)
721 vmw_resource_unreference(&val
->res
);
724 * No need to detach each list entry since they are all freed with
725 * vmw_validation_free_mem. Just make the inaccessible.
727 INIT_LIST_HEAD(&ctx
->bo_list
);
728 INIT_LIST_HEAD(&ctx
->resource_list
);
730 vmw_validation_mem_free(ctx
);
734 * vmw_validation_prepare - Prepare a validation context for command
736 * @ctx: The validation context.
737 * @mutex: The mutex used to protect resource reservation.
738 * @intr: Whether to perform waits interruptible if possible.
740 * Note that the single reservation mutex @mutex is an unfortunate
741 * construct. Ideally resource reservation should be moved to per-resource
743 * If this functions doesn't return Zero to indicate success, all resources
744 * are left unreserved but still referenced.
745 * Return: Zero on success, -ERESTARTSYS if interrupted, negative error code
748 int vmw_validation_prepare(struct vmw_validation_context
*ctx
,
756 ret
= mutex_lock_interruptible(mutex
);
763 ctx
->res_mutex
= mutex
;
764 ret
= vmw_validation_res_reserve(ctx
, intr
);
766 goto out_no_res_reserve
;
768 ret
= vmw_validation_bo_reserve(ctx
, intr
);
770 goto out_no_bo_reserve
;
772 ret
= vmw_validation_bo_validate(ctx
, intr
);
774 goto out_no_validate
;
776 ret
= vmw_validation_res_validate(ctx
, intr
);
778 goto out_no_validate
;
783 vmw_validation_bo_backoff(ctx
);
785 vmw_validation_res_unreserve(ctx
, true);
794 * vmw_validation_revert - Revert validation actions if command submission
797 * @ctx: The validation context.
799 * The caller still needs to unref resources after a call to this function.
801 void vmw_validation_revert(struct vmw_validation_context
*ctx
)
803 vmw_validation_bo_backoff(ctx
);
804 vmw_validation_res_unreserve(ctx
, true);
806 mutex_unlock(ctx
->res_mutex
);
807 vmw_validation_unref_lists(ctx
);
811 * vmw_validation_cone - Commit validation actions after command submission
813 * @ctx: The validation context.
814 * @fence: Fence with which to fence all buffer objects taking part in the
815 * command submission.
817 * The caller does NOT need to unref resources after a call to this function.
819 void vmw_validation_done(struct vmw_validation_context
*ctx
,
820 struct vmw_fence_obj
*fence
)
822 vmw_validation_bo_fence(ctx
, fence
);
823 vmw_validation_res_unreserve(ctx
, false);
825 mutex_unlock(ctx
->res_mutex
);
826 vmw_validation_unref_lists(ctx
);
830 * vmw_validation_preload_bo - Preload the validation memory allocator for a
831 * call to vmw_validation_add_bo().
832 * @ctx: Pointer to the validation context.
834 * Iff this function returns successfully, the next call to
835 * vmw_validation_add_bo() is guaranteed not to sleep. An error is not fatal
836 * but voids the guarantee.
838 * Returns: Zero if successful, %-EINVAL otherwise.
840 int vmw_validation_preload_bo(struct vmw_validation_context
*ctx
)
842 unsigned int size
= sizeof(struct vmw_validation_bo_node
);
844 if (!vmw_validation_mem_alloc(ctx
, size
))
847 ctx
->mem_size_left
+= size
;
852 * vmw_validation_preload_res - Preload the validation memory allocator for a
853 * call to vmw_validation_add_res().
854 * @ctx: Pointer to the validation context.
855 * @size: Size of the validation node extra data. See below.
857 * Iff this function returns successfully, the next call to
858 * vmw_validation_add_res() with the same or smaller @size is guaranteed not to
859 * sleep. An error is not fatal but voids the guarantee.
861 * Returns: Zero if successful, %-EINVAL otherwise.
863 int vmw_validation_preload_res(struct vmw_validation_context
*ctx
,
866 size
= vmw_validation_align(sizeof(struct vmw_validation_res_node
) +
868 vmw_validation_align(sizeof(struct vmw_validation_bo_node
));
869 if (!vmw_validation_mem_alloc(ctx
, size
))
872 ctx
->mem_size_left
+= size
;
877 * vmw_validation_bo_backoff - Unreserve buffer objects registered with a
879 * @ctx: The validation context
881 * This function unreserves the buffer objects previously reserved using
882 * vmw_validation_bo_reserve. It's typically used as part of an error path
884 void vmw_validation_bo_backoff(struct vmw_validation_context
*ctx
)
886 struct vmw_validation_bo_node
*entry
;
889 * Switching coherent resource backup buffers failed.
890 * Release corresponding buffer object dirty trackers.
892 list_for_each_entry(entry
, &ctx
->bo_list
, base
.head
) {
893 if (entry
->coherent_count
) {
894 unsigned int coherent_count
= entry
->coherent_count
;
895 struct vmw_buffer_object
*vbo
=
896 container_of(entry
->base
.bo
, typeof(*vbo
),
899 while (coherent_count
--)
900 vmw_bo_dirty_release(vbo
);
904 ttm_eu_backoff_reservation(&ctx
->ticket
, &ctx
->bo_list
);