2 * Copyright (C) 2008 Ben Skeggs.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nouveau_drm.h"
28 #include "nouveau_dma.h"
29 #include "nouveau_fence.h"
30 #include "nouveau_abi16.h"
32 #include "nouveau_ttm.h"
33 #include "nouveau_gem.h"
36 nouveau_gem_object_del(struct drm_gem_object *gem)
38 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
39 struct ttm_buffer_object *bo = &nvbo->bo;
41 if (gem->import_attach)
42 drm_prime_gem_destroy(gem, nvbo->bo.sg);
44 drm_gem_object_release(gem);
46 /* reset filp so nouveau_bo_del_ttm() can test for it */
52 nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
54 struct nouveau_cli *cli = nouveau_cli(file_priv);
55 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
56 struct nouveau_vma *vma;
62 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, NULL);
66 vma = nouveau_bo_vma_find(nvbo, cli->vm);
68 vma = kzalloc(sizeof(*vma), GFP_KERNEL);
74 ret = nouveau_bo_vma_add(nvbo, cli->vm, vma);
84 ttm_bo_unreserve(&nvbo->bo);
89 nouveau_gem_object_delete(void *data)
91 struct nouveau_vma *vma = data;
92 nouveau_vm_unmap(vma);
98 nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nouveau_vma *vma)
100 const bool mapped = nvbo->bo.mem.mem_type != TTM_PL_SYSTEM;
101 struct reservation_object *resv = nvbo->bo.resv;
102 struct reservation_object_list *fobj;
103 struct fence *fence = NULL;
105 fobj = reservation_object_get_list(resv);
107 list_del(&vma->head);
109 if (fobj && fobj->shared_count > 1)
110 ttm_bo_wait(&nvbo->bo, true, false, false);
111 else if (fobj && fobj->shared_count == 1)
112 fence = rcu_dereference_protected(fobj->shared[0],
113 reservation_object_held(resv));
115 fence = reservation_object_get_excl(nvbo->bo.resv);
117 if (fence && mapped) {
118 nouveau_fence_work(fence, nouveau_gem_object_delete, vma);
121 nouveau_vm_unmap(vma);
128 nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
130 struct nouveau_cli *cli = nouveau_cli(file_priv);
131 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
132 struct nouveau_vma *vma;
138 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, NULL);
142 vma = nouveau_bo_vma_find(nvbo, cli->vm);
144 if (--vma->refcount == 0)
145 nouveau_gem_object_unmap(nvbo, vma);
147 ttm_bo_unreserve(&nvbo->bo);
151 nouveau_gem_new(struct drm_device *dev, int size, int align, uint32_t domain,
152 uint32_t tile_mode, uint32_t tile_flags,
153 struct nouveau_bo **pnvbo)
155 struct nouveau_drm *drm = nouveau_drm(dev);
156 struct nouveau_bo *nvbo;
160 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
161 flags |= TTM_PL_FLAG_VRAM;
162 if (domain & NOUVEAU_GEM_DOMAIN_GART)
163 flags |= TTM_PL_FLAG_TT;
164 if (!flags || domain & NOUVEAU_GEM_DOMAIN_CPU)
165 flags |= TTM_PL_FLAG_SYSTEM;
167 ret = nouveau_bo_new(dev, size, align, flags, tile_mode,
168 tile_flags, NULL, NULL, pnvbo);
173 /* we restrict allowed domains on nv50+ to only the types
174 * that were requested at creation time. not possibly on
175 * earlier chips without busting the ABI.
177 nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM |
178 NOUVEAU_GEM_DOMAIN_GART;
179 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
180 nvbo->valid_domains &= domain;
182 /* Initialize the embedded gem-object. We return a single gem-reference
183 * to the caller, instead of a normal nouveau_bo ttm reference. */
184 ret = drm_gem_object_init(dev, &nvbo->gem, nvbo->bo.mem.size);
186 nouveau_bo_ref(NULL, pnvbo);
190 nvbo->bo.persistent_swap_storage = nvbo->gem.filp;
195 nouveau_gem_info(struct drm_file *file_priv, struct drm_gem_object *gem,
196 struct drm_nouveau_gem_info *rep)
198 struct nouveau_cli *cli = nouveau_cli(file_priv);
199 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
200 struct nouveau_vma *vma;
202 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
203 rep->domain = NOUVEAU_GEM_DOMAIN_GART;
205 rep->domain = NOUVEAU_GEM_DOMAIN_VRAM;
207 rep->offset = nvbo->bo.offset;
209 vma = nouveau_bo_vma_find(nvbo, cli->vm);
213 rep->offset = vma->offset;
216 rep->size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
217 rep->map_handle = drm_vma_node_offset_addr(&nvbo->bo.vma_node);
218 rep->tile_mode = nvbo->tile_mode;
219 rep->tile_flags = nvbo->tile_flags;
224 nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
225 struct drm_file *file_priv)
227 struct nouveau_drm *drm = nouveau_drm(dev);
228 struct nouveau_cli *cli = nouveau_cli(file_priv);
229 struct nouveau_fb *pfb = nvkm_fb(&drm->device);
230 struct drm_nouveau_gem_new *req = data;
231 struct nouveau_bo *nvbo = NULL;
234 if (!pfb->memtype_valid(pfb, req->info.tile_flags)) {
235 NV_PRINTK(error, cli, "bad page flags: 0x%08x\n", req->info.tile_flags);
239 ret = nouveau_gem_new(dev, req->info.size, req->align,
240 req->info.domain, req->info.tile_mode,
241 req->info.tile_flags, &nvbo);
245 ret = drm_gem_handle_create(file_priv, &nvbo->gem, &req->info.handle);
247 ret = nouveau_gem_info(file_priv, &nvbo->gem, &req->info);
249 drm_gem_handle_delete(file_priv, req->info.handle);
252 /* drop reference from allocate - handle holds it now */
253 drm_gem_object_unreference_unlocked(&nvbo->gem);
258 nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains,
259 uint32_t write_domains, uint32_t valid_domains)
261 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
262 struct ttm_buffer_object *bo = &nvbo->bo;
263 uint32_t domains = valid_domains & nvbo->valid_domains &
264 (write_domains ? write_domains : read_domains);
265 uint32_t pref_flags = 0, valid_flags = 0;
270 if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
271 valid_flags |= TTM_PL_FLAG_VRAM;
273 if (valid_domains & NOUVEAU_GEM_DOMAIN_GART)
274 valid_flags |= TTM_PL_FLAG_TT;
276 if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
277 bo->mem.mem_type == TTM_PL_VRAM)
278 pref_flags |= TTM_PL_FLAG_VRAM;
280 else if ((domains & NOUVEAU_GEM_DOMAIN_GART) &&
281 bo->mem.mem_type == TTM_PL_TT)
282 pref_flags |= TTM_PL_FLAG_TT;
284 else if (domains & NOUVEAU_GEM_DOMAIN_VRAM)
285 pref_flags |= TTM_PL_FLAG_VRAM;
288 pref_flags |= TTM_PL_FLAG_TT;
290 nouveau_bo_placement_set(nvbo, pref_flags, valid_flags);
296 struct list_head list;
297 struct ww_acquire_ctx ticket;
301 validate_fini_no_ticket(struct validate_op *op, struct nouveau_fence *fence,
302 struct drm_nouveau_gem_pushbuf_bo *pbbo)
304 struct nouveau_bo *nvbo;
305 struct drm_nouveau_gem_pushbuf_bo *b;
307 while (!list_empty(&op->list)) {
308 nvbo = list_entry(op->list.next, struct nouveau_bo, entry);
309 b = &pbbo[nvbo->pbbo_index];
312 nouveau_bo_fence(nvbo, fence, !!b->write_domains);
314 if (unlikely(nvbo->validate_mapped)) {
315 ttm_bo_kunmap(&nvbo->kmap);
316 nvbo->validate_mapped = false;
319 list_del(&nvbo->entry);
320 nvbo->reserved_by = NULL;
321 ttm_bo_unreserve_ticket(&nvbo->bo, &op->ticket);
322 drm_gem_object_unreference_unlocked(&nvbo->gem);
327 validate_fini(struct validate_op *op, struct nouveau_fence *fence,
328 struct drm_nouveau_gem_pushbuf_bo *pbbo)
330 validate_fini_no_ticket(op, fence, pbbo);
331 ww_acquire_fini(&op->ticket);
335 validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
336 struct drm_nouveau_gem_pushbuf_bo *pbbo,
337 int nr_buffers, struct validate_op *op)
339 struct nouveau_cli *cli = nouveau_cli(file_priv);
340 struct drm_device *dev = chan->drm->dev;
343 struct nouveau_bo *res_bo = NULL;
344 LIST_HEAD(gart_list);
345 LIST_HEAD(vram_list);
346 LIST_HEAD(both_list);
348 ww_acquire_init(&op->ticket, &reservation_ww_class);
350 if (++trycnt > 100000) {
351 NV_PRINTK(error, cli, "%s failed and gave up.\n", __func__);
355 for (i = 0; i < nr_buffers; i++) {
356 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i];
357 struct drm_gem_object *gem;
358 struct nouveau_bo *nvbo;
360 gem = drm_gem_object_lookup(dev, file_priv, b->handle);
362 NV_PRINTK(error, cli, "Unknown handle 0x%08x\n", b->handle);
366 nvbo = nouveau_gem_object(gem);
367 if (nvbo == res_bo) {
369 drm_gem_object_unreference_unlocked(gem);
373 if (nvbo->reserved_by && nvbo->reserved_by == file_priv) {
374 NV_PRINTK(error, cli, "multiple instances of buffer %d on "
375 "validation list\n", b->handle);
376 drm_gem_object_unreference_unlocked(gem);
381 ret = ttm_bo_reserve(&nvbo->bo, true, false, true, &op->ticket);
383 list_splice_tail_init(&vram_list, &op->list);
384 list_splice_tail_init(&gart_list, &op->list);
385 list_splice_tail_init(&both_list, &op->list);
386 validate_fini_no_ticket(op, NULL, NULL);
387 if (unlikely(ret == -EDEADLK)) {
388 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
394 if (ret != -ERESTARTSYS)
395 NV_PRINTK(error, cli, "fail reserve\n");
400 b->user_priv = (uint64_t)(unsigned long)nvbo;
401 nvbo->reserved_by = file_priv;
402 nvbo->pbbo_index = i;
403 if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
404 (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART))
405 list_add_tail(&nvbo->entry, &both_list);
407 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
408 list_add_tail(&nvbo->entry, &vram_list);
410 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)
411 list_add_tail(&nvbo->entry, &gart_list);
413 NV_PRINTK(error, cli, "invalid valid domains: 0x%08x\n",
415 list_add_tail(&nvbo->entry, &both_list);
423 ww_acquire_done(&op->ticket);
424 list_splice_tail(&vram_list, &op->list);
425 list_splice_tail(&gart_list, &op->list);
426 list_splice_tail(&both_list, &op->list);
428 validate_fini(op, NULL, NULL);
434 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
435 struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
436 uint64_t user_pbbo_ptr)
438 struct nouveau_drm *drm = chan->drm;
439 struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
440 (void __force __user *)(uintptr_t)user_pbbo_ptr;
441 struct nouveau_bo *nvbo;
444 list_for_each_entry(nvbo, list, entry) {
445 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index];
447 ret = nouveau_gem_set_domain(&nvbo->gem, b->read_domains,
451 NV_PRINTK(error, cli, "fail set_domain\n");
455 ret = nouveau_bo_validate(nvbo, true, false);
457 if (ret != -ERESTARTSYS)
458 NV_PRINTK(error, cli, "fail ttm_validate\n");
462 ret = nouveau_fence_sync(nvbo, chan, !!b->write_domains, true);
464 if (ret != -ERESTARTSYS)
465 NV_PRINTK(error, cli, "fail post-validate sync\n");
469 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
470 if (nvbo->bo.offset == b->presumed.offset &&
471 ((nvbo->bo.mem.mem_type == TTM_PL_VRAM &&
472 b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) ||
473 (nvbo->bo.mem.mem_type == TTM_PL_TT &&
474 b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART)))
477 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
478 b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART;
480 b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM;
481 b->presumed.offset = nvbo->bo.offset;
482 b->presumed.valid = 0;
485 if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
486 &b->presumed, sizeof(b->presumed)))
495 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
496 struct drm_file *file_priv,
497 struct drm_nouveau_gem_pushbuf_bo *pbbo,
498 uint64_t user_buffers, int nr_buffers,
499 struct validate_op *op, int *apply_relocs)
501 struct nouveau_cli *cli = nouveau_cli(file_priv);
504 INIT_LIST_HEAD(&op->list);
509 ret = validate_init(chan, file_priv, pbbo, nr_buffers, op);
511 if (ret != -ERESTARTSYS)
512 NV_PRINTK(error, cli, "validate_init\n");
516 ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
517 if (unlikely(ret < 0)) {
518 if (ret != -ERESTARTSYS)
519 NV_PRINTK(error, cli, "validating bo list\n");
520 validate_fini(op, NULL, NULL);
530 if (!is_vmalloc_addr(addr))
537 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
540 void __user *userptr = (void __force __user *)(uintptr_t)user;
544 mem = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
548 return ERR_PTR(-ENOMEM);
550 if (copy_from_user(mem, userptr, size)) {
552 return ERR_PTR(-EFAULT);
559 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
560 struct drm_nouveau_gem_pushbuf *req,
561 struct drm_nouveau_gem_pushbuf_bo *bo)
563 struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
567 reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
569 return PTR_ERR(reloc);
571 for (i = 0; i < req->nr_relocs; i++) {
572 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
573 struct drm_nouveau_gem_pushbuf_bo *b;
574 struct nouveau_bo *nvbo;
577 if (unlikely(r->bo_index > req->nr_buffers)) {
578 NV_PRINTK(error, cli, "reloc bo index invalid\n");
583 b = &bo[r->bo_index];
584 if (b->presumed.valid)
587 if (unlikely(r->reloc_bo_index > req->nr_buffers)) {
588 NV_PRINTK(error, cli, "reloc container bo index invalid\n");
592 nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv;
594 if (unlikely(r->reloc_bo_offset + 4 >
595 nvbo->bo.mem.num_pages << PAGE_SHIFT)) {
596 NV_PRINTK(error, cli, "reloc outside of bo\n");
601 if (!nvbo->kmap.virtual) {
602 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages,
605 NV_PRINTK(error, cli, "failed kmap for reloc\n");
608 nvbo->validate_mapped = true;
611 if (r->flags & NOUVEAU_GEM_RELOC_LOW)
612 data = b->presumed.offset + r->data;
614 if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
615 data = (b->presumed.offset + r->data) >> 32;
619 if (r->flags & NOUVEAU_GEM_RELOC_OR) {
620 if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART)
626 ret = ttm_bo_wait(&nvbo->bo, true, false, false);
628 NV_PRINTK(error, cli, "reloc wait_idle failed: %d\n", ret);
632 nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
640 nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
641 struct drm_file *file_priv)
643 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
644 struct nouveau_cli *cli = nouveau_cli(file_priv);
645 struct nouveau_abi16_chan *temp;
646 struct nouveau_drm *drm = nouveau_drm(dev);
647 struct drm_nouveau_gem_pushbuf *req = data;
648 struct drm_nouveau_gem_pushbuf_push *push;
649 struct drm_nouveau_gem_pushbuf_bo *bo;
650 struct nouveau_channel *chan = NULL;
651 struct validate_op op;
652 struct nouveau_fence *fence = NULL;
653 int i, j, ret = 0, do_reloc = 0;
655 if (unlikely(!abi16))
658 list_for_each_entry(temp, &abi16->channels, head) {
659 if (temp->chan->object->handle == (NVDRM_CHAN | req->channel)) {
666 return nouveau_abi16_put(abi16, -ENOENT);
668 req->vram_available = drm->gem.vram_available;
669 req->gart_available = drm->gem.gart_available;
670 if (unlikely(req->nr_push == 0))
673 if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
674 NV_PRINTK(error, cli, "pushbuf push count exceeds limit: %d max %d\n",
675 req->nr_push, NOUVEAU_GEM_MAX_PUSH);
676 return nouveau_abi16_put(abi16, -EINVAL);
679 if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
680 NV_PRINTK(error, cli, "pushbuf bo count exceeds limit: %d max %d\n",
681 req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
682 return nouveau_abi16_put(abi16, -EINVAL);
685 if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
686 NV_PRINTK(error, cli, "pushbuf reloc count exceeds limit: %d max %d\n",
687 req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
688 return nouveau_abi16_put(abi16, -EINVAL);
691 push = u_memcpya(req->push, req->nr_push, sizeof(*push));
693 return nouveau_abi16_put(abi16, PTR_ERR(push));
695 bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
698 return nouveau_abi16_put(abi16, PTR_ERR(bo));
701 /* Ensure all push buffers are on validate list */
702 for (i = 0; i < req->nr_push; i++) {
703 if (push[i].bo_index >= req->nr_buffers) {
704 NV_PRINTK(error, cli, "push %d buffer not in list\n", i);
710 /* Validate buffer list */
711 ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
712 req->nr_buffers, &op, &do_reloc);
714 if (ret != -ERESTARTSYS)
715 NV_PRINTK(error, cli, "validate: %d\n", ret);
719 /* Apply any relocations that are required */
721 ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
723 NV_PRINTK(error, cli, "reloc apply: %d\n", ret);
728 if (chan->dma.ib_max) {
729 ret = nouveau_dma_wait(chan, req->nr_push + 1, 16);
731 NV_PRINTK(error, cli, "nv50cal_space: %d\n", ret);
735 for (i = 0; i < req->nr_push; i++) {
736 struct nouveau_bo *nvbo = (void *)(unsigned long)
737 bo[push[i].bo_index].user_priv;
739 nv50_dma_push(chan, nvbo, push[i].offset,
743 if (drm->device.info.chipset >= 0x25) {
744 ret = RING_SPACE(chan, req->nr_push * 2);
746 NV_PRINTK(error, cli, "cal_space: %d\n", ret);
750 for (i = 0; i < req->nr_push; i++) {
751 struct nouveau_bo *nvbo = (void *)(unsigned long)
752 bo[push[i].bo_index].user_priv;
754 OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2);
758 ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS));
760 NV_PRINTK(error, cli, "jmp_space: %d\n", ret);
764 for (i = 0; i < req->nr_push; i++) {
765 struct nouveau_bo *nvbo = (void *)(unsigned long)
766 bo[push[i].bo_index].user_priv;
769 cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2);
771 if (unlikely(cmd != req->suffix0)) {
772 if (!nvbo->kmap.virtual) {
773 ret = ttm_bo_kmap(&nvbo->bo, 0,
781 nvbo->validate_mapped = true;
784 nouveau_bo_wr32(nvbo, (push[i].offset +
785 push[i].length - 8) / 4, cmd);
788 OUT_RING(chan, 0x20000000 |
789 (nvbo->bo.offset + push[i].offset));
791 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
796 ret = nouveau_fence_new(chan, false, &fence);
798 NV_PRINTK(error, cli, "error fencing pushbuf: %d\n", ret);
804 validate_fini(&op, fence, bo);
805 nouveau_fence_unref(&fence);
812 if (chan->dma.ib_max) {
813 req->suffix0 = 0x00000000;
814 req->suffix1 = 0x00000000;
816 if (drm->device.info.chipset >= 0x25) {
817 req->suffix0 = 0x00020000;
818 req->suffix1 = 0x00000000;
820 req->suffix0 = 0x20000000 |
821 (chan->push.vma.offset + ((chan->dma.cur + 2) << 2));
822 req->suffix1 = 0x00000000;
825 return nouveau_abi16_put(abi16, ret);
828 static inline uint32_t
829 domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain)
833 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
834 flags |= TTM_PL_FLAG_VRAM;
835 if (domain & NOUVEAU_GEM_DOMAIN_GART)
836 flags |= TTM_PL_FLAG_TT;
842 nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
843 struct drm_file *file_priv)
845 struct drm_nouveau_gem_cpu_prep *req = data;
846 struct drm_gem_object *gem;
847 struct nouveau_bo *nvbo;
848 bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
849 bool write = !!(req->flags & NOUVEAU_GEM_CPU_PREP_WRITE);
852 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
855 nvbo = nouveau_gem_object(gem);
858 ret = reservation_object_test_signaled_rcu(nvbo->bo.resv, write) ? 0 : -EBUSY;
862 lret = reservation_object_wait_timeout_rcu(nvbo->bo.resv, write, true, 30 * HZ);
870 nouveau_bo_sync_for_cpu(nvbo);
871 drm_gem_object_unreference_unlocked(gem);
877 nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
878 struct drm_file *file_priv)
880 struct drm_nouveau_gem_cpu_fini *req = data;
881 struct drm_gem_object *gem;
882 struct nouveau_bo *nvbo;
884 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
887 nvbo = nouveau_gem_object(gem);
889 nouveau_bo_sync_for_device(nvbo);
890 drm_gem_object_unreference_unlocked(gem);
895 nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
896 struct drm_file *file_priv)
898 struct drm_nouveau_gem_info *req = data;
899 struct drm_gem_object *gem;
902 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
906 ret = nouveau_gem_info(file_priv, gem, req);
907 drm_gem_object_unreference_unlocked(gem);