ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / ia64 / mm / numa.c
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 static struct node *sysfs_nodes;
24 static struct cpu *sysfs_cpus;
25
26 /*
27  * The following structures are usually initialized by ACPI or
28  * similar mechanisms and describe the NUMA characteristics of the machine.
29  */
30 int num_node_memblks;
31 struct node_memblk_s node_memblk[NR_NODE_MEMBLKS];
32 struct node_cpuid_s node_cpuid[NR_CPUS];
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 /* Identify which cnode a physical address resides on */
40 int
41 paddr_to_nid(unsigned long paddr)
42 {
43         int     i;
44
45         for (i = 0; i < num_node_memblks; i++)
46                 if (paddr >= node_memblk[i].start_paddr &&
47                     paddr < node_memblk[i].start_paddr + node_memblk[i].size)
48                         break;
49
50         return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
51 }
52
53 static int __init topology_init(void)
54 {
55         int i, err = 0;
56
57         sysfs_nodes = kmalloc(sizeof(struct node) * numnodes, GFP_KERNEL);
58         if (!sysfs_nodes) {
59                 err = -ENOMEM;
60                 goto out;
61         }
62         memset(sysfs_nodes, 0, sizeof(struct node) * numnodes);
63
64         sysfs_cpus = kmalloc(sizeof(struct cpu) * NR_CPUS, GFP_KERNEL);
65         if (!sysfs_cpus) {
66                 kfree(sysfs_nodes);
67                 err = -ENOMEM;
68                 goto out;
69         }
70         memset(sysfs_cpus, 0, sizeof(struct cpu) * NR_CPUS);
71
72         for (i = 0; i < numnodes; i++)
73                 if ((err = register_node(&sysfs_nodes[i], i, 0)))
74                         goto out;
75
76         for (i = 0; i < NR_CPUS; i++)
77                 if (cpu_online(i))
78                         if((err = register_cpu(&sysfs_cpus[i], i,
79                                                &sysfs_nodes[cpu_to_node(i)])))
80                                 goto out;
81  out:
82         return err;
83 }
84
85 __initcall(topology_init);