Lines Matching refs:bo
38 static void bo_del(struct fd_bo *bo);
41 static void set_name(struct fd_bo *bo, uint32_t name) in set_name() argument
43 bo->name = name; in set_name()
45 drmHashInsert(bo->dev->name_table, name, bo); in set_name()
51 struct fd_bo *bo = NULL; in lookup_bo() local
52 if (!drmHashLookup(tbl, key, (void **)&bo)) { in lookup_bo()
54 bo = fd_bo_ref(bo); in lookup_bo()
57 list_delinit(&bo->list); in lookup_bo()
59 return bo; in lookup_bo()
66 struct fd_bo *bo; in bo_from_handle() local
68 bo = dev->funcs->bo_from_handle(dev, size, handle); in bo_from_handle()
69 if (!bo) { in bo_from_handle()
76 bo->dev = fd_device_ref(dev); in bo_from_handle()
77 bo->size = size; in bo_from_handle()
78 bo->handle = handle; in bo_from_handle()
79 atomic_set(&bo->refcnt, 1); in bo_from_handle()
80 list_inithead(&bo->list); in bo_from_handle()
82 drmHashInsert(dev->handle_table, handle, bo); in bo_from_handle()
83 return bo; in bo_from_handle()
96 struct fd_bo *bo; in fd_cleanup_bo_cache() local
99 bo = LIST_ENTRY(struct fd_bo, bucket->list.next, list); in fd_cleanup_bo_cache()
102 if (time && ((time - bo->free_time) <= 1)) in fd_cleanup_bo_cache()
105 list_del(&bo->list); in fd_cleanup_bo_cache()
106 bo_del(bo); in fd_cleanup_bo_cache()
130 static int is_idle(struct fd_bo *bo) in is_idle() argument
132 return fd_bo_cpu_prep(bo, NULL, in is_idle()
141 struct fd_bo *bo = NULL; in find_in_bucket() local
152 bo = LIST_ENTRY(struct fd_bo, bucket->list.next, list); in find_in_bucket()
154 list_del(&bo->list); in find_in_bucket()
155 bo_del(bo); in find_in_bucket()
156 bo = NULL; in find_in_bucket()
160 if (is_idle(bo)) { in find_in_bucket()
161 list_del(&bo->list); in find_in_bucket()
164 bo = NULL; in find_in_bucket()
169 return bo; in find_in_bucket()
176 struct fd_bo *bo = NULL; in fd_bo_new() local
187 bo = find_in_bucket(dev, bucket, flags); in fd_bo_new()
188 if (bo) { in fd_bo_new()
189 atomic_set(&bo->refcnt, 1); in fd_bo_new()
190 fd_device_ref(bo->dev); in fd_bo_new()
191 return bo; in fd_bo_new()
200 bo = bo_from_handle(dev, size, handle); in fd_bo_new()
201 bo->bo_reuse = 1; in fd_bo_new()
204 return bo; in fd_bo_new()
210 struct fd_bo *bo = NULL; in fd_bo_from_handle() local
214 bo = lookup_bo(dev->handle_table, handle); in fd_bo_from_handle()
215 if (bo) in fd_bo_from_handle()
218 bo = bo_from_handle(dev, size, handle); in fd_bo_from_handle()
223 return bo; in fd_bo_from_handle()
231 struct fd_bo *bo; in fd_bo_from_dmabuf() local
239 bo = lookup_bo(dev->handle_table, handle); in fd_bo_from_dmabuf()
240 if (bo) in fd_bo_from_dmabuf()
247 bo = bo_from_handle(dev, size, handle); in fd_bo_from_dmabuf()
252 return bo; in fd_bo_from_dmabuf()
260 struct fd_bo *bo; in fd_bo_from_name() local
265 bo = lookup_bo(dev->name_table, name); in fd_bo_from_name()
266 if (bo) in fd_bo_from_name()
274 bo = lookup_bo(dev->handle_table, req.handle); in fd_bo_from_name()
275 if (bo) in fd_bo_from_name()
278 bo = bo_from_handle(dev, req.size, req.handle); in fd_bo_from_name()
279 if (bo) in fd_bo_from_name()
280 set_name(bo, name); in fd_bo_from_name()
285 return bo; in fd_bo_from_name()
288 struct fd_bo * fd_bo_ref(struct fd_bo *bo) in fd_bo_ref() argument
290 atomic_inc(&bo->refcnt); in fd_bo_ref()
291 return bo; in fd_bo_ref()
294 void fd_bo_del(struct fd_bo *bo) in fd_bo_del() argument
296 struct fd_device *dev = bo->dev; in fd_bo_del()
298 if (!atomic_dec_and_test(&bo->refcnt)) in fd_bo_del()
303 if (bo->bo_reuse) { in fd_bo_del()
304 struct fd_bo_bucket *bucket = get_bucket(dev, bo->size); in fd_bo_del()
312 bo->free_time = time.tv_sec; in fd_bo_del()
313 list_addtail(&bo->list, &bucket->list); in fd_bo_del()
324 bo_del(bo); in fd_bo_del()
331 static void bo_del(struct fd_bo *bo) in bo_del() argument
333 if (bo->map) in bo_del()
334 drm_munmap(bo->map, bo->size); in bo_del()
340 if (bo->handle) { in bo_del()
342 .handle = bo->handle, in bo_del()
344 drmHashDelete(bo->dev->handle_table, bo->handle); in bo_del()
345 if (bo->name) in bo_del()
346 drmHashDelete(bo->dev->name_table, bo->name); in bo_del()
347 drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req); in bo_del()
350 bo->funcs->destroy(bo); in bo_del()
353 int fd_bo_get_name(struct fd_bo *bo, uint32_t *name) in fd_bo_get_name() argument
355 if (!bo->name) { in fd_bo_get_name()
357 .handle = bo->handle, in fd_bo_get_name()
361 ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req); in fd_bo_get_name()
367 set_name(bo, req.name); in fd_bo_get_name()
369 bo->bo_reuse = 0; in fd_bo_get_name()
372 *name = bo->name; in fd_bo_get_name()
377 uint32_t fd_bo_handle(struct fd_bo *bo) in fd_bo_handle() argument
379 return bo->handle; in fd_bo_handle()
382 int fd_bo_dmabuf(struct fd_bo *bo) in fd_bo_dmabuf() argument
386 ret = drmPrimeHandleToFD(bo->dev->fd, bo->handle, DRM_CLOEXEC, in fd_bo_dmabuf()
393 bo->bo_reuse = 0; in fd_bo_dmabuf()
398 uint32_t fd_bo_size(struct fd_bo *bo) in fd_bo_size() argument
400 return bo->size; in fd_bo_size()
403 void * fd_bo_map(struct fd_bo *bo) in fd_bo_map() argument
405 if (!bo->map) { in fd_bo_map()
409 ret = bo->funcs->offset(bo, &offset); in fd_bo_map()
414 bo->map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, in fd_bo_map()
415 bo->dev->fd, offset); in fd_bo_map()
416 if (bo->map == MAP_FAILED) { in fd_bo_map()
418 bo->map = NULL; in fd_bo_map()
421 return bo->map; in fd_bo_map()
425 int fd_bo_cpu_prep(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t op) in fd_bo_cpu_prep() argument
427 return bo->funcs->cpu_prep(bo, pipe, op); in fd_bo_cpu_prep()
430 void fd_bo_cpu_fini(struct fd_bo *bo) in fd_bo_cpu_fini() argument
432 bo->funcs->cpu_fini(bo); in fd_bo_cpu_fini()