static void ttm_bo_user_ref_release(struct ttm_base_object *base, enum ttm_ref_type ref_type) { struct ttm_bo_user_object *user_bo = container_of(base, struct ttm_bo_user_object, base); struct ttm_buffer_object *bo = &user_bo->bo; switch (ref_type) { case TTM_REF_SYNCCPU_WRITE: ttm_bo_synccpu_write_release(bo); break; default: BUG(); } }
int ttm_pl_synccpu_ioctl(struct ttm_object_file *tfile, void *data) { struct ttm_pl_synccpu_arg *arg = data; struct ttm_bo_user_object *user_bo; struct ttm_buffer_object *bo; struct ttm_base_object *base; bool existed; int ret; switch (arg->op) { case TTM_PL_SYNCCPU_OP_GRAB: user_bo = ttm_bo_user_lookup(tfile, arg->handle); if (unlikely(user_bo == NULL)) { printk(KERN_ERR "Could not find buffer object for synccpu.\n"); return -EINVAL; } bo = &user_bo->bo; base = &user_bo->base; ret = ttm_bo_synccpu_write_grab(bo, arg->access_mode & TTM_PL_SYNCCPU_MODE_NO_BLOCK); if (unlikely(ret != 0)) { ttm_base_object_unref(&base); goto out; } ret = ttm_ref_object_add(tfile, &user_bo->base, TTM_REF_SYNCCPU_WRITE, &existed); if (existed || ret != 0) ttm_bo_synccpu_write_release(bo); ttm_base_object_unref(&base); break; case TTM_PL_SYNCCPU_OP_RELEASE: ret = ttm_ref_object_base_unref(tfile, arg->handle, TTM_REF_SYNCCPU_WRITE); break; default: ret = -EINVAL; break; } out: return ret; }
void nouveau_gem_object_del(struct drm_gem_object *gem) { struct nouveau_bo *nvbo = gem->driver_private; struct ttm_buffer_object *bo = &nvbo->bo; if (!nvbo) return; nvbo->gem = NULL; if (unlikely(nvbo->cpu_filp)) ttm_bo_synccpu_write_release(bo); if (unlikely(nvbo->pin_refcnt)) { nvbo->pin_refcnt = 1; nouveau_bo_unpin(nvbo); } ttm_bo_unref(&bo); drm_gem_object_release(gem); kfree(gem); }