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/workqueue.h>
21
22 struct node {
23 struct device dev;
24
25 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
26 struct work_struct node_work;
27 #endif
28 };
29
30 struct memory_block;
31 extern struct node *node_devices[];
32 typedef void (*node_registration_func_t)(struct node *);
33
34 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
35 int link_mem_sections(int nid, unsigned long start_pfn,
36 unsigned long end_pfn,
37 enum meminit_context context);
38 #else
link_mem_sections(int nid,unsigned long start_pfn,unsigned long end_pfn,enum meminit_context context)39 static inline int link_mem_sections(int nid, unsigned long start_pfn,
40 unsigned long end_pfn,
41 enum meminit_context context)
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 */
register_one_node(int nid)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 MEMINIT_EARLY);
68 }
69
70 return error;
71 }
72
73 extern void unregister_one_node(int nid);
74 extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
75 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
76 extern int register_mem_sect_under_node(struct memory_block *mem_blk,
77 void *arg);
78 extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
79
80 #ifdef CONFIG_HUGETLBFS
81 extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
82 node_registration_func_t unregister);
83 #endif
84 #else
__register_one_node(int nid)85 static inline int __register_one_node(int nid)
86 {
87 return 0;
88 }
register_one_node(int nid)89 static inline int register_one_node(int nid)
90 {
91 return 0;
92 }
unregister_one_node(int nid)93 static inline int unregister_one_node(int nid)
94 {
95 return 0;
96 }
register_cpu_under_node(unsigned int cpu,unsigned int nid)97 static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
98 {
99 return 0;
100 }
unregister_cpu_under_node(unsigned int cpu,unsigned int nid)101 static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
102 {
103 return 0;
104 }
register_mem_sect_under_node(struct memory_block * mem_blk,void * arg)105 static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
106 void *arg)
107 {
108 return 0;
109 }
unregister_memory_block_under_nodes(struct memory_block * mem_blk)110 static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
111 {
112 }
113
register_hugetlbfs_with_node(node_registration_func_t reg,node_registration_func_t unreg)114 static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
115 node_registration_func_t unreg)
116 {
117 }
118 #endif
119
120 #define to_node(device) container_of(device, struct node, dev)
121
122 #endif /* _LINUX_NODE_H_ */
123