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
6 * This file contains NUMA specific variables and functions which can
7 * be split away from DISCONTIGMEM and are used on NUMA machines with
10 * 2002/08/07 Erich Focht <efocht@ess.nec.de>
13 #include <linux/config.h>
14 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/bootmem.h>
18 #include <linux/mmzone.h>
19 #include <linux/smp.h>
23 * The following structures are usually initialized by ACPI or
24 * similar mechanisms and describe the NUMA characteristics of the machine.
27 struct node_memblk_s node_memblk[NR_MEMBLKS];
28 struct node_cpuid_s node_cpuid[NR_CPUS];
30 * This is a matrix with "distances" between nodes, they should be
31 * proportional to the memory access latency ratios.
33 u8 numa_slit[NR_NODES * NR_NODES];
35 /* Identify which cnode a physical address resides on */
37 paddr_to_nid(unsigned long paddr)
41 for (i = 0; i < num_memblks; i++)
42 if (paddr >= node_memblk[i].start_paddr &&
43 paddr < node_memblk[i].start_paddr + node_memblk[i].size)
46 return (i < num_memblks) ? node_memblk[i].nid : (num_memblks ? -1 : 0);
49 /* return end addr of a memblk */
51 memblk_endpaddr(unsigned long paddr)
55 for (i = 0; i < num_memblks; i++)
56 if (paddr >= node_memblk[i].start_paddr &&
57 paddr < node_memblk[i].start_paddr + node_memblk[i].size)
58 return node_memblk[i].start_paddr + node_memblk[i].size;
64 /* on which node is each logical CPU (one cacheline even for 64 CPUs) */
65 volatile char cpu_to_node_map[NR_CPUS] __cacheline_aligned;
67 /* which logical CPUs are on which nodes */
68 volatile unsigned long node_to_cpu_mask[NR_NODES] __cacheline_aligned;
71 * Build cpu to node mapping and initialize the per node cpu masks.
74 build_cpu_to_node_map (void)
78 for(cpu = 0; cpu < NR_CPUS; ++cpu) {
80 * All Itanium NUMA platforms I know use ACPI, so maybe we
81 * can drop this ifdef completely. [EF]
84 # ifdef CONFIG_ACPI_NUMA
86 for (i = 0; i < NR_CPUS; ++i) {
87 extern volatile int ia64_cpu_to_sapicid[];
88 if (ia64_cpu_to_sapicid[cpu] == node_cpuid[i].phys_id) {
89 node = node_cpuid[i].nid;
94 # error Fixme: Dunno how to build CPU-to-node map.
96 cpu_to_node_map[cpu] = node;
98 __set_bit(cpu, &node_to_cpu_mask[node]);
100 __set_bit(0, &node_to_cpu_mask[0]);