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/cpumask.h>
20 #include <linux/list.h>
21 #include <linux/workqueue.h>
24 * struct node_hmem_attrs - heterogeneous memory performance attributes
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
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;
39 NODE_CACHE_DIRECT_MAP,
44 enum cache_write_policy {
45 NODE_CACHE_WRITE_BACK,
46 NODE_CACHE_WRITE_THROUGH,
47 NODE_CACHE_WRITE_OTHER,
51 * struct node_cache_attrs - system memory caching attributes
53 * @indexing: The ways memory blocks may be placed in cache
54 * @write_policy: Write back or write through policy
55 * @size: Total size of cache in bytes
56 * @line_size: Number of bytes fetched on a cache miss
57 * @level: The cache hierarchy level
59 struct node_cache_attrs {
60 enum cache_indexing indexing;
61 enum cache_write_policy write_policy;
67 #ifdef CONFIG_HMEM_REPORTING
68 void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs);
69 void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
72 static inline void node_add_cache(unsigned int nid,
73 struct node_cache_attrs *cache_attrs)
77 static inline void node_set_perf_attrs(unsigned int nid,
78 struct node_hmem_attrs *hmem_attrs,
86 struct list_head access_list;
88 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_HUGETLBFS)
89 struct work_struct node_work;
91 #ifdef CONFIG_HMEM_REPORTING
92 struct list_head cache_attrs;
93 struct device *cache_dev;
98 extern struct node *node_devices[];
99 typedef void (*node_registration_func_t)(struct node *);
101 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA)
102 void register_memory_blocks_under_node(int nid, unsigned long start_pfn,
103 unsigned long end_pfn,
104 enum meminit_context context);
106 static inline void register_memory_blocks_under_node(int nid, unsigned long start_pfn,
107 unsigned long end_pfn,
108 enum meminit_context context)
113 extern void unregister_node(struct node *node);
115 extern void node_dev_init(void);
116 /* Core of the node registration - only memory hotplug should use this */
117 extern int __register_one_node(int nid);
119 /* Registers an online node */
120 static inline int register_one_node(int nid)
124 if (node_online(nid)) {
125 struct pglist_data *pgdat = NODE_DATA(nid);
126 unsigned long start_pfn = pgdat->node_start_pfn;
127 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
129 error = __register_one_node(nid);
132 register_memory_blocks_under_node(nid, start_pfn, end_pfn,
139 extern void unregister_one_node(int nid);
140 extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
141 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
142 extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
144 extern int register_memory_node_under_compute_node(unsigned int mem_nid,
145 unsigned int cpu_nid,
148 #ifdef CONFIG_HUGETLBFS
149 extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
150 node_registration_func_t unregister);
153 static inline void node_dev_init(void)
156 static inline int __register_one_node(int nid)
160 static inline int register_one_node(int nid)
164 static inline int unregister_one_node(int nid)
168 static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
172 static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
176 static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
180 static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
181 node_registration_func_t unreg)
186 #define to_node(device) container_of(device, struct node, dev)
188 static inline bool node_is_toptier(int node)
190 return node_state(node, N_CPU);
193 #endif /* _LINUX_NODE_H_ */