bootmem.h 11 KB

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