GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / gpu / drm / nouveau / include / nvkm / core / mm.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NVKM_MM_H__
3 #define __NVKM_MM_H__
4 #include <core/os.h>
5
6 struct nvkm_mm_node {
7         struct list_head nl_entry;
8         struct list_head fl_entry;
9         struct nvkm_mm_node *next;
10
11 #define NVKM_MM_HEAP_ANY 0x00
12         u8  heap;
13 #define NVKM_MM_TYPE_NONE 0x00
14 #define NVKM_MM_TYPE_HOLE 0xff
15         u8  type;
16         u32 offset;
17         u32 length;
18 };
19
20 struct nvkm_mm {
21         struct list_head nodes;
22         struct list_head free;
23
24         u32 block_size;
25         int heap_nodes;
26 };
27
28 static inline bool
29 nvkm_mm_initialised(struct nvkm_mm *mm)
30 {
31         return mm->heap_nodes;
32 }
33
34 int  nvkm_mm_init(struct nvkm_mm *, u32 offset, u32 length, u32 block);
35 int  nvkm_mm_fini(struct nvkm_mm *);
36 int  nvkm_mm_head(struct nvkm_mm *, u8 heap, u8 type, u32 size_max,
37                   u32 size_min, u32 align, struct nvkm_mm_node **);
38 int  nvkm_mm_tail(struct nvkm_mm *, u8 heap, u8 type, u32 size_max,
39                   u32 size_min, u32 align, struct nvkm_mm_node **);
40 void nvkm_mm_free(struct nvkm_mm *, struct nvkm_mm_node **);
41 void nvkm_mm_dump(struct nvkm_mm *, const char *);
42
43 static inline bool
44 nvkm_mm_contiguous(struct nvkm_mm_node *node)
45 {
46         return !node->next;
47 }
48 #endif