fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / ia64 / mm / numa.c
index ef2dbcf..7807fc5 100644 (file)
  *                         2002/08/07 Erich Focht <efocht@ess.nec.de>
  */
 
-#include <linux/config.h>
 #include <linux/cpu.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/node.h>
 #include <linux/init.h>
 #include <linux/bootmem.h>
+#include <linux/module.h>
 #include <asm/mmzone.h>
 #include <asm/numa.h>
 
-static struct node *sysfs_nodes;
-static struct cpu *sysfs_cpus;
 
 /*
  * The following structures are usually initialized by ACPI or
@@ -50,36 +48,43 @@ paddr_to_nid(unsigned long paddr)
        return (i < num_node_memblks) ? node_memblk[i].nid : (num_node_memblks ? -1 : 0);
 }
 
-static int __init topology_init(void)
+#if defined(CONFIG_SPARSEMEM) && defined(CONFIG_NUMA)
+/*
+ * Because of holes evaluate on section limits.
+ * If the section of memory exists, then return the node where the section
+ * resides.  Otherwise return node 0 as the default.  This is used by
+ * SPARSEMEM to allocate the SPARSEMEM sectionmap on the NUMA node where
+ * the section resides.
+ */
+int early_pfn_to_nid(unsigned long pfn)
 {
-       int i, err = 0;
+       int i, section = pfn >> PFN_SECTION_SHIFT, ssec, esec;
 
-       sysfs_nodes = kmalloc(sizeof(struct node) * numnodes, GFP_KERNEL);
-       if (!sysfs_nodes) {
-               err = -ENOMEM;
-               goto out;
+       for (i = 0; i < num_node_memblks; i++) {
+               ssec = node_memblk[i].start_paddr >> PA_SECTION_SHIFT;
+               esec = (node_memblk[i].start_paddr + node_memblk[i].size +
+                       ((1L << PA_SECTION_SHIFT) - 1)) >> PA_SECTION_SHIFT;
+               if (section >= ssec && section < esec)
+                       return node_memblk[i].nid;
        }
-       memset(sysfs_nodes, 0, sizeof(struct node) * numnodes);
 
-       sysfs_cpus = kmalloc(sizeof(struct cpu) * NR_CPUS, GFP_KERNEL);
-       if (!sysfs_cpus) {
-               kfree(sysfs_nodes);
-               err = -ENOMEM;
-               goto out;
-       }
-       memset(sysfs_cpus, 0, sizeof(struct cpu) * NR_CPUS);
+       return 0;
+}
 
-       for (i = 0; i < numnodes; i++)
-               if ((err = register_node(&sysfs_nodes[i], i, 0)))
-                       goto out;
+#ifdef CONFIG_MEMORY_HOTPLUG
+/*
+ *  SRAT information is stored in node_memblk[], then we can use SRAT
+ *  information at memory-hot-add if necessary.
+ */
 
-       for (i = 0; i < NR_CPUS; i++)
-               if (cpu_online(i))
-                       if((err = register_cpu(&sysfs_cpus[i], i,
-                                              &sysfs_nodes[cpu_to_node(i)])))
-                               goto out;
- out:
-       return err;
+int memory_add_physaddr_to_nid(u64 addr)
+{
+       int nid = paddr_to_nid(addr);
+       if (nid < 0)
+               return 0;
+       return nid;
 }
 
-__initcall(topology_init);
+EXPORT_SYMBOL_GPL(memory_add_physaddr_to_nid);
+#endif
+#endif