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 __PAN_MEMPOOL_H__ 26bf215546Sopenharmony_ci#define __PAN_MEMPOOL_H__ 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "pan_pool.h" 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci/* Represents grow-only memory. It may be owned by the batch (OpenGL), or may 31bf215546Sopenharmony_ci be unowned for persistent uploads. */ 32bf215546Sopenharmony_ci 33bf215546Sopenharmony_cistruct panfrost_pool { 34bf215546Sopenharmony_ci /* Inherit from pan_pool */ 35bf215546Sopenharmony_ci struct pan_pool base; 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci /* BOs allocated by this pool */ 38bf215546Sopenharmony_ci struct util_dynarray bos; 39bf215546Sopenharmony_ci 40bf215546Sopenharmony_ci /* Current transient BO */ 41bf215546Sopenharmony_ci struct panfrost_bo *transient_bo; 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_ci /* Within the topmost transient BO, how much has been used? */ 44bf215546Sopenharmony_ci unsigned transient_offset; 45bf215546Sopenharmony_ci 46bf215546Sopenharmony_ci /* Mode of the pool. BO management is in the pool for owned mode, but 47bf215546Sopenharmony_ci * the consumed for unowned mode. */ 48bf215546Sopenharmony_ci bool owned; 49bf215546Sopenharmony_ci}; 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_cistatic inline struct panfrost_pool * 52bf215546Sopenharmony_cito_panfrost_pool(struct pan_pool *pool) 53bf215546Sopenharmony_ci{ 54bf215546Sopenharmony_ci return container_of(pool, struct panfrost_pool, base); 55bf215546Sopenharmony_ci} 56bf215546Sopenharmony_ci 57bf215546Sopenharmony_ci/* Reference to pool allocated memory for an unowned pool */ 58bf215546Sopenharmony_ci 59bf215546Sopenharmony_cistruct panfrost_pool_ref { 60bf215546Sopenharmony_ci /* Owning BO */ 61bf215546Sopenharmony_ci struct panfrost_bo *bo; 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci /* Mapped GPU VA */ 64bf215546Sopenharmony_ci mali_ptr gpu; 65bf215546Sopenharmony_ci}; 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci/* Take a reference to an allocation pool. Call directly after allocating from 68bf215546Sopenharmony_ci * an unowned pool for correct operation. */ 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_cistatic inline struct panfrost_pool_ref 71bf215546Sopenharmony_cipanfrost_pool_take_ref(struct panfrost_pool *pool, mali_ptr ptr) 72bf215546Sopenharmony_ci{ 73bf215546Sopenharmony_ci if (!pool->owned) 74bf215546Sopenharmony_ci panfrost_bo_reference(pool->transient_bo); 75bf215546Sopenharmony_ci 76bf215546Sopenharmony_ci return (struct panfrost_pool_ref) { 77bf215546Sopenharmony_ci .bo = pool->transient_bo, 78bf215546Sopenharmony_ci .gpu = ptr 79bf215546Sopenharmony_ci }; 80bf215546Sopenharmony_ci} 81bf215546Sopenharmony_ci 82bf215546Sopenharmony_civoid 83bf215546Sopenharmony_cipanfrost_pool_init(struct panfrost_pool *pool, void *memctx, 84bf215546Sopenharmony_ci struct panfrost_device *dev, unsigned create_flags, 85bf215546Sopenharmony_ci size_t slab_size, const char *label, bool prealloc, bool 86bf215546Sopenharmony_ci owned); 87bf215546Sopenharmony_ci 88bf215546Sopenharmony_civoid 89bf215546Sopenharmony_cipanfrost_pool_cleanup(struct panfrost_pool *pool); 90bf215546Sopenharmony_ci 91bf215546Sopenharmony_cistatic inline unsigned 92bf215546Sopenharmony_cipanfrost_pool_num_bos(struct panfrost_pool *pool) 93bf215546Sopenharmony_ci{ 94bf215546Sopenharmony_ci assert(pool->owned && "pool does not track BOs in unowned mode"); 95bf215546Sopenharmony_ci return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *); 96bf215546Sopenharmony_ci} 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_civoid 99bf215546Sopenharmony_cipanfrost_pool_get_bo_handles(struct panfrost_pool *pool, uint32_t *handles); 100bf215546Sopenharmony_ci 101bf215546Sopenharmony_ci#endif 102