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