panfrost: Move pool routines to common code
[mesa.git] / src / panfrost / encoder / pan_pool.h
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_POOL_H__
26 #define __PAN_POOL_H__
27
28 #include <panfrost-misc.h>
29
30 /* Represents a pool of memory that can only grow, used to allocate objects
31 * with the same lifetime as the pool itself. In OpenGL, a pool is owned by the
32 * batch for transient structures. In Vulkan, it may be owned by e.g. the
33 * command pool */
34
35 struct pan_pool {
36 /* Parent device for allocation */
37 struct panfrost_device *dev;
38
39 /* panfrost_bo -> access_flags owned by the pool */
40 struct hash_table *bos;
41
42 /* Current transient BO */
43 struct panfrost_bo *transient_bo;
44
45 /* Within the topmost transient BO, how much has been used? */
46 unsigned transient_offset;
47 };
48
49 struct pan_pool
50 panfrost_create_pool(void *memctx, struct panfrost_device *dev);
51
52 /* Represents a fat pointer for GPU-mapped memory, returned from the transient
53 * allocator and not used for much else */
54
55 struct panfrost_transfer {
56 uint8_t *cpu;
57 mali_ptr gpu;
58 };
59
60 struct panfrost_transfer
61 panfrost_pool_alloc(struct pan_pool *pool, size_t sz);
62
63 mali_ptr
64 panfrost_pool_upload(struct pan_pool *pool, const void *data, size_t sz);
65
66 #endif