node.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/linux/node.h - generic node definition
  4. *
  5. * This is mainly for topological representation. We define the
  6. * basic 'struct node' here, which can be embedded in per-arch
  7. * definitions of processors.
  8. *
  9. * Basic handling of the devices is done in drivers/base/node.c
  10. * and system devices are handled in drivers/base/sys.c.
  11. *
  12. * Nodes are exported via driverfs in the class/node/devices/
  13. * directory.
  14. */
  15. #ifndef _LINUX_NODE_H_
  16. #define _LINUX_NODE_H_
  17. #include <linux/device.h>
  18. #include <linux/cpumask.h>
  19. #include <linux/workqueue.h>
  20. struct node {
  21. struct device dev;
  22. #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
  23. struct work_struct node_work;
  24. #endif
  25. };
  26. struct memory_block;
  27. extern struct node *node_devices[];
  28. typedef void (*node_registration_func_t)(struct node *);
  29. #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
  30. extern int link_mem_sections(int nid, unsigned long start_pfn,
  31. unsigned long nr_pages, bool check_nid);
  32. #else
  33. static inline int link_mem_sections(int nid, unsigned long start_pfn,
  34. unsigned long nr_pages, bool check_nid)
  35. {
  36. return 0;
  37. }
  38. #endif
  39. extern void unregister_node(struct node *node);
  40. #ifdef CONFIG_NUMA
  41. /* Core of the node registration - only memory hotplug should use this */
  42. extern int __register_one_node(int nid);
  43. /* Registers an online node */
  44. static inline int register_one_node(int nid)
  45. {
  46. int error = 0;
  47. if (node_online(nid)) {
  48. struct pglist_data *pgdat = NODE_DATA(nid);
  49. error = __register_one_node(nid);
  50. if (error)
  51. return error;
  52. /* link memory sections under this node */
  53. error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages, true);
  54. }
  55. return error;
  56. }
  57. extern void unregister_one_node(int nid);
  58. extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
  59. extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
  60. extern int register_mem_sect_under_node(struct memory_block *mem_blk,
  61. int nid, bool check_nid);
  62. extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
  63. unsigned long phys_index);
  64. #ifdef CONFIG_HUGETLBFS
  65. extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
  66. node_registration_func_t unregister);
  67. #endif
  68. #else
  69. static inline int __register_one_node(int nid)
  70. {
  71. return 0;
  72. }
  73. static inline int register_one_node(int nid)
  74. {
  75. return 0;
  76. }
  77. static inline int unregister_one_node(int nid)
  78. {
  79. return 0;
  80. }
  81. static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
  82. {
  83. return 0;
  84. }
  85. static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
  86. {
  87. return 0;
  88. }
  89. static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
  90. int nid, bool check_nid)
  91. {
  92. return 0;
  93. }
  94. static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
  95. unsigned long phys_index)
  96. {
  97. return 0;
  98. }
  99. static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
  100. node_registration_func_t unreg)
  101. {
  102. }
  103. #endif
  104. #define to_node(device) container_of(device, struct node, dev)
  105. #endif /* _LINUX_NODE_H_ */