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