Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/init.h> |
| 12 | #include <linux/bootmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/module.h> |
Franck Bui-Huu | e786e86 | 2006-09-25 23:31:06 -0700 | [diff] [blame^] | 14 | |
| 15 | #include <asm/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/io.h> |
Franck Bui-Huu | e786e86 | 2006-09-25 23:31:06 -0700 | [diff] [blame^] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "internal.h" |
| 19 | |
| 20 | /* |
| 21 | * Access to this subsystem has to be serialized externally. (this is |
| 22 | * true for the boot process anyway) |
| 23 | */ |
| 24 | unsigned long max_low_pfn; |
| 25 | unsigned long min_low_pfn; |
| 26 | unsigned long max_pfn; |
| 27 | |
Adrian Bunk | 6d46cc6 | 2006-07-10 04:44:21 -0700 | [diff] [blame] | 28 | EXPORT_UNUSED_SYMBOL(max_pfn); /* June 2006 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 30 | static LIST_HEAD(bdata_list); |
Vivek Goyal | 92aa63a | 2005-06-25 14:58:18 -0700 | [diff] [blame] | 31 | #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 | */ |
| 36 | unsigned long saved_max_pfn; |
| 37 | #endif |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /* return the number of _pages_ that will be allocated for the boot bitmap */ |
| 40 | unsigned long __init bootmem_bootmap_pages (unsigned long pages) |
| 41 | { |
| 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 | } |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 50 | /* |
| 51 | * link bdata in order |
| 52 | */ |
Franck Bui-Huu | 69d49e6 | 2006-09-25 23:31:04 -0700 | [diff] [blame] | 53 | static void __init link_bootmem(bootmem_data_t *bdata) |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 54 | { |
| 55 | bootmem_data_t *ent; |
| 56 | if (list_empty(&bdata_list)) { |
| 57 | list_add(&bdata->list, &bdata_list); |
| 58 | return; |
| 59 | } |
| 60 | /* insert in order */ |
| 61 | list_for_each_entry(ent, &bdata_list, list) { |
| 62 | if (bdata->node_boot_start < ent->node_boot_start) { |
| 63 | list_add_tail(&bdata->list, &ent->list); |
| 64 | return; |
| 65 | } |
| 66 | } |
| 67 | list_add_tail(&bdata->list, &bdata_list); |
| 68 | return; |
| 69 | } |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Called once to set up the allocator itself. |
| 74 | */ |
| 75 | static unsigned long __init init_bootmem_core (pg_data_t *pgdat, |
| 76 | unsigned long mapstart, unsigned long start, unsigned long end) |
| 77 | { |
| 78 | bootmem_data_t *bdata = pgdat->bdata; |
| 79 | unsigned long mapsize = ((end - start)+7)/8; |
| 80 | |
Nick Wilson | 8c0e33c | 2005-06-25 14:59:00 -0700 | [diff] [blame] | 81 | mapsize = ALIGN(mapsize, sizeof(long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | bdata->node_bootmem_map = phys_to_virt(mapstart << PAGE_SHIFT); |
| 83 | bdata->node_boot_start = (start << PAGE_SHIFT); |
| 84 | bdata->node_low_pfn = end; |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 85 | link_bootmem(bdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * Initially all pages are reserved - setup_arch() has to |
| 89 | * register free RAM areas explicitly. |
| 90 | */ |
| 91 | memset(bdata->node_bootmem_map, 0xff, mapsize); |
| 92 | |
| 93 | return mapsize; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Marks a particular physical memory range as unallocatable. Usable RAM |
| 98 | * might be used for boot-time allocations - or it might get added |
| 99 | * to the free page pool later on. |
| 100 | */ |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 101 | static void __init reserve_bootmem_core(bootmem_data_t *bdata, unsigned long addr, |
| 102 | unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
| 104 | unsigned long i; |
| 105 | /* |
| 106 | * round up, partially reserved pages are considered |
| 107 | * fully reserved. |
| 108 | */ |
| 109 | unsigned long sidx = (addr - bdata->node_boot_start)/PAGE_SIZE; |
| 110 | unsigned long eidx = (addr + size - bdata->node_boot_start + |
| 111 | PAGE_SIZE-1)/PAGE_SIZE; |
| 112 | unsigned long end = (addr + size + PAGE_SIZE-1)/PAGE_SIZE; |
| 113 | |
| 114 | BUG_ON(!size); |
| 115 | BUG_ON(sidx >= eidx); |
| 116 | BUG_ON((addr >> PAGE_SHIFT) >= bdata->node_low_pfn); |
| 117 | BUG_ON(end > bdata->node_low_pfn); |
| 118 | |
| 119 | for (i = sidx; i < eidx; i++) |
| 120 | if (test_and_set_bit(i, bdata->node_bootmem_map)) { |
| 121 | #ifdef CONFIG_DEBUG_BOOTMEM |
| 122 | printk("hm, page %08lx reserved twice.\n", i*PAGE_SIZE); |
| 123 | #endif |
| 124 | } |
| 125 | } |
| 126 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 127 | static void __init free_bootmem_core(bootmem_data_t *bdata, unsigned long addr, |
| 128 | unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | unsigned long i; |
| 131 | unsigned long start; |
| 132 | /* |
| 133 | * round down end of usable mem, partially free pages are |
| 134 | * considered reserved. |
| 135 | */ |
| 136 | unsigned long sidx; |
| 137 | unsigned long eidx = (addr + size - bdata->node_boot_start)/PAGE_SIZE; |
| 138 | unsigned long end = (addr + size)/PAGE_SIZE; |
| 139 | |
| 140 | BUG_ON(!size); |
| 141 | BUG_ON(end > bdata->node_low_pfn); |
| 142 | |
| 143 | if (addr < bdata->last_success) |
| 144 | bdata->last_success = addr; |
| 145 | |
| 146 | /* |
| 147 | * Round up the beginning of the address. |
| 148 | */ |
| 149 | start = (addr + PAGE_SIZE-1) / PAGE_SIZE; |
| 150 | sidx = start - (bdata->node_boot_start/PAGE_SIZE); |
| 151 | |
| 152 | for (i = sidx; i < eidx; i++) { |
| 153 | if (unlikely(!test_and_clear_bit(i, bdata->node_bootmem_map))) |
| 154 | BUG(); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | * We 'merge' subsequent allocations to save space. We might 'lose' |
| 160 | * some fraction of a page if allocations cannot be satisfied due to |
| 161 | * size constraints on boxes where there is physical RAM space |
| 162 | * fragmentation - in these cases (mostly large memory boxes) this |
| 163 | * is not a problem. |
| 164 | * |
| 165 | * On low memory boxes we get it right in 100% of the cases. |
| 166 | * |
| 167 | * alignment has to be a power of 2 value. |
| 168 | * |
| 169 | * NOTE: This function is _not_ reentrant. |
| 170 | */ |
Andi Kleen | 267b480 | 2006-03-25 16:31:10 +0100 | [diff] [blame] | 171 | void * __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | __alloc_bootmem_core(struct bootmem_data *bdata, unsigned long size, |
Yasunori Goto | 281dd25 | 2005-10-19 15:52:18 -0700 | [diff] [blame] | 173 | unsigned long align, unsigned long goal, unsigned long limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
| 175 | unsigned long offset, remaining_size, areasize, preferred; |
Yasunori Goto | 281dd25 | 2005-10-19 15:52:18 -0700 | [diff] [blame] | 176 | unsigned long i, start = 0, incr, eidx, end_pfn = bdata->node_low_pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | void *ret; |
| 178 | |
| 179 | if(!size) { |
| 180 | printk("__alloc_bootmem_core(): zero-sized request\n"); |
| 181 | BUG(); |
| 182 | } |
| 183 | BUG_ON(align & (align-1)); |
| 184 | |
Yasunori Goto | 281dd25 | 2005-10-19 15:52:18 -0700 | [diff] [blame] | 185 | if (limit && bdata->node_boot_start >= limit) |
| 186 | return NULL; |
| 187 | |
| 188 | limit >>=PAGE_SHIFT; |
| 189 | if (limit && end_pfn > limit) |
| 190 | end_pfn = limit; |
| 191 | |
| 192 | eidx = end_pfn - (bdata->node_boot_start >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | offset = 0; |
| 194 | if (align && |
| 195 | (bdata->node_boot_start & (align - 1UL)) != 0) |
| 196 | offset = (align - (bdata->node_boot_start & (align - 1UL))); |
| 197 | offset >>= PAGE_SHIFT; |
| 198 | |
| 199 | /* |
| 200 | * We try to allocate bootmem pages above 'goal' |
| 201 | * first, then we try to allocate lower pages. |
| 202 | */ |
| 203 | if (goal && (goal >= bdata->node_boot_start) && |
Yasunori Goto | 281dd25 | 2005-10-19 15:52:18 -0700 | [diff] [blame] | 204 | ((goal >> PAGE_SHIFT) < end_pfn)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | preferred = goal - bdata->node_boot_start; |
| 206 | |
| 207 | if (bdata->last_success >= preferred) |
Yasunori Goto | 281dd25 | 2005-10-19 15:52:18 -0700 | [diff] [blame] | 208 | if (!limit || (limit && limit > bdata->last_success)) |
| 209 | preferred = bdata->last_success; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } else |
| 211 | preferred = 0; |
| 212 | |
Nick Wilson | 8c0e33c | 2005-06-25 14:59:00 -0700 | [diff] [blame] | 213 | preferred = ALIGN(preferred, align) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | preferred += offset; |
| 215 | areasize = (size+PAGE_SIZE-1)/PAGE_SIZE; |
| 216 | incr = align >> PAGE_SHIFT ? : 1; |
| 217 | |
| 218 | restart_scan: |
| 219 | for (i = preferred; i < eidx; i += incr) { |
| 220 | unsigned long j; |
| 221 | i = find_next_zero_bit(bdata->node_bootmem_map, eidx, i); |
| 222 | i = ALIGN(i, incr); |
Haren Myneni | 66d43e9 | 2005-12-12 00:37:39 -0800 | [diff] [blame] | 223 | if (i >= eidx) |
| 224 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | if (test_bit(i, bdata->node_bootmem_map)) |
| 226 | continue; |
| 227 | for (j = i + 1; j < i + areasize; ++j) { |
| 228 | if (j >= eidx) |
| 229 | goto fail_block; |
| 230 | if (test_bit (j, bdata->node_bootmem_map)) |
| 231 | goto fail_block; |
| 232 | } |
| 233 | start = i; |
| 234 | goto found; |
| 235 | fail_block: |
| 236 | i = ALIGN(j, incr); |
| 237 | } |
| 238 | |
| 239 | if (preferred > offset) { |
| 240 | preferred = offset; |
| 241 | goto restart_scan; |
| 242 | } |
| 243 | return NULL; |
| 244 | |
| 245 | found: |
| 246 | bdata->last_success = start << PAGE_SHIFT; |
| 247 | BUG_ON(start >= eidx); |
| 248 | |
| 249 | /* |
| 250 | * Is the next page of the previous allocation-end the start |
| 251 | * of this allocation's buffer? If yes then we can 'merge' |
| 252 | * the previous partial page with this allocation. |
| 253 | */ |
| 254 | if (align < PAGE_SIZE && |
| 255 | bdata->last_offset && bdata->last_pos+1 == start) { |
Nick Wilson | 8c0e33c | 2005-06-25 14:59:00 -0700 | [diff] [blame] | 256 | offset = ALIGN(bdata->last_offset, align); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | BUG_ON(offset > PAGE_SIZE); |
| 258 | remaining_size = PAGE_SIZE-offset; |
| 259 | if (size < remaining_size) { |
| 260 | areasize = 0; |
| 261 | /* last_pos unchanged */ |
| 262 | bdata->last_offset = offset+size; |
| 263 | ret = phys_to_virt(bdata->last_pos*PAGE_SIZE + offset + |
| 264 | bdata->node_boot_start); |
| 265 | } else { |
| 266 | remaining_size = size - remaining_size; |
| 267 | areasize = (remaining_size+PAGE_SIZE-1)/PAGE_SIZE; |
| 268 | ret = phys_to_virt(bdata->last_pos*PAGE_SIZE + offset + |
| 269 | bdata->node_boot_start); |
| 270 | bdata->last_pos = start+areasize-1; |
| 271 | bdata->last_offset = remaining_size; |
| 272 | } |
| 273 | bdata->last_offset &= ~PAGE_MASK; |
| 274 | } else { |
| 275 | bdata->last_pos = start + areasize - 1; |
| 276 | bdata->last_offset = size & ~PAGE_MASK; |
| 277 | ret = phys_to_virt(start * PAGE_SIZE + bdata->node_boot_start); |
| 278 | } |
| 279 | |
| 280 | /* |
| 281 | * Reserve the area now: |
| 282 | */ |
| 283 | for (i = start; i < start+areasize; i++) |
| 284 | if (unlikely(test_and_set_bit(i, bdata->node_bootmem_map))) |
| 285 | BUG(); |
| 286 | memset(ret, 0, size); |
| 287 | return ret; |
| 288 | } |
| 289 | |
| 290 | static unsigned long __init free_all_bootmem_core(pg_data_t *pgdat) |
| 291 | { |
| 292 | struct page *page; |
Andy Whitcroft | d41dee3 | 2005-06-23 00:07:54 -0700 | [diff] [blame] | 293 | unsigned long pfn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | bootmem_data_t *bdata = pgdat->bdata; |
| 295 | unsigned long i, count, total = 0; |
| 296 | unsigned long idx; |
| 297 | unsigned long *map; |
| 298 | int gofast = 0; |
| 299 | |
| 300 | BUG_ON(!bdata->node_bootmem_map); |
| 301 | |
| 302 | count = 0; |
| 303 | /* first extant page of the node */ |
Andy Whitcroft | d41dee3 | 2005-06-23 00:07:54 -0700 | [diff] [blame] | 304 | pfn = bdata->node_boot_start >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | idx = bdata->node_low_pfn - (bdata->node_boot_start >> PAGE_SHIFT); |
| 306 | map = bdata->node_bootmem_map; |
| 307 | /* Check physaddr is O(LOG2(BITS_PER_LONG)) page aligned */ |
| 308 | if (bdata->node_boot_start == 0 || |
| 309 | ffs(bdata->node_boot_start) - PAGE_SHIFT > ffs(BITS_PER_LONG)) |
| 310 | gofast = 1; |
| 311 | for (i = 0; i < idx; ) { |
| 312 | unsigned long v = ~map[i / BITS_PER_LONG]; |
Andy Whitcroft | d41dee3 | 2005-06-23 00:07:54 -0700 | [diff] [blame] | 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (gofast && v == ~0UL) { |
David Howells | a226f6c | 2006-01-06 00:11:08 -0800 | [diff] [blame] | 315 | int order; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Andy Whitcroft | d41dee3 | 2005-06-23 00:07:54 -0700 | [diff] [blame] | 317 | page = pfn_to_page(pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | count += BITS_PER_LONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | order = ffs(BITS_PER_LONG) - 1; |
David Howells | a226f6c | 2006-01-06 00:11:08 -0800 | [diff] [blame] | 320 | __free_pages_bootmem(page, order); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | i += BITS_PER_LONG; |
| 322 | page += BITS_PER_LONG; |
| 323 | } else if (v) { |
| 324 | unsigned long m; |
Andy Whitcroft | d41dee3 | 2005-06-23 00:07:54 -0700 | [diff] [blame] | 325 | |
| 326 | page = pfn_to_page(pfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | for (m = 1; m && i < idx; m<<=1, page++, i++) { |
| 328 | if (v & m) { |
| 329 | count++; |
David Howells | a226f6c | 2006-01-06 00:11:08 -0800 | [diff] [blame] | 330 | __free_pages_bootmem(page, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | } else { |
| 334 | i+=BITS_PER_LONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
Andy Whitcroft | d41dee3 | 2005-06-23 00:07:54 -0700 | [diff] [blame] | 336 | pfn += BITS_PER_LONG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | total += count; |
| 339 | |
| 340 | /* |
| 341 | * Now free the allocator bitmap itself, it's not |
| 342 | * needed anymore: |
| 343 | */ |
| 344 | page = virt_to_page(bdata->node_bootmem_map); |
| 345 | count = 0; |
| 346 | for (i = 0; i < ((bdata->node_low_pfn-(bdata->node_boot_start >> PAGE_SHIFT))/8 + PAGE_SIZE-1)/PAGE_SIZE; i++,page++) { |
| 347 | count++; |
David Howells | a226f6c | 2006-01-06 00:11:08 -0800 | [diff] [blame] | 348 | __free_pages_bootmem(page, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | total += count; |
| 351 | bdata->node_bootmem_map = NULL; |
| 352 | |
| 353 | return total; |
| 354 | } |
| 355 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 356 | unsigned long __init init_bootmem_node (pg_data_t *pgdat, unsigned long freepfn, |
| 357 | unsigned long startpfn, unsigned long endpfn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
| 359 | return(init_bootmem_core(pgdat, freepfn, startpfn, endpfn)); |
| 360 | } |
| 361 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 362 | void __init reserve_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, |
| 363 | unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
| 365 | reserve_bootmem_core(pgdat->bdata, physaddr, size); |
| 366 | } |
| 367 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 368 | void __init free_bootmem_node (pg_data_t *pgdat, unsigned long physaddr, |
| 369 | unsigned long size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
| 371 | free_bootmem_core(pgdat->bdata, physaddr, size); |
| 372 | } |
| 373 | |
| 374 | unsigned long __init free_all_bootmem_node (pg_data_t *pgdat) |
| 375 | { |
| 376 | return(free_all_bootmem_core(pgdat)); |
| 377 | } |
| 378 | |
| 379 | unsigned long __init init_bootmem (unsigned long start, unsigned long pages) |
| 380 | { |
| 381 | max_low_pfn = pages; |
| 382 | min_low_pfn = start; |
| 383 | return(init_bootmem_core(NODE_DATA(0), start, 0, pages)); |
| 384 | } |
| 385 | |
| 386 | #ifndef CONFIG_HAVE_ARCH_BOOTMEM_NODE |
| 387 | void __init reserve_bootmem (unsigned long addr, unsigned long size) |
| 388 | { |
| 389 | reserve_bootmem_core(NODE_DATA(0)->bdata, addr, size); |
| 390 | } |
| 391 | #endif /* !CONFIG_HAVE_ARCH_BOOTMEM_NODE */ |
| 392 | |
| 393 | void __init free_bootmem (unsigned long addr, unsigned long size) |
| 394 | { |
| 395 | free_bootmem_core(NODE_DATA(0)->bdata, addr, size); |
| 396 | } |
| 397 | |
| 398 | unsigned long __init free_all_bootmem (void) |
| 399 | { |
| 400 | return(free_all_bootmem_core(NODE_DATA(0))); |
| 401 | } |
| 402 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 403 | void * __init __alloc_bootmem_nopanic(unsigned long size, unsigned long align, |
| 404 | unsigned long goal) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | { |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 406 | bootmem_data_t *bdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | void *ptr; |
| 408 | |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 409 | list_for_each_entry(bdata, &bdata_list, list) |
| 410 | if ((ptr = __alloc_bootmem_core(bdata, size, align, goal, 0))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | return(ptr); |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 412 | return NULL; |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 415 | void * __init __alloc_bootmem(unsigned long size, unsigned long align, |
| 416 | unsigned long goal) |
Andi Kleen | a806223 | 2006-04-07 19:49:21 +0200 | [diff] [blame] | 417 | { |
| 418 | void *mem = __alloc_bootmem_nopanic(size,align,goal); |
| 419 | if (mem) |
| 420 | return mem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* |
| 422 | * Whoops, we cannot satisfy the allocation request. |
| 423 | */ |
| 424 | printk(KERN_ALERT "bootmem alloc of %lu bytes failed!\n", size); |
| 425 | panic("Out of memory"); |
| 426 | return NULL; |
| 427 | } |
| 428 | |
Yasunori Goto | 281dd25 | 2005-10-19 15:52:18 -0700 | [diff] [blame] | 429 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 430 | void * __init __alloc_bootmem_node(pg_data_t *pgdat, unsigned long size, |
| 431 | unsigned long align, unsigned long goal) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
| 433 | void *ptr; |
| 434 | |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 435 | ptr = __alloc_bootmem_core(pgdat->bdata, size, align, goal, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | if (ptr) |
| 437 | return (ptr); |
| 438 | |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 439 | return __alloc_bootmem(size, align, goal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 442 | #define LOW32LIMIT 0xffffffff |
| 443 | |
Franck Bui-Huu | bb0923a | 2006-09-25 23:31:05 -0700 | [diff] [blame] | 444 | void * __init __alloc_bootmem_low(unsigned long size, unsigned long align, |
| 445 | unsigned long goal) |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 446 | { |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 447 | bootmem_data_t *bdata; |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 448 | void *ptr; |
| 449 | |
KAMEZAWA Hiroyuki | 679bc9f | 2006-03-27 01:15:58 -0800 | [diff] [blame] | 450 | list_for_each_entry(bdata, &bdata_list, list) |
| 451 | if ((ptr = __alloc_bootmem_core(bdata, size, |
Ravikiran G Thirumalai | 008857c | 2006-01-06 00:11:01 -0800 | [diff] [blame] | 452 | align, goal, LOW32LIMIT))) |
| 453 | return(ptr); |
| 454 | |
| 455 | /* |
| 456 | * Whoops, we cannot satisfy the allocation request. |
| 457 | */ |
| 458 | printk(KERN_ALERT "low bootmem alloc of %lu bytes failed!\n", size); |
| 459 | panic("Out of low memory"); |
| 460 | return NULL; |
| 461 | } |
| 462 | |
| 463 | void * __init __alloc_bootmem_low_node(pg_data_t *pgdat, unsigned long size, |
| 464 | unsigned long align, unsigned long goal) |
| 465 | { |
| 466 | return __alloc_bootmem_core(pgdat->bdata, size, align, goal, LOW32LIMIT); |
| 467 | } |