1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /**************************************************************************
4 * Copyright (c) 2011-2024 Broadcom. All Rights Reserved. The term
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
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 **************************************************************************/
29 #include "vmwgfx_bo.h"
30 #include "vmwgfx_drv.h"
31 #include "vmwgfx_resource_priv.h"
33 #include <drm/ttm/ttm_placement.h>
35 static void vmw_bo_release(struct vmw_bo *vbo)
37 struct vmw_resource *res;
39 WARN_ON(vbo->tbo.base.funcs &&
40 kref_read(&vbo->tbo.base.refcount) != 0);
43 xa_destroy(&vbo->detached_resources);
44 WARN_ON(vbo->is_dumb && !vbo->dumb_surface);
45 if (vbo->is_dumb && vbo->dumb_surface) {
46 res = &vbo->dumb_surface->res;
47 WARN_ON(vbo != res->guest_memory_bo);
48 WARN_ON(!res->guest_memory_bo);
49 if (res->guest_memory_bo) {
50 /* Reserve and switch the backing mob. */
51 mutex_lock(&res->dev_priv->cmdbuf_mutex);
52 (void)vmw_resource_reserve(res, false, true);
53 vmw_resource_mob_detach(res);
55 vmw_bo_dirty_release(res->guest_memory_bo);
56 res->guest_memory_bo = NULL;
57 res->guest_memory_offset = 0;
58 vmw_resource_unreserve(res, false, false, false, NULL,
60 mutex_unlock(&res->dev_priv->cmdbuf_mutex);
62 vmw_surface_unreference(&vbo->dumb_surface);
64 drm_gem_object_release(&vbo->tbo.base);
68 * vmw_bo_free - vmw_bo destructor
70 * @bo: Pointer to the embedded struct ttm_buffer_object
72 static void vmw_bo_free(struct ttm_buffer_object *bo)
74 struct vmw_bo *vbo = to_vmw_bo(&bo->base);
77 WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
83 * vmw_bo_pin_in_placement - Validate a buffer to placement.
85 * @dev_priv: Driver private.
86 * @buf: DMA buffer to move.
87 * @placement: The placement to pin it.
88 * @interruptible: Use interruptible wait.
89 * Return: Zero on success, Negative error code on failure. In particular
90 * -ERESTARTSYS if interrupted by a signal
92 static int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
94 struct ttm_placement *placement,
97 struct ttm_operation_ctx ctx = {interruptible, false };
98 struct ttm_buffer_object *bo = &buf->tbo;
101 vmw_execbuf_release_pinned_bo(dev_priv);
103 ret = ttm_bo_reserve(bo, interruptible, false, NULL);
104 if (unlikely(ret != 0))
107 ret = ttm_bo_validate(bo, placement, &ctx);
109 vmw_bo_pin_reserved(buf, true);
111 ttm_bo_unreserve(bo);
118 * vmw_bo_pin_in_vram_or_gmr - Move a buffer to vram or gmr.
120 * This function takes the reservation_sem in write mode.
121 * Flushes and unpins the query bo to avoid failures.
123 * @dev_priv: Driver private.
124 * @buf: DMA buffer to move.
125 * @interruptible: Use interruptible wait.
126 * Return: Zero on success, Negative error code on failure. In particular
127 * -ERESTARTSYS if interrupted by a signal
129 int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
133 struct ttm_operation_ctx ctx = {interruptible, false };
134 struct ttm_buffer_object *bo = &buf->tbo;
137 vmw_execbuf_release_pinned_bo(dev_priv);
139 ret = ttm_bo_reserve(bo, interruptible, false, NULL);
140 if (unlikely(ret != 0))
143 vmw_bo_placement_set(buf,
144 VMW_BO_DOMAIN_GMR | VMW_BO_DOMAIN_VRAM,
146 ret = ttm_bo_validate(bo, &buf->placement, &ctx);
147 if (likely(ret == 0) || ret == -ERESTARTSYS)
150 vmw_bo_placement_set(buf,
153 ret = ttm_bo_validate(bo, &buf->placement, &ctx);
157 vmw_bo_pin_reserved(buf, true);
159 ttm_bo_unreserve(bo);
166 * vmw_bo_pin_in_vram - Move a buffer to vram.
168 * This function takes the reservation_sem in write mode.
169 * Flushes and unpins the query bo to avoid failures.
171 * @dev_priv: Driver private.
172 * @buf: DMA buffer to move.
173 * @interruptible: Use interruptible wait.
174 * Return: Zero on success, Negative error code on failure. In particular
175 * -ERESTARTSYS if interrupted by a signal
177 int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
181 return vmw_bo_pin_in_placement(dev_priv, buf, &vmw_vram_placement,
187 * vmw_bo_pin_in_start_of_vram - Move a buffer to start of vram.
189 * This function takes the reservation_sem in write mode.
190 * Flushes and unpins the query bo to avoid failures.
192 * @dev_priv: Driver private.
193 * @buf: DMA buffer to pin.
194 * @interruptible: Use interruptible wait.
195 * Return: Zero on success, Negative error code on failure. In particular
196 * -ERESTARTSYS if interrupted by a signal
198 int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
202 struct ttm_operation_ctx ctx = {interruptible, false };
203 struct ttm_buffer_object *bo = &buf->tbo;
206 vmw_execbuf_release_pinned_bo(dev_priv);
207 ret = ttm_bo_reserve(bo, interruptible, false, NULL);
208 if (unlikely(ret != 0))
212 * Is this buffer already in vram but not at the start of it?
213 * In that case, evict it first because TTM isn't good at handling
216 if (bo->resource->mem_type == TTM_PL_VRAM &&
217 bo->resource->start < PFN_UP(bo->resource->size) &&
218 bo->resource->start > 0 &&
219 buf->tbo.pin_count == 0) {
220 ctx.interruptible = false;
221 vmw_bo_placement_set(buf,
224 (void)ttm_bo_validate(bo, &buf->placement, &ctx);
227 vmw_bo_placement_set(buf,
230 buf->places[0].lpfn = PFN_UP(bo->resource->size);
231 ret = ttm_bo_validate(bo, &buf->placement, &ctx);
233 /* For some reason we didn't end up at the start of vram */
234 WARN_ON(ret == 0 && bo->resource->start != 0);
236 vmw_bo_pin_reserved(buf, true);
238 ttm_bo_unreserve(bo);
246 * vmw_bo_unpin - Unpin the buffer given buffer, does not move the buffer.
248 * This function takes the reservation_sem in write mode.
250 * @dev_priv: Driver private.
251 * @buf: DMA buffer to unpin.
252 * @interruptible: Use interruptible wait.
253 * Return: Zero on success, Negative error code on failure. In particular
254 * -ERESTARTSYS if interrupted by a signal
256 int vmw_bo_unpin(struct vmw_private *dev_priv,
260 struct ttm_buffer_object *bo = &buf->tbo;
263 ret = ttm_bo_reserve(bo, interruptible, false, NULL);
264 if (unlikely(ret != 0))
267 vmw_bo_pin_reserved(buf, false);
269 ttm_bo_unreserve(bo);
276 * vmw_bo_get_guest_ptr - Get the guest ptr representing the current placement
279 * @bo: Pointer to a struct ttm_buffer_object. Must be pinned or reserved.
280 * @ptr: SVGAGuestPtr returning the result.
282 void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo,
285 if (bo->resource->mem_type == TTM_PL_VRAM) {
286 ptr->gmrId = SVGA_GMR_FRAMEBUFFER;
287 ptr->offset = bo->resource->start << PAGE_SHIFT;
289 ptr->gmrId = bo->resource->start;
296 * vmw_bo_pin_reserved - Pin or unpin a buffer object without moving it.
298 * @vbo: The buffer object. Must be reserved.
299 * @pin: Whether to pin or unpin.
302 void vmw_bo_pin_reserved(struct vmw_bo *vbo, bool pin)
304 struct ttm_operation_ctx ctx = { false, true };
306 struct ttm_placement placement;
307 struct ttm_buffer_object *bo = &vbo->tbo;
308 uint32_t old_mem_type = bo->resource->mem_type;
311 dma_resv_assert_held(bo->base.resv);
313 if (pin == !!bo->pin_count)
318 pl.mem_type = bo->resource->mem_type;
319 pl.flags = bo->resource->placement;
321 memset(&placement, 0, sizeof(placement));
322 placement.num_placement = 1;
323 placement.placement = &pl;
325 ret = ttm_bo_validate(bo, &placement, &ctx);
327 BUG_ON(ret != 0 || bo->resource->mem_type != old_mem_type);
336 * vmw_bo_map_and_cache - Map a buffer object and cache the map
338 * @vbo: The buffer object to map
339 * Return: A kernel virtual address or NULL if mapping failed.
341 * This function maps a buffer object into the kernel address space, or
342 * returns the virtual kernel address of an already existing map. The virtual
343 * address remains valid as long as the buffer object is pinned or reserved.
344 * The cached map is torn down on either
345 * 1) Buffer object move
346 * 2) Buffer object swapout
347 * 3) Buffer object destruction
350 void *vmw_bo_map_and_cache(struct vmw_bo *vbo)
352 return vmw_bo_map_and_cache_size(vbo, vbo->tbo.base.size);
355 void *vmw_bo_map_and_cache_size(struct vmw_bo *vbo, size_t size)
357 struct ttm_buffer_object *bo = &vbo->tbo;
362 atomic_inc(&vbo->map_count);
364 virtual = ttm_kmap_obj_virtual(&vbo->map, ¬_used);
368 ret = ttm_bo_kmap(bo, 0, PFN_UP(size), &vbo->map);
370 DRM_ERROR("Buffer object map failed: %d (size: bo = %zu, map = %zu).\n",
371 ret, bo->base.size, size);
373 return ttm_kmap_obj_virtual(&vbo->map, ¬_used);
378 * vmw_bo_unmap - Tear down a cached buffer object map.
380 * @vbo: The buffer object whose map we are tearing down.
382 * This function tears down a cached map set up using
383 * vmw_bo_map_and_cache().
385 void vmw_bo_unmap(struct vmw_bo *vbo)
389 if (vbo->map.bo == NULL)
392 map_count = atomic_dec_return(&vbo->map_count);
395 ttm_bo_kunmap(&vbo->map);
402 * vmw_bo_init - Initialize a vmw buffer object
404 * @dev_priv: Pointer to the device private struct
405 * @vmw_bo: Buffer object to initialize
406 * @params: Parameters used to initialize the buffer object
407 * @destroy: The function used to delete the buffer object
408 * Returns: Zero on success, negative error code on error.
411 static int vmw_bo_init(struct vmw_private *dev_priv,
412 struct vmw_bo *vmw_bo,
413 struct vmw_bo_params *params,
414 void (*destroy)(struct ttm_buffer_object *))
416 struct ttm_operation_ctx ctx = {
417 .interruptible = params->bo_type != ttm_bo_type_kernel,
418 .no_wait_gpu = false,
419 .resv = params->resv,
421 struct ttm_device *bdev = &dev_priv->bdev;
422 struct drm_device *vdev = &dev_priv->drm;
425 memset(vmw_bo, 0, sizeof(*vmw_bo));
427 BUILD_BUG_ON(TTM_MAX_BO_PRIORITY <= 3);
428 vmw_bo->tbo.priority = 3;
429 vmw_bo->res_tree = RB_ROOT;
430 xa_init(&vmw_bo->detached_resources);
431 atomic_set(&vmw_bo->map_count, 0);
433 params->size = ALIGN(params->size, PAGE_SIZE);
434 drm_gem_private_object_init(vdev, &vmw_bo->tbo.base, params->size);
436 vmw_bo_placement_set(vmw_bo, params->domain, params->busy_domain);
437 ret = ttm_bo_init_reserved(bdev, &vmw_bo->tbo, params->bo_type,
438 &vmw_bo->placement, 0, &ctx,
439 params->sg, params->resv, destroy);
444 ttm_bo_pin(&vmw_bo->tbo);
445 if (!params->keep_resv)
446 ttm_bo_unreserve(&vmw_bo->tbo);
451 int vmw_bo_create(struct vmw_private *vmw,
452 struct vmw_bo_params *params,
453 struct vmw_bo **p_bo)
457 *p_bo = kmalloc(sizeof(**p_bo), GFP_KERNEL);
458 if (unlikely(!*p_bo)) {
459 DRM_ERROR("Failed to allocate a buffer.\n");
464 * vmw_bo_init will delete the *p_bo object if it fails
466 ret = vmw_bo_init(vmw, *p_bo, params, vmw_bo_free);
467 if (unlikely(ret != 0))
477 * vmw_user_bo_synccpu_grab - Grab a struct vmw_bo for cpu
478 * access, idling previous GPU operations on the buffer and optionally
479 * blocking it for further command submissions.
481 * @vmw_bo: Pointer to the buffer object being grabbed for CPU access
482 * @flags: Flags indicating how the grab should be performed.
483 * Return: Zero on success, Negative error code on error. In particular,
484 * -EBUSY will be returned if a dontblock operation is requested and the
485 * buffer object is busy, and -ERESTARTSYS will be returned if a wait is
486 * interrupted by a signal.
488 * A blocking grab will be automatically released when @tfile is closed.
490 static int vmw_user_bo_synccpu_grab(struct vmw_bo *vmw_bo,
493 bool nonblock = !!(flags & drm_vmw_synccpu_dontblock);
494 struct ttm_buffer_object *bo = &vmw_bo->tbo;
497 if (flags & drm_vmw_synccpu_allow_cs) {
500 lret = dma_resv_wait_timeout(bo->base.resv, DMA_RESV_USAGE_READ,
502 MAX_SCHEDULE_TIMEOUT);
510 ret = ttm_bo_reserve(bo, true, nonblock, NULL);
511 if (unlikely(ret != 0))
514 ret = ttm_bo_wait(bo, true, nonblock);
515 if (likely(ret == 0))
516 atomic_inc(&vmw_bo->cpu_writers);
518 ttm_bo_unreserve(bo);
519 if (unlikely(ret != 0))
526 * vmw_user_bo_synccpu_release - Release a previous grab for CPU access,
527 * and unblock command submission on the buffer if blocked.
529 * @filp: Identifying the caller.
530 * @handle: Handle identifying the buffer object.
531 * @flags: Flags indicating the type of release.
533 static int vmw_user_bo_synccpu_release(struct drm_file *filp,
537 struct vmw_bo *vmw_bo;
538 int ret = vmw_user_bo_lookup(filp, handle, &vmw_bo);
541 if (!(flags & drm_vmw_synccpu_allow_cs)) {
542 atomic_dec(&vmw_bo->cpu_writers);
544 vmw_user_bo_unref(&vmw_bo);
552 * vmw_user_bo_synccpu_ioctl - ioctl function implementing the synccpu
555 * @dev: Identifies the drm device.
556 * @data: Pointer to the ioctl argument.
557 * @file_priv: Identifies the caller.
558 * Return: Zero on success, negative error code on error.
560 * This function checks the ioctl arguments for validity and calls the
561 * relevant synccpu functions.
563 int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
564 struct drm_file *file_priv)
566 struct drm_vmw_synccpu_arg *arg =
567 (struct drm_vmw_synccpu_arg *) data;
571 if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) == 0
572 || (arg->flags & ~(drm_vmw_synccpu_read | drm_vmw_synccpu_write |
573 drm_vmw_synccpu_dontblock |
574 drm_vmw_synccpu_allow_cs)) != 0) {
575 DRM_ERROR("Illegal synccpu flags.\n");
580 case drm_vmw_synccpu_grab:
581 ret = vmw_user_bo_lookup(file_priv, arg->handle, &vbo);
582 if (unlikely(ret != 0))
585 ret = vmw_user_bo_synccpu_grab(vbo, arg->flags);
586 vmw_user_bo_unref(&vbo);
587 if (unlikely(ret != 0)) {
588 if (ret == -ERESTARTSYS || ret == -EBUSY)
590 DRM_ERROR("Failed synccpu grab on handle 0x%08x.\n",
591 (unsigned int) arg->handle);
595 case drm_vmw_synccpu_release:
596 ret = vmw_user_bo_synccpu_release(file_priv,
599 if (unlikely(ret != 0)) {
600 DRM_ERROR("Failed synccpu release on handle 0x%08x.\n",
601 (unsigned int) arg->handle);
606 DRM_ERROR("Invalid synccpu operation.\n");
614 * vmw_bo_unref_ioctl - Generic handle close ioctl.
616 * @dev: Identifies the drm device.
617 * @data: Pointer to the ioctl argument.
618 * @file_priv: Identifies the caller.
619 * Return: Zero on success, negative error code on error.
621 * This function checks the ioctl arguments for validity and closes a
622 * handle to a TTM base object, optionally freeing the object.
624 int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
625 struct drm_file *file_priv)
627 struct drm_vmw_unref_dmabuf_arg *arg =
628 (struct drm_vmw_unref_dmabuf_arg *)data;
630 return drm_gem_handle_delete(file_priv, arg->handle);
635 * vmw_user_bo_lookup - Look up a vmw user buffer object from a handle.
637 * @filp: The file the handle is registered with.
638 * @handle: The user buffer object handle
639 * @out: Pointer to a where a pointer to the embedded
640 * struct vmw_bo should be placed.
641 * Return: Zero on success, Negative error code on error.
643 * The vmw buffer object pointer will be refcounted (both ttm and gem)
645 int vmw_user_bo_lookup(struct drm_file *filp,
649 struct drm_gem_object *gobj;
651 gobj = drm_gem_object_lookup(filp, handle);
653 DRM_ERROR("Invalid buffer object handle 0x%08lx.\n",
654 (unsigned long)handle);
658 *out = to_vmw_bo(gobj);
664 * vmw_bo_fence_single - Utility function to fence a single TTM buffer
665 * object without unreserving it.
667 * @bo: Pointer to the struct ttm_buffer_object to fence.
668 * @fence: Pointer to the fence. If NULL, this function will
669 * insert a fence into the command stream..
671 * Contrary to the ttm_eu version of this function, it takes only
672 * a single buffer object instead of a list, and it also doesn't
673 * unreserve the buffer object, which needs to be done separately.
675 void vmw_bo_fence_single(struct ttm_buffer_object *bo,
676 struct vmw_fence_obj *fence)
678 struct ttm_device *bdev = bo->bdev;
679 struct vmw_private *dev_priv = vmw_priv_from_ttm(bdev);
683 vmw_execbuf_fence_commands(NULL, dev_priv, &fence, NULL);
685 dma_fence_get(&fence->base);
687 ret = dma_resv_reserve_fences(bo->base.resv, 1);
689 dma_resv_add_fence(bo->base.resv, &fence->base,
690 DMA_RESV_USAGE_KERNEL);
692 /* Last resort fallback when we are OOM */
693 dma_fence_wait(&fence->base, false);
694 dma_fence_put(&fence->base);
698 * vmw_bo_swap_notify - swapout notify callback.
700 * @bo: The buffer object to be swapped out.
702 void vmw_bo_swap_notify(struct ttm_buffer_object *bo)
704 /* Kill any cached kernel maps before swapout */
705 vmw_bo_unmap(to_vmw_bo(&bo->base));
710 * vmw_bo_move_notify - TTM move_notify_callback
712 * @bo: The TTM buffer object about to move.
713 * @mem: The struct ttm_resource indicating to what memory
714 * region the move is taking place.
716 * Detaches cached maps and device bindings that require that the
717 * buffer doesn't move.
719 void vmw_bo_move_notify(struct ttm_buffer_object *bo,
720 struct ttm_resource *mem)
722 struct vmw_bo *vbo = to_vmw_bo(&bo->base);
725 * Kill any cached kernel maps before move to or from VRAM.
726 * With other types of moves, the underlying pages stay the same,
727 * and the map can be kept.
729 if (mem->mem_type == TTM_PL_VRAM || bo->resource->mem_type == TTM_PL_VRAM)
733 * If we're moving a backup MOB out of MOB placement, then make sure we
734 * read back all resource content first, and unbind the MOB from
737 if (mem->mem_type != VMW_PL_MOB && bo->resource->mem_type == VMW_PL_MOB)
738 vmw_resource_unbind_list(vbo);
741 static u32 placement_flags(u32 domain, u32 desired, u32 fallback)
743 if (desired & fallback & domain)
746 if (desired & domain)
747 return TTM_PL_FLAG_DESIRED;
749 return TTM_PL_FLAG_FALLBACK;
753 set_placement_list(struct ttm_place *pl, u32 desired, u32 fallback)
755 u32 domain = desired | fallback;
759 * The placements are ordered according to our preferences
761 if (domain & VMW_BO_DOMAIN_MOB) {
762 pl[n].mem_type = VMW_PL_MOB;
763 pl[n].flags = placement_flags(VMW_BO_DOMAIN_MOB, desired,
769 if (domain & VMW_BO_DOMAIN_GMR) {
770 pl[n].mem_type = VMW_PL_GMR;
771 pl[n].flags = placement_flags(VMW_BO_DOMAIN_GMR, desired,
777 if (domain & VMW_BO_DOMAIN_VRAM) {
778 pl[n].mem_type = TTM_PL_VRAM;
779 pl[n].flags = placement_flags(VMW_BO_DOMAIN_VRAM, desired,
785 if (domain & VMW_BO_DOMAIN_WAITABLE_SYS) {
786 pl[n].mem_type = VMW_PL_SYSTEM;
787 pl[n].flags = placement_flags(VMW_BO_DOMAIN_WAITABLE_SYS,
793 if (domain & VMW_BO_DOMAIN_SYS) {
794 pl[n].mem_type = TTM_PL_SYSTEM;
795 pl[n].flags = placement_flags(VMW_BO_DOMAIN_SYS, desired,
804 pl[n].mem_type = TTM_PL_SYSTEM;
813 void vmw_bo_placement_set(struct vmw_bo *bo, u32 domain, u32 busy_domain)
815 struct ttm_device *bdev = bo->tbo.bdev;
816 struct vmw_private *vmw = vmw_priv_from_ttm(bdev);
817 struct ttm_placement *pl = &bo->placement;
818 bool mem_compatible = false;
821 pl->placement = bo->places;
822 pl->num_placement = set_placement_list(bo->places, domain, busy_domain);
824 if (drm_debug_enabled(DRM_UT_DRIVER) && bo->tbo.resource) {
825 for (i = 0; i < pl->num_placement; ++i) {
826 if (bo->tbo.resource->mem_type == TTM_PL_SYSTEM ||
827 bo->tbo.resource->mem_type == pl->placement[i].mem_type)
828 mem_compatible = true;
832 "%s: Incompatible transition from "
833 "bo->base.resource->mem_type = %u to domain = %u\n",
834 __func__, bo->tbo.resource->mem_type, domain);
839 void vmw_bo_placement_set_default_accelerated(struct vmw_bo *bo)
841 struct ttm_device *bdev = bo->tbo.bdev;
842 struct vmw_private *vmw = vmw_priv_from_ttm(bdev);
843 u32 domain = VMW_BO_DOMAIN_GMR | VMW_BO_DOMAIN_VRAM;
846 domain = VMW_BO_DOMAIN_MOB;
848 vmw_bo_placement_set(bo, domain, domain);
851 void vmw_bo_add_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res)
853 xa_store(&vbo->detached_resources, (unsigned long)res, res, GFP_KERNEL);
856 void vmw_bo_del_detached_resource(struct vmw_bo *vbo, struct vmw_resource *res)
858 xa_erase(&vbo->detached_resources, (unsigned long)res);
861 struct vmw_surface *vmw_bo_surface(struct vmw_bo *vbo)
864 struct vmw_resource *res = NULL;
865 struct vmw_surface *surf = NULL;
866 struct rb_node *rb_itr = vbo->res_tree.rb_node;
868 if (vbo->is_dumb && vbo->dumb_surface) {
869 res = &vbo->dumb_surface->res;
873 xa_for_each(&vbo->detached_resources, index, res) {
874 if (res->func->res_type == vmw_res_surface)
878 for (rb_itr = rb_first(&vbo->res_tree); rb_itr;
879 rb_itr = rb_next(rb_itr)) {
880 res = rb_entry(rb_itr, struct vmw_resource, mob_node);
881 if (res->func->res_type == vmw_res_surface)
887 surf = vmw_res_to_srf(res);