blob: 014ba3ab2efd8b7b7b1dc58b0d9e9d63bf3d1e90 [file] [log] [blame]
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00001/* 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/cpumask.h>
David Brazdil0f672f62019-12-10 10:32:29 +000020#include <linux/list.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000021#include <linux/workqueue.h>
22
David Brazdil0f672f62019-12-10 10:32:29 +000023/**
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
38enum 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
67#ifdef CONFIG_HMEM_REPORTING
68void node_add_cache(unsigned int nid, struct node_cache_attrs *cache_attrs);
69void node_set_perf_attrs(unsigned int nid, struct node_hmem_attrs *hmem_attrs,
70 unsigned access);
71#else
72static inline void node_add_cache(unsigned int nid,
73 struct node_cache_attrs *cache_attrs)
74{
75}
76
77static inline void node_set_perf_attrs(unsigned int nid,
78 struct node_hmem_attrs *hmem_attrs,
79 unsigned access)
80{
81}
82#endif
83
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000084struct node {
85 struct device dev;
David Brazdil0f672f62019-12-10 10:32:29 +000086 struct list_head access_list;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000087
88#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_HUGETLBFS)
89 struct work_struct node_work;
90#endif
David Brazdil0f672f62019-12-10 10:32:29 +000091#ifdef CONFIG_HMEM_REPORTING
92 struct list_head cache_attrs;
93 struct device *cache_dev;
94#endif
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000095};
96
97struct memory_block;
98extern struct node *node_devices[];
99typedef void (*node_registration_func_t)(struct node *);
100
101#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
Olivier Deprez0e641232021-09-23 10:07:05 +0200102int link_mem_sections(int nid, unsigned long start_pfn,
103 unsigned long end_pfn,
104 enum meminit_context context);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000105#else
106static inline int link_mem_sections(int nid, unsigned long start_pfn,
Olivier Deprez0e641232021-09-23 10:07:05 +0200107 unsigned long end_pfn,
108 enum meminit_context context)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000109{
110 return 0;
111}
112#endif
113
114extern void unregister_node(struct node *node);
115#ifdef CONFIG_NUMA
116/* Core of the node registration - only memory hotplug should use this */
117extern int __register_one_node(int nid);
118
119/* Registers an online node */
120static inline int register_one_node(int nid)
121{
122 int error = 0;
123
124 if (node_online(nid)) {
125 struct pglist_data *pgdat = NODE_DATA(nid);
126 unsigned long start_pfn = pgdat->node_start_pfn;
127 unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
128
129 error = __register_one_node(nid);
130 if (error)
131 return error;
132 /* link memory sections under this node */
Olivier Deprez0e641232021-09-23 10:07:05 +0200133 error = link_mem_sections(nid, start_pfn, end_pfn,
134 MEMINIT_EARLY);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000135 }
136
137 return error;
138}
139
140extern void unregister_one_node(int nid);
141extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
142extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
David Brazdil0f672f62019-12-10 10:32:29 +0000143extern void unregister_memory_block_under_nodes(struct memory_block *mem_blk);
144
145extern int register_memory_node_under_compute_node(unsigned int mem_nid,
146 unsigned int cpu_nid,
147 unsigned access);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000148
149#ifdef CONFIG_HUGETLBFS
150extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
151 node_registration_func_t unregister);
152#endif
153#else
154static inline int __register_one_node(int nid)
155{
156 return 0;
157}
158static inline int register_one_node(int nid)
159{
160 return 0;
161}
162static inline int unregister_one_node(int nid)
163{
164 return 0;
165}
166static inline int register_cpu_under_node(unsigned int cpu, unsigned int nid)
167{
168 return 0;
169}
170static inline int unregister_cpu_under_node(unsigned int cpu, unsigned int nid)
171{
172 return 0;
173}
David Brazdil0f672f62019-12-10 10:32:29 +0000174static inline void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000175{
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000176}
177
178static inline void register_hugetlbfs_with_node(node_registration_func_t reg,
179 node_registration_func_t unreg)
180{
181}
182#endif
183
184#define to_node(device) container_of(device, struct node, dev)
185
186#endif /* _LINUX_NODE_H_ */