1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020 Loongson Technology Corporation Limited
4  * Author: lvjianmin <lvjianmin@loongson.cn>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 
11 #ifndef _ASM_LOONGARCH_NUMA_H
12 #define _ASM_LOONGARCH_NUMA_H
13 
14 #include <linux/nodemask.h>
15 
16 #define NODE_ADDRSPACE_SHIFT 44
17 
18 #define pa_to_nid(addr)		(((addr) & 0xf00000000000) >> NODE_ADDRSPACE_SHIFT)
19 #define nid_to_addrbase(nid)	(_ULCAST_(nid) << NODE_ADDRSPACE_SHIFT)
20 
21 #ifdef CONFIG_NUMA
22 
23 extern int numa_off;
24 extern s16 __cpuid_to_node[CONFIG_NR_CPUS];
25 extern nodemask_t numa_nodes_parsed __initdata;
26 
27 struct numa_memblk {
28 	u64			start;
29 	u64			end;
30 	int			nid;
31 };
32 
33 #define NR_NODE_MEMBLKS		(MAX_NUMNODES*2)
34 struct numa_meminfo {
35 	int			nr_blks;
36 	struct numa_memblk	blk[NR_NODE_MEMBLKS];
37 };
38 
39 extern int __init numa_add_memblk(int nodeid, u64 start, u64 end);
40 
41 extern void __init early_numa_add_cpu(int cpuid, s16 node);
42 extern void numa_add_cpu(unsigned int cpu);
43 extern void numa_remove_cpu(unsigned int cpu);
44 
numa_clear_node(int cpu)45 static inline void numa_clear_node(int cpu)
46 {
47 }
48 
set_cpuid_to_node(int cpuid, s16 node)49 static inline void set_cpuid_to_node(int cpuid, s16 node)
50 {
51 	__cpuid_to_node[cpuid] = node;
52 }
53 
54 extern int early_cpu_to_node(int cpu);
55 
56 #else
57 
early_numa_add_cpu(int cpuid, s16 node)58 static inline void early_numa_add_cpu(int cpuid, s16 node)	{ }
numa_add_cpu(unsigned int cpu)59 static inline void numa_add_cpu(unsigned int cpu)		{ }
numa_remove_cpu(unsigned int cpu)60 static inline void numa_remove_cpu(unsigned int cpu)		{ }
61 
early_cpu_to_node(int cpu)62 static inline int early_cpu_to_node(int cpu)
63 {
64 	return 0;
65 }
66 
67 #endif	/* CONFIG_NUMA */
68 
69 #endif	/* _ASM_LOONGARCH_NUMA_H */
70