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