xref: /openbmc/linux/arch/ia64/mm/numa.c (revision aeefc1a0)
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * This file contains NUMA specific variables and functions which can
7  * be split away from DISCONTIGMEM and are used on NUMA machines with
8  * contiguous memory.
9  *
10  *                         2002/08/07 Erich Focht <efocht@ess.nec.de>
11  */
12 
13 #include <linux/cpu.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/node.h>
17 #include <linux/init.h>
18 #include <linux/memblock.h>
19 #include <linux/module.h>
20 #include <asm/mmzone.h>
21 #include <asm/numa.h>
22 
23 
24 /*
25  * The following structures are usually initialized by ACPI or
26  * similar mechanisms and describe the NUMA characteristics of the machine.
27  */
28 int num_node_memblks;
29 struct node_memblk_s node_memblk[NR_NODE_MEMBLKS];
30 struct node_cpuid_s node_cpuid[NR_CPUS] =
31 	{ [0 ... NR_CPUS-1] = { .phys_id = 0, .nid = NUMA_NO_NODE } };
32 
33 /*
34  * This is a matrix with "distances" between nodes, they should be
35  * proportional to the memory access latency ratios.
36  */
37 u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
38 
39 int __node_distance(int from, int to)
40 {
41 	return slit_distance(from, to);
42 }
43 EXPORT_SYMBOL(__node_distance);
44 
45 /* Identify which cnode a physical address resides on */
46 int
47 paddr_to_nid(unsigned long paddr)
48 {
49 	int	i;
50 
51 	for (i = 0; i < num_node_memblks; i++)
52 		if (paddr >= node_memblk[i].start_paddr &&
53 		    paddr < node_memblk[i].start_paddr + node_memblk[i].size)
54 			break;
55 
56 	return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
57 }
58 EXPORT_SYMBOL(paddr_to_nid);
59 
60 #if defined(CONFIG_SPARSEMEM) && defined(CONFIG_NUMA)
61 void numa_clear_node(int cpu)
62 {
63 	unmap_cpu_from_node(cpu, NUMA_NO_NODE);
64 }
65 
66 #ifdef CONFIG_MEMORY_HOTPLUG
67 /*
68  *  SRAT information is stored in node_memblk[], then we can use SRAT
69  *  information at memory-hot-add if necessary.
70  */
71 
72 int memory_add_physaddr_to_nid(u64 addr)
73 {
74 	int nid = paddr_to_nid(addr);
75 	if (nid < 0)
76 		return 0;
77 	return nid;
78 }
79 #endif
80 #endif
81