Path: blob/21.2-virgl/src/gallium/drivers/v3d/v3d_bufmgr.h
4570 views
/*1* Copyright © 2014 Broadcom2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#ifndef V3D_BUFMGR_H24#define V3D_BUFMGR_H2526#include <stdint.h>27#include "util/u_hash_table.h"28#include "util/u_inlines.h"29#include "util/list.h"30#include "v3d_screen.h"3132struct v3d_context;3334struct v3d_bo {35struct pipe_reference reference;36struct v3d_screen *screen;37void *map;38const char *name;39uint32_t handle;40uint32_t size;4142/* Address of the BO in our page tables. */43uint32_t offset;4445/** Entry in the linked list of buffers freed, by age. */46struct list_head time_list;47/** Entry in the per-page-count linked list of buffers freed (by age). */48struct list_head size_list;49/** Approximate second when the bo was freed. */50time_t free_time;51/**52* Whether only our process has a reference to the BO (meaning that53* it's safe to reuse it in the BO cache).54*/55bool private;56};5758struct v3d_bo *v3d_bo_alloc(struct v3d_screen *screen, uint32_t size,59const char *name);60void v3d_bo_last_unreference(struct v3d_bo *bo);61void v3d_bo_last_unreference_locked_timed(struct v3d_bo *bo, time_t time);62struct v3d_bo *v3d_bo_open_name(struct v3d_screen *screen, uint32_t name);63struct v3d_bo *v3d_bo_open_dmabuf(struct v3d_screen *screen, int fd);64bool v3d_bo_flink(struct v3d_bo *bo, uint32_t *name);65int v3d_bo_get_dmabuf(struct v3d_bo *bo);6667static inline void68v3d_bo_set_reference(struct v3d_bo **old_bo, struct v3d_bo *new_bo)69{70if (pipe_reference(&(*old_bo)->reference, &new_bo->reference))71v3d_bo_last_unreference(*old_bo);72*old_bo = new_bo;73}7475static inline struct v3d_bo *76v3d_bo_reference(struct v3d_bo *bo)77{78pipe_reference(NULL, &bo->reference);79return bo;80}8182static inline void83v3d_bo_unreference(struct v3d_bo **bo)84{85struct v3d_screen *screen;86if (!*bo)87return;8889if ((*bo)->private) {90/* Avoid the mutex for private BOs */91if (pipe_reference(&(*bo)->reference, NULL))92v3d_bo_last_unreference(*bo);93} else {94screen = (*bo)->screen;95mtx_lock(&screen->bo_handles_mutex);9697if (pipe_reference(&(*bo)->reference, NULL)) {98_mesa_hash_table_remove_key(screen->bo_handles,99(void *)(uintptr_t)(*bo)->handle);100v3d_bo_last_unreference(*bo);101}102103mtx_unlock(&screen->bo_handles_mutex);104}105106*bo = NULL;107}108109static inline void110v3d_bo_unreference_locked_timed(struct v3d_bo **bo, time_t time)111{112if (!*bo)113return;114115if (pipe_reference(&(*bo)->reference, NULL))116v3d_bo_last_unreference_locked_timed(*bo, time);117*bo = NULL;118}119120void *121v3d_bo_map(struct v3d_bo *bo);122123void *124v3d_bo_map_unsynchronized(struct v3d_bo *bo);125126bool127v3d_bo_wait(struct v3d_bo *bo, uint64_t timeout_ns, const char *reason);128129bool130v3d_wait_seqno(struct v3d_screen *screen, uint64_t seqno, uint64_t timeout_ns,131const char *reason);132133void134v3d_bufmgr_destroy(struct pipe_screen *pscreen);135136#endif /* V3D_BUFMGR_H */137138139140