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