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 /* In a CL where a BRANCH has been emitted, the offset of the BRANCH 43 * instruction in the BO. 44 */ 45 uint32_t cl_branch_offset; 46 47 /** Entry in the linked list of buffers freed, by age. */ 48 struct list_head time_list; 49 /** Entry in the per-page-count linked list of buffers freed (by age). */ 50 struct list_head size_list; 51 /** Approximate second when the bo was freed. */ 52 time_t free_time; 53 54 /** 55 * Whether only our process has a reference to the BO (meaning that 56 * it's safe to reuse it in the BO cache). 57 */ 58 bool private; 59 60 /** If this BO has been imported */ 61 bool is_import; 62 63 /** 64 * If this BO was allocated for a swapchain on the display device, the 65 * handle of the dumb BO on that device. 66 */ 67 int32_t dumb_handle; 68 69 int32_t refcnt; 70 }; 71 72 void v3dv_bo_init(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t offset, const char *name, bool private); 73 void v3dv_bo_init_import(struct v3dv_bo *bo, uint32_t handle, uint32_t size, uint32_t offset, bool private); 74 75 struct v3dv_bo *v3dv_bo_alloc(struct v3dv_device *device, uint32_t size, const char *name, bool private); 76 77 bool v3dv_bo_free(struct v3dv_device *device, struct v3dv_bo *bo); 78 79 bool v3dv_bo_wait(struct v3dv_device *device, struct v3dv_bo *bo, uint64_t timeout_ns); 80 81 bool v3dv_bo_map_unsynchronized(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size); 82 83 bool v3dv_bo_map(struct v3dv_device *device, struct v3dv_bo *bo, uint32_t size); 84 85 void v3dv_bo_unmap(struct v3dv_device *device, struct v3dv_bo *bo); 86 87 void v3dv_bo_cache_init(struct v3dv_device *device); 88 void v3dv_bo_cache_destroy(struct v3dv_device *device); 89 90 #endif /* V3DV_BO_H */ 91