numa.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. int tnid;
  14. /* Allocate node data. Try node-local memory and then any node. */
  15. nd_pa = memblock_phys_alloc_try_nid(nd_size, SMP_CACHE_BYTES, nid);
  16. if (!nd_pa)
  17. panic("Cannot allocate %zu bytes for node %d data\n",
  18. nd_size, nid);
  19. /* report and initialize */
  20. pr_info("NODE_DATA(%d) allocated [mem %#010Lx-%#010Lx]\n", nid,
  21. nd_pa, nd_pa + nd_size - 1);
  22. tnid = early_pfn_to_nid(nd_pa >> PAGE_SHIFT);
  23. if (tnid != nid)
  24. pr_info(" NODE_DATA(%d) on node %d\n", nid, tnid);
  25. node_data[nid] = __va(nd_pa);
  26. memset(NODE_DATA(nid), 0, sizeof(pg_data_t));
  27. }
  28. void __init alloc_offline_node_data(int nid)
  29. {
  30. pg_data_t *pgdat;
  31. node_data[nid] = memblock_alloc_or_panic(sizeof(*pgdat), SMP_CACHE_BYTES);
  32. }
  33. /* Stub functions: */
  34. #ifndef memory_add_physaddr_to_nid
  35. int memory_add_physaddr_to_nid(u64 start)
  36. {
  37. pr_info_once("Unknown online node for memory at 0x%llx, assuming node 0\n",
  38. start);
  39. return 0;
  40. }
  41. EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
  42. #endif
  43. #ifndef phys_to_target_node
  44. int phys_to_target_node(u64 start)
  45. {
  46. pr_info_once("Unknown target node for memory at 0x%llx, assuming node 0\n",
  47. start);
  48. return 0;
  49. }
  50. EXPORT_SYMBOL_GPL(phys_to_target_node);
  51. #endif