x86: use roundup() instead of PAGE_ALIGN() in find_early_table_space()
[safe/jmp/linux-2.6] / arch / powerpc / mm / init_64.c
index d12a87e..3e6a654 100644 (file)
@@ -5,7 +5,6 @@
  *  Modifications by Paul Mackerras (PowerMac) (paulus@cs.anu.edu.au)
  *  and Cort Dougan (PReP) (cort@cs.nmt.edu)
  *    Copyright (C) 1996 Paul Mackerras
- *  Amiga/APUS changes by Jesper Skov (jskov@cygnus.co.uk).
  *
  *  Derived from "arch/i386/mm/init.c"
  *    Copyright (C) 1991, 1992, 1993, 1994  Linus Torvalds
 #include <linux/nodemask.h>
 #include <linux/module.h>
 #include <linux/poison.h>
+#include <linux/lmb.h>
 
 #include <asm/pgalloc.h>
 #include <asm/page.h>
 #include <asm/prom.h>
-#include <asm/lmb.h>
 #include <asm/rtas.h>
 #include <asm/io.h>
 #include <asm/mmu_context.h>
 
 #include "mmu_decl.h"
 
-#ifdef DEBUG
-#define DBG(fmt...) printk(fmt)
-#else
-#define DBG(fmt...)
-#endif
-
 #if PGTABLE_RANGE > USER_VSID_RANGE
 #warning Limited user VSID range means pagetable space is wasted
 #endif
@@ -81,8 +74,8 @@
 #warning TASK_SIZE is smaller than it needs to be.
 #endif
 
-/* max amount of RAM to use */
-unsigned long __max_memory;
+phys_addr_t memstart_addr = ~0;
+phys_addr_t kernstart_addr;
 
 void free_initmem(void)
 {
@@ -114,6 +107,7 @@ void free_initrd_mem(unsigned long start, unsigned long end)
 }
 #endif
 
+#ifdef CONFIG_PROC_KCORE
 static struct kcore_list kcore_vmem;
 
 static int __init setup_kcore(void)
@@ -130,7 +124,7 @@ static int __init setup_kcore(void)
                /* GFP_ATOMIC to avoid might_sleep warnings during boot */
                kcore_mem = kmalloc(sizeof(struct kcore_list), GFP_ATOMIC);
                if (!kcore_mem)
-                       panic("%s: kmalloc failed\n", __FUNCTION__);
+                       panic("%s: kmalloc failed\n", __func__);
 
                kclist_add(kcore_mem, __va(base), size);
        }
@@ -140,55 +134,105 @@ static int __init setup_kcore(void)
        return 0;
 }
 module_init(setup_kcore);
+#endif
 
-static void zero_ctor(void *addr, struct kmem_cache *cache, unsigned long flags)
+static void pgd_ctor(void *addr)
 {
-       memset(addr, 0, kmem_cache_size(cache));
+       memset(addr, 0, PGD_TABLE_SIZE);
+}
+
+static void pmd_ctor(void *addr)
+{
+       memset(addr, 0, PMD_TABLE_SIZE);
 }
 
-#ifdef CONFIG_PPC_64K_PAGES
-static const unsigned int pgtable_cache_size[3] = {
-       PTE_TABLE_SIZE, PMD_TABLE_SIZE, PGD_TABLE_SIZE
-};
-static const char *pgtable_cache_name[ARRAY_SIZE(pgtable_cache_size)] = {
-       "pte_pmd_cache", "pmd_cache", "pgd_cache",
-};
-#else
 static const unsigned int pgtable_cache_size[2] = {
-       PTE_TABLE_SIZE, PMD_TABLE_SIZE
+       PGD_TABLE_SIZE, PMD_TABLE_SIZE
 };
 static const char *pgtable_cache_name[ARRAY_SIZE(pgtable_cache_size)] = {
-       "pgd_pte_cache", "pud_pmd_cache",
-};
+#ifdef CONFIG_PPC_64K_PAGES
+       "pgd_cache", "pmd_cache",
+#else
+       "pgd_cache", "pud_pmd_cache",
 #endif /* CONFIG_PPC_64K_PAGES */
+};
 
 #ifdef CONFIG_HUGETLB_PAGE
