node.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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, unsigned long nr_pages);
  31. #else
  32. static inline int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages)
  33. {
  34. return 0;
  35. }
  36. #endif
  37. extern void unregister_node(struct node *node);
  38. #ifdef CONFIG_NUMA
  39. /* Core of the node registration - only memory hotplug should use this */
  40. extern int __register_one_node(int nid);
  41. /* Registers an online node */
  42. static inline int register_one_node(int nid)
  43. {
  44. int error = 0;
  45. if (node_online(nid)) {
  46. struct pglist_data *pgdat = NODE_DATA(nid);
  47. error = __register_one_node(nid);
  48. if (error)
  49. return error;
  50. /* link memory sections under this node */
  51. error = link_mem_sections(nid, pgdat->node_start_pfn, pgdat->node_spanned_pages);
  52. }
  53. return error;
  54. }
  55. extern void unregister_one_node(int nid);
  56. extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
  57. extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
  58. extern int register_mem_sect_under_node(struct memory_block *mem_blk,
  59. int nid, bool check_nid);
  60. extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
  61. unsigned long phys_index);
  62. #ifdef CONFIG_HUGETLBFS
  63. extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
  64. node_registration_func_t unregister);
  65. #endif
  66. #else
  67. static inline int __register_one_node(int nid)
  68. {
  69. return 0;
  70. }
  71. static inline int register_one_node(int nid)
  72. {
  73. return 0;
  74. }
  75. static inline int unregister_one_node(int nid)
  76. {
  77. return 0;
  78. }
  79. static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
  80. {
  81. return 0;
  82. }
  83. static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
  84. {
  85. return 0;
  86. }
  87. static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
  88. int nid, bool check_nid)
  89. {
  90. return 0;
  91. }
  92. static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
  93. unsigned long phys_index)
  94. {
  95. return 0;
  96. }
  97. static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
  98. node_registration_func_t unreg)
  99. {
  100. }
  101. #endif
  102. #define to_node(device) container_of(device, struct node, dev)
  103. #endif /* _LINUX_NODE_H_ */