1
2
3
4#ifndef _LINUX_BOOTMEM_H
5#define _LINUX_BOOTMEM_H
6
7#include <linux/mmzone.h>
8#include <linux/mm_types.h>
9#include <asm/dma.h>
10
11
12
13
14
15extern unsigned long max_low_pfn;
16extern unsigned long min_low_pfn;
17
18
19
20
21extern unsigned long max_pfn;
22
23
24
25extern unsigned long long max_possible_pfn;
26
27#ifndef CONFIG_NO_BOOTMEM
28
29
30
31
32typedef struct bootmem_data {
33 unsigned long node_min_pfn;
34 unsigned long node_low_pfn;
35 void *node_bootmem_map;
36 unsigned long last_end_off;
37 unsigned long hint_idx;
38 struct list_head list;
39} bootmem_data_t;
40
41extern bootmem_data_t bootmem_node_data[];
42#endif
43
44extern unsigned long bootmem_bootmap_pages(unsigned long);
45
46extern unsigned long init_bootmem_node(pg_data_t *pgdat,
47 unsigned long freepfn,
48 unsigned long startpfn,
49 unsigned long endpfn);
50extern unsigned long init_bootmem(unsigned long addr, unsigned long memend);
51
52extern unsigned long free_all_bootmem_node(pg_data_t *pgdat);
53extern unsigned long free_all_bootmem(void);
54extern void reset_node_managed_pages(pg_data_t *pgdat);
55extern void reset_all_zones_managed_pages(void);
56
57extern void free_bootmem_node(pg_data_t *pgdat,
58 unsigned long addr,
59 unsigned long size);
60extern void free_bootmem(unsigned long physaddr, unsigned long size);
61extern void free_bootmem_late(unsigned long physaddr, unsigned long size);
62
63
64
65
66
67
68
69
70
71#define BOOTMEM_DEFAULT 0
72#define BOOTMEM_EXCLUSIVE (1<<0)
73
74extern int reserve_bootmem(unsigned long addr,
75 unsigned long size,
76 int flags);
77extern int reserve_bootmem_node(pg_data_t *pgdat,
78 unsigned long physaddr,
79 unsigned long size,
80 int flags);
81
82extern void *__alloc_bootmem(unsigned long size,
83 unsigned long align,
84 unsigned long goal);
85extern void *__alloc_bootmem_nopanic(unsigned long size,
86 unsigned long align,
87 unsigned long goal);
88extern void *__alloc_bootmem_node(pg_data_t *pgdat,
89 unsigned long size,
90 unsigned long align,
91 unsigned long goal);
92void *__alloc_bootmem_node_high(pg_data_t *pgdat,
93 unsigned long size,
94 unsigned long align,
95 unsigned long goal);
96extern void *__alloc_bootmem_node_nopanic(pg_data_t *pgdat,
97 unsigned long size,
98 unsigned long align,
99 unsigned long goal);
100void *___alloc_bootmem_node_nopanic(pg_data_t *pgdat,
101 unsigned long size,
102 unsigned long align,
103 unsigned long goal,
104 unsigned long limit);
105extern void *__alloc_bootmem_low(unsigned long size,
106 unsigned long align,
107 unsigned long goal);
108void *__alloc_bootmem_low_nopanic(unsigned long size,
109 unsigned long align,
110 unsigned long goal);
111extern void *__alloc_bootmem_low_node(pg_data_t *pgdat,
112 unsigned long size,
113 unsigned long align,
114 unsigned long goal);
115
116#ifdef CONFIG_NO_BOOTMEM
117
118#define BOOTMEM_LOW_LIMIT 0
119#else
120#define BOOTMEM_LOW_LIMIT __pa(MAX_DMA_ADDRESS)
121#endif
122
123#define alloc_bootmem(x) \
124 __alloc_bootmem(x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
125#define alloc_bootmem_align(x, align) \
126 __alloc_bootmem(x, align, BOOTMEM_LOW_LIMIT)
127#define alloc_bootmem_nopanic(x) \
128 __alloc_bootmem_nopanic(x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
129#define alloc_bootmem_pages(x) \
130 __alloc_bootmem(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
131#define alloc_bootmem_pages_nopanic(x) \
132 __alloc_bootmem_nopanic(x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
133#define alloc_bootmem_node(pgdat, x) \
134 __alloc_bootmem_node(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
135#define alloc_bootmem_node_nopanic(pgdat, x) \
136 __alloc_bootmem_node_nopanic(pgdat, x, SMP_CACHE_BYTES, BOOTMEM_LOW_LIMIT)
137#define alloc_bootmem_pages_node(pgdat, x) \
138 __alloc_bootmem_node(pgdat, x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
139#define alloc_bootmem_pages_node_nopanic(pgdat, x) \
140 __alloc_bootmem_node_nopanic(pgdat, x, PAGE_SIZE, BOOTMEM_LOW_LIMIT)
141
142#define alloc_bootmem_low(x) \
143 __alloc_bootmem_low(x, SMP_CACHE_BYTES, 0)
144#define alloc_bootmem_low_pages_nopanic(x) \
145 __alloc_bootmem_low_nopanic(x, PAGE_SIZE, 0)
146#define alloc_bootmem_low_pages(x) \
147 __alloc_bootmem_low(x, PAGE_SIZE, 0)
148#define alloc_bootmem_low_pages_node(pgdat, x) \
149 __alloc_bootmem_low_node(pgdat, x, PAGE_SIZE, 0)
150
151
152#if defined(CONFIG_HAVE_MEMBLOCK) && defined(CONFIG_NO_BOOTMEM)
153
154
155#define BOOTMEM_ALLOC_ACCESSIBLE 0
156#define BOOTMEM_ALLOC_ANYWHERE (~(phys_addr_t)0)
157
158
159void *memblock_virt_alloc_try_nid_nopanic(phys_addr_t size,
160 phys_addr_t align, phys_addr_t min_addr,
161 phys_addr_t max_addr, int nid);
162void *memblock_virt_alloc_try_nid(phys_addr_t size, phys_addr_t align,
163 phys_addr_t min_addr, phys_addr_t max_addr, int nid);
164void __memblock_free_early(phys_addr_t base, phys_addr_t size);
165void __memblock_free_late(phys_addr_t base, phys_addr_t size);
166
167static inline void * __init memblock_virt_alloc(
168 phys_addr_t size, phys_addr_t align)
169{
170 return memblock_virt_alloc_try_nid(size, align, BOOTMEM_LOW_LIMIT,
171 BOOTMEM_ALLOC_ACCESSIBLE,
172 NUMA_NO_NODE);
173}
174
175static inline void * __init memblock_virt_alloc_nopanic(
176 phys_addr_t size, phys_addr_t align)
177{
178 return memblock_virt_alloc_try_nid_nopanic(size, align,
179 BOOTMEM_LOW_LIMIT,
180 BOOTMEM_ALLOC_ACCESSIBLE,
181 NUMA_NO_NODE);
182}
183
184static inline void * __init memblock_virt_alloc_from_nopanic(
185 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
186{
187 return memblock_virt_alloc_try_nid_nopanic(size, align, min_addr,
188 BOOTMEM_ALLOC_ACCESSIBLE,
189 NUMA_NO_NODE);
190}
191
192static inline void * __init memblock_virt_alloc_node(
193 phys_addr_t size, int nid)
194{
195 return memblock_virt_alloc_try_nid(size, 0, BOOTMEM_LOW_LIMIT,
196 BOOTMEM_ALLOC_ACCESSIBLE, nid);
197}
198
199static inline void * __init memblock_virt_alloc_node_nopanic(
200 phys_addr_t size, int nid)
201{
202 return memblock_virt_alloc_try_nid_nopanic(size, 0, BOOTMEM_LOW_LIMIT,
203 BOOTMEM_ALLOC_ACCESSIBLE,
204 nid);
205}
206
207static inline void __init memblock_free_early(
208 phys_addr_t base, phys_addr_t size)
209{
210 __memblock_free_early(base, size);
211}
212
213static inline void __init memblock_free_early_nid(
214 phys_addr_t base, phys_addr_t size, int nid)
215{
216 __memblock_free_early(base, size);
217}
218
219static inline void __init memblock_free_late(
220 phys_addr_t base, phys_addr_t size)
221{
222 __memblock_free_late(base, size);
223}
224
225#else
226
227#define BOOTMEM_ALLOC_ACCESSIBLE 0
228
229
230
231static inline void * __init memblock_virt_alloc(
232 phys_addr_t size, phys_addr_t align)
233{
234 if (!align)
235 align = SMP_CACHE_BYTES;
236 return __alloc_bootmem(size, align, BOOTMEM_LOW_LIMIT);
237}
238
239static inline void * __init memblock_virt_alloc_nopanic(
240 phys_addr_t size, phys_addr_t align)
241{
242 if (!align)
243 align = SMP_CACHE_BYTES;
244 return __alloc_bootmem_nopanic(size, align, BOOTMEM_LOW_LIMIT);
245}
246
247static inline void * __init memblock_virt_alloc_from_nopanic(
248 phys_addr_t size, phys_addr_t align, phys_addr_t min_addr)
249{
250 return __alloc_bootmem_nopanic(size, align, min_addr);
251}
252
253static inline void * __init memblock_virt_alloc_node(
254 phys_addr_t size, int nid)
255{
256 return __alloc_bootmem_node(NODE_DATA(nid), size, SMP_CACHE_BYTES,
257 BOOTMEM_LOW_LIMIT);
258}
259
260static inline void * __init memblock_virt_alloc_node_nopanic(
261 phys_addr_t size, int nid)
262{
263 return __alloc_bootmem_node_nopanic(NODE_DATA(nid), size,
264 SMP_CACHE_BYTES,
265 BOOTMEM_LOW_LIMIT);
266}
267
268static inline void * __init memblock_virt_alloc_try_nid(phys_addr_t size,
269 phys_addr_t align, phys_addr_t min_addr, phys_addr_t max_addr, int nid)
270{
271 return __alloc_bootmem_node_high(NODE_DATA(nid), size, align,
272 min_addr);
273}
274
275static inline void * __init memblock_virt_alloc_try_nid_nopanic(
276 phys_addr_t size, phys_addr_t align,
277 phys_addr_t min_addr, phys_addr_t max_addr, int nid)
278{
279 return ___alloc_bootmem_node_nopanic(NODE_DATA(nid), size, align,
280 min_addr, max_addr);
281}
282
283static inline void __init memblock_free_early(
284 phys_addr_t base, phys_addr_t size)
285{
286 free_bootmem(base, size);
287}
288
289static inline void __init memblock_free_early_nid(
290 phys_addr_t base, phys_addr_t size, int nid)
291{
292 free_bootmem_node(NODE_DATA(nid), base, size);
293}
294
295static inline void __init memblock_free_late(
296 phys_addr_t base, phys_addr_t size)
297{
298 free_bootmem_late(base, size);
299}
300#endif
301
302#ifdef CONFIG_HAVE_ARCH_ALLOC_REMAP
303extern void *alloc_remap(int nid, unsigned long size);
304#else
305static inline void *alloc_remap(int nid, unsigned long size)
306{
307 return NULL;
308}
309#endif
310
311extern void *alloc_large_system_hash(const char *tablename,
312 unsigned long bucketsize,
313 unsigned long numentries,
314 int scale,
315 int flags,
316 unsigned int *_hash_shift,
317 unsigned int *_hash_mask,
318 unsigned long low_limit,
319 unsigned long high_limit);
320
321#define HASH_EARLY 0x00000001
322#define HASH_SMALL 0x00000002
323
324
325
326
327
328#if defined(CONFIG_NUMA) && defined(CONFIG_64BIT)
329#define HASHDIST_DEFAULT 1
330#else
331#define HASHDIST_DEFAULT 0
332#endif
333extern int hashdist;
334
335
336#endif
337