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 <subdev/fb.h>
29 #include "nouveau_drm.h"
30 #include "nouveau_dma.h"
31 #include "nouveau_fence.h"
32 #include "nouveau_abi16.h"
34 #include "nouveau_ttm.h"
35 #include "nouveau_gem.h"
38 nouveau_gem_object_new(struct drm_gem_object *gem)
44 nouveau_gem_object_del(struct drm_gem_object *gem)
46 struct nouveau_bo *nvbo = gem->driver_private;
47 struct ttm_buffer_object *bo = &nvbo->bo;
53 /* Lockdep hates you for doing reserve with gem object lock held */
54 if (WARN_ON_ONCE(nvbo->pin_refcnt)) {
56 nouveau_bo_unpin(nvbo);
59 if (gem->import_attach)
60 drm_prime_gem_destroy(gem, nvbo->bo.sg);
64 drm_gem_object_release(gem);
69 nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
71 struct nouveau_cli *cli = nouveau_cli(file_priv);
72 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
73 struct nouveau_vma *vma;
79 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
83 vma = nouveau_bo_vma_find(nvbo, cli->base.vm);
85 vma = kzalloc(sizeof(*vma), GFP_KERNEL);
91 ret = nouveau_bo_vma_add(nvbo, cli->base.vm, vma);
101 ttm_bo_unreserve(&nvbo->bo);
106 nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
108 struct nouveau_cli *cli = nouveau_cli(file_priv);
109 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
110 struct nouveau_vma *vma;
116 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
120 vma = nouveau_bo_vma_find(nvbo, cli->base.vm);
122 if (--vma->refcount == 0) {
123 nouveau_bo_vma_del(nvbo, vma);
127 ttm_bo_unreserve(&nvbo->bo);
131 nouveau_gem_new(struct drm_device *dev, int size, int align, uint32_t domain,
132 uint32_t tile_mode, uint32_t tile_flags,
133 struct nouveau_bo **pnvbo)
135 struct nouveau_drm *drm = nouveau_drm(dev);
136 struct nouveau_bo *nvbo;
140 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
141 flags |= TTM_PL_FLAG_VRAM;
142 if (domain & NOUVEAU_GEM_DOMAIN_GART)
143 flags |= TTM_PL_FLAG_TT;
144 if (!flags || domain & NOUVEAU_GEM_DOMAIN_CPU)
145 flags |= TTM_PL_FLAG_SYSTEM;
147 ret = nouveau_bo_new(dev, size, align, flags, tile_mode,
148 tile_flags, NULL, pnvbo);
153 /* we restrict allowed domains on nv50+ to only the types
154 * that were requested at creation time. not possibly on
155 * earlier chips without busting the ABI.
157 nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM |
158 NOUVEAU_GEM_DOMAIN_GART;
159 if (nv_device(drm->device)->card_type >= NV_50)
160 nvbo->valid_domains &= domain;
162 nvbo->gem = drm_gem_object_alloc(dev, nvbo->bo.mem.size);
164 nouveau_bo_ref(NULL, pnvbo);
168 nvbo->bo.persistent_swap_storage = nvbo->gem->filp;
169 nvbo->gem->driver_private = nvbo;
174 nouveau_gem_info(struct drm_file *file_priv, struct drm_gem_object *gem,
175 struct drm_nouveau_gem_info *rep)
177 struct nouveau_cli *cli = nouveau_cli(file_priv);
178 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
179 struct nouveau_vma *vma;
181 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
182 rep->domain = NOUVEAU_GEM_DOMAIN_GART;
184 rep->domain = NOUVEAU_GEM_DOMAIN_VRAM;
186 rep->offset = nvbo->bo.offset;
188 vma = nouveau_bo_vma_find(nvbo, cli->base.vm);
192 rep->offset = vma->offset;
195 rep->size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
196 rep->map_handle = nvbo->bo.addr_space_offset;
197 rep->tile_mode = nvbo->tile_mode;
198 rep->tile_flags = nvbo->tile_flags;
203 nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
204 struct drm_file *file_priv)
206 struct nouveau_drm *drm = nouveau_drm(dev);
207 struct nouveau_cli *cli = nouveau_cli(file_priv);
208 struct nouveau_fb *pfb = nouveau_fb(drm->device);
209 struct drm_nouveau_gem_new *req = data;
210 struct nouveau_bo *nvbo = NULL;
213 drm->ttm.bdev.dev_mapping = drm->dev->dev_mapping;
215 if (!pfb->memtype_valid(pfb, req->info.tile_flags)) {
216 NV_ERROR(cli, "bad page flags: 0x%08x\n", req->info.tile_flags);
220 ret = nouveau_gem_new(dev, req->info.size, req->align,
221 req->info.domain, req->info.tile_mode,
222 req->info.tile_flags, &nvbo);
226 ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle);
228 ret = nouveau_gem_info(file_priv, nvbo->gem, &req->info);
230 drm_gem_handle_delete(file_priv, req->info.handle);
233 /* drop reference from allocate - handle holds it now */
234 drm_gem_object_unreference_unlocked(nvbo->gem);
239 nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains,
240 uint32_t write_domains, uint32_t valid_domains)
242 struct nouveau_bo *nvbo = gem->driver_private;
243 struct ttm_buffer_object *bo = &nvbo->bo;
244 uint32_t domains = valid_domains & nvbo->valid_domains &
245 (write_domains ? write_domains : read_domains);
246 uint32_t pref_flags = 0, valid_flags = 0;
251 if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
252 valid_flags |= TTM_PL_FLAG_VRAM;
254 if (valid_domains & NOUVEAU_GEM_DOMAIN_GART)
255 valid_flags |= TTM_PL_FLAG_TT;
257 if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
258 bo->mem.mem_type == TTM_PL_VRAM)
259 pref_flags |= TTM_PL_FLAG_VRAM;
261 else if ((domains & NOUVEAU_GEM_DOMAIN_GART) &&
262 bo->mem.mem_type == TTM_PL_TT)
263 pref_flags |= TTM_PL_FLAG_TT;
265 else if (domains & NOUVEAU_GEM_DOMAIN_VRAM)
266 pref_flags |= TTM_PL_FLAG_VRAM;
269 pref_flags |= TTM_PL_FLAG_TT;
271 nouveau_bo_placement_set(nvbo, pref_flags, valid_flags);
277 struct list_head vram_list;
278 struct list_head gart_list;
279 struct list_head both_list;
283 validate_fini_list(struct list_head *list, struct nouveau_fence *fence)
285 struct list_head *entry, *tmp;
286 struct nouveau_bo *nvbo;
288 list_for_each_safe(entry, tmp, list) {
289 nvbo = list_entry(entry, struct nouveau_bo, entry);
291 nouveau_bo_fence(nvbo, fence);
293 if (unlikely(nvbo->validate_mapped)) {
294 ttm_bo_kunmap(&nvbo->kmap);
295 nvbo->validate_mapped = false;
298 list_del(&nvbo->entry);
299 nvbo->reserved_by = NULL;
300 ttm_bo_unreserve(&nvbo->bo);
301 drm_gem_object_unreference_unlocked(nvbo->gem);
306 validate_fini(struct validate_op *op, struct nouveau_fence* fence)
308 validate_fini_list(&op->vram_list, fence);
309 validate_fini_list(&op->gart_list, fence);
310 validate_fini_list(&op->both_list, fence);
314 validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
315 struct drm_nouveau_gem_pushbuf_bo *pbbo,
316 int nr_buffers, struct validate_op *op)
318 struct nouveau_cli *cli = nouveau_cli(file_priv);
319 struct drm_device *dev = chan->drm->dev;
320 struct nouveau_drm *drm = nouveau_drm(dev);
324 struct nouveau_bo *res_bo = NULL;
326 sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
328 if (++trycnt > 100000) {
329 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
333 for (i = 0; i < nr_buffers; i++) {
334 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i];
335 struct drm_gem_object *gem;
336 struct nouveau_bo *nvbo;
338 gem = drm_gem_object_lookup(dev, file_priv, b->handle);
340 NV_ERROR(cli, "Unknown handle 0x%08x\n", b->handle);
341 validate_fini(op, NULL);
344 nvbo = gem->driver_private;
345 if (nvbo == res_bo) {
347 drm_gem_object_unreference_unlocked(gem);
351 if (nvbo->reserved_by && nvbo->reserved_by == file_priv) {
352 NV_ERROR(cli, "multiple instances of buffer %d on "
353 "validation list\n", b->handle);
354 drm_gem_object_unreference_unlocked(gem);
355 validate_fini(op, NULL);
359 ret = ttm_bo_reserve(&nvbo->bo, true, false, true, sequence);
361 validate_fini(op, NULL);
362 if (unlikely(ret == -EAGAIN)) {
363 sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
364 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
370 drm_gem_object_unreference_unlocked(gem);
371 if (ret != -ERESTARTSYS)
372 NV_ERROR(cli, "fail reserve\n");
377 b->user_priv = (uint64_t)(unsigned long)nvbo;
378 nvbo->reserved_by = file_priv;
379 nvbo->pbbo_index = i;
380 if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
381 (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART))
382 list_add_tail(&nvbo->entry, &op->both_list);
384 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
385 list_add_tail(&nvbo->entry, &op->vram_list);
387 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)
388 list_add_tail(&nvbo->entry, &op->gart_list);
390 NV_ERROR(cli, "invalid valid domains: 0x%08x\n",
392 list_add_tail(&nvbo->entry, &op->both_list);
393 validate_fini(op, NULL);
404 validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo)
406 struct nouveau_fence *fence = NULL;
409 spin_lock(&nvbo->bo.bdev->fence_lock);
410 if (nvbo->bo.sync_obj)
411 fence = nouveau_fence_ref(nvbo->bo.sync_obj);
412 spin_unlock(&nvbo->bo.bdev->fence_lock);
415 ret = nouveau_fence_sync(fence, chan);
416 nouveau_fence_unref(&fence);
423 validate_list(struct nouveau_channel *chan, struct nouveau_cli *cli,
424 struct list_head *list, struct drm_nouveau_gem_pushbuf_bo *pbbo,
425 uint64_t user_pbbo_ptr)
427 struct nouveau_drm *drm = chan->drm;
428 struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
429 (void __force __user *)(uintptr_t)user_pbbo_ptr;
430 struct nouveau_bo *nvbo;
433 list_for_each_entry(nvbo, list, entry) {
434 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index];
436 ret = validate_sync(chan, nvbo);
438 NV_ERROR(cli, "fail pre-validate sync\n");
442 ret = nouveau_gem_set_domain(nvbo->gem, b->read_domains,
446 NV_ERROR(cli, "fail set_domain\n");
450 ret = nouveau_bo_validate(nvbo, true, false);
452 if (ret != -ERESTARTSYS)
453 NV_ERROR(cli, "fail ttm_validate\n");
457 ret = validate_sync(chan, nvbo);
459 NV_ERROR(cli, "fail post-validate sync\n");
463 if (nv_device(drm->device)->card_type < NV_50) {
464 if (nvbo->bo.offset == b->presumed.offset &&
465 ((nvbo->bo.mem.mem_type == TTM_PL_VRAM &&
466 b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) ||
467 (nvbo->bo.mem.mem_type == TTM_PL_TT &&
468 b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART)))
471 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
472 b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART;
474 b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM;
475 b->presumed.offset = nvbo->bo.offset;
476 b->presumed.valid = 0;
479 if (DRM_COPY_TO_USER(&upbbo[nvbo->pbbo_index].presumed,
480 &b->presumed, sizeof(b->presumed)))
489 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
490 struct drm_file *file_priv,
491 struct drm_nouveau_gem_pushbuf_bo *pbbo,
492 uint64_t user_buffers, int nr_buffers,
493 struct validate_op *op, int *apply_relocs)
495 struct nouveau_cli *cli = nouveau_cli(file_priv);
498 INIT_LIST_HEAD(&op->vram_list);
499 INIT_LIST_HEAD(&op->gart_list);
500 INIT_LIST_HEAD(&op->both_list);
505 ret = validate_init(chan, file_priv, pbbo, nr_buffers, op);
507 if (ret != -ERESTARTSYS)
508 NV_ERROR(cli, "validate_init\n");
512 ret = validate_list(chan, cli, &op->vram_list, pbbo, user_buffers);
513 if (unlikely(ret < 0)) {
514 if (ret != -ERESTARTSYS)
515 NV_ERROR(cli, "validate vram_list\n");
516 validate_fini(op, NULL);
521 ret = validate_list(chan, cli, &op->gart_list, pbbo, user_buffers);
522 if (unlikely(ret < 0)) {
523 if (ret != -ERESTARTSYS)
524 NV_ERROR(cli, "validate gart_list\n");
525 validate_fini(op, NULL);
530 ret = validate_list(chan, cli, &op->both_list, pbbo, user_buffers);
531 if (unlikely(ret < 0)) {
532 if (ret != -ERESTARTSYS)
533 NV_ERROR(cli, "validate both_list\n");
534 validate_fini(op, NULL);
539 *apply_relocs = relocs;
544 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
547 void __user *userptr = (void __force __user *)(uintptr_t)user;
549 mem = kmalloc(nmemb * size, GFP_KERNEL);
551 return ERR_PTR(-ENOMEM);
553 if (DRM_COPY_FROM_USER(mem, userptr, nmemb * size)) {
555 return ERR_PTR(-EFAULT);
562 nouveau_gem_pushbuf_reloc_apply(struct nouveau_cli *cli,
563 struct drm_nouveau_gem_pushbuf *req,
564 struct drm_nouveau_gem_pushbuf_bo *bo)
566 struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
570 reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
572 return PTR_ERR(reloc);
574 for (i = 0; i < req->nr_relocs; i++) {
575 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
576 struct drm_nouveau_gem_pushbuf_bo *b;
577 struct nouveau_bo *nvbo;
580 if (unlikely(r->bo_index > req->nr_buffers)) {
581 NV_ERROR(cli, "reloc bo index invalid\n");
586 b = &bo[r->bo_index];
587 if (b->presumed.valid)
590 if (unlikely(r->reloc_bo_index > req->nr_buffers)) {
591 NV_ERROR(cli, "reloc container bo index invalid\n");
595 nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv;
597 if (unlikely(r->reloc_bo_offset + 4 >
598 nvbo->bo.mem.num_pages << PAGE_SHIFT)) {
599 NV_ERROR(cli, "reloc outside of bo\n");
604 if (!nvbo->kmap.virtual) {
605 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages,
608 NV_ERROR(cli, "failed kmap for reloc\n");
611 nvbo->validate_mapped = true;
614 if (r->flags & NOUVEAU_GEM_RELOC_LOW)
615 data = b->presumed.offset + r->data;
617 if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
618 data = (b->presumed.offset + r->data) >> 32;
622 if (r->flags & NOUVEAU_GEM_RELOC_OR) {
623 if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART)
629 spin_lock(&nvbo->bo.bdev->fence_lock);
630 ret = ttm_bo_wait(&nvbo->bo, false, false, false);
631 spin_unlock(&nvbo->bo.bdev->fence_lock);
633 NV_ERROR(cli, "reloc wait_idle failed: %d\n", ret);
637 nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
645 nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
646 struct drm_file *file_priv)
648 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
649 struct nouveau_cli *cli = nouveau_cli(file_priv);
650 struct nouveau_abi16_chan *temp;
651 struct nouveau_drm *drm = nouveau_drm(dev);
652 struct drm_nouveau_gem_pushbuf *req = data;
653 struct drm_nouveau_gem_pushbuf_push *push;
654 struct drm_nouveau_gem_pushbuf_bo *bo;
655 struct nouveau_channel *chan = NULL;
656 struct validate_op op;
657 struct nouveau_fence *fence = NULL;
658 int i, j, ret = 0, do_reloc = 0;
660 if (unlikely(!abi16))
663 list_for_each_entry(temp, &abi16->channels, head) {
664 if (temp->chan->handle == (NVDRM_CHAN | req->channel)) {
671 return nouveau_abi16_put(abi16, -ENOENT);
673 req->vram_available = drm->gem.vram_available;
674 req->gart_available = drm->gem.gart_available;
675 if (unlikely(req->nr_push == 0))
678 if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
679 NV_ERROR(cli, "pushbuf push count exceeds limit: %d max %d\n",
680 req->nr_push, NOUVEAU_GEM_MAX_PUSH);
681 return nouveau_abi16_put(abi16, -EINVAL);
684 if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
685 NV_ERROR(cli, "pushbuf bo count exceeds limit: %d max %d\n",
686 req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
687 return nouveau_abi16_put(abi16, -EINVAL);
690 if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
691 NV_ERROR(cli, "pushbuf reloc count exceeds limit: %d max %d\n",
692 req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
693 return nouveau_abi16_put(abi16, -EINVAL);
696 push = u_memcpya(req->push, req->nr_push, sizeof(*push));
698 return nouveau_abi16_put(abi16, PTR_ERR(push));
700 bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
703 return nouveau_abi16_put(abi16, PTR_ERR(bo));
706 /* Ensure all push buffers are on validate list */
707 for (i = 0; i < req->nr_push; i++) {
708 if (push[i].bo_index >= req->nr_buffers) {
709 NV_ERROR(cli, "push %d buffer not in list\n", i);
715 /* Validate buffer list */
716 ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
717 req->nr_buffers, &op, &do_reloc);
719 if (ret != -ERESTARTSYS)
720 NV_ERROR(cli, "validate: %d\n", ret);
724 /* Apply any relocations that are required */
726 ret = nouveau_gem_pushbuf_reloc_apply(cli, req, bo);
728 NV_ERROR(cli, "reloc apply: %d\n", ret);
733 if (chan->dma.ib_max) {
734 ret = nouveau_dma_wait(chan, req->nr_push + 1, 16);
736 NV_ERROR(cli, "nv50cal_space: %d\n", ret);
740 for (i = 0; i < req->nr_push; i++) {
741 struct nouveau_bo *nvbo = (void *)(unsigned long)
742 bo[push[i].bo_index].user_priv;
744 nv50_dma_push(chan, nvbo, push[i].offset,
748 if (nv_device(drm->device)->chipset >= 0x25) {
749 ret = RING_SPACE(chan, req->nr_push * 2);
751 NV_ERROR(cli, "cal_space: %d\n", ret);
755 for (i = 0; i < req->nr_push; i++) {
756 struct nouveau_bo *nvbo = (void *)(unsigned long)
757 bo[push[i].bo_index].user_priv;
759 OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2);
763 ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS));
765 NV_ERROR(cli, "jmp_space: %d\n", ret);
769 for (i = 0; i < req->nr_push; i++) {
770 struct nouveau_bo *nvbo = (void *)(unsigned long)
771 bo[push[i].bo_index].user_priv;
774 cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2);
776 if (unlikely(cmd != req->suffix0)) {
777 if (!nvbo->kmap.virtual) {
778 ret = ttm_bo_kmap(&nvbo->bo, 0,
786 nvbo->validate_mapped = true;
789 nouveau_bo_wr32(nvbo, (push[i].offset +
790 push[i].length - 8) / 4, cmd);
793 OUT_RING(chan, 0x20000000 |
794 (nvbo->bo.offset + push[i].offset));
796 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
801 ret = nouveau_fence_new(chan, false, &fence);
803 NV_ERROR(cli, "error fencing pushbuf: %d\n", ret);
809 validate_fini(&op, fence);
810 nouveau_fence_unref(&fence);
817 if (chan->dma.ib_max) {
818 req->suffix0 = 0x00000000;
819 req->suffix1 = 0x00000000;
821 if (nv_device(drm->device)->chipset >= 0x25) {
822 req->suffix0 = 0x00020000;
823 req->suffix1 = 0x00000000;
825 req->suffix0 = 0x20000000 |
826 (chan->push.vma.offset + ((chan->dma.cur + 2) << 2));
827 req->suffix1 = 0x00000000;
830 return nouveau_abi16_put(abi16, ret);
833 static inline uint32_t
834 domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain)
838 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
839 flags |= TTM_PL_FLAG_VRAM;
840 if (domain & NOUVEAU_GEM_DOMAIN_GART)
841 flags |= TTM_PL_FLAG_TT;
847 nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
848 struct drm_file *file_priv)
850 struct drm_nouveau_gem_cpu_prep *req = data;
851 struct drm_gem_object *gem;
852 struct nouveau_bo *nvbo;
853 bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
856 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
859 nvbo = nouveau_gem_object(gem);
861 spin_lock(&nvbo->bo.bdev->fence_lock);
862 ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait);
863 spin_unlock(&nvbo->bo.bdev->fence_lock);
864 drm_gem_object_unreference_unlocked(gem);
869 nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
870 struct drm_file *file_priv)
876 nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
877 struct drm_file *file_priv)
879 struct drm_nouveau_gem_info *req = data;
880 struct drm_gem_object *gem;
883 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
887 ret = nouveau_gem_info(file_priv, gem, req);
888 drm_gem_object_unreference_unlocked(gem);