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 nouveau_fence *fence = NULL;
103 list_del(&vma->head);
106 spin_lock(&nvbo->bo.bdev->fence_lock);
107 fence = nouveau_fence_ref(nvbo->bo.sync_obj);
108 spin_unlock(&nvbo->bo.bdev->fence_lock);
112 nouveau_fence_work(fence, nouveau_gem_object_delete, vma);
115 nouveau_vm_unmap(vma);
119 nouveau_fence_unref(&fence);
123 nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
125 struct nouveau_cli *cli = nouveau_cli(file_priv);
126 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
127 struct nouveau_vma *vma;
133 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, NULL);
137 vma = nouveau_bo_vma_find(nvbo, cli->vm);
139 if (--vma->refcount == 0)
140 nouveau_gem_object_unmap(nvbo, vma);
142 ttm_bo_unreserve(&nvbo->bo);
146 nouveau_gem_new(struct drm_device *dev, int size, int align, uint32_t domain,
147 uint32_t tile_mode, uint32_t tile_flags,
148 struct nouveau_bo **pnvbo)
150 struct nouveau_drm *drm = nouveau_drm(dev);
151 struct nouveau_bo *nvbo;
155 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
156 flags |= TTM_PL_FLAG_VRAM;
157 if (domain & NOUVEAU_GEM_DOMAIN_GART)
158 flags |= TTM_PL_FLAG_TT;
159 if (!flags || domain & NOUVEAU_GEM_DOMAIN_CPU)
160 flags |= TTM_PL_FLAG_SYSTEM;
162 ret = nouveau_bo_new(dev, size, align, flags, tile_mode,
163 tile_flags, NULL, pnvbo);
168 /* we restrict allowed domains on nv50+ to only the types
169 * that were requested at creation time. not possibly on
170 * earlier chips without busting the ABI.
172 nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM |
173 NOUVEAU_GEM_DOMAIN_GART;
174 if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA)
175 nvbo->valid_domains &= domain;
177 /* Initialize the embedded gem-object. We return a single gem-reference
178 * to the caller, instead of a normal nouveau_bo ttm reference. */
179 ret = drm_gem_object_init(dev, &nvbo->gem, nvbo->bo.mem.size);
181 nouveau_bo_ref(NULL, pnvbo);
185 nvbo->bo.persistent_swap_storage = nvbo->gem.filp;
190 nouveau_gem_info(struct drm_file *file_priv, struct drm_gem_object *gem,
191 struct drm_nouveau_gem_info *rep)
193 struct nouveau_cli *cli = nouveau_cli(file_priv);
194 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
195 struct nouveau_vma *vma;
197 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
198 rep->domain = NOUVEAU_GEM_DOMAIN_GART;
200 rep->domain = NOUVEAU_GEM_DOMAIN_VRAM;
202 rep->offset = nvbo->bo.offset;
204 vma = nouveau_bo_vma_find(nvbo, cli->vm);
208 rep->offset = vma->offset;
211 rep->size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
212 rep->map_handle = drm_vma_node_offset_addr(&nvbo->bo.vma_node);
213 rep->tile_mode = nvbo->tile_mode;
214 rep->tile_flags = nvbo->tile_flags;
219 nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
220 struct drm_file *file_priv)
222 struct nouveau_drm *drm = nouveau_drm(dev);
223 struct nouveau_cli *cli = nouveau_cli(file_priv);
224 struct nouveau_fb *pfb = nvkm_fb(&drm->device);
225 struct drm_nouveau_gem_new *req = data;
226 struct nouveau_bo *nvbo = NULL;
229 if (!pfb->memtype_valid(pfb, req->info.tile_flags)) {
230 NV_PRINTK(error, cli, "bad page flags: 0x%08x\n", req->info.tile_flags);
234 ret = nouveau_gem_new(dev, req->info.size, req->align,
235 req->info.domain, req->info.tile_mode,
236 req->info.tile_flags, &nvbo);
240 ret = drm_gem_handle_create(file_priv, &nvbo->gem, &req->info.handle);
242 ret = nouveau_gem_info(file_priv, &nvbo->gem, &req->info);
244 drm_gem_handle_delete(file_priv, req->info.handle);
247 /* drop reference from allocate - handle holds it now */
248 drm_gem_object_unreference_unlocked(&nvbo->gem);
253 nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains,
254 uint32_t write_domains, uint32_t valid_domains)
256 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
257 struct ttm_buffer_object *bo = &nvbo->bo;
258 uint32_t domains = valid_domains & nvbo->valid_domains &
259 (write_domains ? write_domains : read_domains);
260 uint32_t pref_flags = 0, valid_flags = 0;
265 if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
266 valid_flags |= TTM_PL_FLAG_VRAM;
268 if (valid_domains & NOUVEAU_GEM_DOMAIN_GART)
269 valid_flags |= TTM_PL_FLAG_TT;
271 if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
272 bo->mem.mem_type == TTM_PL_VRAM)
273 pref_flags |= TTM_PL_FLAG_VRAM;
275 else if ((domains & NOUVEAU_GEM_DOMAIN_GART) &&
276 bo->mem.mem_type == TTM_PL_TT)
277 pref_flags |= TTM_PL_FLAG_TT;
279 else if (domains & NOUVEAU_GEM_DOMAIN_VRAM)
280 pref_flags |= TTM_PL_FLAG_VRAM;
283 pref_flags |= TTM_PL_FLAG_TT;
285 nouveau_bo_placement_set(nvbo, pref_flags, valid_flags);
291 struct list_head vram_list;
292 struct list_head gart_list;
293 struct list_head both_list;
294 struct ww_acquire_ctx ticket;
298 validate_fini_list(struct list_head *list, struct nouveau_fence *fence,
299 struct ww_acquire_ctx *ticket)
301 struct list_head *entry, *tmp;
302 struct nouveau_bo *nvbo;
304 list_for_each_safe(entry, tmp, list) {
305 nvbo = list_entry(entry, struct nouveau_bo, entry);
308 nouveau_bo_fence(nvbo, fence);
310 if (unlikely(nvbo->validate_mapped)) {
311 ttm_bo_kunmap(&nvbo->kmap);
312 nvbo->validate_mapped = false;
315 list_del(&nvbo->entry);
316 nvbo->reserved_by = NULL;
317 ttm_bo_unreserve_ticket(&nvbo->bo, ticket);
318 drm_gem_object_unreference_unlocked(&nvbo->gem);
323 validate_fini_no_ticket(struct validate_op *op, struct nouveau_fence *fence)
325 validate_fini_list(&op->vram_list, fence, &op->ticket);
326 validate_fini_list(&op->gart_list, fence, &op->ticket);
327 validate_fini_list(&op->both_list, fence, &op->ticket);
331 validate_fini(struct validate_op *op, struct nouveau_fence *fence)
333 validate_fini_no_ticket(op, fence);
334 ww_acquire_fini(&op->ticket);
338 validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
339 struct drm_nouveau_gem_pushbuf_bo *pbbo,
340 int nr_buffers, struct validate_op *op)
342 struct nouveau_cli *cli = nouveau_cli(file_priv);
343 struct drm_device *dev = chan->drm->dev;
346 struct nouveau_bo *res_bo = NULL;
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);
363 ww_acquire_done(&op->ticket);
364 validate_fini(op, NULL);
367 nvbo = nouveau_gem_object(gem);
368 if (nvbo == res_bo) {
370 drm_gem_object_unreference_unlocked(gem);
374 if (nvbo->reserved_by && nvbo->reserved_by == file_priv) {
375 NV_PRINTK(error, cli, "multiple instances of buffer %d on "
376 "validation list\n", b->handle);
377 drm_gem_object_unreference_unlocked(gem);
378 ww_acquire_done(&op->ticket);
379 validate_fini(op, NULL);
383 ret = ttm_bo_reserve(&nvbo->bo, true, false, true, &op->ticket);
385 validate_fini_no_ticket(op, NULL);
386 if (unlikely(ret == -EDEADLK)) {
387 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
393 ww_acquire_done(&op->ticket);
394 ww_acquire_fini(&op->ticket);
395 drm_gem_object_unreference_unlocked(gem);
396 if (ret != -ERESTARTSYS)
397 NV_PRINTK(error, cli, "fail reserve\n");
402 b->user_priv = (uint64_t)(unsigned long)nvbo;
403 nvbo->reserved_by = file_priv;
404 nvbo->pbbo_index = i;
405 if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
406 (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART))
407 list_add_tail(&nvbo->entry, &op->both_list);
409 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
410 list_add_tail(&nvbo->entry, &op->vram_list);
412 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)
413 list_add_tail(&nvbo->entry, &op->gart_list);
415 NV_PRINTK(error, cli, "invalid valid domains: 0x%08x\n",
417 list_add_tail(&nvbo->entry, &op->both_list);
418 ww_acquire_done(&op->ticket);
419 validate_fini(op, NULL);
426 ww_acquire_done(&op->ticket);
431 validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo)
433 struct nouveau_fence *fence = NULL;
436 spin_lock(&nvbo->bo.bdev->fence_lock);
437 fence = nouveau_fence_ref(nvbo->bo.sync_obj);
438 spin_unlock(&nvbo->bo.bdev->fence_lock);
441 ret = nouveau_fence_sync(fence, chan);
442 nouveau_fence_unref(&fence);
449 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
450 struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
451 uint64_t user_pbbo_ptr)
453 struct nouveau_drm *drm = chan->drm;
454 struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
455 (void __force __user *)(uintptr_t)user_pbbo_ptr;
456 struct nouveau_bo *nvbo;
459 list_for_each_entry(nvbo, list, entry) {
460 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index];
462 ret = nouveau_gem_set_domain(&nvbo->gem, b->read_domains,
466 NV_PRINTK(error, cli, "fail set_domain\n");
470 ret = nouveau_bo_validate(nvbo, true, false);
472 if (ret != -ERESTARTSYS)
473 NV_PRINTK(error, cli, "fail ttm_validate\n");
477 ret = validate_sync(chan, nvbo);
479 NV_PRINTK(error, cli, "fail post-validate sync\n");
483 if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) {
484 if (nvbo->bo.offset == b->presumed.offset &&
485 ((nvbo->bo.mem.mem_type == TTM_PL_VRAM &&
486 b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) ||
487 (nvbo->bo.mem.mem_type == TTM_PL_TT &&
488 b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART)))
491 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
492 b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART;
494 b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM;
495 b->presumed.offset = nvbo->bo.offset;
496 b->presumed.valid = 0;
499 if (copy_to_user(&upbbo[nvbo->pbbo_index].presumed,
500 &b->presumed, sizeof(b->presumed)))
509 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
510 struct drm_file *file_priv,
511 struct drm_nouveau_gem_pushbuf_bo *pbbo,
512 uint64_t user_buffers, int nr_buffers,
513 struct validate_op *op, int *apply_relocs)
515 struct nouveau_cli *cli = nouveau_cli(file_priv);
518 INIT_LIST_HEAD(&op->vram_list);
519 INIT_LIST_HEAD(&op->gart_list);
520 INIT_LIST_HEAD(&op->both_list);
525 ret = validate_init(chan, file_priv, pbbo, nr_buffers, op);
527 if (ret != -ERESTARTSYS)
528 NV_PRINTK(error, cli, "validate_init\n");
532 ret = validate_list(chan, cli, &op->vram_list, pbbo, user_buffers);
533 if (unlikely(ret < 0)) {
534 if (ret != -ERESTARTSYS)
535 NV_PRINTK(error, cli, "validate vram_list\n");
536 validate_fini(op, NULL);
541 ret = validate_list(chan, cli, &op->gart_list, pbbo, user_buffers);
542 if (unlikely(ret < 0)) {
543 if (ret != -ERESTARTSYS)
544 NV_PRINTK(error, cli, "validate gart_list\n");
545 validate_fini(op, NULL);
550 ret = validate_list(chan, cli, &op->both_list, pbbo, user_buffers);
551 if (unlikely(ret < 0)) {
552 if (ret != -ERESTARTSYS)
553 NV_PRINTK(error, cli, "validate both_list\n");
554 validate_fini(op, NULL);
559 *apply_relocs = relocs;
566 if (!is_vmalloc_addr(addr))
573 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
576 void __user *userptr = (void __force __user *)(uintptr_t)user;
580 mem = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
584 return ERR_PTR(-ENOMEM);
586 if (copy_from_user(mem, userptr, size)) {
588 return ERR_PTR(-EFAULT);
595 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
596 struct drm_nouveau_gem_pushbuf *req,
597 struct drm_nouveau_gem_pushbuf_bo *bo)
599 struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
603 reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
605 return PTR_ERR(reloc);
607 for (i = 0; i < req->nr_relocs; i++) {
608 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
609 struct drm_nouveau_gem_pushbuf_bo *b;
610 struct nouveau_bo *nvbo;
613 if (unlikely(r->bo_index > req->nr_buffers)) {
614 NV_PRINTK(error, cli, "reloc bo index invalid\n");
619 b = &bo[r->bo_index];
620 if (b->presumed.valid)
623 if (unlikely(r->reloc_bo_index > req->nr_buffers)) {
624 NV_PRINTK(error, cli, "reloc container bo index invalid\n");
628 nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv;
630 if (unlikely(r->reloc_bo_offset + 4 >
631 nvbo->bo.mem.num_pages << PAGE_SHIFT)) {
632 NV_PRINTK(error, cli, "reloc outside of bo\n");
637 if (!nvbo->kmap.virtual) {
638 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages,
641 NV_PRINTK(error, cli, "failed kmap for reloc\n");
644 nvbo->validate_mapped = true;
647 if (r->flags & NOUVEAU_GEM_RELOC_LOW)
648 data = b->presumed.offset + r->data;
650 if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
651 data = (b->presumed.offset + r->data) >> 32;
655 if (r->flags & NOUVEAU_GEM_RELOC_OR) {
656 if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART)
662 spin_lock(&nvbo->bo.bdev->fence_lock);
663 ret = ttm_bo_wait(&nvbo->bo, false, false, false);
664 spin_unlock(&nvbo->bo.bdev->fence_lock);
666 NV_PRINTK(error, cli, "reloc wait_idle failed: %d\n", ret);
670 nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
678 nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
679 struct drm_file *file_priv)
681 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
682 struct nouveau_cli *cli = nouveau_cli(file_priv);
683 struct nouveau_abi16_chan *temp;
684 struct nouveau_drm *drm = nouveau_drm(dev);
685 struct drm_nouveau_gem_pushbuf *req = data;
686 struct drm_nouveau_gem_pushbuf_push *push;
687 struct drm_nouveau_gem_pushbuf_bo *bo;
688 struct nouveau_channel *chan = NULL;
689 struct validate_op op;
690 struct nouveau_fence *fence = NULL;
691 int i, j, ret = 0, do_reloc = 0;
693 if (unlikely(!abi16))
696 list_for_each_entry(temp, &abi16->channels, head) {
697 if (temp->chan->object->handle == (NVDRM_CHAN | req->channel)) {
704 return nouveau_abi16_put(abi16, -ENOENT);
706 req->vram_available = drm->gem.vram_available;
707 req->gart_available = drm->gem.gart_available;
708 if (unlikely(req->nr_push == 0))
711 if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
712 NV_PRINTK(error, cli, "pushbuf push count exceeds limit: %d max %d\n",
713 req->nr_push, NOUVEAU_GEM_MAX_PUSH);
714 return nouveau_abi16_put(abi16, -EINVAL);
717 if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
718 NV_PRINTK(error, cli, "pushbuf bo count exceeds limit: %d max %d\n",
719 req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
720 return nouveau_abi16_put(abi16, -EINVAL);
723 if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
724 NV_PRINTK(error, cli, "pushbuf reloc count exceeds limit: %d max %d\n",
725 req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
726 return nouveau_abi16_put(abi16, -EINVAL);
729 push = u_memcpya(req->push, req->nr_push, sizeof(*push));
731 return nouveau_abi16_put(abi16, PTR_ERR(push));
733 bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
736 return nouveau_abi16_put(abi16, PTR_ERR(bo));
739 /* Ensure all push buffers are on validate list */
740 for (i = 0; i < req->nr_push; i++) {
741 if (push[i].bo_index >= req->nr_buffers) {
742 NV_PRINTK(error, cli, "push %d buffer not in list\n", i);
748 /* Validate buffer list */
749 ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
750 req->nr_buffers, &op, &do_reloc);
752 if (ret != -ERESTARTSYS)
753 NV_PRINTK(error, cli, "validate: %d\n", ret);
757 /* Apply any relocations that are required */
759 ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
761 NV_PRINTK(error, cli, "reloc apply: %d\n", ret);
766 if (chan->dma.ib_max) {
767 ret = nouveau_dma_wait(chan, req->nr_push + 1, 16);
769 NV_PRINTK(error, cli, "nv50cal_space: %d\n", ret);
773 for (i = 0; i < req->nr_push; i++) {
774 struct nouveau_bo *nvbo = (void *)(unsigned long)
775 bo[push[i].bo_index].user_priv;
777 nv50_dma_push(chan, nvbo, push[i].offset,
781 if (drm->device.info.chipset >= 0x25) {
782 ret = RING_SPACE(chan, req->nr_push * 2);
784 NV_PRINTK(error, cli, "cal_space: %d\n", ret);
788 for (i = 0; i < req->nr_push; i++) {
789 struct nouveau_bo *nvbo = (void *)(unsigned long)
790 bo[push[i].bo_index].user_priv;
792 OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2);
796 ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS));
798 NV_PRINTK(error, cli, "jmp_space: %d\n", ret);
802 for (i = 0; i < req->nr_push; i++) {
803 struct nouveau_bo *nvbo = (void *)(unsigned long)
804 bo[push[i].bo_index].user_priv;
807 cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2);
809 if (unlikely(cmd != req->suffix0)) {
810 if (!nvbo->kmap.virtual) {
811 ret = ttm_bo_kmap(&nvbo->bo, 0,
819 nvbo->validate_mapped = true;
822 nouveau_bo_wr32(nvbo, (push[i].offset +
823 push[i].length - 8) / 4, cmd);
826 OUT_RING(chan, 0x20000000 |
827 (nvbo->bo.offset + push[i].offset));
829 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
834 ret = nouveau_fence_new(chan, false, &fence);
836 NV_PRINTK(error, cli, "error fencing pushbuf: %d\n", ret);
842 validate_fini(&op, fence);
843 nouveau_fence_unref(&fence);
850 if (chan->dma.ib_max) {
851 req->suffix0 = 0x00000000;
852 req->suffix1 = 0x00000000;
854 if (drm->device.info.chipset >= 0x25) {
855 req->suffix0 = 0x00020000;
856 req->suffix1 = 0x00000000;
858 req->suffix0 = 0x20000000 |
859 (chan->push.vma.offset + ((chan->dma.cur + 2) << 2));
860 req->suffix1 = 0x00000000;
863 return nouveau_abi16_put(abi16, ret);
866 static inline uint32_t
867 domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain)
871 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
872 flags |= TTM_PL_FLAG_VRAM;
873 if (domain & NOUVEAU_GEM_DOMAIN_GART)
874 flags |= TTM_PL_FLAG_TT;
880 nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
881 struct drm_file *file_priv)
883 struct drm_nouveau_gem_cpu_prep *req = data;
884 struct drm_gem_object *gem;
885 struct nouveau_bo *nvbo;
886 bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
889 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
892 nvbo = nouveau_gem_object(gem);
894 spin_lock(&nvbo->bo.bdev->fence_lock);
895 ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait);
896 spin_unlock(&nvbo->bo.bdev->fence_lock);
897 drm_gem_object_unreference_unlocked(gem);
902 nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
903 struct drm_file *file_priv)
909 nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
910 struct drm_file *file_priv)
912 struct drm_nouveau_gem_info *req = data;
913 struct drm_gem_object *gem;
916 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
920 ret = nouveau_gem_info(file_priv, gem, req);
921 drm_gem_object_unreference_unlocked(gem);