Lines Matching refs:bo
56 struct amdgpu_bo *bo; in amdgpu_bo_alloc() local
65 bo = calloc(1, sizeof(struct amdgpu_bo)); in amdgpu_bo_alloc()
66 if (!bo) in amdgpu_bo_alloc()
69 atomic_set(&bo->refcount, 1); in amdgpu_bo_alloc()
70 bo->dev = dev; in amdgpu_bo_alloc()
71 bo->alloc_size = alloc_buffer->alloc_size; in amdgpu_bo_alloc()
85 free(bo); in amdgpu_bo_alloc()
89 bo->handle = args.out.handle; in amdgpu_bo_alloc()
91 pthread_mutex_init(&bo->cpu_access_mutex, NULL); in amdgpu_bo_alloc()
93 *buf_handle = bo; in amdgpu_bo_alloc()
97 int amdgpu_bo_set_metadata(amdgpu_bo_handle bo, in amdgpu_bo_set_metadata() argument
102 args.handle = bo->handle; in amdgpu_bo_set_metadata()
115 return drmCommandWriteRead(bo->dev->fd, in amdgpu_bo_set_metadata()
120 int amdgpu_bo_query_info(amdgpu_bo_handle bo, in amdgpu_bo_query_info() argument
129 if (!bo->handle) in amdgpu_bo_query_info()
133 metadata.handle = bo->handle; in amdgpu_bo_query_info()
136 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_METADATA, in amdgpu_bo_query_info()
146 gem_op.handle = bo->handle; in amdgpu_bo_query_info()
150 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_OP, in amdgpu_bo_query_info()
171 static void amdgpu_add_handle_to_table(amdgpu_bo_handle bo) in amdgpu_add_handle_to_table() argument
173 pthread_mutex_lock(&bo->dev->bo_table_mutex); in amdgpu_add_handle_to_table()
174 util_hash_table_set(bo->dev->bo_handles, in amdgpu_add_handle_to_table()
175 (void*)(uintptr_t)bo->handle, bo); in amdgpu_add_handle_to_table()
176 pthread_mutex_unlock(&bo->dev->bo_table_mutex); in amdgpu_add_handle_to_table()
179 static int amdgpu_bo_export_flink(amdgpu_bo_handle bo) in amdgpu_bo_export_flink() argument
186 fd = bo->dev->fd; in amdgpu_bo_export_flink()
187 handle = bo->handle; in amdgpu_bo_export_flink()
188 if (bo->flink_name) in amdgpu_bo_export_flink()
192 if (bo->dev->flink_fd != bo->dev->fd) { in amdgpu_bo_export_flink()
193 r = drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC, in amdgpu_bo_export_flink()
196 r = drmPrimeFDToHandle(bo->dev->flink_fd, dma_fd, &handle); in amdgpu_bo_export_flink()
201 fd = bo->dev->flink_fd; in amdgpu_bo_export_flink()
210 bo->flink_name = flink.name; in amdgpu_bo_export_flink()
212 if (bo->dev->flink_fd != bo->dev->fd) { in amdgpu_bo_export_flink()
215 drmIoctl(bo->dev->flink_fd, DRM_IOCTL_GEM_CLOSE, &args); in amdgpu_bo_export_flink()
218 pthread_mutex_lock(&bo->dev->bo_table_mutex); in amdgpu_bo_export_flink()
219 util_hash_table_set(bo->dev->bo_flink_names, in amdgpu_bo_export_flink()
220 (void*)(uintptr_t)bo->flink_name, in amdgpu_bo_export_flink()
221 bo); in amdgpu_bo_export_flink()
222 pthread_mutex_unlock(&bo->dev->bo_table_mutex); in amdgpu_bo_export_flink()
227 int amdgpu_bo_export(amdgpu_bo_handle bo, in amdgpu_bo_export() argument
235 r = amdgpu_bo_export_flink(bo); in amdgpu_bo_export()
239 *shared_handle = bo->flink_name; in amdgpu_bo_export()
243 amdgpu_add_handle_to_table(bo); in amdgpu_bo_export()
244 *shared_handle = bo->handle; in amdgpu_bo_export()
248 amdgpu_add_handle_to_table(bo); in amdgpu_bo_export()
249 return drmPrimeHandleToFD(bo->dev->fd, bo->handle, in amdgpu_bo_export()
262 struct amdgpu_bo *bo = NULL; in amdgpu_bo_import() local
299 bo = util_hash_table_get(dev->bo_flink_names, in amdgpu_bo_import()
304 bo = util_hash_table_get(dev->bo_handles, in amdgpu_bo_import()
318 if (bo) { in amdgpu_bo_import()
320 atomic_inc(&bo->refcount); in amdgpu_bo_import()
323 output->buf_handle = bo; in amdgpu_bo_import()
324 output->alloc_size = bo->alloc_size; in amdgpu_bo_import()
328 bo = calloc(1, sizeof(struct amdgpu_bo)); in amdgpu_bo_import()
329 if (!bo) { in amdgpu_bo_import()
343 free(bo); in amdgpu_bo_import()
348 bo->handle = open_arg.handle; in amdgpu_bo_import()
350 r = drmPrimeHandleToFD(dev->flink_fd, bo->handle, DRM_CLOEXEC, &dma_fd); in amdgpu_bo_import()
352 free(bo); in amdgpu_bo_import()
356 r = drmPrimeFDToHandle(dev->fd, dma_fd, &bo->handle ); in amdgpu_bo_import()
361 free(bo); in amdgpu_bo_import()
366 bo->flink_name = shared_handle; in amdgpu_bo_import()
367 bo->alloc_size = open_arg.size; in amdgpu_bo_import()
369 (void*)(uintptr_t)bo->flink_name, bo); in amdgpu_bo_import()
373 bo->handle = shared_handle; in amdgpu_bo_import()
374 bo->alloc_size = dma_buf_size; in amdgpu_bo_import()
382 atomic_set(&bo->refcount, 1); in amdgpu_bo_import()
383 bo->dev = dev; in amdgpu_bo_import()
384 pthread_mutex_init(&bo->cpu_access_mutex, NULL); in amdgpu_bo_import()
386 util_hash_table_set(dev->bo_handles, (void*)(uintptr_t)bo->handle, bo); in amdgpu_bo_import()
389 output->buf_handle = bo; in amdgpu_bo_import()
390 output->alloc_size = bo->alloc_size; in amdgpu_bo_import()
397 struct amdgpu_bo *bo = buf_handle; in amdgpu_bo_free() local
399 assert(bo != NULL); in amdgpu_bo_free()
400 dev = bo->dev; in amdgpu_bo_free()
403 if (update_references(&bo->refcount, NULL)) { in amdgpu_bo_free()
406 (void*)(uintptr_t)bo->handle); in amdgpu_bo_free()
408 if (bo->flink_name) { in amdgpu_bo_free()
410 (void*)(uintptr_t)bo->flink_name); in amdgpu_bo_free()
414 if (bo->cpu_map_count > 0) { in amdgpu_bo_free()
415 bo->cpu_map_count = 1; in amdgpu_bo_free()
416 amdgpu_bo_cpu_unmap(bo); in amdgpu_bo_free()
419 amdgpu_close_kms_handle(dev, bo->handle); in amdgpu_bo_free()
420 pthread_mutex_destroy(&bo->cpu_access_mutex); in amdgpu_bo_free()
421 free(bo); in amdgpu_bo_free()
428 int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu) in amdgpu_bo_cpu_map() argument
434 pthread_mutex_lock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
436 if (bo->cpu_ptr) { in amdgpu_bo_cpu_map()
438 assert(bo->cpu_map_count > 0); in amdgpu_bo_cpu_map()
439 bo->cpu_map_count++; in amdgpu_bo_cpu_map()
440 *cpu = bo->cpu_ptr; in amdgpu_bo_cpu_map()
441 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
445 assert(bo->cpu_map_count == 0); in amdgpu_bo_cpu_map()
451 args.in.handle = bo->handle; in amdgpu_bo_cpu_map()
453 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_MMAP, &args, in amdgpu_bo_cpu_map()
456 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
461 ptr = drm_mmap(NULL, bo->alloc_size, PROT_READ | PROT_WRITE, MAP_SHARED, in amdgpu_bo_cpu_map()
462 bo->dev->fd, args.out.addr_ptr); in amdgpu_bo_cpu_map()
464 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
468 bo->cpu_ptr = ptr; in amdgpu_bo_cpu_map()
469 bo->cpu_map_count = 1; in amdgpu_bo_cpu_map()
470 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
476 int amdgpu_bo_cpu_unmap(amdgpu_bo_handle bo) in amdgpu_bo_cpu_unmap() argument
480 pthread_mutex_lock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
481 assert(bo->cpu_map_count >= 0); in amdgpu_bo_cpu_unmap()
483 if (bo->cpu_map_count == 0) { in amdgpu_bo_cpu_unmap()
485 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
489 bo->cpu_map_count--; in amdgpu_bo_cpu_unmap()
490 if (bo->cpu_map_count > 0) { in amdgpu_bo_cpu_unmap()
492 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
496 r = drm_munmap(bo->cpu_ptr, bo->alloc_size) == 0 ? 0 : -errno; in amdgpu_bo_cpu_unmap()
497 bo->cpu_ptr = NULL; in amdgpu_bo_cpu_unmap()
498 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
510 int amdgpu_bo_wait_for_idle(amdgpu_bo_handle bo, in amdgpu_bo_wait_for_idle() argument
518 args.in.handle = bo->handle; in amdgpu_bo_wait_for_idle()
521 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_WAIT_IDLE, in amdgpu_bo_wait_for_idle()
539 struct amdgpu_bo *bo; in amdgpu_create_bo_from_user_mem() local
551 bo = calloc(1, sizeof(struct amdgpu_bo)); in amdgpu_create_bo_from_user_mem()
552 if (!bo) in amdgpu_create_bo_from_user_mem()
555 atomic_set(&bo->refcount, 1); in amdgpu_create_bo_from_user_mem()
556 bo->dev = dev; in amdgpu_create_bo_from_user_mem()
557 bo->alloc_size = size; in amdgpu_create_bo_from_user_mem()
558 bo->handle = args.handle; in amdgpu_create_bo_from_user_mem()
560 *buf_handle = bo; in amdgpu_create_bo_from_user_mem()
679 int amdgpu_bo_va_op(amdgpu_bo_handle bo, in amdgpu_bo_va_op() argument
686 amdgpu_device_handle dev = bo->dev; in amdgpu_bo_va_op()
690 return amdgpu_bo_va_op_raw(dev, bo, offset, size, addr, in amdgpu_bo_va_op()
697 amdgpu_bo_handle bo, in amdgpu_bo_va_op_raw() argument
712 va.handle = bo ? bo->handle : 0; in amdgpu_bo_va_op_raw()