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 enum cache_mode { 61 NODE_CACHE_ADDR_MODE_RESERVED, 62 NODE_CACHE_ADDR_MODE_EXTENDED_LINEAR, 63 }; 64 65 /** 66 * struct node_cache_attrs - system memory caching attributes 67 * 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 74 */ 75 struct node_cache_attrs { 76 enum cache_indexing indexing; 77 enum cache_write_policy write_policy; 78 u64 size; 79 u16 line_size; 80 u8 level; 81 u16 address_mode; 82 }; 83 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 #else 89 static inline void node_add_cache(unsigned int nid, 90 struct node_cache_attrs *cache_attrs) 91 { 92 } 93 94 static inline void node_set_perf_attrs(unsigned int nid, 95 struct access_coordinate *coord, 96 enum access_coordinate_class access) 97 { 98 } 99 #endif 100 101 struct node { 102 struct device dev; 103 struct list_head access_list; 104 #ifdef CONFIG_HMEM_REPORTING 105 struct list_head cache_attrs; 106 struct device *cache_dev; 107 #endif 108 }; 109 110 struct memory_block; 111 extern struct node *node_devices[]; 112 113 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA) 114 void register_memory_blocks_under_node_hotplug(int nid, unsigned long start_pfn, 115 unsigned long end_pfn); 116 #else 117 static inline void register_memory_blocks_under_node_hotplug(int nid, 118 unsigned long start_pfn, 119 unsigned long end_pfn) 120 { 121 } 122 static inline void register_memory_blocks_under_nodes(void) 123 { 124 } 125 #endif 126 127 extern void unregister_node(struct node *node); 128 129 struct node_notify { 130 int nid; 131 }; 132 133 #define NODE_ADDING_FIRST_MEMORY (1<<0) 134 #define NODE_ADDED_FIRST_MEMORY (1<<1) 135 #define NODE_CANCEL_ADDING_FIRST_MEMORY (1<<2) 136 #define NODE_REMOVING_LAST_MEMORY (1<<3) 137 #define NODE_REMOVED_LAST_MEMORY (1<<4) 138 #define NODE_CANCEL_REMOVING_LAST_MEMORY (1<<5) 139 140 #if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA) 141 extern int register_node_notifier(struct notifier_block *nb); 142 extern void unregister_node_notifier(struct notifier_block *nb); 143 extern int node_notify(unsigned long val, void *v); 144 145 #define hotplug_node_notifier(fn, pri) ({ \ 146 static __meminitdata struct notifier_block fn##_node_nb =\ 147 { .notifier_call = fn, .priority = pri };\ 148 register_node_notifier(&fn##_node_nb); \ 149 }) 150 #else 151 static inline int register_node_notifier(struct notifier_block *nb) 152 { 153 return 0; 154 } 155 static inline void unregister_node_notifier(struct notifier_block *nb) 156 { 157 } 158 static inline int node_notify(unsigned long val, void *v) 159 { 160 return 0; 161 } 162 static inline int hotplug_node_notifier(notifier_fn_t fn, int pri) 163 { 164 return 0; 165 } 166 #endif 167 168 #ifdef CONFIG_NUMA 169 extern void node_dev_init(void); 170 /* Core of the node registration - only memory hotplug should use this */ 171 extern int register_one_node(int nid); 172 extern void unregister_one_node(int nid); 173 extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); 174 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 175 extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk); 176 177 extern int register_memory_node_under_compute_node(unsigned int mem_nid, 178 unsigned int cpu_nid, 179 enum access_coordinate_class access); 180 #else 181 static inline void node_dev_init(void) 182 { 183 } 184 static inline int register_one_node(int nid) 185 { 186 return 0; 187 } 188 static inline int unregister_one_node(int nid) 189 { 190 return 0; 191 } 192 static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) 193 { 194 return 0; 195 } 196 static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) 197 { 198 return 0; 199 } 200 static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk) 201 { 202 } 203 #endif 204 205 #define to_node(device) container_of(device, struct node, dev) 206 207 #endif /* _LINUX_NODE_H_ */ 208