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