xref: /rk3399_rockchip-uboot/include/sysmem.h (revision d0df954bf3d4978ee3feb94b80ec863063c704cc)
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 struct sysmem_property {
17 	const char *name;
18 	phys_addr_t base;
19 	phys_size_t size;
20 	struct list_head node;
21 };
22 
23 struct sysmem {
24 	struct lmb lmb;
25 	struct list_head allocated_head;
26 	struct list_head reserved_head;
27 	ulong allocated_cnt;
28 	bool has_init;
29 };
30 
31 /**
32  * sysmem_init() - Sysmem initialization
33  *
34  * @return 0 on success, otherwise error
35  */
36 int sysmem_init(void);
37 
38 /**
39  * sysmem_add() - Add sysmem region
40  *
41  * @base: region base address
42  * @size: region size
43  *
44  * @return 0 on success, otherwise error
45  */
46 int sysmem_add(phys_addr_t base, phys_size_t size);
47 
48 /**
49  * sysmem_reserve() - Reserve sysmem region
50  *
51  * @name: region name
52  * @base: region base address
53  * @size: region size
54  *
55  * @return 0 on success, otherwise error
56  */
57 int sysmem_reserve(const char *name, phys_addr_t base, phys_size_t size);
58 
59 /**
60  * sysmem_alloc() - Alloc sysmem region at anywhere
61  *
62  * @name: region name
63  * @size: region size
64  *
65  * @return NULL on error, otherwise the allocated region address ptr
66  */
67 void *sysmem_alloc(const char *name, phys_size_t size);
68 
69 /**
70  * sysmem_alloc_align() - Alloc sysmem region at anywhere with addr align down
71  *
72  * @name: region name
73  * @size: region size
74  * @align: region base address align (down)
75  *
76  * @return NULL on error, otherwise the allocated region address ptr
77  */
78 void *sysmem_alloc_align(const char *name, phys_size_t size, ulong align);
79 
80 /**
81  * sysmem_alloc_base() - Alloc sysmem region at the expect addr
82  *
83  * @name: region name
84  * @base: region base
85  * @size: region size
86  *
87  * @return NULL on error, otherwise the allocated region address ptr
88  */
89 void *sysmem_alloc_base(const char *name, phys_addr_t base, phys_size_t size);
90 
91 /**
92  * sysmem_alloc_align_base() - Alloc sysmem region at the expect addr with align down
93  *
94  * @name: region name
95  * @base: region base
96  * @size: region size
97  * @align: region base address align (down)
98  *
99  * @return NULL on error, otherwise the allocated region address ptr
100  */
101 void *sysmem_alloc_align_base(const char *name, phys_addr_t base,
102 			      phys_size_t size, ulong align);
103 
104 /**
105  * sysmem_free() - Free sysmem region
106  *
107  * @base: region base
108  *
109  * @return 0 on success, otherwise error
110  */
111 int sysmem_free(phys_addr_t base);
112 
113 /**
114  * sysmem_check() - Check sysmem regions
115  *
116  * @return 0 on okay, otherwise something wrong
117  */
118 int sysmem_check(void);
119 
120 /**
121  * sysmem_dump_all() - Dump all sysmem stat
122  */
123 void sysmem_dump(void);
124 
125 /**
126  * sysmem_dump_check() - Dump all sysmem stat and check overflow
127  */
128 int sysmem_dump_check(void);
129 
130 /**
131  * board_sysmem_reserve() - Weak function for board to implement
132  *
133  * @sysmem: global sysmem point, ignored
134  *
135  * @return 0 on success, otherwise error
136  */
137 int board_sysmem_reserve(struct sysmem *sysmem);
138 
139 /**
140  * arch_sysmem_reserve() - Weak function for arch to implement
141  *
142  * @sysmem: global sysmem point, ignored
143  *
144  * @return 0 on success, otherwise error
145  */
146 int arch_sysmem_reserve(struct sysmem *sysmem);
147 
148 #endif /* _SYSMEM_H */
149