blob: 4866f32a02d8d4a00d68cdd43fdf3839819c68e7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
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 Torvalds1da177e2005-04-16 15:20:36 -070014 */
15#ifndef _LINUX_NODE_H_
16#define _LINUX_NODE_H_
17
Kay Sievers10fbcf42011-12-21 14:48:43 -080018#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/cpumask.h>
Keith Busch08d9dbe2019-03-11 14:56:00 -060020#include <linux/list.h>
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080021#include <linux/workqueue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Keith Busche1cf33a2019-03-11 14:56:01 -060023/**
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 */
31struct 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
Keith Buschacc02a12019-03-11 14:56:02 -060038enum cache_indexing {
39 NODE_CACHE_DIRECT_MAP,
40 NODE_CACHE_INDEXED,
41 NODE_CACHE_OTHER,
42};
43
44enum cache_write_policy {
45 NODE_CACHE_WRITE_BACK,
46 NODE_CACHE_WRITE_THROUGH,
47 NODE_CACHE_WRITE_OTHER,
48};
49
50/**
51 * struct node_cache_attrs - system memory caching attributes
52 *
53 * @indexing: The ways memory blocks may be placed in cache
54 * @write_policy: Write back or write through policy
55 * @size: Total size of cache in bytes
56 * @line_size: Number of bytes fetched on a cache miss
57 * @level: The cache hierarchy level
58 */
59struct node_cache_attrs {
60 enum cache_indexing indexing;
61 enum cache_write_policy write_policy;
62 u64 size;
63 u16 line_size;
64 u8 level;
65};
66
Keith Busche1cf33a2019-03-11 14:56:01 -060067#ifdef CONFIG_HMEM_REPORTING
Keith Buschacc02a12019-03-11 14:56:02 -060068void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs);
Keith Busche1cf33a2019-03-11 14:56:01 -060069void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
70 unsigned access);
71#else
Keith Buschacc02a12019-03-11 14:56:02 -060072static inline void node_add_cache(unsigned int nid,
73 struct node_cache_attrs *cache_attrs)
74{
75}
76
Keith Busche1cf33a2019-03-11 14:56:01 -060077static inline void node_set_perf_attrs(unsigned int nid,
78 struct node_hmem_attrs *hmem_attrs,
79 unsigned access)
80{
81}
82#endif
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084struct node {
Kay Sievers10fbcf42011-12-21 14:48:43 -080085 struct device dev;
Keith Busch08d9dbe2019-03-11 14:56:00 -060086 struct list_head access_list;
Lee Schermerhorn39da08c2009-12-14 17:58:36 -080087
88#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
89 struct work_struct node_work;
90#endif
Keith Buschacc02a12019-03-11 14:56:02 -060091#ifdef CONFIG_HMEM_REPORTING
92 struct list_head cache_attrs;
93 struct device *cache_dev;
94#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070095};
96
Gary Hadec04fc582009-01-06 14:39:14 -080097struct memory_block;
Wen Congyang87327942012-12-11 16:00:56 -080098extern struct node *node_devices[];
Lee Schermerhorn9a3052302009-12-14 17:58:25 -080099typedef void (*node_registration_func_t)(struct node *);
Yasunori Goto0fc44152006-06-27 02:53:38 -0700100
Michal Hocko9037a992017-07-06 15:37:49 -0700101#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
Jonathan Camerona2155862018-05-25 14:47:53 -0700102extern int link_mem_sections(int nid, unsigned long start_pfn,
Oscar Salvador4fbce632018-08-17 15:46:22 -0700103 unsigned long end_pfn);
Michal Hocko9037a992017-07-06 15:37:49 -0700104#else
Jonathan Camerona2155862018-05-25 14:47:53 -0700105static inline int link_mem_sections(int nid, unsigned long start_pfn,
Oscar Salvador4fbce632018-08-17 15:46:22 -0700106 unsigned long end_pfn)
Michal Hocko9037a992017-07-06 15:37:49 -0700107{
108 return 0;
109}
110#endif
111
Keiichiro Tokunaga4b450992005-05-08 21:28:53 +0900112extern void unregister_node(struct node *node);
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -0700113#ifdef CONFIG_NUMA
Michal Hocko9037a992017-07-06 15:37:49 -0700114/* Core of the node registration - only memory hotplug should use this */
115extern int __register_one_node(int nid);
116
117/* Registers an online node */
118static inline int register_one_node(int nid)
119{
120 int error = 0;
121
122 if (node_online(nid)) {
123 struct pglist_data *pgdat = NODE_DATA(nid);
Oscar Salvador4fbce632018-08-17 15:46:22 -0700124 unsigned long start_pfn = pgdat->node_start_pfn;
125 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
Michal Hocko9037a992017-07-06 15:37:49 -0700126
127 error = __register_one_node(nid);
128 if (error)
129 return error;
130 /* link memory sections under this node */
Oscar Salvador4fbce632018-08-17 15:46:22 -0700131 error = link_mem_sections(nid, start_pfn, end_pfn);
Michal Hocko9037a992017-07-06 15:37:49 -0700132 }
133
134 return error;
135}
136
Yasunori Goto0fc44152006-06-27 02:53:38 -0700137extern void unregister_one_node(int nid);
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700138extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
139extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
David Hildenbranda31b2642019-07-18 15:57:12 -0700140extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800141
Keith Busch08d9dbe2019-03-11 14:56:00 -0600142extern int register_memory_node_under_compute_node(unsigned int mem_nid,
143 unsigned int cpu_nid,
144 unsigned access);
145
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800146#ifdef CONFIG_HUGETLBFS
147extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
148 node_registration_func_t unregister);
149#endif
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700150#else
Michal Hocko9037a992017-07-06 15:37:49 -0700151static inline int __register_one_node(int nid)
152{
153 return 0;
154}
KAMEZAWA Hiroyuki36920e02006-08-27 01:23:52 -0700155static inline int register_one_node(int nid)
156{
157 return 0;
158}
159static inline int unregister_one_node(int nid)
160{
161 return 0;
162}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700163static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
164{
165 return 0;
166}
167static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
168{
169 return 0;
170}
David Hildenbranda31b2642019-07-18 15:57:12 -0700171static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
Gary Hadec04fc582009-01-06 14:39:14 -0800172{
Gary Hadec04fc582009-01-06 14:39:14 -0800173}
Lee Schermerhorn9a3052302009-12-14 17:58:25 -0800174
175static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
176 node_registration_func_t unreg)
177{
178}
KAMEZAWA Hiroyuki76b67ed2006-06-27 02:53:41 -0700179#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Kay Sievers10fbcf42011-12-21 14:48:43 -0800181#define to_node(device) container_of(device, struct node, dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183#endif /* _LINUX_NODE_H_ */