• Home
  • Raw
  • Download

Lines Matching refs:bo

56 drm_private void amdgpu_bo_free_internal(amdgpu_bo_handle bo)  in amdgpu_bo_free_internal()  argument
59 pthread_mutex_lock(&bo->dev->bo_table_mutex); in amdgpu_bo_free_internal()
60 util_hash_table_remove(bo->dev->bo_handles, in amdgpu_bo_free_internal()
61 (void*)(uintptr_t)bo->handle); in amdgpu_bo_free_internal()
62 if (bo->flink_name) { in amdgpu_bo_free_internal()
63 util_hash_table_remove(bo->dev->bo_flink_names, in amdgpu_bo_free_internal()
64 (void*)(uintptr_t)bo->flink_name); in amdgpu_bo_free_internal()
66 pthread_mutex_unlock(&bo->dev->bo_table_mutex); in amdgpu_bo_free_internal()
69 if (bo->cpu_map_count > 0) { in amdgpu_bo_free_internal()
70 bo->cpu_map_count = 1; in amdgpu_bo_free_internal()
71 amdgpu_bo_cpu_unmap(bo); in amdgpu_bo_free_internal()
74 amdgpu_close_kms_handle(bo->dev, bo->handle); in amdgpu_bo_free_internal()
75 pthread_mutex_destroy(&bo->cpu_access_mutex); in amdgpu_bo_free_internal()
76 free(bo); in amdgpu_bo_free_internal()
83 struct amdgpu_bo *bo; in amdgpu_bo_alloc() local
92 bo = calloc(1, sizeof(struct amdgpu_bo)); in amdgpu_bo_alloc()
93 if (!bo) in amdgpu_bo_alloc()
96 atomic_set(&bo->refcount, 1); in amdgpu_bo_alloc()
97 bo->dev = dev; in amdgpu_bo_alloc()
98 bo->alloc_size = alloc_buffer->alloc_size; in amdgpu_bo_alloc()
112 free(bo); in amdgpu_bo_alloc()
116 bo->handle = args.out.handle; in amdgpu_bo_alloc()
118 pthread_mutex_init(&bo->cpu_access_mutex, NULL); in amdgpu_bo_alloc()
120 *buf_handle = bo; in amdgpu_bo_alloc()
124 int amdgpu_bo_set_metadata(amdgpu_bo_handle bo, in amdgpu_bo_set_metadata() argument
129 args.handle = bo->handle; in amdgpu_bo_set_metadata()
142 return drmCommandWriteRead(bo->dev->fd, in amdgpu_bo_set_metadata()
147 int amdgpu_bo_query_info(amdgpu_bo_handle bo, in amdgpu_bo_query_info() argument
156 if (!bo->handle) in amdgpu_bo_query_info()
160 metadata.handle = bo->handle; in amdgpu_bo_query_info()
163 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_METADATA, in amdgpu_bo_query_info()
173 gem_op.handle = bo->handle; in amdgpu_bo_query_info()
177 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_OP, in amdgpu_bo_query_info()
198 static void amdgpu_add_handle_to_table(amdgpu_bo_handle bo) in amdgpu_add_handle_to_table() argument
200 pthread_mutex_lock(&bo->dev->bo_table_mutex); in amdgpu_add_handle_to_table()
201 util_hash_table_set(bo->dev->bo_handles, in amdgpu_add_handle_to_table()
202 (void*)(uintptr_t)bo->handle, bo); in amdgpu_add_handle_to_table()
203 pthread_mutex_unlock(&bo->dev->bo_table_mutex); in amdgpu_add_handle_to_table()
206 static int amdgpu_bo_export_flink(amdgpu_bo_handle bo) in amdgpu_bo_export_flink() argument
213 fd = bo->dev->fd; in amdgpu_bo_export_flink()
214 handle = bo->handle; in amdgpu_bo_export_flink()
215 if (bo->flink_name) in amdgpu_bo_export_flink()
219 if (bo->dev->flink_fd != bo->dev->fd) { in amdgpu_bo_export_flink()
220 r = drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC, in amdgpu_bo_export_flink()
223 r = drmPrimeFDToHandle(bo->dev->flink_fd, dma_fd, &handle); in amdgpu_bo_export_flink()
228 fd = bo->dev->flink_fd; in amdgpu_bo_export_flink()
237 bo->flink_name = flink.name; in amdgpu_bo_export_flink()
239 if (bo->dev->flink_fd != bo->dev->fd) { in amdgpu_bo_export_flink()
242 drmIoctl(bo->dev->flink_fd, DRM_IOCTL_GEM_CLOSE, &args); in amdgpu_bo_export_flink()
245 pthread_mutex_lock(&bo->dev->bo_table_mutex); in amdgpu_bo_export_flink()
246 util_hash_table_set(bo->dev->bo_flink_names, in amdgpu_bo_export_flink()
247 (void*)(uintptr_t)bo->flink_name, in amdgpu_bo_export_flink()
248 bo); in amdgpu_bo_export_flink()
249 pthread_mutex_unlock(&bo->dev->bo_table_mutex); in amdgpu_bo_export_flink()
254 int amdgpu_bo_export(amdgpu_bo_handle bo, in amdgpu_bo_export() argument
262 r = amdgpu_bo_export_flink(bo); in amdgpu_bo_export()
266 *shared_handle = bo->flink_name; in amdgpu_bo_export()
270 amdgpu_add_handle_to_table(bo); in amdgpu_bo_export()
271 *shared_handle = bo->handle; in amdgpu_bo_export()
275 amdgpu_add_handle_to_table(bo); in amdgpu_bo_export()
276 return drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC, in amdgpu_bo_export()
288 struct amdgpu_bo *bo = NULL; in amdgpu_bo_import() local
324 bo = util_hash_table_get(dev->bo_flink_names, in amdgpu_bo_import()
329 bo = util_hash_table_get(dev->bo_handles, in amdgpu_bo_import()
343 if (bo) { in amdgpu_bo_import()
347 atomic_inc(&bo->refcount); in amdgpu_bo_import()
349 output->buf_handle = bo; in amdgpu_bo_import()
350 output->alloc_size = bo->alloc_size; in amdgpu_bo_import()
354 bo = calloc(1, sizeof(struct amdgpu_bo)); in amdgpu_bo_import()
355 if (!bo) { in amdgpu_bo_import()
369 free(bo); in amdgpu_bo_import()
374 bo->handle = open_arg.handle; in amdgpu_bo_import()
376 r = drmPrimeHandleToFD(dev->flink_fd, bo->handle, DRM_CLOEXEC, &dma_fd); in amdgpu_bo_import()
378 free(bo); in amdgpu_bo_import()
382 r = drmPrimeFDToHandle(dev->fd, dma_fd, &bo->handle ); in amdgpu_bo_import()
387 free(bo); in amdgpu_bo_import()
392 bo->flink_name = shared_handle; in amdgpu_bo_import()
393 bo->alloc_size = open_arg.size; in amdgpu_bo_import()
395 (void*)(uintptr_t)bo->flink_name, bo); in amdgpu_bo_import()
399 bo->handle = shared_handle; in amdgpu_bo_import()
400 bo->alloc_size = dma_buf_size; in amdgpu_bo_import()
408 atomic_set(&bo->refcount, 1); in amdgpu_bo_import()
409 bo->dev = dev; in amdgpu_bo_import()
410 pthread_mutex_init(&bo->cpu_access_mutex, NULL); in amdgpu_bo_import()
412 util_hash_table_set(dev->bo_handles, (void*)(uintptr_t)bo->handle, bo); in amdgpu_bo_import()
415 output->buf_handle = bo; in amdgpu_bo_import()
416 output->alloc_size = bo->alloc_size; in amdgpu_bo_import()
427 int amdgpu_bo_cpu_map(amdgpu_bo_handle bo, void **cpu) in amdgpu_bo_cpu_map() argument
433 pthread_mutex_lock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
435 if (bo->cpu_ptr) { in amdgpu_bo_cpu_map()
437 assert(bo->cpu_map_count > 0); in amdgpu_bo_cpu_map()
438 bo->cpu_map_count++; in amdgpu_bo_cpu_map()
439 *cpu = bo->cpu_ptr; in amdgpu_bo_cpu_map()
440 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
444 assert(bo->cpu_map_count == 0); in amdgpu_bo_cpu_map()
450 args.in.handle = bo->handle; in amdgpu_bo_cpu_map()
452 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_MMAP, &args, in amdgpu_bo_cpu_map()
455 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
460 ptr = drm_mmap(NULL, bo->alloc_size, PROT_READ | PROT_WRITE, MAP_SHARED, in amdgpu_bo_cpu_map()
461 bo->dev->fd, args.out.addr_ptr); in amdgpu_bo_cpu_map()
463 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
467 bo->cpu_ptr = ptr; in amdgpu_bo_cpu_map()
468 bo->cpu_map_count = 1; in amdgpu_bo_cpu_map()
469 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_map()
475 int amdgpu_bo_cpu_unmap(amdgpu_bo_handle bo) in amdgpu_bo_cpu_unmap() argument
479 pthread_mutex_lock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
480 assert(bo->cpu_map_count >= 0); in amdgpu_bo_cpu_unmap()
482 if (bo->cpu_map_count == 0) { in amdgpu_bo_cpu_unmap()
484 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
488 bo->cpu_map_count--; in amdgpu_bo_cpu_unmap()
489 if (bo->cpu_map_count > 0) { in amdgpu_bo_cpu_unmap()
491 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
495 r = drm_munmap(bo->cpu_ptr, bo->alloc_size) == 0 ? 0 : -errno; in amdgpu_bo_cpu_unmap()
496 bo->cpu_ptr = NULL; in amdgpu_bo_cpu_unmap()
497 pthread_mutex_unlock(&bo->cpu_access_mutex); in amdgpu_bo_cpu_unmap()
509 int amdgpu_bo_wait_for_idle(amdgpu_bo_handle bo, in amdgpu_bo_wait_for_idle() argument
517 args.in.handle = bo->handle; in amdgpu_bo_wait_for_idle()
520 r = drmCommandWriteRead(bo->dev->fd, DRM_AMDGPU_GEM_WAIT_IDLE, in amdgpu_bo_wait_for_idle()
538 struct amdgpu_bo *bo; in amdgpu_create_bo_from_user_mem() local
558 bo = calloc(1, sizeof(struct amdgpu_bo)); in amdgpu_create_bo_from_user_mem()
559 if (!bo) in amdgpu_create_bo_from_user_mem()
562 atomic_set(&bo->refcount, 1); in amdgpu_create_bo_from_user_mem()
563 bo->dev = dev; in amdgpu_create_bo_from_user_mem()
564 bo->alloc_size = size; in amdgpu_create_bo_from_user_mem()
565 bo->handle = args.handle; in amdgpu_create_bo_from_user_mem()
567 *buf_handle = bo; in amdgpu_create_bo_from_user_mem()
686 int amdgpu_bo_va_op(amdgpu_bo_handle bo, in amdgpu_bo_va_op() argument
693 amdgpu_device_handle dev = bo->dev; in amdgpu_bo_va_op()
701 va.handle = bo->handle; in amdgpu_bo_va_op()