numa.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. #include <linux/memblock.h>
  3. #include <linux/printk.h>
  4. #include <linux/numa.h>
  5. #include <linux/numa_memblks.h>
  6. struct pglist_data *node_data[MAX_NUMNODES];
  7. EXPORT_SYMBOL(node_data);
  8. /* Allocate NODE_DATA for a node on the local memory */
  9. void __init alloc_node_data(int nid)
  10. {
  11. const size_t nd_size = roundup(sizeof(pg_data_t), SMP_CACHE_BYTES);
  12. u64 nd_pa;
  13. void *nd;
  14. int tnid;
  15. /* Allocate node data. Try node-local memory and then any node. */
  16. nd_pa = memblock_phys_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid);
  17. if (!nd_pa)
  18. panic("Cannot allocate %zu bytes for node %d data\n",
  19. nd_size, nid);
  20. nd = __va(nd_pa);
  21. /* report and initialize */
  22. pr_info("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n", nid,
  23. nd_pa, nd_pa + nd_size - 1);
  24. tnid = early_pfn_to_nid(nd_pa >> PAGE_SHIFT);
  25. if (tnid != nid)
  26. pr_info(" NODE_DATA(%d) on node %d\n", nid, tnid);
  27. node_data[nid] = nd;
  28. memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
  29. }
  30. void __init alloc_offline_node_data(int nid)
  31. {
  32. pg_data_t *pgdat;
  33. pgdat = memblock_alloc(sizeof(*pgdat), SMP_CACHE_BYTES);
  34. if (!pgdat)
  35. panic("Cannot allocate %zuB for node %d.\n",
  36. sizeof(*pgdat), nid);
  37. node_data[nid] = pgdat;
  38. }
  39. /* Stub functions: */
  40. #ifndef memory_add_physaddr_to_nid
  41. int memory_add_physaddr_to_nid(u64 start)
  42. {
  43. pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
  44. start);
  45. return 0;
  46. }
  47. EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
  48. #endif
  49. #ifndef phys_to_target_node
  50. int phys_to_target_node(u64 start)
  51. {
  52. pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
  53. start);
  54. return 0;
  55. }
  56. EXPORT_SYMBOL_GPL(phys_to_target_node);
  57. #endif