1 /* SPDX-License-Identifier: GPL-2.0 */
3 * include/linux/node.h - generic node definition
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.
9 * Basic handling of the devices is done in drivers/base/node.c
10 * and system devices are handled in drivers/base/sys.c.
12 * Nodes are exported via driverfs in the class/node/devices/
15 #ifndef _LINUX_NODE_H_
16 #define _LINUX_NODE_H_
18 #include <linux/device.h>
19 #include <linux/list.h>
22 * struct access_coordinate - generic performance coordinates container
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
29 struct access_coordinate
{
30 unsigned int read_bandwidth
;
31 unsigned int write_bandwidth
;
32 unsigned int read_latency
;
33 unsigned int write_latency
;
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
42 enum access_coordinate_class
{
43 ACCESS_COORDINATE_LOCAL
,
44 ACCESS_COORDINATE_CPU
,
49 NODE_CACHE_DIRECT_MAP
,
54 enum cache_write_policy
{
55 NODE_CACHE_WRITE_BACK
,
56 NODE_CACHE_WRITE_THROUGH
,
57 NODE_CACHE_WRITE_OTHER
,
61 NODE_CACHE_ADDR_MODE_RESERVED
,
62 NODE_CACHE_ADDR_MODE_EXTENDED_LINEAR
,
66 * struct node_cache_attrs - system memory caching attributes
68 * @indexing: The ways memory blocks may be placed in cache
69 * @write_policy: Write back or write through policy
70 * @size: Total size of cache in bytes
71 * @line_size: Number of bytes fetched on a cache miss
72 * @level: The cache hierarchy level
73 * @address_mode: The address mode
75 struct node_cache_attrs
{
76 enum cache_indexing indexing
;
77 enum cache_write_policy write_policy
;
84 #ifdef CONFIG_HMEM_REPORTING
85 void node_add_cache(unsigned int nid
, struct node_cache_attrs
*cache_attrs
);
86 void node_set_perf_attrs(unsigned int nid
, struct access_coordinate
*coord
,
87 enum access_coordinate_class access
);
88 void node_update_perf_attrs(unsigned int nid
, struct access_coordinate
*coord
,
89 enum access_coordinate_class access
);
91 static inline void node_add_cache(unsigned int nid
,
92 struct node_cache_attrs
*cache_attrs
)
96 static inline void node_set_perf_attrs(unsigned int nid
,
97 struct access_coordinate
*coord
,
98 enum access_coordinate_class access
)
102 static inline void node_update_perf_attrs(unsigned int nid
,
103 struct access_coordinate
*coord
,
104 enum access_coordinate_class access
)
111 struct list_head access_list
;
112 #ifdef CONFIG_HMEM_REPORTING
113 struct list_head cache_attrs
;
114 struct device
*cache_dev
;
119 extern struct node
*node_devices
[];
121 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA)
122 void register_memory_blocks_under_node_hotplug(int nid
, unsigned long start_pfn
,
123 unsigned long end_pfn
);
125 static inline void register_memory_blocks_under_node_hotplug(int nid
,
126 unsigned long start_pfn
,
127 unsigned long end_pfn
)
130 static inline void register_memory_blocks_under_nodes(void)
139 #define NODE_ADDING_FIRST_MEMORY (1<<0)
140 #define NODE_ADDED_FIRST_MEMORY (1<<1)
141 #define NODE_CANCEL_ADDING_FIRST_MEMORY (1<<2)
142 #define NODE_REMOVING_LAST_MEMORY (1<<3)
143 #define NODE_REMOVED_LAST_MEMORY (1<<4)
144 #define NODE_CANCEL_REMOVING_LAST_MEMORY (1<<5)
146 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA)
147 extern int register_node_notifier(struct notifier_block
*nb
);
148 extern void unregister_node_notifier(struct notifier_block
*nb
);
149 extern int node_notify(unsigned long val
, void *v
);
151 #define hotplug_node_notifier(fn, pri) ({ \
152 static __meminitdata struct notifier_block fn##_node_nb =\
153 { .notifier_call = fn, .priority = pri };\
154 register_node_notifier(&fn##_node_nb); \
157 static inline int register_node_notifier(struct notifier_block
*nb
)
161 static inline void unregister_node_notifier(struct notifier_block
*nb
)
164 static inline int node_notify(unsigned long val
, void *v
)
168 static inline int hotplug_node_notifier(notifier_fn_t fn
, int pri
)
175 extern void node_dev_init(void);
176 /* Core of the node registration - only memory hotplug should use this */
177 int register_node(int nid
);
178 void unregister_node(int nid
);
179 extern int register_cpu_under_node(unsigned int cpu
, unsigned int nid
);
180 extern int unregister_cpu_under_node(unsigned int cpu
, unsigned int nid
);
181 extern void unregister_memory_block_under_nodes(struct memory_block
*mem_blk
);
183 extern int register_memory_node_under_compute_node(unsigned int mem_nid
,
184 unsigned int cpu_nid
,
185 enum access_coordinate_class access
);
187 static inline void node_dev_init(void)
190 static inline int register_node(int nid
)
194 static inline int unregister_node(int nid
)
198 static inline int register_cpu_under_node(unsigned int cpu
, unsigned int nid
)
202 static inline int unregister_cpu_under_node(unsigned int cpu
, unsigned int nid
)
206 static inline void unregister_memory_block_under_nodes(struct memory_block
*mem_blk
)
211 #define to_node(device) container_of(device, struct node, dev)
213 #endif /* _LINUX_NODE_H_ */