blob: cf4bffba6f7cb3357feec5f47698cd0a8882a117 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * pSeries NUMA support
3 *
4 * Copyright (C) 2002 Anton Blanchard <anton@au.ibm.com>, IBM
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11#include <linux/threads.h>
12#include <linux/bootmem.h>
13#include <linux/init.h>
14#include <linux/mm.h>
15#include <linux/mmzone.h>
16#include <linux/module.h>
17#include <linux/nodemask.h>
18#include <linux/cpu.h>
19#include <linux/notifier.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080020#include <linux/lmb.h>
Michael Ellerman6df16462008-02-14 11:37:49 +110021#include <linux/of.h>
Anton Blanchard45fb6ce2005-11-11 14:22:35 +110022#include <asm/sparsemem.h>
David S. Millerd9b2b2a2008-02-13 16:56:49 -080023#include <asm/prom.h>
Paul Mackerrascf00a8d2005-10-31 13:07:02 +110024#include <asm/system.h>
Paul Mackerras2249ca92005-11-07 13:18:13 +110025#include <asm/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27static int numa_enabled = 1;
28
Balbir Singh1daa6d02008-02-01 15:57:31 +110029static char *cmdline __initdata;
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031static int numa_debug;
32#define dbg(args...) if (numa_debug) { printk(KERN_INFO args); }
33
Anton Blanchard45fb6ce2005-11-11 14:22:35 +110034int numa_cpu_lookup_table[NR_CPUS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070035cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070036struct pglist_data *node_data[MAX_NUMNODES];
Anton Blanchard45fb6ce2005-11-11 14:22:35 +110037
38EXPORT_SYMBOL(numa_cpu_lookup_table);
39EXPORT_SYMBOL(numa_cpumask_lookup_table);
40EXPORT_SYMBOL(node_data);
41
42static bootmem_data_t __initdata plat_node_bdata[MAX_NUMNODES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070043static int min_common_depth;
Mike Kravetz237a0982005-12-05 12:06:42 -080044static int n_mem_addr_cells, n_mem_size_cells;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Balbir Singh1daa6d02008-02-01 15:57:31 +110046static int __cpuinit fake_numa_create_new_node(unsigned long end_pfn,
47 unsigned int *nid)
48{
49 unsigned long long mem;
50 char *p = cmdline;
51 static unsigned int fake_nid;
52 static unsigned long long curr_boundary;
53
54 /*
55 * Modify node id, iff we started creating NUMA nodes
56 * We want to continue from where we left of the last time
57 */
58 if (fake_nid)
59 *nid = fake_nid;
60 /*
61 * In case there are no more arguments to parse, the
62 * node_id should be the same as the last fake node id
63 * (we've handled this above).
64 */
65 if (!p)
66 return 0;
67
68 mem = memparse(p, &p);
69 if (!mem)
70 return 0;
71
72 if (mem < curr_boundary)
73 return 0;
74
75 curr_boundary = mem;
76
77 if ((end_pfn << PAGE_SHIFT) > mem) {
78 /*
79 * Skip commas and spaces
80 */
81 while (*p == ',' || *p == ' ' || *p == '\t')
82 p++;
83
84 cmdline = p;
85 fake_nid++;
86 *nid = fake_nid;
87 dbg("created new fake_node with id %d\n", fake_nid);
88 return 1;
89 }
90 return 0;
91}
92
Nathan Lynch2e5ce392006-03-20 18:35:15 -060093static void __cpuinit map_cpu_to_node(int cpu, int node)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
95 numa_cpu_lookup_table[cpu] = node;
Anton Blanchard45fb6ce2005-11-11 14:22:35 +110096
Nathan Lynchbf4b85b2006-03-20 18:34:45 -060097 dbg("adding cpu %d to node %d\n", cpu, node);
98
Anton Blanchard45fb6ce2005-11-11 14:22:35 +110099 if (!(cpu_isset(cpu, numa_cpumask_lookup_table[node])))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 cpu_set(cpu, numa_cpumask_lookup_table[node]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
102
103#ifdef CONFIG_HOTPLUG_CPU
104static void unmap_cpu_from_node(unsigned long cpu)
105{
106 int node = numa_cpu_lookup_table[cpu];
107
108 dbg("removing cpu %lu from node %d\n", cpu, node);
109
110 if (cpu_isset(cpu, numa_cpumask_lookup_table[node])) {
111 cpu_clear(cpu, numa_cpumask_lookup_table[node]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 } else {
113 printk(KERN_ERR "WARNING: cpu %lu not found in node %d\n",
114 cpu, node);
115 }
116}
117#endif /* CONFIG_HOTPLUG_CPU */
118
Nathan Lynch2e5ce392006-03-20 18:35:15 -0600119static struct device_node * __cpuinit find_cpu_node(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
121 unsigned int hw_cpuid = get_hard_smp_processor_id(cpu);
122 struct device_node *cpu_node = NULL;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000123 const unsigned int *interrupt_server, *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 int len;
125
126 while ((cpu_node = of_find_node_by_type(cpu_node, "cpu")) != NULL) {
127 /* Try interrupt server first */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000128 interrupt_server = of_get_property(cpu_node,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 "ibm,ppc-interrupt-server#s", &len);
130
131 len = len / sizeof(u32);
132
133 if (interrupt_server && (len > 0)) {
134 while (len--) {
135 if (interrupt_server[len] == hw_cpuid)
136 return cpu_node;
137 }
138 } else {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000139 reg = of_get_property(cpu_node, "reg", &len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (reg && (len > 0) && (reg[0] == hw_cpuid))
141 return cpu_node;
142 }
143 }
144
145 return NULL;
146}
147
148/* must hold reference to node during call */
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000149static const int *of_get_associativity(struct device_node *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150{
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000151 return of_get_property(dev, "ibm,associativity", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600154/* Returns nid in the range [0..MAX_NUMNODES-1], or -1 if no useful numa
155 * info is found.
156 */
Jeremy Kerr953039c2006-05-01 12:16:12 -0700157static int of_node_to_nid_single(struct device_node *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600159 int nid = -1;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000160 const unsigned int *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 if (min_common_depth == -1)
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600163 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 tmp = of_get_associativity(device);
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600166 if (!tmp)
167 goto out;
168
169 if (tmp[0] >= min_common_depth)
Nathan Lynchcf950b72006-03-20 18:35:45 -0600170 nid = tmp[min_common_depth];
Nathan Lynchbc16a752006-03-20 18:36:15 -0600171
172 /* POWER4 LPAR uses 0xffff as invalid node */
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600173 if (nid == 0xffff || nid >= MAX_NUMNODES)
174 nid = -1;
175out:
Nathan Lynchcf950b72006-03-20 18:35:45 -0600176 return nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
Jeremy Kerr953039c2006-05-01 12:16:12 -0700179/* Walk the device tree upwards, looking for an associativity id */
180int of_node_to_nid(struct device_node *device)
181{
182 struct device_node *tmp;
183 int nid = -1;
184
185 of_node_get(device);
186 while (device) {
187 nid = of_node_to_nid_single(device);
188 if (nid != -1)
189 break;
190
191 tmp = device;
192 device = of_get_parent(tmp);
193 of_node_put(tmp);
194 }
195 of_node_put(device);
196
197 return nid;
198}
199EXPORT_SYMBOL_GPL(of_node_to_nid);
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/*
202 * In theory, the "ibm,associativity" property may contain multiple
203 * associativity lists because a resource may be multiply connected
204 * into the machine. This resource then has different associativity
205 * characteristics relative to its multiple connections. We ignore
206 * this for now. We also assume that all cpu and memory sets have
207 * their distances represented at a common level. This won't be
Uwe Kleine-König1b3c3712007-02-17 19:23:03 +0100208 * true for hierarchical NUMA.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 *
210 * In any case the ibm,associativity-reference-points should give
211 * the correct depth for a normal NUMA system.
212 *
213 * - Dave Hansen <haveblue@us.ibm.com>
214 */
215static int __init find_min_common_depth(void)
216{
217 int depth;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000218 const unsigned int *ref_points;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 struct device_node *rtas_root;
220 unsigned int len;
221
222 rtas_root = of_find_node_by_path("/rtas");
223
224 if (!rtas_root)
225 return -1;
226
227 /*
228 * this property is 2 32-bit integers, each representing a level of
229 * depth in the associativity nodes. The first is for an SMP
230 * configuration (should be all 0's) and the second is for a normal
231 * NUMA configuration.
232 */
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000233 ref_points = of_get_property(rtas_root,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 "ibm,associativity-reference-points", &len);
235
236 if ((len >= 1) && ref_points) {
237 depth = ref_points[1];
238 } else {
Nathan Lynchbf4b85b2006-03-20 18:34:45 -0600239 dbg("NUMA: ibm,associativity-reference-points not found.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 depth = -1;
241 }
242 of_node_put(rtas_root);
243
244 return depth;
245}
246
Mike Kravetz84c9fdd2005-11-30 13:47:23 -0800247static void __init get_n_mem_cells(int *n_addr_cells, int *n_size_cells)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 struct device_node *memory = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 memory = of_find_node_by_type(memory, "memory");
Paul Mackerras54c23312005-12-05 15:50:39 +1100252 if (!memory)
Mike Kravetz84c9fdd2005-11-30 13:47:23 -0800253 panic("numa.c: No memory nodes found!");
Paul Mackerras54c23312005-12-05 15:50:39 +1100254
Stephen Rothwella8bda5d2007-04-03 10:56:50 +1000255 *n_addr_cells = of_n_addr_cells(memory);
Stephen Rothwell9213fee2007-04-03 10:57:48 +1000256 *n_size_cells = of_n_size_cells(memory);
Mike Kravetz84c9fdd2005-11-30 13:47:23 -0800257 of_node_put(memory);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258}
259
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000260static unsigned long __devinit read_n_cells(int n, const unsigned int **buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 unsigned long result = 0;
263
264 while (n--) {
265 result = (result << 32) | **buf;
266 (*buf)++;
267 }
268 return result;
269}
270
Nathan Fontenot83426812008-07-03 13:35:54 +1000271struct of_drconf_cell {
272 u64 base_addr;
273 u32 drc_index;
274 u32 reserved;
275 u32 aa_index;
276 u32 flags;
277};
278
279#define DRCONF_MEM_ASSIGNED 0x00000008
280#define DRCONF_MEM_AI_INVALID 0x00000040
281#define DRCONF_MEM_RESERVED 0x00000080
282
283/*
284 * Read the next lmb list entry from the ibm,dynamic-memory property
285 * and return the information in the provided of_drconf_cell structure.
286 */
287static void read_drconf_cell(struct of_drconf_cell *drmem, const u32 **cellp)
288{
289 const u32 *cp;
290
291 drmem->base_addr = read_n_cells(n_mem_addr_cells, cellp);
292
293 cp = *cellp;
294 drmem->drc_index = cp[0];
295 drmem->reserved = cp[1];
296 drmem->aa_index = cp[2];
297 drmem->flags = cp[3];
298
299 *cellp = cp + 4;
300}
301
302/*
303 * Retreive and validate the ibm,dynamic-memory property of the device tree.
304 *
305 * The layout of the ibm,dynamic-memory property is a number N of lmb
306 * list entries followed by N lmb list entries. Each lmb list entry
307 * contains information as layed out in the of_drconf_cell struct above.
308 */
309static int of_get_drconf_memory(struct device_node *memory, const u32 **dm)
310{
311 const u32 *prop;
312 u32 len, entries;
313
314 prop = of_get_property(memory, "ibm,dynamic-memory", &len);
315 if (!prop || len < sizeof(unsigned int))
316 return 0;
317
318 entries = *prop++;
319
320 /* Now that we know the number of entries, revalidate the size
321 * of the property read in to ensure we have everything
322 */
323 if (len < (entries * (n_mem_addr_cells + 4) + 1) * sizeof(unsigned int))
324 return 0;
325
326 *dm = prop;
327 return entries;
328}
329
330/*
331 * Retreive and validate the ibm,lmb-size property for drconf memory
332 * from the device tree.
333 */
334static u64 of_get_lmb_size(struct device_node *memory)
335{
336 const u32 *prop;
337 u32 len;
338
339 prop = of_get_property(memory, "ibm,lmb-size", &len);
340 if (!prop || len < sizeof(unsigned int))
341 return 0;
342
343 return read_n_cells(n_mem_size_cells, &prop);
344}
345
346struct assoc_arrays {
347 u32 n_arrays;
348 u32 array_sz;
349 const u32 *arrays;
350};
351
352/*
353 * Retreive and validate the list of associativity arrays for drconf
354 * memory from the ibm,associativity-lookup-arrays property of the
355 * device tree..
356 *
357 * The layout of the ibm,associativity-lookup-arrays property is a number N
358 * indicating the number of associativity arrays, followed by a number M
359 * indicating the size of each associativity array, followed by a list
360 * of N associativity arrays.
361 */
362static int of_get_assoc_arrays(struct device_node *memory,
363 struct assoc_arrays *aa)
364{
365 const u32 *prop;
366 u32 len;
367
368 prop = of_get_property(memory, "ibm,associativity-lookup-arrays", &len);
369 if (!prop || len < 2 * sizeof(unsigned int))
370 return -1;
371
372 aa->n_arrays = *prop++;
373 aa->array_sz = *prop++;
374
375 /* Now that we know the number of arrrays and size of each array,
376 * revalidate the size of the property read in.
377 */
378 if (len < (aa->n_arrays * aa->array_sz + 2) * sizeof(unsigned int))
379 return -1;
380
381 aa->arrays = prop;
382 return 0;
383}
384
385/*
386 * This is like of_node_to_nid_single() for memory represented in the
387 * ibm,dynamic-reconfiguration-memory node.
388 */
389static int of_drconf_to_nid_single(struct of_drconf_cell *drmem,
390 struct assoc_arrays *aa)
391{
392 int default_nid = 0;
393 int nid = default_nid;
394 int index;
395
396 if (min_common_depth > 0 && min_common_depth <= aa->array_sz &&
397 !(drmem->flags & DRCONF_MEM_AI_INVALID) &&
398 drmem->aa_index < aa->n_arrays) {
399 index = drmem->aa_index * aa->array_sz + min_common_depth - 1;
400 nid = aa->arrays[index];
401
402 if (nid == 0xffff || nid >= MAX_NUMNODES)
403 nid = default_nid;
404 }
405
406 return nid;
407}
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409/*
410 * Figure out to which domain a cpu belongs and stick it there.
411 * Return the id of the domain used.
412 */
Nathan Lynch2e5ce392006-03-20 18:35:15 -0600413static int __cpuinit numa_setup_cpu(unsigned long lcpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
Nathan Lynchcf950b72006-03-20 18:35:45 -0600415 int nid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 struct device_node *cpu = find_cpu_node(lcpu);
417
418 if (!cpu) {
419 WARN_ON(1);
420 goto out;
421 }
422
Jeremy Kerr953039c2006-05-01 12:16:12 -0700423 nid = of_node_to_nid_single(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600425 if (nid < 0 || !node_online(nid))
426 nid = any_online_node(NODE_MASK_ALL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427out:
Nathan Lynchcf950b72006-03-20 18:35:45 -0600428 map_cpu_to_node(lcpu, nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 of_node_put(cpu);
431
Nathan Lynchcf950b72006-03-20 18:35:45 -0600432 return nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
Chandra Seetharaman74b85f32006-06-27 02:54:09 -0700435static int __cpuinit cpu_numa_callback(struct notifier_block *nfb,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 unsigned long action,
437 void *hcpu)
438{
439 unsigned long lcpu = (unsigned long)hcpu;
440 int ret = NOTIFY_DONE;
441
442 switch (action) {
443 case CPU_UP_PREPARE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700444 case CPU_UP_PREPARE_FROZEN:
Nathan Lynch2b261222006-03-20 18:37:15 -0600445 numa_setup_cpu(lcpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 ret = NOTIFY_OK;
447 break;
448#ifdef CONFIG_HOTPLUG_CPU
449 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700450 case CPU_DEAD_FROZEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 case CPU_UP_CANCELED:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700452 case CPU_UP_CANCELED_FROZEN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 unmap_cpu_from_node(lcpu);
454 break;
455 ret = NOTIFY_OK;
456#endif
457 }
458 return ret;
459}
460
461/*
462 * Check and possibly modify a memory region to enforce the memory limit.
463 *
464 * Returns the size the region should have to enforce the memory limit.
465 * This will either be the original value of size, a truncated value,
466 * or zero. If the returned value of size is 0 the region should be
467 * discarded as it lies wholy above the memory limit.
468 */
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100469static unsigned long __init numa_enforce_memory_limit(unsigned long start,
470 unsigned long size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
472 /*
473 * We use lmb_end_of_DRAM() in here instead of memory_limit because
474 * we've already adjusted it for the limit and it takes care of
475 * having memory holes below the limit.
476 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
478 if (! memory_limit)
479 return size;
480
481 if (start + size <= lmb_end_of_DRAM())
482 return size;
483
484 if (start >= lmb_end_of_DRAM())
485 return 0;
486
487 return lmb_end_of_DRAM() - start;
488}
489
Paul Mackerras02045682006-11-29 22:27:42 +1100490/*
491 * Extract NUMA information from the ibm,dynamic-reconfiguration-memory
492 * node. This assumes n_mem_{addr,size}_cells have been set.
493 */
494static void __init parse_drconf_memory(struct device_node *memory)
495{
Nathan Fontenot83426812008-07-03 13:35:54 +1000496 const u32 *dm;
497 unsigned int n, rc;
498 unsigned long lmb_size, size;
499 int nid;
500 struct assoc_arrays aa;
Paul Mackerras02045682006-11-29 22:27:42 +1100501
Nathan Fontenot83426812008-07-03 13:35:54 +1000502 n = of_get_drconf_memory(memory, &dm);
503 if (!n)
Paul Mackerras02045682006-11-29 22:27:42 +1100504 return;
505
Nathan Fontenot83426812008-07-03 13:35:54 +1000506 lmb_size = of_get_lmb_size(memory);
507 if (!lmb_size)
508 return;
509
510 rc = of_get_assoc_arrays(memory, &aa);
511 if (rc)
Paul Mackerras02045682006-11-29 22:27:42 +1100512 return;
513
514 for (; n != 0; --n) {
Nathan Fontenot83426812008-07-03 13:35:54 +1000515 struct of_drconf_cell drmem;
Balbir Singh1daa6d02008-02-01 15:57:31 +1100516
Nathan Fontenot83426812008-07-03 13:35:54 +1000517 read_drconf_cell(&drmem, &dm);
518
519 /* skip this block if the reserved bit is set in flags (0x80)
520 or if the block is not assigned to this partition (0x8) */
521 if ((drmem.flags & DRCONF_MEM_RESERVED)
522 || !(drmem.flags & DRCONF_MEM_ASSIGNED))
523 continue;
524
525 nid = of_drconf_to_nid_single(&drmem, &aa);
526
527 fake_numa_create_new_node(
528 ((drmem.base_addr + lmb_size) >> PAGE_SHIFT),
529 &nid);
530
Paul Mackerras02045682006-11-29 22:27:42 +1100531 node_set_online(nid);
532
Nathan Fontenot83426812008-07-03 13:35:54 +1000533 size = numa_enforce_memory_limit(drmem.base_addr, lmb_size);
Paul Mackerras02045682006-11-29 22:27:42 +1100534 if (!size)
535 continue;
536
Nathan Fontenot83426812008-07-03 13:35:54 +1000537 add_active_range(nid, drmem.base_addr >> PAGE_SHIFT,
538 (drmem.base_addr >> PAGE_SHIFT)
539 + (size >> PAGE_SHIFT));
Paul Mackerras02045682006-11-29 22:27:42 +1100540 }
541}
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543static int __init parse_numa_properties(void)
544{
545 struct device_node *cpu = NULL;
546 struct device_node *memory = NULL;
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600547 int default_nid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 unsigned long i;
549
550 if (numa_enabled == 0) {
551 printk(KERN_WARNING "NUMA disabled by user\n");
552 return -1;
553 }
554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 min_common_depth = find_min_common_depth();
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 if (min_common_depth < 0)
558 return min_common_depth;
559
Nathan Lynchbf4b85b2006-03-20 18:34:45 -0600560 dbg("NUMA associativity depth for CPU/Memory: %d\n", min_common_depth);
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 /*
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600563 * Even though we connect cpus to numa domains later in SMP
564 * init, we need to know the node ids now. This is because
565 * each node to be onlined must have NODE_DATA etc backing it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 */
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600567 for_each_present_cpu(i) {
Nathan Lynchcf950b72006-03-20 18:35:45 -0600568 int nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 cpu = find_cpu_node(i);
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600571 BUG_ON(!cpu);
Jeremy Kerr953039c2006-05-01 12:16:12 -0700572 nid = of_node_to_nid_single(cpu);
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600573 of_node_put(cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600575 /*
576 * Don't fall back to default_nid yet -- we will plug
577 * cpus into nodes once the memory scan has discovered
578 * the topology.
579 */
580 if (nid < 0)
581 continue;
582 node_set_online(nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 }
584
Mike Kravetz237a0982005-12-05 12:06:42 -0800585 get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 memory = NULL;
587 while ((memory = of_find_node_by_type(memory, "memory")) != NULL) {
588 unsigned long start;
589 unsigned long size;
Nathan Lynchcf950b72006-03-20 18:35:45 -0600590 int nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 int ranges;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000592 const unsigned int *memcell_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 unsigned int len;
594
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000595 memcell_buf = of_get_property(memory,
Michael Ellermanba759482005-12-04 18:39:55 +1100596 "linux,usable-memory", &len);
597 if (!memcell_buf || len <= 0)
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000598 memcell_buf = of_get_property(memory, "reg", &len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 if (!memcell_buf || len <= 0)
600 continue;
601
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +1100602 /* ranges in cell */
603 ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604new_range:
605 /* these are order-sensitive, and modify the buffer pointer */
Mike Kravetz237a0982005-12-05 12:06:42 -0800606 start = read_n_cells(n_mem_addr_cells, &memcell_buf);
607 size = read_n_cells(n_mem_size_cells, &memcell_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600609 /*
610 * Assumption: either all memory nodes or none will
611 * have associativity properties. If none, then
612 * everything goes to default_nid.
613 */
Jeremy Kerr953039c2006-05-01 12:16:12 -0700614 nid = of_node_to_nid_single(memory);
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600615 if (nid < 0)
616 nid = default_nid;
Balbir Singh1daa6d02008-02-01 15:57:31 +1100617
618 fake_numa_create_new_node(((start + size) >> PAGE_SHIFT), &nid);
Nathan Lynch482ec7c2006-03-20 18:36:45 -0600619 node_set_online(nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100621 if (!(size = numa_enforce_memory_limit(start, size))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 if (--ranges)
623 goto new_range;
624 else
625 continue;
626 }
627
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700628 add_active_range(nid, start >> PAGE_SHIFT,
629 (start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 if (--ranges)
632 goto new_range;
633 }
634
Paul Mackerras02045682006-11-29 22:27:42 +1100635 /*
636 * Now do the same thing for each LMB listed in the ibm,dynamic-memory
637 * property in the ibm,dynamic-reconfiguration-memory node.
638 */
639 memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
640 if (memory)
641 parse_drconf_memory(memory);
642
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return 0;
644}
645
646static void __init setup_nonnuma(void)
647{
648 unsigned long top_of_ram = lmb_end_of_DRAM();
649 unsigned long total_ram = lmb_phys_mem_size();
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700650 unsigned long start_pfn, end_pfn;
Balbir Singh1daa6d02008-02-01 15:57:31 +1100651 unsigned int i, nid = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Olof Johanssone110b282006-04-12 15:25:01 -0500653 printk(KERN_DEBUG "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 top_of_ram, total_ram);
Olof Johanssone110b282006-04-12 15:25:01 -0500655 printk(KERN_DEBUG "Memory hole size: %ldMB\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 (top_of_ram - total_ram) >> 20);
657
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700658 for (i = 0; i < lmb.memory.cnt; ++i) {
659 start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
660 end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
Balbir Singh1daa6d02008-02-01 15:57:31 +1100661
662 fake_numa_create_new_node(end_pfn, &nid);
663 add_active_range(nid, start_pfn, end_pfn);
664 node_set_online(nid);
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Anton Blanchard4b703a22005-12-13 06:56:47 +1100668void __init dump_numa_cpu_topology(void)
669{
670 unsigned int node;
671 unsigned int cpu, count;
672
673 if (min_common_depth == -1 || !numa_enabled)
674 return;
675
676 for_each_online_node(node) {
Olof Johanssone110b282006-04-12 15:25:01 -0500677 printk(KERN_DEBUG "Node %d CPUs:", node);
Anton Blanchard4b703a22005-12-13 06:56:47 +1100678
679 count = 0;
680 /*
681 * If we used a CPU iterator here we would miss printing
682 * the holes in the cpumap.
683 */
684 for (cpu = 0; cpu < NR_CPUS; cpu++) {
685 if (cpu_isset(cpu, numa_cpumask_lookup_table[node])) {
686 if (count == 0)
687 printk(" %u", cpu);
688 ++count;
689 } else {
690 if (count > 1)
691 printk("-%u", cpu - 1);
692 count = 0;
693 }
694 }
695
696 if (count > 1)
697 printk("-%u", NR_CPUS - 1);
698 printk("\n");
699 }
700}
701
702static void __init dump_numa_memory_topology(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703{
704 unsigned int node;
705 unsigned int count;
706
707 if (min_common_depth == -1 || !numa_enabled)
708 return;
709
710 for_each_online_node(node) {
711 unsigned long i;
712
Olof Johanssone110b282006-04-12 15:25:01 -0500713 printk(KERN_DEBUG "Node %d Memory:", node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 count = 0;
716
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100717 for (i = 0; i < lmb_end_of_DRAM();
718 i += (1 << SECTION_SIZE_BITS)) {
719 if (early_pfn_to_nid(i >> PAGE_SHIFT) == node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 if (count == 0)
721 printk(" 0x%lx", i);
722 ++count;
723 } else {
724 if (count > 0)
725 printk("-0x%lx", i);
726 count = 0;
727 }
728 }
729
730 if (count > 0)
731 printk("-0x%lx", i);
732 printk("\n");
733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734}
735
736/*
737 * Allocate some memory, satisfying the lmb or bootmem allocator where
738 * required. nid is the preferred node and end is the physical address of
739 * the highest address in the node.
740 *
741 * Returns the physical address of the memory.
742 */
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100743static void __init *careful_allocation(int nid, unsigned long size,
744 unsigned long align,
745 unsigned long end_pfn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100747 int new_nid;
Michael Ellermand7a5b2f2006-01-25 21:31:28 +1300748 unsigned long ret = __lmb_alloc_base(size, align, end_pfn << PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
750 /* retry over all memory */
751 if (!ret)
Michael Ellermand7a5b2f2006-01-25 21:31:28 +1300752 ret = __lmb_alloc_base(size, align, lmb_end_of_DRAM());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 if (!ret)
755 panic("numa.c: cannot allocate %lu bytes on node %d",
756 size, nid);
757
758 /*
759 * If the memory came from a previously allocated node, we must
760 * retry with the bootmem allocator.
761 */
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100762 new_nid = early_pfn_to_nid(ret >> PAGE_SHIFT);
763 if (new_nid < nid) {
764 ret = (unsigned long)__alloc_bootmem_node(NODE_DATA(new_nid),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 size, align, 0);
766
767 if (!ret)
768 panic("numa.c: cannot allocate %lu bytes on node %d",
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100769 size, new_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100771 ret = __pa(ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
773 dbg("alloc_bootmem %lx %lx\n", ret, size);
774 }
775
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100776 return (void *)ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
778
Chandra Seetharaman74b85f32006-06-27 02:54:09 -0700779static struct notifier_block __cpuinitdata ppc64_numa_nb = {
780 .notifier_call = cpu_numa_callback,
781 .priority = 1 /* Must run before sched domains notifier. */
782};
783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784void __init do_init_bootmem(void)
785{
786 int nid;
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100787 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 min_low_pfn = 0;
790 max_low_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
791 max_pfn = max_low_pfn;
792
793 if (parse_numa_properties())
794 setup_nonnuma();
795 else
Anton Blanchard4b703a22005-12-13 06:56:47 +1100796 dump_numa_memory_topology();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 register_cpu_notifier(&ppc64_numa_nb);
Nathan Lynch2b261222006-03-20 18:37:15 -0600799 cpu_numa_callback(&ppc64_numa_nb, CPU_UP_PREPARE,
800 (void *)(unsigned long)boot_cpuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 for_each_online_node(nid) {
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700803 unsigned long start_pfn, end_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 unsigned long bootmem_paddr;
805 unsigned long bootmap_pages;
806
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700807 get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 /* Allocate the node structure node local if possible */
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100810 NODE_DATA(nid) = careful_allocation(nid,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 sizeof(struct pglist_data),
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100812 SMP_CACHE_BYTES, end_pfn);
813 NODE_DATA(nid) = __va(NODE_DATA(nid));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
815
816 dbg("node %d\n", nid);
817 dbg("NODE_DATA() = %p\n", NODE_DATA(nid));
818
819 NODE_DATA(nid)->bdata = &plat_node_bdata[nid];
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100820 NODE_DATA(nid)->node_start_pfn = start_pfn;
821 NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 if (NODE_DATA(nid)->node_spanned_pages == 0)
824 continue;
825
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100826 dbg("start_paddr = %lx\n", start_pfn << PAGE_SHIFT);
827 dbg("end_paddr = %lx\n", end_pfn << PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100829 bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
830 bootmem_paddr = (unsigned long)careful_allocation(nid,
831 bootmap_pages << PAGE_SHIFT,
832 PAGE_SIZE, end_pfn);
833 memset(__va(bootmem_paddr), 0, bootmap_pages << PAGE_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 dbg("bootmap_paddr = %lx\n", bootmem_paddr);
836
837 init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100838 start_pfn, end_pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700840 free_bootmem_with_active_regions(nid, end_pfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100842 /* Mark reserved regions on this node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 for (i = 0; i < lmb.reserved.cnt; i++) {
Michael Ellerman180379d2005-08-03 20:21:26 +1000844 unsigned long physbase = lmb.reserved.region[i].base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 unsigned long size = lmb.reserved.region[i].size;
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100846 unsigned long start_paddr = start_pfn << PAGE_SHIFT;
847 unsigned long end_paddr = end_pfn << PAGE_SHIFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
Anton Blanchard45fb6ce2005-11-11 14:22:35 +1100849 if (early_pfn_to_nid(physbase >> PAGE_SHIFT) != nid &&
850 early_pfn_to_nid((physbase+size-1) >> PAGE_SHIFT) != nid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 continue;
852
853 if (physbase < end_paddr &&
854 (physbase+size) > start_paddr) {
855 /* overlaps */
856 if (physbase < start_paddr) {
857 size -= start_paddr - physbase;
858 physbase = start_paddr;
859 }
860
861 if (size > end_paddr - physbase)
862 size = end_paddr - physbase;
863
864 dbg("reserve_bootmem %lx %lx\n", physbase,
865 size);
866 reserve_bootmem_node(NODE_DATA(nid), physbase,
Bernhard Walle72a7fe32008-02-07 00:15:17 -0800867 size, BOOTMEM_DEFAULT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 }
869 }
Bob Picco802f1922005-09-03 15:54:26 -0700870
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700871 sparse_memory_present_with_active_regions(nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 }
873}
874
875void __init paging_init(void)
876{
Mel Gorman6391af12006-10-11 01:20:39 -0700877 unsigned long max_zone_pfns[MAX_NR_ZONES];
878 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
879 max_zone_pfns[ZONE_DMA] = lmb_end_of_DRAM() >> PAGE_SHIFT;
Mel Gormanc67c3cb2006-09-27 01:49:49 -0700880 free_area_init_nodes(max_zone_pfns);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
882
883static int __init early_numa(char *p)
884{
885 if (!p)
886 return 0;
887
888 if (strstr(p, "off"))
889 numa_enabled = 0;
890
891 if (strstr(p, "debug"))
892 numa_debug = 1;
893
Balbir Singh1daa6d02008-02-01 15:57:31 +1100894 p = strstr(p, "fake=");
895 if (p)
896 cmdline = p + strlen("fake=");
897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return 0;
899}
900early_param("numa", early_numa);
Mike Kravetz237a0982005-12-05 12:06:42 -0800901
902#ifdef CONFIG_MEMORY_HOTPLUG
903/*
Nathan Fontenot0db93602008-07-03 13:25:08 +1000904 * Validate the node associated with the memory section we are
905 * trying to add.
906 */
907int valid_hot_add_scn(int *nid, unsigned long start, u32 lmb_size,
908 unsigned long scn_addr)
909{
910 nodemask_t nodes;
911
912 if (*nid < 0 || !node_online(*nid))
913 *nid = any_online_node(NODE_MASK_ALL);
914
915 if ((scn_addr >= start) && (scn_addr < (start + lmb_size))) {
916 nodes_setall(nodes);
917 while (NODE_DATA(*nid)->node_spanned_pages == 0) {
918 node_clear(*nid, nodes);
919 *nid = any_online_node(nodes);
920 }
921
922 return 1;
923 }
924
925 return 0;
926}
927
928/*
929 * Find the node associated with a hot added memory section represented
930 * by the ibm,dynamic-reconfiguration-memory node.
931 */
932static int hot_add_drconf_scn_to_nid(struct device_node *memory,
933 unsigned long scn_addr)
934{
935 const u32 *dm;
936 unsigned int n, rc;
937 unsigned long lmb_size;
938 int default_nid = any_online_node(NODE_MASK_ALL);
939 int nid;
940 struct assoc_arrays aa;
941
942 n = of_get_drconf_memory(memory, &dm);
943 if (!n)
944 return default_nid;;
945
946 lmb_size = of_get_lmb_size(memory);
947 if (!lmb_size)
948 return default_nid;
949
950 rc = of_get_assoc_arrays(memory, &aa);
951 if (rc)
952 return default_nid;
953
954 for (; n != 0; --n) {
955 struct of_drconf_cell drmem;
956
957 read_drconf_cell(&drmem, &dm);
958
959 /* skip this block if it is reserved or not assigned to
960 * this partition */
961 if ((drmem.flags & DRCONF_MEM_RESERVED)
962 || !(drmem.flags & DRCONF_MEM_ASSIGNED))
963 continue;
964
965 nid = of_drconf_to_nid_single(&drmem, &aa);
966
967 if (valid_hot_add_scn(&nid, drmem.base_addr, lmb_size,
968 scn_addr))
969 return nid;
970 }
971
972 BUG(); /* section address should be found above */
973 return 0;
974}
975
976/*
Mike Kravetz237a0982005-12-05 12:06:42 -0800977 * Find the node associated with a hot added memory section. Section
978 * corresponds to a SPARSEMEM section, not an LMB. It is assumed that
979 * sections are fully contained within a single LMB.
980 */
981int hot_add_scn_to_nid(unsigned long scn_addr)
982{
983 struct device_node *memory = NULL;
Andrew Morton069007a2006-03-24 02:34:46 -0800984 int nid;
Mike Kravetz237a0982005-12-05 12:06:42 -0800985
986 if (!numa_enabled || (min_common_depth < 0))
Nathan Fontenot0db93602008-07-03 13:25:08 +1000987 return any_online_node(NODE_MASK_ALL);
988
989 memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
990 if (memory) {
991 nid = hot_add_drconf_scn_to_nid(memory, scn_addr);
992 of_node_put(memory);
993 return nid;
994 }
Mike Kravetz237a0982005-12-05 12:06:42 -0800995
996 while ((memory = of_find_node_by_type(memory, "memory")) != NULL) {
997 unsigned long start, size;
Mike Kravetzb226e462005-12-16 14:30:35 -0800998 int ranges;
Jeremy Kerra7f67bd2006-07-12 15:35:54 +1000999 const unsigned int *memcell_buf;
Mike Kravetz237a0982005-12-05 12:06:42 -08001000 unsigned int len;
1001
Stephen Rothwelle2eb6392007-04-03 22:26:41 +10001002 memcell_buf = of_get_property(memory, "reg", &len);
Mike Kravetz237a0982005-12-05 12:06:42 -08001003 if (!memcell_buf || len <= 0)
1004 continue;
1005
Benjamin Herrenschmidtcc5d0182005-12-13 18:01:21 +11001006 /* ranges in cell */
1007 ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
Mike Kravetz237a0982005-12-05 12:06:42 -08001008ha_new_range:
1009 start = read_n_cells(n_mem_addr_cells, &memcell_buf);
1010 size = read_n_cells(n_mem_size_cells, &memcell_buf);
Jeremy Kerr953039c2006-05-01 12:16:12 -07001011 nid = of_node_to_nid_single(memory);
Mike Kravetz237a0982005-12-05 12:06:42 -08001012
Nathan Fontenot0db93602008-07-03 13:25:08 +10001013 if (valid_hot_add_scn(&nid, start, size, scn_addr)) {
Mike Kravetz237a0982005-12-05 12:06:42 -08001014 of_node_put(memory);
Nathan Fontenot0db93602008-07-03 13:25:08 +10001015 return nid;
Mike Kravetz237a0982005-12-05 12:06:42 -08001016 }
1017
1018 if (--ranges) /* process all ranges in cell */
1019 goto ha_new_range;
1020 }
Mike Kravetz237a0982005-12-05 12:06:42 -08001021 BUG(); /* section address should be found above */
Andrew Morton069007a2006-03-24 02:34:46 -08001022 return 0;
Mike Kravetz237a0982005-12-05 12:06:42 -08001023}
1024#endif /* CONFIG_MEMORY_HOTPLUG */