Lines Matching refs:bo
47 struct amdgpu_bo *bo; in amdgpu_bo_create() local
50 bo = calloc(1, sizeof(struct amdgpu_bo)); in amdgpu_bo_create()
51 if (!bo) in amdgpu_bo_create()
54 r = handle_table_insert(&dev->bo_handles, handle, bo); in amdgpu_bo_create()
56 free(bo); in amdgpu_bo_create()
60 atomic_set(&bo->refcount, 1); in amdgpu_bo_create()
61 bo->dev = dev; in amdgpu_bo_create()
62 bo->alloc_size = size; in amdgpu_bo_create()
63 bo->handle = handle; in amdgpu_bo_create()
64 pthread_mutex_init(&bo->cpu_access_mutex, NULL); in amdgpu_bo_create()
66 *buf_handle = bo; in amdgpu_bo_create()
103 drm_public int amdgpu_bo_set_metadata(amdgpu_bo_handle bo, in amdgpu_bo_set_metadata() argument
108 args.handle = bo->handle; in amdgpu_bo_set_metadata()
121 return drmCommandWriteRead(bo->dev->fd, in amdgpu_bo_set_metadata()
126 drm_public int amdgpu_bo_query_info(amdgpu_bo_handle bo, in amdgpu_bo_query_info() argument
135 if (!bo->handle) in amdgpu_bo_query_info()
139 metadata.handle = bo->handle; in amdgpu_bo_query_info()
142 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_METADATA, in amdgpu_bo_query_info()
152 gem_op.handle = bo->handle; in amdgpu_bo_query_info()
156 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_OP, in amdgpu_bo_query_info()
177 static int amdgpu_bo_export_flink(amdgpu_bo_handle bo) in amdgpu_bo_export_flink() argument
184 fd = bo->dev->fd; in amdgpu_bo_export_flink()
185 handle = bo->handle; in amdgpu_bo_export_flink()
186 if (bo->flink_name) in amdgpu_bo_export_flink()
190 if (bo->dev->flink_fd != bo->dev->fd) { in amdgpu_bo_export_flink()
191 r = drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC, in amdgpu_bo_export_flink()
194 r = drmPrimeFDToHandle(bo->dev->flink_fd, dma_fd, &handle); in amdgpu_bo_export_flink()
199 fd = bo->dev->flink_fd; in amdgpu_bo_export_flink()
208 bo->flink_name = flink.name; in amdgpu_bo_export_flink()
210 if (bo->dev->flink_fd != bo->dev->fd) in amdgpu_bo_export_flink()
211 drmCloseBufferHandle(bo->dev->flink_fd, handle); in amdgpu_bo_export_flink()
213 pthread_mutex_lock(&bo->dev->bo_table_mutex); in amdgpu_bo_export_flink()
214 r = handle_table_insert(&bo->dev->bo_flink_names, bo->flink_name, bo); in amdgpu_bo_export_flink()
215 pthread_mutex_unlock(&bo->dev->bo_table_mutex); in amdgpu_bo_export_flink()
220 drm_public int amdgpu_bo_export(amdgpu_bo_handle bo, in amdgpu_bo_export() argument
228 r = amdgpu_bo_export_flink(bo); in amdgpu_bo_export()
232 *shared_handle = bo->flink_name; in amdgpu_bo_export()
237 *shared_handle = bo->handle; in amdgpu_bo_export()
241 return drmPrimeHandleToFD(bo->dev->fd, bo->handle, in amdgpu_bo_export()
254 struct amdgpu_bo *bo = NULL; in amdgpu_bo_import() local
289 bo = handle_table_lookup(&dev->bo_flink_names, shared_handle); in amdgpu_bo_import()
293 bo = handle_table_lookup(&dev->bo_handles, shared_handle); in amdgpu_bo_import()
307 if (bo) { in amdgpu_bo_import()
309 atomic_inc(&bo->refcount); in amdgpu_bo_import()
312 output->buf_handle = bo; in amdgpu_bo_import()
313 output->alloc_size = bo->alloc_size; in amdgpu_bo_import()
356 r = amdgpu_bo_create(dev, alloc_size, handle, &bo); in amdgpu_bo_import()
361 bo->flink_name = flink_name; in amdgpu_bo_import()
363 bo); in amdgpu_bo_import()
369 output->buf_handle = bo; in amdgpu_bo_import()
370 output->alloc_size = bo->alloc_size; in amdgpu_bo_import()
378 if (bo) in amdgpu_bo_import()
379 amdgpu_bo_free(bo); in amdgpu_bo_import()
390 struct amdgpu_bo *bo = buf_handle; in amdgpu_bo_free() local
392 assert(bo != NULL); in amdgpu_bo_free()
393 dev = bo->dev; in amdgpu_bo_free()
396 if (update_references(&bo->refcount, NULL)) { in amdgpu_bo_free()
398 handle_table_remove(&dev->bo_handles, bo->handle); in amdgpu_bo_free()
400 if (bo->flink_name) in amdgpu_bo_free()
402 bo->flink_name); in amdgpu_bo_free()
405 if (bo->cpu_map_count > 0) { in amdgpu_bo_free()
406 bo->cpu_map_count = 1; in amdgpu_bo_free()
407 amdgpu_bo_cpu_unmap(bo); in amdgpu_bo_free()
410 drmCloseBufferHandle(dev->fd, bo->handle); in amdgpu_bo_free()
411 pthread_mutex_destroy(&bo->cpu_access_mutex); in amdgpu_bo_free()
412 free(bo); in amdgpu_bo_free()
420 drm_public void amdgpu_bo_inc_ref(amdgpu_bo_handle bo) in amdgpu_bo_inc_ref() argument
422 atomic_inc(&bo->refcount); in amdgpu_bo_inc_ref()
425 drm_public int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu) in amdgpu_bo_cpu_map() argument
431 pthread_mutex_lock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
433 if (bo->cpu_ptr) { in amdgpu_bo_cpu_map()
435 assert(bo->cpu_map_count > 0); in amdgpu_bo_cpu_map()
436 bo->cpu_map_count++; in amdgpu_bo_cpu_map()
437 *cpu = bo->cpu_ptr; in amdgpu_bo_cpu_map()
438 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
442 assert(bo->cpu_map_count == 0); in amdgpu_bo_cpu_map()
448 args.in.handle = bo->handle; in amdgpu_bo_cpu_map()
450 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_MMAP, &args, in amdgpu_bo_cpu_map()
453 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
458 ptr = drm_mmap(NULL, bo->alloc_size, PROT_READ | PROT_WRITE, MAP_SHARED, in amdgpu_bo_cpu_map()
459 bo->dev->fd, args.out.addr_ptr); in amdgpu_bo_cpu_map()
461 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
465 bo->cpu_ptr = ptr; in amdgpu_bo_cpu_map()
466 bo->cpu_map_count = 1; in amdgpu_bo_cpu_map()
467 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
473 drm_public int amdgpu_bo_cpu_unmap(amdgpu_bo_handle bo) in amdgpu_bo_cpu_unmap() argument
477 pthread_mutex_lock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
478 assert(bo->cpu_map_count >= 0); in amdgpu_bo_cpu_unmap()
480 if (bo->cpu_map_count == 0) { in amdgpu_bo_cpu_unmap()
482 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
486 bo->cpu_map_count--; in amdgpu_bo_cpu_unmap()
487 if (bo->cpu_map_count > 0) { in amdgpu_bo_cpu_unmap()
489 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
493 r = drm_munmap(bo->cpu_ptr, bo->alloc_size) == 0 ? 0 : -errno; in amdgpu_bo_cpu_unmap()
494 bo->cpu_ptr = NULL; in amdgpu_bo_cpu_unmap()
495 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
507 drm_public int amdgpu_bo_wait_for_idle(amdgpu_bo_handle bo, in amdgpu_bo_wait_for_idle() argument
515 args.in.handle = bo->handle; in amdgpu_bo_wait_for_idle()
518 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_WAIT_IDLE, in amdgpu_bo_wait_for_idle()
536 struct amdgpu_bo *bo; in amdgpu_find_bo_by_cpu_mapping() local
550 bo = handle_table_lookup(&dev->bo_handles, i); in amdgpu_find_bo_by_cpu_mapping()
551 if (!bo || !bo->cpu_ptr || size > bo->alloc_size) in amdgpu_find_bo_by_cpu_mapping()
553 if (cpu >= bo->cpu_ptr && in amdgpu_find_bo_by_cpu_mapping()
554 cpu < (void*)((uintptr_t)bo->cpu_ptr + bo->alloc_size)) in amdgpu_find_bo_by_cpu_mapping()
559 atomic_inc(&bo->refcount); in amdgpu_find_bo_by_cpu_mapping()
560 *buf_handle = bo; in amdgpu_find_bo_by_cpu_mapping()
561 *offset_in_bo = (uintptr_t)cpu - (uintptr_t)bo->cpu_ptr; in amdgpu_find_bo_by_cpu_mapping()
748 drm_public int amdgpu_bo_va_op(amdgpu_bo_handle bo, in amdgpu_bo_va_op() argument
755 amdgpu_device_handle dev = bo->dev; in amdgpu_bo_va_op()
759 return amdgpu_bo_va_op_raw(dev, bo, offset, size, addr, in amdgpu_bo_va_op()
766 amdgpu_bo_handle bo, in amdgpu_bo_va_op_raw() argument
781 va.handle = bo ? bo->handle : 0; in amdgpu_bo_va_op_raw()