numa.c 19 KB

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