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.
26 #include <linux/dma-buf.h>
29 #include "nouveau_drv.h"
30 #include <drm/nouveau_drm.h>
31 #include "nouveau_dma.h"
32 #include "nouveau_fence.h"
34 #define nouveau_gem_pushbuf_sync(chan) 0
37 nouveau_gem_object_new(struct drm_gem_object *gem)
43 nouveau_gem_object_del(struct drm_gem_object *gem)
45 struct nouveau_bo *nvbo = gem->driver_private;
46 struct ttm_buffer_object *bo = &nvbo->bo;
52 if (unlikely(nvbo->pin_refcnt)) {
54 nouveau_bo_unpin(nvbo);
57 if (gem->import_attach)
58 drm_prime_gem_destroy(gem, nvbo->bo.sg);
62 drm_gem_object_release(gem);
67 nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
69 struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv);
70 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
71 struct nouveau_vma *vma;
77 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
81 vma = nouveau_bo_vma_find(nvbo, fpriv->vm);
83 vma = kzalloc(sizeof(*vma), GFP_KERNEL);
89 ret = nouveau_bo_vma_add(nvbo, fpriv->vm, vma);
99 ttm_bo_unreserve(&nvbo->bo);
104 nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
106 struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv);
107 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
108 struct nouveau_vma *vma;
114 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
118 vma = nouveau_bo_vma_find(nvbo, fpriv->vm);
120 if (--vma->refcount == 0) {
121 nouveau_bo_vma_del(nvbo, vma);
125 ttm_bo_unreserve(&nvbo->bo);
129 nouveau_gem_new(struct drm_device *dev, int size, int align, uint32_t domain,
130 uint32_t tile_mode, uint32_t tile_flags,
131 struct nouveau_bo **pnvbo)
133 struct drm_nouveau_private *dev_priv = dev->dev_private;
134 struct nouveau_bo *nvbo;
138 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
139 flags |= TTM_PL_FLAG_VRAM;
140 if (domain & NOUVEAU_GEM_DOMAIN_GART)
141 flags |= TTM_PL_FLAG_TT;
142 if (!flags || domain & NOUVEAU_GEM_DOMAIN_CPU)
143 flags |= TTM_PL_FLAG_SYSTEM;
145 ret = nouveau_bo_new(dev, size, align, flags, tile_mode,
146 tile_flags, NULL, pnvbo);
151 /* we restrict allowed domains on nv50+ to only the types
152 * that were requested at creation time. not possibly on
153 * earlier chips without busting the ABI.
155 nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM |
156 NOUVEAU_GEM_DOMAIN_GART;
157 if (dev_priv->card_type >= NV_50)
158 nvbo->valid_domains &= domain;
160 nvbo->gem = drm_gem_object_alloc(dev, nvbo->bo.mem.size);
162 nouveau_bo_ref(NULL, pnvbo);
166 nvbo->bo.persistent_swap_storage = nvbo->gem->filp;
167 nvbo->gem->driver_private = nvbo;
172 nouveau_gem_info(struct drm_file *file_priv, struct drm_gem_object *gem,
173 struct drm_nouveau_gem_info *rep)
175 struct nouveau_fpriv *fpriv = nouveau_fpriv(file_priv);
176 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
177 struct nouveau_vma *vma;
179 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
180 rep->domain = NOUVEAU_GEM_DOMAIN_GART;
182 rep->domain = NOUVEAU_GEM_DOMAIN_VRAM;
184 rep->offset = nvbo->bo.offset;
186 vma = nouveau_bo_vma_find(nvbo, fpriv->vm);
190 rep->offset = vma->offset;
193 rep->size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
194 rep->map_handle = nvbo->bo.addr_space_offset;
195 rep->tile_mode = nvbo->tile_mode;
196 rep->tile_flags = nvbo->tile_flags;
201 nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
202 struct drm_file *file_priv)
204 struct drm_nouveau_private *dev_priv = dev->dev_private;
205 struct drm_nouveau_gem_new *req = data;
206 struct nouveau_bo *nvbo = NULL;
209 dev_priv->ttm.bdev.dev_mapping = dev->dev_mapping;
211 if (!dev_priv->engine.vram.flags_valid(dev, req->info.tile_flags)) {
212 NV_ERROR(dev, "bad page flags: 0x%08x\n", req->info.tile_flags);
216 ret = nouveau_gem_new(dev, req->info.size, req->align,
217 req->info.domain, req->info.tile_mode,
218 req->info.tile_flags, &nvbo);
222 ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle);
224 ret = nouveau_gem_info(file_priv, nvbo->gem, &req->info);
226 drm_gem_handle_delete(file_priv, req->info.handle);
229 /* drop reference from allocate - handle holds it now */
230 drm_gem_object_unreference_unlocked(nvbo->gem);
235 nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains,
236 uint32_t write_domains, uint32_t valid_domains)
238 struct nouveau_bo *nvbo = gem->driver_private;
239 struct ttm_buffer_object *bo = &nvbo->bo;
240 uint32_t domains = valid_domains & nvbo->valid_domains &
241 (write_domains ? write_domains : read_domains);
242 uint32_t pref_flags = 0, valid_flags = 0;
247 if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
248 valid_flags |= TTM_PL_FLAG_VRAM;
250 if (valid_domains & NOUVEAU_GEM_DOMAIN_GART)
251 valid_flags |= TTM_PL_FLAG_TT;
253 if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
254 bo->mem.mem_type == TTM_PL_VRAM)
255 pref_flags |= TTM_PL_FLAG_VRAM;
257 else if ((domains & NOUVEAU_GEM_DOMAIN_GART) &&
258 bo->mem.mem_type == TTM_PL_TT)
259 pref_flags |= TTM_PL_FLAG_TT;
261 else if (domains & NOUVEAU_GEM_DOMAIN_VRAM)
262 pref_flags |= TTM_PL_FLAG_VRAM;
265 pref_flags |= TTM_PL_FLAG_TT;
267 nouveau_bo_placement_set(nvbo, pref_flags, valid_flags);
273 struct list_head vram_list;
274 struct list_head gart_list;
275 struct list_head both_list;
279 validate_fini_list(struct list_head *list, struct nouveau_fence *fence)
281 struct list_head *entry, *tmp;
282 struct nouveau_bo *nvbo;
284 list_for_each_safe(entry, tmp, list) {
285 nvbo = list_entry(entry, struct nouveau_bo, entry);
287 nouveau_bo_fence(nvbo, fence);
289 if (unlikely(nvbo->validate_mapped)) {
290 ttm_bo_kunmap(&nvbo->kmap);
291 nvbo->validate_mapped = false;
294 list_del(&nvbo->entry);
295 nvbo->reserved_by = NULL;
296 ttm_bo_unreserve(&nvbo->bo);
297 drm_gem_object_unreference_unlocked(nvbo->gem);
302 validate_fini(struct validate_op *op, struct nouveau_fence* fence)
304 validate_fini_list(&op->vram_list, fence);
305 validate_fini_list(&op->gart_list, fence);
306 validate_fini_list(&op->both_list, fence);
310 validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
311 struct drm_nouveau_gem_pushbuf_bo *pbbo,
312 int nr_buffers, struct validate_op *op)
314 struct drm_device *dev = chan->dev;
315 struct drm_nouveau_private *dev_priv = dev->dev_private;
320 sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
322 if (++trycnt > 100000) {
323 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
327 for (i = 0; i < nr_buffers; i++) {
328 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i];
329 struct drm_gem_object *gem;
330 struct nouveau_bo *nvbo;
332 gem = drm_gem_object_lookup(dev, file_priv, b->handle);
334 NV_ERROR(dev, "Unknown handle 0x%08x\n", b->handle);
335 validate_fini(op, NULL);
338 nvbo = gem->driver_private;
340 if (nvbo->reserved_by && nvbo->reserved_by == file_priv) {
341 NV_ERROR(dev, "multiple instances of buffer %d on "
342 "validation list\n", b->handle);
343 drm_gem_object_unreference_unlocked(gem);
344 validate_fini(op, NULL);
348 ret = ttm_bo_reserve(&nvbo->bo, true, false, true, sequence);
350 validate_fini(op, NULL);
351 if (unlikely(ret == -EAGAIN))
352 ret = ttm_bo_wait_unreserved(&nvbo->bo, true);
353 drm_gem_object_unreference_unlocked(gem);
355 if (ret != -ERESTARTSYS)
356 NV_ERROR(dev, "fail reserve\n");
362 b->user_priv = (uint64_t)(unsigned long)nvbo;
363 nvbo->reserved_by = file_priv;
364 nvbo->pbbo_index = i;
365 if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
366 (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART))
367 list_add_tail(&nvbo->entry, &op->both_list);
369 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
370 list_add_tail(&nvbo->entry, &op->vram_list);
372 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)
373 list_add_tail(&nvbo->entry, &op->gart_list);
375 NV_ERROR(dev, "invalid valid domains: 0x%08x\n",
377 list_add_tail(&nvbo->entry, &op->both_list);
378 validate_fini(op, NULL);
387 validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo)
389 struct nouveau_fence *fence = NULL;
392 spin_lock(&nvbo->bo.bdev->fence_lock);
393 if (nvbo->bo.sync_obj)
394 fence = nouveau_fence_ref(nvbo->bo.sync_obj);
395 spin_unlock(&nvbo->bo.bdev->fence_lock);
398 ret = nouveau_fence_sync(fence, chan);
399 nouveau_fence_unref(&fence);
406 validate_list(struct nouveau_channel *chan, struct list_head *list,
407 struct drm_nouveau_gem_pushbuf_bo *pbbo, uint64_t user_pbbo_ptr)
409 struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
410 struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
411 (void __force __user *)(uintptr_t)user_pbbo_ptr;
412 struct drm_device *dev = chan->dev;
413 struct nouveau_bo *nvbo;
416 list_for_each_entry(nvbo, list, entry) {
417 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index];
419 ret = validate_sync(chan, nvbo);
421 NV_ERROR(dev, "fail pre-validate sync\n");
425 ret = nouveau_gem_set_domain(nvbo->gem, b->read_domains,
429 NV_ERROR(dev, "fail set_domain\n");
433 ret = nouveau_bo_validate(nvbo, true, false, false);
435 if (ret != -ERESTARTSYS)
436 NV_ERROR(dev, "fail ttm_validate\n");
440 ret = validate_sync(chan, nvbo);
442 NV_ERROR(dev, "fail post-validate sync\n");
446 if (dev_priv->card_type < NV_50) {
447 if (nvbo->bo.offset == b->presumed.offset &&
448 ((nvbo->bo.mem.mem_type == TTM_PL_VRAM &&
449 b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) ||
450 (nvbo->bo.mem.mem_type == TTM_PL_TT &&
451 b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART)))
454 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
455 b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART;
457 b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM;
458 b->presumed.offset = nvbo->bo.offset;
459 b->presumed.valid = 0;
462 if (DRM_COPY_TO_USER(&upbbo[nvbo->pbbo_index].presumed,
463 &b->presumed, sizeof(b->presumed)))
472 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
473 struct drm_file *file_priv,
474 struct drm_nouveau_gem_pushbuf_bo *pbbo,
475 uint64_t user_buffers, int nr_buffers,
476 struct validate_op *op, int *apply_relocs)
478 struct drm_device *dev = chan->dev;
481 INIT_LIST_HEAD(&op->vram_list);
482 INIT_LIST_HEAD(&op->gart_list);
483 INIT_LIST_HEAD(&op->both_list);
488 ret = validate_init(chan, file_priv, pbbo, nr_buffers, op);
490 if (ret != -ERESTARTSYS)
491 NV_ERROR(dev, "validate_init\n");
495 ret = validate_list(chan, &op->vram_list, pbbo, user_buffers);
496 if (unlikely(ret < 0)) {
497 if (ret != -ERESTARTSYS)
498 NV_ERROR(dev, "validate vram_list\n");
499 validate_fini(op, NULL);
504 ret = validate_list(chan, &op->gart_list, pbbo, user_buffers);
505 if (unlikely(ret < 0)) {
506 if (ret != -ERESTARTSYS)
507 NV_ERROR(dev, "validate gart_list\n");
508 validate_fini(op, NULL);
513 ret = validate_list(chan, &op->both_list, pbbo, user_buffers);
514 if (unlikely(ret < 0)) {
515 if (ret != -ERESTARTSYS)
516 NV_ERROR(dev, "validate both_list\n");
517 validate_fini(op, NULL);
522 *apply_relocs = relocs;
527 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
530 void __user *userptr = (void __force __user *)(uintptr_t)user;
532 mem = kmalloc(nmemb * size, GFP_KERNEL);
534 return ERR_PTR(-ENOMEM);
536 if (DRM_COPY_FROM_USER(mem, userptr, nmemb * size)) {
538 return ERR_PTR(-EFAULT);
545 nouveau_gem_pushbuf_reloc_apply(struct drm_device *dev,
546 struct drm_nouveau_gem_pushbuf *req,
547 struct drm_nouveau_gem_pushbuf_bo *bo)
549 struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
553 reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
555 return PTR_ERR(reloc);
557 for (i = 0; i < req->nr_relocs; i++) {
558 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
559 struct drm_nouveau_gem_pushbuf_bo *b;
560 struct nouveau_bo *nvbo;
563 if (unlikely(r->bo_index > req->nr_buffers)) {
564 NV_ERROR(dev, "reloc bo index invalid\n");
569 b = &bo[r->bo_index];
570 if (b->presumed.valid)
573 if (unlikely(r->reloc_bo_index > req->nr_buffers)) {
574 NV_ERROR(dev, "reloc container bo index invalid\n");
578 nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv;
580 if (unlikely(r->reloc_bo_offset + 4 >
581 nvbo->bo.mem.num_pages << PAGE_SHIFT)) {
582 NV_ERROR(dev, "reloc outside of bo\n");
587 if (!nvbo->kmap.virtual) {
588 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages,
591 NV_ERROR(dev, "failed kmap for reloc\n");
594 nvbo->validate_mapped = true;
597 if (r->flags & NOUVEAU_GEM_RELOC_LOW)
598 data = b->presumed.offset + r->data;
600 if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
601 data = (b->presumed.offset + r->data) >> 32;
605 if (r->flags & NOUVEAU_GEM_RELOC_OR) {
606 if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART)
612 spin_lock(&nvbo->bo.bdev->fence_lock);
613 ret = ttm_bo_wait(&nvbo->bo, false, false, false);
614 spin_unlock(&nvbo->bo.bdev->fence_lock);
616 NV_ERROR(dev, "reloc wait_idle failed: %d\n", ret);
620 nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
628 nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
629 struct drm_file *file_priv)
631 struct drm_nouveau_private *dev_priv = dev->dev_private;
632 struct drm_nouveau_gem_pushbuf *req = data;
633 struct drm_nouveau_gem_pushbuf_push *push;
634 struct drm_nouveau_gem_pushbuf_bo *bo;
635 struct nouveau_channel *chan;
636 struct validate_op op;
637 struct nouveau_fence *fence = NULL;
638 int i, j, ret = 0, do_reloc = 0;
640 chan = nouveau_channel_get(file_priv, req->channel);
642 return PTR_ERR(chan);
644 req->vram_available = dev_priv->fb_aper_free;
645 req->gart_available = dev_priv->gart_info.aper_free;
646 if (unlikely(req->nr_push == 0))
649 if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
650 NV_ERROR(dev, "pushbuf push count exceeds limit: %d max %d\n",
651 req->nr_push, NOUVEAU_GEM_MAX_PUSH);
652 nouveau_channel_put(&chan);
656 if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
657 NV_ERROR(dev, "pushbuf bo count exceeds limit: %d max %d\n",
658 req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
659 nouveau_channel_put(&chan);
663 if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
664 NV_ERROR(dev, "pushbuf reloc count exceeds limit: %d max %d\n",
665 req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
666 nouveau_channel_put(&chan);
670 push = u_memcpya(req->push, req->nr_push, sizeof(*push));
672 nouveau_channel_put(&chan);
673 return PTR_ERR(push);
676 bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
679 nouveau_channel_put(&chan);
683 /* Ensure all push buffers are on validate list */
684 for (i = 0; i < req->nr_push; i++) {
685 if (push[i].bo_index >= req->nr_buffers) {
686 NV_ERROR(dev, "push %d buffer not in list\n", i);
692 /* Validate buffer list */
693 ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
694 req->nr_buffers, &op, &do_reloc);
696 if (ret != -ERESTARTSYS)
697 NV_ERROR(dev, "validate: %d\n", ret);
701 /* Apply any relocations that are required */
703 ret = nouveau_gem_pushbuf_reloc_apply(dev, req, bo);
705 NV_ERROR(dev, "reloc apply: %d\n", ret);
710 if (chan->dma.ib_max) {
711 ret = nouveau_dma_wait(chan, req->nr_push + 1, 16);
713 NV_INFO(dev, "nv50cal_space: %d\n", ret);
717 for (i = 0; i < req->nr_push; i++) {
718 struct nouveau_bo *nvbo = (void *)(unsigned long)
719 bo[push[i].bo_index].user_priv;
721 nv50_dma_push(chan, nvbo, push[i].offset,
725 if (dev_priv->chipset >= 0x25) {
726 ret = RING_SPACE(chan, req->nr_push * 2);
728 NV_ERROR(dev, "cal_space: %d\n", ret);
732 for (i = 0; i < req->nr_push; i++) {
733 struct nouveau_bo *nvbo = (void *)(unsigned long)
734 bo[push[i].bo_index].user_priv;
735 struct drm_mm_node *mem = nvbo->bo.mem.mm_node;
737 OUT_RING(chan, ((mem->start << PAGE_SHIFT) +
738 push[i].offset) | 2);
742 ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS));
744 NV_ERROR(dev, "jmp_space: %d\n", ret);
748 for (i = 0; i < req->nr_push; i++) {
749 struct nouveau_bo *nvbo = (void *)(unsigned long)
750 bo[push[i].bo_index].user_priv;
751 struct drm_mm_node *mem = nvbo->bo.mem.mm_node;
754 cmd = chan->pushbuf_base + ((chan->dma.cur + 2) << 2);
756 if (unlikely(cmd != req->suffix0)) {
757 if (!nvbo->kmap.virtual) {
758 ret = ttm_bo_kmap(&nvbo->bo, 0,
766 nvbo->validate_mapped = true;
769 nouveau_bo_wr32(nvbo, (push[i].offset +
770 push[i].length - 8) / 4, cmd);
773 OUT_RING(chan, ((mem->start << PAGE_SHIFT) +
774 push[i].offset) | 0x20000000);
776 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
781 ret = nouveau_fence_new(chan, &fence);
783 NV_ERROR(dev, "error fencing pushbuf: %d\n", ret);
789 validate_fini(&op, fence);
790 nouveau_fence_unref(&fence);
797 if (chan->dma.ib_max) {
798 req->suffix0 = 0x00000000;
799 req->suffix1 = 0x00000000;
801 if (dev_priv->chipset >= 0x25) {
802 req->suffix0 = 0x00020000;
803 req->suffix1 = 0x00000000;
805 req->suffix0 = 0x20000000 |
806 (chan->pushbuf_base + ((chan->dma.cur + 2) << 2));
807 req->suffix1 = 0x00000000;
810 nouveau_channel_put(&chan);
814 static inline uint32_t
815 domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain)
819 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
820 flags |= TTM_PL_FLAG_VRAM;
821 if (domain & NOUVEAU_GEM_DOMAIN_GART)
822 flags |= TTM_PL_FLAG_TT;
828 nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
829 struct drm_file *file_priv)
831 struct drm_nouveau_gem_cpu_prep *req = data;
832 struct drm_gem_object *gem;
833 struct nouveau_bo *nvbo;
834 bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
837 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
840 nvbo = nouveau_gem_object(gem);
842 spin_lock(&nvbo->bo.bdev->fence_lock);
843 ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait);
844 spin_unlock(&nvbo->bo.bdev->fence_lock);
845 drm_gem_object_unreference_unlocked(gem);
850 nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
851 struct drm_file *file_priv)
857 nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
858 struct drm_file *file_priv)
860 struct drm_nouveau_gem_info *req = data;
861 struct drm_gem_object *gem;
864 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
868 ret = nouveau_gem_info(file_priv, gem, req);
869 drm_gem_object_unreference_unlocked(gem);