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 <linux/dma-buf.h>
29 #include <subdev/fb.h>
31 #include "nouveau_drm.h"
32 #include "nouveau_dma.h"
33 #include "nouveau_fence.h"
34 #include "nouveau_abi16.h"
36 #include "nouveau_ttm.h"
37 #include "nouveau_gem.h"
40 nouveau_gem_object_new(struct drm_gem_object *gem)
46 nouveau_gem_object_del(struct drm_gem_object *gem)
48 struct nouveau_bo *nvbo = gem->driver_private;
49 struct ttm_buffer_object *bo = &nvbo->bo;
55 if (unlikely(nvbo->pin_refcnt)) {
57 nouveau_bo_unpin(nvbo);
60 if (gem->import_attach)
61 drm_prime_gem_destroy(gem, nvbo->bo.sg);
65 drm_gem_object_release(gem);
70 nouveau_gem_object_open(struct drm_gem_object *gem, struct drm_file *file_priv)
72 struct nouveau_cli *cli = nouveau_cli(file_priv);
73 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
74 struct nouveau_vma *vma;
80 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
84 vma = nouveau_bo_vma_find(nvbo, cli->base.vm);
86 vma = kzalloc(sizeof(*vma), GFP_KERNEL);
92 ret = nouveau_bo_vma_add(nvbo, cli->base.vm, vma);
102 ttm_bo_unreserve(&nvbo->bo);
107 nouveau_gem_object_close(struct drm_gem_object *gem, struct drm_file *file_priv)
109 struct nouveau_cli *cli = nouveau_cli(file_priv);
110 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
111 struct nouveau_vma *vma;
117 ret = ttm_bo_reserve(&nvbo->bo, false, false, false, 0);
121 vma = nouveau_bo_vma_find(nvbo, cli->base.vm);
123 if (--vma->refcount == 0) {
124 nouveau_bo_vma_del(nvbo, vma);
128 ttm_bo_unreserve(&nvbo->bo);
132 nouveau_gem_new(struct drm_device *dev, int size, int align, uint32_t domain,
133 uint32_t tile_mode, uint32_t tile_flags,
134 struct nouveau_bo **pnvbo)
136 struct nouveau_drm *drm = nouveau_drm(dev);
137 struct nouveau_bo *nvbo;
141 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
142 flags |= TTM_PL_FLAG_VRAM;
143 if (domain & NOUVEAU_GEM_DOMAIN_GART)
144 flags |= TTM_PL_FLAG_TT;
145 if (!flags || domain & NOUVEAU_GEM_DOMAIN_CPU)
146 flags |= TTM_PL_FLAG_SYSTEM;
148 ret = nouveau_bo_new(dev, size, align, flags, tile_mode,
149 tile_flags, NULL, pnvbo);
154 /* we restrict allowed domains on nv50+ to only the types
155 * that were requested at creation time. not possibly on
156 * earlier chips without busting the ABI.
158 nvbo->valid_domains = NOUVEAU_GEM_DOMAIN_VRAM |
159 NOUVEAU_GEM_DOMAIN_GART;
160 if (nv_device(drm->device)->card_type >= NV_50)
161 nvbo->valid_domains &= domain;
163 nvbo->gem = drm_gem_object_alloc(dev, nvbo->bo.mem.size);
165 nouveau_bo_ref(NULL, pnvbo);
169 nvbo->bo.persistent_swap_storage = nvbo->gem->filp;
170 nvbo->gem->driver_private = nvbo;
175 nouveau_gem_info(struct drm_file *file_priv, struct drm_gem_object *gem,
176 struct drm_nouveau_gem_info *rep)
178 struct nouveau_cli *cli = nouveau_cli(file_priv);
179 struct nouveau_bo *nvbo = nouveau_gem_object(gem);
180 struct nouveau_vma *vma;
182 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
183 rep->domain = NOUVEAU_GEM_DOMAIN_GART;
185 rep->domain = NOUVEAU_GEM_DOMAIN_VRAM;
187 rep->offset = nvbo->bo.offset;
189 vma = nouveau_bo_vma_find(nvbo, cli->base.vm);
193 rep->offset = vma->offset;
196 rep->size = nvbo->bo.mem.num_pages << PAGE_SHIFT;
197 rep->map_handle = nvbo->bo.addr_space_offset;
198 rep->tile_mode = nvbo->tile_mode;
199 rep->tile_flags = nvbo->tile_flags;
204 nouveau_gem_ioctl_new(struct drm_device *dev, void *data,
205 struct drm_file *file_priv)
207 struct nouveau_drm *drm = nouveau_drm(dev);
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(drm, "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 drm_device *dev = chan->drm->dev;
319 struct nouveau_drm *drm = nouveau_drm(dev);
324 sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
326 if (++trycnt > 100000) {
327 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
331 for (i = 0; i < nr_buffers; i++) {
332 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[i];
333 struct drm_gem_object *gem;
334 struct nouveau_bo *nvbo;
336 gem = drm_gem_object_lookup(dev, file_priv, b->handle);
338 NV_ERROR(drm, "Unknown handle 0x%08x\n", b->handle);
339 validate_fini(op, NULL);
342 nvbo = gem->driver_private;
344 if (nvbo->reserved_by && nvbo->reserved_by == file_priv) {
345 NV_ERROR(drm, "multiple instances of buffer %d on "
346 "validation list\n", b->handle);
347 drm_gem_object_unreference_unlocked(gem);
348 validate_fini(op, NULL);
352 ret = ttm_bo_reserve(&nvbo->bo, true, false, true, sequence);
354 validate_fini(op, NULL);
355 if (unlikely(ret == -EAGAIN))
356 ret = ttm_bo_wait_unreserved(&nvbo->bo, true);
357 drm_gem_object_unreference_unlocked(gem);
359 if (ret != -ERESTARTSYS)
360 NV_ERROR(drm, "fail reserve\n");
366 b->user_priv = (uint64_t)(unsigned long)nvbo;
367 nvbo->reserved_by = file_priv;
368 nvbo->pbbo_index = i;
369 if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) &&
370 (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART))
371 list_add_tail(&nvbo->entry, &op->both_list);
373 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM)
374 list_add_tail(&nvbo->entry, &op->vram_list);
376 if (b->valid_domains & NOUVEAU_GEM_DOMAIN_GART)
377 list_add_tail(&nvbo->entry, &op->gart_list);
379 NV_ERROR(drm, "invalid valid domains: 0x%08x\n",
381 list_add_tail(&nvbo->entry, &op->both_list);
382 validate_fini(op, NULL);
391 validate_sync(struct nouveau_channel *chan, struct nouveau_bo *nvbo)
393 struct nouveau_fence *fence = NULL;
396 spin_lock(&nvbo->bo.bdev->fence_lock);
397 if (nvbo->bo.sync_obj)
398 fence = nouveau_fence_ref(nvbo->bo.sync_obj);
399 spin_unlock(&nvbo->bo.bdev->fence_lock);
402 ret = nouveau_fence_sync(fence, chan);
403 nouveau_fence_unref(&fence);
410 validate_list(struct nouveau_channel *chan, struct list_head *list,
411 struct drm_nouveau_gem_pushbuf_bo *pbbo, uint64_t user_pbbo_ptr)
413 struct nouveau_drm *drm = chan->drm;
414 struct drm_nouveau_gem_pushbuf_bo __user *upbbo =
415 (void __force __user *)(uintptr_t)user_pbbo_ptr;
416 struct nouveau_bo *nvbo;
419 list_for_each_entry(nvbo, list, entry) {
420 struct drm_nouveau_gem_pushbuf_bo *b = &pbbo[nvbo->pbbo_index];
422 ret = validate_sync(chan, nvbo);
424 NV_ERROR(drm, "fail pre-validate sync\n");
428 ret = nouveau_gem_set_domain(nvbo->gem, b->read_domains,
432 NV_ERROR(drm, "fail set_domain\n");
436 ret = nouveau_bo_validate(nvbo, true, false);
438 if (ret != -ERESTARTSYS)
439 NV_ERROR(drm, "fail ttm_validate\n");
443 ret = validate_sync(chan, nvbo);
445 NV_ERROR(drm, "fail post-validate sync\n");
449 if (nv_device(drm->device)->card_type < NV_50) {
450 if (nvbo->bo.offset == b->presumed.offset &&
451 ((nvbo->bo.mem.mem_type == TTM_PL_VRAM &&
452 b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) ||
453 (nvbo->bo.mem.mem_type == TTM_PL_TT &&
454 b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART)))
457 if (nvbo->bo.mem.mem_type == TTM_PL_TT)
458 b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART;
460 b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM;
461 b->presumed.offset = nvbo->bo.offset;
462 b->presumed.valid = 0;
465 if (DRM_COPY_TO_USER(&upbbo[nvbo->pbbo_index].presumed,
466 &b->presumed, sizeof(b->presumed)))
475 nouveau_gem_pushbuf_validate(struct nouveau_channel *chan,
476 struct drm_file *file_priv,
477 struct drm_nouveau_gem_pushbuf_bo *pbbo,
478 uint64_t user_buffers, int nr_buffers,
479 struct validate_op *op, int *apply_relocs)
481 struct nouveau_drm *drm = chan->drm;
484 INIT_LIST_HEAD(&op->vram_list);
485 INIT_LIST_HEAD(&op->gart_list);
486 INIT_LIST_HEAD(&op->both_list);
491 ret = validate_init(chan, file_priv, pbbo, nr_buffers, op);
493 if (ret != -ERESTARTSYS)
494 NV_ERROR(drm, "validate_init\n");
498 ret = validate_list(chan, &op->vram_list, pbbo, user_buffers);
499 if (unlikely(ret < 0)) {
500 if (ret != -ERESTARTSYS)
501 NV_ERROR(drm, "validate vram_list\n");
502 validate_fini(op, NULL);
507 ret = validate_list(chan, &op->gart_list, pbbo, user_buffers);
508 if (unlikely(ret < 0)) {
509 if (ret != -ERESTARTSYS)
510 NV_ERROR(drm, "validate gart_list\n");
511 validate_fini(op, NULL);
516 ret = validate_list(chan, &op->both_list, pbbo, user_buffers);
517 if (unlikely(ret < 0)) {
518 if (ret != -ERESTARTSYS)
519 NV_ERROR(drm, "validate both_list\n");
520 validate_fini(op, NULL);
525 *apply_relocs = relocs;
530 u_memcpya(uint64_t user, unsigned nmemb, unsigned size)
533 void __user *userptr = (void __force __user *)(uintptr_t)user;
535 mem = kmalloc(nmemb * size, GFP_KERNEL);
537 return ERR_PTR(-ENOMEM);
539 if (DRM_COPY_FROM_USER(mem, userptr, nmemb * size)) {
541 return ERR_PTR(-EFAULT);
548 nouveau_gem_pushbuf_reloc_apply(struct drm_device *dev,
549 struct drm_nouveau_gem_pushbuf *req,
550 struct drm_nouveau_gem_pushbuf_bo *bo)
552 struct nouveau_drm *drm = nouveau_drm(dev);
553 struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL;
557 reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc));
559 return PTR_ERR(reloc);
561 for (i = 0; i < req->nr_relocs; i++) {
562 struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i];
563 struct drm_nouveau_gem_pushbuf_bo *b;
564 struct nouveau_bo *nvbo;
567 if (unlikely(r->bo_index > req->nr_buffers)) {
568 NV_ERROR(drm, "reloc bo index invalid\n");
573 b = &bo[r->bo_index];
574 if (b->presumed.valid)
577 if (unlikely(r->reloc_bo_index > req->nr_buffers)) {
578 NV_ERROR(drm, "reloc container bo index invalid\n");
582 nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv;
584 if (unlikely(r->reloc_bo_offset + 4 >
585 nvbo->bo.mem.num_pages << PAGE_SHIFT)) {
586 NV_ERROR(drm, "reloc outside of bo\n");
591 if (!nvbo->kmap.virtual) {
592 ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages,
595 NV_ERROR(drm, "failed kmap for reloc\n");
598 nvbo->validate_mapped = true;
601 if (r->flags & NOUVEAU_GEM_RELOC_LOW)
602 data = b->presumed.offset + r->data;
604 if (r->flags & NOUVEAU_GEM_RELOC_HIGH)
605 data = (b->presumed.offset + r->data) >> 32;
609 if (r->flags & NOUVEAU_GEM_RELOC_OR) {
610 if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART)
616 spin_lock(&nvbo->bo.bdev->fence_lock);
617 ret = ttm_bo_wait(&nvbo->bo, false, false, false);
618 spin_unlock(&nvbo->bo.bdev->fence_lock);
620 NV_ERROR(drm, "reloc wait_idle failed: %d\n", ret);
624 nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data);
632 nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data,
633 struct drm_file *file_priv)
635 struct nouveau_abi16 *abi16 = nouveau_abi16_get(file_priv, dev);
636 struct nouveau_abi16_chan *temp;
637 struct nouveau_drm *drm = nouveau_drm(dev);
638 struct drm_nouveau_gem_pushbuf *req = data;
639 struct drm_nouveau_gem_pushbuf_push *push;
640 struct drm_nouveau_gem_pushbuf_bo *bo;
641 struct nouveau_channel *chan = NULL;
642 struct validate_op op;
643 struct nouveau_fence *fence = NULL;
644 int i, j, ret = 0, do_reloc = 0;
646 if (unlikely(!abi16))
649 list_for_each_entry(temp, &abi16->channels, head) {
650 if (temp->chan->handle == (NVDRM_CHAN | req->channel)) {
657 return nouveau_abi16_put(abi16, -ENOENT);
659 req->vram_available = drm->gem.vram_available;
660 req->gart_available = drm->gem.gart_available;
661 if (unlikely(req->nr_push == 0))
664 if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) {
665 NV_ERROR(drm, "pushbuf push count exceeds limit: %d max %d\n",
666 req->nr_push, NOUVEAU_GEM_MAX_PUSH);
667 return nouveau_abi16_put(abi16, -EINVAL);
670 if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) {
671 NV_ERROR(drm, "pushbuf bo count exceeds limit: %d max %d\n",
672 req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS);
673 return nouveau_abi16_put(abi16, -EINVAL);
676 if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) {
677 NV_ERROR(drm, "pushbuf reloc count exceeds limit: %d max %d\n",
678 req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS);
679 return nouveau_abi16_put(abi16, -EINVAL);
682 push = u_memcpya(req->push, req->nr_push, sizeof(*push));
684 return nouveau_abi16_put(abi16, PTR_ERR(push));
686 bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo));
689 return nouveau_abi16_put(abi16, PTR_ERR(bo));
692 /* Ensure all push buffers are on validate list */
693 for (i = 0; i < req->nr_push; i++) {
694 if (push[i].bo_index >= req->nr_buffers) {
695 NV_ERROR(drm, "push %d buffer not in list\n", i);
701 /* Validate buffer list */
702 ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers,
703 req->nr_buffers, &op, &do_reloc);
705 if (ret != -ERESTARTSYS)
706 NV_ERROR(drm, "validate: %d\n", ret);
710 /* Apply any relocations that are required */
712 ret = nouveau_gem_pushbuf_reloc_apply(dev, req, bo);
714 NV_ERROR(drm, "reloc apply: %d\n", ret);
719 if (chan->dma.ib_max) {
720 ret = nouveau_dma_wait(chan, req->nr_push + 1, 16);
722 NV_ERROR(drm, "nv50cal_space: %d\n", ret);
726 for (i = 0; i < req->nr_push; i++) {
727 struct nouveau_bo *nvbo = (void *)(unsigned long)
728 bo[push[i].bo_index].user_priv;
730 nv50_dma_push(chan, nvbo, push[i].offset,
734 if (nv_device(drm->device)->chipset >= 0x25) {
735 ret = RING_SPACE(chan, req->nr_push * 2);
737 NV_ERROR(drm, "cal_space: %d\n", ret);
741 for (i = 0; i < req->nr_push; i++) {
742 struct nouveau_bo *nvbo = (void *)(unsigned long)
743 bo[push[i].bo_index].user_priv;
745 OUT_RING(chan, (nvbo->bo.offset + push[i].offset) | 2);
749 ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS));
751 NV_ERROR(drm, "jmp_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;
760 cmd = chan->push.vma.offset + ((chan->dma.cur + 2) << 2);
762 if (unlikely(cmd != req->suffix0)) {
763 if (!nvbo->kmap.virtual) {
764 ret = ttm_bo_kmap(&nvbo->bo, 0,
772 nvbo->validate_mapped = true;
775 nouveau_bo_wr32(nvbo, (push[i].offset +
776 push[i].length - 8) / 4, cmd);
779 OUT_RING(chan, 0x20000000 |
780 (nvbo->bo.offset + push[i].offset));
782 for (j = 0; j < NOUVEAU_DMA_SKIPS; j++)
787 ret = nouveau_fence_new(chan, &fence);
789 NV_ERROR(drm, "error fencing pushbuf: %d\n", ret);
795 validate_fini(&op, fence);
796 nouveau_fence_unref(&fence);
803 if (chan->dma.ib_max) {
804 req->suffix0 = 0x00000000;
805 req->suffix1 = 0x00000000;
807 if (nv_device(drm->device)->chipset >= 0x25) {
808 req->suffix0 = 0x00020000;
809 req->suffix1 = 0x00000000;
811 req->suffix0 = 0x20000000 |
812 (chan->push.vma.offset + ((chan->dma.cur + 2) << 2));
813 req->suffix1 = 0x00000000;
816 return nouveau_abi16_put(abi16, ret);
819 static inline uint32_t
820 domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain)
824 if (domain & NOUVEAU_GEM_DOMAIN_VRAM)
825 flags |= TTM_PL_FLAG_VRAM;
826 if (domain & NOUVEAU_GEM_DOMAIN_GART)
827 flags |= TTM_PL_FLAG_TT;
833 nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data,
834 struct drm_file *file_priv)
836 struct drm_nouveau_gem_cpu_prep *req = data;
837 struct drm_gem_object *gem;
838 struct nouveau_bo *nvbo;
839 bool no_wait = !!(req->flags & NOUVEAU_GEM_CPU_PREP_NOWAIT);
842 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
845 nvbo = nouveau_gem_object(gem);
847 spin_lock(&nvbo->bo.bdev->fence_lock);
848 ret = ttm_bo_wait(&nvbo->bo, true, true, no_wait);
849 spin_unlock(&nvbo->bo.bdev->fence_lock);
850 drm_gem_object_unreference_unlocked(gem);
855 nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data,
856 struct drm_file *file_priv)
862 nouveau_gem_ioctl_info(struct drm_device *dev, void *data,
863 struct drm_file *file_priv)
865 struct drm_nouveau_gem_info *req = data;
866 struct drm_gem_object *gem;
869 gem = drm_gem_object_lookup(dev, file_priv, req->handle);
873 ret = nouveau_gem_info(file_priv, gem, req);
874 drm_gem_object_unreference_unlocked(gem);