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 18 #include <linux/device.h> 19 #include <linux/cpumask.h> 20 #include <linux/list.h> 21 #include <linux/workqueue.h> 22 23 struct node { 24 struct device dev; 25 struct list_head access_list; 26 27 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS) 28 struct work_struct node_work; 29 #endif 30 }; 31 32 struct memory_block; 33 extern struct node *node_devices[]; 34 typedef void (*node_registration_func_t)(struct node *); 35 36 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA) 37 extern int link_mem_sections(int nid, unsigned long start_pfn, 38 unsigned long end_pfn); 39 #else 40 static inline int link_mem_sections(int nid, unsigned long start_pfn, 41 unsigned long end_pfn) 42 { 43 return 0; 44 } 45 #endif 46 47 extern void unregister_node(struct node *node); 48 #ifdef CONFIG_NUMA 49 /* Core of the node registration - only memory hotplug should use this */ 50 extern int __register_one_node(int nid); 51 52 /* Registers an online node */ 53 static inline int register_one_node(int nid) 54 { 55 int error = 0; 56 57 if (node_online(nid)) { 58 struct pglist_data *pgdat = NODE_DATA(nid); 59 unsigned long start_pfn = pgdat->node_start_pfn; 60 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages; 61 62 error = __register_one_node(nid); 63 if (error) 64 return error; 65 /* link memory sections under this node */ 66 error = link_mem_sections(nid, start_pfn, end_pfn); 67 } 68 69 return error; 70 } 71 72 extern void unregister_one_node(int nid); 73 extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); 74 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 75 extern int register_mem_sect_under_node(struct memory_block *mem_blk, 76 void *arg); 77 extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 78 unsigned long phys_index); 79 80 extern int register_memory_node_under_compute_node(unsigned int mem_nid, 81 unsigned int cpu_nid, 82 unsigned access); 83 84 #ifdef CONFIG_HUGETLBFS 85 extern void register_hugetlbfs_with_node(node_registration_func_t doregister, 86 node_registration_func_t unregister); 87 #endif 88 #else 89 static inline int __register_one_node(int nid) 90 { 91 return 0; 92 } 93 static inline int register_one_node(int nid) 94 { 95 return 0; 96 } 97 static inline int unregister_one_node(int nid) 98 { 99 return 0; 100 } 101 static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) 102 { 103 return 0; 104 } 105 static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) 106 { 107 return 0; 108 } 109 static inline int register_mem_sect_under_node(struct memory_block *mem_blk, 110 void *arg) 111 { 112 return 0; 113 } 114 static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 115 unsigned long phys_index) 116 { 117 return 0; 118 } 119 120 static inline void register_hugetlbfs_with_node(node_registration_func_t reg, 121 node_registration_func_t unreg) 122 { 123 } 124 #endif 125 126 #define to_node(device) container_of(device, struct node, dev) 127 128 #endif /* _LINUX_NODE_H_ */ 129