1 /*
2  * Copyright © 2019 Raspberry Pi
3  *
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:
10  *
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
13  * Software.
14  *
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
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef V3DV_BO_H
25 #define V3DV_BO_H
26 
27 struct v3dv_device;
28 
29 struct v3dv_bo {
30    struct list_head list_link;
31 
32    uint32_t handle;
33    uint32_t size;
34    uint32_t offset;
35 
36    uint32_t map_size;
37    void *map;
38 
39    const char *name;
40 
41    /** Entry in the linked list of buffers freed, by age. */
42    struct list_head time_list;
43    /** Entry in the per-page-count linked list of buffers freed (by age). */
44    struct list_head size_list;
45    /** Approximate second when the bo was freed. */
46    time_t free_time;
47 
48    /**
49     * Whether only our process has a reference to the BO (meaning that
50     * it's safe to reuse it in the BO cache).
51     */
52    bool private;
53 
54    /**
55     * If this BO was allocated for a swapchain on the display device, the
56     * handle of the dumb BO on that device.
57     */
58    int32_t dumb_handle;
59 };
60 
61 void v3dv_bo_init(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t offset, const char *name, bool private);
62 
63 struct v3dv_bo *v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, const char *name, bool private);
64 
65 bool v3dv_bo_free(struct v3dv_device *device, struct v3dv_bo *bo);
66 
67 bool v3dv_bo_wait(struct v3dv_device *device, struct v3dv_bo *bo, uint64_t timeout_ns);
68 
69 bool v3dv_bo_map_unsynchronized(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size);
70 
71 bool v3dv_bo_map(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size);
72 
73 void v3dv_bo_unmap(struct v3dv_device *device, struct v3dv_bo *bo);
74 
75 void v3dv_bo_cache_init(struct v3dv_device *device);
76 void v3dv_bo_cache_destroy(struct v3dv_device *device);
77 
78 #endif /* V3DV_BO_H */
79