Linux 6.12-rc7
[linux-stable.git] / include / drm / drm_suballoc.h
blob7ba72a81a808f4133d763e5826c9826bc4cb34f0
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /*
3 * Copyright 2011 Red Hat Inc.
4 * Copyright © 2022 Intel Corporation
5 */
6 #ifndef _DRM_SUBALLOC_H_
7 #define _DRM_SUBALLOC_H_
9 #include <drm/drm_mm.h>
11 #include <linux/dma-fence.h>
12 #include <linux/types.h>
14 #define DRM_SUBALLOC_MAX_QUEUES 32
15 /**
16 * struct drm_suballoc_manager - fenced range allocations
17 * @wq: Wait queue for sleeping allocations on contention.
18 * @hole: Pointer to first hole node.
19 * @olist: List of allocated ranges.
20 * @flist: Array[fence context hash] of queues of fenced allocated ranges.
21 * @size: Size of the managed range.
22 * @align: Default alignment for the managed range.
24 struct drm_suballoc_manager {
25 wait_queue_head_t wq;
26 struct list_head *hole;
27 struct list_head olist;
28 struct list_head flist[DRM_SUBALLOC_MAX_QUEUES];
29 size_t size;
30 size_t align;
33 /**
34 * struct drm_suballoc - Sub-allocated range
35 * @olist: List link for list of allocated ranges.
36 * @flist: List linkk for the manager fenced allocated ranges queues.
37 * @manager: The drm_suballoc_manager.
38 * @soffset: Start offset.
39 * @eoffset: End offset + 1 so that @eoffset - @soffset = size.
40 * @fence: The fence protecting the allocation.
42 struct drm_suballoc {
43 struct list_head olist;
44 struct list_head flist;
45 struct drm_suballoc_manager *manager;
46 size_t soffset;
47 size_t eoffset;
48 struct dma_fence *fence;
51 void drm_suballoc_manager_init(struct drm_suballoc_manager *sa_manager,
52 size_t size, size_t align);
54 void drm_suballoc_manager_fini(struct drm_suballoc_manager *sa_manager);
56 struct drm_suballoc *
57 drm_suballoc_new(struct drm_suballoc_manager *sa_manager, size_t size,
58 gfp_t gfp, bool intr, size_t align);
60 void drm_suballoc_free(struct drm_suballoc *sa, struct dma_fence *fence);
62 /**
63 * drm_suballoc_soffset - Range start.
64 * @sa: The struct drm_suballoc.
66 * Return: The start of the allocated range.
68 static inline size_t drm_suballoc_soffset(struct drm_suballoc *sa)
70 return sa->soffset;
73 /**
74 * drm_suballoc_eoffset - Range end.
75 * @sa: The struct drm_suballoc.
77 * Return: The end of the allocated range + 1.
79 static inline size_t drm_suballoc_eoffset(struct drm_suballoc *sa)
81 return sa->eoffset;
84 /**
85 * drm_suballoc_size - Range size.
86 * @sa: The struct drm_suballoc.
88 * Return: The size of the allocated range.
90 static inline size_t drm_suballoc_size(struct drm_suballoc *sa)
92 return sa->eoffset - sa->soffset;
95 #ifdef CONFIG_DEBUG_FS
96 void drm_suballoc_dump_debug_info(struct drm_suballoc_manager *sa_manager,
97 struct drm_printer *p,
98 unsigned long long suballoc_base);
99 #else
100 static inline void
101 drm_suballoc_dump_debug_info(struct drm_suballoc_manager *sa_manager,
102 struct drm_printer *p,
103 unsigned long long suballoc_base)
106 #endif
108 #endif /* _DRM_SUBALLOC_H_ */