1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * © Copyright 2017-2018 Alyssa Rosenzweig 3bf215546Sopenharmony_ci * 4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci * 11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 13bf215546Sopenharmony_ci * Software. 14bf215546Sopenharmony_ci * 15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21bf215546Sopenharmony_ci * SOFTWARE. 22bf215546Sopenharmony_ci * 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#ifndef __PANVK_POOL_H__ 26bf215546Sopenharmony_ci#define __PANVK_POOL_H__ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "pan_pool.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_cistruct panvk_bo_pool { 31bf215546Sopenharmony_ci struct util_dynarray free_bos; 32bf215546Sopenharmony_ci}; 33bf215546Sopenharmony_ci 34bf215546Sopenharmony_cistatic inline void panvk_bo_pool_init(struct panvk_bo_pool *bo_pool) 35bf215546Sopenharmony_ci{ 36bf215546Sopenharmony_ci util_dynarray_init(&bo_pool->free_bos, NULL); 37bf215546Sopenharmony_ci} 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_cistatic inline void panvk_bo_pool_cleanup(struct panvk_bo_pool *bo_pool) 40bf215546Sopenharmony_ci{ 41bf215546Sopenharmony_ci util_dynarray_foreach(&bo_pool->free_bos, struct panfrost_bo *, bo) 42bf215546Sopenharmony_ci panfrost_bo_unreference(*bo); 43bf215546Sopenharmony_ci util_dynarray_fini(&bo_pool->free_bos); 44bf215546Sopenharmony_ci} 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci/* Represents grow-only memory. It may be owned by the batch (OpenGL), or may 47bf215546Sopenharmony_ci be unowned for persistent uploads. */ 48bf215546Sopenharmony_ci 49bf215546Sopenharmony_cistruct panvk_pool { 50bf215546Sopenharmony_ci /* Inherit from pan_pool */ 51bf215546Sopenharmony_ci struct pan_pool base; 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci /* Before allocating a new BO, check if the BO pool has free BOs. 54bf215546Sopenharmony_ci * When returning BOs, if bo_pool != NULL, return them to this bo_pool. 55bf215546Sopenharmony_ci */ 56bf215546Sopenharmony_ci struct panvk_bo_pool *bo_pool; 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci /* BOs allocated by this pool */ 59bf215546Sopenharmony_ci struct util_dynarray bos; 60bf215546Sopenharmony_ci struct util_dynarray big_bos; 61bf215546Sopenharmony_ci 62bf215546Sopenharmony_ci /* Current transient BO */ 63bf215546Sopenharmony_ci struct panfrost_bo *transient_bo; 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci /* Within the topmost transient BO, how much has been used? */ 66bf215546Sopenharmony_ci unsigned transient_offset; 67bf215546Sopenharmony_ci}; 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_cistatic inline struct panvk_pool * 70bf215546Sopenharmony_cito_panvk_pool(struct pan_pool *pool) 71bf215546Sopenharmony_ci{ 72bf215546Sopenharmony_ci return container_of(pool, struct panvk_pool, base); 73bf215546Sopenharmony_ci} 74bf215546Sopenharmony_ci 75bf215546Sopenharmony_civoid 76bf215546Sopenharmony_cipanvk_pool_init(struct panvk_pool *pool, struct panfrost_device *dev, 77bf215546Sopenharmony_ci struct panvk_bo_pool *bo_pool, unsigned create_flags, 78bf215546Sopenharmony_ci size_t slab_size, const char *label, bool prealloc); 79bf215546Sopenharmony_ci 80bf215546Sopenharmony_civoid 81bf215546Sopenharmony_cipanvk_pool_reset(struct panvk_pool *pool); 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_civoid 84bf215546Sopenharmony_cipanvk_pool_cleanup(struct panvk_pool *pool); 85bf215546Sopenharmony_ci 86bf215546Sopenharmony_cistatic inline unsigned 87bf215546Sopenharmony_cipanvk_pool_num_bos(struct panvk_pool *pool) 88bf215546Sopenharmony_ci{ 89bf215546Sopenharmony_ci return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *); 90bf215546Sopenharmony_ci} 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_civoid 93bf215546Sopenharmony_cipanvk_pool_get_bo_handles(struct panvk_pool *pool, uint32_t *handles); 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ci#endif 96