bootmem.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
  3. */
  4. #ifndef _LINUX_BOOTMEM_H
  5. #define _LINUX_BOOTMEM_H
  6. #include <linux/mmzone.h>
  7. #include <linux/mm_types.h>
  8. #include <asm/dma.h>
  9. #include <asm/processor.h>
  10. /*
  11. * simple boot-time physical memory area allocator.
  12. */
  13. extern unsigned long max_low_pfn;
  14. extern unsigned long min_low_pfn;
  15. /*
  16. * highest page
  17. */
  18. extern unsigned long max_pfn;
  19. /*
  20. * highest possible page
  21. */
  22. extern unsigned long long max_possible_pfn;
  23. #ifndef CONFIG_NO_BOOTMEM
  24. /*
  25. * node_bootmem_map is a map pointer - the bits represent all physical
  26. * memory pages (including holes) on the node.
  27. */
  28. typedef struct bootmem_data {
  29. unsigned long node_min_pfn;
  30. unsigned long node_low_pfn;
  31. void *node_bootmem_map;
  32. unsigned long last_end_off;
  33. unsigned long hint_idx;
  34. struct list_head list;
  35. } bootmem_data_t;
  36. extern bootmem_data_t bootmem_node_data[];
  37. #endif
  38. extern unsigned long bootmem_bootmap_pages(unsigned long);
  39. extern unsigned long init_bootmem_node(pg_data_t *pgdat,
  40. unsigned long freepfn,
  41. unsigned long startpfn,
  42. unsigned long endpfn);
  43. extern unsigned long init_bootmem(unsigned long addr, unsigned long memend);
  44. extern unsigned long free_all_bootmem(void);
  45. extern void reset_node_managed_pages(pg_data_t *pgdat);
  46. extern void reset_all_zones_managed_pages(void);
  47. extern void free_bootmem_node(pg_data_t *pgdat,
  48. unsigned long addr,
  49. unsigned long size);
  50. extern void free_bootmem(unsigned long physaddr, unsigned long size);
  51. extern void free_bootmem_late(unsigned long physaddr, unsigned long size);
  52. /*
  53. * Flags for reserve_bootmem (also if CONFIG_HAVE_ARCH_BOOTMEM_NODE,
  54. * the architecture-specific code should honor this).
  55. *
  56. * If flags is BOOTMEM_DEFAULT, then the return value is always 0 (success).
  57. * If flags contains BOOTMEM_EXCLUSIVE, then -EBUSY is returned if the memory
  58. * already was reserved.
  59. */
  60. #define BOOTMEM_DEFAULT 0
  61. #define BOOTMEM_EXCLUSIVE (1<<0)
  62. extern int reserve_bootmem(unsigned long addr,
  63. unsigned long size,
  64. int flags);
  65. extern int reserve_bootmem_node(pg_data_t *pgdat,
  66. unsigned long physaddr,
  67. unsigned long size,
  68. int flags);
  69. extern void *__alloc_bootmem(unsigned long size,
  70. unsigned long align,
  71. unsigned long goal);
  72. extern void *__alloc_bootmem_nopanic(unsigned long size,
  73. unsigned long align,
  74. unsigned long goal) __malloc;
  75. extern void *__alloc_bootmem_node(pg_data_t *pgdat,
  76. unsigned long size,
  77. unsigned long align,
  78. unsigned long goal) __malloc;
  79. void *__alloc_bootmem_node_high(pg_data_t *pgdat,
  80. unsigned long size,
  81. unsigned long align,
  82. unsigned long goal) __malloc;
  83. extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat,
  84. unsigned long size,
  85. unsigned long align,
  86. unsigned long goal) __malloc;
  87. void *___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
  88. unsigned long size,
  89. unsigned long align,
  90. unsigned long goal,
  91. unsigned long limit) __malloc;
  92. extern void *__alloc_bootmem_low(unsigned long size,
  93. unsigned long align,
  94. unsigned long goal) __malloc;
  95. void *__alloc_bootmem_low_nopanic(unsigned long size,
  96. unsigned long align,
  97. unsigned long goal) __malloc;
  98. extern void *__alloc_bootmem_low_node(pg_data_t *pgdat,
  99. unsigned long size,
  100. unsigned long align,
  101. unsigned long goal) __malloc;
  102. #ifdef CONFIG_NO_BOOTMEM
  103. /* We are using top down, so it is safe to use 0 here */
  104. #define BOOTMEM_LOW_LIMIT 0
  105. #else
  106. #define BOOTMEM_LOW_LIMIT __pa(MAX_DMA_ADDRESS)
  107. #endif
  108. #ifndef ARCH_LOW_ADDRESS_LIMIT
  109. #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
  110. #endif
  111. #define alloc_bootmem(x) \
  112. __alloc_bootmem(x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
  113. #define alloc_bootmem_align(x, align) \
  114. __alloc_bootmem(x, align, BOOTMEM_LOW_LIMIT)
  115. #define alloc_bootmem_nopanic(x) \
  116. __alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
  117. #define alloc_bootmem_pages(x) \
  118. __alloc_bootmem(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
  119. #define alloc_bootmem_pages_nopanic(x) \
  120. __alloc_bootmem_nopanic(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
  121. #define alloc_bootmem_node(pgdat, x) \
  122. __alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
  123. #define alloc_bootmem_node_nopanic(pgdat, x) \
  124. __alloc_bootmem_node_nopanic(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
  125. #define alloc_bootmem_pages_node(pgdat, x) \
  126. __alloc_bootmem_node(pgdat, x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
  127. #define alloc_bootmem_pages_node_nopanic(pgdat, x) \
  128. __alloc_bootmem_node_nopanic(pgdat, x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
  129. #define alloc_bootmem_low(x) \
  130. __alloc_bootmem_low(x, SMP_CACHE_BYTES, 0)
  131. #define alloc_bootmem_low_pages_nopanic(x) \
  132. __alloc_bootmem_low_nopanic(x, PAGE_SIZE, 0)
  133. #define alloc_bootmem_low_pages(x) \
  134. __alloc_bootmem_low(x, PAGE_SIZE, 0)
  135. #define alloc_bootmem_low_pages_node(pgdat, x) \
  136. __alloc_bootmem_low_node(pgdat, x, PAGE_SIZE, 0)
  137. #if defined(CONFIG_HAVE_MEMBLOCK) && defined(CONFIG_NO_BOOTMEM)
  138. /* FIXME: use MEMBLOCK_ALLOC_* variants here */
  139. #define BOOTMEM_ALLOC_ACCESSIBLE 0
  140. #define BOOTMEM_ALLOC_ANYWHERE (~(phys_addr_t)0)
  141. /* FIXME: Move to memblock.h at a point where we remove nobootmem.c */
  142. void *memblock_virt_alloc_try_nid_nopanic(phys_addr_t size,
  143. phys_addr_t align, phys_addr_t min_addr,
  144. phys_addr_t max_addr, int nid);
  145. void *memblock_virt_alloc_try_nid(phys_addr_t size, phys_addr_t align,
  146. phys_addr_t min_addr, phys_addr_t max_addr, int nid);
  147. void __memblock_free_early(phys_addr_t base, phys_addr_t size);
  148. void __memblock_free_late(phys_addr_t base, phys_addr_t size);
  149. static inline void * __init memblock_virt_alloc(
  150. phys_addr_t size, phys_addr_t align)
  151. {
  152. return memblock_virt_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
  153. BOOTMEM_ALLOC_ACCESSIBLE,
  154. NUMA_NO_NODE);
  155. }
  156. static inline void * __init memblock_virt_alloc_nopanic(
  157. phys_addr_t size, phys_addr_t align)
  158. {
  159. return memblock_virt_alloc_try_nid_nopanic(size, align,
  160. BOOTMEM_LOW_LIMIT,
  161. BOOTMEM_ALLOC_ACCESSIBLE,
  162. NUMA_NO_NODE);
  163. }
  164. static inline void * __init memblock_virt_alloc_low(
  165. phys_addr_t size, phys_addr_t align)
  166. {
  167. return memblock_virt_alloc_try_nid(size, align,
  168. BOOTMEM_LOW_LIMIT,
  169. ARCH_LOW_ADDRESS_LIMIT,
  170. NUMA_NO_NODE);
  171. }
  172. static inline void * __init memblock_virt_alloc_low_nopanic(
  173. phys_addr_t size, phys_addr_t align)
  174. {
  175. return memblock_virt_alloc_try_nid_nopanic(size, align,
  176. BOOTMEM_LOW_LIMIT,
  177. ARCH_LOW_ADDRESS_LIMIT,
  178. NUMA_NO_NODE);
  179. }
  180. static inline void * __init memblock_virt_alloc_from_nopanic(
  181. phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
  182. {
  183. return memblock_virt_alloc_try_nid_nopanic(size, align, min_addr,
  184. BOOTMEM_ALLOC_ACCESSIBLE,
  185. NUMA_NO_NODE);
  186. }
  187. static inline void * __init memblock_virt_alloc_node(
  188. phys_addr_t size, int nid)
  189. {
  190. return memblock_virt_alloc_try_nid(size, 0, BOOTMEM_LOW_LIMIT,
  191. BOOTMEM_ALLOC_ACCESSIBLE, nid);
  192. }
  193. static inline void * __init memblock_virt_alloc_node_nopanic(
  194. phys_addr_t size, int nid)
  195. {
  196. return memblock_virt_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT,
  197. BOOTMEM_ALLOC_ACCESSIBLE,
  198. nid);
  199. }
  200. static inline void __init memblock_free_early(
  201. phys_addr_t base, phys_addr_t size)
  202. {
  203. __memblock_free_early(base, size);
  204. }
  205. static inline void __init memblock_free_early_nid(
  206. phys_addr_t base, phys_addr_t size, int nid)
  207. {
  208. __memblock_free_early(base, size);
  209. }
  210. static inline void __init memblock_free_late(
  211. phys_addr_t base, phys_addr_t size)
  212. {
  213. __memblock_free_late(base, size);
  214. }
  215. #else
  216. #define BOOTMEM_ALLOC_ACCESSIBLE 0
  217. /* Fall back to all the existing bootmem APIs */
  218. static inline void * __init memblock_virt_alloc(
  219. phys_addr_t size, phys_addr_t align)
  220. {
  221. if (!align)
  222. align = SMP_CACHE_BYTES;
  223. return __alloc_bootmem(size, align, BOOTMEM_LOW_LIMIT);
  224. }
  225. static inline void * __init memblock_virt_alloc_nopanic(
  226. phys_addr_t size, phys_addr_t align)
  227. {
  228. if (!align)
  229. align = SMP_CACHE_BYTES;
  230. return __alloc_bootmem_nopanic(size, align, BOOTMEM_LOW_LIMIT);
  231. }
  232. static inline void * __init memblock_virt_alloc_low(
  233. phys_addr_t size, phys_addr_t align)
  234. {
  235. if (!align)
  236. align = SMP_CACHE_BYTES;
  237. return __alloc_bootmem_low(size, align, 0);
  238. }
  239. static inline void * __init memblock_virt_alloc_low_nopanic(
  240. phys_addr_t size, phys_addr_t align)
  241. {
  242. if (!align)
  243. align = SMP_CACHE_BYTES;
  244. return __alloc_bootmem_low_nopanic(size, align, 0);
  245. }
  246. static inline void * __init memblock_virt_alloc_from_nopanic(
  247. phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
  248. {
  249. return __alloc_bootmem_nopanic(size, align, min_addr);
  250. }
  251. static inline void * __init memblock_virt_alloc_node(
  252. phys_addr_t size, int nid)
  253. {
  254. return __alloc_bootmem_node(NODE_DATA(nid), size, SMP_CACHE_BYTES,
  255. BOOTMEM_LOW_LIMIT);
  256. }
  257. static inline void * __init memblock_virt_alloc_node_nopanic(
  258. phys_addr_t size, int nid)
  259. {
  260. return __alloc_bootmem_node_nopanic(NODE_DATA(nid), size,
  261. SMP_CACHE_BYTES,
  262. BOOTMEM_LOW_LIMIT);
  263. }
  264. static inline void * __init memblock_virt_alloc_try_nid(phys_addr_t size,
  265. phys_addr_t align, phys_addr_t min_addr, phys_addr_t max_addr, int nid)
  266. {
  267. return __alloc_bootmem_node_high(NODE_DATA(nid), size, align,
  268. min_addr);
  269. }
  270. static inline void * __init memblock_virt_alloc_try_nid_nopanic(
  271. phys_addr_t size, phys_addr_t align,
  272. phys_addr_t min_addr, phys_addr_t max_addr, int nid)
  273. {
  274. return ___alloc_bootmem_node_nopanic(NODE_DATA(nid), size, align,
  275. min_addr, max_addr);
  276. }
  277. static inline void __init memblock_free_early(
  278. phys_addr_t base, phys_addr_t size)
  279. {
  280. free_bootmem(base, size);
  281. }
  282. static inline void __init memblock_free_early_nid(
  283. phys_addr_t base, phys_addr_t size, int nid)
  284. {
  285. free_bootmem_node(NODE_DATA(nid), base, size);
  286. }
  287. static inline void __init memblock_free_late(
  288. phys_addr_t base, phys_addr_t size)
  289. {
  290. free_bootmem_late(base, size);
  291. }
  292. #endif /* defined(CONFIG_HAVE_MEMBLOCK) && defined(CONFIG_NO_BOOTMEM) */
  293. #ifdef CONFIG_HAVE_ARCH_ALLOC_REMAP
  294. extern void *alloc_remap(int nid, unsigned long size);
  295. #else
  296. static inline void *alloc_remap(int nid, unsigned long size)
  297. {
  298. return NULL;
  299. }
  300. #endif /* CONFIG_HAVE_ARCH_ALLOC_REMAP */
  301. extern void *alloc_large_system_hash(const char *tablename,
  302. unsigned long bucketsize,
  303. unsigned long numentries,
  304. int scale,
  305. int flags,
  306. unsigned int *_hash_shift,
  307. unsigned int *_hash_mask,
  308. unsigned long low_limit,
  309. unsigned long high_limit);
  310. #define HASH_EARLY 0x00000001 /* Allocating during early boot? */
  311. #define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min
  312. * shift passed via *_hash_shift */
  313. /* Only NUMA needs hash distribution. 64bit NUMA architectures have
  314. * sufficient vmalloc space.
  315. */
  316. #ifdef CONFIG_NUMA
  317. #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT)
  318. extern int hashdist; /* Distribute hashes across NUMA nodes? */
  319. #else
  320. #define hashdist (0)
  321. #endif
  322. #endif /* _LINUX_BOOTMEM_H */