Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ |
| 15 | #ifndef _LINUX_NODE_H_ |
| 16 | #define _LINUX_NODE_H_ |
| 17 | |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 18 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/cpumask.h> |
Keith Busch | 08d9dbe | 2019-03-11 14:56:00 -0600 | [diff] [blame] | 20 | #include <linux/list.h> |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 21 | #include <linux/workqueue.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Keith Busch | e1cf33a | 2019-03-11 14:56:01 -0600 | [diff] [blame^] | 23 | /** |
| 24 | * struct node_hmem_attrs - heterogeneous memory performance attributes |
| 25 | * |
| 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 |
| 30 | */ |
| 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; |
| 36 | }; |
| 37 | |
| 38 | #ifdef CONFIG_HMEM_REPORTING |
| 39 | void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs, |
| 40 | unsigned access); |
| 41 | #else |
| 42 | static inline void node_set_perf_attrs(unsigned int nid, |
| 43 | struct node_hmem_attrs *hmem_attrs, |
| 44 | unsigned access) |
| 45 | { |
| 46 | } |
| 47 | #endif |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | struct node { |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 50 | struct device dev; |
Keith Busch | 08d9dbe | 2019-03-11 14:56:00 -0600 | [diff] [blame] | 51 | struct list_head access_list; |
Lee Schermerhorn | 39da08c | 2009-12-14 17:58:36 -0800 | [diff] [blame] | 52 | |
| 53 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS) |
| 54 | struct work_struct node_work; |
| 55 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 58 | struct memory_block; |
Wen Congyang | 8732794 | 2012-12-11 16:00:56 -0800 | [diff] [blame] | 59 | extern struct node *node_devices[]; |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 60 | typedef void (*node_registration_func_t)(struct node *); |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 61 | |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 62 | #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA) |
Jonathan Cameron | a215586 | 2018-05-25 14:47:53 -0700 | [diff] [blame] | 63 | extern int link_mem_sections(int nid, unsigned long start_pfn, |
Oscar Salvador | 4fbce63 | 2018-08-17 15:46:22 -0700 | [diff] [blame] | 64 | unsigned long end_pfn); |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 65 | #else |
Jonathan Cameron | a215586 | 2018-05-25 14:47:53 -0700 | [diff] [blame] | 66 | static inline int link_mem_sections(int nid, unsigned long start_pfn, |
Oscar Salvador | 4fbce63 | 2018-08-17 15:46:22 -0700 | [diff] [blame] | 67 | unsigned long end_pfn) |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 68 | { |
| 69 | return 0; |
| 70 | } |
| 71 | #endif |
| 72 | |
Keiichiro Tokunaga | 4b45099 | 2005-05-08 21:28:53 +0900 | [diff] [blame] | 73 | extern void unregister_node(struct node *node); |
KAMEZAWA Hiroyuki | 36920e0 | 2006-08-27 01:23:52 -0700 | [diff] [blame] | 74 | #ifdef CONFIG_NUMA |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 75 | /* Core of the node registration - only memory hotplug should use this */ |
| 76 | extern int __register_one_node(int nid); |
| 77 | |
| 78 | /* Registers an online node */ |
| 79 | static inline int register_one_node(int nid) |
| 80 | { |
| 81 | int error = 0; |
| 82 | |
| 83 | if (node_online(nid)) { |
| 84 | struct pglist_data *pgdat = NODE_DATA(nid); |
Oscar Salvador | 4fbce63 | 2018-08-17 15:46:22 -0700 | [diff] [blame] | 85 | unsigned long start_pfn = pgdat->node_start_pfn; |
| 86 | unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages; |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 87 | |
| 88 | error = __register_one_node(nid); |
| 89 | if (error) |
| 90 | return error; |
| 91 | /* link memory sections under this node */ |
Oscar Salvador | 4fbce63 | 2018-08-17 15:46:22 -0700 | [diff] [blame] | 92 | error = link_mem_sections(nid, start_pfn, end_pfn); |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return error; |
| 96 | } |
| 97 | |
Yasunori Goto | 0fc4415 | 2006-06-27 02:53:38 -0700 | [diff] [blame] | 98 | extern void unregister_one_node(int nid); |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 99 | extern int register_cpu_under_node(unsigned int cpu, unsigned int nid); |
| 100 | extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 101 | extern int register_mem_sect_under_node(struct memory_block *mem_blk, |
Oscar Salvador | 4fbce63 | 2018-08-17 15:46:22 -0700 | [diff] [blame] | 102 | void *arg); |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 103 | extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
| 104 | unsigned long phys_index); |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 105 | |
Keith Busch | 08d9dbe | 2019-03-11 14:56:00 -0600 | [diff] [blame] | 106 | extern int register_memory_node_under_compute_node(unsigned int mem_nid, |
| 107 | unsigned int cpu_nid, |
| 108 | unsigned access); |
| 109 | |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 110 | #ifdef CONFIG_HUGETLBFS |
| 111 | extern void register_hugetlbfs_with_node(node_registration_func_t doregister, |
| 112 | node_registration_func_t unregister); |
| 113 | #endif |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 114 | #else |
Michal Hocko | 9037a99 | 2017-07-06 15:37:49 -0700 | [diff] [blame] | 115 | static inline int __register_one_node(int nid) |
| 116 | { |
| 117 | return 0; |
| 118 | } |
KAMEZAWA Hiroyuki | 36920e0 | 2006-08-27 01:23:52 -0700 | [diff] [blame] | 119 | static inline int register_one_node(int nid) |
| 120 | { |
| 121 | return 0; |
| 122 | } |
| 123 | static inline int unregister_one_node(int nid) |
| 124 | { |
| 125 | return 0; |
| 126 | } |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 127 | static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 128 | { |
| 129 | return 0; |
| 130 | } |
| 131 | static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid) |
| 132 | { |
| 133 | return 0; |
| 134 | } |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 135 | static inline int register_mem_sect_under_node(struct memory_block *mem_blk, |
Oscar Salvador | 4fbce63 | 2018-08-17 15:46:22 -0700 | [diff] [blame] | 136 | void *arg) |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 137 | { |
| 138 | return 0; |
| 139 | } |
Nathan Fontenot | d336016 | 2011-01-20 10:44:29 -0600 | [diff] [blame] | 140 | static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, |
| 141 | unsigned long phys_index) |
Gary Hade | c04fc58 | 2009-01-06 14:39:14 -0800 | [diff] [blame] | 142 | { |
| 143 | return 0; |
| 144 | } |
Lee Schermerhorn | 9a305230 | 2009-12-14 17:58:25 -0800 | [diff] [blame] | 145 | |
| 146 | static inline void register_hugetlbfs_with_node(node_registration_func_t reg, |
| 147 | node_registration_func_t unreg) |
| 148 | { |
| 149 | } |
KAMEZAWA Hiroyuki | 76b67ed | 2006-06-27 02:53:41 -0700 | [diff] [blame] | 150 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Kay Sievers | 10fbcf4 | 2011-12-21 14:48:43 -0800 | [diff] [blame] | 152 | #define to_node(device) container_of(device, struct node, dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | #endif /* _LINUX_NODE_H_ */ |