at v6.16 4.9 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); 88#else 89static inline void node_add_cache(unsigned int nid, 90 struct node_cache_attrs *cache_attrs) 91{ 92} 93 94static 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 101struct 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 110struct memory_block; 111extern struct node *node_devices[]; 112 113#if defined(CONFIG_MEMORY_HOTPLUG) && defined(CONFIG_NUMA) 114void register_memory_blocks_under_node(int nid, unsigned long start_pfn, 115 unsigned long end_pfn, 116 enum meminit_context context); 117#else 118static inline void register_memory_blocks_under_node(int nid, unsigned long start_pfn, 119 unsigned long end_pfn, 120 enum meminit_context context) 121{ 122} 123#endif 124 125extern void unregister_node(struct node *node); 126#ifdef CONFIG_NUMA 127extern void node_dev_init(void); 128/* Core of the node registration - only memory hotplug should use this */ 129extern int __register_one_node(int nid); 130 131/* Registers an online node */ 132static inline int register_one_node(int nid) 133{ 134 int error = 0; 135 136 if (node_online(nid)) { 137 struct pglist_data *pgdat = NODE_DATA(nid); 138 unsigned long start_pfn = pgdat->node_start_pfn; 139 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages; 140 141 error = __register_one_node(nid); 142 if (error) 143 return error; 144 register_memory_blocks_under_node(nid, start_pfn, end_pfn, 145 MEMINIT_EARLY); 146 } 147 148 return error; 149} 150 151extern void unregister_one_node(int nid); 152extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); 153extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 154extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk); 155 156extern int register_memory_node_under_compute_node(unsigned int mem_nid, 157 unsigned int cpu_nid, 158 enum access_coordinate_class access); 159#else 160static inline void node_dev_init(void) 161{ 162} 163static inline int __register_one_node(int nid) 164{ 165 return 0; 166} 167static inline int register_one_node(int nid) 168{ 169 return 0; 170} 171static inline int unregister_one_node(int nid) 172{ 173 return 0; 174} 175static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) 176{ 177 return 0; 178} 179static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) 180{ 181 return 0; 182} 183static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk) 184{ 185} 186#endif 187 188#define to_node(device) container_of(device, struct node, dev) 189 190#endif /* _LINUX_NODE_H_ */