Lines Matching refs:res

39  * @res: The resource
41 void vmw_resource_mob_attach(struct vmw_resource *res)
43 struct vmw_bo *gbo = res->guest_memory_bo;
47 res->used_prio = (res->res_dirty) ? res->func->dirty_prio :
48 res->func->prio;
55 new = (res->guest_memory_offset < this->guest_memory_offset) ?
59 rb_link_node(&res->mob_node, parent, new);
60 rb_insert_color(&res->mob_node, &gbo->res_tree);
62 vmw_bo_prio_add(gbo, res->used_prio);
67 * @res: The resource
69 void vmw_resource_mob_detach(struct vmw_resource *res)
71 struct vmw_bo *gbo = res->guest_memory_bo;
74 if (vmw_resource_mob_attached(res)) {
75 rb_erase(&res->mob_node, &gbo->res_tree);
76 RB_CLEAR_NODE(&res->mob_node);
77 vmw_bo_prio_del(gbo, res->used_prio);
81 struct vmw_resource *vmw_resource_reference(struct vmw_resource *res)
83 kref_get(&res->kref);
84 return res;
88 vmw_resource_reference_unless_doomed(struct vmw_resource *res)
90 return kref_get_unless_zero(&res->kref) ? res : NULL;
96 * @res: Pointer to the resource.
100 void vmw_resource_release_id(struct vmw_resource *res)
102 struct vmw_private *dev_priv = res->dev_priv;
103 struct idr *idr = &dev_priv->res_idr[res->func->res_type];
106 if (res->id != -1)
107 idr_remove(idr, res->id);
108 res->id = -1;
114 struct vmw_resource *res =
116 struct vmw_private *dev_priv = res->dev_priv;
119 struct idr *idr = &dev_priv->res_idr[res->func->res_type];
122 list_del_init(&res->lru_head);
124 if (res->guest_memory_bo) {
125 struct ttm_buffer_object *bo = &res->guest_memory_bo->tbo;
129 if (vmw_resource_mob_attached(res) &&
130 res->func->unbind != NULL) {
135 res->func->unbind(res, false, &val_buf);
137 res->guest_memory_size = false;
138 vmw_resource_mob_detach(res);
139 if (res->dirty)
140 res->func->dirty_free(res);
141 if (res->coherent)
142 vmw_bo_dirty_release(res->guest_memory_bo);
144 vmw_user_bo_unref(&res->guest_memory_bo);
147 if (likely(res->hw_destroy != NULL)) {
149 vmw_binding_res_list_kill(&res->binding_head);
151 res->hw_destroy(res);
154 id = res->id;
155 if (res->res_free != NULL)
156 res->res_free(res);
158 kfree(res);
168 struct vmw_resource *res = *p_res;
171 kref_put(&res->kref, vmw_resource_release);
178 * @res: Pointer to the resource.
181 * @res->id to that id. Returns 0 on success and -ENOMEM on failure.
183 int vmw_resource_alloc_id(struct vmw_resource *res)
185 struct vmw_private *dev_priv = res->dev_priv;
187 struct idr *idr = &dev_priv->res_idr[res->func->res_type];
189 BUG_ON(res->id != -1);
194 ret = idr_alloc(idr, res, 1, 0, GFP_NOWAIT);
196 res->id = ret;
207 * @res: The struct vmw_resource to initialize.
213 int vmw_resource_init(struct vmw_private *dev_priv, struct vmw_resource *res,
215 void (*res_free) (struct vmw_resource *res),
218 kref_init(&res->kref);
219 res->hw_destroy = NULL;
220 res->res_free = res_free;
221 res->dev_priv = dev_priv;
222 res->func = func;
223 RB_CLEAR_NODE(&res->mob_node);
224 INIT_LIST_HEAD(&res->lru_head);
225 INIT_LIST_HEAD(&res->binding_head);
226 res->id = -1;
227 res->guest_memory_bo = NULL;
228 res->guest_memory_offset = 0;
229 res->guest_memory_dirty = false;
230 res->res_dirty = false;
231 res->coherent = false;
232 res->used_prio = 3;
233 res->dirty = NULL;
237 return vmw_resource_alloc_id(res);
263 struct vmw_resource *res;
273 res = converter->base_obj_to_res(base);
274 kref_get(&res->kref);
276 *p_res = res;
297 struct vmw_resource *res;
304 &res);
306 *out_surf = vmw_res_to_srf(res);
318 * @res: The resource for which to allocate a gbo buffer.
322 static int vmw_resource_buf_alloc(struct vmw_resource *res,
325 unsigned long size = PFN_ALIGN(res->guest_memory_size);
328 .domain = res->func->domain,
329 .busy_domain = res->func->busy_domain,
331 .size = res->guest_memory_size,
336 if (likely(res->guest_memory_bo)) {
337 BUG_ON(res->guest_memory_bo->tbo.base.size < size);
341 ret = vmw_gem_object_create(res->dev_priv, &bo_params, &gbo);
345 res->guest_memory_bo = gbo;
355 * @res: The resource to make visible to the device.
363 static int vmw_resource_do_validate(struct vmw_resource *res,
368 const struct vmw_res_func *func = res->func;
370 if (unlikely(res->id == -1)) {
371 ret = func->create(res);
377 ((func->needs_guest_memory && !vmw_resource_mob_attached(res) &&
380 ret = func->bind(res, val_buf);
384 vmw_resource_mob_attach(res);
391 if (func->dirty_alloc && vmw_resource_mob_attached(res) &&
392 !res->coherent) {
393 if (res->guest_memory_bo->dirty && !res->dirty) {
394 ret = func->dirty_alloc(res);
397 } else if (!res->guest_memory_bo->dirty && res->dirty) {
398 func->dirty_free(res);
406 if (res->dirty) {
407 if (dirtying && !res->res_dirty) {
408 pgoff_t start = res->guest_memory_offset >> PAGE_SHIFT;
410 (res->guest_memory_offset + res->guest_memory_size,
413 vmw_bo_dirty_unmap(res->guest_memory_bo, start, end);
416 vmw_bo_dirty_transfer_to_res(res);
417 return func->dirty_sync(res);
423 func->destroy(res);
432 * @res: Pointer to the struct vmw_resource to unreserve.
443 void vmw_resource_unreserve(struct vmw_resource *res,
450 struct vmw_private *dev_priv = res->dev_priv;
452 if (!list_empty(&res->lru_head))
455 if (switch_guest_memory && new_guest_memory_bo != res->guest_memory_bo) {
456 if (res->guest_memory_bo) {
457 vmw_resource_mob_detach(res);
458 if (res->coherent)
459 vmw_bo_dirty_release(res->guest_memory_bo);
460 vmw_user_bo_unref(&res->guest_memory_bo);
464 res->guest_memory_bo = vmw_user_bo_ref(new_guest_memory_bo);
470 WARN_ON(res->coherent && !new_guest_memory_bo->dirty);
472 vmw_resource_mob_attach(res);
474 res->guest_memory_bo = NULL;
476 } else if (switch_guest_memory && res->coherent) {
477 vmw_bo_dirty_release(res->guest_memory_bo);
481 res->guest_memory_offset = new_guest_memory_offset;
484 res->res_dirty = dirty;
486 if (!res->func->may_evict || res->id == -1 || res->pin_count)
490 list_add_tail(&res->lru_head,
491 &res->dev_priv->res_lru[res->func->res_type]);
501 * @res: The resource for which to allocate a backup buffer.
509 struct vmw_resource *res,
518 if (unlikely(!res->guest_memory_bo)) {
519 ret = vmw_resource_buf_alloc(res, interruptible);
525 ttm_bo_get(&res->guest_memory_bo->tbo);
526 val_buf->bo = &res->guest_memory_bo->tbo;
533 if (res->func->needs_guest_memory && !vmw_resource_mob_attached(res))
536 guest_memory_dirty = res->guest_memory_dirty;
537 vmw_bo_placement_set(res->guest_memory_bo, res->func->domain,
538 res->func->busy_domain);
539 ret = ttm_bo_validate(&res->guest_memory_bo->tbo,
540 &res->guest_memory_bo->placement,
554 vmw_user_bo_unref(&res->guest_memory_bo);
562 * @res: The resource to reserve.
570 int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
573 struct vmw_private *dev_priv = res->dev_priv;
577 list_del_init(&res->lru_head);
580 if (res->func->needs_guest_memory && !res->guest_memory_bo &&
582 ret = vmw_resource_buf_alloc(res, interruptible);
586 (unsigned long) res->guest_memory_size);
622 * @res: The resource to evict.
626 struct vmw_resource *res, bool interruptible)
629 const struct vmw_res_func *func = res->func;
636 ret = vmw_resource_check_buffer(ticket, res, interruptible, &val_buf);
641 (!func->needs_guest_memory || vmw_resource_mob_attached(res)))) {
642 ret = func->unbind(res, res->res_dirty, &val_buf);
645 vmw_resource_mob_detach(res);
647 ret = func->destroy(res);
648 res->guest_memory_dirty = true;
649 res->res_dirty = false;
660 * @res: The resource to make visible to the device.
664 * On successful return, any backup DMA buffer pointed to by @res->backup will
672 int vmw_resource_validate(struct vmw_resource *res, bool intr,
677 struct vmw_private *dev_priv = res->dev_priv;
678 struct list_head *lru_list = &dev_priv->res_lru[res->func->res_type];
682 if (!res->func->create)
687 if (res->guest_memory_bo)
688 val_buf.bo = &res->guest_memory_bo->tbo;
690 ret = vmw_resource_do_validate(res, &val_buf, dirtying);
695 if (list_empty(lru_list) || !res->func->may_evict) {
697 "for %s.\n", res->func->type_name);
728 else if (!res->func->needs_guest_memory && res->guest_memory_bo) {
729 WARN_ON_ONCE(vmw_resource_mob_attached(res));
730 vmw_user_bo_unref(&res->guest_memory_bo);
761 struct vmw_resource *res =
764 if (!WARN_ON_ONCE(!res->func->unbind))
765 (void) res->func->unbind(res, res->res_dirty, &val_buf);
767 res->guest_memory_size = true;
768 res->res_dirty = false;
769 vmw_resource_mob_detach(res);
869 * @res: The resource being queried.
871 bool vmw_resource_needs_backup(const struct vmw_resource *res)
873 return res->func->needs_guest_memory;
950 * @res: The resource to add a pin reference on
957 int vmw_resource_pin(struct vmw_resource *res, bool interruptible)
960 struct vmw_private *dev_priv = res->dev_priv;
964 ret = vmw_resource_reserve(res, interruptible, false);
968 if (res->pin_count == 0) {
971 if (res->guest_memory_bo) {
972 vbo = res->guest_memory_bo;
979 res->func->domain,
980 res->func->busy_domain);
994 ret = vmw_resource_validate(res, interruptible, true);
1000 res->pin_count++;
1003 vmw_resource_unreserve(res, false, false, false, NULL, 0UL);
1013 * @res: The resource to remove a pin reference from
1018 void vmw_resource_unpin(struct vmw_resource *res)
1020 struct vmw_private *dev_priv = res->dev_priv;
1025 ret = vmw_resource_reserve(res, false, true);
1028 WARN_ON(res->pin_count == 0);
1029 if (--res->pin_count == 0 && res->guest_memory_bo) {
1030 struct vmw_bo *vbo = res->guest_memory_bo;
1037 vmw_resource_unreserve(res, false, false, false, NULL, 0UL);
1045 * @res: Pointer to the resource
1047 enum vmw_res_type vmw_res_type(const struct vmw_resource *res)
1049 return res->func->res_type;
1055 * @res: The resource.
1059 void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
1062 if (res->dirty)
1063 res->func->dirty_range_add(res, start << PAGE_SHIFT,