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_drv.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 nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
40 struct ttm_buffer_object *bo = &nvbo->bo;
41 struct device *dev = drm->dev->dev;
44 ret = pm_runtime_get_sync(dev);
45 if (WARN_ON(ret < 0 && ret != -EACCES)) {
46 pm_runtime_put_autosuspend(dev);
50 if (gem->import_attach)
51 drm_prime_gem_destroy(gem, nvbo->bo.sg);
53 drm_gem_object_release(gem);
55 /* reset filp so nouveau_bo_del_ttm() can test for it */
59 pm_runtime_mark_last_busy(dev);
60 pm_runtime_put_autosuspend(dev);
64 nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
66 struct nouveau_cli *cli = nouveau_cli(file_priv);
67 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
68 struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
70 struct device *dev = drm->dev->dev;
76 ret = ttm_bo_reserve(&nvbo->bo, false, false, NULL);
80 vma = nouveau_bo_vma_find(nvbo, cli->vm);
82 vma = kzalloc(sizeof(*vma), GFP_KERNEL);
88 ret = pm_runtime_get_sync(dev);
89 if (ret < 0 && ret != -EACCES) {
94 ret = nouveau_bo_vma_add(nvbo, cli->vm, vma);
98 pm_runtime_mark_last_busy(dev);
99 pm_runtime_put_autosuspend(dev);
105 ttm_bo_unreserve(&nvbo->bo);
110 nouveau_gem_object_delete(void *data)
112 struct nvkm_vma *vma = data;
119 nouveau_gem_object_unmap(struct nouveau_bo *nvbo, struct nvkm_vma *vma)
121 const bool mapped = nvbo->bo.mem.mem_type != TTM_PL_SYSTEM;
122 struct reservation_object *resv = nvbo->bo.resv;
123 struct reservation_object_list *fobj;
124 struct fence *fence = NULL;
126 fobj = reservation_object_get_list(resv);
128 list_del(&vma->head);
130 if (fobj && fobj->shared_count > 1)
131 ttm_bo_wait(&nvbo->bo, false, false);
132 else if (fobj && fobj->shared_count == 1)
133 fence = rcu_dereference_protected(fobj->shared[0],
134 reservation_object_held(resv));
136 fence = reservation_object_get_excl(nvbo->bo.resv);
138 if (fence && mapped) {
139 nouveau_fence_work(fence, nouveau_gem_object_delete, vma);
149 nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
151 struct nouveau_cli *cli = nouveau_cli(file_priv);
152 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
153 struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
154 struct device *dev = drm->dev->dev;
155 struct nvkm_vma *vma;
161 ret = ttm_bo_reserve(&nvbo->bo, false, false, NULL);
165 vma = nouveau_bo_vma_find(nvbo, cli->vm);
167 if (--vma->refcount == 0) {
168 ret = pm_runtime_get_sync(dev);
169 if (!WARN_ON(ret < 0 && ret != -EACCES)) {
170 nouveau_gem_object_unmap(nvbo, vma);
171 pm_runtime_mark_last_busy(dev);
172 pm_runtime_put_autosuspend(dev);
176 ttm_bo_unreserve(&nvbo->bo);
180 nouveau_gem_new(struct drm_device *dev, int size, int align, uint32_t domain,
181 uint32_t tile_mode, uint32_t tile_flags,
182 struct nouveau_bo **pnvbo)
184 struct nouveau_drm *drm = nouveau_drm(dev);
185 struct nouveau_bo *nvbo;
189 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
190 flags |= TTM_PL_FLAG_VRAM;
191 if (domain & NOUVEAU_GEM_DOMAIN_GART)
192 flags |= TTM_PL_FLAG_TT;
193 if (!flags || domain & NOUVEAU_GEM_DOMAIN_CPU)
194 flags |= TTM_PL_FLAG_SYSTEM;
196 if (domain & NOUVEAU_GEM_DOMAIN_COHERENT)
197 flags |= TTM_PL_FLAG_UNCACHED;
199 ret = nouveau_bo_new(dev, size, align, flags, tile_mode,
200 tile_flags, NULL, NULL, pnvbo);
205 /* we restrict allowed domains on nv50+ to only the types
206 * that were requested at creation time. not possibly on
207 * earlier chips without busting the ABI.
209 nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM |
210 NOUVEAU_GEM_DOMAIN_GART;
211 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
212 nvbo->valid_domains &= domain;
214 /* Initialize the embedded gem-object. We return a single gem-reference
215 * to the caller, instead of a normal nouveau_bo ttm reference. */
216 ret = drm_gem_object_init(dev, &nvbo->gem, nvbo->bo.mem.size);
218 nouveau_bo_ref(NULL, pnvbo);
222 nvbo->bo.persistent_swap_storage = nvbo->gem.filp;
227 nouveau_gem_info(struct drm_file *file_priv, struct drm_gem_object *gem,
228 struct drm_nouveau_gem_info *rep)
230 struct nouveau_cli *cli = nouveau_cli(file_priv);
231 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
232 struct nvkm_vma *vma;
234 if (is_power_of_2(nvbo->valid_domains))
235 rep->domain = nvbo->valid_domains;
236 else if (nvbo->bo.mem.mem_type == TTM_PL_TT)
237 rep->domain = NOUVEAU_GEM_DOMAIN_GART;
239 rep->domain = NOUVEAU_GEM_DOMAIN_VRAM;
240 rep->offset = nvbo->bo.offset;
242 vma = nouveau_bo_vma_find(nvbo, cli->vm);
246 rep->offset = vma->offset;
249 rep->size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
250 rep->map_handle = drm_vma_node_offset_addr(&nvbo->bo.vma_node);
251 rep->tile_mode = nvbo->tile_mode;
252 rep->tile_flags = nvbo->tile_flags;
257 nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
258 struct drm_file *file_priv)
260 struct nouveau_drm *drm = nouveau_drm(dev);
261 struct nouveau_cli *cli = nouveau_cli(file_priv);
262 struct nvkm_fb *fb = nvxx_fb(&drm->device);
263 struct drm_nouveau_gem_new *req = data;
264 struct nouveau_bo *nvbo = NULL;
267 if (!nvkm_fb_memtype_valid(fb, req->info.tile_flags)) {
268 NV_PRINTK(err, cli, "bad page flags: 0x%08x\n", req->info.tile_flags);
272 ret = nouveau_gem_new(dev, req->info.size, req->align,
273 req->info.domain, req->info.tile_mode,
274 req->info.tile_flags, &nvbo);
278 ret = drm_gem_handle_create(file_priv, &nvbo->gem, &req->info.handle);
280 ret = nouveau_gem_info(file_priv, &nvbo->gem, &req->info);
282 drm_gem_handle_delete(file_priv, req->info.handle);
285 /* drop reference from allocate - handle holds it now */
286 drm_gem_object_unreference_unlocked(&nvbo->gem);
291 nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains,
292 uint32_t write_domains, uint32_t valid_domains)
294 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
295 struct ttm_buffer_object *bo = &nvbo->bo;
296 uint32_t domains = valid_domains & nvbo->valid_domains &
297 (write_domains ? write_domains : read_domains);
298 uint32_t pref_flags = 0, valid_flags = 0;
303 if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
304 valid_flags |= TTM_PL_FLAG_VRAM;
306 if (valid_domains & NOUVEAU_GEM_DOMAIN_GART)
307 valid_flags |= TTM_PL_FLAG_TT;
309 if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
310 bo->mem.mem_type == TTM_PL_VRAM)
311 pref_flags |= TTM_PL_FLAG_VRAM;
313 else if ((domains & NOUVEAU_GEM_DOMAIN_GART) &&
314 bo->mem.mem_type == TTM_PL_TT)
315 pref_flags |= TTM_PL_FLAG_TT;
317 else if (domains & NOUVEAU_GEM_DOMAIN_VRAM)
318 pref_flags |= TTM_PL_FLAG_VRAM;
321 pref_flags |= TTM_PL_FLAG_TT;
323 nouveau_bo_placement_set(nvbo, pref_flags, valid_flags);
329 struct list_head list;
330 struct ww_acquire_ctx ticket;
334 validate_fini_no_ticket(struct validate_op *op, struct nouveau_fence *fence,
335 struct drm_nouveau_gem_pushbuf_bo *pbbo)
337 struct nouveau_bo *nvbo;
338 struct drm_nouveau_gem_pushbuf_bo *b;
340 while (!list_empty(&op->list)) {
341 nvbo = list_entry(op->list.next, struct nouveau_bo, entry);
342 b = &pbbo[nvbo->pbbo_index];
345 nouveau_bo_fence(nvbo, fence, !!b->write_domains);
347 if (unlikely(nvbo->validate_mapped)) {
348 ttm_bo_kunmap(&nvbo->kmap);
349 nvbo->validate_mapped = false;
352 list_del(&nvbo->entry);
353 nvbo->reserved_by = NULL;
354 ttm_bo_unreserve_ticket(&nvbo->bo, &op->ticket);
355 drm_gem_object_unreference_unlocked(&nvbo->gem);
360 validate_fini(struct validate_op *op, struct nouveau_fence *fence,
361 struct drm_nouveau_gem_pushbuf_bo *pbbo)
363 validate_fini_no_ticket(op, fence, pbbo);
364 ww_acquire_fini(&op->ticket);
368 validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
369 struct drm_nouveau_gem_pushbuf_bo *pbbo,
370 int nr_buffers, struct validate_op *op)
372 struct nouveau_cli *cli = nouveau_cli(file_priv);
374 int ret = -EINVAL, i;
375 struct nouveau_bo *res_bo = NULL;
376 LIST_HEAD(gart_list);
377 LIST_HEAD(vram_list);
378 LIST_HEAD(both_list);
380 ww_acquire_init(&op->ticket, &reservation_ww_class);
382 if (++trycnt > 100000) {
383 NV_PRINTK(err, cli, "%s failed and gave up.\n", __func__);
387 for (i = 0; i < nr_buffers; i++) {
388 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i];
389 struct drm_gem_object *gem;
390 struct nouveau_bo *nvbo;
392 gem = drm_gem_object_lookup(file_priv, b->handle);
394 NV_PRINTK(err, cli, "Unknown handle 0x%08x\n", b->handle);
398 nvbo = nouveau_gem_object(gem);
399 if (nvbo == res_bo) {
401 drm_gem_object_unreference_unlocked(gem);
405 if (nvbo->reserved_by && nvbo->reserved_by == file_priv) {
406 NV_PRINTK(err, cli, "multiple instances of buffer %d on "
407 "validation list\n", b->handle);
408 drm_gem_object_unreference_unlocked(gem);
413 ret = ttm_bo_reserve(&nvbo->bo, true, false, &op->ticket);
415 list_splice_tail_init(&vram_list, &op->list);
416 list_splice_tail_init(&gart_list, &op->list);
417 list_splice_tail_init(&both_list, &op->list);
418 validate_fini_no_ticket(op, NULL, NULL);
419 if (unlikely(ret == -EDEADLK)) {
420 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
426 if (ret != -ERESTARTSYS)
427 NV_PRINTK(err, cli, "fail reserve\n");
432 b->user_priv = (uint64_t)(unsigned long)nvbo;
433 nvbo->reserved_by = file_priv;
434 nvbo->pbbo_index = i;
435 if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
436 (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART))
437 list_add_tail(&nvbo->entry, &both_list);
439 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
440 list_add_tail(&nvbo->entry, &vram_list);
442 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)
443 list_add_tail(&nvbo->entry, &gart_list);
445 NV_PRINTK(err, cli, "invalid valid domains: 0x%08x\n",
447 list_add_tail(&nvbo->entry, &both_list);
455 ww_acquire_done(&op->ticket);
456 list_splice_tail(&vram_list, &op->list);
457 list_splice_tail(&gart_list, &op->list);
458 list_splice_tail(&both_list, &op->list);
460 validate_fini(op, NULL, NULL);
466 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
467 struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
468 uint64_t user_pbbo_ptr)
470 struct nouveau_drm *drm = chan->drm;
471 struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
472 (void __force __user *)(uintptr_t)user_pbbo_ptr;
473 struct nouveau_bo *nvbo;
476 list_for_each_entry(nvbo, list, entry) {
477 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index];
479 ret = nouveau_gem_set_domain(&nvbo->gem, b->read_domains,
483 NV_PRINTK(err, cli, "fail set_domain\n");
487 ret = nouveau_bo_validate(nvbo, true, false);
489 if (ret != -ERESTARTSYS)
490 NV_PRINTK(err, cli, "fail ttm_validate\n");
494 ret = nouveau_fence_sync(nvbo, chan, !!b->write_domains, true);
496 if (ret != -ERESTARTSYS)
497 NV_PRINTK(err, cli, "fail post-validate sync\n");
501 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
502 if (nvbo->bo.offset == b->presumed.offset &&
503 ((nvbo->bo.mem.mem_type == TTM_PL_VRAM &&
504 b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) ||
505 (nvbo->bo.mem.mem_type == TTM_PL_TT &&
506 b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART)))
509 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
510 b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART;
512 b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM;
513 b->presumed.offset = nvbo->bo.offset;
514 b->presumed.valid = 0;
517 if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
518 &b->presumed, sizeof(b->presumed)))
527 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
528 struct drm_file *file_priv,
529 struct drm_nouveau_gem_pushbuf_bo *pbbo,
530 uint64_t user_buffers, int nr_buffers,
531 struct validate_op *op, int *apply_relocs)
533 struct nouveau_cli *cli = nouveau_cli(file_priv);
536 INIT_LIST_HEAD(&op->list);
541 ret = validate_init(chan, file_priv, pbbo, nr_buffers, op);
543 if (ret != -ERESTARTSYS)
544 NV_PRINTK(err, cli, "validate_init\n");
548 ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
549 if (unlikely(ret < 0)) {
550 if (ret != -ERESTARTSYS)
551 NV_PRINTK(err, cli, "validating bo list\n");
552 validate_fini(op, NULL, NULL);
566 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
569 void __user *userptr = (void __force __user *)(uintptr_t)user;
573 mem = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
577 return ERR_PTR(-ENOMEM);
579 if (copy_from_user(mem, userptr, size)) {
581 return ERR_PTR(-EFAULT);
588 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
589 struct drm_nouveau_gem_pushbuf *req,
590 struct drm_nouveau_gem_pushbuf_bo *bo)
592 struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
596 reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
598 return PTR_ERR(reloc);
600 for (i = 0; i < req->nr_relocs; i++) {
601 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
602 struct drm_nouveau_gem_pushbuf_bo *b;
603 struct nouveau_bo *nvbo;
606 if (unlikely(r->bo_index >= req->nr_buffers)) {
607 NV_PRINTK(err, cli, "reloc bo index invalid\n");
612 b = &bo[r->bo_index];
613 if (b->presumed.valid)
616 if (unlikely(r->reloc_bo_index >= req->nr_buffers)) {
617 NV_PRINTK(err, cli, "reloc container bo index invalid\n");
621 nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv;
623 if (unlikely(r->reloc_bo_offset + 4 >
624 nvbo->bo.mem.num_pages << PAGE_SHIFT)) {
625 NV_PRINTK(err, cli, "reloc outside of bo\n");
630 if (!nvbo->kmap.virtual) {
631 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages,
634 NV_PRINTK(err, cli, "failed kmap for reloc\n");
637 nvbo->validate_mapped = true;
640 if (r->flags & NOUVEAU_GEM_RELOC_LOW)
641 data = b->presumed.offset + r->data;
643 if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
644 data = (b->presumed.offset + r->data) >> 32;
648 if (r->flags & NOUVEAU_GEM_RELOC_OR) {
649 if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART)
655 ret = ttm_bo_wait(&nvbo->bo, false, false);
657 NV_PRINTK(err, cli, "reloc wait_idle failed: %d\n", ret);
661 nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
669 nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
670 struct drm_file *file_priv)
672 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
673 struct nouveau_cli *cli = nouveau_cli(file_priv);
674 struct nouveau_abi16_chan *temp;
675 struct nouveau_drm *drm = nouveau_drm(dev);
676 struct drm_nouveau_gem_pushbuf *req = data;
677 struct drm_nouveau_gem_pushbuf_push *push;
678 struct drm_nouveau_gem_pushbuf_bo *bo;
679 struct nouveau_channel *chan = NULL;
680 struct validate_op op;
681 struct nouveau_fence *fence = NULL;
682 int i, j, ret = 0, do_reloc = 0;
684 if (unlikely(!abi16))
687 list_for_each_entry(temp, &abi16->channels, head) {
688 if (temp->chan->chid == req->channel) {
695 return nouveau_abi16_put(abi16, -ENOENT);
697 req->vram_available = drm->gem.vram_available;
698 req->gart_available = drm->gem.gart_available;
699 if (unlikely(req->nr_push == 0))
702 if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
703 NV_PRINTK(err, cli, "pushbuf push count exceeds limit: %d max %d\n",
704 req->nr_push, NOUVEAU_GEM_MAX_PUSH);
705 return nouveau_abi16_put(abi16, -EINVAL);
708 if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
709 NV_PRINTK(err, cli, "pushbuf bo count exceeds limit: %d max %d\n",
710 req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
711 return nouveau_abi16_put(abi16, -EINVAL);
714 if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
715 NV_PRINTK(err, cli, "pushbuf reloc count exceeds limit: %d max %d\n",
716 req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
717 return nouveau_abi16_put(abi16, -EINVAL);
720 push = u_memcpya(req->push, req->nr_push, sizeof(*push));
722 return nouveau_abi16_put(abi16, PTR_ERR(push));
724 bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
727 return nouveau_abi16_put(abi16, PTR_ERR(bo));
730 /* Ensure all push buffers are on validate list */
731 for (i = 0; i < req->nr_push; i++) {
732 if (push[i].bo_index >= req->nr_buffers) {
733 NV_PRINTK(err, cli, "push %d buffer not in list\n", i);
739 /* Validate buffer list */
740 ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
741 req->nr_buffers, &op, &do_reloc);
743 if (ret != -ERESTARTSYS)
744 NV_PRINTK(err, cli, "validate: %d\n", ret);
748 /* Apply any relocations that are required */
750 ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
752 NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
757 if (chan->dma.ib_max) {
758 ret = nouveau_dma_wait(chan, req->nr_push + 1, 16);
760 NV_PRINTK(err, cli, "nv50cal_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;
768 nv50_dma_push(chan, nvbo, push[i].offset,
772 if (drm->device.info.chipset >= 0x25) {
773 ret = RING_SPACE(chan, req->nr_push * 2);
775 NV_PRINTK(err, cli, "cal_space: %d\n", ret);
779 for (i = 0; i < req->nr_push; i++) {
780 struct nouveau_bo *nvbo = (void *)(unsigned long)
781 bo[push[i].bo_index].user_priv;
783 OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2);
787 ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS));
789 NV_PRINTK(err, cli, "jmp_space: %d\n", ret);
793 for (i = 0; i < req->nr_push; i++) {
794 struct nouveau_bo *nvbo = (void *)(unsigned long)
795 bo[push[i].bo_index].user_priv;
798 cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2);
800 if (unlikely(cmd != req->suffix0)) {
801 if (!nvbo->kmap.virtual) {
802 ret = ttm_bo_kmap(&nvbo->bo, 0,
810 nvbo->validate_mapped = true;
813 nouveau_bo_wr32(nvbo, (push[i].offset +
814 push[i].length - 8) / 4, cmd);
817 OUT_RING(chan, 0x20000000 |
818 (nvbo->bo.offset + push[i].offset));
820 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
825 ret = nouveau_fence_new(chan, false, &fence);
827 NV_PRINTK(err, cli, "error fencing pushbuf: %d\n", ret);
833 validate_fini(&op, fence, bo);
834 nouveau_fence_unref(&fence);
841 if (chan->dma.ib_max) {
842 req->suffix0 = 0x00000000;
843 req->suffix1 = 0x00000000;
845 if (drm->device.info.chipset >= 0x25) {
846 req->suffix0 = 0x00020000;
847 req->suffix1 = 0x00000000;
849 req->suffix0 = 0x20000000 |
850 (chan->push.vma.offset + ((chan->dma.cur + 2) << 2));
851 req->suffix1 = 0x00000000;
854 return nouveau_abi16_put(abi16, ret);
858 nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
859 struct drm_file *file_priv)
861 struct drm_nouveau_gem_cpu_prep *req = data;
862 struct drm_gem_object *gem;
863 struct nouveau_bo *nvbo;
864 bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
865 bool write = !!(req->flags & NOUVEAU_GEM_CPU_PREP_WRITE);
868 gem = drm_gem_object_lookup(file_priv, req->handle);
871 nvbo = nouveau_gem_object(gem);
874 ret = reservation_object_test_signaled_rcu(nvbo->bo.resv, write) ? 0 : -EBUSY;
878 lret = reservation_object_wait_timeout_rcu(nvbo->bo.resv, write, true, 30 * HZ);
886 nouveau_bo_sync_for_cpu(nvbo);
887 drm_gem_object_unreference_unlocked(gem);
893 nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
894 struct drm_file *file_priv)
896 struct drm_nouveau_gem_cpu_fini *req = data;
897 struct drm_gem_object *gem;
898 struct nouveau_bo *nvbo;
900 gem = drm_gem_object_lookup(file_priv, req->handle);
903 nvbo = nouveau_gem_object(gem);
905 nouveau_bo_sync_for_device(nvbo);
906 drm_gem_object_unreference_unlocked(gem);
911 nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
912 struct drm_file *file_priv)
914 struct drm_nouveau_gem_info *req = data;
915 struct drm_gem_object *gem;
918 gem = drm_gem_object_lookup(file_priv, req->handle);
922 ret = nouveau_gem_info(file_priv, gem, req);
923 drm_gem_object_unreference_unlocked(gem);