Lines Matching +full:resource +full:- +full:id
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
4 * Copyright 2014-2023 VMware, Inc., Palo Alto, CA., USA
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
28 * Treat context OTables as resources to make use of the resource
42 * struct vmw_cotable - Context Object Table resource
45 * @ctx: non-refcounted pointer to the owning context.
63 * struct vmw_cotable_info - Static info about cotable types
68 * @unbind_func: Unbind call-back function.
148 * vmw_cotable - Convert a struct vmw_resource pointer to a struct
151 * @res: Pointer to the resource.
159 * vmw_cotable_destroy - Cotable resource destroy callback
161 * @res: Pointer to the cotable resource.
164 * makes sure that the resource id is set to invalid.
168 res->id = -1; in vmw_cotable_destroy()
173 * vmw_cotable_unscrub - Undo a cotable unscrub operation
175 * @res: Pointer to the cotable resource
184 struct vmw_private *dev_priv = res->dev_priv; in vmw_cotable_unscrub()
185 struct ttm_buffer_object *bo = &res->guest_memory_bo->tbo; in vmw_cotable_unscrub()
191 WARN_ON_ONCE(bo->resource->mem_type != VMW_PL_MOB); in vmw_cotable_unscrub()
192 dma_resv_assert_held(bo->base.resv); in vmw_cotable_unscrub()
196 return -ENOMEM; in vmw_cotable_unscrub()
198 WARN_ON(vcotbl->ctx->id == SVGA3D_INVALID_ID); in vmw_cotable_unscrub()
199 WARN_ON(bo->resource->mem_type != VMW_PL_MOB); in vmw_cotable_unscrub()
200 cmd->header.id = SVGA_3D_CMD_DX_SET_COTABLE; in vmw_cotable_unscrub()
201 cmd->header.size = sizeof(cmd->body); in vmw_cotable_unscrub()
202 cmd->body.cid = vcotbl->ctx->id; in vmw_cotable_unscrub()
203 cmd->body.type = vcotbl->type; in vmw_cotable_unscrub()
204 cmd->body.mobid = bo->resource->start; in vmw_cotable_unscrub()
205 cmd->body.validSizeInBytes = vcotbl->size_read_back; in vmw_cotable_unscrub()
208 vcotbl->scrubbed = false; in vmw_cotable_unscrub()
214 * vmw_cotable_bind - Undo a cotable unscrub operation
216 * @res: Pointer to the cotable resource
227 * The create() callback may have changed @res->backup without in vmw_cotable_bind()
228 * the caller noticing, and with val_buf->bo still pointing to in vmw_cotable_bind()
233 val_buf->bo = &res->guest_memory_bo->tbo; in vmw_cotable_bind()
239 * vmw_cotable_scrub - Scrub the cotable from the device.
241 * @res: Pointer to the cotable resource.
254 * resource destruction, vmw_cotable_unbind() must be called.
259 struct vmw_private *dev_priv = res->dev_priv; in vmw_cotable_scrub()
271 if (vcotbl->scrubbed) in vmw_cotable_scrub()
274 if (co_info[vcotbl->type].unbind_func) in vmw_cotable_scrub()
275 co_info[vcotbl->type].unbind_func(dev_priv, in vmw_cotable_scrub()
276 &vcotbl->resource_list, in vmw_cotable_scrub()
284 return -ENOMEM; in vmw_cotable_scrub()
286 vcotbl->size_read_back = 0; in vmw_cotable_scrub()
289 cmd0->header.id = SVGA_3D_CMD_DX_READBACK_COTABLE; in vmw_cotable_scrub()
290 cmd0->header.size = sizeof(cmd0->body); in vmw_cotable_scrub()
291 cmd0->body.cid = vcotbl->ctx->id; in vmw_cotable_scrub()
292 cmd0->body.type = vcotbl->type; in vmw_cotable_scrub()
294 vcotbl->size_read_back = res->guest_memory_size; in vmw_cotable_scrub()
296 cmd1->header.id = SVGA_3D_CMD_DX_SET_COTABLE; in vmw_cotable_scrub()
297 cmd1->header.size = sizeof(cmd1->body); in vmw_cotable_scrub()
298 cmd1->body.cid = vcotbl->ctx->id; in vmw_cotable_scrub()
299 cmd1->body.type = vcotbl->type; in vmw_cotable_scrub()
300 cmd1->body.mobid = SVGA3D_INVALID_ID; in vmw_cotable_scrub()
301 cmd1->body.validSizeInBytes = 0; in vmw_cotable_scrub()
303 vcotbl->scrubbed = true; in vmw_cotable_scrub()
306 res->id = -1; in vmw_cotable_scrub()
312 * vmw_cotable_unbind - Cotable resource unbind callback
314 * @res: Pointer to the cotable resource.
326 struct vmw_private *dev_priv = res->dev_priv; in vmw_cotable_unbind()
327 struct ttm_buffer_object *bo = val_buf->bo; in vmw_cotable_unbind()
333 WARN_ON_ONCE(bo->resource->mem_type != VMW_PL_MOB); in vmw_cotable_unbind()
334 dma_resv_assert_held(bo->base.resv); in vmw_cotable_unbind()
336 mutex_lock(&dev_priv->binding_mutex); in vmw_cotable_unbind()
337 if (!vcotbl->scrubbed) in vmw_cotable_unbind()
338 vmw_dx_context_scrub_cotables(vcotbl->ctx, readback); in vmw_cotable_unbind()
339 mutex_unlock(&dev_priv->binding_mutex); in vmw_cotable_unbind()
349 * vmw_cotable_readback - Read back a cotable without unbinding.
351 * @res: The cotable resource.
359 struct vmw_private *dev_priv = res->dev_priv; in vmw_cotable_readback()
367 if (!vcotbl->scrubbed) { in vmw_cotable_readback()
370 return -ENOMEM; in vmw_cotable_readback()
372 cmd->header.id = SVGA_3D_CMD_DX_READBACK_COTABLE; in vmw_cotable_readback()
373 cmd->header.size = sizeof(cmd->body); in vmw_cotable_readback()
374 cmd->body.cid = vcotbl->ctx->id; in vmw_cotable_readback()
375 cmd->body.type = vcotbl->type; in vmw_cotable_readback()
376 vcotbl->size_read_back = res->guest_memory_size; in vmw_cotable_readback()
381 vmw_bo_fence_single(&res->guest_memory_bo->tbo, fence); in vmw_cotable_readback()
388 * vmw_cotable_resize - Resize a cotable.
390 * @res: The cotable resource.
402 struct vmw_private *dev_priv = res->dev_priv; in vmw_cotable_resize()
404 struct vmw_bo *buf, *old_buf = res->guest_memory_bo; in vmw_cotable_resize()
405 struct ttm_buffer_object *bo, *old_bo = &res->guest_memory_bo->tbo; in vmw_cotable_resize()
406 size_t old_size = res->guest_memory_size; in vmw_cotable_resize()
407 size_t old_size_read_back = vcotbl->size_read_back; in vmw_cotable_resize()
427 cur_size_read_back = vcotbl->size_read_back; in vmw_cotable_resize()
428 vcotbl->size_read_back = old_size_read_back; in vmw_cotable_resize()
441 bo = &buf->tbo; in vmw_cotable_resize()
454 for (i = 0; i < PFN_UP(old_bo->resource->size); ++i) { in vmw_cotable_resize()
478 ret = ttm_bo_validate(bo, &buf->placement, &ctx); in vmw_cotable_resize()
485 res->guest_memory_bo = buf; in vmw_cotable_resize()
486 res->guest_memory_size = new_size; in vmw_cotable_resize()
487 vcotbl->size_read_back = cur_size_read_back; in vmw_cotable_resize()
496 res->guest_memory_bo = old_buf; in vmw_cotable_resize()
497 res->guest_memory_size = old_size; in vmw_cotable_resize()
498 vcotbl->size_read_back = old_size_read_back; in vmw_cotable_resize()
506 res->id = vcotbl->type; in vmw_cotable_resize()
508 ret = dma_resv_reserve_fences(bo->base.resv, 1); in vmw_cotable_resize()
533 * vmw_cotable_create - Cotable resource create callback
535 * @res: Pointer to a cotable resource.
547 size_t new_size = res->guest_memory_size; in vmw_cotable_create()
552 needed_size = (vcotbl->seen_entries + 1) * co_info[vcotbl->type].size; in vmw_cotable_create()
556 if (likely(new_size <= res->guest_memory_size)) { in vmw_cotable_create()
557 if (vcotbl->scrubbed && vmw_resource_mob_attached(res)) { in vmw_cotable_create()
562 res->id = vcotbl->type; in vmw_cotable_create()
570 * vmw_hw_cotable_destroy - Cotable hw_destroy callback
572 * @res: Pointer to a cotable resource.
574 * The final (part of resource destruction) destroy callback.
582 * vmw_cotable_free - Cotable resource destructor
584 * @res: Pointer to a cotable resource.
592 * vmw_cotable_alloc - Create a cotable resource
595 * @ctx: Pointer to the context resource.
596 * The cotable resource will not add a refcount.
609 ret = -ENOMEM; in vmw_cotable_alloc()
613 ret = vmw_resource_init(dev_priv, &vcotbl->res, true, in vmw_cotable_alloc()
618 INIT_LIST_HEAD(&vcotbl->resource_list); in vmw_cotable_alloc()
619 vcotbl->res.id = type; in vmw_cotable_alloc()
620 vcotbl->res.guest_memory_size = PAGE_SIZE; in vmw_cotable_alloc()
623 vcotbl->res.guest_memory_size = co_info[type].min_initial_entries * in vmw_cotable_alloc()
625 vcotbl->res.guest_memory_size = PFN_ALIGN(vcotbl->res.guest_memory_size); in vmw_cotable_alloc()
628 vcotbl->scrubbed = true; in vmw_cotable_alloc()
629 vcotbl->seen_entries = -1; in vmw_cotable_alloc()
630 vcotbl->type = type; in vmw_cotable_alloc()
631 vcotbl->ctx = ctx; in vmw_cotable_alloc()
633 vcotbl->res.hw_destroy = vmw_hw_cotable_destroy; in vmw_cotable_alloc()
635 return &vcotbl->res; in vmw_cotable_alloc()
644 * vmw_cotable_notify - Notify the cotable about an item creation
646 * @res: Pointer to a cotable resource.
647 * @id: Item id.
649 int vmw_cotable_notify(struct vmw_resource *res, int id) in vmw_cotable_notify() argument
653 if (id < 0 || id >= SVGA_COTABLE_MAX_IDS) { in vmw_cotable_notify()
654 DRM_ERROR("Illegal COTable id. Type is %u. Id is %d\n", in vmw_cotable_notify()
655 (unsigned) vcotbl->type, id); in vmw_cotable_notify()
656 return -EINVAL; in vmw_cotable_notify()
659 if (vcotbl->seen_entries < id) { in vmw_cotable_notify()
661 res->id = -1; in vmw_cotable_notify()
662 vcotbl->seen_entries = id; in vmw_cotable_notify()
669 * vmw_cotable_add_resource - add a view to the cotable's list of active views.
672 * @head: pointer to the struct list_head member of the resource, dedicated
673 * to the cotable active resource list.
680 list_add_tail(head, &vcotbl->resource_list); in vmw_cotable_add_resource()