1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
5 #ifndef _LINUX_BOOTMEM_H
6 #define _LINUX_BOOTMEM_H
8 #include <linux/mmzone.h>
9 #include <linux/mm_types.h>
11 #include <asm/processor.h>
14 * simple boot-time physical memory area allocator.
17 extern unsigned long max_low_pfn;
18 extern unsigned long min_low_pfn;
23 extern unsigned long max_pfn;
25 * highest possible page
27 extern unsigned long long max_possible_pfn;
29 extern unsigned long free_all_bootmem(void);
30 extern void reset_node_managed_pages(pg_data_t *pgdat);
31 extern void reset_all_zones_managed_pages(void);
33 extern void free_bootmem_node(pg_data_t *pgdat,
36 extern void free_bootmem(unsigned long physaddr, unsigned long size);
37 extern void free_bootmem_late(unsigned long physaddr, unsigned long size);
39 extern void *__alloc_bootmem(unsigned long size,
42 extern void *__alloc_bootmem_nopanic(unsigned long size,
44 unsigned long goal) __malloc;
45 extern void *__alloc_bootmem_node(pg_data_t *pgdat,
48 unsigned long goal) __malloc;
49 void *__alloc_bootmem_node_high(pg_data_t *pgdat,
52 unsigned long goal) __malloc;
53 extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat,
56 unsigned long goal) __malloc;
57 void *___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
61 unsigned long limit) __malloc;
62 extern void *__alloc_bootmem_low(unsigned long size,
64 unsigned long goal) __malloc;
66 /* We are using top down, so it is safe to use 0 here */
67 #define BOOTMEM_LOW_LIMIT 0
69 #ifndef ARCH_LOW_ADDRESS_LIMIT
70 #define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
73 #define alloc_bootmem(x) \
74 __alloc_bootmem(x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
75 #define alloc_bootmem_align(x, align) \
76 __alloc_bootmem(x, align, BOOTMEM_LOW_LIMIT)
77 #define alloc_bootmem_pages(x) \
78 __alloc_bootmem(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
79 #define alloc_bootmem_pages_nopanic(x) \
80 __alloc_bootmem_nopanic(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
81 #define alloc_bootmem_node(pgdat, x) \
82 __alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
83 #define alloc_bootmem_node_nopanic(pgdat, x) \
84 __alloc_bootmem_node_nopanic(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
85 #define alloc_bootmem_pages_node(pgdat, x) \
86 __alloc_bootmem_node(pgdat, x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
88 #define alloc_bootmem_low(x) \
89 __alloc_bootmem_low(x, SMP_CACHE_BYTES, 0)
90 #define alloc_bootmem_low_pages(x) \
91 __alloc_bootmem_low(x, PAGE_SIZE, 0)
93 /* FIXME: use MEMBLOCK_ALLOC_* variants here */
94 #define BOOTMEM_ALLOC_ACCESSIBLE 0
95 #define BOOTMEM_ALLOC_ANYWHERE (~(phys_addr_t)0)
97 /* FIXME: Move to memblock.h at a point where we remove nobootmem.c */
98 void *memblock_virt_alloc_try_nid_raw(phys_addr_t size, phys_addr_t align,
100 phys_addr_t max_addr, int nid);
101 void *memblock_virt_alloc_try_nid_nopanic(phys_addr_t size,
102 phys_addr_t align, phys_addr_t min_addr,
103 phys_addr_t max_addr, int nid);
104 void *memblock_virt_alloc_try_nid(phys_addr_t size, phys_addr_t align,
105 phys_addr_t min_addr, phys_addr_t max_addr, int nid);
106 void __memblock_free_early(phys_addr_t base, phys_addr_t size);
107 void __memblock_free_late(phys_addr_t base, phys_addr_t size);
109 static inline void * __init memblock_virt_alloc(
110 phys_addr_t size, phys_addr_t align)
112 return memblock_virt_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
113 BOOTMEM_ALLOC_ACCESSIBLE,
117 static inline void * __init memblock_virt_alloc_raw(
118 phys_addr_t size, phys_addr_t align)
120 return memblock_virt_alloc_try_nid_raw(size, align, BOOTMEM_LOW_LIMIT,
121 BOOTMEM_ALLOC_ACCESSIBLE,
125 static inline void * __init memblock_virt_alloc_nopanic(
126 phys_addr_t size, phys_addr_t align)
128 return memblock_virt_alloc_try_nid_nopanic(size, align,
130 BOOTMEM_ALLOC_ACCESSIBLE,
134 static inline void * __init memblock_virt_alloc_low(
135 phys_addr_t size, phys_addr_t align)
137 return memblock_virt_alloc_try_nid(size, align,
139 ARCH_LOW_ADDRESS_LIMIT,
142 static inline void * __init memblock_virt_alloc_low_nopanic(
143 phys_addr_t size, phys_addr_t align)
145 return memblock_virt_alloc_try_nid_nopanic(size, align,
147 ARCH_LOW_ADDRESS_LIMIT,
151 static inline void * __init memblock_virt_alloc_from_nopanic(
152 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
154 return memblock_virt_alloc_try_nid_nopanic(size, align, min_addr,
155 BOOTMEM_ALLOC_ACCESSIBLE,
159 static inline void * __init memblock_virt_alloc_node(
160 phys_addr_t size, int nid)
162 return memblock_virt_alloc_try_nid(size, 0, BOOTMEM_LOW_LIMIT,
163 BOOTMEM_ALLOC_ACCESSIBLE, nid);
166 static inline void * __init memblock_virt_alloc_node_nopanic(
167 phys_addr_t size, int nid)
169 return memblock_virt_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT,
170 BOOTMEM_ALLOC_ACCESSIBLE,
174 static inline void __init memblock_free_early(
175 phys_addr_t base, phys_addr_t size)
177 __memblock_free_early(base, size);
180 static inline void __init memblock_free_early_nid(
181 phys_addr_t base, phys_addr_t size, int nid)
183 __memblock_free_early(base, size);
186 static inline void __init memblock_free_late(
187 phys_addr_t base, phys_addr_t size)
189 __memblock_free_late(base, size);
192 extern void *alloc_large_system_hash(const char *tablename,
193 unsigned long bucketsize,
194 unsigned long numentries,
197 unsigned int *_hash_shift,
198 unsigned int *_hash_mask,
199 unsigned long low_limit,
200 unsigned long high_limit);
202 #define HASH_EARLY 0x00000001 /* Allocating during early boot? */
203 #define HASH_SMALL 0x00000002 /* sub-page allocation allowed, min
204 * shift passed via *_hash_shift */
205 #define HASH_ZERO 0x00000004 /* Zero allocated hash table */
207 /* Only NUMA needs hash distribution. 64bit NUMA architectures have
208 * sufficient vmalloc space.
211 #define HASHDIST_DEFAULT IS_ENABLED(CONFIG_64BIT)
212 extern int hashdist; /* Distribute hashes across NUMA nodes? */
218 #endif /* _LINUX_BOOTMEM_H */