2 * Copyright © 2014 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include "util/u_hash_table.h"
29 #include "util/u_inlines.h"
35 struct pipe_reference reference
;
36 struct vc4_screen
*screen
;
42 /** Entry in the linked list of buffers freed, by age. */
43 struct list_head time_list
;
44 /** Entry in the per-page-count linked list of buffers freed (by age). */
45 struct list_head size_list
;
46 /** Approximate second when the bo was freed. */
49 * Whether only our process has a reference to the BO (meaning that
50 * it's safe to reuse it in the BO cache).
55 struct vc4_bo
*vc4_bo_alloc(struct vc4_screen
*screen
, uint32_t size
,
57 struct vc4_bo
*vc4_bo_alloc_shader(struct vc4_screen
*screen
, const void *data
,
59 void vc4_bo_last_unreference(struct vc4_bo
*bo
);
60 void vc4_bo_last_unreference_locked_timed(struct vc4_bo
*bo
, time_t time
);
61 struct vc4_bo
*vc4_bo_open_name(struct vc4_screen
*screen
, uint32_t name
,
62 uint32_t winsys_stride
);
63 struct vc4_bo
*vc4_bo_open_dmabuf(struct vc4_screen
*screen
, int fd
,
64 uint32_t winsys_stride
);
65 bool vc4_bo_flink(struct vc4_bo
*bo
, uint32_t *name
);
66 int vc4_bo_get_dmabuf(struct vc4_bo
*bo
);
69 vc4_bo_set_reference(struct vc4_bo
**old_bo
, struct vc4_bo
*new_bo
)
71 if (pipe_reference(&(*old_bo
)->reference
, &new_bo
->reference
))
72 vc4_bo_last_unreference(*old_bo
);
76 static inline struct vc4_bo
*
77 vc4_bo_reference(struct vc4_bo
*bo
)
79 pipe_reference(NULL
, &bo
->reference
);
84 vc4_bo_unreference(struct vc4_bo
**bo
)
86 struct vc4_screen
*screen
;
91 /* Avoid the mutex for private BOs */
92 if (pipe_reference(&(*bo
)->reference
, NULL
))
93 vc4_bo_last_unreference(*bo
);
95 screen
= (*bo
)->screen
;
96 mtx_lock(&screen
->bo_handles_mutex
);
98 if (pipe_reference(&(*bo
)->reference
, NULL
)) {
99 util_hash_table_remove(screen
->bo_handles
,
100 (void *)(uintptr_t)(*bo
)->handle
);
101 vc4_bo_last_unreference(*bo
);
104 pipe_mutex_unlock(screen
->bo_handles_mutex
);
111 vc4_bo_unreference_locked_timed(struct vc4_bo
**bo
, time_t time
)
116 if (pipe_reference(&(*bo
)->reference
, NULL
))
117 vc4_bo_last_unreference_locked_timed(*bo
, time
);
122 vc4_bo_map(struct vc4_bo
*bo
);
125 vc4_bo_map_unsynchronized(struct vc4_bo
*bo
);
128 vc4_bo_wait(struct vc4_bo
*bo
, uint64_t timeout_ns
, const char *reason
);
131 vc4_wait_seqno(struct vc4_screen
*screen
, uint64_t seqno
, uint64_t timeout_ns
,
135 vc4_bufmgr_destroy(struct pipe_screen
*pscreen
);
137 #endif /* VC4_BUFMGR_H */