blob: f6ff4337b4242e911ab4e4faadb160b76a445b50 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/mm/bootmem.c
3 *
4 * Copyright (C) 1999 Ingo Molnar
5 * Discontiguous memory support, Kanoj Sarcar, SGI, Nov 1999
6 *
7 * simple boot-time physical memory area allocator and
8 * free memory collector. It's used to deal with reserved
9 * system memory and memory holes as well.
10 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
Franck Bui-Huubbc7b922006-09-25 23:31:07 -070012#include <linux/pfn.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/bootmem.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
Franck Bui-Huue786e862006-09-25 23:31:06 -070015
16#include <asm/bug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/io.h>
Heiko Carstensdfd54cb2006-09-25 23:31:33 -070018#include <asm/processor.h>
Franck Bui-Huue786e862006-09-25 23:31:06 -070019
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "internal.h"
21
22/*
23 * Access to this subsystem has to be serialized externally. (this is
24 * true for the boot process anyway)
25 */
26unsigned long max_low_pfn;
27unsigned long min_low_pfn;
28unsigned long max_pfn;
29
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -080030static LIST_HEAD(bdata_list);
Vivek Goyal92aa63a2005-06-25 14:58:18 -070031#ifdef CONFIG_CRASH_DUMP
32/*
33 * If we have booted due to a crash, max_pfn will be a very low value. We need
34 * to know the amount of memory that the previous kernel used.
35 */
36unsigned long saved_max_pfn;
37#endif
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/* return the number of _pages_ that will be allocated for the boot bitmap */
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -070040unsigned long __init bootmem_bootmap_pages(unsigned long pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -070041{
42 unsigned long mapsize;
43
44 mapsize = (pages+7)/8;
45 mapsize = (mapsize + ~PAGE_MASK) & PAGE_MASK;
46 mapsize >>= PAGE_SHIFT;
47
48 return mapsize;
49}
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -070050
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -080051/*
52 * link bdata in order
53 */
Franck Bui-Huu69d49e62006-09-25 23:31:04 -070054static void __init link_bootmem(bootmem_data_t *bdata)
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -080055{
56 bootmem_data_t *ent;
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -070057
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -080058 if (list_empty(&bdata_list)) {
59 list_add(&bdata->list, &bdata_list);
60 return;
61 }
62 /* insert in order */
63 list_for_each_entry(ent, &bdata_list, list) {
64 if (bdata->node_boot_start < ent->node_boot_start) {
65 list_add_tail(&bdata->list, &ent->list);
66 return;
67 }
68 }
69 list_add_tail(&bdata->list, &bdata_list);
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -080070}
71
Franck Bui-Huubbc7b922006-09-25 23:31:07 -070072/*
73 * Given an initialised bdata, it returns the size of the boot bitmap
74 */
75static unsigned long __init get_mapsize(bootmem_data_t *bdata)
76{
77 unsigned long mapsize;
78 unsigned long start = PFN_DOWN(bdata->node_boot_start);
79 unsigned long end = bdata->node_low_pfn;
80
81 mapsize = ((end - start) + 7) / 8;
82 return ALIGN(mapsize, sizeof(long));
83}
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85/*
86 * Called once to set up the allocator itself.
87 */
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -070088static unsigned long __init init_bootmem_core(pg_data_t *pgdat,
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned long mapstart, unsigned long start, unsigned long end)
90{
91 bootmem_data_t *bdata = pgdat->bdata;
Franck Bui-Huubbc7b922006-09-25 23:31:07 -070092 unsigned long mapsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Franck Bui-Huubbc7b922006-09-25 23:31:07 -070094 bdata->node_bootmem_map = phys_to_virt(PFN_PHYS(mapstart));
95 bdata->node_boot_start = PFN_PHYS(start);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 bdata->node_low_pfn = end;
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -080097 link_bootmem(bdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 /*
100 * Initially all pages are reserved - setup_arch() has to
101 * register free RAM areas explicitly.
102 */
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700103 mapsize = get_mapsize(bdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 memset(bdata->node_bootmem_map, 0xff, mapsize);
105
106 return mapsize;
107}
108
109/*
110 * Marks a particular physical memory range as unallocatable. Usable RAM
111 * might be used for boot-time allocations - or it might get added
112 * to the free page pool later on.
113 */
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800114static int __init reserve_bootmem_core(bootmem_data_t *bdata,
115 unsigned long addr, unsigned long size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700117 unsigned long sidx, eidx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 unsigned long i;
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800119 int ret;
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 /*
122 * round up, partially reserved pages are considered
123 * fully reserved.
124 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 BUG_ON(!size);
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700126 BUG_ON(PFN_DOWN(addr) >= bdata->node_low_pfn);
127 BUG_ON(PFN_UP(addr + size) > bdata->node_low_pfn);
128
129 sidx = PFN_DOWN(addr - bdata->node_boot_start);
130 eidx = PFN_UP(addr + size - bdata->node_boot_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 for (i = sidx; i < eidx; i++)
133 if (test_and_set_bit(i, bdata->node_bootmem_map)) {
134#ifdef CONFIG_DEBUG_BOOTMEM
135 printk("hm, page %08lx reserved twice.\n", i*PAGE_SIZE);
136#endif
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800137 if (flags & BOOTMEM_EXCLUSIVE) {
138 ret = -EBUSY;
139 goto err;
140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 }
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800142
143 return 0;
144
145err:
146 /* unreserve memory we accidentally reserved */
147 for (i--; i >= sidx; i--)
148 clear_bit(i, bdata->node_bootmem_map);
149
150 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700153static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr,
154 unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700156 unsigned long sidx, eidx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 unsigned long i;
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 /*
160 * round down end of usable mem, partially free pages are
161 * considered reserved.
162 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 BUG_ON(!size);
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700164 BUG_ON(PFN_DOWN(addr + size) > bdata->node_low_pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166 if (addr < bdata->last_success)
167 bdata->last_success = addr;
168
169 /*
170 * Round up the beginning of the address.
171 */
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700172 sidx = PFN_UP(addr) - PFN_DOWN(bdata->node_boot_start);
173 eidx = PFN_DOWN(addr + size - bdata->node_boot_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 for (i = sidx; i < eidx; i++) {
176 if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map)))
177 BUG();
178 }
179}
180
181/*
182 * We 'merge' subsequent allocations to save space. We might 'lose'
183 * some fraction of a page if allocations cannot be satisfied due to
184 * size constraints on boxes where there is physical RAM space
185 * fragmentation - in these cases (mostly large memory boxes) this
186 * is not a problem.
187 *
188 * On low memory boxes we get it right in 100% of the cases.
189 *
190 * alignment has to be a power of 2 value.
191 *
192 * NOTE: This function is _not_ reentrant.
193 */
Andi Kleen267b4802006-03-25 16:31:10 +0100194void * __init
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195__alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size,
Yasunori Goto281dd252005-10-19 15:52:18 -0700196 unsigned long align, unsigned long goal, unsigned long limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
198 unsigned long offset, remaining_size, areasize, preferred;
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700199 unsigned long i, start = 0, incr, eidx, end_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 void *ret;
201
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700202 if (!size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 printk("__alloc_bootmem_core(): zero-sized request\n");
204 BUG();
205 }
206 BUG_ON(align & (align-1));
207
Yasunori Goto281dd252005-10-19 15:52:18 -0700208 if (limit && bdata->node_boot_start >= limit)
209 return NULL;
210
Christian Krafft7c309a62006-12-06 20:32:41 -0800211 /* on nodes without memory - bootmem_map is NULL */
212 if (!bdata->node_bootmem_map)
213 return NULL;
214
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700215 end_pfn = bdata->node_low_pfn;
216 limit = PFN_DOWN(limit);
Yasunori Goto281dd252005-10-19 15:52:18 -0700217 if (limit && end_pfn > limit)
218 end_pfn = limit;
219
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700220 eidx = end_pfn - PFN_DOWN(bdata->node_boot_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 offset = 0;
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700222 if (align && (bdata->node_boot_start & (align - 1UL)) != 0)
223 offset = align - (bdata->node_boot_start & (align - 1UL));
224 offset = PFN_DOWN(offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 /*
227 * We try to allocate bootmem pages above 'goal'
228 * first, then we try to allocate lower pages.
229 */
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700230 if (goal && goal >= bdata->node_boot_start && PFN_DOWN(goal) < end_pfn) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 preferred = goal - bdata->node_boot_start;
232
233 if (bdata->last_success >= preferred)
Yasunori Goto281dd252005-10-19 15:52:18 -0700234 if (!limit || (limit && limit > bdata->last_success))
235 preferred = bdata->last_success;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 } else
237 preferred = 0;
238
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700239 preferred = PFN_DOWN(ALIGN(preferred, align)) + offset;
240 areasize = (size + PAGE_SIZE-1) / PAGE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 incr = align >> PAGE_SHIFT ? : 1;
242
243restart_scan:
244 for (i = preferred; i < eidx; i += incr) {
245 unsigned long j;
246 i = find_next_zero_bit(bdata->node_bootmem_map, eidx, i);
247 i = ALIGN(i, incr);
Haren Myneni66d43e92005-12-12 00:37:39 -0800248 if (i >= eidx)
249 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 if (test_bit(i, bdata->node_bootmem_map))
251 continue;
252 for (j = i + 1; j < i + areasize; ++j) {
253 if (j >= eidx)
254 goto fail_block;
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700255 if (test_bit(j, bdata->node_bootmem_map))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 goto fail_block;
257 }
258 start = i;
259 goto found;
260 fail_block:
261 i = ALIGN(j, incr);
262 }
263
264 if (preferred > offset) {
265 preferred = offset;
266 goto restart_scan;
267 }
268 return NULL;
269
270found:
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700271 bdata->last_success = PFN_PHYS(start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 BUG_ON(start >= eidx);
273
274 /*
275 * Is the next page of the previous allocation-end the start
276 * of this allocation's buffer? If yes then we can 'merge'
277 * the previous partial page with this allocation.
278 */
279 if (align < PAGE_SIZE &&
280 bdata->last_offset && bdata->last_pos+1 == start) {
Nick Wilson8c0e33c2005-06-25 14:59:00 -0700281 offset = ALIGN(bdata->last_offset, align);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 BUG_ON(offset > PAGE_SIZE);
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700283 remaining_size = PAGE_SIZE - offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (size < remaining_size) {
285 areasize = 0;
286 /* last_pos unchanged */
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700287 bdata->last_offset = offset + size;
288 ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
289 offset +
290 bdata->node_boot_start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 } else {
292 remaining_size = size - remaining_size;
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700293 areasize = (remaining_size + PAGE_SIZE-1) / PAGE_SIZE;
294 ret = phys_to_virt(bdata->last_pos * PAGE_SIZE +
295 offset +
296 bdata->node_boot_start);
297 bdata->last_pos = start + areasize - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 bdata->last_offset = remaining_size;
299 }
300 bdata->last_offset &= ~PAGE_MASK;
301 } else {
302 bdata->last_pos = start + areasize - 1;
303 bdata->last_offset = size & ~PAGE_MASK;
304 ret = phys_to_virt(start * PAGE_SIZE + bdata->node_boot_start);
305 }
306
307 /*
308 * Reserve the area now:
309 */
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700310 for (i = start; i < start + areasize; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 if (unlikely(test_and_set_bit(i, bdata->node_bootmem_map)))
312 BUG();
313 memset(ret, 0, size);
314 return ret;
315}
316
317static unsigned long __init free_all_bootmem_core(pg_data_t *pgdat)
318{
319 struct page *page;
Andy Whitcroftd41dee32005-06-23 00:07:54 -0700320 unsigned long pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 bootmem_data_t *bdata = pgdat->bdata;
322 unsigned long i, count, total = 0;
323 unsigned long idx;
324 unsigned long *map;
325 int gofast = 0;
326
327 BUG_ON(!bdata->node_bootmem_map);
328
329 count = 0;
330 /* first extant page of the node */
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700331 pfn = PFN_DOWN(bdata->node_boot_start);
332 idx = bdata->node_low_pfn - pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 map = bdata->node_bootmem_map;
334 /* Check physaddr is O(LOG2(BITS_PER_LONG)) page aligned */
335 if (bdata->node_boot_start == 0 ||
336 ffs(bdata->node_boot_start) - PAGE_SHIFT > ffs(BITS_PER_LONG))
337 gofast = 1;
338 for (i = 0; i < idx; ) {
339 unsigned long v = ~map[i / BITS_PER_LONG];
Andy Whitcroftd41dee32005-06-23 00:07:54 -0700340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 if (gofast && v == ~0UL) {
David Howellsa226f6c2006-01-06 00:11:08 -0800342 int order;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Andy Whitcroftd41dee32005-06-23 00:07:54 -0700344 page = pfn_to_page(pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 count += BITS_PER_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 order = ffs(BITS_PER_LONG) - 1;
David Howellsa226f6c2006-01-06 00:11:08 -0800347 __free_pages_bootmem(page, order);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 i += BITS_PER_LONG;
349 page += BITS_PER_LONG;
350 } else if (v) {
351 unsigned long m;
Andy Whitcroftd41dee32005-06-23 00:07:54 -0700352
353 page = pfn_to_page(pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 for (m = 1; m && i < idx; m<<=1, page++, i++) {
355 if (v & m) {
356 count++;
David Howellsa226f6c2006-01-06 00:11:08 -0800357 __free_pages_bootmem(page, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 }
359 }
360 } else {
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700361 i += BITS_PER_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
Andy Whitcroftd41dee32005-06-23 00:07:54 -0700363 pfn += BITS_PER_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 }
365 total += count;
366
367 /*
368 * Now free the allocator bitmap itself, it's not
369 * needed anymore:
370 */
371 page = virt_to_page(bdata->node_bootmem_map);
372 count = 0;
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700373 idx = (get_mapsize(bdata) + PAGE_SIZE-1) >> PAGE_SHIFT;
374 for (i = 0; i < idx; i++, page++) {
David Howellsa226f6c2006-01-06 00:11:08 -0800375 __free_pages_bootmem(page, 0);
Franck Bui-Huubbc7b922006-09-25 23:31:07 -0700376 count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378 total += count;
379 bdata->node_bootmem_map = NULL;
380
381 return total;
382}
383
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700384unsigned long __init init_bootmem_node(pg_data_t *pgdat, unsigned long freepfn,
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700385 unsigned long startpfn, unsigned long endpfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700387 return init_bootmem_core(pgdat, freepfn, startpfn, endpfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388}
389
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700390void __init reserve_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800391 unsigned long size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800393 reserve_bootmem_core(pgdat->bdata, physaddr, size, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394}
395
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700396void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr,
397 unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
399 free_bootmem_core(pgdat->bdata, physaddr, size);
400}
401
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700402unsigned long __init free_all_bootmem_node(pg_data_t *pgdat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700404 return free_all_bootmem_core(pgdat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405}
406
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700407unsigned long __init init_bootmem(unsigned long start, unsigned long pages)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
409 max_low_pfn = pages;
410 min_low_pfn = start;
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700411 return init_bootmem_core(NODE_DATA(0), start, 0, pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
413
414#ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800415int __init reserve_bootmem(unsigned long addr, unsigned long size,
416 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417{
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800418 return reserve_bootmem_core(NODE_DATA(0)->bdata, addr, size, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420#endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */
421
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700422void __init free_bootmem(unsigned long addr, unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
424 free_bootmem_core(NODE_DATA(0)->bdata, addr, size);
425}
426
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700427unsigned long __init free_all_bootmem(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428{
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700429 return free_all_bootmem_core(NODE_DATA(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700432void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align,
433 unsigned long goal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434{
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -0800435 bootmem_data_t *bdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 void *ptr;
437
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700438 list_for_each_entry(bdata, &bdata_list, list) {
439 ptr = __alloc_bootmem_core(bdata, size, align, goal, 0);
440 if (ptr)
441 return ptr;
442 }
Andi Kleena8062232006-04-07 19:49:21 +0200443 return NULL;
444}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700446void * __init __alloc_bootmem(unsigned long size, unsigned long align,
447 unsigned long goal)
Andi Kleena8062232006-04-07 19:49:21 +0200448{
449 void *mem = __alloc_bootmem_nopanic(size,align,goal);
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700450
Andi Kleena8062232006-04-07 19:49:21 +0200451 if (mem)
452 return mem;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 /*
454 * Whoops, we cannot satisfy the allocation request.
455 */
456 printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size);
457 panic("Out of memory");
458 return NULL;
459}
460
Yasunori Goto281dd252005-10-19 15:52:18 -0700461
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700462void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size,
463 unsigned long align, unsigned long goal)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
465 void *ptr;
466
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800467 ptr = __alloc_bootmem_core(pgdat->bdata, size, align, goal, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 if (ptr)
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700469 return ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800471 return __alloc_bootmem(size, align, goal);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472}
473
Heiko Carstensdfd54cb2006-09-25 23:31:33 -0700474#ifndef ARCH_LOW_ADDRESS_LIMIT
475#define ARCH_LOW_ADDRESS_LIMIT 0xffffffffUL
476#endif
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800477
Franck Bui-Huubb0923a2006-09-25 23:31:05 -0700478void * __init __alloc_bootmem_low(unsigned long size, unsigned long align,
479 unsigned long goal)
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800480{
KAMEZAWA Hiroyuki679bc9f2006-03-27 01:15:58 -0800481 bootmem_data_t *bdata;
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800482 void *ptr;
483
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700484 list_for_each_entry(bdata, &bdata_list, list) {
Heiko Carstensdfd54cb2006-09-25 23:31:33 -0700485 ptr = __alloc_bootmem_core(bdata, size, align, goal,
486 ARCH_LOW_ADDRESS_LIMIT);
Franck Bui-Huuf71bf0c2006-09-25 23:31:08 -0700487 if (ptr)
488 return ptr;
489 }
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800490
491 /*
492 * Whoops, we cannot satisfy the allocation request.
493 */
494 printk(KERN_ALERT "low bootmem alloc of %lu bytes failed!\n", size);
495 panic("Out of low memory");
496 return NULL;
497}
498
499void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size,
500 unsigned long align, unsigned long goal)
501{
Heiko Carstensdfd54cb2006-09-25 23:31:33 -0700502 return __alloc_bootmem_core(pgdat->bdata, size, align, goal,
503 ARCH_LOW_ADDRESS_LIMIT);
Ravikiran G Thirumalai008857c2006-01-06 00:11:01 -0800504}