Commit | Line | Data |
---|---|---|
95f72d1e YL |
1 | #ifndef _LINUX_MEMBLOCK_H |
2 | #define _LINUX_MEMBLOCK_H | |
3 | #ifdef __KERNEL__ | |
4 | ||
5 | /* | |
6 | * Logical memory blocks. | |
7 | * | |
8 | * Copyright (C) 2001 Peter Bergner, IBM Corp. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public License | |
12 | * as published by the Free Software Foundation; either version | |
13 | * 2 of the License, or (at your option) any later version. | |
14 | */ | |
15 | ||
16 | #include <linux/init.h> | |
17 | #include <linux/mm.h> | |
57c8a661 MR |
18 | #include <asm/dma.h> |
19 | ||
20 | extern unsigned long max_low_pfn; | |
21 | extern unsigned long min_low_pfn; | |
22 | ||
23 | /* | |
24 | * highest page | |
25 | */ | |
26 | extern unsigned long max_pfn; | |
27 | /* | |
28 | * highest possible page | |
29 | */ | |
30 | extern unsigned long long max_possible_pfn; | |
95f72d1e | 31 | |
9a0de1bf MR |
32 | /** |
33 | * enum memblock_flags - definition of memory region attributes | |
34 | * @MEMBLOCK_NONE: no special request | |
35 | * @MEMBLOCK_HOTPLUG: hotpluggable region | |
36 | * @MEMBLOCK_MIRROR: mirrored region | |
37 | * @MEMBLOCK_NOMAP: don't add to kernel direct mapping | |
38 | */ | |
e1720fee | 39 | enum memblock_flags { |
fc6daaf9 TL |
40 | MEMBLOCK_NONE = 0x0, /* No special request */ |
41 | MEMBLOCK_HOTPLUG = 0x1, /* hotpluggable region */ | |
a3f5bafc | 42 | MEMBLOCK_MIRROR = 0x2, /* mirrored region */ |
bf3d3cc5 | 43 | MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ |
fc6daaf9 | 44 | }; |
66b16edf | 45 | |
9a0de1bf MR |
46 | /** |
47 | * struct memblock_region - represents a memory region | |
48 | * @base: physical address of the region | |
49 | * @size: size of the region | |
50 | * @flags: memory region attributes | |
51 | * @nid: NUMA node id | |
52 | */ | |
e3239ff9 | 53 | struct memblock_region { |
2898cc4c BH |
54 | phys_addr_t base; |
55 | phys_addr_t size; | |
e1720fee | 56 | enum memblock_flags flags; |
7c0caeb8 TH |
57 | #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP |
58 | int nid; | |
59 | #endif | |
95f72d1e YL |
60 | }; |
61 | ||
9a0de1bf MR |
62 | /** |
63 | * struct memblock_type - collection of memory regions of certain type | |
64 | * @cnt: number of regions | |
65 | * @max: size of the allocated array | |
66 | * @total_size: size of all regions | |
67 | * @regions: array of regions | |
68 | * @name: the memory type symbolic name | |
69 | */ | |
e3239ff9 | 70 | struct memblock_type { |
9a0de1bf MR |
71 | unsigned long cnt; |
72 | unsigned long max; | |
73 | phys_addr_t total_size; | |
bf23c51f | 74 | struct memblock_region *regions; |
0262d9c8 | 75 | char *name; |
95f72d1e YL |
76 | }; |
77 | ||
9a0de1bf MR |
78 | /** |
79 | * struct memblock - memblock allocator metadata | |
80 | * @bottom_up: is bottom up direction? | |
81 | * @current_limit: physical address of the current allocation limit | |
82 | * @memory: usabe memory regions | |
83 | * @reserved: reserved memory regions | |
84 | * @physmem: all physical memory | |
85 | */ | |
95f72d1e | 86 | struct memblock { |
79442ed1 | 87 | bool bottom_up; /* is bottom up direction? */ |
2898cc4c | 88 | phys_addr_t current_limit; |
e3239ff9 BH |
89 | struct memblock_type memory; |
90 | struct memblock_type reserved; | |
70210ed9 PH |
91 | #ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP |
92 | struct memblock_type physmem; | |
93 | #endif | |
95f72d1e YL |
94 | }; |
95 | ||
96 | extern struct memblock memblock; | |
5e63cf43 | 97 | extern int memblock_debug; |
5e63cf43 | 98 | |
036fbb21 KS |
99 | #ifdef CONFIG_ARCH_DISCARD_MEMBLOCK |
100 | #define __init_memblock __meminit | |
101 | #define __initdata_memblock __meminitdata | |
3010f876 | 102 | void memblock_discard(void); |
036fbb21 KS |
103 | #else |
104 | #define __init_memblock | |
105 | #define __initdata_memblock | |
106 | #endif | |
107 | ||
5e63cf43 YL |
108 | #define memblock_dbg(fmt, ...) \ |
109 | if (memblock_debug) printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) | |
95f72d1e | 110 | |
fc769a8e TH |
111 | phys_addr_t memblock_find_in_range(phys_addr_t start, phys_addr_t end, |
112 | phys_addr_t size, phys_addr_t align); | |
1aadc056 | 113 | void memblock_allow_resize(void); |
7fb0bc3f | 114 | int memblock_add_node(phys_addr_t base, phys_addr_t size, int nid); |
581adcbe TH |
115 | int memblock_add(phys_addr_t base, phys_addr_t size); |
116 | int memblock_remove(phys_addr_t base, phys_addr_t size); | |
117 | int memblock_free(phys_addr_t base, phys_addr_t size); | |
118 | int memblock_reserve(phys_addr_t base, phys_addr_t size); | |
6ede1fd3 | 119 | void memblock_trim_memory(phys_addr_t align); |
95cf82ec TC |
120 | bool memblock_overlaps_region(struct memblock_type *type, |
121 | phys_addr_t base, phys_addr_t size); | |
66b16edf TC |
122 | int memblock_mark_hotplug(phys_addr_t base, phys_addr_t size); |
123 | int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); | |
a3f5bafc | 124 | int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); |
bf3d3cc5 | 125 | int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); |
4c546b8a | 126 | int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); |
f1af9d3a | 127 | |
57c8a661 MR |
128 | unsigned long memblock_free_all(void); |
129 | void reset_node_managed_pages(pg_data_t *pgdat); | |
130 | void reset_all_zones_managed_pages(void); | |
131 | ||
f1af9d3a PH |
132 | /* Low level functions */ |
133 | int memblock_add_range(struct memblock_type *type, | |
134 | phys_addr_t base, phys_addr_t size, | |
e1720fee | 135 | int nid, enum memblock_flags flags); |
f1af9d3a | 136 | |
e1720fee | 137 | void __next_mem_range(u64 *idx, int nid, enum memblock_flags flags, |
fc6daaf9 | 138 | struct memblock_type *type_a, |
f1af9d3a PH |
139 | struct memblock_type *type_b, phys_addr_t *out_start, |
140 | phys_addr_t *out_end, int *out_nid); | |
141 | ||
e1720fee | 142 | void __next_mem_range_rev(u64 *idx, int nid, enum memblock_flags flags, |
fc6daaf9 | 143 | struct memblock_type *type_a, |
f1af9d3a PH |
144 | struct memblock_type *type_b, phys_addr_t *out_start, |
145 | phys_addr_t *out_end, int *out_nid); | |
146 | ||
8e7a7f86 | 147 | void __next_reserved_mem_region(u64 *idx, phys_addr_t *out_start, |
ba6c19fd | 148 | phys_addr_t *out_end); |
8e7a7f86 | 149 | |
3010f876 PT |
150 | void __memblock_free_late(phys_addr_t base, phys_addr_t size); |
151 | ||
f1af9d3a PH |
152 | /** |
153 | * for_each_mem_range - iterate through memblock areas from type_a and not | |
154 | * included in type_b. Or just type_a if type_b is NULL. | |
155 | * @i: u64 used as loop variable | |
156 | * @type_a: ptr to memblock_type to iterate | |
157 | * @type_b: ptr to memblock_type which excludes from the iteration | |
158 | * @nid: node selector, %NUMA_NO_NODE for all nodes | |
fc6daaf9 | 159 | * @flags: pick from blocks based on memory attributes |
f1af9d3a PH |
160 | * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL |
161 | * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL | |
162 | * @p_nid: ptr to int for nid of the range, can be %NULL | |
163 | */ | |
fc6daaf9 | 164 | #define for_each_mem_range(i, type_a, type_b, nid, flags, \ |
f1af9d3a | 165 | p_start, p_end, p_nid) \ |
fc6daaf9 | 166 | for (i = 0, __next_mem_range(&i, nid, flags, type_a, type_b, \ |
f1af9d3a PH |
167 | p_start, p_end, p_nid); \ |
168 | i != (u64)ULLONG_MAX; \ | |
fc6daaf9 | 169 | __next_mem_range(&i, nid, flags, type_a, type_b, \ |
f1af9d3a PH |
170 | p_start, p_end, p_nid)) |
171 | ||
172 | /** | |
173 | * for_each_mem_range_rev - reverse iterate through memblock areas from | |
174 | * type_a and not included in type_b. Or just type_a if type_b is NULL. | |
175 | * @i: u64 used as loop variable | |
176 | * @type_a: ptr to memblock_type to iterate | |
177 | * @type_b: ptr to memblock_type which excludes from the iteration | |
178 | * @nid: node selector, %NUMA_NO_NODE for all nodes | |
fc6daaf9 | 179 | * @flags: pick from blocks based on memory attributes |
f1af9d3a PH |
180 | * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL |
181 | * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL | |
182 | * @p_nid: ptr to int for nid of the range, can be %NULL | |
183 | */ | |
fc6daaf9 | 184 | #define for_each_mem_range_rev(i, type_a, type_b, nid, flags, \ |
f1af9d3a PH |
185 | p_start, p_end, p_nid) \ |
186 | for (i = (u64)ULLONG_MAX, \ | |
fc6daaf9 | 187 | __next_mem_range_rev(&i, nid, flags, type_a, type_b,\ |
ba6c19fd | 188 | p_start, p_end, p_nid); \ |
f1af9d3a | 189 | i != (u64)ULLONG_MAX; \ |
fc6daaf9 | 190 | __next_mem_range_rev(&i, nid, flags, type_a, type_b, \ |
f1af9d3a PH |
191 | p_start, p_end, p_nid)) |
192 | ||
8e7a7f86 RH |
193 | /** |
194 | * for_each_reserved_mem_region - iterate over all reserved memblock areas | |
195 | * @i: u64 used as loop variable | |
196 | * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL | |
197 | * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL | |
198 | * | |
199 | * Walks over reserved areas of memblock. Available as soon as memblock | |
200 | * is initialized. | |
201 | */ | |
202 | #define for_each_reserved_mem_region(i, p_start, p_end) \ | |
ba6c19fd | 203 | for (i = 0UL, __next_reserved_mem_region(&i, p_start, p_end); \ |
8e7a7f86 RH |
204 | i != (u64)ULLONG_MAX; \ |
205 | __next_reserved_mem_region(&i, p_start, p_end)) | |
206 | ||
55ac590c TC |
207 | static inline bool memblock_is_hotpluggable(struct memblock_region *m) |
208 | { | |
209 | return m->flags & MEMBLOCK_HOTPLUG; | |
210 | } | |
211 | ||
a3f5bafc TL |
212 | static inline bool memblock_is_mirror(struct memblock_region *m) |
213 | { | |
214 | return m->flags & MEMBLOCK_MIRROR; | |
215 | } | |
216 | ||
bf3d3cc5 AB |
217 | static inline bool memblock_is_nomap(struct memblock_region *m) |
218 | { | |
219 | return m->flags & MEMBLOCK_NOMAP; | |
220 | } | |
221 | ||
0ee332c1 | 222 | #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP |
e76b63f8 YL |
223 | int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, |
224 | unsigned long *end_pfn); | |
0ee332c1 TH |
225 | void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, |
226 | unsigned long *out_end_pfn, int *out_nid); | |
227 | ||
228 | /** | |
229 | * for_each_mem_pfn_range - early memory pfn range iterator | |
230 | * @i: an integer used as loop variable | |
231 | * @nid: node selector, %MAX_NUMNODES for all nodes | |
232 | * @p_start: ptr to ulong for start pfn of the range, can be %NULL | |
233 | * @p_end: ptr to ulong for end pfn of the range, can be %NULL | |
234 | * @p_nid: ptr to int for nid of the range, can be %NULL | |
235 | * | |
f2d52fe5 | 236 | * Walks over configured memory ranges. |
0ee332c1 TH |
237 | */ |
238 | #define for_each_mem_pfn_range(i, nid, p_start, p_end, p_nid) \ | |
239 | for (i = -1, __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid); \ | |
240 | i >= 0; __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid)) | |
241 | #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */ | |
242 | ||
837566e7 AD |
243 | #ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT |
244 | void __next_mem_pfn_range_in_zone(u64 *idx, struct zone *zone, | |
245 | unsigned long *out_spfn, | |
246 | unsigned long *out_epfn); | |
247 | /** | |
248 | * for_each_free_mem_range_in_zone - iterate through zone specific free | |
249 | * memblock areas | |
250 | * @i: u64 used as loop variable | |
251 | * @zone: zone in which all of the memory blocks reside | |
252 | * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL | |
253 | * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL | |
254 | * | |
255 | * Walks over free (memory && !reserved) areas of memblock in a specific | |
256 | * zone. Available once memblock and an empty zone is initialized. The main | |
257 | * assumption is that the zone start, end, and pgdat have been associated. | |
258 | * This way we can use the zone to determine NUMA node, and if a given part | |
259 | * of the memblock is valid for the zone. | |
260 | */ | |
261 | #define for_each_free_mem_pfn_range_in_zone(i, zone, p_start, p_end) \ | |
262 | for (i = 0, \ | |
263 | __next_mem_pfn_range_in_zone(&i, zone, p_start, p_end); \ | |
264 | i != U64_MAX; \ | |
265 | __next_mem_pfn_range_in_zone(&i, zone, p_start, p_end)) | |
0e56acae AD |
266 | |
267 | /** | |
268 | * for_each_free_mem_range_in_zone_from - iterate through zone specific | |
269 | * free memblock areas from a given point | |
270 | * @i: u64 used as loop variable | |
271 | * @zone: zone in which all of the memory blocks reside | |
272 | * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL | |
273 | * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL | |
274 | * | |
275 | * Walks over free (memory && !reserved) areas of memblock in a specific | |
276 | * zone, continuing from current position. Available as soon as memblock is | |
277 | * initialized. | |
278 | */ | |
279 | #define for_each_free_mem_pfn_range_in_zone_from(i, zone, p_start, p_end) \ | |
280 | for (; i != U64_MAX; \ | |
281 | __next_mem_pfn_range_in_zone(&i, zone, p_start, p_end)) | |
837566e7 AD |
282 | #endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */ |
283 | ||
35fd0808 TH |
284 | /** |
285 | * for_each_free_mem_range - iterate through free memblock areas | |
286 | * @i: u64 used as loop variable | |
b1154233 | 287 | * @nid: node selector, %NUMA_NO_NODE for all nodes |
d30b5545 | 288 | * @flags: pick from blocks based on memory attributes |
35fd0808 TH |
289 | * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL |
290 | * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL | |
291 | * @p_nid: ptr to int for nid of the range, can be %NULL | |
292 | * | |
293 | * Walks over free (memory && !reserved) areas of memblock. Available as | |
294 | * soon as memblock is initialized. | |
295 | */ | |
fc6daaf9 | 296 | #define for_each_free_mem_range(i, nid, flags, p_start, p_end, p_nid) \ |
f1af9d3a | 297 | for_each_mem_range(i, &memblock.memory, &memblock.reserved, \ |
fc6daaf9 | 298 | nid, flags, p_start, p_end, p_nid) |
7bd0b0f0 TH |
299 | |
300 | /** | |
301 | * for_each_free_mem_range_reverse - rev-iterate through free memblock areas | |
302 | * @i: u64 used as loop variable | |
b1154233 | 303 | * @nid: node selector, %NUMA_NO_NODE for all nodes |
d30b5545 | 304 | * @flags: pick from blocks based on memory attributes |
7bd0b0f0 TH |
305 | * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL |
306 | * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL | |
307 | * @p_nid: ptr to int for nid of the range, can be %NULL | |
308 | * | |
309 | * Walks over free (memory && !reserved) areas of memblock in reverse | |
310 | * order. Available as soon as memblock is initialized. | |
311 | */ | |
fc6daaf9 TL |
312 | #define for_each_free_mem_range_reverse(i, nid, flags, p_start, p_end, \ |
313 | p_nid) \ | |
f1af9d3a | 314 | for_each_mem_range_rev(i, &memblock.memory, &memblock.reserved, \ |
fc6daaf9 | 315 | nid, flags, p_start, p_end, p_nid) |
7bd0b0f0 | 316 | |
7c0caeb8 | 317 | #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP |
e7e8de59 TC |
318 | int memblock_set_node(phys_addr_t base, phys_addr_t size, |
319 | struct memblock_type *type, int nid); | |
7c0caeb8 TH |
320 | |
321 | static inline void memblock_set_region_node(struct memblock_region *r, int nid) | |
322 | { | |
323 | r->nid = nid; | |
324 | } | |
325 | ||
326 | static inline int memblock_get_region_node(const struct memblock_region *r) | |
327 | { | |
328 | return r->nid; | |
329 | } | |
330 | #else | |
331 | static inline void memblock_set_region_node(struct memblock_region *r, int nid) | |
332 | { | |
333 | } | |
334 | ||
335 | static inline int memblock_get_region_node(const struct memblock_region *r) | |
336 | { | |
337 | return 0; | |
338 | } | |
339 | #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */ | |
340 | ||
57c8a661 MR |
341 | /* Flags for memblock allocation APIs */ |
342 | #define MEMBLOCK_ALLOC_ANYWHERE (~(phys_addr_t)0) | |
343 | #define MEMBLOCK_ALLOC_ACCESSIBLE 0 | |
fed84c78 | 344 | #define MEMBLOCK_ALLOC_KASAN 1 |
57c8a661 MR |
345 | |
346 | /* We are using top down, so it is safe to use 0 here */ | |
347 | #define MEMBLOCK_LOW_LIMIT 0 | |
348 | ||
349 | #ifndef ARCH_LOW_ADDRESS_LIMIT | |
350 | #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL | |
351 | #endif | |
352 | ||
8a770c2a MR |
353 | phys_addr_t memblock_phys_alloc_range(phys_addr_t size, phys_addr_t align, |
354 | phys_addr_t start, phys_addr_t end); | |
9a8dd708 | 355 | phys_addr_t memblock_phys_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid); |
9d1e2492 | 356 | |
ecc3e771 MR |
357 | static inline phys_addr_t memblock_phys_alloc(phys_addr_t size, |
358 | phys_addr_t align) | |
359 | { | |
360 | return memblock_phys_alloc_range(size, align, 0, | |
361 | MEMBLOCK_ALLOC_ACCESSIBLE); | |
362 | } | |
e63075a3 | 363 | |
57c8a661 MR |
364 | void *memblock_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align, |
365 | phys_addr_t min_addr, phys_addr_t max_addr, | |
366 | int nid); | |
57c8a661 MR |
367 | void *memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, |
368 | phys_addr_t min_addr, phys_addr_t max_addr, | |
369 | int nid); | |
370 | ||
371 | static inline void * __init memblock_alloc(phys_addr_t size, phys_addr_t align) | |
372 | { | |
373 | return memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, | |
374 | MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE); | |
375 | } | |
376 | ||
377 | static inline void * __init memblock_alloc_raw(phys_addr_t size, | |
378 | phys_addr_t align) | |
379 | { | |
380 | return memblock_alloc_try_nid_raw(size, align, MEMBLOCK_LOW_LIMIT, | |
381 | MEMBLOCK_ALLOC_ACCESSIBLE, | |
382 | NUMA_NO_NODE); | |
383 | } | |
384 | ||
385 | static inline void * __init memblock_alloc_from(phys_addr_t size, | |
386 | phys_addr_t align, | |
387 | phys_addr_t min_addr) | |
388 | { | |
389 | return memblock_alloc_try_nid(size, align, min_addr, | |
390 | MEMBLOCK_ALLOC_ACCESSIBLE, NUMA_NO_NODE); | |
391 | } | |
392 | ||
57c8a661 MR |
393 | static inline void * __init memblock_alloc_low(phys_addr_t size, |
394 | phys_addr_t align) | |
395 | { | |
396 | return memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, | |
397 | ARCH_LOW_ADDRESS_LIMIT, NUMA_NO_NODE); | |
398 | } | |
57c8a661 MR |
399 | |
400 | static inline void * __init memblock_alloc_node(phys_addr_t size, | |
401 | phys_addr_t align, int nid) | |
402 | { | |
403 | return memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, | |
404 | MEMBLOCK_ALLOC_ACCESSIBLE, nid); | |
405 | } | |
406 | ||
57c8a661 MR |
407 | static inline void __init memblock_free_early(phys_addr_t base, |
408 | phys_addr_t size) | |
409 | { | |
4d72868c | 410 | memblock_free(base, size); |
57c8a661 MR |
411 | } |
412 | ||
413 | static inline void __init memblock_free_early_nid(phys_addr_t base, | |
414 | phys_addr_t size, int nid) | |
415 | { | |
4d72868c | 416 | memblock_free(base, size); |
57c8a661 MR |
417 | } |
418 | ||
419 | static inline void __init memblock_free_late(phys_addr_t base, phys_addr_t size) | |
420 | { | |
421 | __memblock_free_late(base, size); | |
422 | } | |
423 | ||
79442ed1 TC |
424 | /* |
425 | * Set the allocation direction to bottom-up or top-down. | |
426 | */ | |
2cfb3665 | 427 | static inline void __init memblock_set_bottom_up(bool enable) |
79442ed1 TC |
428 | { |
429 | memblock.bottom_up = enable; | |
430 | } | |
431 | ||
432 | /* | |
433 | * Check if the allocation direction is bottom-up or not. | |
434 | * if this is true, that said, memblock will allocate memory | |
435 | * in bottom-up direction. | |
436 | */ | |
437 | static inline bool memblock_bottom_up(void) | |
438 | { | |
439 | return memblock.bottom_up; | |
440 | } | |
79442ed1 | 441 | |
581adcbe | 442 | phys_addr_t memblock_phys_mem_size(void); |
8907de5d | 443 | phys_addr_t memblock_reserved_size(void); |
595ad9af | 444 | phys_addr_t memblock_mem_size(unsigned long limit_pfn); |
581adcbe TH |
445 | phys_addr_t memblock_start_of_DRAM(void); |
446 | phys_addr_t memblock_end_of_DRAM(void); | |
447 | void memblock_enforce_memory_limit(phys_addr_t memory_limit); | |
c9ca9b4e | 448 | void memblock_cap_memory_range(phys_addr_t base, phys_addr_t size); |
a571d4eb | 449 | void memblock_mem_limit_remove_map(phys_addr_t limit); |
b4ad0c7e | 450 | bool memblock_is_memory(phys_addr_t addr); |
937f0c26 YB |
451 | bool memblock_is_map_memory(phys_addr_t addr); |
452 | bool memblock_is_region_memory(phys_addr_t base, phys_addr_t size); | |
b4ad0c7e | 453 | bool memblock_is_reserved(phys_addr_t addr); |
c5c5c9d1 | 454 | bool memblock_is_region_reserved(phys_addr_t base, phys_addr_t size); |
581adcbe | 455 | |
4ff7b82f TH |
456 | extern void __memblock_dump_all(void); |
457 | ||
458 | static inline void memblock_dump_all(void) | |
459 | { | |
460 | if (memblock_debug) | |
461 | __memblock_dump_all(); | |
462 | } | |
95f72d1e | 463 | |
e63075a3 BH |
464 | /** |
465 | * memblock_set_current_limit - Set the current allocation limit to allow | |
466 | * limiting allocations to what is currently | |
467 | * accessible during boot | |
468 | * @limit: New limit value (physical address) | |
469 | */ | |
581adcbe | 470 | void memblock_set_current_limit(phys_addr_t limit); |
e63075a3 | 471 | |
35a1f0bd | 472 | |
fec51014 LA |
473 | phys_addr_t memblock_get_current_limit(void); |
474 | ||
5b385f25 BH |
475 | /* |
476 | * pfn conversion functions | |
477 | * | |
478 | * While the memory MEMBLOCKs should always be page aligned, the reserved | |
479 | * MEMBLOCKs may not be. This accessor attempt to provide a very clear | |
480 | * idea of what they return for such non aligned MEMBLOCKs. | |
481 | */ | |
482 | ||
483 | /** | |
47cec443 | 484 | * memblock_region_memory_base_pfn - get the lowest pfn of the memory region |
5b385f25 | 485 | * @reg: memblock_region structure |
47cec443 MR |
486 | * |
487 | * Return: the lowest pfn intersecting with the memory region | |
5b385f25 | 488 | */ |
c7fc2de0 | 489 | static inline unsigned long memblock_region_memory_base_pfn(const struct memblock_region *reg) |
5b385f25 | 490 | { |
c7fc2de0 | 491 | return PFN_UP(reg->base); |
5b385f25 BH |
492 | } |
493 | ||
494 | /** | |
47cec443 | 495 | * memblock_region_memory_end_pfn - get the end pfn of the memory region |
5b385f25 | 496 | * @reg: memblock_region structure |
47cec443 MR |
497 | * |
498 | * Return: the end_pfn of the reserved region | |
5b385f25 | 499 | */ |
c7fc2de0 | 500 | static inline unsigned long memblock_region_memory_end_pfn(const struct memblock_region *reg) |
5b385f25 | 501 | { |
c7fc2de0 | 502 | return PFN_DOWN(reg->base + reg->size); |
5b385f25 BH |
503 | } |
504 | ||
505 | /** | |
47cec443 | 506 | * memblock_region_reserved_base_pfn - get the lowest pfn of the reserved region |
5b385f25 | 507 | * @reg: memblock_region structure |
47cec443 MR |
508 | * |
509 | * Return: the lowest pfn intersecting with the reserved region | |
5b385f25 | 510 | */ |
c7fc2de0 | 511 | static inline unsigned long memblock_region_reserved_base_pfn(const struct memblock_region *reg) |
5b385f25 | 512 | { |
c7fc2de0 | 513 | return PFN_DOWN(reg->base); |
5b385f25 BH |
514 | } |
515 | ||
516 | /** | |
47cec443 | 517 | * memblock_region_reserved_end_pfn - get the end pfn of the reserved region |
5b385f25 | 518 | * @reg: memblock_region structure |
47cec443 MR |
519 | * |
520 | * Return: the end_pfn of the reserved region | |
5b385f25 | 521 | */ |
c7fc2de0 | 522 | static inline unsigned long memblock_region_reserved_end_pfn(const struct memblock_region *reg) |
5b385f25 | 523 | { |
c7fc2de0 | 524 | return PFN_UP(reg->base + reg->size); |
5b385f25 BH |
525 | } |
526 | ||
527 | #define for_each_memblock(memblock_type, region) \ | |
ba6c19fd | 528 | for (region = memblock.memblock_type.regions; \ |
5b385f25 BH |
529 | region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \ |
530 | region++) | |
531 | ||
66e8b438 GK |
532 | #define for_each_memblock_type(i, memblock_type, rgn) \ |
533 | for (i = 0, rgn = &memblock_type->regions[0]; \ | |
534 | i < memblock_type->cnt; \ | |
535 | i++, rgn = &memblock_type->regions[i]) | |
5b385f25 | 536 | |
57c8a661 MR |
537 | extern void *alloc_large_system_hash(const char *tablename, |
538 | unsigned long bucketsize, | |
539 | unsigned long numentries, | |
540 | int scale, | |
541 | int flags, | |
542 | unsigned int *_hash_shift, | |
543 | unsigned int *_hash_mask, | |
544 | unsigned long low_limit, | |
545 | unsigned long high_limit); | |
546 | ||
547 | #define HASH_EARLY 0x00000001 /* Allocating during early boot? */ | |
548 | #define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min | |
549 | * shift passed via *_hash_shift */ | |
550 | #define HASH_ZERO 0x00000004 /* Zero allocated hash table */ | |
551 | ||
552 | /* Only NUMA needs hash distribution. 64bit NUMA architectures have | |
553 | * sufficient vmalloc space. | |
554 | */ | |
555 | #ifdef CONFIG_NUMA | |
556 | #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT) | |
557 | extern int hashdist; /* Distribute hashes across NUMA nodes? */ | |
558 | #else | |
559 | #define hashdist (0) | |
560 | #endif | |
561 | ||
4a20799d | 562 | #ifdef CONFIG_MEMTEST |
7f70baee | 563 | extern void early_memtest(phys_addr_t start, phys_addr_t end); |
4a20799d | 564 | #else |
7f70baee | 565 | static inline void early_memtest(phys_addr_t start, phys_addr_t end) |
4a20799d VM |
566 | { |
567 | } | |
568 | #endif | |
f0b37fad | 569 | |
95f72d1e YL |
570 | #endif /* __KERNEL__ */ |
571 | ||
572 | #endif /* _LINUX_MEMBLOCK_H */ |