1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2015-2018 Etnaviv Project
6 #include <drm/drm_prime.h>
7 #include <linux/dma-mapping.h>
8 #include <linux/shmem_fs.h>
9 #include <linux/spinlock.h>
10 #include <linux/vmalloc.h>
12 #include "etnaviv_drv.h"
13 #include "etnaviv_gem.h"
14 #include "etnaviv_gpu.h"
15 #include "etnaviv_mmu.h"
17 static struct lock_class_key etnaviv_shm_lock_class
;
18 static struct lock_class_key etnaviv_userptr_lock_class
;
20 static void etnaviv_gem_scatter_map(struct etnaviv_gem_object
*etnaviv_obj
)
22 struct drm_device
*dev
= etnaviv_obj
->base
.dev
;
23 struct sg_table
*sgt
= etnaviv_obj
->sgt
;
26 * For non-cached buffers, ensure the new pages are clean
27 * because display controller, GPU, etc. are not coherent.
29 if (etnaviv_obj
->flags
& ETNA_BO_CACHE_MASK
)
30 dma_map_sgtable(dev
->dev
, sgt
, DMA_BIDIRECTIONAL
, 0);
33 static void etnaviv_gem_scatterlist_unmap(struct etnaviv_gem_object
*etnaviv_obj
)
35 struct drm_device
*dev
= etnaviv_obj
->base
.dev
;
36 struct sg_table
*sgt
= etnaviv_obj
->sgt
;
39 * For non-cached buffers, ensure the new pages are clean
40 * because display controller, GPU, etc. are not coherent:
42 * WARNING: The DMA API does not support concurrent CPU
43 * and device access to the memory area. With BIDIRECTIONAL,
44 * we will clean the cache lines which overlap the region,
45 * and invalidate all cache lines (partially) contained in
48 * If you have dirty data in the overlapping cache lines,
49 * that will corrupt the GPU-written data. If you have
50 * written into the remainder of the region, this can
51 * discard those writes.
53 if (etnaviv_obj
->flags
& ETNA_BO_CACHE_MASK
)
54 dma_unmap_sgtable(dev
->dev
, sgt
, DMA_BIDIRECTIONAL
, 0);
57 /* called with etnaviv_obj->lock held */
58 static int etnaviv_gem_shmem_get_pages(struct etnaviv_gem_object
*etnaviv_obj
)
60 struct drm_device
*dev
= etnaviv_obj
->base
.dev
;
61 struct page
**p
= drm_gem_get_pages(&etnaviv_obj
->base
);
64 dev_dbg(dev
->dev
, "could not get pages: %ld\n", PTR_ERR(p
));
68 etnaviv_obj
->pages
= p
;
73 static void put_pages(struct etnaviv_gem_object
*etnaviv_obj
)
75 if (etnaviv_obj
->sgt
) {
76 etnaviv_gem_scatterlist_unmap(etnaviv_obj
);
77 sg_free_table(etnaviv_obj
->sgt
);
78 kfree(etnaviv_obj
->sgt
);
79 etnaviv_obj
->sgt
= NULL
;
81 if (etnaviv_obj
->pages
) {
82 drm_gem_put_pages(&etnaviv_obj
->base
, etnaviv_obj
->pages
,
85 etnaviv_obj
->pages
= NULL
;
89 struct page
**etnaviv_gem_get_pages(struct etnaviv_gem_object
*etnaviv_obj
)
93 lockdep_assert_held(&etnaviv_obj
->lock
);
95 if (!etnaviv_obj
->pages
) {
96 ret
= etnaviv_obj
->ops
->get_pages(etnaviv_obj
);
101 if (!etnaviv_obj
->sgt
) {
102 struct drm_device
*dev
= etnaviv_obj
->base
.dev
;
103 int npages
= etnaviv_obj
->base
.size
>> PAGE_SHIFT
;
104 struct sg_table
*sgt
;
106 sgt
= drm_prime_pages_to_sg(etnaviv_obj
->base
.dev
,
107 etnaviv_obj
->pages
, npages
);
109 dev_err(dev
->dev
, "failed to allocate sgt: %ld\n",
111 return ERR_CAST(sgt
);
114 etnaviv_obj
->sgt
= sgt
;
116 etnaviv_gem_scatter_map(etnaviv_obj
);
119 return etnaviv_obj
->pages
;
122 void etnaviv_gem_put_pages(struct etnaviv_gem_object
*etnaviv_obj
)
124 lockdep_assert_held(&etnaviv_obj
->lock
);
125 /* when we start tracking the pin count, then do something here */
128 static int etnaviv_gem_mmap_obj(struct etnaviv_gem_object
*etnaviv_obj
,
129 struct vm_area_struct
*vma
)
131 pgprot_t vm_page_prot
;
133 vma
->vm_flags
|= VM_IO
| VM_MIXEDMAP
| VM_DONTEXPAND
| VM_DONTDUMP
;
135 vm_page_prot
= vm_get_page_prot(vma
->vm_flags
);
137 if (etnaviv_obj
->flags
& ETNA_BO_WC
) {
138 vma
->vm_page_prot
= pgprot_writecombine(vm_page_prot
);
139 } else if (etnaviv_obj
->flags
& ETNA_BO_UNCACHED
) {
140 vma
->vm_page_prot
= pgprot_noncached(vm_page_prot
);
143 * Shunt off cached objs to shmem file so they have their own
144 * address_space (so unmap_mapping_range does what we want,
145 * in particular in the case of mmap'd dmabufs)
148 vma_set_file(vma
, etnaviv_obj
->base
.filp
);
150 vma
->vm_page_prot
= vm_page_prot
;
156 static int etnaviv_gem_mmap(struct drm_gem_object
*obj
, struct vm_area_struct
*vma
)
158 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
160 return etnaviv_obj
->ops
->mmap(etnaviv_obj
, vma
);
163 static vm_fault_t
etnaviv_gem_fault(struct vm_fault
*vmf
)
165 struct vm_area_struct
*vma
= vmf
->vma
;
166 struct drm_gem_object
*obj
= vma
->vm_private_data
;
167 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
168 struct page
**pages
, *page
;
173 * Make sure we don't parallel update on a fault, nor move or remove
174 * something from beneath our feet. Note that vmf_insert_page() is
175 * specifically coded to take care of this, so we don't have to.
177 err
= mutex_lock_interruptible(&etnaviv_obj
->lock
);
179 return VM_FAULT_NOPAGE
;
180 /* make sure we have pages attached now */
181 pages
= etnaviv_gem_get_pages(etnaviv_obj
);
182 mutex_unlock(&etnaviv_obj
->lock
);
185 err
= PTR_ERR(pages
);
186 return vmf_error(err
);
189 /* We don't use vmf->pgoff since that has the fake offset: */
190 pgoff
= (vmf
->address
- vma
->vm_start
) >> PAGE_SHIFT
;
194 VERB("Inserting %p pfn %lx, pa %lx", (void *)vmf
->address
,
195 page_to_pfn(page
), page_to_pfn(page
) << PAGE_SHIFT
);
197 return vmf_insert_page(vma
, vmf
->address
, page
);
200 int etnaviv_gem_mmap_offset(struct drm_gem_object
*obj
, u64
*offset
)
204 /* Make it mmapable */
205 ret
= drm_gem_create_mmap_offset(obj
);
207 dev_err(obj
->dev
->dev
, "could not allocate mmap offset\n");
209 *offset
= drm_vma_node_offset_addr(&obj
->vma_node
);
214 static struct etnaviv_vram_mapping
*
215 etnaviv_gem_get_vram_mapping(struct etnaviv_gem_object
*obj
,
216 struct etnaviv_iommu_context
*context
)
218 struct etnaviv_vram_mapping
*mapping
;
220 list_for_each_entry(mapping
, &obj
->vram_list
, obj_node
) {
221 if (mapping
->context
== context
)
228 void etnaviv_gem_mapping_unreference(struct etnaviv_vram_mapping
*mapping
)
230 struct etnaviv_gem_object
*etnaviv_obj
= mapping
->object
;
232 mutex_lock(&etnaviv_obj
->lock
);
233 WARN_ON(mapping
->use
== 0);
235 mutex_unlock(&etnaviv_obj
->lock
);
237 drm_gem_object_put(&etnaviv_obj
->base
);
240 struct etnaviv_vram_mapping
*etnaviv_gem_mapping_get(
241 struct drm_gem_object
*obj
, struct etnaviv_iommu_context
*mmu_context
,
244 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
245 struct etnaviv_vram_mapping
*mapping
;
249 mutex_lock(&etnaviv_obj
->lock
);
250 mapping
= etnaviv_gem_get_vram_mapping(etnaviv_obj
, mmu_context
);
253 * Holding the object lock prevents the use count changing
254 * beneath us. If the use count is zero, the MMU might be
255 * reaping this object, so take the lock and re-check that
256 * the MMU owns this mapping to close this race.
258 if (mapping
->use
== 0) {
259 mutex_lock(&mmu_context
->lock
);
260 if (mapping
->context
== mmu_context
)
264 mutex_unlock(&mmu_context
->lock
);
273 pages
= etnaviv_gem_get_pages(etnaviv_obj
);
275 ret
= PTR_ERR(pages
);
280 * See if we have a reaped vram mapping we can re-use before
281 * allocating a fresh mapping.
283 mapping
= etnaviv_gem_get_vram_mapping(etnaviv_obj
, NULL
);
285 mapping
= kzalloc(sizeof(*mapping
), GFP_KERNEL
);
291 INIT_LIST_HEAD(&mapping
->scan_node
);
292 mapping
->object
= etnaviv_obj
;
294 list_del(&mapping
->obj_node
);
297 etnaviv_iommu_context_get(mmu_context
);
298 mapping
->context
= mmu_context
;
301 ret
= etnaviv_iommu_map_gem(mmu_context
, etnaviv_obj
,
302 mmu_context
->global
->memory_base
,
305 etnaviv_iommu_context_put(mmu_context
);
308 list_add_tail(&mapping
->obj_node
, &etnaviv_obj
->vram_list
);
312 mutex_unlock(&etnaviv_obj
->lock
);
317 /* Take a reference on the object */
318 drm_gem_object_get(obj
);
322 void *etnaviv_gem_vmap(struct drm_gem_object
*obj
)
324 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
326 if (etnaviv_obj
->vaddr
)
327 return etnaviv_obj
->vaddr
;
329 mutex_lock(&etnaviv_obj
->lock
);
331 * Need to check again, as we might have raced with another thread
332 * while waiting for the mutex.
334 if (!etnaviv_obj
->vaddr
)
335 etnaviv_obj
->vaddr
= etnaviv_obj
->ops
->vmap(etnaviv_obj
);
336 mutex_unlock(&etnaviv_obj
->lock
);
338 return etnaviv_obj
->vaddr
;
341 static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object
*obj
)
345 lockdep_assert_held(&obj
->lock
);
347 pages
= etnaviv_gem_get_pages(obj
);
351 return vmap(pages
, obj
->base
.size
>> PAGE_SHIFT
,
352 VM_MAP
, pgprot_writecombine(PAGE_KERNEL
));
355 static inline enum dma_data_direction
etnaviv_op_to_dma_dir(u32 op
)
357 if (op
& ETNA_PREP_READ
)
358 return DMA_FROM_DEVICE
;
359 else if (op
& ETNA_PREP_WRITE
)
360 return DMA_TO_DEVICE
;
362 return DMA_BIDIRECTIONAL
;
365 int etnaviv_gem_cpu_prep(struct drm_gem_object
*obj
, u32 op
,
366 struct drm_etnaviv_timespec
*timeout
)
368 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
369 struct drm_device
*dev
= obj
->dev
;
370 bool write
= !!(op
& ETNA_PREP_WRITE
);
373 if (!etnaviv_obj
->sgt
) {
376 mutex_lock(&etnaviv_obj
->lock
);
377 ret
= etnaviv_gem_get_pages(etnaviv_obj
);
378 mutex_unlock(&etnaviv_obj
->lock
);
383 if (op
& ETNA_PREP_NOSYNC
) {
384 if (!dma_resv_test_signaled(obj
->resv
, write
))
387 unsigned long remain
= etnaviv_timeout_to_jiffies(timeout
);
389 ret
= dma_resv_wait_timeout(obj
->resv
, write
, true, remain
);
391 return ret
== 0 ? -ETIMEDOUT
: ret
;
394 if (etnaviv_obj
->flags
& ETNA_BO_CACHED
) {
395 dma_sync_sgtable_for_cpu(dev
->dev
, etnaviv_obj
->sgt
,
396 etnaviv_op_to_dma_dir(op
));
397 etnaviv_obj
->last_cpu_prep_op
= op
;
403 int etnaviv_gem_cpu_fini(struct drm_gem_object
*obj
)
405 struct drm_device
*dev
= obj
->dev
;
406 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
408 if (etnaviv_obj
->flags
& ETNA_BO_CACHED
) {
409 /* fini without a prep is almost certainly a userspace error */
410 WARN_ON(etnaviv_obj
->last_cpu_prep_op
== 0);
411 dma_sync_sgtable_for_device(dev
->dev
, etnaviv_obj
->sgt
,
412 etnaviv_op_to_dma_dir(etnaviv_obj
->last_cpu_prep_op
));
413 etnaviv_obj
->last_cpu_prep_op
= 0;
419 int etnaviv_gem_wait_bo(struct etnaviv_gpu
*gpu
, struct drm_gem_object
*obj
,
420 struct drm_etnaviv_timespec
*timeout
)
422 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
424 return etnaviv_gpu_wait_obj_inactive(gpu
, etnaviv_obj
, timeout
);
427 #ifdef CONFIG_DEBUG_FS
428 static void etnaviv_gem_describe_fence(struct dma_fence
*fence
,
429 const char *type
, struct seq_file
*m
)
431 if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT
, &fence
->flags
))
432 seq_printf(m
, "\t%9s: %s %s seq %llu\n",
434 fence
->ops
->get_driver_name(fence
),
435 fence
->ops
->get_timeline_name(fence
),
439 static void etnaviv_gem_describe(struct drm_gem_object
*obj
, struct seq_file
*m
)
441 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
442 struct dma_resv
*robj
= obj
->resv
;
443 struct dma_resv_list
*fobj
;
444 struct dma_fence
*fence
;
445 unsigned long off
= drm_vma_node_start(&obj
->vma_node
);
447 seq_printf(m
, "%08x: %c %2d (%2d) %08lx %p %zd\n",
448 etnaviv_obj
->flags
, is_active(etnaviv_obj
) ? 'A' : 'I',
449 obj
->name
, kref_read(&obj
->refcount
),
450 off
, etnaviv_obj
->vaddr
, obj
->size
);
453 fobj
= dma_resv_shared_list(robj
);
455 unsigned int i
, shared_count
= fobj
->shared_count
;
457 for (i
= 0; i
< shared_count
; i
++) {
458 fence
= rcu_dereference(fobj
->shared
[i
]);
459 etnaviv_gem_describe_fence(fence
, "Shared", m
);
463 fence
= dma_resv_excl_fence(robj
);
465 etnaviv_gem_describe_fence(fence
, "Exclusive", m
);
469 void etnaviv_gem_describe_objects(struct etnaviv_drm_private
*priv
,
472 struct etnaviv_gem_object
*etnaviv_obj
;
476 mutex_lock(&priv
->gem_lock
);
477 list_for_each_entry(etnaviv_obj
, &priv
->gem_list
, gem_node
) {
478 struct drm_gem_object
*obj
= &etnaviv_obj
->base
;
481 etnaviv_gem_describe(obj
, m
);
485 mutex_unlock(&priv
->gem_lock
);
487 seq_printf(m
, "Total %d objects, %zu bytes\n", count
, size
);
491 static void etnaviv_gem_shmem_release(struct etnaviv_gem_object
*etnaviv_obj
)
493 vunmap(etnaviv_obj
->vaddr
);
494 put_pages(etnaviv_obj
);
497 static const struct etnaviv_gem_ops etnaviv_gem_shmem_ops
= {
498 .get_pages
= etnaviv_gem_shmem_get_pages
,
499 .release
= etnaviv_gem_shmem_release
,
500 .vmap
= etnaviv_gem_vmap_impl
,
501 .mmap
= etnaviv_gem_mmap_obj
,
504 void etnaviv_gem_free_object(struct drm_gem_object
*obj
)
506 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
507 struct etnaviv_drm_private
*priv
= obj
->dev
->dev_private
;
508 struct etnaviv_vram_mapping
*mapping
, *tmp
;
510 /* object should not be active */
511 WARN_ON(is_active(etnaviv_obj
));
513 mutex_lock(&priv
->gem_lock
);
514 list_del(&etnaviv_obj
->gem_node
);
515 mutex_unlock(&priv
->gem_lock
);
517 list_for_each_entry_safe(mapping
, tmp
, &etnaviv_obj
->vram_list
,
519 struct etnaviv_iommu_context
*context
= mapping
->context
;
521 WARN_ON(mapping
->use
);
524 etnaviv_iommu_unmap_gem(context
, mapping
);
525 etnaviv_iommu_context_put(context
);
528 list_del(&mapping
->obj_node
);
532 drm_gem_free_mmap_offset(obj
);
533 etnaviv_obj
->ops
->release(etnaviv_obj
);
534 drm_gem_object_release(obj
);
539 void etnaviv_gem_obj_add(struct drm_device
*dev
, struct drm_gem_object
*obj
)
541 struct etnaviv_drm_private
*priv
= dev
->dev_private
;
542 struct etnaviv_gem_object
*etnaviv_obj
= to_etnaviv_bo(obj
);
544 mutex_lock(&priv
->gem_lock
);
545 list_add_tail(&etnaviv_obj
->gem_node
, &priv
->gem_list
);
546 mutex_unlock(&priv
->gem_lock
);
549 static const struct vm_operations_struct vm_ops
= {
550 .fault
= etnaviv_gem_fault
,
551 .open
= drm_gem_vm_open
,
552 .close
= drm_gem_vm_close
,
555 static const struct drm_gem_object_funcs etnaviv_gem_object_funcs
= {
556 .free
= etnaviv_gem_free_object
,
557 .pin
= etnaviv_gem_prime_pin
,
558 .unpin
= etnaviv_gem_prime_unpin
,
559 .get_sg_table
= etnaviv_gem_prime_get_sg_table
,
560 .vmap
= etnaviv_gem_prime_vmap
,
561 .mmap
= etnaviv_gem_mmap
,
565 static int etnaviv_gem_new_impl(struct drm_device
*dev
, u32 size
, u32 flags
,
566 const struct etnaviv_gem_ops
*ops
, struct drm_gem_object
**obj
)
568 struct etnaviv_gem_object
*etnaviv_obj
;
569 unsigned sz
= sizeof(*etnaviv_obj
);
573 switch (flags
& ETNA_BO_CACHE_MASK
) {
574 case ETNA_BO_UNCACHED
:
583 dev_err(dev
->dev
, "invalid cache flag: %x\n",
584 (flags
& ETNA_BO_CACHE_MASK
));
588 etnaviv_obj
= kzalloc(sz
, GFP_KERNEL
);
592 etnaviv_obj
->flags
= flags
;
593 etnaviv_obj
->ops
= ops
;
595 mutex_init(&etnaviv_obj
->lock
);
596 INIT_LIST_HEAD(&etnaviv_obj
->vram_list
);
598 *obj
= &etnaviv_obj
->base
;
599 (*obj
)->funcs
= &etnaviv_gem_object_funcs
;
604 /* convenience method to construct a GEM buffer object, and userspace handle */
605 int etnaviv_gem_new_handle(struct drm_device
*dev
, struct drm_file
*file
,
606 u32 size
, u32 flags
, u32
*handle
)
608 struct etnaviv_drm_private
*priv
= dev
->dev_private
;
609 struct drm_gem_object
*obj
= NULL
;
612 size
= PAGE_ALIGN(size
);
614 ret
= etnaviv_gem_new_impl(dev
, size
, flags
,
615 &etnaviv_gem_shmem_ops
, &obj
);
619 lockdep_set_class(&to_etnaviv_bo(obj
)->lock
, &etnaviv_shm_lock_class
);
621 ret
= drm_gem_object_init(dev
, obj
, size
);
626 * Our buffers are kept pinned, so allocating them from the MOVABLE
627 * zone is a really bad idea, and conflicts with CMA. See comments
628 * above new_inode() why this is required _and_ expected if you're
629 * going to pin these pages.
631 mapping_set_gfp_mask(obj
->filp
->f_mapping
, priv
->shm_gfp_mask
);
633 etnaviv_gem_obj_add(dev
, obj
);
635 ret
= drm_gem_handle_create(file
, obj
, handle
);
637 /* drop reference from allocate - handle holds it now */
639 drm_gem_object_put(obj
);
644 int etnaviv_gem_new_private(struct drm_device
*dev
, size_t size
, u32 flags
,
645 const struct etnaviv_gem_ops
*ops
, struct etnaviv_gem_object
**res
)
647 struct drm_gem_object
*obj
;
650 ret
= etnaviv_gem_new_impl(dev
, size
, flags
, ops
, &obj
);
654 drm_gem_private_object_init(dev
, obj
, size
);
656 *res
= to_etnaviv_bo(obj
);
661 static int etnaviv_gem_userptr_get_pages(struct etnaviv_gem_object
*etnaviv_obj
)
663 struct page
**pvec
= NULL
;
664 struct etnaviv_gem_userptr
*userptr
= &etnaviv_obj
->userptr
;
665 int ret
, pinned
= 0, npages
= etnaviv_obj
->base
.size
>> PAGE_SHIFT
;
667 might_lock_read(¤t
->mm
->mmap_lock
);
669 if (userptr
->mm
!= current
->mm
)
672 pvec
= kvmalloc_array(npages
, sizeof(struct page
*), GFP_KERNEL
);
677 unsigned num_pages
= npages
- pinned
;
678 uint64_t ptr
= userptr
->ptr
+ pinned
* PAGE_SIZE
;
679 struct page
**pages
= pvec
+ pinned
;
681 ret
= pin_user_pages_fast(ptr
, num_pages
,
682 FOLL_WRITE
| FOLL_FORCE
| FOLL_LONGTERM
,
685 unpin_user_pages(pvec
, pinned
);
692 } while (pinned
< npages
);
694 etnaviv_obj
->pages
= pvec
;
699 static void etnaviv_gem_userptr_release(struct etnaviv_gem_object
*etnaviv_obj
)
701 if (etnaviv_obj
->sgt
) {
702 etnaviv_gem_scatterlist_unmap(etnaviv_obj
);
703 sg_free_table(etnaviv_obj
->sgt
);
704 kfree(etnaviv_obj
->sgt
);
706 if (etnaviv_obj
->pages
) {
707 int npages
= etnaviv_obj
->base
.size
>> PAGE_SHIFT
;
709 unpin_user_pages(etnaviv_obj
->pages
, npages
);
710 kvfree(etnaviv_obj
->pages
);
714 static int etnaviv_gem_userptr_mmap_obj(struct etnaviv_gem_object
*etnaviv_obj
,
715 struct vm_area_struct
*vma
)
720 static const struct etnaviv_gem_ops etnaviv_gem_userptr_ops
= {
721 .get_pages
= etnaviv_gem_userptr_get_pages
,
722 .release
= etnaviv_gem_userptr_release
,
723 .vmap
= etnaviv_gem_vmap_impl
,
724 .mmap
= etnaviv_gem_userptr_mmap_obj
,
727 int etnaviv_gem_new_userptr(struct drm_device
*dev
, struct drm_file
*file
,
728 uintptr_t ptr
, u32 size
, u32 flags
, u32
*handle
)
730 struct etnaviv_gem_object
*etnaviv_obj
;
733 ret
= etnaviv_gem_new_private(dev
, size
, ETNA_BO_CACHED
,
734 &etnaviv_gem_userptr_ops
, &etnaviv_obj
);
738 lockdep_set_class(&etnaviv_obj
->lock
, &etnaviv_userptr_lock_class
);
740 etnaviv_obj
->userptr
.ptr
= ptr
;
741 etnaviv_obj
->userptr
.mm
= current
->mm
;
742 etnaviv_obj
->userptr
.ro
= !(flags
& ETNA_USERPTR_WRITE
);
744 etnaviv_gem_obj_add(dev
, &etnaviv_obj
->base
);
746 ret
= drm_gem_handle_create(file
, &etnaviv_obj
->base
, handle
);
748 /* drop reference from allocate - handle holds it now */
749 drm_gem_object_put(&etnaviv_obj
->base
);