Lines Matching refs:buf
22 struct hl_mmap_mem_buf *buf; in hl_mmap_mem_buf_get() local
25 buf = idr_find(&mmg->handles, lower_32_bits(handle >> PAGE_SHIFT)); in hl_mmap_mem_buf_get()
26 if (!buf) { in hl_mmap_mem_buf_get()
32 kref_get(&buf->refcount); in hl_mmap_mem_buf_get()
34 return buf; in hl_mmap_mem_buf_get()
46 static void hl_mmap_mem_buf_destroy(struct hl_mmap_mem_buf *buf) in hl_mmap_mem_buf_destroy() argument
48 if (buf->behavior->release) in hl_mmap_mem_buf_destroy()
49 buf->behavior->release(buf); in hl_mmap_mem_buf_destroy()
51 kfree(buf); in hl_mmap_mem_buf_destroy()
64 struct hl_mmap_mem_buf *buf = in hl_mmap_mem_buf_release() local
67 spin_lock(&buf->mmg->lock); in hl_mmap_mem_buf_release()
68 idr_remove(&buf->mmg->handles, lower_32_bits(buf->handle >> PAGE_SHIFT)); in hl_mmap_mem_buf_release()
69 spin_unlock(&buf->mmg->lock); in hl_mmap_mem_buf_release()
71 hl_mmap_mem_buf_destroy(buf); in hl_mmap_mem_buf_release()
84 struct hl_mmap_mem_buf *buf = in hl_mmap_mem_buf_remove_idr_locked() local
87 idr_remove(&buf->mmg->handles, lower_32_bits(buf->handle >> PAGE_SHIFT)); in hl_mmap_mem_buf_remove_idr_locked()
98 int hl_mmap_mem_buf_put(struct hl_mmap_mem_buf *buf) in hl_mmap_mem_buf_put() argument
100 return kref_put(&buf->refcount, hl_mmap_mem_buf_release); in hl_mmap_mem_buf_put()
116 struct hl_mmap_mem_buf *buf; in hl_mmap_mem_buf_put_handle() local
119 buf = idr_find(&mmg->handles, lower_32_bits(handle >> PAGE_SHIFT)); in hl_mmap_mem_buf_put_handle()
120 if (!buf) { in hl_mmap_mem_buf_put_handle()
127 if (kref_put(&buf->refcount, hl_mmap_mem_buf_remove_idr_locked)) { in hl_mmap_mem_buf_put_handle()
129 hl_mmap_mem_buf_destroy(buf); in hl_mmap_mem_buf_put_handle()
153 struct hl_mmap_mem_buf *buf; in hl_mmap_mem_buf_alloc() local
156 buf = kzalloc(sizeof(*buf), gfp); in hl_mmap_mem_buf_alloc()
157 if (!buf) in hl_mmap_mem_buf_alloc()
161 rc = idr_alloc(&mmg->handles, buf, 1, 0, GFP_ATOMIC); in hl_mmap_mem_buf_alloc()
170 buf->mmg = mmg; in hl_mmap_mem_buf_alloc()
171 buf->behavior = behavior; in hl_mmap_mem_buf_alloc()
172 buf->handle = (((u64)rc | buf->behavior->mem_id) << PAGE_SHIFT); in hl_mmap_mem_buf_alloc()
173 kref_init(&buf->refcount); in hl_mmap_mem_buf_alloc()
175 rc = buf->behavior->alloc(buf, gfp, args); in hl_mmap_mem_buf_alloc()
182 return buf; in hl_mmap_mem_buf_alloc()
186 idr_remove(&mmg->handles, lower_32_bits(buf->handle >> PAGE_SHIFT)); in hl_mmap_mem_buf_alloc()
189 kfree(buf); in hl_mmap_mem_buf_alloc()
202 struct hl_mmap_mem_buf *buf = in hl_mmap_mem_buf_vm_close() local
206 new_mmap_size = buf->real_mapped_size - (vma->vm_end - vma->vm_start); in hl_mmap_mem_buf_vm_close()
209 buf->real_mapped_size = new_mmap_size; in hl_mmap_mem_buf_vm_close()
213 atomic_set(&buf->mmap, 0); in hl_mmap_mem_buf_vm_close()
214 hl_mmap_mem_buf_put(buf); in hl_mmap_mem_buf_vm_close()
234 struct hl_mmap_mem_buf *buf; local
246 buf = hl_mmap_mem_buf_get(mmg, handle);
247 if (!buf) {
255 if (user_mem_size != ALIGN(buf->mappable_size, PAGE_SIZE)) {
258 buf->behavior->topic, user_mem_size, buf->mappable_size);
271 buf->behavior->topic, vma->vm_start);
277 if (atomic_cmpxchg(&buf->mmap, 0, 1)) {
280 buf->behavior->topic);
289 vma->vm_private_data = buf;
291 rc = buf->behavior->mmap(buf, vma, args);
293 atomic_set(&buf->mmap, 0);
297 buf->real_mapped_size = buf->mappable_size;
303 hl_mmap_mem_buf_put(buf);
331 struct hl_mmap_mem_buf *buf; local
338 idr_for_each_entry(idp, buf, id) {
339 topic = buf->behavior->topic;
340 if (hl_mmap_mem_buf_put(buf) != 1)