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