Merge tag 'backlight-next-6.10' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / include / linux / memory-tiers.h
CommitLineData
992bf775
AK
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_MEMORY_TIERS_H
3#define _LINUX_MEMORY_TIERS_H
4
7b88bda3
AK
5#include <linux/types.h>
6#include <linux/nodemask.h>
7#include <linux/kref.h>
32008027 8#include <linux/mmzone.h>
07a8bdd4 9#include <linux/notifier.h>
992bf775
AK
10/*
11 * Each tier cover a abstrace distance chunk size of 128
12 */
13#define MEMTIER_CHUNK_BITS 7
14#define MEMTIER_CHUNK_SIZE (1 << MEMTIER_CHUNK_BITS)
15/*
16 * Smaller abstract distance values imply faster (higher) memory tiers. Offset
17 * the DRAM adistance so that we can accommodate devices with a slightly lower
18 * adistance value (slightly faster) than default DRAM adistance to be part of
19 * the same memory tier.
20 */
21#define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1))
22
7b88bda3
AK
23struct memory_tier;
24struct memory_dev_type {
25 /* list of memory types that are part of same tier as this type */
51a23b1b 26 struct list_head tier_sibling;
6bc2cfdf
HY
27 /* list of memory types that are managed by one driver */
28 struct list_head list;
7b88bda3
AK
29 /* abstract distance for this specific memory type */
30 int adistance;
31 /* Nodes of same abstract distance */
32 nodemask_t nodes;
33 struct kref kref;
7b88bda3
AK
34};
35
6a954e94 36struct access_coordinate;
3718c02d 37
91952440 38#ifdef CONFIG_NUMA
91952440 39extern bool numa_demotion_enabled;
3718c02d 40extern struct memory_dev_type *default_dram_type;
7b88bda3 41struct memory_dev_type *alloc_memory_type(int adistance);
bded67f8 42void put_memory_type(struct memory_dev_type *memtype);
7b88bda3
AK
43void init_node_memory_type(int node, struct memory_dev_type *default_type);
44void clear_node_memory_type(int node, struct memory_dev_type *memtype);
07a8bdd4
HY
45int register_mt_adistance_algorithm(struct notifier_block *nb);
46int unregister_mt_adistance_algorithm(struct notifier_block *nb);
47int mt_calc_adistance(int node, int *adist);
6a954e94 48int mt_set_default_dram_perf(int nid, struct access_coordinate *perf,
3718c02d 49 const char *source);
6a954e94 50int mt_perf_to_adistance(struct access_coordinate *perf, int *adist);
a72a30af
HRJC
51struct memory_dev_type *mt_find_alloc_memory_type(int adist,
52 struct list_head *memory_types);
53void mt_put_memory_types(struct list_head *memory_types);
6c542ab7
AK
54#ifdef CONFIG_MIGRATION
55int next_demotion_node(int node);
32008027 56void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets);
467b171a 57bool node_is_toptier(int node);
6c542ab7
AK
58#else
59static inline int next_demotion_node(int node)
60{
61 return NUMA_NO_NODE;
62}
32008027
JG
63
64static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
65{
66 *targets = NODE_MASK_NONE;
67}
467b171a
AK
68
69static inline bool node_is_toptier(int node)
70{
71 return true;
72}
6c542ab7 73#endif
91952440
AK
74
75#else
76
77#define numa_demotion_enabled false
3718c02d 78#define default_dram_type NULL
7b88bda3
AK
79/*
80 * CONFIG_NUMA implementation returns non NULL error.
81 */
82static inline struct memory_dev_type *alloc_memory_type(int adistance)
83{
84 return NULL;
85}
86
bded67f8 87static inline void put_memory_type(struct memory_dev_type *memtype)
7b88bda3
AK
88{
89
90}
91
92static inline void init_node_memory_type(int node, struct memory_dev_type *default_type)
93{
94
95}
96
97static inline void clear_node_memory_type(int node, struct memory_dev_type *memtype)
98{
99
100}
6c542ab7
AK
101
102static inline int next_demotion_node(int node)
103{
104 return NUMA_NO_NODE;
105}
32008027
JG
106
107static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
108{
109 *targets = NODE_MASK_NONE;
110}
467b171a
AK
111
112static inline bool node_is_toptier(int node)
113{
114 return true;
115}
07a8bdd4
HY
116
117static inline int register_mt_adistance_algorithm(struct notifier_block *nb)
118{
119 return 0;
120}
121
122static inline int unregister_mt_adistance_algorithm(struct notifier_block *nb)
123{
124 return 0;
125}
126
127static inline int mt_calc_adistance(int node, int *adist)
128{
129 return NOTIFY_DONE;
130}
3718c02d 131
6a954e94 132static inline int mt_set_default_dram_perf(int nid, struct access_coordinate *perf,
3718c02d
HY
133 const char *source)
134{
135 return -EIO;
136}
137
6a954e94 138static inline int mt_perf_to_adistance(struct access_coordinate *perf, int *adist)
3718c02d
HY
139{
140 return -EIO;
141}
a72a30af
HRJC
142
143static inline struct memory_dev_type *mt_find_alloc_memory_type(int adist,
144 struct list_head *memory_types)
145{
146 return NULL;
147}
148
149static inline void mt_put_memory_types(struct list_head *memory_types)
150{
151}
91952440 152#endif /* CONFIG_NUMA */
992bf775 153#endif /* _LINUX_MEMORY_TIERS_H */