numa.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. /*
  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>
  20. #include <asm/sparsemem.h>
  21. #include <asm/lmb.h>
  22. #include <asm/system.h>
  23. #include <asm/smp.h>
  24. static int numa_enabled = 1;
  25. static int numa_debug;
  26. #define dbg(args...) if (numa_debug) { printk(KERN_INFO args); }
  27. int numa_cpu_lookup_table[NR_CPUS];
  28. cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES];
  29. struct pglist_data *node_data[MAX_NUMNODES];
  30. EXPORT_SYMBOL(numa_cpu_lookup_table);
  31. EXPORT_SYMBOL(numa_cpumask_lookup_table);
  32. EXPORT_SYMBOL(node_data);
  33. static bootmem_data_t __initdata plat_node_bdata[MAX_NUMNODES];
  34. static int min_common_depth;
  35. static int n_mem_addr_cells, n_mem_size_cells;
  36. static void __cpuinit map_cpu_to_node(int cpu, int node)
  37. {
  38. numa_cpu_lookup_table[cpu] = node;
  39. dbg("adding cpu %d to node %d\n", cpu, node);
  40. if (!(cpu_isset(cpu, numa_cpumask_lookup_table[node])))
  41. cpu_set(cpu, numa_cpumask_lookup_table[node]);
  42. }
  43. #ifdef CONFIG_HOTPLUG_CPU
  44. static void unmap_cpu_from_node(unsigned long cpu)
  45. {
  46. int node = numa_cpu_lookup_table[cpu];
  47. dbg("removing cpu %lu from node %d\n", cpu, node);
  48. if (cpu_isset(cpu, numa_cpumask_lookup_table[node])) {
  49. cpu_clear(cpu, numa_cpumask_lookup_table[node]);
  50. } else {
  51. printk(KERN_ERR "WARNING: cpu %lu not found in node %d\n",
  52. cpu, node);
  53. }
  54. }
  55. #endif /* CONFIG_HOTPLUG_CPU */
  56. static struct device_node * __cpuinit find_cpu_node(unsigned int cpu)
  57. {
  58. unsigned int hw_cpuid = get_hard_smp_processor_id(cpu);
  59. struct device_node *cpu_node = NULL;
  60. const unsigned int *interrupt_server, *reg;
  61. int len;
  62. while ((cpu_node = of_find_node_by_type(cpu_node, "cpu")) != NULL) {
  63. /* Try interrupt server first */
  64. interrupt_server = get_property(cpu_node,
  65. "ibm,ppc-interrupt-server#s", &len);
  66. len = len / sizeof(u32);
  67. if (interrupt_server && (len > 0)) {
  68. while (len--) {
  69. if (interrupt_server[len] == hw_cpuid)
  70. return cpu_node;
  71. }
  72. } else {
  73. reg = get_property(cpu_node, "reg", &len);
  74. if (reg && (len > 0) && (reg[0] == hw_cpuid))
  75. return cpu_node;
  76. }
  77. }
  78. return NULL;
  79. }
  80. /* must hold reference to node during call */
  81. static const int *of_get_associativity(struct device_node *dev)
  82. {
  83. return get_property(dev, "ibm,associativity", NULL);
  84. }
  85. /* Returns nid in the range [0..MAX_NUMNODES-1], or -1 if no useful numa
  86. * info is found.
  87. */
  88. static int of_node_to_nid_single(struct device_node *device)
  89. {
  90. int nid = -1;
  91. const unsigned int *tmp;
  92. if (min_common_depth == -1)
  93. goto out;
  94. tmp = of_get_associativity(device);
  95. if (!tmp)
  96. goto out;
  97. if (tmp[0] >= min_common_depth)
  98. nid = tmp[min_common_depth];
  99. /* POWER4 LPAR uses 0xffff as invalid node */
  100. if (nid == 0xffff || nid >= MAX_NUMNODES)
  101. nid = -1;
  102. out:
  103. return nid;
  104. }
  105. /* Walk the device tree upwards, looking for an associativity id */
  106. int of_node_to_nid(struct device_node *device)
  107. {
  108. struct device_node *tmp;
  109. int nid = -1;
  110. of_node_get(device);
  111. while (device) {
  112. nid = of_node_to_nid_single(device);
  113. if (nid != -1)
  114. break;
  115. tmp = device;
  116. device = of_get_parent(tmp);
  117. of_node_put(tmp);
  118. }
  119. of_node_put(device);
  120. return nid;
  121. }
  122. EXPORT_SYMBOL_GPL(of_node_to_nid);
  123. /*
  124. * In theory, the "ibm,associativity" property may contain multiple
  125. * associativity lists because a resource may be multiply connected
  126. * into the machine. This resource then has different associativity
  127. * characteristics relative to its multiple connections. We ignore
  128. * this for now. We also assume that all cpu and memory sets have
  129. * their distances represented at a common level. This won't be
  130. * true for heirarchical NUMA.
  131. *
  132. * In any case the ibm,associativity-reference-points should give
  133. * the correct depth for a normal NUMA system.
  134. *
  135. * - Dave Hansen <haveblue@us.ibm.com>
  136. */
  137. static int __init find_min_common_depth(void)
  138. {
  139. int depth;
  140. const unsigned int *ref_points;
  141. struct device_node *rtas_root;
  142. unsigned int len;
  143. rtas_root = of_find_node_by_path("/rtas");
  144. if (!rtas_root)
  145. return -1;
  146. /*
  147. * this property is 2 32-bit integers, each representing a level of
  148. * depth in the associativity nodes. The first is for an SMP
  149. * configuration (should be all 0's) and the second is for a normal
  150. * NUMA configuration.
  151. */
  152. ref_points = get_property(rtas_root,
  153. "ibm,associativity-reference-points", &len);
  154. if ((len >= 1) && ref_points) {
  155. depth = ref_points[1];
  156. } else {
  157. dbg("NUMA: ibm,associativity-reference-points not found.\n");
  158. depth = -1;
  159. }
  160. of_node_put(rtas_root);
  161. return depth;
  162. }
  163. static void __init get_n_mem_cells(int *n_addr_cells, int *n_size_cells)
  164. {
  165. struct device_node *memory = NULL;
  166. memory = of_find_node_by_type(memory, "memory");
  167. if (!memory)
  168. panic("numa.c: No memory nodes found!");
  169. *n_addr_cells = prom_n_addr_cells(memory);
  170. *n_size_cells = prom_n_size_cells(memory);
  171. of_node_put(memory);
  172. }
  173. static unsigned long __devinit read_n_cells(int n, const unsigned int **buf)
  174. {
  175. unsigned long result = 0;
  176. while (n--) {
  177. result = (result << 32) | **buf;
  178. (*buf)++;
  179. }
  180. return result;
  181. }
  182. /*
  183. * Figure out to which domain a cpu belongs and stick it there.
  184. * Return the id of the domain used.
  185. */
  186. static int __cpuinit numa_setup_cpu(unsigned long lcpu)
  187. {
  188. int nid = 0;
  189. struct device_node *cpu = find_cpu_node(lcpu);
  190. if (!cpu) {
  191. WARN_ON(1);
  192. goto out;
  193. }
  194. nid = of_node_to_nid_single(cpu);
  195. if (nid < 0 || !node_online(nid))
  196. nid = any_online_node(NODE_MASK_ALL);
  197. out:
  198. map_cpu_to_node(lcpu, nid);
  199. of_node_put(cpu);
  200. return nid;
  201. }
  202. static int __cpuinit cpu_numa_callback(struct notifier_block *nfb,
  203. unsigned long action,
  204. void *hcpu)
  205. {
  206. unsigned long lcpu = (unsigned long)hcpu;
  207. int ret = NOTIFY_DONE;
  208. switch (action) {
  209. case CPU_UP_PREPARE:
  210. numa_setup_cpu(lcpu);
  211. ret = NOTIFY_OK;
  212. break;
  213. #ifdef CONFIG_HOTPLUG_CPU
  214. case CPU_DEAD:
  215. case CPU_UP_CANCELED:
  216. unmap_cpu_from_node(lcpu);
  217. break;
  218. ret = NOTIFY_OK;
  219. #endif
  220. }
  221. return ret;
  222. }
  223. /*
  224. * Check and possibly modify a memory region to enforce the memory limit.
  225. *
  226. * Returns the size the region should have to enforce the memory limit.
  227. * This will either be the original value of size, a truncated value,
  228. * or zero. If the returned value of size is 0 the region should be
  229. * discarded as it lies wholy above the memory limit.
  230. */
  231. static unsigned long __init numa_enforce_memory_limit(unsigned long start,
  232. unsigned long size)
  233. {
  234. /*
  235. * We use lmb_end_of_DRAM() in here instead of memory_limit because
  236. * we've already adjusted it for the limit and it takes care of
  237. * having memory holes below the limit.
  238. */
  239. if (! memory_limit)
  240. return size;
  241. if (start + size <= lmb_end_of_DRAM())
  242. return size;
  243. if (start >= lmb_end_of_DRAM())
  244. return 0;
  245. return lmb_end_of_DRAM() - start;
  246. }
  247. /*
  248. * Extract NUMA information from the ibm,dynamic-reconfiguration-memory
  249. * node. This assumes n_mem_{addr,size}_cells have been set.
  250. */
  251. static void __init parse_drconf_memory(struct device_node *memory)
  252. {
  253. const unsigned int *lm, *dm, *aa;
  254. unsigned int ls, ld, la;
  255. unsigned int n, aam, aalen;
  256. unsigned long lmb_size, size;
  257. int nid, default_nid = 0;
  258. unsigned int start, ai, flags;
  259. lm = get_property(memory, "ibm,lmb-size", &ls);
  260. dm = get_property(memory, "ibm,dynamic-memory", &ld);
  261. aa = get_property(memory, "ibm,associativity-lookup-arrays", &la);
  262. if (!lm || !dm || !aa ||
  263. ls < sizeof(unsigned int) || ld < sizeof(unsigned int) ||
  264. la < 2 * sizeof(unsigned int))
  265. return;
  266. lmb_size = read_n_cells(n_mem_size_cells, &lm);
  267. n = *dm++; /* number of LMBs */
  268. aam = *aa++; /* number of associativity lists */
  269. aalen = *aa++; /* length of each associativity list */
  270. if (ld < (n * (n_mem_addr_cells + 4) + 1) * sizeof(unsigned int) ||
  271. la < (aam * aalen + 2) * sizeof(unsigned int))
  272. return;
  273. for (; n != 0; --n) {
  274. start = read_n_cells(n_mem_addr_cells, &dm);
  275. ai = dm[2];
  276. flags = dm[3];
  277. dm += 4;
  278. /* 0x80 == reserved, 0x8 = assigned to us */
  279. if ((flags & 0x80) || !(flags & 0x8))
  280. continue;
  281. nid = default_nid;
  282. /* flags & 0x40 means associativity index is invalid */
  283. if (min_common_depth > 0 && min_common_depth <= aalen &&
  284. (flags & 0x40) == 0 && ai < aam) {
  285. /* this is like of_node_to_nid_single */
  286. nid = aa[ai * aalen + min_common_depth - 1];
  287. if (nid == 0xffff || nid >= MAX_NUMNODES)
  288. nid = default_nid;
  289. }
  290. node_set_online(nid);
  291. size = numa_enforce_memory_limit(start, lmb_size);
  292. if (!size)
  293. continue;
  294. add_active_range(nid, start >> PAGE_SHIFT,
  295. (start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
  296. }
  297. }
  298. static int __init parse_numa_properties(void)
  299. {
  300. struct device_node *cpu = NULL;
  301. struct device_node *memory = NULL;
  302. int default_nid = 0;
  303. unsigned long i;
  304. if (numa_enabled == 0) {
  305. printk(KERN_WARNING "NUMA disabled by user\n");
  306. return -1;
  307. }
  308. min_common_depth = find_min_common_depth();
  309. if (min_common_depth < 0)
  310. return min_common_depth;
  311. dbg("NUMA associativity depth for CPU/Memory: %d\n", min_common_depth);
  312. /*
  313. * Even though we connect cpus to numa domains later in SMP
  314. * init, we need to know the node ids now. This is because
  315. * each node to be onlined must have NODE_DATA etc backing it.
  316. */
  317. for_each_present_cpu(i) {
  318. int nid;
  319. cpu = find_cpu_node(i);
  320. BUG_ON(!cpu);
  321. nid = of_node_to_nid_single(cpu);
  322. of_node_put(cpu);
  323. /*
  324. * Don't fall back to default_nid yet -- we will plug
  325. * cpus into nodes once the memory scan has discovered
  326. * the topology.
  327. */
  328. if (nid < 0)
  329. continue;
  330. node_set_online(nid);
  331. }
  332. get_n_mem_cells(&n_mem_addr_cells, &n_mem_size_cells);
  333. memory = NULL;
  334. while ((memory = of_find_node_by_type(memory, "memory")) != NULL) {
  335. unsigned long start;
  336. unsigned long size;
  337. int nid;
  338. int ranges;
  339. const unsigned int *memcell_buf;
  340. unsigned int len;
  341. memcell_buf = get_property(memory,
  342. "linux,usable-memory", &len);
  343. if (!memcell_buf || len <= 0)
  344. memcell_buf = get_property(memory, "reg", &len);
  345. if (!memcell_buf || len <= 0)
  346. continue;
  347. /* ranges in cell */
  348. ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
  349. new_range:
  350. /* these are order-sensitive, and modify the buffer pointer */
  351. start = read_n_cells(n_mem_addr_cells, &memcell_buf);
  352. size = read_n_cells(n_mem_size_cells, &memcell_buf);
  353. /*
  354. * Assumption: either all memory nodes or none will
  355. * have associativity properties. If none, then
  356. * everything goes to default_nid.
  357. */
  358. nid = of_node_to_nid_single(memory);
  359. if (nid < 0)
  360. nid = default_nid;
  361. node_set_online(nid);
  362. if (!(size = numa_enforce_memory_limit(start, size))) {
  363. if (--ranges)
  364. goto new_range;
  365. else
  366. continue;
  367. }
  368. add_active_range(nid, start >> PAGE_SHIFT,
  369. (start >> PAGE_SHIFT) + (size >> PAGE_SHIFT));
  370. if (--ranges)
  371. goto new_range;
  372. }
  373. /*
  374. * Now do the same thing for each LMB listed in the ibm,dynamic-memory
  375. * property in the ibm,dynamic-reconfiguration-memory node.
  376. */
  377. memory = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
  378. if (memory)
  379. parse_drconf_memory(memory);
  380. return 0;
  381. }
  382. static void __init setup_nonnuma(void)
  383. {
  384. unsigned long top_of_ram = lmb_end_of_DRAM();
  385. unsigned long total_ram = lmb_phys_mem_size();
  386. unsigned long start_pfn, end_pfn;
  387. unsigned int i;
  388. printk(KERN_DEBUG "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
  389. top_of_ram, total_ram);
  390. printk(KERN_DEBUG "Memory hole size: %ldMB\n",
  391. (top_of_ram - total_ram) >> 20);
  392. for (i = 0; i < lmb.memory.cnt; ++i) {
  393. start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
  394. end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
  395. add_active_range(0, start_pfn, end_pfn);
  396. }
  397. node_set_online(0);
  398. }
  399. void __init dump_numa_cpu_topology(void)
  400. {
  401. unsigned int node;
  402. unsigned int cpu, count;
  403. if (min_common_depth == -1 || !numa_enabled)
  404. return;
  405. for_each_online_node(node) {
  406. printk(KERN_DEBUG "Node %d CPUs:", node);
  407. count = 0;
  408. /*
  409. * If we used a CPU iterator here we would miss printing
  410. * the holes in the cpumap.
  411. */
  412. for (cpu = 0; cpu < NR_CPUS; cpu++) {
  413. if (cpu_isset(cpu, numa_cpumask_lookup_table[node])) {
  414. if (count == 0)
  415. printk(" %u", cpu);
  416. ++count;
  417. } else {
  418. if (count > 1)
  419. printk("-%u", cpu - 1);
  420. count = 0;
  421. }
  422. }
  423. if (count > 1)
  424. printk("-%u", NR_CPUS - 1);
  425. printk("\n");
  426. }
  427. }
  428. static void __init dump_numa_memory_topology(void)
  429. {
  430. unsigned int node;
  431. unsigned int count;
  432. if (min_common_depth == -1 || !numa_enabled)
  433. return;
  434. for_each_online_node(node) {
  435. unsigned long i;
  436. printk(KERN_DEBUG "Node %d Memory:", node);
  437. count = 0;
  438. for (i = 0; i < lmb_end_of_DRAM();
  439. i += (1 << SECTION_SIZE_BITS)) {
  440. if (early_pfn_to_nid(i >> PAGE_SHIFT) == node) {
  441. if (count == 0)
  442. printk(" 0x%lx", i);
  443. ++count;
  444. } else {
  445. if (count > 0)
  446. printk("-0x%lx", i);
  447. count = 0;
  448. }
  449. }
  450. if (count > 0)
  451. printk("-0x%lx", i);
  452. printk("\n");
  453. }
  454. }
  455. /*
  456. * Allocate some memory, satisfying the lmb or bootmem allocator where
  457. * required. nid is the preferred node and end is the physical address of
  458. * the highest address in the node.
  459. *
  460. * Returns the physical address of the memory.
  461. */
  462. static void __init *careful_allocation(int nid, unsigned long size,
  463. unsigned long align,
  464. unsigned long end_pfn)
  465. {
  466. int new_nid;
  467. unsigned long ret = __lmb_alloc_base(size, align, end_pfn << PAGE_SHIFT);
  468. /* retry over all memory */
  469. if (!ret)
  470. ret = __lmb_alloc_base(size, align, lmb_end_of_DRAM());
  471. if (!ret)
  472. panic("numa.c: cannot allocate %lu bytes on node %d",
  473. size, nid);
  474. /*
  475. * If the memory came from a previously allocated node, we must
  476. * retry with the bootmem allocator.
  477. */
  478. new_nid = early_pfn_to_nid(ret >> PAGE_SHIFT);
  479. if (new_nid < nid) {
  480. ret = (unsigned long)__alloc_bootmem_node(NODE_DATA(new_nid),
  481. size, align, 0);
  482. if (!ret)
  483. panic("numa.c: cannot allocate %lu bytes on node %d",
  484. size, new_nid);
  485. ret = __pa(ret);
  486. dbg("alloc_bootmem %lx %lx\n", ret, size);
  487. }
  488. return (void *)ret;
  489. }
  490. static struct notifier_block __cpuinitdata ppc64_numa_nb = {
  491. .notifier_call = cpu_numa_callback,
  492. .priority = 1 /* Must run before sched domains notifier. */
  493. };
  494. void __init do_init_bootmem(void)
  495. {
  496. int nid;
  497. unsigned int i;
  498. min_low_pfn = 0;
  499. max_low_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
  500. max_pfn = max_low_pfn;
  501. if (parse_numa_properties())
  502. setup_nonnuma();
  503. else
  504. dump_numa_memory_topology();
  505. register_cpu_notifier(&ppc64_numa_nb);
  506. cpu_numa_callback(&ppc64_numa_nb, CPU_UP_PREPARE,
  507. (void *)(unsigned long)boot_cpuid);
  508. for_each_online_node(nid) {
  509. unsigned long start_pfn, end_pfn;
  510. unsigned long bootmem_paddr;
  511. unsigned long bootmap_pages;
  512. get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
  513. /* Allocate the node structure node local if possible */
  514. NODE_DATA(nid) = careful_allocation(nid,
  515. sizeof(struct pglist_data),
  516. SMP_CACHE_BYTES, end_pfn);
  517. NODE_DATA(nid) = __va(NODE_DATA(nid));
  518. memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
  519. dbg("node %d\n", nid);
  520. dbg("NODE_DATA() = %p\n", NODE_DATA(nid));
  521. NODE_DATA(nid)->bdata = &plat_node_bdata[nid];
  522. NODE_DATA(nid)->node_start_pfn = start_pfn;
  523. NODE_DATA(nid)->node_spanned_pages = end_pfn - start_pfn;
  524. if (NODE_DATA(nid)->node_spanned_pages == 0)
  525. continue;
  526. dbg("start_paddr = %lx\n", start_pfn << PAGE_SHIFT);
  527. dbg("end_paddr = %lx\n", end_pfn << PAGE_SHIFT);
  528. bootmap_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
  529. bootmem_paddr = (unsigned long)careful_allocation(nid,
  530. bootmap_pages << PAGE_SHIFT,
  531. PAGE_SIZE, end_pfn);
  532. memset(__va(bootmem_paddr), 0, bootmap_pages << PAGE_SHIFT);
  533. dbg("bootmap_paddr = %lx\n", bootmem_paddr);
  534. init_bootmem_node(NODE_DATA(nid), bootmem_paddr >> PAGE_SHIFT,
  535. start_pfn, end_pfn);
  536. free_bootmem_with_active_regions(nid, end_pfn);
  537. /* Mark reserved regions on this node */
  538. for (i = 0; i < lmb.reserved.cnt; i++) {
  539. unsigned long physbase = lmb.reserved.region[i].base;
  540. unsigned long size = lmb.reserved.region[i].size;
  541. unsigned long start_paddr = start_pfn << PAGE_SHIFT;
  542. unsigned long end_paddr = end_pfn << PAGE_SHIFT;
  543. if (early_pfn_to_nid(physbase >> PAGE_SHIFT) != nid &&
  544. early_pfn_to_nid((physbase+size-1) >> PAGE_SHIFT) != nid)
  545. continue;
  546. if (physbase < end_paddr &&
  547. (physbase+size) > start_paddr) {
  548. /* overlaps */
  549. if (physbase < start_paddr) {
  550. size -= start_paddr - physbase;
  551. physbase = start_paddr;
  552. }
  553. if (size > end_paddr - physbase)
  554. size = end_paddr - physbase;
  555. dbg("reserve_bootmem %lx %lx\n", physbase,
  556. size);
  557. reserve_bootmem_node(NODE_DATA(nid), physbase,
  558. size);
  559. }
  560. }
  561. sparse_memory_present_with_active_regions(nid);
  562. }
  563. }
  564. void __init paging_init(void)
  565. {
  566. unsigned long max_zone_pfns[MAX_NR_ZONES];
  567. memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
  568. max_zone_pfns[ZONE_DMA] = lmb_end_of_DRAM() >> PAGE_SHIFT;
  569. free_area_init_nodes(max_zone_pfns);
  570. }
  571. static int __init early_numa(char *p)
  572. {
  573. if (!p)
  574. return 0;
  575. if (strstr(p, "off"))
  576. numa_enabled = 0;
  577. if (strstr(p, "debug"))
  578. numa_debug = 1;
  579. return 0;
  580. }
  581. early_param("numa", early_numa);
  582. #ifdef CONFIG_MEMORY_HOTPLUG
  583. /*
  584. * Find the node associated with a hot added memory section. Section
  585. * corresponds to a SPARSEMEM section, not an LMB. It is assumed that
  586. * sections are fully contained within a single LMB.
  587. */
  588. int hot_add_scn_to_nid(unsigned long scn_addr)
  589. {
  590. struct device_node *memory = NULL;
  591. nodemask_t nodes;
  592. int default_nid = any_online_node(NODE_MASK_ALL);
  593. int nid;
  594. if (!numa_enabled || (min_common_depth < 0))
  595. return default_nid;
  596. while ((memory = of_find_node_by_type(memory, "memory")) != NULL) {
  597. unsigned long start, size;
  598. int ranges;
  599. const unsigned int *memcell_buf;
  600. unsigned int len;
  601. memcell_buf = get_property(memory, "reg", &len);
  602. if (!memcell_buf || len <= 0)
  603. continue;
  604. /* ranges in cell */
  605. ranges = (len >> 2) / (n_mem_addr_cells + n_mem_size_cells);
  606. ha_new_range:
  607. start = read_n_cells(n_mem_addr_cells, &memcell_buf);
  608. size = read_n_cells(n_mem_size_cells, &memcell_buf);
  609. nid = of_node_to_nid_single(memory);
  610. /* Domains not present at boot default to 0 */
  611. if (nid < 0 || !node_online(nid))
  612. nid = default_nid;
  613. if ((scn_addr >= start) && (scn_addr < (start + size))) {
  614. of_node_put(memory);
  615. goto got_nid;
  616. }
  617. if (--ranges) /* process all ranges in cell */
  618. goto ha_new_range;
  619. }
  620. BUG(); /* section address should be found above */
  621. return 0;
  622. /* Temporary code to ensure that returned node is not empty */
  623. got_nid:
  624. nodes_setall(nodes);
  625. while (NODE_DATA(nid)->node_spanned_pages == 0) {
  626. node_clear(nid, nodes);
  627. nid = any_online_node(nodes);
  628. }
  629. return nid;
  630. }
  631. #endif /* CONFIG_MEMORY_HOTPLUG */