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