xref: /openbmc/linux/arch/ia64/mm/numa.c (revision 87c2ce3b)
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/config.h>
14 #include <linux/cpu.h>
15 #include <linux/kernel.h>
16 #include <linux/mm.h>
17 #include <linux/node.h>
18 #include <linux/init.h>
19 #include <linux/bootmem.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 /*
32  * This is a matrix with "distances" between nodes, they should be
33  * proportional to the memory access latency ratios.
34  */
35 u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
36 
37 /* Identify which cnode a physical address resides on */
38 int
39 paddr_to_nid(unsigned long paddr)
40 {
41 	int	i;
42 
43 	for (i = 0; i < num_node_memblks; i++)
44 		if (paddr >= node_memblk[i].start_paddr &&
45 		    paddr < node_memblk[i].start_paddr + node_memblk[i].size)
46 			break;
47 
48 	return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
49 }
50 
51 #if defined(CONFIG_SPARSEMEM) && defined(CONFIG_NUMA)
52 /*
53  * Because of holes evaluate on section limits.
54  * If the section of memory exists, then return the node where the section
55  * resides.  Otherwise return node 0 as the default.  This is used by
56  * SPARSEMEM to allocate the SPARSEMEM sectionmap on the NUMA node where
57  * the section resides.
58  */
59 int early_pfn_to_nid(unsigned long pfn)
60 {
61 	int i, section = pfn >> PFN_SECTION_SHIFT, ssec, esec;
62 
63 	for (i = 0; i < num_node_memblks; i++) {
64 		ssec = node_memblk[i].start_paddr >> PA_SECTION_SHIFT;
65 		esec = (node_memblk[i].start_paddr + node_memblk[i].size +
66 			((1L << PA_SECTION_SHIFT) - 1)) >> PA_SECTION_SHIFT;
67 		if (section >= ssec && section < esec)
68 			return node_memblk[i].nid;
69 	}
70 
71 	return 0;
72 }
73 #endif
74