int ttm_pl_reference_ioctl(struct ttm_object_file *tfile, void *data) { union ttm_pl_reference_arg *arg = data; struct ttm_pl_rep *rep = &arg->rep; struct ttm_bo_user_object *user_bo; struct ttm_buffer_object *bo; struct ttm_base_object *base; int ret; user_bo = ttm_bo_user_lookup(tfile, arg->req.handle); if (unlikely(user_bo == NULL)) { printk(KERN_ERR "Could not reference buffer object.\n"); return -EINVAL; } bo = &user_bo->bo; ret = ttm_ref_object_add(tfile, &user_bo->base, TTM_REF_USAGE, NULL); if (unlikely(ret != 0)) { printk(KERN_ERR "Could not add a reference to buffer object.\n"); goto out; } ret = ttm_bo_reserve(bo, true, false, false, 0); if (unlikely(ret != 0)) goto out; ttm_pl_fill_rep(bo, rep); ttm_bo_unreserve(bo); out: base = &user_bo->base; ttm_base_object_unref(&base); return ret; }
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; }
int ttm_base_object_init(struct ttm_object_file *tfile, struct ttm_base_object *base, bool shareable, enum ttm_object_type object_type, void (*rcount_release) (struct ttm_base_object **), void (*ref_obj_release) (struct ttm_base_object *, enum ttm_ref_type ref_type)) { struct ttm_object_device *tdev = tfile->tdev; int ret; base->shareable = shareable; base->tfile = ttm_object_file_ref(tfile); base->refcount_release = rcount_release; base->ref_obj_release = ref_obj_release; base->object_type = object_type; refcount_init(&base->refcount, 1); rw_init(&tdev->object_lock, "ttmbao"); rw_wlock(&tdev->object_lock); ret = drm_ht_just_insert_please(&tdev->object_hash, &base->hash, (unsigned long)base, 31, 0, 0); rw_wunlock(&tdev->object_lock); if (unlikely(ret != 0)) goto out_err0; ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL); if (unlikely(ret != 0)) goto out_err1; ttm_base_object_unref(&base); return 0; out_err1: rw_wlock(&tdev->object_lock); (void)drm_ht_remove_item(&tdev->object_hash, &base->hash); rw_wunlock(&tdev->object_lock); out_err0: return ret; }