xref: /rk3399_rockchip-uboot/include/sysmem.h (revision 2c9d117912719dca97b8973eeed469b5fa5dce1a)
1 /* SPDX-License-Identifier:     GPL-2.0+ */
2 /*
3  * (C) Copyright 2019 Rockchip Electronics Co., Ltd
4  */
5 
6 #ifndef _SYSMEM_H
7 #define _SYSMEM_H
8 
9 #include <asm/types.h>
10 
11 #define	MAX_SYSMEM_REGIONS		64
12 
13 #undef	MAX_LMB_REGIONS
14 #define	MAX_LMB_REGIONS			MAX_SYSMEM_REGIONS
15 
16 /*
17  * CONFIG_SYS_FDT_PAD default value is sync with bootm framework in:
18  * common/image-fdt.c
19  */
20 #ifndef CONFIG_SYS_FDT_PAD
21 #define CONFIG_SYS_FDT_PAD		0x3000
22 #endif
23 
24 struct sysmem_property {
25 	const char *name;
26 	phys_addr_t base;
27 	phys_size_t size;
28 	struct list_head node;
29 };
30 
31 struct sysmem {
32 	struct lmb lmb;
33 	struct list_head allocated_head;
34 	struct list_head reserved_head;
35 	ulong allocated_cnt;
36 	bool has_init;
37 };
38 
39 /**
40  * sysmem_init() - Sysmem initialization
41  *
42  * @return 0 on success, otherwise error
43  */
44 int sysmem_init(void);
45 
46 /**
47  * sysmem_add() - Add sysmem region
48  *
49  * @base: region base address
50  * @size: region size
51  *
52  * @return 0 on success, otherwise error
53  */
54 int sysmem_add(phys_addr_t base, phys_size_t size);
55 
56 /**
57  * sysmem_reserve() - Reserve sysmem region
58  *
59  * @name: region name
60  * @base: region base address
61  * @size: region size
62  *
63  * @return 0 on success, otherwise error
64  */
65 int sysmem_reserve(const char *name, phys_addr_t base, phys_size_t size);
66 
67 /**
68  * sysmem_alloc() - Alloc sysmem region at anywhere
69  *
70  * @name: region name
71  * @size: region size
72  *
73  * @return NULL on error, otherwise the allocated region address ptr
74  */
75 void *sysmem_alloc(const char *name, phys_size_t size);
76 
77 /**
78  * sysmem_alloc_align() - Alloc sysmem region at anywhere with addr align down
79  *
80  * @name: region name
81  * @size: region size
82  * @align: region base address align (down)
83  *
84  * @return NULL on error, otherwise the allocated region address ptr
85  */
86 void *sysmem_alloc_align(const char *name, phys_size_t size, ulong align);
87 
88 /**
89  * sysmem_alloc_base() - Alloc sysmem region at the expect addr
90  *
91  * @name: region name
92  * @base: region base
93  * @size: region size
94  *
95  * @return NULL on error, otherwise the allocated region address ptr
96  */
97 void *sysmem_alloc_base(const char *name, phys_addr_t base, phys_size_t size);
98 
99 /**
100  * sysmem_alloc_align_base() - Alloc sysmem region at the expect addr with align down
101  *
102  * @name: region name
103  * @base: region base
104  * @size: region size
105  * @align: region base address align (down)
106  *
107  * @return NULL on error, otherwise the allocated region address ptr
108  */
109 void *sysmem_alloc_align_base(const char *name, phys_addr_t base,
110 			      phys_size_t size, ulong align);
111 
112 /**
113  * sysmem_free() - Free sysmem region
114  *
115  * @base: region base
116  *
117  * @return 0 on success, otherwise error
118  */
119 int sysmem_free(phys_addr_t base);
120 
121 /**
122  * sysmem_check() - Check sysmem regions
123  *
124  * @return 0 on okay, otherwise something wrong
125  */
126 int sysmem_check(void);
127 
128 /**
129  * sysmem_dump_all() - Dump all sysmem stat
130  */
131 void sysmem_dump(void);
132 
133 /**
134  * sysmem_dump_check() - Dump all sysmem stat and check overflow
135  */
136 int sysmem_dump_check(void);
137 
138 /**
139  * board_sysmem_reserve() - Weak function for board to implement
140  *
141  * @sysmem: global sysmem point, ignored
142  *
143  * @return 0 on success, otherwise error
144  */
145 int board_sysmem_reserve(struct sysmem *sysmem);
146 
147 /**
148  * arch_sysmem_reserve() - Weak function for arch to implement
149  *
150  * @sysmem: global sysmem point, ignored
151  *
152  * @return 0 on success, otherwise error
153  */
154 int arch_sysmem_reserve(struct sysmem *sysmem);
155 
156 #endif /* _SYSMEM_H */
157