at v6.18-rc2 5.8 kB view raw
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 */ 29struct 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 */ 42enum access_coordinate_class { 43 ACCESS_COORDINATE_LOCAL, 44 ACCESS_COORDINATE_CPU, 45 ACCESS_COORDINATE_MAX 46}; 47 48enum cache_indexing { 49 NODE_CACHE_DIRECT_MAP, 50 NODE_CACHE_INDEXED, 51 NODE_CACHE_OTHER, 52}; 53 54enum cache_write_policy { 55 NODE_CACHE_WRITE_BACK, 56 NODE_CACHE_WRITE_THROUGH, 57 NODE_CACHE_WRITE_OTHER, 58}; 59 60enum 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 */ 75struct 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 85void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs); 86void node_set_perf_attrs(unsigned int nid, struct access_coordinate *coord, 87 enum access_coordinate_class access); 88void node_update_perf_attrs(unsigned int nid, struct access_coordinate *coord, 89 enum access_coordinate_class access); 90#else 91static inline void node_add_cache(unsigned int nid, 92 struct node_cache_attrs *cache_attrs) 93{ 94} 95 96static inline void node_set_perf_attrs(unsigned int nid, 97 struct access_coordinate *coord, 98 enum access_coordinate_class access) 99{ 100} 101 102static inline void node_update_perf_attrs(unsigned int nid, 103 struct access_coordinate *coord, 104 enum access_coordinate_class access) 105{ 106} 107#endif 108 109struct node { 110 struct device dev; 111 struct list_head access_list; 112#ifdef CONFIG_HMEM_REPORTING 113 struct list_head cache_attrs; 114 struct device *cache_dev; 115#endif 116}; 117 118struct memory_block; 119extern struct node *node_devices[]; 120 121#if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA) 122void register_memory_blocks_under_node_hotplug(int nid, unsigned long start_pfn, 123 unsigned long end_pfn); 124#else 125static inline void register_memory_blocks_under_node_hotplug(int nid, 126 unsigned long start_pfn, 127 unsigned long end_pfn) 128{ 129} 130static inline void register_memory_blocks_under_nodes(void) 131{ 132} 133#endif 134 135extern void unregister_node(struct node *node); 136 137struct node_notify { 138 int nid; 139}; 140 141#define NODE_ADDING_FIRST_MEMORY (1<<0) 142#define NODE_ADDED_FIRST_MEMORY (1<<1) 143#define NODE_CANCEL_ADDING_FIRST_MEMORY (1<<2) 144#define NODE_REMOVING_LAST_MEMORY (1<<3) 145#define NODE_REMOVED_LAST_MEMORY (1<<4) 146#define NODE_CANCEL_REMOVING_LAST_MEMORY (1<<5) 147 148#if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA) 149extern int register_node_notifier(struct notifier_block *nb); 150extern void unregister_node_notifier(struct notifier_block *nb); 151extern int node_notify(unsigned long val, void *v); 152 153#define hotplug_node_notifier(fn, pri) ({ \ 154 static __meminitdata struct notifier_block fn##_node_nb =\ 155 { .notifier_call = fn, .priority = pri };\ 156 register_node_notifier(&fn##_node_nb); \ 157}) 158#else 159static inline int register_node_notifier(struct notifier_block *nb) 160{ 161 return 0; 162} 163static inline void unregister_node_notifier(struct notifier_block *nb) 164{ 165} 166static inline int node_notify(unsigned long val, void *v) 167{ 168 return 0; 169} 170static inline int hotplug_node_notifier(notifier_fn_t fn, int pri) 171{ 172 return 0; 173} 174#endif 175 176#ifdef CONFIG_NUMA 177extern void node_dev_init(void); 178/* Core of the node registration - only memory hotplug should use this */ 179extern int register_one_node(int nid); 180extern void unregister_one_node(int nid); 181extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); 182extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 183extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk); 184 185extern int register_memory_node_under_compute_node(unsigned int mem_nid, 186 unsigned int cpu_nid, 187 enum access_coordinate_class access); 188#else 189static inline void node_dev_init(void) 190{ 191} 192static inline int register_one_node(int nid) 193{ 194 return 0; 195} 196static inline int unregister_one_node(int nid) 197{ 198 return 0; 199} 200static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) 201{ 202 return 0; 203} 204static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) 205{ 206 return 0; 207} 208static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk) 209{ 210} 211#endif 212 213#define to_node(device) container_of(device, struct node, dev) 214 215#endif /* _LINUX_NODE_H_ */