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