1 /* 2 * Copyright © 2016 Red Hat. 3 * Copyright © 2016 Bas Nieuwenhuizen 4 * SPDX-License-Identifier: MIT 5 * 6 * based in part on anv driver which is: 7 * Copyright © 2015 Intel Corporation 8 */ 9 10 #ifndef TU_SUBALLOC_H 11 #define TU_SUBALLOC_H 12 13 #include "tu_common.h" 14 15 #include "tu_knl.h" 16 17 /* externally-synchronized BO suballocator. */ 18 struct tu_suballocator 19 { 20 struct tu_device *dev; 21 22 uint32_t default_size; 23 enum tu_bo_alloc_flags flags; 24 25 /** Current BO we're suballocating out of. */ 26 struct tu_bo *bo; 27 uint32_t next_offset; 28 29 /** Optional BO cached for recycling as the next suballoc->bo, instead of having to allocate one. */ 30 struct tu_bo *cached_bo; 31 32 const char *name; 33 }; 34 35 struct tu_suballoc_bo 36 { 37 struct tu_bo *bo; 38 uint64_t iova; 39 uint32_t size; /* bytes */ 40 }; 41 42 void 43 tu_bo_suballocator_init(struct tu_suballocator *suballoc, 44 struct tu_device *dev, 45 uint32_t default_size, 46 enum tu_bo_alloc_flags flags, 47 const char *name); 48 void 49 tu_bo_suballocator_finish(struct tu_suballocator *suballoc); 50 51 VkResult 52 tu_suballoc_bo_alloc(struct tu_suballoc_bo *suballoc_bo, struct tu_suballocator *suballoc, 53 uint32_t size, uint32_t alignment); 54 55 void * 56 tu_suballoc_bo_map(struct tu_suballoc_bo *bo); 57 58 void 59 tu_suballoc_bo_free(struct tu_suballocator *suballoc, struct tu_suballoc_bo *bo); 60 61 #endif /* TU_SUBALLOC_H */ 62