• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2019 Raspberry Pi Ltd
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    uint64_t handle_bit;
34    uint32_t size;
35    uint32_t offset;
36 
37    uint32_t map_size;
38    void *map;
39 
40    const char *name;
41 
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. */
47    time_t free_time;
48 
49    /**
50     * Whether only our process has a reference to the BO (meaning that
51     * it's safe to reuse it in the BO cache).
52     */
53    bool private;
54 
55    /**
56     * If this BO was allocated for a swapchain on the display device, the
57     * handle of the dumb BO on that device.
58     */
59    int32_t dumb_handle;
60 
61    int32_t refcnt;
62 };
63 
64 void v3dv_bo_init(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t offset, const char *name, bool private);
65 
66 struct v3dv_bo *v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, const char *name, bool private);
67 
68 bool v3dv_bo_free(struct v3dv_device *device, struct v3dv_bo *bo);
69 
70 bool v3dv_bo_wait(struct v3dv_device *device, struct v3dv_bo *bo, uint64_t timeout_ns);
71 
72 bool v3dv_bo_map_unsynchronized(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size);
73 
74 bool v3dv_bo_map(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size);
75 
76 void v3dv_bo_unmap(struct v3dv_device *device, struct v3dv_bo *bo);
77 
78 void v3dv_bo_cache_init(struct v3dv_device *device);
79 void v3dv_bo_cache_destroy(struct v3dv_device *device);
80 
81 #endif /* V3DV_BO_H */
82