blob: 5bbb87f59aeef41a0d1ec887c344c0adfa0be0ac [file] [log] [blame]
Yinghai Lu95f72d12010-07-12 14:36:09 +10001/*
2 * Procedures for maintaining information about logical memory blocks.
3 *
4 * Peter Bergner, IBM Corp. June 2001.
5 * Copyright (C) 2001 Peter Bergner.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#include <linux/kernel.h>
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -070014#include <linux/slab.h>
Yinghai Lu95f72d12010-07-12 14:36:09 +100015#include <linux/init.h>
16#include <linux/bitops.h>
Benjamin Herrenschmidt449e8df2010-07-06 15:39:07 -070017#include <linux/poison.h>
Benjamin Herrenschmidtc196f762010-07-06 15:39:16 -070018#include <linux/pfn.h>
Benjamin Herrenschmidt6d03b882010-07-06 15:39:19 -070019#include <linux/debugfs.h>
20#include <linux/seq_file.h>
Yinghai Lu95f72d12010-07-12 14:36:09 +100021#include <linux/memblock.h>
22
Tejun Heofe091c22011-12-08 10:22:07 -080023static struct memblock_region memblock_memory_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
24static struct memblock_region memblock_reserved_init_regions[INIT_MEMBLOCK_REGIONS] __initdata_memblock;
25
26struct memblock memblock __initdata_memblock = {
27 .memory.regions = memblock_memory_init_regions,
28 .memory.cnt = 1, /* empty dummy entry */
29 .memory.max = INIT_MEMBLOCK_REGIONS,
30
31 .reserved.regions = memblock_reserved_init_regions,
32 .reserved.cnt = 1, /* empty dummy entry */
33 .reserved.max = INIT_MEMBLOCK_REGIONS,
34
35 .current_limit = MEMBLOCK_ALLOC_ANYWHERE,
36};
Yinghai Lu95f72d12010-07-12 14:36:09 +100037
Yinghai Lu10d06432010-07-28 15:43:02 +100038int memblock_debug __initdata_memblock;
39int memblock_can_resize __initdata_memblock;
Yinghai Lu95f72d12010-07-12 14:36:09 +100040
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -070041/* inline so we don't get a warning when pr_debug is compiled out */
42static inline const char *memblock_type_name(struct memblock_type *type)
43{
44 if (type == &memblock.memory)
45 return "memory";
46 else if (type == &memblock.reserved)
47 return "reserved";
48 else
49 return "unknown";
50}
51
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +100052/*
53 * Address comparison utilities
54 */
Yinghai Lu10d06432010-07-28 15:43:02 +100055static unsigned long __init_memblock memblock_addrs_overlap(phys_addr_t base1, phys_addr_t size1,
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +100056 phys_addr_t base2, phys_addr_t size2)
Yinghai Lu95f72d12010-07-12 14:36:09 +100057{
58 return ((base1 < (base2 + size2)) && (base2 < (base1 + size1)));
59}
60
H Hartley Sweeten2d7d3eb2011-10-31 17:09:15 -070061static long __init_memblock memblock_overlaps_region(struct memblock_type *type,
62 phys_addr_t base, phys_addr_t size)
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +100063{
64 unsigned long i;
65
66 for (i = 0; i < type->cnt; i++) {
67 phys_addr_t rgnbase = type->regions[i].base;
68 phys_addr_t rgnsize = type->regions[i].size;
69 if (memblock_addrs_overlap(base, size, rgnbase, rgnsize))
70 break;
71 }
72
73 return (i < type->cnt) ? i : -1;
74}
75
76/*
77 * Find, allocate, deallocate or reserve unreserved regions. All allocations
78 * are top-down.
79 */
80
Yinghai Lucd794812010-10-11 12:34:09 -070081static phys_addr_t __init_memblock memblock_find_region(phys_addr_t start, phys_addr_t end,
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +100082 phys_addr_t size, phys_addr_t align)
83{
84 phys_addr_t base, res_base;
85 long j;
86
Yinghai Luf1af98c2010-10-04 14:57:39 -070087 /* In case, huge size is requested */
88 if (end < size)
Tejun Heo1f5026a2011-07-12 09:58:09 +020089 return 0;
Yinghai Luf1af98c2010-10-04 14:57:39 -070090
Tejun Heo348968e2011-07-12 09:58:08 +020091 base = round_down(end - size, align);
Yinghai Luf1af98c2010-10-04 14:57:39 -070092
Benjamin Herrenschmidt25818f02010-07-28 15:25:10 +100093 /* Prevent allocations returning 0 as it's also used to
94 * indicate an allocation failure
95 */
96 if (start == 0)
97 start = PAGE_SIZE;
98
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +100099 while (start <= base) {
100 j = memblock_overlaps_region(&memblock.reserved, base, size);
101 if (j < 0)
102 return base;
103 res_base = memblock.reserved.regions[j].base;
104 if (res_base < size)
105 break;
Tejun Heo348968e2011-07-12 09:58:08 +0200106 base = round_down(res_base - size, align);
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000107 }
108
Tejun Heo1f5026a2011-07-12 09:58:09 +0200109 return 0;
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000110}
111
Tejun Heofc769a82011-07-12 09:58:10 +0200112/*
113 * Find a free area with specified alignment in a specific range.
114 */
115phys_addr_t __init_memblock memblock_find_in_range(phys_addr_t start, phys_addr_t end,
116 phys_addr_t size, phys_addr_t align)
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000117{
118 long i;
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000119
120 BUG_ON(0 == size);
121
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000122 /* Pump up max_addr */
Benjamin Herrenschmidtfef501d2010-07-12 15:00:34 +1000123 if (end == MEMBLOCK_ALLOC_ACCESSIBLE)
124 end = memblock.current_limit;
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000125
126 /* We do a top-down search, this tends to limit memory
127 * fragmentation by keeping early boot allocs near the
128 * top of memory
129 */
130 for (i = memblock.memory.cnt - 1; i >= 0; i--) {
131 phys_addr_t memblockbase = memblock.memory.regions[i].base;
132 phys_addr_t memblocksize = memblock.memory.regions[i].size;
Benjamin Herrenschmidtfef501d2010-07-12 15:00:34 +1000133 phys_addr_t bottom, top, found;
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000134
135 if (memblocksize < size)
136 continue;
Benjamin Herrenschmidtfef501d2010-07-12 15:00:34 +1000137 if ((memblockbase + memblocksize) <= start)
138 break;
139 bottom = max(memblockbase, start);
140 top = min(memblockbase + memblocksize, end);
141 if (bottom >= top)
142 continue;
143 found = memblock_find_region(bottom, top, size, align);
Tejun Heo1f5026a2011-07-12 09:58:09 +0200144 if (found)
Benjamin Herrenschmidtfef501d2010-07-12 15:00:34 +1000145 return found;
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000146 }
Tejun Heo1f5026a2011-07-12 09:58:09 +0200147 return 0;
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000148}
149
Yinghai Lu5303b682010-07-28 15:38:40 +1000150/*
Yinghai Lu7950c402010-08-25 13:39:14 -0700151 * Free memblock.reserved.regions
152 */
153int __init_memblock memblock_free_reserved_regions(void)
154{
155 if (memblock.reserved.regions == memblock_reserved_init_regions)
156 return 0;
157
158 return memblock_free(__pa(memblock.reserved.regions),
159 sizeof(struct memblock_region) * memblock.reserved.max);
160}
161
162/*
163 * Reserve memblock.reserved.regions
164 */
165int __init_memblock memblock_reserve_reserved_regions(void)
166{
167 if (memblock.reserved.regions == memblock_reserved_init_regions)
168 return 0;
169
170 return memblock_reserve(__pa(memblock.reserved.regions),
171 sizeof(struct memblock_region) * memblock.reserved.max);
172}
173
Yinghai Lu10d06432010-07-28 15:43:02 +1000174static void __init_memblock memblock_remove_region(struct memblock_type *type, unsigned long r)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000175{
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200176 memmove(&type->regions[r], &type->regions[r + 1],
177 (type->cnt - (r + 1)) * sizeof(type->regions[r]));
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000178 type->cnt--;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000179
Benjamin Herrenschmidt8f7a6602011-03-22 16:33:43 -0700180 /* Special case for empty arrays */
181 if (type->cnt == 0) {
182 type->cnt = 1;
183 type->regions[0].base = 0;
184 type->regions[0].size = 0;
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200185 memblock_set_region_node(&type->regions[0], MAX_NUMNODES);
Benjamin Herrenschmidt8f7a6602011-03-22 16:33:43 -0700186 }
Yinghai Lu95f72d12010-07-12 14:36:09 +1000187}
188
Yinghai Lu10d06432010-07-28 15:43:02 +1000189static int __init_memblock memblock_double_array(struct memblock_type *type)
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700190{
191 struct memblock_region *new_array, *old_array;
192 phys_addr_t old_size, new_size, addr;
193 int use_slab = slab_is_available();
194
195 /* We don't allow resizing until we know about the reserved regions
196 * of memory that aren't suitable for allocation
197 */
198 if (!memblock_can_resize)
199 return -1;
200
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700201 /* Calculate new doubled size */
202 old_size = type->max * sizeof(struct memblock_region);
203 new_size = old_size << 1;
204
205 /* Try to find some space for it.
206 *
207 * WARNING: We assume that either slab_is_available() and we use it or
208 * we use MEMBLOCK for allocations. That means that this is unsafe to use
209 * when bootmem is currently active (unless bootmem itself is implemented
210 * on top of MEMBLOCK which isn't the case yet)
211 *
212 * This should however not be an issue for now, as we currently only
213 * call into MEMBLOCK while it's still active, or much later when slab is
214 * active for memory hotplug operations
215 */
216 if (use_slab) {
217 new_array = kmalloc(new_size, GFP_KERNEL);
Tejun Heo1f5026a2011-07-12 09:58:09 +0200218 addr = new_array ? __pa(new_array) : 0;
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700219 } else
Tejun Heofc769a82011-07-12 09:58:10 +0200220 addr = memblock_find_in_range(0, MEMBLOCK_ALLOC_ACCESSIBLE, new_size, sizeof(phys_addr_t));
Tejun Heo1f5026a2011-07-12 09:58:09 +0200221 if (!addr) {
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700222 pr_err("memblock: Failed to double %s array from %ld to %ld entries !\n",
223 memblock_type_name(type), type->max, type->max * 2);
224 return -1;
225 }
226 new_array = __va(addr);
227
Yinghai Luea9e4372010-07-28 15:13:22 +1000228 memblock_dbg("memblock: %s array is doubled to %ld at [%#010llx-%#010llx]",
229 memblock_type_name(type), type->max * 2, (u64)addr, (u64)addr + new_size - 1);
230
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700231 /* Found space, we now need to move the array over before
232 * we add the reserved region since it may be our reserved
233 * array itself that is full.
234 */
235 memcpy(new_array, type->regions, old_size);
236 memset(new_array + type->max, 0, old_size);
237 old_array = type->regions;
238 type->regions = new_array;
239 type->max <<= 1;
240
241 /* If we use SLAB that's it, we are done */
242 if (use_slab)
243 return 0;
244
245 /* Add the new reserved region now. Should not fail ! */
Tejun Heo9c8c27e2011-12-08 10:22:06 -0800246 BUG_ON(memblock_reserve(addr, new_size));
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700247
248 /* If the array wasn't our static init one, then free it. We only do
249 * that before SLAB is available as later on, we don't know whether
250 * to use kfree or free_bootmem_pages(). Shouldn't be a big deal
251 * anyways
252 */
253 if (old_array != memblock_memory_init_regions &&
254 old_array != memblock_reserved_init_regions)
255 memblock_free(__pa(old_array), old_size);
256
257 return 0;
258}
259
Tejun Heo784656f92011-07-12 11:15:55 +0200260/**
261 * memblock_merge_regions - merge neighboring compatible regions
262 * @type: memblock type to scan
263 *
264 * Scan @type and merge neighboring compatible regions.
265 */
266static void __init_memblock memblock_merge_regions(struct memblock_type *type)
267{
268 int i = 0;
269
270 /* cnt never goes below 1 */
271 while (i < type->cnt - 1) {
272 struct memblock_region *this = &type->regions[i];
273 struct memblock_region *next = &type->regions[i + 1];
274
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200275 if (this->base + this->size != next->base ||
276 memblock_get_region_node(this) !=
277 memblock_get_region_node(next)) {
Tejun Heo784656f92011-07-12 11:15:55 +0200278 BUG_ON(this->base + this->size > next->base);
279 i++;
280 continue;
281 }
282
283 this->size += next->size;
284 memmove(next, next + 1, (type->cnt - (i + 1)) * sizeof(*next));
285 type->cnt--;
286 }
287}
288
289/**
290 * memblock_insert_region - insert new memblock region
291 * @type: memblock type to insert into
292 * @idx: index for the insertion point
293 * @base: base address of the new region
294 * @size: size of the new region
295 *
296 * Insert new memblock region [@base,@base+@size) into @type at @idx.
297 * @type must already have extra room to accomodate the new region.
298 */
299static void __init_memblock memblock_insert_region(struct memblock_type *type,
300 int idx, phys_addr_t base,
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200301 phys_addr_t size, int nid)
Tejun Heo784656f92011-07-12 11:15:55 +0200302{
303 struct memblock_region *rgn = &type->regions[idx];
304
305 BUG_ON(type->cnt >= type->max);
306 memmove(rgn + 1, rgn, (type->cnt - idx) * sizeof(*rgn));
307 rgn->base = base;
308 rgn->size = size;
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200309 memblock_set_region_node(rgn, nid);
Tejun Heo784656f92011-07-12 11:15:55 +0200310 type->cnt++;
311}
312
313/**
314 * memblock_add_region - add new memblock region
315 * @type: memblock type to add new region into
316 * @base: base address of the new region
317 * @size: size of the new region
318 *
319 * Add new memblock region [@base,@base+@size) into @type. The new region
320 * is allowed to overlap with existing ones - overlaps don't affect already
321 * existing regions. @type is guaranteed to be minimal (all neighbouring
322 * compatible regions are merged) after the addition.
323 *
324 * RETURNS:
325 * 0 on success, -errno on failure.
326 */
Tejun Heo581adcb2011-12-08 10:22:06 -0800327static int __init_memblock memblock_add_region(struct memblock_type *type,
328 phys_addr_t base, phys_addr_t size)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000329{
Tejun Heo784656f92011-07-12 11:15:55 +0200330 bool insert = false;
331 phys_addr_t obase = base, end = base + size;
332 int i, nr_new;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000333
Tejun Heo784656f92011-07-12 11:15:55 +0200334 /* special case for empty array */
335 if (type->regions[0].size == 0) {
336 WARN_ON(type->cnt != 1);
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000337 type->regions[0].base = base;
338 type->regions[0].size = size;
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200339 memblock_set_region_node(&type->regions[0], MAX_NUMNODES);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000340 return 0;
341 }
Tejun Heo784656f92011-07-12 11:15:55 +0200342repeat:
343 /*
344 * The following is executed twice. Once with %false @insert and
345 * then with %true. The first counts the number of regions needed
346 * to accomodate the new area. The second actually inserts them.
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700347 */
Tejun Heo784656f92011-07-12 11:15:55 +0200348 base = obase;
349 nr_new = 0;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000350
Tejun Heo784656f92011-07-12 11:15:55 +0200351 for (i = 0; i < type->cnt; i++) {
352 struct memblock_region *rgn = &type->regions[i];
353 phys_addr_t rbase = rgn->base;
354 phys_addr_t rend = rbase + rgn->size;
355
356 if (rbase >= end)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000357 break;
Tejun Heo784656f92011-07-12 11:15:55 +0200358 if (rend <= base)
359 continue;
360 /*
361 * @rgn overlaps. If it separates the lower part of new
362 * area, insert that portion.
363 */
364 if (rbase > base) {
365 nr_new++;
366 if (insert)
367 memblock_insert_region(type, i++, base,
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200368 rbase - base, MAX_NUMNODES);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000369 }
Tejun Heo784656f92011-07-12 11:15:55 +0200370 /* area below @rend is dealt with, forget about it */
371 base = min(rend, end);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000372 }
Yinghai Lu95f72d12010-07-12 14:36:09 +1000373
Tejun Heo784656f92011-07-12 11:15:55 +0200374 /* insert the remaining portion */
375 if (base < end) {
376 nr_new++;
377 if (insert)
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200378 memblock_insert_region(type, i, base, end - base,
379 MAX_NUMNODES);
Tejun Heo784656f92011-07-12 11:15:55 +0200380 }
381
382 /*
383 * If this was the first round, resize array and repeat for actual
384 * insertions; otherwise, merge and return.
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700385 */
Tejun Heo784656f92011-07-12 11:15:55 +0200386 if (!insert) {
387 while (type->cnt + nr_new > type->max)
388 if (memblock_double_array(type) < 0)
389 return -ENOMEM;
390 insert = true;
391 goto repeat;
392 } else {
393 memblock_merge_regions(type);
394 return 0;
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700395 }
Yinghai Lu95f72d12010-07-12 14:36:09 +1000396}
397
Tejun Heo581adcb2011-12-08 10:22:06 -0800398int __init_memblock memblock_add(phys_addr_t base, phys_addr_t size)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000399{
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000400 return memblock_add_region(&memblock.memory, base, size);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000401}
402
Tejun Heo581adcb2011-12-08 10:22:06 -0800403static int __init_memblock __memblock_remove(struct memblock_type *type,
404 phys_addr_t base, phys_addr_t size)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000405{
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +1000406 phys_addr_t end = base + size;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000407 int i;
408
Benjamin Herrenschmidt8f7a6602011-03-22 16:33:43 -0700409 /* Walk through the array for collisions */
410 for (i = 0; i < type->cnt; i++) {
411 struct memblock_region *rgn = &type->regions[i];
412 phys_addr_t rend = rgn->base + rgn->size;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000413
Benjamin Herrenschmidt8f7a6602011-03-22 16:33:43 -0700414 /* Nothing more to do, exit */
415 if (rgn->base > end || rgn->size == 0)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000416 break;
Benjamin Herrenschmidt8f7a6602011-03-22 16:33:43 -0700417
418 /* If we fully enclose the block, drop it */
419 if (base <= rgn->base && end >= rend) {
420 memblock_remove_region(type, i--);
421 continue;
422 }
423
424 /* If we are fully enclosed within a block
425 * then we need to split it and we are done
426 */
427 if (base > rgn->base && end < rend) {
428 rgn->size = base - rgn->base;
429 if (!memblock_add_region(type, end, rend - end))
430 return 0;
431 /* Failure to split is bad, we at least
432 * restore the block before erroring
433 */
434 rgn->size = rend - rgn->base;
435 WARN_ON(1);
436 return -1;
437 }
438
439 /* Check if we need to trim the bottom of a block */
440 if (rgn->base < end && rend > end) {
441 rgn->size -= end - rgn->base;
442 rgn->base = end;
443 break;
444 }
445
446 /* And check if we need to trim the top of a block */
447 if (base < rend)
448 rgn->size -= rend - base;
449
Yinghai Lu95f72d12010-07-12 14:36:09 +1000450 }
Benjamin Herrenschmidt8f7a6602011-03-22 16:33:43 -0700451 return 0;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000452}
453
Tejun Heo581adcb2011-12-08 10:22:06 -0800454int __init_memblock memblock_remove(phys_addr_t base, phys_addr_t size)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000455{
456 return __memblock_remove(&memblock.memory, base, size);
457}
458
Tejun Heo581adcb2011-12-08 10:22:06 -0800459int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000460{
Tejun Heo24aa0782011-07-12 11:16:06 +0200461 memblock_dbg(" memblock_free: [%#016llx-%#016llx] %pF\n",
H. Peter Anvina1504392011-07-14 11:57:10 -0700462 (unsigned long long)base,
463 (unsigned long long)base + size,
464 (void *)_RET_IP_);
Tejun Heo24aa0782011-07-12 11:16:06 +0200465
Yinghai Lu95f72d12010-07-12 14:36:09 +1000466 return __memblock_remove(&memblock.reserved, base, size);
467}
468
Tejun Heo581adcb2011-12-08 10:22:06 -0800469int __init_memblock memblock_reserve(phys_addr_t base, phys_addr_t size)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000470{
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000471 struct memblock_type *_rgn = &memblock.reserved;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000472
Tejun Heo24aa0782011-07-12 11:16:06 +0200473 memblock_dbg("memblock_reserve: [%#016llx-%#016llx] %pF\n",
H. Peter Anvina1504392011-07-14 11:57:10 -0700474 (unsigned long long)base,
475 (unsigned long long)base + size,
476 (void *)_RET_IP_);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000477 BUG_ON(0 == size);
478
479 return memblock_add_region(_rgn, base, size);
480}
481
Tejun Heo35fd0802011-07-12 11:15:59 +0200482/**
483 * __next_free_mem_range - next function for for_each_free_mem_range()
484 * @idx: pointer to u64 loop variable
485 * @nid: nid: node selector, %MAX_NUMNODES for all nodes
486 * @p_start: ptr to phys_addr_t for start address of the range, can be %NULL
487 * @p_end: ptr to phys_addr_t for end address of the range, can be %NULL
488 * @p_nid: ptr to int for nid of the range, can be %NULL
489 *
490 * Find the first free area from *@idx which matches @nid, fill the out
491 * parameters, and update *@idx for the next iteration. The lower 32bit of
492 * *@idx contains index into memory region and the upper 32bit indexes the
493 * areas before each reserved region. For example, if reserved regions
494 * look like the following,
495 *
496 * 0:[0-16), 1:[32-48), 2:[128-130)
497 *
498 * The upper 32bit indexes the following regions.
499 *
500 * 0:[0-0), 1:[16-32), 2:[48-128), 3:[130-MAX)
501 *
502 * As both region arrays are sorted, the function advances the two indices
503 * in lockstep and returns each intersection.
504 */
505void __init_memblock __next_free_mem_range(u64 *idx, int nid,
506 phys_addr_t *out_start,
507 phys_addr_t *out_end, int *out_nid)
508{
509 struct memblock_type *mem = &memblock.memory;
510 struct memblock_type *rsv = &memblock.reserved;
511 int mi = *idx & 0xffffffff;
512 int ri = *idx >> 32;
513
514 for ( ; mi < mem->cnt; mi++) {
515 struct memblock_region *m = &mem->regions[mi];
516 phys_addr_t m_start = m->base;
517 phys_addr_t m_end = m->base + m->size;
518
519 /* only memory regions are associated with nodes, check it */
520 if (nid != MAX_NUMNODES && nid != memblock_get_region_node(m))
521 continue;
522
523 /* scan areas before each reservation for intersection */
524 for ( ; ri < rsv->cnt + 1; ri++) {
525 struct memblock_region *r = &rsv->regions[ri];
526 phys_addr_t r_start = ri ? r[-1].base + r[-1].size : 0;
527 phys_addr_t r_end = ri < rsv->cnt ? r->base : ULLONG_MAX;
528
529 /* if ri advanced past mi, break out to advance mi */
530 if (r_start >= m_end)
531 break;
532 /* if the two regions intersect, we're done */
533 if (m_start < r_end) {
534 if (out_start)
535 *out_start = max(m_start, r_start);
536 if (out_end)
537 *out_end = min(m_end, r_end);
538 if (out_nid)
539 *out_nid = memblock_get_region_node(m);
540 /*
541 * The region which ends first is advanced
542 * for the next iteration.
543 */
544 if (m_end <= r_end)
545 mi++;
546 else
547 ri++;
548 *idx = (u32)mi | (u64)ri << 32;
549 return;
550 }
551 }
552 }
553
554 /* signal end of iteration */
555 *idx = ULLONG_MAX;
556}
557
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200558#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
559/*
560 * Common iterator interface used to define for_each_mem_range().
561 */
562void __init_memblock __next_mem_pfn_range(int *idx, int nid,
563 unsigned long *out_start_pfn,
564 unsigned long *out_end_pfn, int *out_nid)
565{
566 struct memblock_type *type = &memblock.memory;
567 struct memblock_region *r;
568
569 while (++*idx < type->cnt) {
570 r = &type->regions[*idx];
571
572 if (PFN_UP(r->base) >= PFN_DOWN(r->base + r->size))
573 continue;
574 if (nid == MAX_NUMNODES || nid == r->nid)
575 break;
576 }
577 if (*idx >= type->cnt) {
578 *idx = -1;
579 return;
580 }
581
582 if (out_start_pfn)
583 *out_start_pfn = PFN_UP(r->base);
584 if (out_end_pfn)
585 *out_end_pfn = PFN_DOWN(r->base + r->size);
586 if (out_nid)
587 *out_nid = r->nid;
588}
589
590/**
591 * memblock_set_node - set node ID on memblock regions
592 * @base: base of area to set node ID for
593 * @size: size of area to set node ID for
594 * @nid: node ID to set
595 *
596 * Set the nid of memblock memory regions in [@base,@base+@size) to @nid.
597 * Regions which cross the area boundaries are split as necessary.
598 *
599 * RETURNS:
600 * 0 on success, -errno on failure.
601 */
602int __init_memblock memblock_set_node(phys_addr_t base, phys_addr_t size,
603 int nid)
604{
605 struct memblock_type *type = &memblock.memory;
606 phys_addr_t end = base + size;
607 int i;
608
609 /* we'll create at most two more regions */
610 while (type->cnt + 2 > type->max)
611 if (memblock_double_array(type) < 0)
612 return -ENOMEM;
613
614 for (i = 0; i < type->cnt; i++) {
615 struct memblock_region *rgn = &type->regions[i];
616 phys_addr_t rbase = rgn->base;
617 phys_addr_t rend = rbase + rgn->size;
618
619 if (rbase >= end)
620 break;
621 if (rend <= base)
622 continue;
623
624 if (rbase < base) {
625 /*
626 * @rgn intersects from below. Split and continue
627 * to process the next region - the new top half.
628 */
629 rgn->base = base;
630 rgn->size = rend - rgn->base;
631 memblock_insert_region(type, i, rbase, base - rbase,
632 rgn->nid);
633 } else if (rend > end) {
634 /*
635 * @rgn intersects from above. Split and redo the
636 * current region - the new bottom half.
637 */
638 rgn->base = end;
639 rgn->size = rend - rgn->base;
640 memblock_insert_region(type, i--, rbase, end - rbase,
641 rgn->nid);
642 } else {
643 /* @rgn is fully contained, set ->nid */
644 rgn->nid = nid;
645 }
646 }
647
648 memblock_merge_regions(type);
649 return 0;
650}
651#endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */
652
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000653phys_addr_t __init __memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000654{
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000655 phys_addr_t found;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000656
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000657 /* We align the size to limit fragmentation. Without this, a lot of
658 * small allocs quickly eat up the whole reserve array on sparc
659 */
Tejun Heo348968e2011-07-12 09:58:08 +0200660 size = round_up(size, align);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000661
Tejun Heofc769a82011-07-12 09:58:10 +0200662 found = memblock_find_in_range(0, max_addr, size, align);
Tejun Heo9c8c27e2011-12-08 10:22:06 -0800663 if (found && !memblock_reserve(found, size))
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000664 return found;
665
666 return 0;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000667}
668
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000669phys_addr_t __init memblock_alloc_base(phys_addr_t size, phys_addr_t align, phys_addr_t max_addr)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000670{
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000671 phys_addr_t alloc;
672
673 alloc = __memblock_alloc_base(size, align, max_addr);
674
675 if (alloc == 0)
676 panic("ERROR: Failed to allocate 0x%llx bytes below 0x%llx.\n",
677 (unsigned long long) size, (unsigned long long) max_addr);
678
679 return alloc;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000680}
681
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000682phys_addr_t __init memblock_alloc(phys_addr_t size, phys_addr_t align)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000683{
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000684 return memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000685}
686
Yinghai Lu95f72d12010-07-12 14:36:09 +1000687
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000688/*
Tejun Heo34e18452011-07-12 10:46:33 +0200689 * Additional node-local top-down allocators.
Benjamin Herrenschmidtc196f762010-07-06 15:39:16 -0700690 *
691 * WARNING: Only available after early_node_map[] has been populated,
692 * on some architectures, that is after all the calls to add_active_range()
693 * have been done to populate it.
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000694 */
Yinghai Lu95f72d12010-07-12 14:36:09 +1000695
Tejun Heo34e18452011-07-12 10:46:33 +0200696static phys_addr_t __init memblock_nid_range_rev(phys_addr_t start,
697 phys_addr_t end, int *nid)
Benjamin Herrenschmidtc3f72b52010-07-06 15:38:59 -0700698{
Benjamin Herrenschmidtc196f762010-07-06 15:39:16 -0700699#ifdef CONFIG_ARCH_POPULATES_NODE_MAP
Benjamin Herrenschmidtc196f762010-07-06 15:39:16 -0700700 unsigned long start_pfn, end_pfn;
701 int i;
702
Tejun Heob2fea982011-07-12 10:46:31 +0200703 for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, nid)
Tejun Heo34e18452011-07-12 10:46:33 +0200704 if (end > PFN_PHYS(start_pfn) && end <= PFN_PHYS(end_pfn))
705 return max(start, PFN_PHYS(start_pfn));
Benjamin Herrenschmidtc196f762010-07-06 15:39:16 -0700706#endif
Benjamin Herrenschmidtc3f72b52010-07-06 15:38:59 -0700707 *nid = 0;
Tejun Heo34e18452011-07-12 10:46:33 +0200708 return start;
Benjamin Herrenschmidtc3f72b52010-07-06 15:38:59 -0700709}
710
Tejun Heoe6498042011-07-12 10:46:34 +0200711phys_addr_t __init memblock_find_in_range_node(phys_addr_t start,
712 phys_addr_t end,
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +1000713 phys_addr_t size,
714 phys_addr_t align, int nid)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000715{
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000716 struct memblock_type *mem = &memblock.memory;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000717 int i;
718
719 BUG_ON(0 == size);
720
Tejun Heoe6498042011-07-12 10:46:34 +0200721 /* Pump up max_addr */
722 if (end == MEMBLOCK_ALLOC_ACCESSIBLE)
723 end = memblock.current_limit;
724
725 for (i = mem->cnt - 1; i >= 0; i--) {
726 struct memblock_region *r = &mem->regions[i];
727 phys_addr_t base = max(start, r->base);
728 phys_addr_t top = min(end, r->base + r->size);
729
730 while (base < top) {
731 phys_addr_t tbase, ret;
732 int tnid;
733
734 tbase = memblock_nid_range_rev(base, top, &tnid);
735 if (nid == MAX_NUMNODES || tnid == nid) {
736 ret = memblock_find_region(tbase, top, size, align);
737 if (ret)
738 return ret;
739 }
740 top = tbase;
741 }
742 }
743
744 return 0;
745}
746
747phys_addr_t __init memblock_alloc_nid(phys_addr_t size, phys_addr_t align, int nid)
748{
749 phys_addr_t found;
750
751 /*
752 * We align the size to limit fragmentation. Without this, a lot of
Benjamin Herrenschmidt7f219c72010-07-12 14:24:57 +1000753 * small allocs quickly eat up the whole reserve array on sparc
754 */
Tejun Heo348968e2011-07-12 09:58:08 +0200755 size = round_up(size, align);
Benjamin Herrenschmidt7f219c72010-07-12 14:24:57 +1000756
Tejun Heoe6498042011-07-12 10:46:34 +0200757 found = memblock_find_in_range_node(0, MEMBLOCK_ALLOC_ACCESSIBLE,
758 size, align, nid);
Tejun Heo9c8c27e2011-12-08 10:22:06 -0800759 if (found && !memblock_reserve(found, size))
Tejun Heoe6498042011-07-12 10:46:34 +0200760 return found;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000761
Benjamin Herrenschmidt9d1e2492010-07-06 15:39:17 -0700762 return 0;
763}
764
765phys_addr_t __init memblock_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid)
766{
767 phys_addr_t res = memblock_alloc_nid(size, align, nid);
768
769 if (res)
770 return res;
Tejun Heo15fb0972011-07-12 09:58:07 +0200771 return memblock_alloc_base(size, align, MEMBLOCK_ALLOC_ACCESSIBLE);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000772}
773
Benjamin Herrenschmidt9d1e2492010-07-06 15:39:17 -0700774
775/*
776 * Remaining API functions
777 */
778
Yinghai Lu95f72d12010-07-12 14:36:09 +1000779/* You must call memblock_analyze() before this. */
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +1000780phys_addr_t __init memblock_phys_mem_size(void)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000781{
Benjamin Herrenschmidt4734b592010-07-28 14:31:29 +1000782 return memblock.memory_size;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000783}
784
Sam Ravnborg0a93ebe2011-10-31 17:08:16 -0700785/* lowest address */
786phys_addr_t __init_memblock memblock_start_of_DRAM(void)
787{
788 return memblock.memory.regions[0].base;
789}
790
Yinghai Lu10d06432010-07-28 15:43:02 +1000791phys_addr_t __init_memblock memblock_end_of_DRAM(void)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000792{
793 int idx = memblock.memory.cnt - 1;
794
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000795 return (memblock.memory.regions[idx].base + memblock.memory.regions[idx].size);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000796}
797
798/* You must call memblock_analyze() after this. */
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +1000799void __init memblock_enforce_memory_limit(phys_addr_t memory_limit)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000800{
801 unsigned long i;
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +1000802 phys_addr_t limit;
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000803 struct memblock_region *p;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000804
805 if (!memory_limit)
806 return;
807
808 /* Truncate the memblock regions to satisfy the memory limit. */
809 limit = memory_limit;
810 for (i = 0; i < memblock.memory.cnt; i++) {
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000811 if (limit > memblock.memory.regions[i].size) {
812 limit -= memblock.memory.regions[i].size;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000813 continue;
814 }
815
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000816 memblock.memory.regions[i].size = limit;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000817 memblock.memory.cnt = i + 1;
818 break;
819 }
820
Yinghai Lu95f72d12010-07-12 14:36:09 +1000821 memory_limit = memblock_end_of_DRAM();
822
823 /* And truncate any reserves above the limit also. */
824 for (i = 0; i < memblock.reserved.cnt; i++) {
Benjamin Herrenschmidte3239ff2010-08-04 14:06:41 +1000825 p = &memblock.reserved.regions[i];
Yinghai Lu95f72d12010-07-12 14:36:09 +1000826
827 if (p->base > memory_limit)
828 p->size = 0;
829 else if ((p->base + p->size) > memory_limit)
830 p->size = memory_limit - p->base;
831
832 if (p->size == 0) {
833 memblock_remove_region(&memblock.reserved, i);
834 i--;
835 }
836 }
837}
838
Yinghai Lucd794812010-10-11 12:34:09 -0700839static int __init_memblock memblock_search(struct memblock_type *type, phys_addr_t addr)
Benjamin Herrenschmidt72d4b0b2010-08-04 14:38:47 +1000840{
841 unsigned int left = 0, right = type->cnt;
842
843 do {
844 unsigned int mid = (right + left) / 2;
845
846 if (addr < type->regions[mid].base)
847 right = mid;
848 else if (addr >= (type->regions[mid].base +
849 type->regions[mid].size))
850 left = mid + 1;
851 else
852 return mid;
853 } while (left < right);
854 return -1;
855}
856
Benjamin Herrenschmidt2898cc42010-08-04 13:34:42 +1000857int __init memblock_is_reserved(phys_addr_t addr)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000858{
Benjamin Herrenschmidt72d4b0b2010-08-04 14:38:47 +1000859 return memblock_search(&memblock.reserved, addr) != -1;
860}
Yinghai Lu95f72d12010-07-12 14:36:09 +1000861
Yinghai Lu3661ca62010-09-15 13:05:29 -0700862int __init_memblock memblock_is_memory(phys_addr_t addr)
Benjamin Herrenschmidt72d4b0b2010-08-04 14:38:47 +1000863{
864 return memblock_search(&memblock.memory, addr) != -1;
865}
866
Yinghai Lu3661ca62010-09-15 13:05:29 -0700867int __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t size)
Benjamin Herrenschmidt72d4b0b2010-08-04 14:38:47 +1000868{
Tomi Valkeinenabb65272011-01-20 14:44:20 -0800869 int idx = memblock_search(&memblock.memory, base);
Benjamin Herrenschmidt72d4b0b2010-08-04 14:38:47 +1000870
871 if (idx == -1)
872 return 0;
Tomi Valkeinenabb65272011-01-20 14:44:20 -0800873 return memblock.memory.regions[idx].base <= base &&
874 (memblock.memory.regions[idx].base +
875 memblock.memory.regions[idx].size) >= (base + size);
Yinghai Lu95f72d12010-07-12 14:36:09 +1000876}
877
Yinghai Lu10d06432010-07-28 15:43:02 +1000878int __init_memblock memblock_is_region_reserved(phys_addr_t base, phys_addr_t size)
Yinghai Lu95f72d12010-07-12 14:36:09 +1000879{
Benjamin Herrenschmidtf1c2c192010-08-04 14:17:17 +1000880 return memblock_overlaps_region(&memblock.reserved, base, size) >= 0;
Yinghai Lu95f72d12010-07-12 14:36:09 +1000881}
882
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700883
Yinghai Lu3661ca62010-09-15 13:05:29 -0700884void __init_memblock memblock_set_current_limit(phys_addr_t limit)
Benjamin Herrenschmidte63075a2010-07-06 15:39:01 -0700885{
886 memblock.current_limit = limit;
887}
888
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200889static void __init_memblock memblock_dump(struct memblock_type *type, char *name)
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000890{
891 unsigned long long base, size;
892 int i;
893
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200894 pr_info(" %s.cnt = 0x%lx\n", name, type->cnt);
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000895
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200896 for (i = 0; i < type->cnt; i++) {
897 struct memblock_region *rgn = &type->regions[i];
898 char nid_buf[32] = "";
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000899
Tejun Heo7c0caeb2011-07-14 11:43:42 +0200900 base = rgn->base;
901 size = rgn->size;
902#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
903 if (memblock_get_region_node(rgn) != MAX_NUMNODES)
904 snprintf(nid_buf, sizeof(nid_buf), " on node %d",
905 memblock_get_region_node(rgn));
906#endif
907 pr_info(" %s[%#x]\t[%#016llx-%#016llx], %#llx bytes%s\n",
908 name, i, base, base + size - 1, size, nid_buf);
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000909 }
910}
911
Tejun Heo4ff7b822011-12-08 10:22:06 -0800912void __init_memblock __memblock_dump_all(void)
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000913{
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000914 pr_info("MEMBLOCK configuration:\n");
915 pr_info(" memory size = 0x%llx\n", (unsigned long long)memblock.memory_size);
916
917 memblock_dump(&memblock.memory, "memory");
918 memblock_dump(&memblock.reserved, "reserved");
919}
920
921void __init memblock_analyze(void)
922{
923 int i;
924
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000925 memblock.memory_size = 0;
926
927 for (i = 0; i < memblock.memory.cnt; i++)
928 memblock.memory_size += memblock.memory.regions[i].size;
Benjamin Herrenschmidt142b45a2010-07-06 15:39:13 -0700929
930 /* We allow resizing from there */
931 memblock_can_resize = 1;
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000932}
933
Benjamin Herrenschmidt6ed311b2010-07-12 14:36:48 +1000934static int __init early_memblock(char *p)
935{
936 if (p && strstr(p, "debug"))
937 memblock_debug = 1;
938 return 0;
939}
940early_param("memblock", early_memblock);
941
Tejun Heoc378ddd2011-07-14 11:46:03 +0200942#if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_ARCH_DISCARD_MEMBLOCK)
Benjamin Herrenschmidt6d03b882010-07-06 15:39:19 -0700943
944static int memblock_debug_show(struct seq_file *m, void *private)
945{
946 struct memblock_type *type = m->private;
947 struct memblock_region *reg;
948 int i;
949
950 for (i = 0; i < type->cnt; i++) {
951 reg = &type->regions[i];
952 seq_printf(m, "%4d: ", i);
953 if (sizeof(phys_addr_t) == 4)
954 seq_printf(m, "0x%08lx..0x%08lx\n",
955 (unsigned long)reg->base,
956 (unsigned long)(reg->base + reg->size - 1));
957 else
958 seq_printf(m, "0x%016llx..0x%016llx\n",
959 (unsigned long long)reg->base,
960 (unsigned long long)(reg->base + reg->size - 1));
961
962 }
963 return 0;
964}
965
966static int memblock_debug_open(struct inode *inode, struct file *file)
967{
968 return single_open(file, memblock_debug_show, inode->i_private);
969}
970
971static const struct file_operations memblock_debug_fops = {
972 .open = memblock_debug_open,
973 .read = seq_read,
974 .llseek = seq_lseek,
975 .release = single_release,
976};
977
978static int __init memblock_init_debugfs(void)
979{
980 struct dentry *root = debugfs_create_dir("memblock", NULL);
981 if (!root)
982 return -ENXIO;
983 debugfs_create_file("memory", S_IRUGO, root, &memblock.memory, &memblock_debug_fops);
984 debugfs_create_file("reserved", S_IRUGO, root, &memblock.reserved, &memblock_debug_fops);
985
986 return 0;
987}
988__initcall(memblock_init_debugfs);
989
990#endif /* CONFIG_DEBUG_FS */