memblock.h 21 KB

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