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()
56 return bo; in lookup_bo()
63 struct fd_bo *bo; in bo_from_handle() local
65 bo = dev->funcs->bo_from_handle(dev, size, handle); in bo_from_handle()
66 if (!bo) { in bo_from_handle()
73 bo->dev = fd_device_ref(dev); in bo_from_handle()
74 bo->size = size; in bo_from_handle()
75 bo->handle = handle; in bo_from_handle()
76 atomic_set(&bo->refcnt, 1); in bo_from_handle()
77 list_inithead(&bo->list); in bo_from_handle()
79 drmHashInsert(dev->handle_table, handle, bo); in bo_from_handle()
80 return bo; in bo_from_handle()
93 struct fd_bo *bo; in fd_cleanup_bo_cache() local
96 bo = LIST_ENTRY(struct fd_bo, bucket->list.next, list); in fd_cleanup_bo_cache()
99 if (time && ((time - bo->free_time) <= 1)) in fd_cleanup_bo_cache()
102 list_del(&bo->list); in fd_cleanup_bo_cache()
103 bo_del(bo); in fd_cleanup_bo_cache()
127 static int is_idle(struct fd_bo *bo) in is_idle() argument
129 return fd_bo_cpu_prep(bo, NULL, in is_idle()
138 struct fd_bo *bo = NULL; in find_in_bucket() local
149 bo = LIST_ENTRY(struct fd_bo, bucket->list.next, list); in find_in_bucket()
151 list_del(&bo->list); in find_in_bucket()
152 bo_del(bo); in find_in_bucket()
153 bo = NULL; in find_in_bucket()
157 if (is_idle(bo)) { in find_in_bucket()
158 list_del(&bo->list); in find_in_bucket()
161 bo = NULL; in find_in_bucket()
166 return bo; in find_in_bucket()
173 struct fd_bo *bo = NULL; in fd_bo_new() local
184 bo = find_in_bucket(dev, bucket, flags); in fd_bo_new()
185 if (bo) { in fd_bo_new()
186 atomic_set(&bo->refcnt, 1); in fd_bo_new()
187 fd_device_ref(bo->dev); in fd_bo_new()
188 return bo; in fd_bo_new()
197 bo = bo_from_handle(dev, size, handle); in fd_bo_new()
198 bo->bo_reuse = 1; in fd_bo_new()
201 return bo; in fd_bo_new()
207 struct fd_bo *bo = NULL; in fd_bo_from_handle() local
211 bo = lookup_bo(dev->handle_table, handle); in fd_bo_from_handle()
212 if (bo) in fd_bo_from_handle()
215 bo = bo_from_handle(dev, size, handle); in fd_bo_from_handle()
220 return bo; in fd_bo_from_handle()
247 struct fd_bo *bo; in fd_bo_from_name() local
252 bo = lookup_bo(dev->name_table, name); in fd_bo_from_name()
253 if (bo) in fd_bo_from_name()
261 bo = lookup_bo(dev->handle_table, req.handle); in fd_bo_from_name()
262 if (bo) in fd_bo_from_name()
265 bo = bo_from_handle(dev, req.size, req.handle); in fd_bo_from_name()
266 if (bo) in fd_bo_from_name()
267 set_name(bo, name); in fd_bo_from_name()
272 return bo; in fd_bo_from_name()
275 drm_public struct fd_bo * fd_bo_ref(struct fd_bo *bo) in fd_bo_ref() argument
277 atomic_inc(&bo->refcnt); in fd_bo_ref()
278 return bo; in fd_bo_ref()
281 drm_public void fd_bo_del(struct fd_bo *bo) in fd_bo_del() argument
283 struct fd_device *dev = bo->dev; in fd_bo_del()
285 if (!atomic_dec_and_test(&bo->refcnt)) in fd_bo_del()
288 if (bo->fd) { in fd_bo_del()
289 close(bo->fd); in fd_bo_del()
290 bo->fd = 0; in fd_bo_del()
295 if (bo->bo_reuse) { in fd_bo_del()
296 struct fd_bo_bucket *bucket = get_bucket(dev, bo->size); in fd_bo_del()
304 bo->free_time = time.tv_sec; in fd_bo_del()
305 list_addtail(&bo->list, &bucket->list); in fd_bo_del()
316 bo_del(bo); in fd_bo_del()
323 static void bo_del(struct fd_bo *bo) in bo_del() argument
325 if (bo->map) in bo_del()
326 drm_munmap(bo->map, bo->size); in bo_del()
332 if (bo->handle) { in bo_del()
334 .handle = bo->handle, in bo_del()
336 drmHashDelete(bo->dev->handle_table, bo->handle); in bo_del()
337 if (bo->name) in bo_del()
338 drmHashDelete(bo->dev->name_table, bo->name); in bo_del()
339 drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_CLOSE, &req); in bo_del()
342 bo->funcs->destroy(bo); in bo_del()
345 drm_public int fd_bo_get_name(struct fd_bo *bo, uint32_t *name) in fd_bo_get_name() argument
347 if (!bo->name) { in fd_bo_get_name()
349 .handle = bo->handle, in fd_bo_get_name()
353 ret = drmIoctl(bo->dev->fd, DRM_IOCTL_GEM_FLINK, &req); in fd_bo_get_name()
359 set_name(bo, req.name); in fd_bo_get_name()
363 *name = bo->name; in fd_bo_get_name()
368 drm_public uint32_t fd_bo_handle(struct fd_bo *bo) in fd_bo_handle() argument
370 return bo->handle; in fd_bo_handle()
373 drm_public int fd_bo_dmabuf(struct fd_bo *bo) in fd_bo_dmabuf() argument
375 if (!bo->fd) { in fd_bo_dmabuf()
377 .handle = bo->handle, in fd_bo_dmabuf()
382 ret = drmIoctl(bo->dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req); in fd_bo_dmabuf()
387 bo->fd = req.fd; in fd_bo_dmabuf()
389 return dup(bo->fd); in fd_bo_dmabuf()
392 drm_public uint32_t fd_bo_size(struct fd_bo *bo) in fd_bo_size() argument
394 return bo->size; in fd_bo_size()
397 drm_public void * fd_bo_map(struct fd_bo *bo) in fd_bo_map() argument
399 if (!bo->map) { in fd_bo_map()
403 ret = bo->funcs->offset(bo, &offset); in fd_bo_map()
408 bo->map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, in fd_bo_map()
409 bo->dev->fd, offset); in fd_bo_map()
410 if (bo->map == MAP_FAILED) { in fd_bo_map()
412 bo->map = NULL; in fd_bo_map()
415 return bo->map; in fd_bo_map()
419 drm_public int fd_bo_cpu_prep(struct fd_bo *bo, struct fd_pipe *pipe, uint32_t op) in fd_bo_cpu_prep() argument
421 return bo->funcs->cpu_prep(bo, pipe, op); in fd_bo_cpu_prep()
424 drm_public void fd_bo_cpu_fini(struct fd_bo *bo) in fd_bo_cpu_fini() argument
426 bo->funcs->cpu_fini(bo); in fd_bo_cpu_fini()