1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
3 * Copyright 2011 Red Hat Inc.
4 * Copyright © 2022 Intel Corporation
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
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
{
26 struct list_head
*hole
;
27 struct list_head olist
;
28 struct list_head flist
[DRM_SUBALLOC_MAX_QUEUES
];
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.
43 struct list_head olist
;
44 struct list_head flist
;
45 struct drm_suballoc_manager
*manager
;
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
);
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
);
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
)
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
)
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
);
101 drm_suballoc_dump_debug_info(struct drm_suballoc_manager
*sa_manager
,
102 struct drm_printer
*p
,
103 unsigned long long suballoc_base
)
108 #endif /* _DRM_SUBALLOC_H_ */