17ec681f3Smrg/* 27ec681f3Smrg * © Copyright 2017-2018 Alyssa Rosenzweig 37ec681f3Smrg * 47ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 57ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 67ec681f3Smrg * to deal in the Software without restriction, including without limitation 77ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 87ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 97ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 107ec681f3Smrg * 117ec681f3Smrg * The above copyright notice and this permission notice (including the next 127ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 137ec681f3Smrg * Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 167ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 197ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 207ec681f3Smrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 217ec681f3Smrg * SOFTWARE. 227ec681f3Smrg * 237ec681f3Smrg */ 247ec681f3Smrg 257ec681f3Smrg#ifndef __PANVK_POOL_H__ 267ec681f3Smrg#define __PANVK_POOL_H__ 277ec681f3Smrg 287ec681f3Smrg#include "pan_pool.h" 297ec681f3Smrg 307ec681f3Smrgstruct panvk_bo_pool { 317ec681f3Smrg struct util_dynarray free_bos; 327ec681f3Smrg}; 337ec681f3Smrg 347ec681f3Smrgstatic inline void panvk_bo_pool_init(struct panvk_bo_pool *bo_pool) 357ec681f3Smrg{ 367ec681f3Smrg util_dynarray_init(&bo_pool->free_bos, NULL); 377ec681f3Smrg} 387ec681f3Smrg 397ec681f3Smrgstatic inline void panvk_bo_pool_cleanup(struct panvk_bo_pool *bo_pool) 407ec681f3Smrg{ 417ec681f3Smrg util_dynarray_foreach(&bo_pool->free_bos, struct panfrost_bo *, bo) 427ec681f3Smrg panfrost_bo_unreference(*bo); 437ec681f3Smrg util_dynarray_fini(&bo_pool->free_bos); 447ec681f3Smrg} 457ec681f3Smrg 467ec681f3Smrg/* Represents grow-only memory. It may be owned by the batch (OpenGL), or may 477ec681f3Smrg be unowned for persistent uploads. */ 487ec681f3Smrg 497ec681f3Smrgstruct panvk_pool { 507ec681f3Smrg /* Inherit from pan_pool */ 517ec681f3Smrg struct pan_pool base; 527ec681f3Smrg 537ec681f3Smrg /* Before allocating a new BO, check if the BO pool has free BOs. 547ec681f3Smrg * When returning BOs, if bo_pool != NULL, return them to this bo_pool. 557ec681f3Smrg */ 567ec681f3Smrg struct panvk_bo_pool *bo_pool; 577ec681f3Smrg 587ec681f3Smrg /* BOs allocated by this pool */ 597ec681f3Smrg struct util_dynarray bos; 607ec681f3Smrg struct util_dynarray big_bos; 617ec681f3Smrg 627ec681f3Smrg /* Current transient BO */ 637ec681f3Smrg struct panfrost_bo *transient_bo; 647ec681f3Smrg 657ec681f3Smrg /* Within the topmost transient BO, how much has been used? */ 667ec681f3Smrg unsigned transient_offset; 677ec681f3Smrg}; 687ec681f3Smrg 697ec681f3Smrgstatic inline struct panvk_pool * 707ec681f3Smrgto_panvk_pool(struct pan_pool *pool) 717ec681f3Smrg{ 727ec681f3Smrg return container_of(pool, struct panvk_pool, base); 737ec681f3Smrg} 747ec681f3Smrg 757ec681f3Smrgvoid 767ec681f3Smrgpanvk_pool_init(struct panvk_pool *pool, struct panfrost_device *dev, 777ec681f3Smrg struct panvk_bo_pool *bo_pool, unsigned create_flags, 787ec681f3Smrg size_t slab_size, const char *label, bool prealloc); 797ec681f3Smrg 807ec681f3Smrgvoid 817ec681f3Smrgpanvk_pool_reset(struct panvk_pool *pool); 827ec681f3Smrg 837ec681f3Smrgvoid 847ec681f3Smrgpanvk_pool_cleanup(struct panvk_pool *pool); 857ec681f3Smrg 867ec681f3Smrgstatic inline unsigned 877ec681f3Smrgpanvk_pool_num_bos(struct panvk_pool *pool) 887ec681f3Smrg{ 897ec681f3Smrg return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *); 907ec681f3Smrg} 917ec681f3Smrg 927ec681f3Smrgvoid 937ec681f3Smrgpanvk_pool_get_bo_handles(struct panvk_pool *pool, uint32_t *handles); 947ec681f3Smrg 957ec681f3Smrg#endif 96