1/*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 * SPDX-License-Identifier: MIT
5 *
6 * based in part on anv driver which is:
7 * Copyright © 2015 Intel Corporation
8 */
9
10#ifndef TU_SUBALLOC_H
11#define TU_SUBALLOC_H
12
13#include "tu_common.h"
14
15#include "tu_drm.h"
16
17/* externally-synchronized BO suballocator. */
18struct tu_suballocator
19{
20   struct tu_device *dev;
21
22   uint32_t default_size;
23   enum tu_bo_alloc_flags flags;
24
25   /** Current BO we're suballocating out of. */
26   struct tu_bo *bo;
27   uint32_t next_offset;
28
29   /** Optional BO cached for recycling as the next suballoc->bo, instead of having to allocate one. */
30   struct tu_bo *cached_bo;
31};
32
33struct tu_suballoc_bo
34{
35   struct tu_bo *bo;
36   uint64_t iova;
37   uint32_t size; /* bytes */
38};
39
40void
41tu_bo_suballocator_init(struct tu_suballocator *suballoc,
42                        struct tu_device *dev,
43                        uint32_t default_size,
44                        uint32_t flags);
45void
46tu_bo_suballocator_finish(struct tu_suballocator *suballoc);
47
48VkResult
49tu_suballoc_bo_alloc(struct tu_suballoc_bo *suballoc_bo, struct tu_suballocator *suballoc,
50                     uint32_t size, uint32_t align);
51
52void *
53tu_suballoc_bo_map(struct tu_suballoc_bo *bo);
54
55void
56tu_suballoc_bo_free(struct tu_suballocator *suballoc, struct tu_suballoc_bo *bo);
57
58#endif /* TU_SUBALLOC_H */
59