• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * © Copyright 2017-2018 Alyssa Rosenzweig
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 FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  */
24 
25 #ifndef __PAN_MEMPOOL_H__
26 #define __PAN_MEMPOOL_H__
27 
28 #include "pan_pool.h"
29 
30 /* Represents grow-only memory. It may be owned by the batch (OpenGL), or may
31    be unowned for persistent uploads. */
32 
33 struct panfrost_pool {
34         /* Inherit from pan_pool */
35         struct pan_pool base;
36 
37         /* BOs allocated by this pool */
38         struct util_dynarray bos;
39 
40         /* Current transient BO */
41         struct panfrost_bo *transient_bo;
42 
43         /* Within the topmost transient BO, how much has been used? */
44         unsigned transient_offset;
45 
46         /* Mode of the pool. BO management is in the pool for owned mode, but
47          * the consumed for unowned mode. */
48         bool owned;
49 };
50 
51 static inline struct panfrost_pool *
to_panfrost_pool(struct pan_pool * pool)52 to_panfrost_pool(struct pan_pool *pool)
53 {
54         return container_of(pool, struct panfrost_pool, base);
55 }
56 
57 /* Reference to pool allocated memory for an unowned pool */
58 
59 struct panfrost_pool_ref {
60         /* Owning BO */
61         struct panfrost_bo *bo;
62 
63         /* Mapped GPU VA */
64         mali_ptr gpu;
65 };
66 
67 /* Take a reference to an allocation pool. Call directly after allocating from
68  * an unowned pool for correct operation. */
69 
70 static inline struct panfrost_pool_ref
panfrost_pool_take_ref(struct panfrost_pool * pool,mali_ptr ptr)71 panfrost_pool_take_ref(struct panfrost_pool *pool, mali_ptr ptr)
72 {
73         if (!pool->owned)
74                 panfrost_bo_reference(pool->transient_bo);
75 
76         return (struct panfrost_pool_ref) {
77                 .bo = pool->transient_bo,
78                 .gpu = ptr
79         };
80 }
81 
82 void
83 panfrost_pool_init(struct panfrost_pool *pool, void *memctx,
84                    struct panfrost_device *dev, unsigned create_flags,
85                    size_t slab_size, const char *label, bool prealloc, bool
86                    owned);
87 
88 void
89 panfrost_pool_cleanup(struct panfrost_pool *pool);
90 
91 static inline unsigned
panfrost_pool_num_bos(struct panfrost_pool * pool)92 panfrost_pool_num_bos(struct panfrost_pool *pool)
93 {
94         assert(pool->owned && "pool does not track BOs in unowned mode");
95         return util_dynarray_num_elements(&pool->bos, struct panfrost_bo *);
96 }
97 
98 void
99 panfrost_pool_get_bo_handles(struct panfrost_pool *pool, uint32_t *handles);
100 
101 #endif
102