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 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, 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, true, 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, 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);
373 struct drm_device *dev = chan->drm->dev;
375 int ret = -EINVAL, i;
376 struct nouveau_bo *res_bo = NULL;
377 LIST_HEAD(gart_list);
378 LIST_HEAD(vram_list);
379 LIST_HEAD(both_list);
381 ww_acquire_init(&op->ticket, &reservation_ww_class);
383 if (++trycnt > 100000) {
384 NV_PRINTK(err, cli, "%s failed and gave up.\n", __func__);
388 for (i = 0; i < nr_buffers; i++) {
389 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i];
390 struct drm_gem_object *gem;
391 struct nouveau_bo *nvbo;
393 gem = drm_gem_object_lookup(dev, file_priv, b->handle);
395 NV_PRINTK(err, cli, "Unknown handle 0x%08x\n", b->handle);
399 nvbo = nouveau_gem_object(gem);
400 if (nvbo == res_bo) {
402 drm_gem_object_unreference_unlocked(gem);
406 if (nvbo->reserved_by && nvbo->reserved_by == file_priv) {
407 NV_PRINTK(err, cli, "multiple instances of buffer %d on "
408 "validation list\n", b->handle);
409 drm_gem_object_unreference_unlocked(gem);
414 ret = ttm_bo_reserve(&nvbo->bo, true, false, true, &op->ticket);
416 list_splice_tail_init(&vram_list, &op->list);
417 list_splice_tail_init(&gart_list, &op->list);
418 list_splice_tail_init(&both_list, &op->list);
419 validate_fini_no_ticket(op, NULL, NULL);
420 if (unlikely(ret == -EDEADLK)) {
421 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
427 if (ret != -ERESTARTSYS)
428 NV_PRINTK(err, cli, "fail reserve\n");
433 b->user_priv = (uint64_t)(unsigned long)nvbo;
434 nvbo->reserved_by = file_priv;
435 nvbo->pbbo_index = i;
436 if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
437 (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART))
438 list_add_tail(&nvbo->entry, &both_list);
440 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
441 list_add_tail(&nvbo->entry, &vram_list);
443 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)
444 list_add_tail(&nvbo->entry, &gart_list);
446 NV_PRINTK(err, cli, "invalid valid domains: 0x%08x\n",
448 list_add_tail(&nvbo->entry, &both_list);
456 ww_acquire_done(&op->ticket);
457 list_splice_tail(&vram_list, &op->list);
458 list_splice_tail(&gart_list, &op->list);
459 list_splice_tail(&both_list, &op->list);
461 validate_fini(op, NULL, NULL);
467 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
468 struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
469 uint64_t user_pbbo_ptr)
471 struct nouveau_drm *drm = chan->drm;
472 struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
473 (void __force __user *)(uintptr_t)user_pbbo_ptr;
474 struct nouveau_bo *nvbo;
477 list_for_each_entry(nvbo, list, entry) {
478 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index];
480 ret = nouveau_gem_set_domain(&nvbo->gem, b->read_domains,
484 NV_PRINTK(err, cli, "fail set_domain\n");
488 ret = nouveau_bo_validate(nvbo, true, false);
490 if (ret != -ERESTARTSYS)
491 NV_PRINTK(err, cli, "fail ttm_validate\n");
495 ret = nouveau_fence_sync(nvbo, chan, !!b->write_domains, true);
497 if (ret != -ERESTARTSYS)
498 NV_PRINTK(err, cli, "fail post-validate sync\n");
502 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
503 if (nvbo->bo.offset == b->presumed.offset &&
504 ((nvbo->bo.mem.mem_type == TTM_PL_VRAM &&
505 b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) ||
506 (nvbo->bo.mem.mem_type == TTM_PL_TT &&
507 b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART)))
510 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
511 b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART;
513 b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM;
514 b->presumed.offset = nvbo->bo.offset;
515 b->presumed.valid = 0;
518 if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
519 &b->presumed, sizeof(b->presumed)))
528 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
529 struct drm_file *file_priv,
530 struct drm_nouveau_gem_pushbuf_bo *pbbo,
531 uint64_t user_buffers, int nr_buffers,
532 struct validate_op *op, int *apply_relocs)
534 struct nouveau_cli *cli = nouveau_cli(file_priv);
537 INIT_LIST_HEAD(&op->list);
542 ret = validate_init(chan, file_priv, pbbo, nr_buffers, op);
544 if (ret != -ERESTARTSYS)
545 NV_PRINTK(err, cli, "validate_init\n");
549 ret = validate_list(chan, cli, &op->list, pbbo, user_buffers);
550 if (unlikely(ret < 0)) {
551 if (ret != -ERESTARTSYS)
552 NV_PRINTK(err, cli, "validating bo list\n");
553 validate_fini(op, NULL, NULL);
567 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
570 void __user *userptr = (void __force __user *)(uintptr_t)user;
574 mem = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
578 return ERR_PTR(-ENOMEM);
580 if (copy_from_user(mem, userptr, size)) {
582 return ERR_PTR(-EFAULT);
589 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
590 struct drm_nouveau_gem_pushbuf *req,
591 struct drm_nouveau_gem_pushbuf_bo *bo)
593 struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
597 reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
599 return PTR_ERR(reloc);
601 for (i = 0; i < req->nr_relocs; i++) {
602 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
603 struct drm_nouveau_gem_pushbuf_bo *b;
604 struct nouveau_bo *nvbo;
607 if (unlikely(r->bo_index >= req->nr_buffers)) {
608 NV_PRINTK(err, cli, "reloc bo index invalid\n");
613 b = &bo[r->bo_index];
614 if (b->presumed.valid)
617 if (unlikely(r->reloc_bo_index >= req->nr_buffers)) {
618 NV_PRINTK(err, cli, "reloc container bo index invalid\n");
622 nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv;
624 if (unlikely(r->reloc_bo_offset + 4 >
625 nvbo->bo.mem.num_pages << PAGE_SHIFT)) {
626 NV_PRINTK(err, cli, "reloc outside of bo\n");
631 if (!nvbo->kmap.virtual) {
632 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages,
635 NV_PRINTK(err, cli, "failed kmap for reloc\n");
638 nvbo->validate_mapped = true;
641 if (r->flags & NOUVEAU_GEM_RELOC_LOW)
642 data = b->presumed.offset + r->data;
644 if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
645 data = (b->presumed.offset + r->data) >> 32;
649 if (r->flags & NOUVEAU_GEM_RELOC_OR) {
650 if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART)
656 ret = ttm_bo_wait(&nvbo->bo, true, false, false);
658 NV_PRINTK(err, cli, "reloc wait_idle failed: %d\n", ret);
662 nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
670 nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
671 struct drm_file *file_priv)
673 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv);
674 struct nouveau_cli *cli = nouveau_cli(file_priv);
675 struct nouveau_abi16_chan *temp;
676 struct nouveau_drm *drm = nouveau_drm(dev);
677 struct drm_nouveau_gem_pushbuf *req = data;
678 struct drm_nouveau_gem_pushbuf_push *push;
679 struct drm_nouveau_gem_pushbuf_bo *bo;
680 struct nouveau_channel *chan = NULL;
681 struct validate_op op;
682 struct nouveau_fence *fence = NULL;
683 int i, j, ret = 0, do_reloc = 0;
685 if (unlikely(!abi16))
688 list_for_each_entry(temp, &abi16->channels, head) {
689 if (temp->chan->chid == req->channel) {
696 return nouveau_abi16_put(abi16, -ENOENT);
698 req->vram_available = drm->gem.vram_available;
699 req->gart_available = drm->gem.gart_available;
700 if (unlikely(req->nr_push == 0))
703 if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
704 NV_PRINTK(err, cli, "pushbuf push count exceeds limit: %d max %d\n",
705 req->nr_push, NOUVEAU_GEM_MAX_PUSH);
706 return nouveau_abi16_put(abi16, -EINVAL);
709 if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
710 NV_PRINTK(err, cli, "pushbuf bo count exceeds limit: %d max %d\n",
711 req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
712 return nouveau_abi16_put(abi16, -EINVAL);
715 if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
716 NV_PRINTK(err, cli, "pushbuf reloc count exceeds limit: %d max %d\n",
717 req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
718 return nouveau_abi16_put(abi16, -EINVAL);
721 push = u_memcpya(req->push, req->nr_push, sizeof(*push));
723 return nouveau_abi16_put(abi16, PTR_ERR(push));
725 bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
728 return nouveau_abi16_put(abi16, PTR_ERR(bo));
731 /* Ensure all push buffers are on validate list */
732 for (i = 0; i < req->nr_push; i++) {
733 if (push[i].bo_index >= req->nr_buffers) {
734 NV_PRINTK(err, cli, "push %d buffer not in list\n", i);
740 /* Validate buffer list */
741 ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
742 req->nr_buffers, &op, &do_reloc);
744 if (ret != -ERESTARTSYS)
745 NV_PRINTK(err, cli, "validate: %d\n", ret);
749 /* Apply any relocations that are required */
751 ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
753 NV_PRINTK(err, cli, "reloc apply: %d\n", ret);
758 if (chan->dma.ib_max) {
759 ret = nouveau_dma_wait(chan, req->nr_push + 1, 16);
761 NV_PRINTK(err, cli, "nv50cal_space: %d\n", ret);
765 for (i = 0; i < req->nr_push; i++) {
766 struct nouveau_bo *nvbo = (void *)(unsigned long)
767 bo[push[i].bo_index].user_priv;
769 nv50_dma_push(chan, nvbo, push[i].offset,
773 if (drm->device.info.chipset >= 0x25) {
774 ret = RING_SPACE(chan, req->nr_push * 2);
776 NV_PRINTK(err, cli, "cal_space: %d\n", ret);
780 for (i = 0; i < req->nr_push; i++) {
781 struct nouveau_bo *nvbo = (void *)(unsigned long)
782 bo[push[i].bo_index].user_priv;
784 OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2);
788 ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS));
790 NV_PRINTK(err, cli, "jmp_space: %d\n", ret);
794 for (i = 0; i < req->nr_push; i++) {
795 struct nouveau_bo *nvbo = (void *)(unsigned long)
796 bo[push[i].bo_index].user_priv;
799 cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2);
801 if (unlikely(cmd != req->suffix0)) {
802 if (!nvbo->kmap.virtual) {
803 ret = ttm_bo_kmap(&nvbo->bo, 0,
811 nvbo->validate_mapped = true;
814 nouveau_bo_wr32(nvbo, (push[i].offset +
815 push[i].length - 8) / 4, cmd);
818 OUT_RING(chan, 0x20000000 |
819 (nvbo->bo.offset + push[i].offset));
821 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
826 ret = nouveau_fence_new(chan, false, &fence);
828 NV_PRINTK(err, cli, "error fencing pushbuf: %d\n", ret);
834 validate_fini(&op, fence, bo);
835 nouveau_fence_unref(&fence);
842 if (chan->dma.ib_max) {
843 req->suffix0 = 0x00000000;
844 req->suffix1 = 0x00000000;
846 if (drm->device.info.chipset >= 0x25) {
847 req->suffix0 = 0x00020000;
848 req->suffix1 = 0x00000000;
850 req->suffix0 = 0x20000000 |
851 (chan->push.vma.offset + ((chan->dma.cur + 2) << 2));
852 req->suffix1 = 0x00000000;
855 return nouveau_abi16_put(abi16, ret);
859 nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
860 struct drm_file *file_priv)
862 struct drm_nouveau_gem_cpu_prep *req = data;
863 struct drm_gem_object *gem;
864 struct nouveau_bo *nvbo;
865 bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
866 bool write = !!(req->flags & NOUVEAU_GEM_CPU_PREP_WRITE);
869 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
872 nvbo = nouveau_gem_object(gem);
875 ret = reservation_object_test_signaled_rcu(nvbo->bo.resv, write) ? 0 : -EBUSY;
879 lret = reservation_object_wait_timeout_rcu(nvbo->bo.resv, write, true, 30 * HZ);
887 nouveau_bo_sync_for_cpu(nvbo);
888 drm_gem_object_unreference_unlocked(gem);
894 nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
895 struct drm_file *file_priv)
897 struct drm_nouveau_gem_cpu_fini *req = data;
898 struct drm_gem_object *gem;
899 struct nouveau_bo *nvbo;
901 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
904 nvbo = nouveau_gem_object(gem);
906 nouveau_bo_sync_for_device(nvbo);
907 drm_gem_object_unreference_unlocked(gem);
912 nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
913 struct drm_file *file_priv)
915 struct drm_nouveau_gem_info *req = data;
916 struct drm_gem_object *gem;
919 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
923 ret = nouveau_gem_info(file_priv, gem, req);
924 drm_gem_object_unreference_unlocked(gem);