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