1992bf775SAneesh Kumar K.V /* SPDX-License-Identifier: GPL-2.0 */
2992bf775SAneesh Kumar K.V #ifndef _LINUX_MEMORY_TIERS_H
3992bf775SAneesh Kumar K.V #define _LINUX_MEMORY_TIERS_H
4992bf775SAneesh Kumar K.V
57b88bda3SAneesh Kumar K.V #include <linux/types.h>
67b88bda3SAneesh Kumar K.V #include <linux/nodemask.h>
77b88bda3SAneesh Kumar K.V #include <linux/kref.h>
832008027SJagdish Gediya #include <linux/mmzone.h>
907a8bdd4SHuang Ying #include <linux/notifier.h>
10992bf775SAneesh Kumar K.V /*
11992bf775SAneesh Kumar K.V * Each tier cover a abstrace distance chunk size of 128
12992bf775SAneesh Kumar K.V */
13992bf775SAneesh Kumar K.V #define MEMTIER_CHUNK_BITS 7
14992bf775SAneesh Kumar K.V #define MEMTIER_CHUNK_SIZE (1 << MEMTIER_CHUNK_BITS)
15992bf775SAneesh Kumar K.V /*
16992bf775SAneesh Kumar K.V * Smaller abstract distance values imply faster (higher) memory tiers. Offset
17992bf775SAneesh Kumar K.V * the DRAM adistance so that we can accommodate devices with a slightly lower
18992bf775SAneesh Kumar K.V * adistance value (slightly faster) than default DRAM adistance to be part of
19992bf775SAneesh Kumar K.V * the same memory tier.
20992bf775SAneesh Kumar K.V */
21992bf775SAneesh Kumar K.V #define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1))
22992bf775SAneesh Kumar K.V
237b88bda3SAneesh Kumar K.V struct memory_tier;
247b88bda3SAneesh Kumar K.V struct memory_dev_type {
257b88bda3SAneesh Kumar K.V /* list of memory types that are part of same tier as this type */
2651a23b1bSLi Zhijian struct list_head tier_sibling;
276bc2cfdfSHuang Ying /* list of memory types that are managed by one driver */
286bc2cfdfSHuang Ying struct list_head list;
297b88bda3SAneesh Kumar K.V /* abstract distance for this specific memory type */
307b88bda3SAneesh Kumar K.V int adistance;
317b88bda3SAneesh Kumar K.V /* Nodes of same abstract distance */
327b88bda3SAneesh Kumar K.V nodemask_t nodes;
337b88bda3SAneesh Kumar K.V struct kref kref;
347b88bda3SAneesh Kumar K.V };
357b88bda3SAneesh Kumar K.V
366a954e94SDave Jiang struct access_coordinate;
373718c02dSHuang Ying
3891952440SAneesh Kumar K.V #ifdef CONFIG_NUMA
3991952440SAneesh Kumar K.V extern bool numa_demotion_enabled;
403718c02dSHuang Ying extern struct memory_dev_type *default_dram_type;
41*823430c8SHo-Ren (Jack) Chuang extern nodemask_t default_dram_nodes;
427b88bda3SAneesh Kumar K.V struct memory_dev_type *alloc_memory_type(int adistance);
43bded67f8SMiaohe Lin void put_memory_type(struct memory_dev_type *memtype);
447b88bda3SAneesh Kumar K.V void init_node_memory_type(int node, struct memory_dev_type *default_type);
457b88bda3SAneesh Kumar K.V void clear_node_memory_type(int node, struct memory_dev_type *memtype);
4607a8bdd4SHuang Ying int register_mt_adistance_algorithm(struct notifier_block *nb);
4707a8bdd4SHuang Ying int unregister_mt_adistance_algorithm(struct notifier_block *nb);
4807a8bdd4SHuang Ying int mt_calc_adistance(int node, int *adist);
496a954e94SDave Jiang int mt_set_default_dram_perf(int nid, struct access_coordinate *perf,
503718c02dSHuang Ying const char *source);
516a954e94SDave Jiang int mt_perf_to_adistance(struct access_coordinate *perf, int *adist);
52a72a30afSHo-Ren (Jack) Chuang struct memory_dev_type *mt_find_alloc_memory_type(int adist,
53a72a30afSHo-Ren (Jack) Chuang struct list_head *memory_types);
54a72a30afSHo-Ren (Jack) Chuang void mt_put_memory_types(struct list_head *memory_types);
556c542ab7SAneesh Kumar K.V #ifdef CONFIG_MIGRATION
566c542ab7SAneesh Kumar K.V int next_demotion_node(int node);
5732008027SJagdish Gediya void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets);
58467b171aSAneesh Kumar K.V bool node_is_toptier(int node);
596c542ab7SAneesh Kumar K.V #else
next_demotion_node(int node)606c542ab7SAneesh Kumar K.V static inline int next_demotion_node(int node)
616c542ab7SAneesh Kumar K.V {
626c542ab7SAneesh Kumar K.V return NUMA_NO_NODE;
636c542ab7SAneesh Kumar K.V }
6432008027SJagdish Gediya
node_get_allowed_targets(pg_data_t * pgdat,nodemask_t * targets)6532008027SJagdish Gediya static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
6632008027SJagdish Gediya {
6732008027SJagdish Gediya *targets = NODE_MASK_NONE;
6832008027SJagdish Gediya }
69467b171aSAneesh Kumar K.V
node_is_toptier(int node)70467b171aSAneesh Kumar K.V static inline bool node_is_toptier(int node)
71467b171aSAneesh Kumar K.V {
72467b171aSAneesh Kumar K.V return true;
73467b171aSAneesh Kumar K.V }
746c542ab7SAneesh Kumar K.V #endif
7591952440SAneesh Kumar K.V
7691952440SAneesh Kumar K.V #else
7791952440SAneesh Kumar K.V
7891952440SAneesh Kumar K.V #define numa_demotion_enabled false
793718c02dSHuang Ying #define default_dram_type NULL
80*823430c8SHo-Ren (Jack) Chuang #define default_dram_nodes NODE_MASK_NONE
817b88bda3SAneesh Kumar K.V /*
827b88bda3SAneesh Kumar K.V * CONFIG_NUMA implementation returns non NULL error.
837b88bda3SAneesh Kumar K.V */
alloc_memory_type(int adistance)847b88bda3SAneesh Kumar K.V static inline struct memory_dev_type *alloc_memory_type(int adistance)
857b88bda3SAneesh Kumar K.V {
867b88bda3SAneesh Kumar K.V return NULL;
877b88bda3SAneesh Kumar K.V }
887b88bda3SAneesh Kumar K.V
put_memory_type(struct memory_dev_type * memtype)89bded67f8SMiaohe Lin static inline void put_memory_type(struct memory_dev_type *memtype)
907b88bda3SAneesh Kumar K.V {
917b88bda3SAneesh Kumar K.V
927b88bda3SAneesh Kumar K.V }
937b88bda3SAneesh Kumar K.V
init_node_memory_type(int node,struct memory_dev_type * default_type)947b88bda3SAneesh Kumar K.V static inline void init_node_memory_type(int node, struct memory_dev_type *default_type)
957b88bda3SAneesh Kumar K.V {
967b88bda3SAneesh Kumar K.V
977b88bda3SAneesh Kumar K.V }
987b88bda3SAneesh Kumar K.V
clear_node_memory_type(int node,struct memory_dev_type * memtype)997b88bda3SAneesh Kumar K.V static inline void clear_node_memory_type(int node, struct memory_dev_type *memtype)
1007b88bda3SAneesh Kumar K.V {
1017b88bda3SAneesh Kumar K.V
1027b88bda3SAneesh Kumar K.V }
1036c542ab7SAneesh Kumar K.V
next_demotion_node(int node)1046c542ab7SAneesh Kumar K.V static inline int next_demotion_node(int node)
1056c542ab7SAneesh Kumar K.V {
1066c542ab7SAneesh Kumar K.V return NUMA_NO_NODE;
1076c542ab7SAneesh Kumar K.V }
10832008027SJagdish Gediya
node_get_allowed_targets(pg_data_t * pgdat,nodemask_t * targets)10932008027SJagdish Gediya static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
11032008027SJagdish Gediya {
11132008027SJagdish Gediya *targets = NODE_MASK_NONE;
11232008027SJagdish Gediya }
113467b171aSAneesh Kumar K.V
node_is_toptier(int node)114467b171aSAneesh Kumar K.V static inline bool node_is_toptier(int node)
115467b171aSAneesh Kumar K.V {
116467b171aSAneesh Kumar K.V return true;
117467b171aSAneesh Kumar K.V }
11807a8bdd4SHuang Ying
register_mt_adistance_algorithm(struct notifier_block * nb)11907a8bdd4SHuang Ying static inline int register_mt_adistance_algorithm(struct notifier_block *nb)
12007a8bdd4SHuang Ying {
12107a8bdd4SHuang Ying return 0;
12207a8bdd4SHuang Ying }
12307a8bdd4SHuang Ying
unregister_mt_adistance_algorithm(struct notifier_block * nb)12407a8bdd4SHuang Ying static inline int unregister_mt_adistance_algorithm(struct notifier_block *nb)
12507a8bdd4SHuang Ying {
12607a8bdd4SHuang Ying return 0;
12707a8bdd4SHuang Ying }
12807a8bdd4SHuang Ying
mt_calc_adistance(int node,int * adist)12907a8bdd4SHuang Ying static inline int mt_calc_adistance(int node, int *adist)
13007a8bdd4SHuang Ying {
13107a8bdd4SHuang Ying return NOTIFY_DONE;
13207a8bdd4SHuang Ying }
1333718c02dSHuang Ying
mt_set_default_dram_perf(int nid,struct access_coordinate * perf,const char * source)1346a954e94SDave Jiang static inline int mt_set_default_dram_perf(int nid, struct access_coordinate *perf,
1353718c02dSHuang Ying const char *source)
1363718c02dSHuang Ying {
1373718c02dSHuang Ying return -EIO;
1383718c02dSHuang Ying }
1393718c02dSHuang Ying
mt_perf_to_adistance(struct access_coordinate * perf,int * adist)1406a954e94SDave Jiang static inline int mt_perf_to_adistance(struct access_coordinate *perf, int *adist)
1413718c02dSHuang Ying {
1423718c02dSHuang Ying return -EIO;
1433718c02dSHuang Ying }
144a72a30afSHo-Ren (Jack) Chuang
mt_find_alloc_memory_type(int adist,struct list_head * memory_types)145a72a30afSHo-Ren (Jack) Chuang static inline struct memory_dev_type *mt_find_alloc_memory_type(int adist,
146a72a30afSHo-Ren (Jack) Chuang struct list_head *memory_types)
147a72a30afSHo-Ren (Jack) Chuang {
148a72a30afSHo-Ren (Jack) Chuang return NULL;
149a72a30afSHo-Ren (Jack) Chuang }
150a72a30afSHo-Ren (Jack) Chuang
mt_put_memory_types(struct list_head * memory_types)151a72a30afSHo-Ren (Jack) Chuang static inline void mt_put_memory_types(struct list_head *memory_types)
152a72a30afSHo-Ren (Jack) Chuang {
153a72a30afSHo-Ren (Jack) Chuang }
15491952440SAneesh Kumar K.V #endif /* CONFIG_NUMA */
155992bf775SAneesh Kumar K.V #endif /* _LINUX_MEMORY_TIERS_H */
156