-/* Hugepages need one extra cache, initialized in hugetlbpage.c.  We
- * can't put into the tables above, because HPAGE_SHIFT is not compile
- * time constant. */
-struct kmem_cache *pgtable_cache[ARRAY_SIZE(pgtable_cache_size)+1];
+/* Hugepages need an extra cache per hugepagesize, initialized in
+ * hugetlbpage.c.  We can't put into the tables above, because HPAGE_SHIFT
+ * is not compile time constant. */
+struct kmem_cache *pgtable_cache[ARRAY_SIZE(pgtable_cache_size)+MMU_PAGE_COUNT];
 #else
 struct kmem_cache *pgtable_cache[ARRAY_SIZE(pgtable_cache_size)];
 #endif
 
 void pgtable_cache_init(void)
 {
-       int i;
+       pgtable_cache[0] = kmem_cache_create(pgtable_cache_name[0], PGD_TABLE_SIZE, PGD_TABLE_SIZE, SLAB_PANIC, pgd_ctor);
+       pgtable_cache[1] = kmem_cache_create(pgtable_cache_name[1], PMD_TABLE_SIZE, PMD_TABLE_SIZE, SLAB_PANIC, pmd_ctor);
+}
 
-       for (i = 0; i < ARRAY_SIZE(pgtable_cache_size); i++) {
-               int size = pgtable_cache_size[i];
-               const char *name = pgtable_cache_name[i];
-
-               DBG("Allocating page table cache %s (#%d) "
-                   "for size: %08x...\n", name, i, size);
-               pgtable_cache[i] = kmem_cache_create(name,
-                                                    size, size,
-                                                    SLAB_HWCACHE_ALIGN |
-                                                    SLAB_MUST_HWCACHE_ALIGN,
-                                                    zero_ctor,
-                                                    NULL);
-               if (! pgtable_cache[i])
-                       panic("pgtable_cache_init(): could not create %s!\n",
-                             name);
+#ifdef CONFIG_SPARSEMEM_VMEMMAP
+/*
+ * Given an address within the vmemmap, determine the pfn of the page that
+ * represents the start of the section it is within.  Note that we have to
+ * do this by hand as the proffered address may not be correctly aligned.
+ * Subtraction of non-aligned pointers produces undefined results.
+ */
+static unsigned long __meminit vmemmap_section_start(unsigned long page)
+{
+       unsigned long offset = page - ((unsigned long)(vmemmap));
+
+       /* Return the pfn of the start of the section. */
+       return (offset / sizeof(struct page)) & PAGE_SECTION_MASK;
+}
+
+/*
+ * Check if this vmemmap page is already initialised.  If any section
+ * which overlaps this vmemmap page is initialised then this page is
+ * initialised already.
+ */
+static int __meminit vmemmap_populated(unsigned long start, int page_size)
+{
+       unsigned long end = start + page_size;
+
+       for (; start < end; start += (PAGES_PER_SECTION * sizeof(struct page)))
+               if (pfn_valid(vmemmap_section_start(start)))
+                       return 1;
+
+       return 0;
+}
+
+int __meminit vmemmap_populate(struct page *start_page,
+                              unsigned long nr_pages, int node)
+{
+       unsigned long start = (unsigned long)start_page;
+       unsigned long end = (unsigned long)(start_page + nr_pages);
+       unsigned long page_size = 1 << mmu_psize_defs[mmu_vmemmap_psize].shift;
+
+       /* Align to the page size of the linear mapping. */
+       start = _ALIGN_DOWN(start, page_size);
+
+       for (; start < end; start += page_size) {
+               int mapped;
+               void *p;
+
+               if (vmemmap_populated(start, page_size))
+                       continue;
+
+               p = vmemmap_alloc_block(page_size, node);
+               if (!p)
+                       return -ENOMEM;
+
+               pr_debug("vmemmap %08lx allocated at %p, physical %08lx.\n",
+                       start, p, __pa(p));
+
+               mapped = htab_bolt_mapping(start, start + page_size, __pa(p),
+                                          pgprot_val(PAGE_KERNEL),
+                                          mmu_vmemmap_psize, mmu_kernel_ssize);
+               BUG_ON(mapped < 0);
        }
+
+       return 0;
 }
+#endif /* CONFIG_SPARSEMEM_VMEMMAP */