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