xref: /linux/include/linux/node.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
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/list.h>
20 
21 /**
22  * struct access_coordinate - generic performance coordinates container
23  *
24  * @read_bandwidth:	Read bandwidth in MB/s
25  * @write_bandwidth:	Write bandwidth in MB/s
26  * @read_latency:	Read latency in nanoseconds
27  * @write_latency:	Write latency in nanoseconds
28  */
29 struct access_coordinate {
30 	unsigned int read_bandwidth;
31 	unsigned int write_bandwidth;
32 	unsigned int read_latency;
33 	unsigned int write_latency;
34 };
35 
36 /*
37  * ACCESS_COORDINATE_LOCAL correlates to ACCESS CLASS 0
38  *	- access_coordinate between target node and nearest initiator node
39  * ACCESS_COORDINATE_CPU correlates to ACCESS CLASS 1
40  *	- access_coordinate between target node and nearest CPU node
41  */
42 enum access_coordinate_class {
43 	ACCESS_COORDINATE_LOCAL,
44 	ACCESS_COORDINATE_CPU,
45 	ACCESS_COORDINATE_MAX
46 };
47 
48 enum cache_indexing {
49 	NODE_CACHE_DIRECT_MAP,
50 	NODE_CACHE_INDEXED,
51 	NODE_CACHE_OTHER,
52 };
53 
54 enum cache_write_policy {
55 	NODE_CACHE_WRITE_BACK,
56 	NODE_CACHE_WRITE_THROUGH,
57 	NODE_CACHE_WRITE_OTHER,
58 };
59 
60 /**
61  * struct node_cache_attrs - system memory caching attributes
62  *
63  * @indexing:		The ways memory blocks may be placed in cache
64  * @write_policy:	Write back or write through policy
65  * @size:		Total size of cache in bytes
66  * @line_size:		Number of bytes fetched on a cache miss
67  * @level:		The cache hierarchy level
68  */
69 struct node_cache_attrs {
70 	enum cache_indexing indexing;
71 	enum cache_write_policy write_policy;
72 	u64 size;
73 	u16 line_size;
74 	u8 level;
75 };
76 
77 #ifdef CONFIG_HMEM_REPORTING
78 void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs);
79 void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord,
80 			 enum access_coordinate_class access);
81 #else
node_add_cache(unsigned int nid,struct node_cache_attrs * cache_attrs)82 static inline void node_add_cache(unsigned int nid,
83 				  struct node_cache_attrs *cache_attrs)
84 {
85 }
86 
node_set_perf_attrs(unsigned int nid,struct access_coordinate * coord,enum access_coordinate_class access)87 static inline void node_set_perf_attrs(unsigned int nid,
88 				       struct access_coordinate *coord,
89 				       enum access_coordinate_class access)
90 {
91 }
92 #endif
93 
94 struct node {
95 	struct device	dev;
96 	struct list_head access_list;
97 #ifdef CONFIG_HMEM_REPORTING
98 	struct list_head cache_attrs;
99 	struct device *cache_dev;
100 #endif
101 };
102 
103 struct memory_block;
104 extern struct node *node_devices[];
105 
106 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA)
107 void register_memory_blocks_under_node(int nid, unsigned long start_pfn,
108 				       unsigned long end_pfn,
109 				       enum meminit_context context);
110 #else
register_memory_blocks_under_node(int nid,unsigned long start_pfn,unsigned long end_pfn,enum meminit_context context)111 static inline void register_memory_blocks_under_node(int nid, unsigned long start_pfn,
112 						     unsigned long end_pfn,
113 						     enum meminit_context context)
114 {
115 }
116 #endif
117 
118 extern void unregister_node(struct node *node);
119 #ifdef CONFIG_NUMA
120 extern void node_dev_init(void);
121 /* Core of the node registration - only memory hotplug should use this */
122 extern int __register_one_node(int nid);
123 
124 /* Registers an online node */
register_one_node(int nid)125 static inline int register_one_node(int nid)
126 {
127 	int error = 0;
128 
129 	if (node_online(nid)) {
130 		struct pglist_data *pgdat = NODE_DATA(nid);
131 		unsigned long start_pfn = pgdat->node_start_pfn;
132 		unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
133 
134 		error = __register_one_node(nid);
135 		if (error)
136 			return error;
137 		register_memory_blocks_under_node(nid, start_pfn, end_pfn,
138 						  MEMINIT_EARLY);
139 	}
140 
141 	return error;
142 }
143 
144 extern void unregister_one_node(int nid);
145 extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
146 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
147 extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
148 
149 extern int register_memory_node_under_compute_node(unsigned int mem_nid,
150 						   unsigned int cpu_nid,
151 						   enum access_coordinate_class access);
152 #else
node_dev_init(void)153 static inline void node_dev_init(void)
154 {
155 }
__register_one_node(int nid)156 static inline int __register_one_node(int nid)
157 {
158 	return 0;
159 }
register_one_node(int nid)160 static inline int register_one_node(int nid)
161 {
162 	return 0;
163 }
unregister_one_node(int nid)164 static inline int unregister_one_node(int nid)
165 {
166 	return 0;
167 }
register_cpu_under_node(unsigned int cpu,unsigned int nid)168 static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
169 {
170 	return 0;
171 }
unregister_cpu_under_node(unsigned int cpu,unsigned int nid)172 static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
173 {
174 	return 0;
175 }
unregister_memory_block_under_nodes(struct memory_block * mem_blk)176 static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
177 {
178 }
179 #endif
180 
181 #define to_node(device) container_of(device, struct node, dev)
182 
183 #endif /* _LINUX_NODE_H_ */
184