xref: /linux-6.15/include/linux/node.h (revision e1cf33aa)
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 /**
24  * struct node_hmem_attrs - heterogeneous memory performance attributes
25  *
26  * @read_bandwidth:	Read bandwidth in MB/s
27  * @write_bandwidth:	Write bandwidth in MB/s
28  * @read_latency:	Read latency in nanoseconds
29  * @write_latency:	Write latency in nanoseconds
30  */
31 struct node_hmem_attrs {
32 	unsigned int read_bandwidth;
33 	unsigned int write_bandwidth;
34 	unsigned int read_latency;
35 	unsigned int write_latency;
36 };
37 
38 #ifdef CONFIG_HMEM_REPORTING
39 void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
40 			 unsigned access);
41 #else
42 static inline void node_set_perf_attrs(unsigned int nid,
43 				       struct node_hmem_attrs *hmem_attrs,
44 				       unsigned access)
45 {
46 }
47 #endif
48 
49 struct node {
50 	struct device	dev;
51 	struct list_head access_list;
52 
53 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
54 	struct work_struct	node_work;
55 #endif
56 };
57 
58 struct memory_block;
59 extern struct node *node_devices[];
60 typedef  void (*node_registration_func_t)(struct node *);
61 
62 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
63 extern int link_mem_sections(int nid, unsigned long start_pfn,
64 			     unsigned long end_pfn);
65 #else
66 static inline int link_mem_sections(int nid, unsigned long start_pfn,
67 				    unsigned long end_pfn)
68 {
69 	return 0;
70 }
71 #endif
72 
73 extern void unregister_node(struct node *node);
74 #ifdef CONFIG_NUMA
75 /* Core of the node registration - only memory hotplug should use this */
76 extern int __register_one_node(int nid);
77 
78 /* Registers an online node */
79 static inline int register_one_node(int nid)
80 {
81 	int error = 0;
82 
83 	if (node_online(nid)) {
84 		struct pglist_data *pgdat = NODE_DATA(nid);
85 		unsigned long start_pfn = pgdat->node_start_pfn;
86 		unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
87 
88 		error = __register_one_node(nid);
89 		if (error)
90 			return error;
91 		/* link memory sections under this node */
92 		error = link_mem_sections(nid, start_pfn, end_pfn);
93 	}
94 
95 	return error;
96 }
97 
98 extern void unregister_one_node(int nid);
99 extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
100 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
101 extern int register_mem_sect_under_node(struct memory_block *mem_blk,
102 						void *arg);
103 extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
104 					   unsigned long phys_index);
105 
106 extern int register_memory_node_under_compute_node(unsigned int mem_nid,
107 						   unsigned int cpu_nid,
108 						   unsigned access);
109 
110 #ifdef CONFIG_HUGETLBFS
111 extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
112 					 node_registration_func_t unregister);
113 #endif
114 #else
115 static inline int __register_one_node(int nid)
116 {
117 	return 0;
118 }
119 static inline int register_one_node(int nid)
120 {
121 	return 0;
122 }
123 static inline int unregister_one_node(int nid)
124 {
125 	return 0;
126 }
127 static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
128 {
129 	return 0;
130 }
131 static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
132 {
133 	return 0;
134 }
135 static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
136 							void *arg)
137 {
138 	return 0;
139 }
140 static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
141 						  unsigned long phys_index)
142 {
143 	return 0;
144 }
145 
146 static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
147 						node_registration_func_t unreg)
148 {
149 }
150 #endif
151 
152 #define to_node(device) container_of(device, struct node, dev)
153 
154 #endif /* _LINUX_NODE_H_ */
155